commit af4885f

Michael Forney  ·  2013-09-10 08:15:59 +0000 UTC
parent 95a78e6
Add map operation
5 files changed,  +69, -17
M wld.h
+5, -0
 1@@ -111,6 +111,11 @@ void wld_write(struct wld_drawable * drawable, const void * data, size_t size)
 2     drawable->interface->write(drawable, data, size);
 3 }
 4 
 5+pixman_image_t * wld_map(struct wld_drawable * drawable)
 6+{
 7+    return drawable->interface->map(drawable);
 8+}
 9+
10 void wld_flush(struct wld_drawable * drawable)
11 {
12     drawable->interface->flush(drawable);
+37, -4
  1@@ -43,6 +43,7 @@ struct intel_drawable
  2 
  3     struct wld_intel_context * context;
  4     drm_intel_bo * bo;
  5+    pixman_image_t * virtual;
  6 };
  7 
  8 _Static_assert(offsetof(struct intel_drawable, drm) == 0,
  9@@ -64,6 +65,7 @@ static void intel_draw_text_utf8(struct wld_drawable * drawable,
 10                                  struct wld_extents * extents);
 11 static void intel_write(struct wld_drawable * drawable,
 12                         const void * data, size_t size);
 13+static pixman_image_t * intel_map(struct wld_drawable * drawable);
 14 static void intel_flush(struct wld_drawable * drawable);
 15 static void intel_destroy(struct wld_drawable * drawable);
 16 
 17@@ -89,6 +91,7 @@ const static struct wld_draw_interface intel_draw = {
 18     .copy_region = &default_copy_region,
 19     .draw_text_utf8 = &intel_draw_text_utf8,
 20     .write = &intel_write,
 21+    .map = &intel_map,
 22     .flush = &intel_flush,
 23     .destroy = &intel_destroy
 24 };
 25@@ -130,7 +133,8 @@ void intel_destroy_context(struct wld_intel_context * context)
 26 }
 27 
 28 static struct intel_drawable * new_drawable(struct wld_intel_context * context,
 29-                                            uint32_t width, uint32_t height)
 30+                                            uint32_t width, uint32_t height,
 31+                                            uint32_t format)
 32 {
 33     struct intel_drawable * intel;
 34 
 35@@ -140,7 +144,9 @@ static struct intel_drawable * new_drawable(struct wld_intel_context * context,
 36     intel->drm.base.interface = &intel_draw;
 37     intel->drm.base.width = width;
 38     intel->drm.base.height = height;
 39+    intel->drm.base.format = format;
 40     intel->context = context;
 41+    intel->virtual = NULL;
 42 
 43     return intel;
 44 }
 45@@ -152,7 +158,7 @@ struct drm_drawable * intel_create_drawable
 46     struct intel_drawable * intel;
 47     uint32_t tiling_mode = width >= 128 ? I915_TILING_X : I915_TILING_NONE;
 48 
 49-    if (!(intel = new_drawable(context, width, height)))
 50+    if (!(intel = new_drawable(context, width, height, format)))
 51         return NULL;
 52 
 53     intel->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "drawable",
 54@@ -171,7 +177,7 @@ struct drm_drawable * intel_import(struct wld_intel_context * context,
 55     struct intel_drawable * intel;
 56     uint32_t size = width * height * 4;
 57 
 58-    if (!(intel = new_drawable(context, width, height)))
 59+    if (!(intel = new_drawable(context, width, height, format)))
 60         return NULL;
 61 
 62     intel->bo = drm_intel_bo_gem_create_from_prime(context->bufmgr,
 63@@ -189,7 +195,7 @@ struct drm_drawable * intel_import_gem(struct wld_intel_context * context,
 64 {
 65     struct intel_drawable * intel;
 66 
 67-    if (!(intel = new_drawable(context, width, height)))
 68+    if (!(intel = new_drawable(context, width, height, format)))
 69         return NULL;
 70 
 71     intel->bo = drm_intel_bo_gem_create_from_name(context->bufmgr, "drawable",
 72@@ -311,6 +317,33 @@ static void intel_write(struct wld_drawable * drawable,
 73     drm_intel_bo_subdata(intel->bo, 0, size, data);
 74 }
 75 
 76+static void destroy_virtual(pixman_image_t * image, void * data)
 77+{
 78+    struct intel_drawable * intel = data;
 79+
 80+    drm_intel_gem_bo_unmap_gtt(intel->bo);
 81+    intel->virtual = NULL;
 82+}
 83+
 84+pixman_image_t * intel_map(struct wld_drawable * drawable)
 85+{
 86+    struct intel_drawable * intel = (void *) drawable;
 87+
 88+    if (!intel->virtual)
 89+    {
 90+        drm_intel_gem_bo_map_gtt(intel->bo);
 91+        intel->virtual = pixman_image_create_bits_no_clear
 92+            (pixman_format(drawable->format), drawable->width, drawable->height,
 93+             intel->bo->virtual, drawable->pitch);
 94+        pixman_image_set_destroy_function(intel->virtual, &destroy_virtual,
 95+                                          intel);
 96+    }
 97+    else
 98+        pixman_image_ref(intel->virtual);
 99+
100+    return intel->virtual;
101+}
102+
103 static void intel_flush(struct wld_drawable * drawable)
104 {
105     struct intel_drawable * intel = (void *) drawable;
+10, -13
 1@@ -67,6 +67,7 @@ static void pixman_draw_text_utf8(struct wld_drawable * drawable,
 2                                   struct wld_extents * extents);
 3 static void pixman_write(struct wld_drawable * drawable,
 4                          const void * data, size_t size);
 5+static pixman_image_t * pixman_map(struct wld_drawable * drawable);
 6 static void pixman_flush(struct wld_drawable * drawable);
 7 static void pixman_destroy(struct wld_drawable * drawable);
 8 
 9@@ -77,23 +78,11 @@ const static struct wld_draw_interface pixman_draw = {
10     .copy_region = &pixman_copy_region,
11     .draw_text_utf8 = &pixman_draw_text_utf8,
12     .write = &pixman_write,
13+    .map = &pixman_map,
14     .flush = &pixman_flush,
15     .destroy = &pixman_destroy
16 };
17 
18-static inline pixman_format_code_t pixman_format(uint32_t format)
19-{
20-    switch (format)
21-    {
22-        case WLD_FORMAT_ARGB8888:
23-            return PIXMAN_a8r8g8b8;
24-        case WLD_FORMAT_XRGB8888:
25-            return PIXMAN_x8r8g8b8;
26-        default:
27-            return 0;
28-    }
29-}
30-
31 struct wld_pixman_context * wld_pixman_create_context()
32 {
33     struct wld_pixman_context * context;
34@@ -128,6 +117,7 @@ struct wld_drawable * wld_pixman_create_drawable
35     pixman->base.interface = &pixman_draw;
36     pixman->base.width = width;
37     pixman->base.height = height;
38+    pixman->base.format = format;
39     pixman->base.pitch = pitch;
40 
41     pixman->context = context;
42@@ -312,6 +302,13 @@ static void pixman_write(struct wld_drawable * drawable,
43     memcpy(pixman_image_get_data(pixman->image), data, size);
44 }
45 
46+pixman_image_t * pixman_map(struct wld_drawable * drawable)
47+{
48+    struct pixman_drawable * pixman = (void *) drawable;
49+
50+    return pixman_image_ref(pixman->image);
51+}
52+
53 static void pixman_flush(struct wld_drawable * drawable)
54 {
55 }
+14, -0
 1@@ -98,6 +98,7 @@ struct wld_draw_interface
 2                             struct wld_extents * extents);
 3     void (* write)(struct wld_drawable * drawable,
 4                    const void * data, size_t size);
 5+    pixman_image_t * (* map)(struct wld_drawable * drawable);
 6     void (* flush)(struct wld_drawable * drawable);
 7     void (* destroy)(struct wld_drawable * drawable);
 8 };
 9@@ -120,6 +121,19 @@ static inline uint8_t format_bytes_per_pixel(enum wld_format format)
10     }
11 }
12 
13+static inline pixman_format_code_t pixman_format(uint32_t format)
14+{
15+    switch (format)
16+    {
17+        case WLD_FORMAT_ARGB8888:
18+            return PIXMAN_a8r8g8b8;
19+        case WLD_FORMAT_XRGB8888:
20+            return PIXMAN_x8r8g8b8;
21+        default:
22+            return 0;
23+    }
24+}
25+
26 /**
27  * This default fill_region method is implemented in terms of fill_rectangle.
28  */
M wld.h
+3, -0
 1@@ -116,6 +116,7 @@ struct wld_drawable
 2 {
 3     uint32_t width, height;
 4     unsigned long pitch;
 5+    enum wld_format format;
 6 
 7     const struct wld_draw_interface * interface;
 8 };
 9@@ -163,6 +164,8 @@ static inline void wld_draw_text_utf8(struct wld_drawable * drawable,
10 
11 void wld_write(struct wld_drawable * drawable, const void * data, size_t size);
12 
13+pixman_image_t * wld_map(struct wld_drawable * drawable);
14+
15 void wld_flush(struct wld_drawable * drawable);
16 
17 #endif