commit 3e011e5
Michael Forney
·
2013-07-25 06:52:32 +0000 UTC
parent 13a9267
Add copy_{rectangle,region} operations
6 files changed,
+150,
-0
+37,
-0
1@@ -23,6 +23,8 @@
2
3 #include "wld-private.h"
4
5+#include <assert.h>
6+
7 void default_fill_region(struct wld_drawable * drawable, uint32_t color,
8 pixman_region32_t * region)
9 {
10@@ -40,6 +42,24 @@ void default_fill_region(struct wld_drawable * drawable, uint32_t color,
11 }
12 }
13
14+void default_copy_region(struct wld_drawable * src, struct wld_drawable * dst,
15+ pixman_region32_t * region,
16+ int32_t dst_x, int32_t dst_y)
17+{
18+ pixman_box32_t * box;
19+ int num_boxes;
20+
21+ box = pixman_region32_rectangles(region, &num_boxes);
22+
23+ while (num_boxes--)
24+ {
25+ dst->interface->copy_rectangle(src, dst, box->x1, box->y1,
26+ dst_x + box->x1, dst_y + box->y1,
27+ box->x2 - box->x1, box->y2 - box->y1);
28+ ++box;
29+ }
30+}
31+
32 void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
33 int32_t x, int32_t y, uint32_t width, uint32_t height)
34 {
35@@ -52,6 +72,23 @@ void wld_fill_region(struct wld_drawable * drawable, uint32_t color,
36 drawable->interface->fill_region(drawable, color, region);
37 }
38
39+void wld_copy_rectangle(struct wld_drawable * src, struct wld_drawable * dst,
40+ int32_t src_x, int32_t src_y,
41+ int32_t dst_x, int32_t dst_y,
42+ uint32_t width, uint32_t height)
43+{
44+ assert(src->interface == dst->interface);
45+ dst->interface->copy_rectangle(src, dst, src_x, src_y, dst_x, dst_y,
46+ width, height);
47+}
48+
49+void wld_copy_region(struct wld_drawable * src, struct wld_drawable * dst,
50+ pixman_region32_t * region, int32_t dst_x, int32_t dst_y)
51+{
52+ assert(src->interface == dst->interface);
53+ dst->interface->copy_region(src, dst, region, dst_x, dst_y);
54+}
55+
56 void wld_draw_text_utf8_n(struct wld_drawable * drawable,
57 struct wld_font * font_base, uint32_t color,
58 int32_t x, int32_t y,
M
intel.c
+20,
-0
1@@ -52,6 +52,11 @@ _Static_assert(offsetof(struct intel_drawable, drm) == 0,
2 static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
3 int32_t x, int32_t y,
4 uint32_t width, uint32_t height);
5+static void intel_copy_rectangle(struct wld_drawable * src,
6+ struct wld_drawable * dst,
7+ int32_t src_x, int32_t src_y,
8+ int32_t dst_x, int32_t dst_y,
9+ uint32_t width, uint32_t height);
10 static void intel_draw_text_utf8(struct wld_drawable * drawable,
11 struct font * font, uint32_t color,
12 int32_t x, int32_t y,
13@@ -62,6 +67,8 @@ static void intel_destroy(struct wld_drawable * drawable);
14 const static struct wld_draw_interface intel_draw = {
15 .fill_rectangle = &intel_fill_rectangle,
16 .fill_region = &default_fill_region,
17+ .copy_rectangle = &intel_copy_rectangle,
18+ .copy_region = &default_copy_region,
19 .draw_text_utf8 = &intel_draw_text_utf8,
20 .flush = &intel_flush,
21 .destroy = &intel_destroy
22@@ -135,6 +142,19 @@ static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
23 x, y, x + width, y + height, color);
24 }
25
26+static void intel_copy_rectangle(struct wld_drawable * src_drawable,
27+ struct wld_drawable * dst_drawable,
28+ int32_t src_x, int32_t src_y,
29+ int32_t dst_x, int32_t dst_y,
30+ uint32_t width, uint32_t height)
31+{
32+ struct intel_drawable * src = (void *) src_drawable;
33+ struct intel_drawable * dst = (void *) dst_drawable;
34+
35+ xy_src_copy_blt(&dst->context->batch, src->bo, src->drm.pitch, src_x, src_y,
36+ dst->bo, dst->drm.pitch, dst_x, dst_y, width, height);
37+}
38+
39 static void intel_draw_text_utf8(struct wld_drawable * drawable,
40 struct font * font, uint32_t color,
41 int32_t x, int32_t y,
M
pixman.c
+42,
-0
1@@ -51,6 +51,15 @@ static void pixman_fill_rectangle(struct wld_drawable * drawable,
2 uint32_t width, uint32_t height);
3 static void pixman_fill_region(struct wld_drawable * drawable, uint32_t color,
4 pixman_region32_t * region);
5+static void pixman_copy_rectangle(struct wld_drawable * src,
6+ struct wld_drawable * dst,
7+ int32_t src_x, int32_t src_y,
8+ int32_t dst_x, int32_t dst_y,
9+ uint32_t width, uint32_t height);
10+static void pixman_copy_region(struct wld_drawable * src,
11+ struct wld_drawable * dst,
12+ pixman_region32_t * region,
13+ int32_t dst_x, int32_t dst_y);
14 static void pixman_draw_text_utf8(struct wld_drawable * drawable,
15 struct font * font, uint32_t color,
16 int32_t x, int32_t y,
17@@ -61,6 +70,8 @@ static void pixman_destroy(struct wld_drawable * drawable);
18 const static struct wld_draw_interface pixman_draw = {
19 .fill_rectangle = &pixman_fill_rectangle,
20 .fill_region = &pixman_fill_region,
21+ .copy_rectangle = &pixman_copy_rectangle,
22+ .copy_region = &pixman_copy_region,
23 .draw_text_utf8 = &pixman_draw_text_utf8,
24 .flush = &pixman_flush,
25 .destroy = &pixman_destroy
26@@ -155,6 +166,37 @@ static void pixman_fill_region(struct wld_drawable * drawable, uint32_t color,
27 num_boxes, boxes);
28 }
29
30+static void pixman_copy_rectangle(struct wld_drawable * src_drawable,
31+ struct wld_drawable * dst_drawable,
32+ int32_t src_x, int32_t src_y,
33+ int32_t dst_x, int32_t dst_y,
34+ uint32_t width, uint32_t height)
35+{
36+ struct pixman_drawable * src = (void *) src_drawable;
37+ struct pixman_drawable * dst = (void *) dst_drawable;
38+
39+ pixman_image_composite32(PIXMAN_OP_SRC, src->image, NULL, dst->image,
40+ src_x, src_y, 0, 0, dst_x, dst_y, width, height);
41+}
42+
43+static void pixman_copy_region(struct wld_drawable * src_drawable,
44+ struct wld_drawable * dst_drawable,
45+ pixman_region32_t * region,
46+ int32_t dst_x, int32_t dst_y)
47+{
48+ struct pixman_drawable * src = (void *) src_drawable;
49+ struct pixman_drawable * dst = (void *) dst_drawable;
50+
51+ pixman_image_set_clip_region32(src->image, region);
52+ pixman_image_composite32(PIXMAN_OP_SRC, src->image, NULL, dst->image,
53+ region->extents.x1, region->extents.y1, 0, 0,
54+ region->extents.x1 + dst_x,
55+ region->extents.y1 + dst_y,
56+ region->extents.x2 - region->extents.x1,
57+ region->extents.y2 - region->extents.y1);
58+ pixman_image_set_clip_region32(src->image, NULL);
59+}
60+
61 static inline uint8_t reverse(uint8_t byte)
62 {
63 byte = ((byte << 1) & 0xaa) | ((byte >> 1) & 0x55);
+28,
-0
1@@ -63,6 +63,15 @@ static void wayland_fill_rectangle(struct wld_drawable * drawable,
2 uint32_t width, uint32_t height);
3 static void wayland_fill_region(struct wld_drawable * drawable, uint32_t color,
4 pixman_region32_t * region);
5+static void wayland_copy_rectangle(struct wld_drawable * src,
6+ struct wld_drawable * dst,
7+ int32_t src_x, int32_t src_y,
8+ int32_t dst_x, int32_t dst_y,
9+ uint32_t width, uint32_t height);
10+static void wayland_copy_region(struct wld_drawable * src,
11+ struct wld_drawable * dst,
12+ pixman_region32_t * region,
13+ int32_t dst_x, int32_t dst_y);
14 static void wayland_draw_text_utf8(struct wld_drawable * drawable,
15 struct font * font, uint32_t color,
16 int32_t x, int32_t y,
17@@ -77,6 +86,8 @@ const struct wl_callback_listener sync_listener = {
18 const struct wld_draw_interface wayland_draw = {
19 .fill_rectangle = &wayland_fill_rectangle,
20 .fill_region = &wayland_fill_region,
21+ .copy_rectangle = &wayland_copy_rectangle,
22+ .copy_region = &wayland_copy_region,
23 .draw_text_utf8 = &wayland_draw_text_utf8,
24 .flush = &wayland_flush,
25 .destroy = &wayland_destroy
26@@ -270,6 +281,23 @@ static void wayland_fill_region(struct wld_drawable * drawable, uint32_t color,
27 wld_fill_region(BACKBUF(wayland).drawable, color, region);
28 }
29
30+static void wayland_copy_rectangle(struct wld_drawable * src_drawable,
31+ struct wld_drawable * dst_drawable,
32+ int32_t src_x, int32_t src_y,
33+ int32_t dst_x, int32_t dst_y,
34+ uint32_t width, uint32_t height)
35+{
36+ fprintf(stderr, "wayland: Copy rectangle is not implemented\n");
37+}
38+
39+static void wayland_copy_region(struct wld_drawable * src_drawable,
40+ struct wld_drawable * dst_drawable,
41+ pixman_region32_t * region,
42+ int32_t dst_x, int32_t dst_y)
43+{
44+ fprintf(stderr, "wayland: Copy region is not implemented\n");
45+}
46+
47 static void wayland_draw_text_utf8(struct wld_drawable * drawable,
48 struct font * font, uint32_t color,
49 int32_t x, int32_t y,
+15,
-0
1@@ -83,6 +83,14 @@ struct wld_draw_interface
2 uint32_t width, uint32_t height);
3 void (* fill_region)(struct wld_drawable * drawable, uint32_t color,
4 pixman_region32_t * region);
5+ void (* copy_rectangle)(struct wld_drawable * src,
6+ struct wld_drawable * dst,
7+ int32_t src_x, int32_t src_y,
8+ int32_t dst_x, int32_t dst_y,
9+ uint32_t width, uint32_t height);
10+ void (* copy_region)(struct wld_drawable * src, struct wld_drawable * dst,
11+ pixman_region32_t * region,
12+ int32_t dst_x, int32_t dst_y);
13 void (* draw_text_utf8)(struct wld_drawable * drawable,
14 struct font * font, uint32_t color,
15 int32_t x, int32_t y,
16@@ -115,5 +123,12 @@ static inline uint8_t format_bytes_per_pixel(enum wld_format format)
17 void default_fill_region(struct wld_drawable * drawable, uint32_t color,
18 pixman_region32_t * region);
19
20+/**
21+ * This default copy_region method is implemented in terms of copy_rectangle.
22+ */
23+void default_copy_region(struct wld_drawable * src, struct wld_drawable * dst,
24+ pixman_region32_t * region,
25+ int32_t dst_x, int32_t dst_y);
26+
27 #endif
28
M
wld.h
+8,
-0
1@@ -129,6 +129,14 @@ void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
2 void wld_fill_region(struct wld_drawable * drawable, uint32_t color,
3 pixman_region32_t * region);
4
5+void wld_copy_rectangle(struct wld_drawable * src, struct wld_drawable * dst,
6+ int32_t src_x, int32_t src_y,
7+ int32_t dst_x, int32_t dst_y,
8+ uint32_t width, uint32_t height);
9+
10+void wld_copy_region(struct wld_drawable * src, struct wld_drawable * dst,
11+ pixman_region32_t * region, int32_t dst_x, int32_t dst_y);
12+
13 void wld_draw_text_utf8_n(struct wld_drawable * drawable,
14 struct wld_font * font, uint32_t color,
15 int32_t x, int32_t y,