simple-damage: Offset drawing co-ordinates not buffer start
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@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
+34
-24
@@ -454,8 +454,8 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
|
|||||||
{
|
{
|
||||||
struct window *window = data;
|
struct window *window = data;
|
||||||
struct buffer *buffer;
|
struct buffer *buffer;
|
||||||
int off_x, off_y, bwidth, bheight, bborder, bpitch, bradius;
|
int off_x = 0, off_y = 0;
|
||||||
uint32_t *buffer_data;
|
int bwidth, bheight, bborder, bpitch, bradius;
|
||||||
float bx, by;
|
float bx, by;
|
||||||
|
|
||||||
buffer = window_next_buffer(window);
|
buffer = window_next_buffer(window);
|
||||||
@@ -494,8 +494,8 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
|
|||||||
bborder = window->border * window->scale;
|
bborder = window->border * window->scale;
|
||||||
bradius = window->ball.radius * window->scale;
|
bradius = window->ball.radius * window->scale;
|
||||||
|
|
||||||
buffer_data = buffer->shm_data;
|
|
||||||
if (window->viewport) {
|
if (window->viewport) {
|
||||||
|
int tx, ty;
|
||||||
/* Fill the whole thing with red to detect viewport errors */
|
/* Fill the whole thing with red to detect viewport errors */
|
||||||
paint_box(buffer->shm_data, bpitch, 0, 0, bwidth, bheight,
|
paint_box(buffer->shm_data, bpitch, 0, 0, bwidth, bheight,
|
||||||
0xffff0000);
|
0xffff0000);
|
||||||
@@ -508,35 +508,41 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
|
|||||||
bheight /= 2;
|
bheight /= 2;
|
||||||
|
|
||||||
/* Offset the drawing region */
|
/* Offset the drawing region */
|
||||||
off_x = (window->width / 3) * window->scale;
|
tx = (window->width / 3) * window->scale;
|
||||||
off_y = (window->height / 5) * window->scale;
|
ty = (window->height / 5) * window->scale;
|
||||||
switch (window->transform) {
|
switch (window->transform) {
|
||||||
default:
|
default:
|
||||||
case WL_OUTPUT_TRANSFORM_NORMAL:
|
case WL_OUTPUT_TRANSFORM_NORMAL:
|
||||||
buffer_data += off_y * bpitch + off_x;
|
off_y = ty;
|
||||||
|
off_x = tx;
|
||||||
break;
|
break;
|
||||||
case WL_OUTPUT_TRANSFORM_90:
|
case WL_OUTPUT_TRANSFORM_90:
|
||||||
buffer_data += off_x * bpitch + (bwidth - off_y);
|
off_y = tx;
|
||||||
|
off_x = bwidth - ty;
|
||||||
break;
|
break;
|
||||||
case WL_OUTPUT_TRANSFORM_180:
|
case WL_OUTPUT_TRANSFORM_180:
|
||||||
buffer_data += (bheight - off_y) * bpitch +
|
off_y = bheight - ty;
|
||||||
(bwidth - off_x);
|
off_x = bwidth - tx;
|
||||||
break;
|
break;
|
||||||
case WL_OUTPUT_TRANSFORM_270:
|
case WL_OUTPUT_TRANSFORM_270:
|
||||||
buffer_data += (bheight - off_x) * bpitch + off_y;
|
off_y = bheight - tx;
|
||||||
|
off_x = ty;
|
||||||
break;
|
break;
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||||||
buffer_data += off_y * bpitch + (bwidth - off_x);
|
off_y = ty;
|
||||||
|
off_x = bwidth - tx;
|
||||||
break;
|
break;
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||||||
buffer_data += (bheight - off_x) * bpitch +
|
off_y = bheight - tx;
|
||||||
(bwidth - off_y);
|
off_x = bwidth - ty;
|
||||||
break;
|
break;
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||||||
buffer_data += (bheight - off_y) * bpitch + off_x;
|
off_y = bheight - ty;
|
||||||
|
off_x = tx;
|
||||||
break;
|
break;
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||||||
buffer_data += off_x * bpitch + off_y;
|
off_y = tx;
|
||||||
|
off_x = ty;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wl_viewport_set_source(window->viewport,
|
wl_viewport_set_source(window->viewport,
|
||||||
@@ -547,15 +553,17 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Paint the border */
|
/* Paint the border */
|
||||||
paint_box(buffer_data, bpitch, 0, 0, bwidth, bborder, 0xffffffff);
|
paint_box(buffer->shm_data, bpitch, off_x, off_y,
|
||||||
paint_box(buffer_data, bpitch, 0, 0, bborder, bheight, 0xffffffff);
|
bwidth, bborder, 0xffffffff);
|
||||||
paint_box(buffer_data, bpitch,
|
paint_box(buffer->shm_data, bpitch, off_x, off_y,
|
||||||
bwidth - bborder, 0, bborder, bheight, 0xffffffff);
|
bborder, bheight, 0xffffffff);
|
||||||
paint_box(buffer_data, bpitch,
|
paint_box(buffer->shm_data, bpitch, off_x + bwidth - bborder, off_y,
|
||||||
0, bheight - bborder, bwidth, bborder, 0xffffffff);
|
bborder, bheight, 0xffffffff);
|
||||||
|
paint_box(buffer->shm_data, bpitch, off_x, off_y + bheight - bborder,
|
||||||
|
bwidth, bborder, 0xffffffff);
|
||||||
|
|
||||||
/* fill with translucent */
|
/* 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);
|
bwidth - 2 * bborder, bheight - 2 * bborder, 0x80000000);
|
||||||
|
|
||||||
/* Damage where the ball was */
|
/* 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);
|
window_get_transformed_ball(window, &bx, &by);
|
||||||
|
|
||||||
/* Paint the ball */
|
/* 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) {
|
if (print_debug) {
|
||||||
printf("Ball now located at (%f, %f)\n",
|
printf("Ball now located at (%f, %f)\n",
|
||||||
@@ -580,7 +589,8 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
|
|||||||
bradius);
|
bradius);
|
||||||
|
|
||||||
printf("Buffer damage rectangle: (%d, %d) @ %dx%d\n",
|
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);
|
bradius * 2 + 1, bradius * 2 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user