compositor: Move repaint loop into a backend function
authorKristian Høgsberg <krh@bitplanet.net>
Thu, 26 Jan 2012 04:32:28 +0000 (23:32 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 26 Jan 2012 04:32:28 +0000 (23:32 -0500)
We've trimmed down the actual repaint loop to just iterating through the
surface list and calling weston_surface_draw(), so we push that to the
backend without too much code duplication.

src/compositor-drm.c
src/compositor-openwfd.c
src/compositor-wayland.c
src/compositor-x11.c
src/compositor.c
src/compositor.h

index 1f30e7b..b987a12 100644 (file)
@@ -94,6 +94,19 @@ drm_output_prepare_render(struct weston_output *output_base)
        return 0;
 }
 
+static void
+drm_output_repaint(struct weston_output *output)
+{
+       struct weston_compositor *compositor = output->compositor;
+       struct weston_surface *surface;
+
+       surface = container_of(compositor->surface_list.next,
+                              struct weston_surface, link);
+
+       wl_list_for_each_reverse(surface, &compositor->surface_list, link)
+               weston_surface_draw(surface, output);
+}
+
 static int
 drm_output_present(struct weston_output *output_base)
 {
@@ -554,6 +567,7 @@ create_output_for_connector(struct drm_compositor *ec,
 
        output->pending_fs_surf_fb_id = 0;
        output->base.prepare_render = drm_output_prepare_render;
+       output->base.repaint = drm_output_repaint;
        output->base.present = drm_output_present;
        output->base.prepare_scanout_surface =
                drm_output_prepare_scanout_surface;
index 2299d99..a5bb265 100644 (file)
@@ -101,6 +101,16 @@ wfd_output_prepare_render(struct weston_output *output_base)
        return 0;
 }
 
+static void
+wfd_output_repaint(struct weston_output *output)
+{
+       struct weston_compositor *compositor;
+       struct weston_surface *surface;
+
+       wl_list_for_each_reverse(surface, &compositor->surface_list, link)
+               weston_surface_draw(surface, output);
+}
+
 static int
 wfd_output_present(struct weston_output *output_base)
 {
@@ -407,6 +417,7 @@ create_output_for_port(struct wfd_compositor *ec,
        wfdDeviceCommit(ec->dev, WFD_COMMIT_ENTIRE_DEVICE, WFD_INVALID_HANDLE);
 
        output->base.prepare_render = wfd_output_prepare_render;
+       output->base.repaint = wfd_output_repaint;
        output->base.present = wfd_output_present;
        output->base.prepare_scanout_surface =
                wfd_output_prepare_scanout_surface;
index 4fa9df1..c909253 100644 (file)
@@ -177,6 +177,16 @@ wayland_output_prepare_render(struct weston_output *output_base)
 }
 
 static void
+wayland_output_repaint(struct weston_output *output)
+{
+       struct weston_compositor *compositor = output->compositor;
+       struct weston_surface *surface;
+
+       wl_list_for_each_reverse(surface, &compositor->surface_list, link)
+               weston_surface_draw(surface, output);
+}
+
+static void
 frame_done(void *data, struct wl_callback *wl_callback, uint32_t time)
 {
        struct weston_output *output = data;
@@ -291,6 +301,7 @@ wayland_compositor_create_output(struct wayland_compositor *c,
        glClearColor(0, 0, 0, 0.5);
 
        output->base.prepare_render = wayland_output_prepare_render;
+       output->base.repaint = wayland_output_repaint;
        output->base.present = wayland_output_present;
        output->base.prepare_scanout_surface =
                wayland_output_prepare_scanout_surface;
index 09213f7..771bf69 100644 (file)
@@ -200,6 +200,16 @@ x11_output_prepare_render(struct weston_output *output_base)
        return 0;
 }
 
+static void
+x11_output_repaint(struct weston_output *output)
+{
+       struct weston_compositor *compositor = output->compositor;
+       struct weston_surface *surface;
+
+       wl_list_for_each_reverse(surface, &compositor->surface_list, link)
+               weston_surface_draw(surface, output);
+}
+
 static int
 finish_frame_handler(void *data)
 {
@@ -462,6 +472,7 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
                wl_event_loop_add_timer(loop, finish_frame_handler, output);
 
        output->base.prepare_render = x11_output_prepare_render;
+       output->base.repaint = x11_output_repaint;
        output->base.present = x11_output_present;
        output->base.prepare_scanout_surface =
                x11_output_prepare_scanout_surface;
index 3f178ae..93c76c7 100644 (file)
@@ -555,7 +555,7 @@ texture_transformed_surface(struct weston_surface *es)
        return 1;
 }
 
-static void
+WL_EXPORT void
 weston_surface_draw(struct weston_surface *es, struct weston_output *output)
 {
        struct weston_compositor *ec = es->compositor;
@@ -861,8 +861,7 @@ weston_output_repaint(struct weston_output *output)
                /* We're drawing nothing, just let the damage accumulate */
                return;
 
-       wl_list_for_each_reverse(es, &ec->surface_list, link)
-               weston_surface_draw(es, output);
+       output->repaint(output);
 
        if (ec->fade.spring.current > 0.001)
                solid_surface_release(&solid);
index 973901e..d7eeae7 100644 (file)
@@ -88,6 +88,7 @@ struct weston_output {
        struct wl_listener pending_scanout_buffer_destroy_listener;
 
        int (*prepare_render)(struct weston_output *output);
+       void (*repaint)(struct weston_output *output);
        int (*present)(struct weston_output *output);
        int (*prepare_scanout_surface)(struct weston_output *output,
                                       struct weston_surface *es);
@@ -276,6 +277,8 @@ weston_spring_done(struct weston_spring *spring);
 void
 weston_surface_activate(struct weston_surface *surface,
                        struct weston_input_device *device, uint32_t time);
+void
+weston_surface_draw(struct weston_surface *es, struct weston_output *output);
 
 void
 notify_motion(struct wl_input_device *device,