commit 828f469

Michael Forney  ·  2013-12-20 00:42:28 +0000 UTC
parent 4eb8401
Rename surface_class -> view, move to view.h
12 files changed,  +138, -102
+5, -6
 1@@ -28,7 +28,7 @@ static void calculate_damage(struct swc_compositor * compositor)
 2     /* Go through surfaces top-down to calculate clipping regions. */
 3     wl_list_for_each(surface, &compositor->surfaces, link)
 4     {
 5-        state = surface->class_state;
 6+        state = surface->view_state;
 7 
 8         /* Clip the surface by the opaque region covering it. */
 9         pixman_region32_copy(&state->clip, &compositor->opaque);
10@@ -239,10 +239,10 @@ static void handle_pointer_event(struct wl_listener * listener, void * data)
11     {
12         case SWC_POINTER_CURSOR_CHANGED:
13             if (event_data->old)
14-                swc_surface_set_class(event_data->old, NULL);
15+                swc_surface_set_view(event_data->old, NULL);
16 
17             if (event_data->new)
18-                swc_surface_set_class(event_data->new, &compositor->cursor_class);
19+                swc_surface_set_view(event_data->new, &compositor->cursor_view);
20             break;
21     }
22 }
23@@ -325,9 +325,8 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
24     compositor->pointer_listener.notify = &handle_pointer_event;
25     compositor->scheduled_updates = 0;
26     compositor->pending_flips = 0;
27-    compositor->compositor_class.interface
28-        = &swc_compositor_class_implementation;
29-    compositor->cursor_class.interface = &swc_cursor_class_implementation;
30+    compositor->compositor_view.impl = &swc_compositor_view_impl;
31+    compositor->cursor_view.impl = &swc_cursor_view_impl;
32     compositor->pointer_handler = (struct swc_pointer_handler) {
33         .focus = &handle_focus,
34         .motion = &handle_motion
+3, -2
 1@@ -3,6 +3,7 @@
 2 
 3 #include "pointer.h"
 4 #include "renderer.h"
 5+#include "view.h"
 6 
 7 #include <wayland-server.h>
 8 
 9@@ -30,8 +31,8 @@ struct swc_compositor
10         uint32_t scheduled_updates;
11     };
12 
13-    struct swc_surface_class compositor_class;
14-    struct swc_surface_class cursor_class;
15+    struct swc_view compositor_view;
16+    struct swc_view cursor_view;
17 
18     struct swc_pointer_handler pointer_handler;
19 
+25, -25
  1@@ -35,7 +35,7 @@ static void attach(struct swc_surface * surface, struct wl_resource * resource);
  2 static void update(struct swc_surface * surface);
  3 static void move(struct swc_surface * surface, int32_t x, int32_t y);
  4 
  5-const struct swc_surface_class_interface swc_compositor_class_implementation = {
  6+const struct swc_view_impl swc_compositor_view_impl = {
  7     .add = &add,
  8     .remove = &remove_,
  9     .attach = &attach,
 10@@ -50,8 +50,8 @@ const struct swc_surface_class_interface swc_compositor_class_implementation = {
 11 static void damage_below_surface(struct swc_surface * surface)
 12 {
 13     struct swc_compositor * compositor = CONTAINER_OF
 14-        (surface->class, typeof(*compositor), compositor_class);
 15-    struct swc_compositor_surface_state * state = surface->class_state;
 16+        (surface->view, typeof(*compositor), compositor_view);
 17+    struct swc_compositor_surface_state * state = surface->view_state;
 18     pixman_region32_t damage_below;
 19 
 20     pixman_region32_init_with_extents(&damage_below, &state->extents);
 21@@ -66,7 +66,7 @@ static void damage_below_surface(struct swc_surface * surface)
 22  */
 23 static void damage_surface(struct swc_surface * surface)
 24 {
 25-    struct swc_compositor_surface_state * state = surface->class_state;
 26+    struct swc_compositor_surface_state * state = surface->view_state;
 27     printf("damaging surface\n");
 28 
 29     pixman_region32_fini(&surface->state.damage);
 30@@ -78,7 +78,7 @@ static void damage_surface(struct swc_surface * surface)
 31 
 32 static void update_extents(struct swc_surface * surface)
 33 {
 34-    struct swc_compositor_surface_state * state = surface->class_state;
 35+    struct swc_compositor_surface_state * state = surface->view_state;
 36 
 37     state->extents.x1 = surface->geometry.x - state->border.width;
 38     state->extents.y1 = surface->geometry.y - state->border.width;
 39@@ -94,8 +94,8 @@ static void update_extents(struct swc_surface * surface)
 40 static void update_outputs(struct swc_surface * surface)
 41 {
 42     struct swc_compositor * compositor = CONTAINER_OF
 43-        (surface->class, typeof(*compositor), compositor_class);
 44-    struct swc_compositor_surface_state * state = surface->class_state;
 45+        (surface->view, typeof(*compositor), compositor_view);
 46+    struct swc_compositor_surface_state * state = surface->view_state;
 47     uint32_t old_outputs = surface->outputs, new_outputs = 0,
 48              entered_outputs, left_outputs, changed_outputs;
 49     struct swc_output * output;
 50@@ -159,11 +159,11 @@ static void handle_surface_event(struct wl_listener * listener, void * data)
 51     }
 52 }
 53 
 54-/* Compositor class */
 55+/* Compositor view */
 56 bool add(struct swc_surface * surface)
 57 {
 58     struct swc_compositor * compositor = CONTAINER_OF
 59-        (surface->class, typeof(*compositor), compositor_class);
 60+        (surface->view, typeof(*compositor), compositor_view);
 61     struct swc_compositor_surface_state * state;
 62 
 63     state = malloc(sizeof *state);
 64@@ -186,7 +186,7 @@ bool add(struct swc_surface * surface)
 65 
 66     pixman_region32_init(&state->clip);
 67 
 68-    surface->class_state = state;
 69+    surface->view_state = state;
 70 
 71     return true;
 72 }
 73@@ -194,8 +194,8 @@ bool add(struct swc_surface * surface)
 74 void remove_(struct swc_surface * surface)
 75 {
 76     struct swc_compositor * compositor = CONTAINER_OF
 77-        (surface->class, typeof(*compositor), compositor_class);
 78-    struct swc_compositor_surface_state * state = surface->class_state;
 79+        (surface->view, typeof(*compositor), compositor_view);
 80+    struct swc_compositor_surface_state * state = surface->view_state;
 81 
 82     swc_compositor_surface_hide(surface);
 83 
 84@@ -208,7 +208,7 @@ void remove_(struct swc_surface * surface)
 85 void attach(struct swc_surface * surface, struct wl_resource * resource)
 86 {
 87     struct swc_compositor * compositor = CONTAINER_OF
 88-        (surface->class, typeof(*compositor), compositor_class);
 89+        (surface->view, typeof(*compositor), compositor_view);
 90 
 91     swc_renderer_attach(&compositor->renderer, surface, resource);
 92 }
 93@@ -216,8 +216,8 @@ void attach(struct swc_surface * surface, struct wl_resource * resource)
 94 void update(struct swc_surface * surface)
 95 {
 96     struct swc_compositor * compositor = CONTAINER_OF
 97-        (surface->class, typeof(*compositor), compositor_class);
 98-    struct swc_compositor_surface_state * state = surface->class_state;
 99+        (surface->view, typeof(*compositor), compositor_view);
100+    struct swc_compositor_surface_state * state = surface->view_state;
101     struct swc_output * output;
102 
103     if (!state->mapped)
104@@ -233,8 +233,8 @@ void update(struct swc_surface * surface)
105 void move(struct swc_surface * surface, int32_t x, int32_t y)
106 {
107     struct swc_compositor * compositor = CONTAINER_OF
108-        (surface->class, typeof(*compositor), compositor_class);
109-    struct swc_compositor_surface_state * state = surface->class_state;
110+        (surface->view, typeof(*compositor), compositor_view);
111+    struct swc_compositor_surface_state * state = surface->view_state;
112 
113     if (x == surface->geometry.x && y == surface->geometry.y)
114         return;
115@@ -263,10 +263,10 @@ void move(struct swc_surface * surface, int32_t x, int32_t y)
116 void swc_compositor_surface_show(struct swc_surface * surface)
117 {
118     struct swc_compositor * compositor = CONTAINER_OF
119-        (surface->class, typeof(*compositor), compositor_class);
120-    struct swc_compositor_surface_state * state = surface->class_state;
121+        (surface->view, typeof(*compositor), compositor_view);
122+    struct swc_compositor_surface_state * state = surface->view_state;
123 
124-    if (surface->class->interface != &swc_compositor_class_implementation)
125+    if (surface->view->impl != &swc_compositor_view_impl)
126         return;
127 
128     if (state->mapped)
129@@ -289,10 +289,10 @@ void swc_compositor_surface_show(struct swc_surface * surface)
130 void swc_compositor_surface_hide(struct swc_surface * surface)
131 {
132     struct swc_compositor * compositor = CONTAINER_OF
133-        (surface->class, typeof(*compositor), compositor_class);
134-    struct swc_compositor_surface_state * state = surface->class_state;
135+        (surface->view, typeof(*compositor), compositor_view);
136+    struct swc_compositor_surface_state * state = surface->view_state;
137 
138-    if (surface->class->interface != &swc_compositor_class_implementation)
139+    if (surface->view->impl != &swc_compositor_view_impl)
140         return;
141 
142     if (!state->mapped)
143@@ -311,7 +311,7 @@ void swc_compositor_surface_hide(struct swc_surface * surface)
144 void swc_compositor_surface_set_border_width(struct swc_surface * surface,
145                                              uint32_t width)
146 {
147-    struct swc_compositor_surface_state * state = surface->class_state;
148+    struct swc_compositor_surface_state * state = surface->view_state;
149 
150     if (state->border.width == width)
151         return;
152@@ -328,7 +328,7 @@ void swc_compositor_surface_set_border_width(struct swc_surface * surface,
153 void swc_compositor_surface_set_border_color(struct swc_surface * surface,
154                                              uint32_t color)
155 {
156-    struct swc_compositor_surface_state * state = surface->class_state;
157+    struct swc_compositor_surface_state * state = surface->view_state;
158 
159     if (state->border.color == color)
160         return;
+4, -3
 1@@ -24,11 +24,13 @@
 2 #ifndef SWC_COMPOSITOR_SURFACE_H
 3 #define SWC_COMPOSITOR_SURFACE_H
 4 
 5-#include "surface.h"
 6+#include "view.h"
 7 
 8 #include <wayland-server.h>
 9 #include <pixman.h>
10 
11+struct swc_surface;
12+
13 struct swc_compositor_surface_state
14 {
15     struct swc_compositor * compositor;
16@@ -52,8 +54,7 @@ struct swc_compositor_surface_state
17     struct wl_listener event_listener;
18 };
19 
20-extern const struct swc_surface_class_interface
21-    swc_compositor_class_implementation;
22+extern const struct swc_view_impl swc_compositor_view_impl;
23 
24 void swc_compositor_surface_show(struct swc_surface * surface);
25 
+4, -4
 1@@ -27,7 +27,7 @@
 2 #include <string.h>
 3 #include <wld/wld.h>
 4 
 5-/* Cursor class */
 6+/* Cursor view */
 7 static const uint32_t cursor_buffer_size = 64 * 64 * 4;
 8 
 9 static void update_plane(struct swc_plane * plane, void * data)
10@@ -42,7 +42,7 @@ static void attach(struct swc_surface * surface,
11                    struct wl_resource * resource)
12 {
13     struct swc_compositor * compositor = CONTAINER_OF
14-        (surface->class, typeof(*compositor), cursor_class);
15+        (surface->view, typeof(*compositor), cursor_view);
16 
17     if (pixman_region32_not_empty(&surface->state.damage))
18     {
19@@ -87,7 +87,7 @@ static void update(struct swc_surface * surface)
20 static void move(struct swc_surface * surface, int32_t x, int32_t y)
21 {
22     struct swc_compositor * compositor = CONTAINER_OF
23-        (surface->class, typeof(*compositor), cursor_class);
24+        (surface->view, typeof(*compositor), cursor_view);
25     struct swc_output * output;
26 
27     surface->geometry.x = x;
28@@ -104,7 +104,7 @@ static void move(struct swc_surface * surface, int32_t x, int32_t y)
29     }
30 }
31 
32-const struct swc_surface_class_interface swc_cursor_class_implementation = {
33+const struct swc_view_impl swc_cursor_view_impl = {
34     .attach = &attach,
35     .update = &update,
36     .move = &move
+2, -3
 1@@ -24,10 +24,9 @@
 2 #ifndef SWC_CURSOR_SURFACE_H
 3 #define SWC_CURSOR_SURFACE_H
 4 
 5-#include "surface.h"
 6+#include "view.h"
 7 
 8-extern const struct swc_surface_class_interface
 9-    swc_cursor_class_implementation;
10+extern const struct swc_view_impl swc_cursor_view_impl;
11 
12 #endif
13 
+1, -1
1@@ -76,7 +76,7 @@ static void repaint_surface(struct swc_renderer * renderer,
2     pixman_region32_t border_damage;
3     pixman_region32_t surface_region;
4     struct buffer_state * state;
5-    struct swc_compositor_surface_state * surface_state = surface->class_state;
6+    struct swc_compositor_surface_state * surface_state = surface->view_state;
7 
8     if (!surface->state.buffer)
9         return;
+1, -0
1@@ -24,6 +24,7 @@
2 #include "swc.h"
3 #include "compositor_surface.h"
4 #include "shell_surface.h"
5+#include "surface.h"
6 #include "util.h"
7 #include "window.h"
8 
+24, -23
  1@@ -26,6 +26,7 @@
  2 #include "event.h"
  3 #include "region.h"
  4 #include "util.h"
  5+#include "view.h"
  6 
  7 #include <stdlib.h>
  8 #include <stdio.h>
  9@@ -300,11 +301,11 @@ static void commit(struct wl_client * client, struct wl_resource * resource)
 10         wl_list_init(&surface->pending.state.frame_callbacks);
 11     }
 12 
 13-    if (surface->class)
 14+    if (surface->view)
 15     {
 16         if (surface->pending.commit & SWC_SURFACE_COMMIT_ATTACH)
 17-            surface->class->interface->attach(surface, surface->state.buffer);
 18-        surface->class->interface->update(surface);
 19+            surface->view->impl->attach(surface, surface->state.buffer);
 20+        surface->view->impl->update(surface);
 21     }
 22 
 23     surface->pending.commit = 0;
 24@@ -338,8 +339,8 @@ static void surface_destroy(struct wl_resource * resource)
 25 {
 26     struct swc_surface * surface = wl_resource_get_user_data(resource);
 27 
 28-    if (surface->class && surface->class->interface->remove)
 29-        surface->class->interface->remove(surface);
 30+    if (surface->view && surface->view->impl->remove)
 31+        surface->view->impl->remove(surface);
 32 
 33     /* Finish the surface. */
 34     state_finish(&surface->state);
 35@@ -374,8 +375,8 @@ struct swc_surface * swc_surface_new(struct wl_client * client,
 36     surface->geometry.height = 0;
 37     surface->pending.commit = 0;
 38     surface->window = NULL;
 39-    surface->class = NULL;
 40-    surface->class_state = NULL;
 41+    surface->view = NULL;
 42+    surface->view_state = NULL;
 43 
 44     state_initialize(&surface->state, true);
 45     state_initialize(&surface->pending.state, false);
 46@@ -405,41 +406,41 @@ void swc_surface_send_frame_callbacks(struct swc_surface * surface,
 47     wl_list_init(&surface->state.frame_callbacks);
 48 }
 49 
 50-void swc_surface_set_class(struct swc_surface * surface,
 51-                           const struct swc_surface_class * class)
 52+void swc_surface_set_view(struct swc_surface * surface,
 53+                          const struct swc_view * view)
 54 {
 55-    if (surface->class == class)
 56+    if (surface->view == view)
 57         return;
 58 
 59-    if (surface->class && surface->class->interface->remove)
 60-        surface->class->interface->remove(surface);
 61+    if (surface->view && surface->view->impl->remove)
 62+        surface->view->impl->remove(surface);
 63 
 64-    surface->class = class;
 65+    surface->view = view;
 66 
 67-    if (surface->class)
 68+    if (surface->view)
 69     {
 70-        if (surface->class->interface->add
 71-            && !surface->class->interface->add(surface))
 72+        if (surface->view->impl->add
 73+            && !surface->view->impl->add(surface))
 74         {
 75-            surface->class = NULL;
 76+            surface->view = NULL;
 77             return;
 78         }
 79 
 80 
 81-        surface->class->interface->attach(surface, surface->state.buffer);
 82-        surface->class->interface->update(surface);
 83+        surface->view->impl->attach(surface, surface->state.buffer);
 84+        surface->view->impl->update(surface);
 85     }
 86 }
 87 
 88 void swc_surface_update(struct swc_surface * surface)
 89 {
 90-    if (surface->class)
 91-        surface->class->interface->update(surface);
 92+    if (surface->view)
 93+        surface->view->impl->update(surface);
 94 }
 95 
 96 void swc_surface_move(struct swc_surface * surface, int32_t x, int32_t y)
 97 {
 98-    if (surface->class)
 99-        surface->class->interface->move(surface, x, y);
100+    if (surface->view)
101+        surface->view->impl->move(surface, x, y);
102 }
103 
+4, -33
 1@@ -71,35 +71,6 @@ struct swc_surface_state
 2     struct wl_list frame_callbacks;
 3 };
 4 
 5-/**
 6- * A surface class is a set of operations that can be performed on a surface.
 7- * This gives the compositor the ability to classify surfaces, treating some
 8- * specially (for example, a cursor surface).
 9- */
10-struct swc_surface_class_interface
11-{
12-    /* Called when a surface is added to the class. */
13-    bool (* add)(struct swc_surface * surface);
14-
15-    /* Called when a surface is removed from the class. */
16-    void (* remove)(struct swc_surface * surface);
17-
18-    /* Called when a new buffer is attached to a surface. */
19-    void (* attach)(struct swc_surface * surface,
20-                    struct wl_resource * resource);
21-
22-    /* Called after a surface requests a commit. */
23-    void (* update)(struct swc_surface * surface);
24-
25-    /* Moves the surface to the specified coordinates. */
26-    void (* move)(struct swc_surface * surface, int32_t x, int32_t y);
27-};
28-
29-struct swc_surface_class
30-{
31-    const struct swc_surface_class_interface * interface;
32-};
33-
34 struct swc_surface
35 {
36     struct wl_resource * resource;
37@@ -114,8 +85,8 @@ struct swc_surface
38     } pending;
39 
40     struct swc_window * window;
41-    const struct swc_surface_class * class;
42-    void * class_state;
43+    const struct swc_view * view;
44+    void * view_state;
45 
46     uint32_t outputs;
47     pixman_rectangle32_t geometry;
48@@ -129,8 +100,8 @@ struct swc_surface * swc_surface_new(struct wl_client * client,
49 
50 void swc_surface_send_frame_callbacks(struct swc_surface * surface,
51                                       uint32_t time);
52-void swc_surface_set_class(struct swc_surface * surface,
53-                           const struct swc_surface_class * class);
54+void swc_surface_set_view(struct swc_surface * surface,
55+                          const struct swc_view * view);
56 
57 void swc_surface_update(struct swc_surface * surface);
58 
+63, -0
 1@@ -0,0 +1,63 @@
 2+/* swc: libswc/view.h
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_VIEW_H
26+#define SWC_VIEW_H
27+
28+#include <stdbool.h>
29+#include <stdint.h>
30+
31+struct swc_surface;
32+struct wl_resource;
33+
34+struct swc_view
35+{
36+    const struct swc_view_impl * impl;
37+};
38+
39+/**
40+ * A view is a set of operations that can be performed on a surface.  This
41+ * gives the compositor the ability to classify surfaces, treating some
42+ * specially (for example, a cursor surface).
43+ */
44+struct swc_view_impl
45+{
46+    /* Called when a surface is added to the view. */
47+    bool (* add)(struct swc_surface * surface);
48+
49+    /* Called when a surface is removed from the view. */
50+    void (* remove)(struct swc_surface * surface);
51+
52+    /* Called when a new buffer is attached to a surface. */
53+    void (* attach)(struct swc_surface * surface,
54+                    struct wl_resource * resource);
55+
56+    /* Called after a surface requests a commit. */
57+    void (* update)(struct swc_surface * surface);
58+
59+    /* Moves the surface to the specified coordinates. */
60+    void (* move)(struct swc_surface * surface, int32_t x, int32_t y);
61+};
62+
63+#endif
64+
+2, -2
 1@@ -124,7 +124,7 @@ bool swc_window_initialize(struct swc_window * window,
 2     INTERNAL(window)->impl = impl;
 3 
 4     surface->window = window;
 5-    swc_surface_set_class(surface, &swc.compositor->compositor_class);
 6+    swc_surface_set_view(surface, &swc.compositor->compositor_view);
 7 
 8     swc.manager->new_window(window);
 9 
10@@ -136,7 +136,7 @@ void swc_window_finalize(struct swc_window * window)
11     DEBUG("Finalizing window, %p\n", window);
12 
13     swc_send_event(&window->event_signal, SWC_WINDOW_DESTROYED, NULL);
14-    swc_surface_set_class(INTERNAL(window)->surface, NULL);
15+    swc_surface_set_view(INTERNAL(window)->surface, NULL);
16     INTERNAL(window)->surface->window = NULL;
17 }
18