commit e9462f0
Michael Forney
·
2014-01-14 02:24:33 +0000 UTC
parent e2b75f7
dumb: Use map mechanism instead of pixman drawable
3 files changed,
+63,
-99
M
dumb.c
+57,
-36
1@@ -21,10 +21,9 @@
2 * SOFTWARE.
3 */
4
5-#include "pixman.h"
6-#include "pixman-private.h"
7 #include "drm-private.h"
8 #include "drm.h"
9+#include "pixman.h"
10
11 #include <fcntl.h>
12 #include <unistd.h>
13@@ -41,17 +40,19 @@ struct dumb_context
14
15 struct dumb_drawable
16 {
17- struct pixman_drawable pixman;
18+ struct wld_drawable base;
19 struct wld_exporter exporter;
20 struct dumb_context * context;
21 uint32_t handle;
22 };
23
24-#define DRM_DRIVER_NAME dumb
25 #include "interface/context.h"
26+#include "interface/drawable.h"
27 #include "interface/exporter.h"
28+#define DRM_DRIVER_NAME dumb
29 #include "interface/drm.h"
30 IMPL(dumb, context)
31+IMPL(dumb, drawable)
32
33 const struct wld_context_impl * dumb_context_impl = &context_impl;
34
35@@ -84,44 +85,18 @@ static struct wld_drawable * new_drawable(struct dumb_context * context,
36 unsigned long pitch)
37 {
38 struct dumb_drawable * drawable;
39- struct drm_mode_map_dumb map_dumb_arg = { .handle = handle };
40- void * data;
41- size_t size = pitch * height;
42- int ret;
43
44 if (!(drawable = malloc(sizeof *drawable)))
45- goto error0;
46-
47- ret = drmIoctl(context->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_dumb_arg);
48-
49- if (ret != 0)
50- goto error1;
51-
52- data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, context->fd,
53- map_dumb_arg.offset);
54-
55- if (data == MAP_FAILED)
56- goto error1;
57-
58- if (!pixman_initialize_drawable(wld_pixman_context, &drawable->pixman,
59- width, height, data, pitch, format))
60- {
61- goto error2;
62- }
63+ return NULL;
64
65+ drawable_initialize(&drawable->base, &drawable_impl,
66+ width, height, format, pitch);
67 drawable->context = context;
68 drawable->handle = handle;
69 exporter_initialize(&drawable->exporter, &exporter_impl);
70- drawable_add_exporter(&drawable->pixman.base, &drawable->exporter);
71+ drawable_add_exporter(&drawable->base, &drawable->exporter);
72
73- return &drawable->pixman.base;
74-
75- error2:
76- munmap(data, size);
77- error1:
78- free(drawable);
79- error0:
80- return NULL;
81+ return &drawable->base;
82 }
83
84 struct wld_drawable * context_create_drawable(struct wld_context * base,
85@@ -199,12 +174,58 @@ void context_destroy(struct wld_context * base)
86 free(context);
87 }
88
89+/**** Drawable ****/
90+
91+bool drawable_map(struct wld_drawable * drawable)
92+{
93+ struct dumb_drawable * dumb = dumb_drawable(drawable);
94+ struct drm_mode_map_dumb map_dumb = { .handle = dumb->handle };
95+ void * data;
96+
97+ if (drmIoctl(dumb->context->fd, DRM_IOCTL_MODE_MAP_DUMB,
98+ &map_dumb) != 0)
99+ {
100+ return false;
101+ }
102+
103+ data = mmap(NULL, drawable->pitch * drawable->height, PROT_READ | PROT_WRITE,
104+ MAP_SHARED, dumb->context->fd, map_dumb.offset);
105+
106+ if (data == MAP_FAILED)
107+ return false;
108+
109+ drawable->map.data = data;
110+
111+ return true;
112+}
113+
114+bool drawable_unmap(struct wld_drawable * drawable)
115+{
116+ if (munmap(drawable->map.data, drawable->pitch * drawable->height) == -1)
117+ return false;
118+
119+ drawable->map.data = NULL;
120+
121+ return true;
122+}
123+
124+void drawable_destroy(struct wld_drawable * drawable_base)
125+{
126+ struct dumb_drawable * drawable = dumb_drawable(drawable_base);
127+ struct drm_mode_destroy_dumb destroy_dumb = {
128+ .handle = drawable->handle
129+ };
130+
131+ drmIoctl(drawable->context->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
132+ free(drawable);
133+}
134+
135 /**** Exporter ****/
136
137 bool exporter_export(struct wld_exporter * exporter, struct wld_drawable * base,
138 uint32_t type, union wld_object * object)
139 {
140- struct dumb_drawable * drawable = (void *) base;
141+ struct dumb_drawable * drawable = dumb_drawable(base);
142
143 switch (type)
144 {
+0,
-46
1@@ -1,46 +0,0 @@
2-/* wld: pixman-private.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 WLD_PIXMAN_PRIVATE_H
26-#define WLD_PIXMAN_PRIVATE_H
27-
28-#include "wld.h"
29-
30-struct wld_context;
31-
32-struct pixman_drawable
33-{
34- struct wld_drawable base;
35- pixman_image_t * image;
36- struct pixman_context * context;
37-};
38-
39-extern const struct wld_drawable_impl * const pixman_drawable_impl;
40-
41-bool pixman_initialize_drawable
42- (struct wld_context * context, struct pixman_drawable * drawable,
43- uint32_t width, uint32_t height,
44- void * data, uint32_t pitch, uint32_t format);
45-
46-#endif
47-
M
pixman.c
+6,
-17
1@@ -22,7 +22,6 @@
2 */
3
4 #include "pixman.h"
5-#include "pixman-private.h"
6 #include "wld-private.h"
7
8 #define PIXMAN_COLOR(c) { \
9@@ -39,6 +38,12 @@ struct pixman_renderer
10 pixman_glyph_cache_t * glyph_cache;
11 };
12
13+struct pixman_drawable
14+{
15+ struct wld_drawable base;
16+ pixman_image_t * image;
17+};
18+
19 struct pixman_exporter
20 {
21 struct wld_exporter base;
22@@ -55,7 +60,6 @@ IMPL(pixman, drawable)
23 IMPL(pixman, exporter)
24
25 static struct wld_context context = { .impl = &context_impl };
26-const struct wld_drawable_impl * const pixman_drawable_impl = &drawable_impl;
27
28 EXPORT
29 struct wld_context * wld_pixman_context = &context;
30@@ -81,21 +85,6 @@ struct wld_renderer * context_create_renderer(struct wld_context * context)
31 return NULL;
32 }
33
34-bool pixman_initialize_drawable
35- (struct wld_context * context, struct pixman_drawable * drawable,
36- uint32_t width, uint32_t height,
37- void * data, uint32_t pitch, uint32_t format)
38-{
39- drawable_initialize(&drawable->base, &drawable_impl,
40- width, height, format, pitch);
41- drawable->context = (void *) context;
42- drawable->image = pixman_image_create_bits(format_wld_to_pixman(format),
43- width, height,
44- (uint32_t *) data, pitch);
45-
46- return drawable->image != NULL;
47-}
48-
49 struct wld_drawable * new_drawable(pixman_image_t * image)
50 {
51 struct pixman_drawable * drawable;