summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2010-09-03 14:46:38 -0400
committerKristian Høgsberg <krh@bitplanet.net>2010-09-03 14:46:38 -0400
commit9d69f8e7963965ec4301364a01d941b3615fa1a1 (patch)
treef6a466b0b8684635782175d23eff92c882caffe6 /clients
parent13b8ae49867bee41e2d6f73d7afdeba4ecd7570c (diff)
Replace commit/ack/frame protocol with simpler sync and frame callbacks
Diffstat (limited to 'clients')
-rw-r--r--clients/dnd.c2
-rw-r--r--clients/flower.c17
-rw-r--r--clients/gears.c32
-rw-r--r--clients/image.c2
-rw-r--r--clients/terminal.c2
-rw-r--r--clients/view.c3
-rw-r--r--clients/window.c96
-rw-r--r--clients/window.h16
8 files changed, 60 insertions, 110 deletions
diff --git a/clients/dnd.c b/clients/dnd.c
index df4d8c5..9095672 100644
--- a/clients/dnd.c
+++ b/clients/dnd.c
@@ -183,8 +183,8 @@ dnd_draw(struct dnd *dnd)
cairo_destroy(cr);
window_copy_surface(dnd->window, &rectangle, surface);
- window_commit(dnd->window, dnd->key);
cairo_surface_destroy(surface);
+ window_flush(dnd->window);
}
static void
diff --git a/clients/flower.c b/clients/flower.c
index 54d54f2..3a06bf9 100644
--- a/clients/flower.c
+++ b/clients/flower.c
@@ -98,21 +98,22 @@ draw_stuff(cairo_surface_t *surface, int width, int height)
}
struct flower {
+ struct display *display;
struct window *window;
int x, y, width, height;
int offset;
};
static void
-handle_frame(struct window *window,
- uint32_t frame, uint32_t timestamp, void *data)
+frame_callback(void *data, uint32_t time)
{
struct flower *flower = data;
window_move(flower->window,
- flower->x + cos((flower->offset + timestamp) / 400.0) * 400 - flower->width / 2,
- flower->y + sin((flower->offset + timestamp) / 320.0) * 300 - flower->height / 2);
- window_commit(flower->window, 0);
+ flower->x + cos((flower->offset + time) / 400.0) * 400 - flower->width / 2,
+ flower->y + sin((flower->offset + time) / 320.0) * 300 - flower->height / 2);
+ wl_display_frame_callback(display_get_display(flower->display),
+ frame_callback, flower);
}
int main(int argc, char *argv[])
@@ -128,6 +129,7 @@ int main(int argc, char *argv[])
flower.y = 384;
flower.width = 200;
flower.height = 200;
+ flower.display = d;
flower.window = window_create(d, "flower", flower.x, flower.y,
flower.width, flower.height);
@@ -145,10 +147,11 @@ int main(int argc, char *argv[])
draw_stuff(s, flower.width, flower.height);
cairo_surface_flush(s);
+ window_flush(flower.window);
window_set_user_data(flower.window, &flower);
- window_set_frame_handler(flower.window, handle_frame);
- window_commit(flower.window, 0);
+ wl_display_frame_callback(display_get_display(d),
+ frame_callback, &flower);
display_run(d);
diff --git a/clients/gears.c b/clients/gears.c
index 0426f20..f8c77ec 100644
--- a/clients/gears.c
+++ b/clients/gears.c
@@ -317,31 +317,21 @@ keyboard_focus_handler(struct window *window,
}
static void
-acknowledge_handler(struct window *window,
- uint32_t key, uint32_t frame,
- void *data)
+frame_callback(void *data, uint32_t time)
{
struct gears *gears = data;
- if (key == 10) {
- if (gears->resized)
- resize_window(gears);
+ window_copy_image(gears->window, &gears->rectangle, gears->image);
- draw_gears(gears);
- }
-}
+ if (gears->resized)
+ resize_window(gears);
-static void
-frame_handler(struct window *window,
- uint32_t frame, uint32_t timestamp, void *data)
-{
- struct gears *gears = data;
-
- window_copy_image(gears->window, &gears->rectangle, gears->image);
+ draw_gears(gears);
- window_commit(gears->window, 10);
+ gears->angle = (GLfloat) (time % 8192) * 360 / 8192.0;
- gears->angle = (GLfloat) (timestamp % 8192) * 360 / 8192.0;
+ wl_display_frame_callback(display_get_display(gears->d),
+ frame_callback, gears);
}
static struct gears *
@@ -417,13 +407,13 @@ gears_create(struct display *display)
resize_window(gears);
draw_gears(gears);
- frame_handler(gears->window, 0, 0, gears);
window_set_user_data(gears->window, gears);
window_set_resize_handler(gears->window, resize_handler);
window_set_keyboard_focus_handler(gears->window, keyboard_focus_handler);
- window_set_acknowledge_handler(gears->window, acknowledge_handler);
- window_set_frame_handler(gears->window, frame_handler);
+
+ wl_display_frame_callback(display_get_display(gears->d),
+ frame_callback, gears);
return gears;
}
diff --git a/clients/image.c b/clients/image.c
index fa23520..b359a94 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -176,7 +176,7 @@ image_draw(struct image *image)
g_object_unref(pb);
window_copy_surface(image->window, &rectangle, surface);
- window_commit(image->window, image->key);
+ window_flush(image->window);
cairo_surface_destroy(surface);
}
diff --git a/clients/terminal.c b/clients/terminal.c
index 1bb496d..c841ef2 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -215,7 +215,7 @@ terminal_draw(struct terminal *terminal)
window_draw(terminal->window);
terminal_draw_contents(terminal);
- window_commit(terminal->window, 0);
+ window_flush(terminal->window);
}
static void
diff --git a/clients/view.c b/clients/view.c
index 0c8ce5a..ace838d 100644
--- a/clients/view.c
+++ b/clients/view.c
@@ -101,8 +101,7 @@ view_draw(struct view *view)
poppler_page_render(page, cr);
cairo_destroy(cr);
g_object_unref(G_OBJECT(page));
-
- window_commit(view->window, 0);
+ window_flush(view->window);
}
static void
diff --git a/clients/window.c b/clients/window.c
index 5a2f247..0aa319d 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -98,8 +98,6 @@ struct window {
window_key_handler_t key_handler;
window_button_handler_t button_handler;
window_keyboard_focus_handler_t keyboard_focus_handler;
- window_acknowledge_handler_t acknowledge_handler;
- window_frame_handler_t frame_handler;
window_motion_handler_t motion_handler;
void *user_data;
@@ -331,6 +329,21 @@ display_get_pointer_surface(struct display *display, int pointer,
return cairo_surface_reference(surface);
}
+
+static void
+window_attach_surface(struct window *window);
+
+static void
+free_surface(void *data)
+{
+ struct window *window = data;
+
+ cairo_surface_destroy(window->pending_surface);
+ window->pending_surface = NULL;
+ if (window->cairo_surface)
+ window_attach_surface(window);
+}
+
static void
window_attach_surface(struct window *window)
{
@@ -353,17 +366,14 @@ window_attach_surface(struct window *window)
window->allocation.width,
window->allocation.height);
- wl_compositor_commit(window->display->compositor, 0);
+ wl_display_sync_callback(display->display, free_surface, window);
}
void
-window_commit(struct window *window, uint32_t key)
+window_flush(struct window *window)
{
- if (window->cairo_surface) {
- window_attach_surface(window);
- } else {
- wl_compositor_commit(window->display->compositor, key);
- }
+ if (window->cairo_surface)
+ window_attach_surface(window);
}
static void
@@ -848,6 +858,10 @@ window_copy_surface(struct window *window,
cairo_paint (cr);
cairo_destroy (cr);
+
+ wl_surface_damage(window->surface,
+ rectangle->x, rectangle->y,
+ rectangle->width, rectangle->height);
}
static gboolean
@@ -934,20 +948,6 @@ window_set_button_handler(struct window *window,
}
void
-window_set_acknowledge_handler(struct window *window,
- window_acknowledge_handler_t handler)
-{
- window->acknowledge_handler = handler;
-}
-
-void
-window_set_frame_handler(struct window *window,
- window_frame_handler_t handler)
-{
- window->frame_handler = handler;
-}
-
-void
window_set_motion_handler(struct window *window,
window_motion_handler_t handler)
{
@@ -1023,48 +1023,6 @@ static const struct wl_drm_listener drm_listener = {
};
static void
-display_handle_acknowledge(void *data,
- struct wl_compositor *compositor,
- uint32_t key, uint32_t frame)
-{
- struct display *d = data;
- struct window *window;
-
- /* The acknowledge event means that the server processed our
- * last commit request and we can now safely free the old
- * window buffer if we resized and render the next frame into
- * our back buffer.. */
- wl_list_for_each(window, &d->window_list, link) {
- cairo_surface_destroy(window->pending_surface);
- window->pending_surface = NULL;
- if (window->cairo_surface)
- window_attach_surface(window);
- if (window->acknowledge_handler)
- (*window->acknowledge_handler)(window, key, frame, window->user_data);
- }
-}
-
-static void
-display_handle_frame(void *data,
- struct wl_compositor *compositor,
- uint32_t frame, uint32_t timestamp)
-{
- struct display *d = data;
- struct window *window;
-
- wl_list_for_each(window, &d->window_list, link) {
- if (window->frame_handler)
- (*window->frame_handler)(window, frame,
- timestamp, window->user_data);
- }
-}
-
-static const struct wl_compositor_listener compositor_listener = {
- display_handle_acknowledge,
- display_handle_frame,
-};
-
-static void
display_handle_geometry(void *data,
struct wl_output *output,
int32_t width, int32_t height)
@@ -1111,8 +1069,6 @@ display_handle_global(struct wl_display *display, uint32_t id,
if (strcmp(interface, "compositor") == 0) {
d->compositor = wl_compositor_create(display, id);
- wl_compositor_add_listener(d->compositor,
- &compositor_listener, d);
} else if (strcmp(interface, "output") == 0) {
d->output = wl_output_create(display, id);
wl_output_add_listener(d->output, &output_listener, d);
@@ -1290,6 +1246,12 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
return d;
}
+struct wl_display *
+display_get_display(struct display *display)
+{
+ return display->display;
+}
+
struct wl_compositor *
display_get_compositor(struct display *display)
{
diff --git a/clients/window.h b/clients/window.h
index 1b4285f..343d536 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -38,6 +38,9 @@ struct input;
struct display *
display_create(int *argc, char **argv[], const GOptionEntry *option_entries);
+struct wl_display *
+display_get_display(struct display *display);
+
struct wl_compositor *
display_get_compositor(struct display *display);
@@ -96,7 +99,6 @@ enum pointer_type {
typedef void (*window_resize_handler_t)(struct window *window, void *data);
typedef void (*window_redraw_handler_t)(struct window *window, void *data);
typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
-typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, uint32_t frame, void *data);
typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t unicode,
uint32_t state, uint32_t modifiers, void *data);
typedef void (*window_keyboard_focus_handler_t)(struct window *window,
@@ -121,8 +123,6 @@ window_create(struct display *display, const char *title,
void
window_draw(struct window *window);
void
-window_commit(struct window *window, uint32_t key);
-void
window_get_child_rectangle(struct window *window,
struct rectangle *rectangle);
void
@@ -147,6 +147,9 @@ window_copy_surface(struct window *window,
cairo_surface_t *surface);
void
+window_flush(struct window *window);
+
+void
window_set_fullscreen(struct window *window, int fullscreen);
void
@@ -168,9 +171,6 @@ window_set_resize_handler(struct window *window,
void
window_set_frame_handler(struct window *window,
window_frame_handler_t handler);
-void
-window_set_acknowledge_handler(struct window *window,
- window_acknowledge_handler_t handler);
void
window_set_key_handler(struct window *window,
@@ -189,10 +189,6 @@ window_set_keyboard_focus_handler(struct window *window,
window_keyboard_focus_handler_t handler);
void
-window_set_acknowledge_handler(struct window *window,
- window_acknowledge_handler_t handler);
-
-void
window_set_frame_handler(struct window *window,
window_frame_handler_t handler);