window: Allocate and flush the window surface in window.c
authorKristian Høgsberg <krh@bitplanet.net>
Tue, 10 Jan 2012 15:49:41 +0000 (10:49 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 10 Jan 2012 17:25:32 +0000 (12:25 -0500)
No need to push this to the toolkit users.

clients/desktop-shell.c
clients/dnd.c
clients/eventdemo.c
clients/flower.c
clients/gears.c
clients/image.c
clients/resizor.c
clients/tablet-shell.c
clients/terminal.c
clients/window.c
clients/wscreensaver.c

index 8cb85be..ad1318d 100644 (file)
@@ -341,7 +341,7 @@ background_draw(struct window *window, int width, int height, const char *path)
        double sx, sy;
 
        window_set_child_size(window, width, height);
-       window_draw(window);
+       window_create_surface(window);
        surface = window_get_surface(window);
 
        cr = cairo_create(surface);
@@ -388,8 +388,6 @@ unlock_dialog_draw(struct unlock_dialog *dialog)
        cairo_pattern_t *pat;
        double cx, cy, r, f;
 
-       window_draw(dialog->window);
-
        surface = window_get_surface(dialog->window);
        cr = cairo_create(surface);
        window_get_child_allocation(dialog->window, &allocation);
@@ -428,7 +426,6 @@ unlock_dialog_draw(struct unlock_dialog *dialog)
        cairo_paint(cr);
        cairo_destroy(cr);
 
-       window_flush(dialog->window);
        cairo_surface_destroy(surface);
 }
 
index e1c057d..cd03b1f 100644 (file)
@@ -167,8 +167,6 @@ dnd_draw(struct dnd *dnd)
        cairo_surface_t *surface;
        int i;
 
-       window_draw(dnd->window);
-
        surface = window_get_surface(dnd->window);
        cr = cairo_create(surface);
        window_get_child_allocation(dnd->window, &allocation);
@@ -191,7 +189,6 @@ dnd_draw(struct dnd *dnd)
 
        cairo_destroy(cr);
        cairo_surface_destroy(surface);
-       window_flush(dnd->window);
 }
 
 static void
index 928cfdd..5ea6831 100644 (file)
@@ -103,7 +103,6 @@ eventdemo_draw(struct eventdemo *e) {
        cairo_t *cr;
        struct rectangle rect;
 
-       window_draw(e->window);
        window_get_child_allocation(e->window, &rect);
        surface = window_get_surface(e->window);
 
@@ -120,7 +119,6 @@ eventdemo_draw(struct eventdemo *e) {
 
        cairo_destroy(cr);
        cairo_surface_destroy(surface);
-       window_flush(e->window);
 }
 
 /**
@@ -329,7 +327,7 @@ eventdemo_create(struct display *d)
        }
 
        /* Initial drawing of the window */
-       eventdemo_draw(e);
+       window_schedule_redraw(e->window);
 
        return e;
 }
index cac470d..42028f0 100644 (file)
@@ -146,7 +146,7 @@ int main(int argc, char *argv[])
 
        window_set_title(flower.window, "flower");
        window_set_decoration(flower.window, 0);
-       window_draw(flower.window);
+       window_create_surface(flower.window);
        s = window_get_surface(flower.window);
        if (s == NULL || cairo_surface_status (s) != CAIRO_STATUS_SUCCESS) {
                fprintf(stderr, "failed to create cairo egl surface\n");
index bc85f54..b5e7bd4 100644 (file)
@@ -195,13 +195,30 @@ make_gear(const struct gear_template *t)
 }
 
 static void
-draw_gears(struct gears *gears)
+frame_callback(void *data, struct wl_callback *callback, uint32_t time)
+{
+       struct gears *gears = data;
+
+       gears->angle = (GLfloat) (time % 8192) * 360 / 8192.0;
+
+       window_schedule_redraw(gears->window);
+
+       if (callback)
+               wl_callback_destroy(callback);
+}
+
+static const struct wl_callback_listener listener = {
+       frame_callback
+};
+
+static void
+redraw_handler(struct window *window, void *data)
 {
        GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
        struct rectangle window_allocation;
        struct rectangle allocation;
-
-       window_draw(gears->window);
+       struct wl_callback *callback;
+       struct gears *gears = data;
 
        window_get_child_allocation(gears->window, &allocation);
        window_get_allocation(gears->window, &window_allocation);
@@ -254,7 +271,9 @@ draw_gears(struct gears *gears)
        glFlush();
 
        display_release_window_surface(gears->d, gears->window);
-       window_flush(gears->window);
+
+       callback = wl_surface_frame(window_get_wl_surface(gears->window));
+       wl_callback_add_listener(callback, &listener, gears);
 }
 
 static void
@@ -287,25 +306,6 @@ keyboard_focus_handler(struct window *window,
        resize_handler(window, allocation.width, allocation.height, gears);
 }
 
-static void
-frame_callback(void *data, struct wl_callback *callback, uint32_t time)
-{
-       static const struct wl_callback_listener listener = {
-               frame_callback
-       };
-       struct gears *gears = data;
-
-       gears->angle = (GLfloat) (time % 8192) * 360 / 8192.0;
-
-       draw_gears(gears);
-
-       if (callback)
-               wl_callback_destroy(callback);
-
-       callback = wl_surface_frame(window_get_wl_surface(gears->window));
-       wl_callback_add_listener(callback, &listener, gears);
-}
-
 static struct gears *
 gears_create(struct display *display)
 {
@@ -359,6 +359,7 @@ gears_create(struct display *display)
 
        window_set_user_data(gears->window, gears);
        window_set_resize_handler(gears->window, resize_handler);
+       window_set_redraw_handler(gears->window, redraw_handler);
        window_set_keyboard_focus_handler(gears->window, keyboard_focus_handler);
 
        frame_callback(gears, NULL, 0);
index 45990f9..0e34103 100644 (file)
@@ -140,8 +140,6 @@ image_draw(struct image *image)
        cairo_t *cr;
        cairo_surface_t *surface;
 
-       window_draw(image->window);
-
        window_get_child_allocation(image->window, &allocation);
 
        pb = gdk_pixbuf_new_from_file_at_size(image->filename,
@@ -175,7 +173,6 @@ image_draw(struct image *image)
        cairo_paint(cr);
        cairo_destroy(cr);
 
-       window_flush(image->window);
        cairo_surface_destroy(surface);
 }
 
@@ -223,7 +220,7 @@ image_create(struct display *display, const char *filename)
        window_set_keyboard_focus_handler(image->window,
                                          keyboard_focus_handler);
 
-       image_draw(image);
+       window_schedule_redraw(image->window);
 
        return image;
 }
index 8f70d53..395fdcd 100644 (file)
@@ -104,8 +104,6 @@ resizor_draw(struct resizor *resizor)
        cairo_t *cr;
        struct rectangle allocation;
 
-       window_draw(resizor->window);
-
        window_get_child_allocation(resizor->window, &allocation);
 
        surface = window_get_surface(resizor->window);
@@ -122,8 +120,6 @@ resizor_draw(struct resizor *resizor)
        cairo_destroy(cr);
 
        cairo_surface_destroy(surface);
-
-       window_flush(resizor->window);
 }
 
 static void
@@ -236,7 +232,7 @@ resizor_create(struct display *display)
        window_set_child_size(resizor->window, resizor->width, height);
        widget_set_button_handler(resizor->widget, button_handler);
 
-       resizor_draw(resizor);
+       window_schedule_redraw(resizor->window);
 
        return resizor;
 }
index cdb38b4..90cb766 100644 (file)
@@ -121,7 +121,7 @@ homescreen_draw(struct tablet_shell *shell)
        const int rows = 4, columns = 5, icon_width = 128, icon_height = 128;
        int x, y, i, width, height, vmargin, hmargin, vpadding, hpadding;
 
-       window_draw(shell->homescreen);
+       window_create_surface(shell->homescreen);
        window_get_child_allocation(shell->homescreen, &allocation);
        surface = window_get_surface(shell->homescreen);
        cr = cairo_create(surface);
@@ -175,7 +175,7 @@ lockscreen_draw(struct tablet_shell *shell)
        cairo_t *cr;
        int width, height;
 
-       window_draw(shell->lockscreen);
+       window_create_surface(shell->lockscreen);
        window_get_child_allocation(shell->lockscreen, &allocation);
        surface = window_get_surface(shell->lockscreen);
        cr = cairo_create(surface);
index b507ab6..9c3c56b 100644 (file)
@@ -1030,19 +1030,11 @@ resize_handler(struct window *window,
 }
 
 static void
-terminal_draw(struct terminal *terminal)
-{
-       window_draw(terminal->window);
-       terminal_draw_contents(terminal);
-       window_flush(terminal->window);
-}
-
-static void
 redraw_handler(struct window *window, void *data)
 {
        struct terminal *terminal = data;
 
-       terminal_draw(terminal);
+       terminal_draw_contents(terminal);
 }
 
 static void
@@ -2371,7 +2363,7 @@ terminal_run(struct terminal *terminal, const char *path)
        if (!terminal->fullscreen)
                terminal_resize(terminal, 80, 24);
 
-       terminal_draw(terminal);
+       window_schedule_redraw(terminal->window);
 
        return 0;
 }
index 998afb6..5f80721 100644 (file)
@@ -965,8 +965,6 @@ window_draw_decorations(struct window *window)
        cairo_surface_t *frame;
        int width, height, shadow_dx = 3, shadow_dy = 3;
 
-       window_create_surface(window);
-
        width = window->allocation.width;
        height = window->allocation.height;
 
@@ -1134,15 +1132,6 @@ widget_schedule_redraw(struct widget *widget)
        window_schedule_redraw(widget->window);
 }
 
-void
-window_draw(struct window *window)
-{
-       if (!window->decoration)
-               window_create_surface(window);
-       else
-               window_draw_decorations(window);
-}
-
 cairo_surface_t *
 window_get_surface(struct window *window)
 {
@@ -1966,8 +1955,16 @@ idle_redraw(struct task *task, uint32_t events)
        struct window *window =
                container_of(task, struct window, redraw_task);
 
+       window_create_surface(window);
+       if (window->decoration)
+               window_draw_decorations(window);
+
        window->redraw_handler(window, window->user_data);
+
+       window_flush(window);
+
        window->redraw_scheduled = 0;
+
 }
 
 void
@@ -2256,8 +2253,6 @@ menu_redraw_handler(struct window *window, void *data)
        struct menu *menu = data;
        int32_t width, height, i;
 
-       window_create_surface(window);
-
        cr = cairo_create(window->cairo_surface);
        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
@@ -2287,7 +2282,6 @@ menu_redraw_handler(struct window *window, void *data)
        }
 
        cairo_destroy(cr);
-       window_flush(window);
 }
 
 struct window *
index 7a0015a..3ac7313 100644 (file)
@@ -73,8 +73,6 @@ draw_instance(struct ModeInfo *mi)
 
        mi->swap_buffers = 0;
 
-       window_draw(mi->window);
-
        window_get_child_allocation(mi->window, &drawarea);
        window_get_allocation(mi->window, &winarea);
 
@@ -103,7 +101,6 @@ draw_instance(struct ModeInfo *mi)
                fprintf(stderr, "%s: swapBuffers not called\n", progname);
 
        display_release_window_surface(wscr->display, mi->window);
-       window_flush(mi->window);
 }
 
 static void