commit a0520fc8db16bb2beb53c54f9b31f21f70347709
parent 4555a6b930370c671683772b47dae6e287168301
Author: Michael Forney <mforney@mforney.org>
Date: Wed, 15 Jan 2014 04:50:03 -0800
Add surface interface
Diffstat:
8 files changed, 190 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -23,7 +23,8 @@ WLD_SOURCES = \
color.c \
context.c \
font.c \
- renderer.c
+ renderer.c \
+ surface.c
WLD_HEADERS = wld.h
ifeq ($(ENABLE_DRM),1)
diff --git a/context.c b/context.c
@@ -54,6 +54,14 @@ struct wld_buffer * wld_import_buffer(struct wld_context * context,
}
EXPORT
+struct wld_surface * wld_create_surface(struct wld_context * context,
+ uint32_t width, uint32_t height,
+ uint32_t format)
+{
+ return context->impl->create_surface(context, width, height, format);
+}
+
+EXPORT
void wld_destroy_context(struct wld_context * context)
{
context->impl->destroy(context);
diff --git a/interface/context.h b/interface/context.h
@@ -29,12 +29,22 @@ static struct wld_buffer * context_create_buffer
static struct wld_buffer * context_import_buffer
(struct wld_context * context, uint32_t type, union wld_object object,
uint32_t width, uint32_t height, uint32_t format, uint32_t pitch);
+#ifdef CONTEXT_IMPLEMENTS_CREATE_SURFACE
+static struct wld_surface * context_create_surface
+ (struct wld_context * context,
+ uint32_t width, uint32_t height, uint32_t format);
+#endif
static void context_destroy(struct wld_context * context);
static const struct wld_context_impl context_impl = {
.create_renderer = &context_create_renderer,
.create_buffer = &context_create_buffer,
.import_buffer = &context_import_buffer,
+#ifdef CONTEXT_IMPLEMENTS_CREATE_SURFACE
+ .create_surface = &context_create_surface,
+#else
+ .create_surface = &default_create_surface,
+#endif
.destroy = &context_destroy
};
diff --git a/interface/surface.h b/interface/surface.h
@@ -0,0 +1,41 @@
+/* wld: interface/surface.h
+ *
+ * Copyright (c) 2013, 2014 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.
+ */
+
+static pixman_region32_t * surface_damage(struct wld_surface * surface,
+ pixman_region32_t * new_damage);
+static struct wld_buffer * surface_back(struct wld_surface * surface);
+static struct wld_buffer * surface_take(struct wld_surface * surface);
+static bool surface_release(struct wld_surface * surface,
+ struct wld_buffer * buffer);
+static bool surface_swap(struct wld_surface * surface);
+static void surface_destroy(struct wld_surface * surface);
+
+static const struct wld_surface_impl surface_impl = {
+ .damage = &surface_damage,
+ .back = &surface_back,
+ .take = &surface_take,
+ .release = &surface_release,
+ .swap = &surface_swap,
+ .destroy = &surface_destroy
+};
+
diff --git a/renderer.c b/renderer.c
@@ -92,6 +92,18 @@ bool wld_set_target_buffer(struct wld_renderer * renderer,
}
EXPORT
+bool wld_set_target_surface(struct wld_renderer * renderer,
+ struct wld_surface * surface)
+{
+ struct wld_buffer * back_buffer;
+
+ if (!(back_buffer = surface->impl->back(surface)))
+ return false;
+
+ return wld_set_target_buffer(renderer, back_buffer);
+}
+
+EXPORT
void wld_fill_rectangle(struct wld_renderer * renderer, uint32_t color,
int32_t x, int32_t y, uint32_t width, uint32_t height)
{
diff --git a/surface.c b/surface.c
@@ -0,0 +1,70 @@
+/* wld: surface.c
+ *
+ * Copyright (c) 2013, 2014 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.
+ */
+
+#include "wld-private.h"
+
+struct wld_surface * default_create_surface(struct wld_context * context,
+ uint32_t width, uint32_t height,
+ uint32_t format)
+{
+ return NULL;
+}
+
+void surface_initialize(struct wld_surface * surface,
+ const struct wld_surface_impl * impl)
+{
+ *((const struct wld_surface_impl **) &surface->impl) = impl;
+}
+
+EXPORT
+pixman_region32_t * wld_surface_damage(struct wld_surface * surface,
+ pixman_region32_t * new_damage)
+{
+ return surface->impl->damage(surface, new_damage);
+}
+
+EXPORT
+struct wld_buffer * wld_surface_take(struct wld_surface * surface)
+{
+ return surface->impl->take(surface);
+}
+
+EXPORT
+void wld_surface_release(struct wld_surface * surface,
+ struct wld_buffer * buffer)
+{
+ surface->impl->release(surface, buffer);
+}
+
+EXPORT
+bool wld_swap(struct wld_surface * surface)
+{
+ return surface->impl->swap(surface);
+}
+
+EXPORT
+void wld_destroy_surface(struct wld_surface * surface)
+{
+ surface->impl->destroy(surface);
+}
+
diff --git a/wld-private.h b/wld-private.h
@@ -94,6 +94,9 @@ struct wld_context_impl
union wld_object object,
uint32_t width, uint32_t height,
uint32_t format, uint32_t pitch);
+ struct wld_surface * (* create_surface)(struct wld_context * context,
+ uint32_t width, uint32_t height,
+ uint32_t format);
void (* destroy)(struct wld_context * context);
};
@@ -132,6 +135,17 @@ struct wld_buffer_impl
void (* destroy)(struct wld_buffer * buffer);
};
+struct wld_surface_impl
+{
+ pixman_region32_t * (* damage)(struct wld_surface * surface,
+ pixman_region32_t * damage);
+ struct wld_buffer * (* back)(struct wld_surface * surface);
+ struct wld_buffer * (* take)(struct wld_surface * surface);
+ bool (* release)(struct wld_surface * surface, struct wld_buffer * buffer);
+ bool (* swap)(struct wld_surface * surface);
+ void (* destroy)(struct wld_surface * surface);
+};
+
struct wld_exporter
{
const struct wld_exporter_impl * const impl;
@@ -202,6 +216,10 @@ void default_copy_region(struct wld_renderer * renderer,
int32_t dst_x, int32_t dst_y,
pixman_region32_t * region);
+struct wld_surface * default_create_surface(struct wld_context * context,
+ uint32_t width, uint32_t height,
+ uint32_t format);
+
void context_initialize(struct wld_context * context,
const struct wld_context_impl * impl);
@@ -219,5 +237,8 @@ void buffer_add_exporter(struct wld_buffer * buffer,
void exporter_initialize(struct wld_exporter * exporter,
const struct wld_exporter_impl * impl);
+void surface_initialize(struct wld_surface * surface,
+ const struct wld_surface_impl * impl);
+
#endif
diff --git a/wld.h b/wld.h
@@ -77,6 +77,10 @@ struct wld_buffer * wld_import_buffer(struct wld_context * context,
uint32_t width, uint32_t height,
uint32_t format, uint32_t pitch);
+struct wld_surface * wld_create_surface(struct wld_context * context,
+ uint32_t width, uint32_t height,
+ uint32_t format);
+
void wld_destroy_context(struct wld_context * context);
/**** Font Handling ****/
@@ -177,6 +181,25 @@ bool wld_export(struct wld_buffer * buffer,
*/
void wld_destroy_buffer(struct wld_buffer * buffer);
+/**** Surfaces ****/
+
+struct wld_surface
+{
+ const struct wld_surface_impl * const impl;
+};
+
+pixman_region32_t * wld_surface_damage(struct wld_surface * surface,
+ pixman_region32_t * new_damage);
+
+struct wld_buffer * wld_surface_take(struct wld_surface * surface);
+
+void wld_surface_release(struct wld_surface * surface,
+ struct wld_buffer * buffer);
+
+bool wld_swap(struct wld_surface * surface);
+
+void wld_destroy_surface(struct wld_surface * surface);
+
/**** Renderers ****/
struct wld_renderer
@@ -199,6 +222,9 @@ uint32_t wld_capabilities(struct wld_renderer * renderer,
bool wld_set_target_buffer(struct wld_renderer * renderer,
struct wld_buffer * buffer);
+bool wld_set_target_surface(struct wld_renderer * renderer,
+ struct wld_surface * surface);
+
void wld_fill_rectangle(struct wld_renderer * renderer, uint32_t color,
int32_t x, int32_t y, uint32_t width, uint32_t height);