commit 6797a55

Michael Forney  ·  2014-01-16 23:15:28 +0000 UTC
parent b7805fb
view: Add event signal and frame events
5 files changed,  +73, -29
+1, -1
1@@ -646,7 +646,7 @@ static void handle_drm_event(struct wl_listener * listener, void * data)
2             if (compositor->pending_flips == 0)
3             {
4                 wl_list_for_each(surface, &compositor->surfaces, link)
5-                    swc_surface_send_frame_callbacks(surface, event_data->time);
6+                    swc_view_frame(surface->view, event_data->time);
7             }
8 
9             /* If we had scheduled updates that couldn't run because we were
+36, -19
 1@@ -339,6 +339,32 @@ static void surface_destroy(struct wl_resource * resource)
 2     free(surface);
 3 }
 4 
 5+static void handle_view_event(struct wl_listener * listener, void * data)
 6+{
 7+    struct swc_surface * surface
 8+        = CONTAINER_OF(listener, typeof(*surface), view_listener);
 9+    struct swc_event * event = data;
10+    struct swc_view_event_data * event_data = event->data;
11+
12+    switch (event->type)
13+    {
14+        case SWC_VIEW_EVENT_FRAME:
15+        {
16+            struct wl_resource * resource, * tmp;
17+
18+            wl_list_for_each_safe(resource, tmp,
19+                                  &surface->state.frame_callbacks, link)
20+            {
21+                wl_callback_send_done(resource, event_data->frame.time);
22+                wl_resource_destroy(resource);
23+            }
24+
25+            wl_list_init(&surface->state.frame_callbacks);
26+            break;
27+        }
28+    }
29+}
30+
31 /**
32  * Construct a new surface, adding it to the given client as id.
33  *
34@@ -365,6 +391,7 @@ struct swc_surface * swc_surface_new(struct wl_client * client,
35     surface->pending.commit = 0;
36     surface->window = NULL;
37     surface->view = NULL;
38+    surface->view_listener.notify = &handle_view_event;
39     surface->view_state = NULL;
40 
41     state_initialize(&surface->state, true);
42@@ -381,33 +408,23 @@ struct swc_surface * swc_surface_new(struct wl_client * client,
43     return surface;
44 }
45 
46-void swc_surface_send_frame_callbacks(struct swc_surface * surface,
47-                                      uint32_t time)
48-{
49-    struct wl_resource * resource, * tmp;
50-
51-    wl_list_for_each_safe(resource, tmp, &surface->state.frame_callbacks, link)
52-    {
53-        wl_callback_send_done(resource, time);
54-        wl_resource_destroy(resource);
55-    }
56-
57-    wl_list_init(&surface->state.frame_callbacks);
58-}
59-
60-void swc_surface_set_view(struct swc_surface * surface,
61-                          const struct swc_view * view)
62+void swc_surface_set_view(struct swc_surface * surface, struct swc_view * view)
63 {
64     if (surface->view == view)
65         return;
66 
67-    if (surface->view && surface->view->impl->remove)
68-        surface->view->impl->remove(surface);
69+    if (surface->view)
70+    {
71+        if (surface->view->impl->remove)
72+            surface->view->impl->remove(surface);
73+        wl_list_remove(&surface->view_listener.link);
74+    }
75 
76     surface->view = view;
77 
78-    if (surface->view)
79+    if (view)
80     {
81+        wl_signal_add(&view->event_signal, &surface->view_listener);
82         surface->view->impl->attach(surface, surface->state.buffer);
83         surface->view->impl->update(surface);
84     }
+3, -5
 1@@ -85,7 +85,8 @@ struct swc_surface
 2     } pending;
 3 
 4     struct swc_window * window;
 5-    const struct swc_view * view;
 6+    struct swc_view * view;
 7+    struct wl_listener view_listener;
 8     void * view_state;
 9 
10     uint32_t outputs;
11@@ -98,10 +99,7 @@ struct swc_surface
12 struct swc_surface * swc_surface_new(struct wl_client * client,
13                                      uint32_t version, uint32_t id);
14 
15-void swc_surface_send_frame_callbacks(struct swc_surface * surface,
16-                                      uint32_t time);
17-void swc_surface_set_view(struct swc_surface * surface,
18-                          const struct swc_view * view);
19+void swc_surface_set_view(struct swc_surface * surface, struct swc_view * view);
20 
21 void swc_surface_update(struct swc_surface * surface);
22 
+9, -0
 1@@ -22,14 +22,23 @@
 2  */
 3 
 4 #include "view.h"
 5+#include "event.h"
 6 
 7 void swc_view_initialize(struct swc_view * view,
 8                          const struct swc_view_impl * impl)
 9 {
10     view->impl = impl;
11+    wl_signal_init(&view->event_signal);
12 }
13 
14 void swc_view_finalize(struct swc_view * view)
15 {
16 }
17 
18+void swc_view_frame(struct swc_view * view, uint32_t time)
19+{
20+    struct swc_view_event_data data = { .view = view, .frame = { time } };
21+
22+    swc_send_event(&view->event_signal, SWC_VIEW_EVENT_FRAME, &data);
23+}
24+
+24, -4
 1@@ -24,16 +24,34 @@
 2 #ifndef SWC_VIEW_H
 3 #define SWC_VIEW_H
 4 
 5-#include <stdbool.h>
 6-#include <stdint.h>
 7+#include "swc.h"
 8 
 9-struct swc_buffer;
10 struct swc_surface;
11-struct wl_resource;
12+struct swc_buffer;
13+
14+enum swc_view_event
15+{
16+    /* Sent when the view has displayed the next frame. */
17+    SWC_VIEW_EVENT_FRAME,
18+};
19+
20+struct swc_view_event_data
21+{
22+    struct swc_view * view;
23+    union
24+    {
25+        struct
26+        {
27+            uint32_t time;
28+        } frame;
29+    };
30+};
31 
32 struct swc_view
33 {
34     const struct swc_view_impl * impl;
35+
36+    struct wl_signal event_signal;
37 };
38 
39 /**
40@@ -61,5 +79,7 @@ void swc_view_initialize(struct swc_view * view,
41 
42 void swc_view_finalize(struct swc_view * view);
43 
44+void swc_view_frame(struct swc_view * view, uint32_t time);
45+
46 #endif
47