commit a0520fc
Michael Forney
·
2014-01-15 12:50:03 +0000 UTC
parent 4555a6b
Add surface interface
M
Makefile
+2,
-1
1@@ -23,7 +23,8 @@ WLD_SOURCES = \
2 color.c \
3 context.c \
4 font.c \
5- renderer.c
6+ renderer.c \
7+ surface.c
8 WLD_HEADERS = wld.h
9
10 ifeq ($(ENABLE_DRM),1)
+8,
-0
1@@ -53,6 +53,14 @@ struct wld_buffer * wld_import_buffer(struct wld_context * context,
2 width, height, format, pitch);
3 }
4
5+EXPORT
6+struct wld_surface * wld_create_surface(struct wld_context * context,
7+ uint32_t width, uint32_t height,
8+ uint32_t format)
9+{
10+ return context->impl->create_surface(context, width, height, format);
11+}
12+
13 EXPORT
14 void wld_destroy_context(struct wld_context * context)
15 {
+10,
-0
1@@ -29,12 +29,22 @@ static struct wld_buffer * context_create_buffer
2 static struct wld_buffer * context_import_buffer
3 (struct wld_context * context, uint32_t type, union wld_object object,
4 uint32_t width, uint32_t height, uint32_t format, uint32_t pitch);
5+#ifdef CONTEXT_IMPLEMENTS_CREATE_SURFACE
6+static struct wld_surface * context_create_surface
7+ (struct wld_context * context,
8+ uint32_t width, uint32_t height, uint32_t format);
9+#endif
10 static void context_destroy(struct wld_context * context);
11
12 static const struct wld_context_impl context_impl = {
13 .create_renderer = &context_create_renderer,
14 .create_buffer = &context_create_buffer,
15 .import_buffer = &context_import_buffer,
16+#ifdef CONTEXT_IMPLEMENTS_CREATE_SURFACE
17+ .create_surface = &context_create_surface,
18+#else
19+ .create_surface = &default_create_surface,
20+#endif
21 .destroy = &context_destroy
22 };
23
+41,
-0
1@@ -0,0 +1,41 @@
2+/* wld: interface/surface.h
3+ *
4+ * Copyright (c) 2013, 2014 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+static pixman_region32_t * surface_damage(struct wld_surface * surface,
26+ pixman_region32_t * new_damage);
27+static struct wld_buffer * surface_back(struct wld_surface * surface);
28+static struct wld_buffer * surface_take(struct wld_surface * surface);
29+static bool surface_release(struct wld_surface * surface,
30+ struct wld_buffer * buffer);
31+static bool surface_swap(struct wld_surface * surface);
32+static void surface_destroy(struct wld_surface * surface);
33+
34+static const struct wld_surface_impl surface_impl = {
35+ .damage = &surface_damage,
36+ .back = &surface_back,
37+ .take = &surface_take,
38+ .release = &surface_release,
39+ .swap = &surface_swap,
40+ .destroy = &surface_destroy
41+};
42+
+12,
-0
1@@ -91,6 +91,18 @@ bool wld_set_target_buffer(struct wld_renderer * renderer,
2 return true;
3 }
4
5+EXPORT
6+bool wld_set_target_surface(struct wld_renderer * renderer,
7+ struct wld_surface * surface)
8+{
9+ struct wld_buffer * back_buffer;
10+
11+ if (!(back_buffer = surface->impl->back(surface)))
12+ return false;
13+
14+ return wld_set_target_buffer(renderer, back_buffer);
15+}
16+
17 EXPORT
18 void wld_fill_rectangle(struct wld_renderer * renderer, uint32_t color,
19 int32_t x, int32_t y, uint32_t width, uint32_t height)
+70,
-0
1@@ -0,0 +1,70 @@
2+/* wld: surface.c
3+ *
4+ * Copyright (c) 2013, 2014 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+#include "wld-private.h"
26+
27+struct wld_surface * default_create_surface(struct wld_context * context,
28+ uint32_t width, uint32_t height,
29+ uint32_t format)
30+{
31+ return NULL;
32+}
33+
34+void surface_initialize(struct wld_surface * surface,
35+ const struct wld_surface_impl * impl)
36+{
37+ *((const struct wld_surface_impl **) &surface->impl) = impl;
38+}
39+
40+EXPORT
41+pixman_region32_t * wld_surface_damage(struct wld_surface * surface,
42+ pixman_region32_t * new_damage)
43+{
44+ return surface->impl->damage(surface, new_damage);
45+}
46+
47+EXPORT
48+struct wld_buffer * wld_surface_take(struct wld_surface * surface)
49+{
50+ return surface->impl->take(surface);
51+}
52+
53+EXPORT
54+void wld_surface_release(struct wld_surface * surface,
55+ struct wld_buffer * buffer)
56+{
57+ surface->impl->release(surface, buffer);
58+}
59+
60+EXPORT
61+bool wld_swap(struct wld_surface * surface)
62+{
63+ return surface->impl->swap(surface);
64+}
65+
66+EXPORT
67+void wld_destroy_surface(struct wld_surface * surface)
68+{
69+ surface->impl->destroy(surface);
70+}
71+
+21,
-0
1@@ -94,6 +94,9 @@ struct wld_context_impl
2 union wld_object object,
3 uint32_t width, uint32_t height,
4 uint32_t format, uint32_t pitch);
5+ struct wld_surface * (* create_surface)(struct wld_context * context,
6+ uint32_t width, uint32_t height,
7+ uint32_t format);
8 void (* destroy)(struct wld_context * context);
9 };
10
11@@ -132,6 +135,17 @@ struct wld_buffer_impl
12 void (* destroy)(struct wld_buffer * buffer);
13 };
14
15+struct wld_surface_impl
16+{
17+ pixman_region32_t * (* damage)(struct wld_surface * surface,
18+ pixman_region32_t * damage);
19+ struct wld_buffer * (* back)(struct wld_surface * surface);
20+ struct wld_buffer * (* take)(struct wld_surface * surface);
21+ bool (* release)(struct wld_surface * surface, struct wld_buffer * buffer);
22+ bool (* swap)(struct wld_surface * surface);
23+ void (* destroy)(struct wld_surface * surface);
24+};
25+
26 struct wld_exporter
27 {
28 const struct wld_exporter_impl * const impl;
29@@ -202,6 +216,10 @@ void default_copy_region(struct wld_renderer * renderer,
30 int32_t dst_x, int32_t dst_y,
31 pixman_region32_t * region);
32
33+struct wld_surface * default_create_surface(struct wld_context * context,
34+ uint32_t width, uint32_t height,
35+ uint32_t format);
36+
37 void context_initialize(struct wld_context * context,
38 const struct wld_context_impl * impl);
39
40@@ -219,5 +237,8 @@ void buffer_add_exporter(struct wld_buffer * buffer,
41 void exporter_initialize(struct wld_exporter * exporter,
42 const struct wld_exporter_impl * impl);
43
44+void surface_initialize(struct wld_surface * surface,
45+ const struct wld_surface_impl * impl);
46+
47 #endif
48
M
wld.h
+26,
-0
1@@ -77,6 +77,10 @@ struct wld_buffer * wld_import_buffer(struct wld_context * context,
2 uint32_t width, uint32_t height,
3 uint32_t format, uint32_t pitch);
4
5+struct wld_surface * wld_create_surface(struct wld_context * context,
6+ uint32_t width, uint32_t height,
7+ uint32_t format);
8+
9 void wld_destroy_context(struct wld_context * context);
10
11 /**** Font Handling ****/
12@@ -177,6 +181,25 @@ bool wld_export(struct wld_buffer * buffer,
13 */
14 void wld_destroy_buffer(struct wld_buffer * buffer);
15
16+/**** Surfaces ****/
17+
18+struct wld_surface
19+{
20+ const struct wld_surface_impl * const impl;
21+};
22+
23+pixman_region32_t * wld_surface_damage(struct wld_surface * surface,
24+ pixman_region32_t * new_damage);
25+
26+struct wld_buffer * wld_surface_take(struct wld_surface * surface);
27+
28+void wld_surface_release(struct wld_surface * surface,
29+ struct wld_buffer * buffer);
30+
31+bool wld_swap(struct wld_surface * surface);
32+
33+void wld_destroy_surface(struct wld_surface * surface);
34+
35 /**** Renderers ****/
36
37 struct wld_renderer
38@@ -199,6 +222,9 @@ uint32_t wld_capabilities(struct wld_renderer * renderer,
39 bool wld_set_target_buffer(struct wld_renderer * renderer,
40 struct wld_buffer * buffer);
41
42+bool wld_set_target_surface(struct wld_renderer * renderer,
43+ struct wld_surface * surface);
44+
45 void wld_fill_rectangle(struct wld_renderer * renderer, uint32_t color,
46 int32_t x, int32_t y, uint32_t width, uint32_t height);
47