commit 828f46972c67c25b6feab657b01e13927b12f59f
parent 4eb84015e0862ccbc6482ef78b4dfd082a811a1c
Author: Michael Forney <mforney@mforney.org>
Date: Thu, 19 Dec 2013 16:42:28 -0800
Rename surface_class -> view, move to view.h
Diffstat:
12 files changed, 138 insertions(+), 102 deletions(-)
diff --git a/libswc/compositor.c b/libswc/compositor.c
@@ -28,7 +28,7 @@ static void calculate_damage(struct swc_compositor * compositor)
/* Go through surfaces top-down to calculate clipping regions. */
wl_list_for_each(surface, &compositor->surfaces, link)
{
- state = surface->class_state;
+ state = surface->view_state;
/* Clip the surface by the opaque region covering it. */
pixman_region32_copy(&state->clip, &compositor->opaque);
@@ -239,10 +239,10 @@ static void handle_pointer_event(struct wl_listener * listener, void * data)
{
case SWC_POINTER_CURSOR_CHANGED:
if (event_data->old)
- swc_surface_set_class(event_data->old, NULL);
+ swc_surface_set_view(event_data->old, NULL);
if (event_data->new)
- swc_surface_set_class(event_data->new, &compositor->cursor_class);
+ swc_surface_set_view(event_data->new, &compositor->cursor_view);
break;
}
}
@@ -325,9 +325,8 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
compositor->pointer_listener.notify = &handle_pointer_event;
compositor->scheduled_updates = 0;
compositor->pending_flips = 0;
- compositor->compositor_class.interface
- = &swc_compositor_class_implementation;
- compositor->cursor_class.interface = &swc_cursor_class_implementation;
+ compositor->compositor_view.impl = &swc_compositor_view_impl;
+ compositor->cursor_view.impl = &swc_cursor_view_impl;
compositor->pointer_handler = (struct swc_pointer_handler) {
.focus = &handle_focus,
.motion = &handle_motion
diff --git a/libswc/compositor.h b/libswc/compositor.h
@@ -3,6 +3,7 @@
#include "pointer.h"
#include "renderer.h"
+#include "view.h"
#include <wayland-server.h>
@@ -30,8 +31,8 @@ struct swc_compositor
uint32_t scheduled_updates;
};
- struct swc_surface_class compositor_class;
- struct swc_surface_class cursor_class;
+ struct swc_view compositor_view;
+ struct swc_view cursor_view;
struct swc_pointer_handler pointer_handler;
diff --git a/libswc/compositor_surface.c b/libswc/compositor_surface.c
@@ -35,7 +35,7 @@ static void attach(struct swc_surface * surface, struct wl_resource * resource);
static void update(struct swc_surface * surface);
static void move(struct swc_surface * surface, int32_t x, int32_t y);
-const struct swc_surface_class_interface swc_compositor_class_implementation = {
+const struct swc_view_impl swc_compositor_view_impl = {
.add = &add,
.remove = &remove_,
.attach = &attach,
@@ -50,8 +50,8 @@ const struct swc_surface_class_interface swc_compositor_class_implementation = {
static void damage_below_surface(struct swc_surface * surface)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
- struct swc_compositor_surface_state * state = surface->class_state;
+ (surface->view, typeof(*compositor), compositor_view);
+ struct swc_compositor_surface_state * state = surface->view_state;
pixman_region32_t damage_below;
pixman_region32_init_with_extents(&damage_below, &state->extents);
@@ -66,7 +66,7 @@ static void damage_below_surface(struct swc_surface * surface)
*/
static void damage_surface(struct swc_surface * surface)
{
- struct swc_compositor_surface_state * state = surface->class_state;
+ struct swc_compositor_surface_state * state = surface->view_state;
printf("damaging surface\n");
pixman_region32_fini(&surface->state.damage);
@@ -78,7 +78,7 @@ static void damage_surface(struct swc_surface * surface)
static void update_extents(struct swc_surface * surface)
{
- struct swc_compositor_surface_state * state = surface->class_state;
+ struct swc_compositor_surface_state * state = surface->view_state;
state->extents.x1 = surface->geometry.x - state->border.width;
state->extents.y1 = surface->geometry.y - state->border.width;
@@ -94,8 +94,8 @@ static void update_extents(struct swc_surface * surface)
static void update_outputs(struct swc_surface * surface)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
- struct swc_compositor_surface_state * state = surface->class_state;
+ (surface->view, typeof(*compositor), compositor_view);
+ struct swc_compositor_surface_state * state = surface->view_state;
uint32_t old_outputs = surface->outputs, new_outputs = 0,
entered_outputs, left_outputs, changed_outputs;
struct swc_output * output;
@@ -159,11 +159,11 @@ static void handle_surface_event(struct wl_listener * listener, void * data)
}
}
-/* Compositor class */
+/* Compositor view */
bool add(struct swc_surface * surface)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
+ (surface->view, typeof(*compositor), compositor_view);
struct swc_compositor_surface_state * state;
state = malloc(sizeof *state);
@@ -186,7 +186,7 @@ bool add(struct swc_surface * surface)
pixman_region32_init(&state->clip);
- surface->class_state = state;
+ surface->view_state = state;
return true;
}
@@ -194,8 +194,8 @@ bool add(struct swc_surface * surface)
void remove_(struct swc_surface * surface)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
- struct swc_compositor_surface_state * state = surface->class_state;
+ (surface->view, typeof(*compositor), compositor_view);
+ struct swc_compositor_surface_state * state = surface->view_state;
swc_compositor_surface_hide(surface);
@@ -208,7 +208,7 @@ void remove_(struct swc_surface * surface)
void attach(struct swc_surface * surface, struct wl_resource * resource)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
+ (surface->view, typeof(*compositor), compositor_view);
swc_renderer_attach(&compositor->renderer, surface, resource);
}
@@ -216,8 +216,8 @@ void attach(struct swc_surface * surface, struct wl_resource * resource)
void update(struct swc_surface * surface)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
- struct swc_compositor_surface_state * state = surface->class_state;
+ (surface->view, typeof(*compositor), compositor_view);
+ struct swc_compositor_surface_state * state = surface->view_state;
struct swc_output * output;
if (!state->mapped)
@@ -233,8 +233,8 @@ void update(struct swc_surface * surface)
void move(struct swc_surface * surface, int32_t x, int32_t y)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
- struct swc_compositor_surface_state * state = surface->class_state;
+ (surface->view, typeof(*compositor), compositor_view);
+ struct swc_compositor_surface_state * state = surface->view_state;
if (x == surface->geometry.x && y == surface->geometry.y)
return;
@@ -263,10 +263,10 @@ void move(struct swc_surface * surface, int32_t x, int32_t y)
void swc_compositor_surface_show(struct swc_surface * surface)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
- struct swc_compositor_surface_state * state = surface->class_state;
+ (surface->view, typeof(*compositor), compositor_view);
+ struct swc_compositor_surface_state * state = surface->view_state;
- if (surface->class->interface != &swc_compositor_class_implementation)
+ if (surface->view->impl != &swc_compositor_view_impl)
return;
if (state->mapped)
@@ -289,10 +289,10 @@ void swc_compositor_surface_show(struct swc_surface * surface)
void swc_compositor_surface_hide(struct swc_surface * surface)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), compositor_class);
- struct swc_compositor_surface_state * state = surface->class_state;
+ (surface->view, typeof(*compositor), compositor_view);
+ struct swc_compositor_surface_state * state = surface->view_state;
- if (surface->class->interface != &swc_compositor_class_implementation)
+ if (surface->view->impl != &swc_compositor_view_impl)
return;
if (!state->mapped)
@@ -311,7 +311,7 @@ void swc_compositor_surface_hide(struct swc_surface * surface)
void swc_compositor_surface_set_border_width(struct swc_surface * surface,
uint32_t width)
{
- struct swc_compositor_surface_state * state = surface->class_state;
+ struct swc_compositor_surface_state * state = surface->view_state;
if (state->border.width == width)
return;
@@ -328,7 +328,7 @@ void swc_compositor_surface_set_border_width(struct swc_surface * surface,
void swc_compositor_surface_set_border_color(struct swc_surface * surface,
uint32_t color)
{
- struct swc_compositor_surface_state * state = surface->class_state;
+ struct swc_compositor_surface_state * state = surface->view_state;
if (state->border.color == color)
return;
diff --git a/libswc/compositor_surface.h b/libswc/compositor_surface.h
@@ -24,11 +24,13 @@
#ifndef SWC_COMPOSITOR_SURFACE_H
#define SWC_COMPOSITOR_SURFACE_H
-#include "surface.h"
+#include "view.h"
#include <wayland-server.h>
#include <pixman.h>
+struct swc_surface;
+
struct swc_compositor_surface_state
{
struct swc_compositor * compositor;
@@ -52,8 +54,7 @@ struct swc_compositor_surface_state
struct wl_listener event_listener;
};
-extern const struct swc_surface_class_interface
- swc_compositor_class_implementation;
+extern const struct swc_view_impl swc_compositor_view_impl;
void swc_compositor_surface_show(struct swc_surface * surface);
diff --git a/libswc/cursor_surface.c b/libswc/cursor_surface.c
@@ -27,7 +27,7 @@
#include <string.h>
#include <wld/wld.h>
-/* Cursor class */
+/* Cursor view */
static const uint32_t cursor_buffer_size = 64 * 64 * 4;
static void update_plane(struct swc_plane * plane, void * data)
@@ -42,7 +42,7 @@ static void attach(struct swc_surface * surface,
struct wl_resource * resource)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), cursor_class);
+ (surface->view, typeof(*compositor), cursor_view);
if (pixman_region32_not_empty(&surface->state.damage))
{
@@ -87,7 +87,7 @@ static void update(struct swc_surface * surface)
static void move(struct swc_surface * surface, int32_t x, int32_t y)
{
struct swc_compositor * compositor = CONTAINER_OF
- (surface->class, typeof(*compositor), cursor_class);
+ (surface->view, typeof(*compositor), cursor_view);
struct swc_output * output;
surface->geometry.x = x;
@@ -104,7 +104,7 @@ static void move(struct swc_surface * surface, int32_t x, int32_t y)
}
}
-const struct swc_surface_class_interface swc_cursor_class_implementation = {
+const struct swc_view_impl swc_cursor_view_impl = {
.attach = &attach,
.update = &update,
.move = &move
diff --git a/libswc/cursor_surface.h b/libswc/cursor_surface.h
@@ -24,10 +24,9 @@
#ifndef SWC_CURSOR_SURFACE_H
#define SWC_CURSOR_SURFACE_H
-#include "surface.h"
+#include "view.h"
-extern const struct swc_surface_class_interface
- swc_cursor_class_implementation;
+extern const struct swc_view_impl swc_cursor_view_impl;
#endif
diff --git a/libswc/renderer.c b/libswc/renderer.c
@@ -76,7 +76,7 @@ static void repaint_surface(struct swc_renderer * renderer,
pixman_region32_t border_damage;
pixman_region32_t surface_region;
struct buffer_state * state;
- struct swc_compositor_surface_state * surface_state = surface->class_state;
+ struct swc_compositor_surface_state * surface_state = surface->view_state;
if (!surface->state.buffer)
return;
diff --git a/libswc/shell_surface.c b/libswc/shell_surface.c
@@ -24,6 +24,7 @@
#include "swc.h"
#include "compositor_surface.h"
#include "shell_surface.h"
+#include "surface.h"
#include "util.h"
#include "window.h"
diff --git a/libswc/surface.c b/libswc/surface.c
@@ -26,6 +26,7 @@
#include "event.h"
#include "region.h"
#include "util.h"
+#include "view.h"
#include <stdlib.h>
#include <stdio.h>
@@ -300,11 +301,11 @@ static void commit(struct wl_client * client, struct wl_resource * resource)
wl_list_init(&surface->pending.state.frame_callbacks);
}
- if (surface->class)
+ if (surface->view)
{
if (surface->pending.commit & SWC_SURFACE_COMMIT_ATTACH)
- surface->class->interface->attach(surface, surface->state.buffer);
- surface->class->interface->update(surface);
+ surface->view->impl->attach(surface, surface->state.buffer);
+ surface->view->impl->update(surface);
}
surface->pending.commit = 0;
@@ -338,8 +339,8 @@ static void surface_destroy(struct wl_resource * resource)
{
struct swc_surface * surface = wl_resource_get_user_data(resource);
- if (surface->class && surface->class->interface->remove)
- surface->class->interface->remove(surface);
+ if (surface->view && surface->view->impl->remove)
+ surface->view->impl->remove(surface);
/* Finish the surface. */
state_finish(&surface->state);
@@ -374,8 +375,8 @@ struct swc_surface * swc_surface_new(struct wl_client * client,
surface->geometry.height = 0;
surface->pending.commit = 0;
surface->window = NULL;
- surface->class = NULL;
- surface->class_state = NULL;
+ surface->view = NULL;
+ surface->view_state = NULL;
state_initialize(&surface->state, true);
state_initialize(&surface->pending.state, false);
@@ -405,41 +406,41 @@ void swc_surface_send_frame_callbacks(struct swc_surface * surface,
wl_list_init(&surface->state.frame_callbacks);
}
-void swc_surface_set_class(struct swc_surface * surface,
- const struct swc_surface_class * class)
+void swc_surface_set_view(struct swc_surface * surface,
+ const struct swc_view * view)
{
- if (surface->class == class)
+ if (surface->view == view)
return;
- if (surface->class && surface->class->interface->remove)
- surface->class->interface->remove(surface);
+ if (surface->view && surface->view->impl->remove)
+ surface->view->impl->remove(surface);
- surface->class = class;
+ surface->view = view;
- if (surface->class)
+ if (surface->view)
{
- if (surface->class->interface->add
- && !surface->class->interface->add(surface))
+ if (surface->view->impl->add
+ && !surface->view->impl->add(surface))
{
- surface->class = NULL;
+ surface->view = NULL;
return;
}
- surface->class->interface->attach(surface, surface->state.buffer);
- surface->class->interface->update(surface);
+ surface->view->impl->attach(surface, surface->state.buffer);
+ surface->view->impl->update(surface);
}
}
void swc_surface_update(struct swc_surface * surface)
{
- if (surface->class)
- surface->class->interface->update(surface);
+ if (surface->view)
+ surface->view->impl->update(surface);
}
void swc_surface_move(struct swc_surface * surface, int32_t x, int32_t y)
{
- if (surface->class)
- surface->class->interface->move(surface, x, y);
+ if (surface->view)
+ surface->view->impl->move(surface, x, y);
}
diff --git a/libswc/surface.h b/libswc/surface.h
@@ -71,35 +71,6 @@ struct swc_surface_state
struct wl_list frame_callbacks;
};
-/**
- * A surface class is a set of operations that can be performed on a surface.
- * This gives the compositor the ability to classify surfaces, treating some
- * specially (for example, a cursor surface).
- */
-struct swc_surface_class_interface
-{
- /* Called when a surface is added to the class. */
- bool (* add)(struct swc_surface * surface);
-
- /* Called when a surface is removed from the class. */
- void (* remove)(struct swc_surface * surface);
-
- /* Called when a new buffer is attached to a surface. */
- void (* attach)(struct swc_surface * surface,
- struct wl_resource * resource);
-
- /* Called after a surface requests a commit. */
- void (* update)(struct swc_surface * surface);
-
- /* Moves the surface to the specified coordinates. */
- void (* move)(struct swc_surface * surface, int32_t x, int32_t y);
-};
-
-struct swc_surface_class
-{
- const struct swc_surface_class_interface * interface;
-};
-
struct swc_surface
{
struct wl_resource * resource;
@@ -114,8 +85,8 @@ struct swc_surface
} pending;
struct swc_window * window;
- const struct swc_surface_class * class;
- void * class_state;
+ const struct swc_view * view;
+ void * view_state;
uint32_t outputs;
pixman_rectangle32_t geometry;
@@ -129,8 +100,8 @@ struct swc_surface * swc_surface_new(struct wl_client * client,
void swc_surface_send_frame_callbacks(struct swc_surface * surface,
uint32_t time);
-void swc_surface_set_class(struct swc_surface * surface,
- const struct swc_surface_class * class);
+void swc_surface_set_view(struct swc_surface * surface,
+ const struct swc_view * view);
void swc_surface_update(struct swc_surface * surface);
diff --git a/libswc/view.h b/libswc/view.h
@@ -0,0 +1,63 @@
+/* swc: libswc/view.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_VIEW_H
+#define SWC_VIEW_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct swc_surface;
+struct wl_resource;
+
+struct swc_view
+{
+ const struct swc_view_impl * impl;
+};
+
+/**
+ * A view is a set of operations that can be performed on a surface. This
+ * gives the compositor the ability to classify surfaces, treating some
+ * specially (for example, a cursor surface).
+ */
+struct swc_view_impl
+{
+ /* Called when a surface is added to the view. */
+ bool (* add)(struct swc_surface * surface);
+
+ /* Called when a surface is removed from the view. */
+ void (* remove)(struct swc_surface * surface);
+
+ /* Called when a new buffer is attached to a surface. */
+ void (* attach)(struct swc_surface * surface,
+ struct wl_resource * resource);
+
+ /* Called after a surface requests a commit. */
+ void (* update)(struct swc_surface * surface);
+
+ /* Moves the surface to the specified coordinates. */
+ void (* move)(struct swc_surface * surface, int32_t x, int32_t y);
+};
+
+#endif
+
diff --git a/libswc/window.c b/libswc/window.c
@@ -124,7 +124,7 @@ bool swc_window_initialize(struct swc_window * window,
INTERNAL(window)->impl = impl;
surface->window = window;
- swc_surface_set_class(surface, &swc.compositor->compositor_class);
+ swc_surface_set_view(surface, &swc.compositor->compositor_view);
swc.manager->new_window(window);
@@ -136,7 +136,7 @@ void swc_window_finalize(struct swc_window * window)
DEBUG("Finalizing window, %p\n", window);
swc_send_event(&window->event_signal, SWC_WINDOW_DESTROYED, NULL);
- swc_surface_set_class(INTERNAL(window)->surface, NULL);
+ swc_surface_set_view(INTERNAL(window)->surface, NULL);
INTERNAL(window)->surface->window = NULL;
}