<div dir="ltr">As this code is going to be referred to by people trying to figure out wayland, it might be best to use this by default. Fall back to the old damage request only if the api is too old or if a special switch is passed.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 18, 2015 at 2:32 PM, Derek Foreman <span dir="ltr"><<a href="mailto:derekf@osg.samsung.com" target="_blank">derekf@osg.samsung.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Add a new flag for testing damage in buffer co-ordinates<br>
<br>
Signed-off-by: Derek Foreman <<a href="mailto:derekf@osg.samsung.com">derekf@osg.samsung.com</a>><br>
---<br>
clients/simple-damage.c | 62 +++++++++++++++++++++++++++++++++++++------------<br>
1 file changed, 47 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/clients/simple-damage.c b/clients/simple-damage.c<br>
index 0551b9d..8929071 100644<br>
--- a/clients/simple-damage.c<br>
+++ b/clients/simple-damage.c<br>
@@ -64,6 +64,7 @@ struct buffer {<br>
enum window_flags {<br>
WINDOW_FLAG_USE_VIEWPORT = 0x1,<br>
WINDOW_FLAG_ROTATING_TRANSFORM = 0x2,<br>
+ WINDOW_FLAG_USE_DAMAGE_BUFFER = 0x4,<br>
};<br>
<br>
struct window {<br>
@@ -261,6 +262,14 @@ create_window(struct display *display, int width, int height,<br>
exit(1);<br>
}<br>
<br>
+ if (display->compositor_version < 4 &&<br>
+ (flags & WINDOW_FLAG_USE_DAMAGE_BUFFER)) {<br>
+ fprintf(stderr, "wl_surface.damage_buffer unsupported in "<br>
+ "wl_surface version %d\n",<br>
+ display->compositor_version);<br>
+ exit(1);<br>
+ }<br>
+<br>
window = calloc(1, sizeof *window);<br>
if (!window)<br>
return NULL;<br>
@@ -303,8 +312,12 @@ create_window(struct display *display, int width, int height,<br>
}<br>
<br>
/* Initialise damage to full surface, so the padding gets painted */<br>
- wl_surface_damage(window->surface, 0, 0, INT32_MAX, INT32_MAX);<br>
-<br>
+ if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) {<br>
+ wl_surface_damage_buffer(window->surface, 0, 0,<br>
+ INT32_MAX, INT32_MAX);<br>
+ } else {<br>
+ wl_surface_damage(window->surface, 0, 0, INT32_MAX, INT32_MAX);<br>
+ }<br>
return window;<br>
}<br>
<br>
@@ -567,12 +580,20 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)<br>
bwidth - 2 * bborder, bheight - 2 * bborder, 0x80000000);<br>
<br>
/* Damage where the ball was */<br>
- wl_surface_damage(window->surface,<br>
- window->ball.x - window->ball.radius,<br>
- window->ball.y - window->ball.radius,<br>
- window->ball.radius * 2 + 1,<br>
- window->ball.radius * 2 + 1);<br>
-<br>
+ if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) {<br>
+ window_get_transformed_ball(window, &bx, &by);<br>
+ wl_surface_damage_buffer(window->surface,<br>
+ bx - bradius + off_x,<br>
+ by - bradius + off_y,<br>
+ bradius * 2 + 1,<br>
+ bradius * 2 + 1);<br>
+ } else {<br>
+ wl_surface_damage(window->surface,<br>
+ window->ball.x - window->ball.radius,<br>
+ window->ball.y - window->ball.radius,<br>
+ window->ball.radius * 2 + 1,<br>
+ window->ball.radius * 2 + 1);<br>
+ }<br>
window_advance_game(window, time);<br>
<br>
window_get_transformed_ball(window, &bx, &by);<br>
@@ -595,12 +616,19 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)<br>
}<br>
<br>
/* Damage where the ball is now */<br>
- wl_surface_damage(window->surface,<br>
- window->ball.x - window->ball.radius,<br>
- window->ball.y - window->ball.radius,<br>
- window->ball.radius * 2 + 1,<br>
- window->ball.radius * 2 + 1);<br>
-<br>
+ if (window->flags & WINDOW_FLAG_USE_DAMAGE_BUFFER) {<br>
+ wl_surface_damage_buffer(window->surface,<br>
+ bx - bradius + off_x,<br>
+ by - bradius + off_y,<br>
+ bradius * 2 + 1,<br>
+ bradius * 2 + 1);<br>
+ } else {<br>
+ wl_surface_damage(window->surface,<br>
+ window->ball.x - window->ball.radius,<br>
+ window->ball.y - window->ball.radius,<br>
+ window->ball.radius * 2 + 1,<br>
+ window->ball.radius * 2 + 1);<br>
+ }<br>
wl_surface_attach(window->surface, buffer->buffer, 0, 0);<br>
<br>
if (window->display->compositor_version >= 2 &&<br>
@@ -787,6 +815,7 @@ print_usage(int retval)<br>
" --transform=TRANSFORM\tTransform for the surface\n"<br>
" --rotating-transform\tUse a different buffer_transform for each frame\n"<br>
" --use-viewport\tUse wl_viewport\n"<br>
+ " --use-damage-buffer\tUse damage_buffer to post damage\n"<br>
);<br>
<br>
exit(retval);<br>
@@ -837,7 +866,7 @@ main(int argc, char **argv)<br>
strcmp(argv[i], "-h") == 0) {<br>
print_usage(0);<br>
} else if (sscanf(argv[i], "--version=%d", &version) > 0) {<br>
- if (version < 1 || version > 3) {<br>
+ if (version < 1 || version > 4) {<br>
fprintf(stderr, "Unsupported wl_surface version: %d\n",<br>
version);<br>
return 1;<br>
@@ -861,6 +890,9 @@ main(int argc, char **argv)<br>
} else if (strcmp(argv[i], "--use-viewport") == 0) {<br>
flags |= WINDOW_FLAG_USE_VIEWPORT;<br>
continue;<br>
+ } else if (strcmp(argv[i], "--use-damage-buffer") == 0) {<br>
+ flags |= WINDOW_FLAG_USE_DAMAGE_BUFFER;<br>
+ continue;<br>
} else {<br>
printf("Invalid option: %s\n", argv[i]);<br>
print_usage(255);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.6.2<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>