[PATCH weston 10/11] simple-damage: Offset drawing co-ordinates not buffer start

Derek Foreman derekf at osg.samsung.com
Thu Nov 19 09:28:25 PST 2015


On 18/11/15 07:31 PM, Bill Spitzak wrote:
> You sure this has to change?

If I'm posting damage in buffer co-ordinates, I need to know what buffer
co-ordinates to use.

Currently, the code moves the *data pointer and does its drawing as if
everything is still at 0,0.

ie) if we set a buffer viewport with a top left corner of 20, 20, we
move the pointer, all the drawing ops are done with 0,0 as origin.

So we draw the bouncy ball at 75, 75 in the buffer by using a draw call
at 55, 55.  Now I've got those 55, 55 co-ordinates to pass to the
damage_buffer function.  I get a box of damage that isn't in the right
place.


So, I don't technically need to change any of the drawing operations,
and I can still move the pointer to do the offset - but I still need to
track the "real" co-ordinates of what I just drew.

I could write a smaller patch that just tracked those co-ordinates to
use for damage posting, but I think it ends up being simpler code to
read if stop moving the buffer pointer entirely so damage and draw use
the same co-ordinates.

(There's actually a bug fix hidden in here - the debug prints were wrong
when viewports were in use because they showed the 0,0 referenced
co-ordinates)

For the following patch, the important bit is that off_x and off_y are
now transformed.

Thanks,
Derek

> On Wed, Nov 18, 2015 at 2:32 PM, Derek Foreman <derekf at osg.samsung.com
> <mailto:derekf at osg.samsung.com>> wrote:
> 
>     We've been setting up the viewport by moving the start pointer of the
>     draw buffer, but later when we want to post damage in buffer
>     co-ordinates
>     we'll need to keep track of the x,y offsets anyway.
> 
>     Signed-off-by: Derek Foreman <derekf at osg.samsung.com
>     <mailto:derekf at osg.samsung.com>>
>     ---
>      clients/simple-damage.c | 58
>     +++++++++++++++++++++++++++++--------------------
>      1 file changed, 34 insertions(+), 24 deletions(-)
> 
>     diff --git a/clients/simple-damage.c b/clients/simple-damage.c
>     index 13e220a..0551b9d 100644
>     --- a/clients/simple-damage.c
>     +++ b/clients/simple-damage.c
>     @@ -454,8 +454,8 @@ redraw(void *data, struct wl_callback *callback,
>     uint32_t time)
>      {
>             struct window *window = data;
>             struct buffer *buffer;
>     -       int off_x, off_y, bwidth, bheight, bborder, bpitch, bradius;
>     -       uint32_t *buffer_data;
>     +       int off_x = 0, off_y = 0;
>     +       int bwidth, bheight, bborder, bpitch, bradius;
>             float bx, by;
> 
>             buffer = window_next_buffer(window);
>     @@ -494,8 +494,8 @@ redraw(void *data, struct wl_callback *callback,
>     uint32_t time)
>             bborder = window->border * window->scale;
>             bradius = window->ball.radius * window->scale;
> 
>     -       buffer_data = buffer->shm_data;
>             if (window->viewport) {
>     +               int tx, ty;
>                     /* Fill the whole thing with red to detect viewport
>     errors */
>                     paint_box(buffer->shm_data, bpitch, 0, 0, bwidth,
>     bheight,
>                               0xffff0000);
>     @@ -508,35 +508,41 @@ redraw(void *data, struct wl_callback
>     *callback, uint32_t time)
>                     bheight /= 2;
> 
>                     /* Offset the drawing region */
>     -               off_x = (window->width / 3) * window->scale;
>     -               off_y = (window->height / 5) * window->scale;
>     +               tx = (window->width / 3) * window->scale;
>     +               ty = (window->height / 5) * window->scale;
>                     switch (window->transform) {
>                     default:
>                     case WL_OUTPUT_TRANSFORM_NORMAL:
>     -                       buffer_data += off_y * bpitch + off_x;
>     +                       off_y = ty;
>     +                       off_x = tx;
>                             break;
>                     case WL_OUTPUT_TRANSFORM_90:
>     -                       buffer_data += off_x * bpitch + (bwidth -
>     off_y);
>     +                       off_y = tx;
>     +                       off_x = bwidth - ty;
>                             break;
>                     case WL_OUTPUT_TRANSFORM_180:
>     -                       buffer_data += (bheight - off_y) * bpitch +
>     -                                      (bwidth - off_x);
>     +                       off_y = bheight - ty;
>     +                       off_x = bwidth - tx;
>                             break;
>                     case WL_OUTPUT_TRANSFORM_270:
>     -                       buffer_data += (bheight - off_x) * bpitch +
>     off_y;
>     +                       off_y = bheight - tx;
>     +                       off_x = ty;
>                             break;
>                     case WL_OUTPUT_TRANSFORM_FLIPPED:
>     -                       buffer_data += off_y * bpitch + (bwidth -
>     off_x);
>     +                       off_y = ty;
>     +                       off_x = bwidth - tx;
>                             break;
>                     case WL_OUTPUT_TRANSFORM_FLIPPED_90:
>     -                       buffer_data += (bheight - off_x) * bpitch +
>     -                                      (bwidth - off_y);
>     +                       off_y = bheight - tx;
>     +                       off_x = bwidth - ty;
>                             break;
>                     case WL_OUTPUT_TRANSFORM_FLIPPED_180:
>     -                       buffer_data += (bheight - off_y) * bpitch +
>     off_x;
>     +                       off_y = bheight - ty;
>     +                       off_x = tx;
>                             break;
>                     case WL_OUTPUT_TRANSFORM_FLIPPED_270:
>     -                       buffer_data += off_x * bpitch + off_y;
>     +                       off_y = tx;
>     +                       off_x = ty;
>                             break;
>                     }
>                     wl_viewport_set_source(window->viewport,
>     @@ -547,15 +553,17 @@ redraw(void *data, struct wl_callback
>     *callback, uint32_t time)
>             }
> 
>             /* Paint the border */
>     -       paint_box(buffer_data, bpitch, 0, 0, bwidth, bborder,
>     0xffffffff);
>     -       paint_box(buffer_data, bpitch, 0, 0, bborder, bheight,
>     0xffffffff);
>     -       paint_box(buffer_data, bpitch,
>     -                 bwidth - bborder, 0, bborder, bheight, 0xffffffff);
>     -       paint_box(buffer_data, bpitch,
>     -                 0, bheight - bborder, bwidth, bborder, 0xffffffff);
>     +       paint_box(buffer->shm_data, bpitch, off_x, off_y,
>     +                 bwidth, bborder, 0xffffffff);
>     +       paint_box(buffer->shm_data, bpitch, off_x, off_y,
>     +                 bborder, bheight, 0xffffffff);
>     +       paint_box(buffer->shm_data, bpitch, off_x + bwidth -
>     bborder, off_y,
>     +                 bborder, bheight, 0xffffffff);
>     +       paint_box(buffer->shm_data, bpitch, off_x, off_y + bheight -
>     bborder,
>     +                 bwidth, bborder, 0xffffffff);
> 
>             /* fill with translucent */
>     -       paint_box(buffer_data, bpitch, bborder, bborder,
>     +       paint_box(buffer->shm_data, bpitch, off_x + bborder, off_y +
>     bborder,
>                       bwidth - 2 * bborder, bheight - 2 * bborder,
>     0x80000000);
> 
>             /* Damage where the ball was */
>     @@ -570,7 +578,8 @@ redraw(void *data, struct wl_callback *callback,
>     uint32_t time)
>             window_get_transformed_ball(window, &bx, &by);
> 
>             /* Paint the ball */
>     -       paint_circle(buffer_data, bpitch, bx, by, bradius, 0xff00ff00);
>     +       paint_circle(buffer->shm_data, bpitch, off_x + bx, off_y + by,
>     +                    bradius, 0xff00ff00);
> 
>             if (print_debug) {
>                     printf("Ball now located at (%f, %f)\n",
>     @@ -580,7 +589,8 @@ redraw(void *data, struct wl_callback *callback,
>     uint32_t time)
>                            bradius);
> 
>                     printf("Buffer damage rectangle: (%d, %d) @ %dx%d\n",
>     -                      (int)(bx - bradius), (int)(by - bradius),
>     +                      (int)(bx - bradius) + off_x,
>     +                      (int)(by - bradius) + off_y,
>                            bradius * 2 + 1, bradius * 2 + 1);
>             }
> 
>     --
>     2.6.2
> 
>     _______________________________________________
>     wayland-devel mailing list
>     wayland-devel at lists.freedesktop.org
>     <mailto:wayland-devel at lists.freedesktop.org>
>     http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 
> 
> 
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 



More information about the wayland-devel mailing list