commit c53915e

Michael Forney  ·  2014-01-14 09:04:46 +0000 UTC
parent e9462f0
Rename drawable -> buffer

Since buffers can not only be drawn to, but also copied from, I thought
buffer was a better name.
19 files changed,  +337, -327
M dumb.c
M wld.h
+1, -1
 1@@ -16,9 +16,9 @@ CLEAN_FILES     := $(TARGETS)
 2 WLD_REQUIRES = fontconfig pixman-1
 3 WLD_REQUIRES_PRIVATE = freetype2
 4 WLD_SOURCES =           \
 5+    buffer.c            \
 6     color.c             \
 7     context.c           \
 8-    drawable.c          \
 9     font.c              \
10     renderer.c
11 WLD_HEADERS = wld.h
R drawable.c => buffer.c
+38, -32
  1@@ -1,6 +1,6 @@
  2-/* wld: drawable.c
  3+/* wld: buffer.c
  4  *
  5- * Copyright (c) 2013 Michael Forney
  6+ * Copyright (c) 2013, 2014 Michael Forney
  7  *
  8  * Permission is hereby granted, free of charge, to any person obtaining a copy
  9  * of this software and associated documentation files (the "Software"), to deal
 10@@ -23,28 +23,26 @@
 11 
 12 #include "wld-private.h"
 13 
 14-#include <assert.h>
 15-
 16-void drawable_initialize(struct wld_drawable * drawable,
 17-                         const struct wld_drawable_impl * impl,
 18-                         uint32_t width, uint32_t height,
 19-                         uint32_t format, uint32_t pitch)
 20+void buffer_initialize(struct wld_buffer * buffer,
 21+                       const struct wld_buffer_impl * impl,
 22+                       uint32_t width, uint32_t height,
 23+                       uint32_t format, uint32_t pitch)
 24 {
 25-    *((const struct wld_drawable_impl **) &drawable->impl) = impl;
 26-    drawable->width = width;
 27-    drawable->height = height;
 28-    drawable->format = format;
 29-    drawable->pitch = pitch;
 30-    drawable->map.data = NULL;
 31-    drawable->map.count = 0;
 32-    drawable->exporters = NULL;
 33+    *((const struct wld_buffer_impl **) &buffer->impl) = impl;
 34+    buffer->width = width;
 35+    buffer->height = height;
 36+    buffer->format = format;
 37+    buffer->pitch = pitch;
 38+    buffer->map.data = NULL;
 39+    buffer->map.count = 0;
 40+    buffer->exporters = NULL;
 41 }
 42 
 43-void drawable_add_exporter(struct wld_drawable * drawable,
 44-                           struct wld_exporter * exporter)
 45+void buffer_add_exporter(struct wld_buffer * buffer,
 46+                         struct wld_exporter * exporter)
 47 {
 48-    exporter->next = drawable->exporters;
 49-    drawable->exporters = exporter;
 50+    exporter->next = buffer->exporters;
 51+    buffer->exporters = exporter;
 52 }
 53 
 54 void exporter_initialize(struct wld_exporter * exporter,
 55@@ -55,37 +53,37 @@ void exporter_initialize(struct wld_exporter * exporter,
 56 }
 57 
 58 EXPORT
 59-bool wld_map(struct wld_drawable * drawable)
 60+bool wld_map(struct wld_buffer * buffer)
 61 {
 62-    if (drawable->map.count == 0 && !drawable->impl->map(drawable))
 63+    if (buffer->map.count == 0 && !buffer->impl->map(buffer))
 64         return false;
 65 
 66-    ++drawable->map.count;
 67+    ++buffer->map.count;
 68     return true;
 69 }
 70 
 71 EXPORT
 72-bool wld_unmap(struct wld_drawable * drawable)
 73+bool wld_unmap(struct wld_buffer * buffer)
 74 {
 75-    if (drawable->map.count == 0
 76-        || (drawable->map.count == 1 && !drawable->impl->unmap(drawable)))
 77+    if (buffer->map.count == 0
 78+        || (buffer->map.count == 1 && !buffer->impl->unmap(buffer)))
 79     {
 80         return false;
 81     }
 82 
 83-    --drawable->map.count;
 84+    --buffer->map.count;
 85     return true;
 86 }
 87 
 88 EXPORT
 89-bool wld_export(struct wld_drawable * drawable,
 90+bool wld_export(struct wld_buffer * buffer,
 91                 uint32_t type, union wld_object * object)
 92 {
 93     struct wld_exporter * exporter;
 94 
 95-    for (exporter = drawable->exporters; exporter; exporter = exporter->next)
 96+    for (exporter = buffer->exporters; exporter; exporter = exporter->next)
 97     {
 98-        if (exporter->impl->export(exporter, drawable, type, object))
 99+        if (exporter->impl->export(exporter, buffer, type, object))
100             return true;
101     }
102 
103@@ -93,8 +91,16 @@ bool wld_export(struct wld_drawable * drawable,
104 }
105 
106 EXPORT
107-void wld_destroy_drawable(struct wld_drawable * drawable)
108+void wld_destroy_buffer(struct wld_buffer * buffer)
109 {
110-    drawable->impl->destroy(drawable);
111+    struct wld_exporter * exporter;
112+
113+    if (buffer->map.count > 0)
114+        wld_unmap(buffer);
115+
116+    for (exporter = buffer->exporters; exporter; exporter = exporter->next)
117+        exporter->impl->destroy(exporter);
118+
119+    buffer->impl->destroy(buffer);
120 }
121 
+10, -10
 1@@ -36,21 +36,21 @@ struct wld_renderer * wld_create_renderer(struct wld_context * context)
 2 }
 3 
 4 EXPORT
 5-struct wld_drawable * wld_create_drawable(struct wld_context * context,
 6-                                          uint32_t width, uint32_t height,
 7-                                          uint32_t format)
 8+struct wld_buffer * wld_create_buffer(struct wld_context * context,
 9+                                      uint32_t width, uint32_t height,
10+                                      uint32_t format)
11 {
12-    return context->impl->create_drawable(context, width, height, format);
13+    return context->impl->create_buffer(context, width, height, format);
14 }
15 
16 EXPORT
17-struct wld_drawable * wld_import(struct wld_context * context,
18-                                 uint32_t type, union wld_object object,
19-                                 uint32_t width, uint32_t height,
20-                                 uint32_t format, uint32_t pitch)
21+struct wld_buffer * wld_import_buffer(struct wld_context * context,
22+                                      uint32_t type, union wld_object object,
23+                                      uint32_t width, uint32_t height,
24+                                      uint32_t format, uint32_t pitch)
25 {
26-    return context->impl->import(context, type, object,
27-                                 width, height, format, pitch);
28+    return context->impl->import_buffer(context, type, object,
29+                                        width, height, format, pitch);
30 }
31 
32 EXPORT
M dumb.c
+53, -55
  1@@ -38,21 +38,21 @@ struct dumb_context
  2     int fd;
  3 };
  4 
  5-struct dumb_drawable
  6+struct dumb_buffer
  7 {
  8-    struct wld_drawable base;
  9+    struct wld_buffer base;
 10     struct wld_exporter exporter;
 11     struct dumb_context * context;
 12     uint32_t handle;
 13 };
 14 
 15 #include "interface/context.h"
 16-#include "interface/drawable.h"
 17+#include "interface/buffer.h"
 18 #include "interface/exporter.h"
 19 #define DRM_DRIVER_NAME dumb
 20 #include "interface/drm.h"
 21 IMPL(dumb, context)
 22-IMPL(dumb, drawable)
 23+IMPL(dumb, buffer)
 24 
 25 const struct wld_context_impl * dumb_context_impl = &context_impl;
 26 
 27@@ -79,32 +79,32 @@ struct wld_renderer * context_create_renderer(struct wld_context * context)
 28     return wld_create_renderer(wld_pixman_context);
 29 }
 30 
 31-static struct wld_drawable * new_drawable(struct dumb_context * context,
 32-                                          uint32_t width, uint32_t height,
 33-                                          uint32_t format, uint32_t handle,
 34-                                          unsigned long pitch)
 35+static struct wld_buffer * new_buffer(struct dumb_context * context,
 36+                                      uint32_t width, uint32_t height,
 37+                                      uint32_t format, uint32_t handle,
 38+                                      unsigned long pitch)
 39 {
 40-    struct dumb_drawable * drawable;
 41+    struct dumb_buffer * buffer;
 42 
 43-    if (!(drawable = malloc(sizeof *drawable)))
 44+    if (!(buffer = malloc(sizeof *buffer)))
 45         return NULL;
 46 
 47-    drawable_initialize(&drawable->base, &drawable_impl,
 48-                        width, height, format, pitch);
 49-    drawable->context = context;
 50-    drawable->handle = handle;
 51-    exporter_initialize(&drawable->exporter, &exporter_impl);
 52-    drawable_add_exporter(&drawable->base, &drawable->exporter);
 53+    buffer_initialize(&buffer->base, &buffer_impl,
 54+                      width, height, format, pitch);
 55+    buffer->context = context;
 56+    buffer->handle = handle;
 57+    exporter_initialize(&buffer->exporter, &exporter_impl);
 58+    buffer_add_exporter(&buffer->base, &buffer->exporter);
 59 
 60-    return &drawable->base;
 61+    return &buffer->base;
 62 }
 63 
 64-struct wld_drawable * context_create_drawable(struct  wld_context * base,
 65-                                              uint32_t width, uint32_t height,
 66-                                              uint32_t format)
 67+struct wld_buffer * context_create_buffer(struct wld_context * base,
 68+                                          uint32_t width, uint32_t height,
 69+                                          uint32_t format)
 70 {
 71     struct dumb_context * context = dumb_context(base);
 72-    struct wld_drawable * drawable;
 73+    struct wld_buffer * buffer;
 74     struct drm_mode_create_dumb create_dumb_arg = {
 75         .height = height, .width = width,
 76         .bpp = format_bytes_per_pixel(format) * 8,
 77@@ -116,13 +116,13 @@ struct wld_drawable * context_create_drawable(struct  wld_context * base,
 78     if (ret != 0)
 79         goto error0;
 80 
 81-    drawable = new_drawable(context, width, height, format,
 82-                            create_dumb_arg.handle, create_dumb_arg.pitch);
 83+    buffer = new_buffer(context, width, height, format,
 84+                        create_dumb_arg.handle, create_dumb_arg.pitch);
 85 
 86-    if (!drawable)
 87+    if (!buffer)
 88         goto error1;
 89 
 90-    return drawable;
 91+    return buffer;
 92 
 93   error1:
 94     {
 95@@ -136,10 +136,11 @@ struct wld_drawable * context_create_drawable(struct  wld_context * base,
 96     return NULL;
 97 }
 98 
 99-struct wld_drawable * context_import(struct wld_context * base,
100-                                     uint32_t type, union wld_object object,
101-                                     uint32_t width, uint32_t height,
102-                                     uint32_t format, uint32_t pitch)
103+struct wld_buffer * context_import_buffer(struct wld_context * base,
104+                                          uint32_t type,
105+                                          union wld_object object,
106+                                          uint32_t width, uint32_t height,
107+                                          uint32_t format, uint32_t pitch)
108 {
109     struct dumb_context * context = dumb_context(base);
110     uint32_t handle;
111@@ -163,7 +164,7 @@ struct wld_drawable * context_import(struct wld_context * base,
112         default: return NULL;
113     }
114 
115-    return new_drawable(context, width, height, format, handle, pitch);
116+    return new_buffer(context, width, height, format, handle, pitch);
117 }
118 
119 void context_destroy(struct wld_context * base)
120@@ -174,66 +175,66 @@ void context_destroy(struct wld_context * base)
121     free(context);
122 }
123 
124-/**** Drawable ****/
125+/**** Buffer ****/
126 
127-bool drawable_map(struct wld_drawable * drawable)
128+bool buffer_map(struct wld_buffer * base)
129 {
130-    struct dumb_drawable * dumb = dumb_drawable(drawable);
131-    struct drm_mode_map_dumb map_dumb = { .handle = dumb->handle };
132+    struct dumb_buffer * buffer = dumb_buffer(base);
133+    struct drm_mode_map_dumb map_dumb = { .handle = buffer->handle };
134     void * data;
135 
136-    if (drmIoctl(dumb->context->fd, DRM_IOCTL_MODE_MAP_DUMB,
137+    if (drmIoctl(buffer->context->fd, DRM_IOCTL_MODE_MAP_DUMB,
138                  &map_dumb) != 0)
139     {
140         return false;
141     }
142 
143-    data = mmap(NULL, drawable->pitch * drawable->height, PROT_READ | PROT_WRITE,
144-                MAP_SHARED, dumb->context->fd, map_dumb.offset);
145+    data = mmap(NULL, base->pitch * base->height, PROT_READ | PROT_WRITE,
146+                MAP_SHARED, buffer->context->fd, map_dumb.offset);
147 
148     if (data == MAP_FAILED)
149         return false;
150 
151-    drawable->map.data = data;
152+    buffer->base.map.data = data;
153 
154     return true;
155 }
156 
157-bool drawable_unmap(struct wld_drawable * drawable)
158+bool buffer_unmap(struct wld_buffer * buffer)
159 {
160-    if (munmap(drawable->map.data, drawable->pitch * drawable->height) == -1)
161+    if (munmap(buffer->map.data, buffer->pitch * buffer->height) == -1)
162         return false;
163 
164-    drawable->map.data = NULL;
165+    buffer->map.data = NULL;
166 
167     return true;
168 }
169 
170-void drawable_destroy(struct wld_drawable * drawable_base)
171+void buffer_destroy(struct wld_buffer * base)
172 {
173-    struct dumb_drawable * drawable = dumb_drawable(drawable_base);
174+    struct dumb_buffer * buffer = dumb_buffer(base);
175     struct drm_mode_destroy_dumb destroy_dumb = {
176-        .handle = drawable->handle
177+        .handle = buffer->handle
178     };
179 
180-    drmIoctl(drawable->context->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
181-    free(drawable);
182+    drmIoctl(buffer->context->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
183+    free(buffer);
184 }
185 
186 /**** Exporter ****/
187 
188-bool exporter_export(struct wld_exporter * exporter, struct wld_drawable * base,
189+bool exporter_export(struct wld_exporter * exporter, struct wld_buffer * base,
190                      uint32_t type, union wld_object * object)
191 {
192-    struct dumb_drawable * drawable = dumb_drawable(base);
193+    struct dumb_buffer * buffer = dumb_buffer(base);
194 
195     switch (type)
196     {
197         case WLD_DRM_OBJECT_HANDLE:
198-            object->u32 = drawable->handle;
199+            object->u32 = buffer->handle;
200             return true;
201         case WLD_DRM_OBJECT_PRIME_FD:
202-            if (drmPrimeHandleToFD(drawable->context->fd, drawable->handle,
203+            if (drmPrimeHandleToFD(buffer->context->fd, buffer->handle,
204                                    DRM_CLOEXEC, &object->i) != 0)
205             {
206                 return false;
207@@ -242,13 +243,10 @@ bool exporter_export(struct wld_exporter * exporter, struct wld_drawable * base,
208             return true;
209         case WLD_DRM_OBJECT_GEM_NAME:
210         {
211-            struct drm_gem_flink flink = { .handle = drawable->handle };
212+            struct drm_gem_flink flink = { .handle = buffer->handle };
213 
214-            if (drmIoctl(drawable->context->fd, DRM_IOCTL_GEM_FLINK,
215-                         &flink) != 0)
216-            {
217+            if (drmIoctl(buffer->context->fd, DRM_IOCTL_GEM_FLINK, &flink) != 0)
218                 return false;
219-            }
220 
221             object->u32 = flink.name;
222             return true;
+61, -58
  1@@ -40,25 +40,25 @@ struct intel_renderer
  2 {
  3     struct wld_renderer base;
  4     struct intel_batch * batch;
  5-    struct intel_drawable * target;
  6+    struct intel_buffer * target;
  7 };
  8 
  9-struct intel_drawable
 10+struct intel_buffer
 11 {
 12-    struct wld_drawable base;
 13+    struct wld_buffer base;
 14     struct wld_exporter exporter;
 15     drm_intel_bo * bo;
 16 };
 17 
 18 #include "interface/context.h"
 19 #include "interface/renderer.h"
 20-#include "interface/drawable.h"
 21+#include "interface/buffer.h"
 22 #include "interface/exporter.h"
 23 #define DRM_DRIVER_NAME intel
 24 #include "interface/drm.h"
 25 IMPL(intel, context)
 26 IMPL(intel, renderer)
 27-IMPL(intel, drawable)
 28+IMPL(intel, buffer)
 29 
 30 bool driver_device_supported(uint32_t vendor_id, uint32_t device_id)
 31 {
 32@@ -110,47 +110,48 @@ struct wld_renderer * context_create_renderer(struct wld_context * base)
 33     return NULL;
 34 }
 35 
 36-static struct intel_drawable * new_drawable(uint32_t width, uint32_t height,
 37-                                            uint32_t format)
 38+static struct intel_buffer * new_buffer(uint32_t width, uint32_t height,
 39+                                        uint32_t format)
 40 {
 41-    struct intel_drawable * intel;
 42+    struct intel_buffer * buffer;
 43 
 44-    if (!(intel = malloc(sizeof *intel)))
 45+    if (!(buffer = malloc(sizeof *buffer)))
 46         return NULL;
 47 
 48-    drawable_initialize(&intel->base, &drawable_impl,
 49-                        width, height, format, 0);
 50-    exporter_initialize(&intel->exporter, &exporter_impl);
 51-    drawable_add_exporter(&intel->base, &intel->exporter);
 52+    buffer_initialize(&buffer->base, &buffer_impl,
 53+                      width, height, format, 0);
 54+    exporter_initialize(&buffer->exporter, &exporter_impl);
 55+    buffer_add_exporter(&buffer->base, &buffer->exporter);
 56 
 57-    return intel;
 58+    return buffer;
 59 }
 60 
 61-struct wld_drawable * context_create_drawable(struct wld_context * base,
 62-                                              uint32_t width, uint32_t height,
 63-                                              uint32_t format)
 64+struct wld_buffer * context_create_buffer(struct wld_context * base,
 65+                                          uint32_t width, uint32_t height,
 66+                                          uint32_t format)
 67 {
 68     struct intel_context * context = intel_context(base);
 69-    struct intel_drawable * intel;
 70+    struct intel_buffer * buffer;
 71     uint32_t tiling_mode = width >= 128 ? I915_TILING_X : I915_TILING_NONE;
 72 
 73-    if (!(intel = new_drawable(width, height, format)))
 74+    if (!(buffer = new_buffer(width, height, format)))
 75         return NULL;
 76 
 77-    intel->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "drawable",
 78-                                         width, height, 4, &tiling_mode,
 79-                                         &intel->base.pitch, 0);
 80+    buffer->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "buffer",
 81+                                          width, height, 4, &tiling_mode,
 82+                                          &buffer->base.pitch, 0);
 83 
 84-    return &intel->base;
 85+    return &buffer->base;
 86 }
 87 
 88-struct wld_drawable * context_import(struct wld_context * base,
 89-                                     uint32_t type, union wld_object object,
 90-                                     uint32_t width, uint32_t height,
 91-                                     uint32_t format, uint32_t pitch)
 92+struct wld_buffer * context_import_buffer(struct wld_context * base,
 93+                                          uint32_t type,
 94+                                          union wld_object object,
 95+                                          uint32_t width, uint32_t height,
 96+                                          uint32_t format, uint32_t pitch)
 97 {
 98     struct intel_context * context = intel_context(base);
 99-    struct intel_drawable * intel;
100+    struct intel_buffer * buffer;
101     drm_intel_bo * bo;
102 
103     switch (type)
104@@ -172,13 +173,13 @@ struct wld_drawable * context_import(struct wld_context * base,
105     if (!bo)
106         goto error0;
107 
108-    if (!(intel = new_drawable(width, height, format)))
109+    if (!(buffer = new_buffer(width, height, format)))
110         goto error1;
111 
112-    intel->bo = bo;
113-    intel->base.pitch = pitch;
114+    buffer->bo = bo;
115+    buffer->base.pitch = pitch;
116 
117-    return &intel->base;
118+    return &buffer->base;
119 
120   error1:
121     drm_intel_bo_unreference(bo);
122@@ -196,23 +197,23 @@ void context_destroy(struct wld_context * base)
123 
124 /**** Renderer ****/
125 uint32_t renderer_capabilities(struct wld_renderer * renderer,
126-                               struct wld_drawable * drawable)
127+                               struct wld_buffer * buffer)
128 {
129-    if (drawable->impl == &drawable_impl)
130+    if (buffer->impl == &buffer_impl)
131         return WLD_CAPABILITY_READ | WLD_CAPABILITY_WRITE;
132 
133     return 0;
134 }
135 
136 bool renderer_set_target(struct wld_renderer * base,
137-                         struct wld_drawable * drawable)
138+                         struct wld_buffer * buffer)
139 {
140     struct intel_renderer * renderer = intel_renderer(base);
141 
142-    if (drawable && drawable->impl != &drawable_impl)
143+    if (buffer && buffer->impl != &buffer_impl)
144         return false;
145 
146-    renderer->target = drawable ? intel_drawable(drawable) : NULL;
147+    renderer->target = buffer ? intel_buffer(buffer) : NULL;
148 
149     return true;
150 }
151@@ -229,19 +230,19 @@ void renderer_fill_rectangle(struct wld_renderer * base, uint32_t color,
152 }
153 
154 void renderer_copy_rectangle(struct wld_renderer * base,
155-                             struct wld_drawable * drawable_base,
156+                             struct wld_buffer * buffer_base,
157                              int32_t dst_x, int32_t dst_y,
158                              int32_t src_x, int32_t src_y,
159                              uint32_t width, uint32_t height)
160 {
161     struct intel_renderer * renderer = intel_renderer(base);
162 
163-    if (drawable_base->impl != &drawable_impl)
164+    if (buffer_base->impl != &buffer_impl)
165         return;
166 
167-    struct intel_drawable * drawable = intel_drawable(drawable_base);
168+    struct intel_buffer * buffer = intel_buffer(buffer_base);
169 
170-    xy_src_copy_blt(renderer->batch, drawable->bo, drawable->base.pitch,
171+    xy_src_copy_blt(renderer->batch, buffer->bo, buffer->base.pitch,
172                     src_x, src_y,
173                     renderer->target->bo, renderer->target->base.pitch,
174                     dst_x, dst_y, width, height);
175@@ -329,54 +330,56 @@ void renderer_destroy(struct wld_renderer * base)
176     free(renderer);
177 }
178 
179-bool drawable_map(struct wld_drawable * base)
180+/**** Buffer ****/
181+bool buffer_map(struct wld_buffer * base)
182 {
183-    struct intel_drawable * drawable = intel_drawable(base);
184+    struct intel_buffer * buffer = intel_buffer(base);
185 
186-    if (drm_intel_gem_bo_map_gtt(drawable->bo) != 0)
187+    if (drm_intel_gem_bo_map_gtt(buffer->bo) != 0)
188         return false;
189 
190-    drawable->base.map.data = drawable->bo->virtual;
191+    buffer->base.map.data = buffer->bo->virtual;
192 
193     return true;
194 }
195 
196-bool drawable_unmap(struct wld_drawable * base)
197+bool buffer_unmap(struct wld_buffer * base)
198 {
199-    struct intel_drawable * drawable = intel_drawable(base);
200+    struct intel_buffer * buffer = intel_buffer(base);
201 
202-    if (drm_intel_gem_bo_unmap_gtt(drawable->bo) != 0)
203+    if (drm_intel_gem_bo_unmap_gtt(buffer->bo) != 0)
204         return false;
205 
206-    drawable->base.map.data = NULL;
207+    buffer->base.map.data = NULL;
208 
209     return true;
210 }
211 
212-void drawable_destroy(struct wld_drawable * drawable)
213+void buffer_destroy(struct wld_buffer * base)
214 {
215-    struct intel_drawable * intel = (void *) drawable;
216-    drm_intel_bo_unreference(intel->bo);
217-    free(intel);
218+    struct intel_buffer * buffer = intel_buffer(base);
219+
220+    drm_intel_bo_unreference(buffer->bo);
221+    free(buffer);
222 }
223 
224 /**** Exporter ****/
225-bool exporter_export(struct wld_exporter * exporter, struct wld_drawable * base,
226+bool exporter_export(struct wld_exporter * exporter, struct wld_buffer * base,
227                      uint32_t type, union wld_object * object)
228 {
229-    struct intel_drawable * drawable = intel_drawable(base);
230+    struct intel_buffer * buffer = intel_buffer(base);
231 
232     switch (type)
233     {
234         case WLD_DRM_OBJECT_HANDLE:
235-            object->u32 = drawable->bo->handle;
236+            object->u32 = buffer->bo->handle;
237             return true;
238         case WLD_DRM_OBJECT_PRIME_FD:
239-            if (drm_intel_bo_gem_export_to_prime(drawable->bo, &object->i) != 0)
240+            if (drm_intel_bo_gem_export_to_prime(buffer->bo, &object->i) != 0)
241                 return false;
242             return true;
243         case WLD_DRM_OBJECT_GEM_NAME:
244-            if (drm_intel_bo_flink(drawable->bo, &object->u32) != 0)
245+            if (drm_intel_bo_flink(buffer->bo, &object->u32) != 0)
246                 return false;
247             return true;
248         default:
R interface/drawable.h => interface/buffer.h
+9, -9
 1@@ -1,6 +1,6 @@
 2-/* wld: interface/drawable.h
 3+/* wld: interface/buffer.h
 4  *
 5- * Copyright (c) 2013 Michael Forney
 6+ * Copyright (c) 2013, 2014 Michael Forney
 7  *
 8  * Permission is hereby granted, free of charge, to any person obtaining a copy
 9  * of this software and associated documentation files (the "Software"), to deal
10@@ -21,13 +21,13 @@
11  * SOFTWARE.
12  */
13 
14-static bool drawable_map(struct wld_drawable * drawable);
15-static bool drawable_unmap(struct wld_drawable * drawable);
16-static void drawable_destroy(struct wld_drawable * drawable);
17+static bool buffer_map(struct wld_buffer * drawable);
18+static bool buffer_unmap(struct wld_buffer * drawable);
19+static void buffer_destroy(struct wld_buffer * drawable);
20 
21-static const struct wld_drawable_impl drawable_impl = {
22-    .map = &drawable_map,
23-    .unmap = &drawable_unmap,
24-    .destroy = &drawable_destroy
25+static const struct wld_buffer_impl buffer_impl = {
26+    .map = &buffer_map,
27+    .unmap = &buffer_unmap,
28+    .destroy = &buffer_destroy
29 };
30 
+4, -4
 1@@ -23,18 +23,18 @@
 2 
 3 static struct wld_renderer * context_create_renderer
 4     (struct wld_context * context);
 5-static struct wld_drawable * context_create_drawable
 6+static struct wld_buffer * context_create_buffer
 7     (struct wld_context * context,
 8      uint32_t width, uint32_t height, uint32_t format);
 9-static struct wld_drawable * context_import
10+static struct wld_buffer * context_import_buffer
11     (struct wld_context * context, uint32_t type, union wld_object object,
12      uint32_t width, uint32_t height, uint32_t format, uint32_t pitch);
13 static void context_destroy(struct wld_context * context);
14 
15 static const struct wld_context_impl context_impl = {
16     .create_renderer = &context_create_renderer,
17-    .create_drawable = &context_create_drawable,
18-    .import = &context_import,
19+    .create_buffer = &context_create_buffer,
20+    .import_buffer = &context_import_buffer,
21     .destroy = &context_destroy
22 };
23 
+1, -1
1@@ -23,7 +23,7 @@
2 
3 static void exporter_destroy(struct wld_exporter * exporter);
4 static bool exporter_export(struct wld_exporter * exporter,
5-                            struct wld_drawable * drawable,
6+                            struct wld_buffer * buffer,
7                             uint32_t type, union wld_object * object);
8 
9 static const struct wld_exporter_impl exporter_impl = {
+4, -4
 1@@ -22,14 +22,14 @@
 2  */
 3 
 4 static uint32_t renderer_capabilities(struct wld_renderer * renderer,
 5-                                      struct wld_drawable * drawable);
 6+                                      struct wld_buffer * buffer);
 7 static bool renderer_set_target(struct wld_renderer * renderer,
 8-                                struct wld_drawable * drawable);
 9+                                struct wld_buffer * buffer);
10 static void renderer_fill_rectangle(struct wld_renderer * renderer,
11                                     uint32_t color, int32_t x, int32_t y,
12                                     uint32_t width, uint32_t height);
13 static void renderer_copy_rectangle(struct wld_renderer * renderer,
14-                                    struct wld_drawable * drawable,
15+                                    struct wld_buffer * buffer,
16                                     int32_t dst_x, int32_t dst_y,
17                                     int32_t src_x, int32_t src_y,
18                                     uint32_t width, uint32_t height);
19@@ -37,7 +37,7 @@ static void renderer_copy_rectangle(struct wld_renderer * renderer,
20 static void renderer_fill_region(struct wld_renderer * base, uint32_t color,
21                                  pixman_region32_t * region);
22 static void renderer_copy_region(struct wld_renderer * base,
23-                                 struct wld_drawable * drawable,
24+                                 struct wld_buffer * buffer,
25                                  int32_t dst_x, int32_t dst_y,
26                                  pixman_region32_t * region);
27 #endif
+58, -57
  1@@ -38,9 +38,9 @@ struct pixman_renderer
  2     pixman_glyph_cache_t * glyph_cache;
  3 };
  4 
  5-struct pixman_drawable
  6+struct pixman_buffer
  7 {
  8-    struct wld_drawable base;
  9+    struct wld_buffer base;
 10     pixman_image_t * image;
 11 };
 12 
 13@@ -53,10 +53,10 @@ struct pixman_exporter
 14 #include "interface/context.h"
 15 #define RENDERER_IMPLEMENTS_REGION
 16 #include "interface/renderer.h"
 17-#include "interface/drawable.h"
 18+#include "interface/buffer.h"
 19 #include "interface/exporter.h"
 20 IMPL(pixman, renderer)
 21-IMPL(pixman, drawable)
 22+IMPL(pixman, buffer)
 23 IMPL(pixman, exporter)
 24 
 25 static struct wld_context context = { .impl = &context_impl };
 26@@ -85,29 +85,29 @@ struct wld_renderer * context_create_renderer(struct wld_context * context)
 27     return NULL;
 28 }
 29 
 30-struct wld_drawable * new_drawable(pixman_image_t * image)
 31+static struct wld_buffer * new_buffer(pixman_image_t * image)
 32 {
 33-    struct pixman_drawable * drawable;
 34+    struct pixman_buffer * buffer;
 35 
 36-    if (!(drawable = malloc(sizeof *drawable)))
 37+    if (!(buffer = malloc(sizeof *buffer)))
 38         return NULL;
 39 
 40-    drawable_initialize(&drawable->base, &drawable_impl,
 41-                        pixman_image_get_width(image),
 42-                        pixman_image_get_height(image),
 43-                        format_pixman_to_wld(pixman_image_get_format(image)),
 44-                        pixman_image_get_stride(image));
 45-    drawable->base.map.data = pixman_image_get_data(image);
 46-    drawable->image = image;
 47+    buffer_initialize(&buffer->base, &buffer_impl,
 48+                      pixman_image_get_width(image),
 49+                      pixman_image_get_height(image),
 50+                      format_pixman_to_wld(pixman_image_get_format(image)),
 51+                      pixman_image_get_stride(image));
 52+    buffer->base.map.data = pixman_image_get_data(image);
 53+    buffer->image = image;
 54 
 55-    return &drawable->base;
 56+    return &buffer->base;
 57 }
 58 
 59-struct wld_drawable * context_create_drawable(struct wld_context * context,
 60-                                              uint32_t width, uint32_t height,
 61-                                              uint32_t format)
 62+struct wld_buffer * context_create_buffer(struct wld_context * context,
 63+                                          uint32_t width, uint32_t height,
 64+                                          uint32_t format)
 65 {
 66-    struct wld_drawable * drawable;
 67+    struct wld_buffer * buffer;
 68     pixman_image_t * image;
 69 
 70     image = pixman_image_create_bits(format_wld_to_pixman(format),
 71@@ -116,10 +116,10 @@ struct wld_drawable * context_create_drawable(struct wld_context * context,
 72     if (!image)
 73         goto error0;
 74 
 75-    if (!(drawable = new_drawable(image)))
 76+    if (!(buffer = new_buffer(image)))
 77         goto error1;
 78 
 79-    return drawable;
 80+    return buffer;
 81 
 82   error1:
 83     pixman_image_unref(image);
 84@@ -127,12 +127,13 @@ struct wld_drawable * context_create_drawable(struct wld_context * context,
 85     return NULL;
 86 }
 87 
 88-struct wld_drawable * context_import(struct wld_context * context,
 89-                                     uint32_t type, union wld_object object,
 90-                                     uint32_t width, uint32_t height,
 91-                                     uint32_t format, uint32_t pitch)
 92+struct wld_buffer * context_import_buffer(struct wld_context * context,
 93+                                          uint32_t type,
 94+                                          union wld_object object,
 95+                                          uint32_t width, uint32_t height,
 96+                                          uint32_t format, uint32_t pitch)
 97 {
 98-    struct wld_drawable * drawable;
 99+    struct wld_buffer * buffer;
100     pixman_image_t * image;
101 
102     switch (type)
103@@ -147,10 +148,10 @@ struct wld_drawable * context_import(struct wld_context * context,
104     if (!image)
105         goto error0;
106 
107-    if (!(drawable = new_drawable(image)))
108+    if (!(buffer = new_buffer(image)))
109         goto error1;
110 
111-    return drawable;
112+    return buffer;
113 
114   error1:
115     pixman_image_unref(image);
116@@ -164,40 +165,40 @@ void context_destroy(struct wld_context * context)
117 }
118 
119 uint32_t renderer_capabilities(struct wld_renderer * renderer,
120-                               struct wld_drawable * drawable)
121+                               struct wld_buffer * buffer)
122 {
123-    /* The pixman renderer can read and write to any drawable using it's map
124+    /* The pixman renderer can read and write to any buffer using it's map
125      * implementation. */
126     return WLD_CAPABILITY_READ | WLD_CAPABILITY_WRITE;
127 }
128 
129 static void destroy_image(pixman_image_t * image, void * data)
130 {
131-    struct wld_drawable * drawable = data;
132+    struct wld_buffer * buffer = data;
133 
134-    wld_unmap(drawable);
135+    wld_unmap(buffer);
136 }
137 
138-static pixman_image_t * pixman_image(struct wld_drawable * drawable)
139+static pixman_image_t * pixman_image(struct wld_buffer * buffer)
140 {
141-    if (drawable->impl == &drawable_impl)
142-        return pixman_image_ref(pixman_drawable(drawable)->image);
143+    if (buffer->impl == &buffer_impl)
144+        return pixman_image_ref(pixman_buffer(buffer)->image);
145 
146     union wld_object object;
147 
148-    if (wld_export(drawable, WLD_PIXMAN_OBJECT_IMAGE, &object))
149+    if (wld_export(buffer, WLD_PIXMAN_OBJECT_IMAGE, &object))
150         return object.ptr;
151 
152     struct pixman_exporter * exporter;
153     pixman_image_t * image;
154 
155-    if (!wld_map(drawable))
156+    if (!wld_map(buffer))
157         goto error0;
158 
159-    image = pixman_image_create_bits(format_wld_to_pixman(drawable->format),
160-                                     drawable->width, drawable->height,
161-                                     drawable->map.data, drawable->pitch);
162-    pixman_image_set_destroy_function(image, &destroy_image, drawable);
163+    image = pixman_image_create_bits(format_wld_to_pixman(buffer->format),
164+                                     buffer->width, buffer->height,
165+                                     buffer->map.data, buffer->pitch);
166+    pixman_image_set_destroy_function(image, &destroy_image, buffer);
167 
168     if (!image)
169         goto error1;
170@@ -207,26 +208,26 @@ static pixman_image_t * pixman_image(struct wld_drawable * drawable)
171 
172     exporter_initialize(&exporter->base, &exporter_impl);
173     exporter->image = image;
174-    drawable_add_exporter(drawable, &exporter->base);
175+    buffer_add_exporter(buffer, &exporter->base);
176 
177     return pixman_image_ref(image);
178 
179   error1:
180-    wld_unmap(drawable);
181+    wld_unmap(buffer);
182   error0:
183     return NULL;
184 }
185 
186 bool renderer_set_target(struct wld_renderer * base,
187-                         struct wld_drawable * drawable)
188+                         struct wld_buffer * buffer)
189 {
190     struct pixman_renderer * renderer = pixman_renderer(base);
191 
192     if (renderer->target)
193         pixman_image_unref(renderer->target);
194 
195-    if (drawable)
196-        return (renderer->target = pixman_image(drawable));
197+    if (buffer)
198+        return (renderer->target = pixman_image(buffer));
199 
200     renderer->target = NULL;
201     return true;
202@@ -258,13 +259,13 @@ void renderer_fill_region(struct wld_renderer * base, uint32_t color,
203 }
204 
205 void renderer_copy_rectangle(struct wld_renderer * base,
206-                             struct wld_drawable * drawable,
207+                             struct wld_buffer * buffer,
208                              int32_t dst_x, int32_t dst_y,
209                              int32_t src_x, int32_t src_y,
210                              uint32_t width, uint32_t height)
211 {
212     struct pixman_renderer * renderer = pixman_renderer(base);
213-    pixman_image_t * src = pixman_image(drawable), * dst = renderer->target;
214+    pixman_image_t * src = pixman_image(buffer), * dst = renderer->target;
215 
216     if (!src) return;
217 
218@@ -273,12 +274,12 @@ void renderer_copy_rectangle(struct wld_renderer * base,
219 }
220 
221 void renderer_copy_region(struct wld_renderer * base,
222-                          struct wld_drawable * drawable,
223+                          struct wld_buffer * buffer,
224                           int32_t dst_x, int32_t dst_y,
225                           pixman_region32_t * region)
226 {
227     struct pixman_renderer * renderer = pixman_renderer(base);
228-    pixman_image_t * src = pixman_image(drawable), * dst = renderer->target;
229+    pixman_image_t * src = pixman_image(buffer), * dst = renderer->target;
230 
231     if (!src) return;
232 
233@@ -405,26 +406,26 @@ void renderer_destroy(struct wld_renderer * base)
234     free(renderer);
235 }
236 
237-bool drawable_map(struct wld_drawable * drawable)
238+bool buffer_map(struct wld_buffer * buffer)
239 {
240     return true;
241 }
242 
243-bool drawable_unmap(struct wld_drawable * drawable)
244+bool buffer_unmap(struct wld_buffer * buffer)
245 {
246     return true;
247 }
248 
249-void drawable_destroy(struct wld_drawable * drawable)
250+void buffer_destroy(struct wld_buffer * base)
251 {
252-    struct pixman_drawable * pixman = (void *) drawable;
253+    struct pixman_buffer * buffer = pixman_buffer(base);
254 
255-    pixman_image_unref(pixman->image);
256-    free(pixman);
257+    pixman_image_unref(buffer->image);
258+    free(buffer);
259 }
260 
261 /**** Exporter ****/
262-bool exporter_export(struct wld_exporter * base, struct wld_drawable * drawable,
263+bool exporter_export(struct wld_exporter * base, struct wld_buffer * buffer,
264                      uint32_t type, union wld_object * object)
265 {
266     struct pixman_exporter * exporter = pixman_exporter(base);
+13, -13
 1@@ -40,7 +40,7 @@ void default_fill_region(struct wld_renderer * renderer, uint32_t color,
 2 }
 3 
 4 void default_copy_region(struct wld_renderer * renderer,
 5-                         struct wld_drawable * drawable,
 6+                         struct wld_buffer * buffer,
 7                          int32_t dst_x, int32_t dst_y,
 8                          pixman_region32_t * region)
 9 {
10@@ -51,7 +51,7 @@ void default_copy_region(struct wld_renderer * renderer,
11 
12     while (num_boxes--)
13     {
14-        renderer->impl->copy_rectangle(renderer, drawable,
15+        renderer->impl->copy_rectangle(renderer, buffer,
16                                        dst_x + box->x1, dst_y + box->y1,
17                                        box->x1, box->y1,
18                                        box->x2 - box->x1, box->y2 - box->y1);
19@@ -74,19 +74,19 @@ void wld_destroy_renderer(struct wld_renderer * renderer)
20 
21 EXPORT
22 uint32_t wld_capabilities(struct wld_renderer * renderer,
23-                          struct wld_drawable * drawable)
24+                          struct wld_buffer * buffer)
25 {
26-    return renderer->impl->capabilities(renderer, drawable);
27+    return renderer->impl->capabilities(renderer, buffer);
28 }
29 
30 EXPORT
31-bool wld_set_target_drawable(struct wld_renderer * renderer,
32-                             struct wld_drawable * drawable)
33+bool wld_set_target_buffer(struct wld_renderer * renderer,
34+                           struct wld_buffer * buffer)
35 {
36-    if (!renderer->impl->set_target(renderer, drawable))
37+    if (!renderer->impl->set_target(renderer, buffer))
38         return false;
39 
40-    renderer->target = drawable;
41+    renderer->target = buffer;
42 
43     return true;
44 }
45@@ -107,21 +107,21 @@ void wld_fill_region(struct wld_renderer * renderer, uint32_t color,
46 
47 EXPORT
48 void wld_copy_rectangle(struct wld_renderer * renderer,
49-                        struct wld_drawable * drawable,
50+                        struct wld_buffer * buffer,
51                         int32_t dst_x, int32_t dst_y,
52                         int32_t src_x, int32_t src_y,
53                         uint32_t width, uint32_t height)
54 {
55-    renderer->impl->copy_rectangle(renderer, drawable, dst_x, dst_y,
56-                                   src_x, src_y, width, height);
57+    renderer->impl->copy_rectangle(renderer, buffer, dst_x, dst_y, src_x, src_y,
58+                                   width, height);
59 }
60 
61 EXPORT
62 void wld_copy_region(struct wld_renderer * renderer,
63-                     struct wld_drawable * drawable,
64+                     struct wld_buffer * buffer,
65                      int32_t dst_x, int32_t dst_y, pixman_region32_t * region)
66 {
67-    renderer->impl->copy_region(renderer, drawable, dst_x, dst_y, region);
68+    renderer->impl->copy_region(renderer, buffer, dst_x, dst_y, region);
69 }
70 
71 EXPORT
+16, -15
 1@@ -191,12 +191,12 @@ struct wld_renderer * context_create_renderer(struct wld_context * base)
 2     return wld_create_renderer(context->driver_context);
 3 }
 4 
 5-struct wld_drawable * context_create_drawable(struct wld_context * base,
 6-                                              uint32_t width, uint32_t height,
 7-                                              uint32_t format)
 8+struct wld_buffer * context_create_buffer(struct wld_context * base,
 9+                                          uint32_t width, uint32_t height,
10+                                          uint32_t format)
11 {
12     struct drm_context * context = drm_context(base);
13-    struct wld_drawable * drawable;
14+    struct wld_buffer * buffer;
15     struct wld_exporter * exporter;
16     union wld_object object;
17     struct wl_buffer * wl;
18@@ -204,16 +204,16 @@ struct wld_drawable * context_create_drawable(struct wld_context * base,
19     if (!wld_wayland_drm_has_format(&context->base, format))
20         goto error0;
21 
22-    drawable = wld_create_drawable(context->driver_context, width, height, format);
23+    buffer = wld_create_buffer(context->driver_context, width, height, format);
24 
25-    if (!drawable)
26+    if (!buffer)
27         goto error0;
28 
29-    if (!wld_export(drawable, WLD_DRM_OBJECT_PRIME_FD, &object))
30+    if (!wld_export(buffer, WLD_DRM_OBJECT_PRIME_FD, &object))
31         goto error1;
32 
33     wl = wl_drm_create_prime_buffer(context->wl, object.i, width, height,
34-                                    format, 0, drawable->pitch, 0, 0, 0, 0);
35+                                    format, 0, buffer->pitch, 0, 0, 0, 0);
36     close(object.i);
37 
38     if (!wl)
39@@ -222,22 +222,23 @@ struct wld_drawable * context_create_drawable(struct wld_context * base,
40     if (!(exporter = wayland_create_exporter(wl)))
41         goto error2;
42 
43-    drawable_add_exporter(drawable, exporter);
44+    buffer_add_exporter(buffer, exporter);
45 
46-    return drawable;
47+    return buffer;
48 
49   error2:
50     wl_buffer_destroy(wl);
51   error1:
52-    wld_destroy_drawable(drawable);
53+    wld_destroy_buffer(buffer);
54   error0:
55     return NULL;
56 }
57 
58-struct wld_drawable * context_import(struct wld_context * context,
59-                                     uint32_t type, union wld_object object,
60-                                     uint32_t width, uint32_t height,
61-                                     uint32_t format, uint32_t pitch)
62+struct wld_buffer * context_import_buffer(struct wld_context * context,
63+                                          uint32_t type,
64+                                          union wld_object object,
65+                                          uint32_t width, uint32_t height,
66+                                          uint32_t format, uint32_t pitch)
67 {
68     return NULL;
69 }
+2, -2
 1@@ -31,8 +31,8 @@ struct wl_display;
 2 struct wl_event_queue;
 3 
 4 /**
 5- * Create a new drawable context which creates Wayland buffers through the
 6- * wl_drm interface, backed by hardware specific drawable implementations.
 7+ * Create a new WLD context which creates Wayland buffers through the wl_drm
 8+ * interface, backed by hardware specific buffer implementations.
 9  */
10 struct wld_context * wld_wayland_drm_create_context
11     (struct wl_display * display, struct wl_event_queue * queue);
+15, -14
 1@@ -149,12 +149,12 @@ struct wld_renderer * context_create_renderer(struct wld_context * context)
 2     return wld_create_renderer(wld_pixman_context);
 3 }
 4 
 5-struct wld_drawable * context_create_drawable(struct wld_context * base,
 6-                                              uint32_t width, uint32_t height,
 7-                                              uint32_t format)
 8+struct wld_buffer * context_create_buffer(struct wld_context * base,
 9+                                          uint32_t width, uint32_t height,
10+                                          uint32_t format)
11 {
12     struct shm_context * context = shm_context(base);
13-    struct wld_drawable * drawable;
14+    struct wld_buffer * buffer;
15     struct wld_exporter * exporter;
16     char name[] = "/tmp/wld-XXXXXX";
17     uint32_t pitch = width * format_bytes_per_pixel(format);
18@@ -182,10 +182,10 @@ struct wld_drawable * context_create_drawable(struct wld_context * base,
19         goto error1;
20 
21     object.ptr = data;
22-    drawable = wld_import(wld_pixman_context, WLD_OBJECT_DATA, object,
23-                          width, height, format, pitch);
24+    buffer = wld_import_buffer(wld_pixman_context, WLD_OBJECT_DATA, object,
25+                               width, height, format, pitch);
26 
27-    if (!drawable)
28+    if (!buffer)
29         goto error2;
30 
31     if (!(pool = wl_shm_create_pool(context->wl, fd, size)))
32@@ -200,15 +200,15 @@ struct wld_drawable * context_create_drawable(struct wld_context * base,
33     if (!(exporter = wayland_create_exporter(wl)))
34         goto error4;
35 
36-    drawable_add_exporter(drawable, exporter);
37+    buffer_add_exporter(buffer, exporter);
38     close(fd);
39 
40-    return drawable;
41+    return buffer;
42 
43   error4:
44     wl_buffer_destroy(wl);
45   error3:
46-    wld_destroy_drawable(drawable);
47+    wld_destroy_buffer(buffer);
48   error2:
49     munmap(object.ptr, size);
50   error1:
51@@ -217,10 +217,11 @@ struct wld_drawable * context_create_drawable(struct wld_context * base,
52     return NULL;
53 }
54 
55-struct wld_drawable * context_import(struct wld_context * context,
56-                                     uint32_t type, union wld_object object,
57-                                     uint32_t width, uint32_t height,
58-                                     uint32_t format, uint32_t pitch)
59+struct wld_buffer * context_import_buffer(struct wld_context * context,
60+                                          uint32_t type,
61+                                          union wld_object object,
62+                                          uint32_t width, uint32_t height,
63+                                          uint32_t format, uint32_t pitch)
64 {
65     return NULL;
66 }
+2, -2
 1@@ -31,8 +31,8 @@ struct wl_display;
 2 struct wl_event_queue;
 3 
 4 /**
 5- * Create a new drawable context which creates Wayland buffers through the
 6- * wl_shm interface, back by Pixman drawables.
 7+ * Create a new WLD context which creates Wayland buffers through the wl_shm
 8+ * interface, backed by Pixman images.
 9  */
10 struct wld_context * wld_shm_create_context(struct wl_display * display,
11                                             struct wl_event_queue * queue);
+1, -1
1@@ -139,7 +139,7 @@ struct wld_exporter * wayland_create_exporter(struct wl_buffer * buffer)
2     return &exporter->base;
3 }
4 
5-bool exporter_export(struct wld_exporter * base, struct wld_drawable * drawable,
6+bool exporter_export(struct wld_exporter * base, struct wld_buffer * buffer,
7                      uint32_t type, union wld_object * object)
8 {
9     struct wayland_exporter * exporter = wayland_exporter(base);
+3, -3
 1@@ -50,9 +50,9 @@ enum wld_wayland_object_type
 2 };
 3 
 4 /**
 5- * Create a new drawing context which uses various available Wayland interfaces
 6- * (such as wl_shm and wl_drm) to create buffers backed by drawables specific
 7- * to the interface.
 8+ * Create a new WLD context which uses various available Wayland interfaces
 9+ * (such as wl_shm and wl_drm) to create wl_buffers backed by implementations
10+ * specific to the interface.
11  *
12  * You can specify the particular interface you want to use by specifying them
13  * as arguments. Interfaces will be tried in the order they are given.
+24, -24
  1@@ -86,34 +86,35 @@ struct font
  2 struct wld_context_impl
  3 {
  4     struct wld_renderer * (* create_renderer)(struct wld_context * context);
  5-    struct wld_drawable * (* create_drawable)(struct wld_context * context,
  6-                                              uint32_t width, uint32_t height,
  7-                                              uint32_t format);
  8-    struct wld_drawable * (* import)(struct wld_context * context,
  9-                                     uint32_t type, union wld_object object,
 10-                                     uint32_t width, uint32_t height,
 11-                                     uint32_t format, uint32_t pitch);
 12+    struct wld_buffer * (* create_buffer)(struct wld_context * context,
 13+                                          uint32_t width, uint32_t height,
 14+                                          uint32_t format);
 15+    struct wld_buffer * (* import_buffer)(struct wld_context * context,
 16+                                          uint32_t type,
 17+                                          union wld_object object,
 18+                                          uint32_t width, uint32_t height,
 19+                                          uint32_t format, uint32_t pitch);
 20     void (* destroy)(struct wld_context * context);
 21 };
 22 
 23 struct wld_renderer_impl
 24 {
 25     uint32_t (* capabilities)(struct wld_renderer * renderer,
 26-                              struct wld_drawable * buffer);
 27+                              struct wld_buffer * buffer);
 28     bool (* set_target)(struct wld_renderer * renderer,
 29-                        struct wld_drawable * drawable);
 30+                        struct wld_buffer * buffer);
 31     void (* fill_rectangle)(struct wld_renderer * renderer,
 32                             uint32_t color, int32_t x, int32_t y,
 33                             uint32_t width, uint32_t height);
 34     void (* fill_region)(struct wld_renderer * renderer,
 35                          uint32_t color, pixman_region32_t * region);
 36     void (* copy_rectangle)(struct wld_renderer * renderer,
 37-                            struct wld_drawable * src,
 38+                            struct wld_buffer * src,
 39                             int32_t dst_x, int32_t dst_y,
 40                             int32_t src_x, int32_t src_y,
 41                             uint32_t width, uint32_t height);
 42     void (* copy_region)(struct wld_renderer * renderer,
 43-                         struct wld_drawable * src,
 44+                         struct wld_buffer * src,
 45                          int32_t dst_x, int32_t dst_y,
 46                          pixman_region32_t * region);
 47     void (* draw_text)(struct wld_renderer * renderer,
 48@@ -124,11 +125,11 @@ struct wld_renderer_impl
 49     void (* destroy)(struct wld_renderer * renderer);
 50 };
 51 
 52-struct wld_drawable_impl
 53+struct wld_buffer_impl
 54 {
 55-    bool (* map)(struct wld_drawable * drawable);
 56-    bool (* unmap)(struct wld_drawable * drawable);
 57-    void (* destroy)(struct wld_drawable * drawable);
 58+    bool (* map)(struct wld_buffer * buffer);
 59+    bool (* unmap)(struct wld_buffer * buffer);
 60+    void (* destroy)(struct wld_buffer * buffer);
 61 };
 62 
 63 struct wld_exporter
 64@@ -139,8 +140,7 @@ struct wld_exporter
 65 
 66 struct wld_exporter_impl
 67 {
 68-    bool (* export)(struct wld_exporter * exporter,
 69-                    struct wld_drawable * drawable,
 70+    bool (* export)(struct wld_exporter * exporter, struct wld_buffer * buffer,
 71                     uint32_t type, union wld_object * object);
 72     void (* destroy)(struct wld_exporter * exporter);
 73 };
 74@@ -198,7 +198,7 @@ void default_fill_region(struct wld_renderer * renderer, uint32_t color,
 75  * This default copy_region method is implemented in terms of copy_rectangle.
 76  */
 77 void default_copy_region(struct wld_renderer * renderer,
 78-                         struct wld_drawable * drawable,
 79+                         struct wld_buffer * buffer,
 80                          int32_t dst_x, int32_t dst_y,
 81                          pixman_region32_t * region);
 82 
 83@@ -208,13 +208,13 @@ void context_initialize(struct wld_context * context,
 84 void renderer_initialize(struct wld_renderer * renderer,
 85                          const struct wld_renderer_impl * impl);
 86 
 87-void drawable_initialize(struct wld_drawable * drawable,
 88-                         const struct wld_drawable_impl * impl,
 89-                         uint32_t width, uint32_t height,
 90-                         uint32_t format, uint32_t pitch);
 91+void buffer_initialize(struct wld_buffer * buffer,
 92+                       const struct wld_buffer_impl * impl,
 93+                       uint32_t width, uint32_t height,
 94+                       uint32_t format, uint32_t pitch);
 95 
 96-void drawable_add_exporter(struct wld_drawable * drawable,
 97-                           struct wld_exporter * exporter);
 98+void buffer_add_exporter(struct wld_buffer * buffer,
 99+                         struct wld_exporter * exporter);
100 
101 void exporter_initialize(struct wld_exporter * exporter,
102                          const struct wld_exporter_impl * impl);
M wld.h
+22, -22
  1@@ -68,14 +68,14 @@ struct wld_context
  2 
  3 struct wld_renderer * wld_create_renderer(struct wld_context * context);
  4 
  5-struct wld_drawable * wld_create_drawable(struct wld_context * context,
  6-                                          uint32_t width, uint32_t height,
  7-                                          uint32_t format);
  8+struct wld_buffer * wld_create_buffer(struct wld_context * context,
  9+                                      uint32_t width, uint32_t height,
 10+                                      uint32_t format);
 11 
 12-struct wld_drawable * wld_import(struct wld_context * context, uint32_t type,
 13-                                 union wld_object object,
 14-                                 uint32_t width, uint32_t height,
 15-                                 uint32_t format, uint32_t pitch);
 16+struct wld_buffer * wld_import_buffer(struct wld_context * context,
 17+                                      uint32_t type, union wld_object object,
 18+                                      uint32_t width, uint32_t height,
 19+                                      uint32_t format, uint32_t pitch);
 20 
 21 void wld_destroy_context(struct wld_context * context);
 22 
 23@@ -144,10 +144,12 @@ static inline void wld_font_text_extents(struct wld_font * font,
 24     wld_font_text_extents_n(font, text, INT32_MAX, extents);
 25 }
 26 
 27-/**** Drawables ****/
 28+/**** Buffers ****/
 29 
 30-struct wld_drawable
 31+struct wld_buffer
 32 {
 33+    const struct wld_buffer_impl * const impl;
 34+
 35     uint32_t width, height;
 36     unsigned long pitch;
 37     enum wld_format format;
 38@@ -159,27 +161,25 @@ struct wld_drawable
 39     } map;
 40 
 41     struct wld_exporter * exporters;
 42-
 43-    const struct wld_drawable_impl * impl;
 44 };
 45 
 46-bool wld_map(struct wld_drawable * drawable);
 47-bool wld_unmap(struct wld_drawable * drawable);
 48+bool wld_map(struct wld_buffer * buffer);
 49+bool wld_unmap(struct wld_buffer * buffer);
 50 
 51-bool wld_export(struct wld_drawable * drawable,
 52+bool wld_export(struct wld_buffer * buffer,
 53                 uint32_t type, union wld_object * object);
 54 
 55 /**
 56- * Destroy a drawable (created with any context).
 57+ * Destroy a buffer.
 58  */
 59-void wld_destroy_drawable(struct wld_drawable * drawable);
 60+void wld_destroy_buffer(struct wld_buffer * buffer);
 61 
 62 /**** Renderers ****/
 63 
 64 struct wld_renderer
 65 {
 66     const struct wld_renderer_impl * const impl;
 67-    struct wld_drawable * target;
 68+    struct wld_buffer * target;
 69 };
 70 
 71 enum wld_capability
 72@@ -191,10 +191,10 @@ enum wld_capability
 73 void wld_destroy_renderer(struct wld_renderer * renderer);
 74 
 75 uint32_t wld_capabilities(struct wld_renderer * renderer,
 76-                          struct wld_drawable * drawable);
 77+                          struct wld_buffer * buffer);
 78 
 79 bool wld_set_target_buffer(struct wld_renderer * renderer,
 80-                           struct wld_drawable * drawable);
 81+                           struct wld_buffer * buffer);
 82 
 83 void wld_fill_rectangle(struct wld_renderer * renderer, uint32_t color,
 84                         int32_t x, int32_t y, uint32_t width, uint32_t height);
 85@@ -203,17 +203,17 @@ void wld_fill_region(struct wld_renderer * renderer, uint32_t color,
 86                      pixman_region32_t * region);
 87 
 88 void wld_copy_rectangle(struct wld_renderer * renderer,
 89-                        struct wld_drawable * drawable,
 90+                        struct wld_buffer * buffer,
 91                         int32_t dst_x, int32_t dst_y,
 92                         int32_t src_x, int32_t src_y,
 93                         uint32_t width, uint32_t height);
 94 
 95 void wld_copy_region(struct wld_renderer * renderer,
 96-                     struct wld_drawable * drawable,
 97+                     struct wld_buffer * buffer,
 98                      int32_t dst_x, int32_t dst_y, pixman_region32_t * region);
 99 
100 /**
101- * Draw a UTF-8 text string to the given drawable.
102+ * Draw a UTF-8 text string to the given buffer.
103  *
104  * @param length    The maximum number of bytes in the string to process
105  * @param extents   If not NULL, will be initialized to the extents of the