commit bd5e82a
Michael Forney
·
2013-07-25 05:17:18 +0000 UTC
parent b8b5c06
Use cleaner API for filling rectangle(s) Specify coordinates explicitly for fill_rectangle, and replace fill_rectangles with fill_region.
6 files changed,
+71,
-71
+18,
-17
1@@ -23,32 +23,33 @@
2
3 #include "wld-private.h"
4
5-void default_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
6- pixman_rectangle16_t * rectangle)
7+void default_fill_region(struct wld_drawable * drawable, uint32_t color,
8+ pixman_region32_t * region)
9 {
10- wld_fill_rectangles(drawable, color, rectangle, 1);
11-}
12+ pixman_box32_t * boxes;
13+ int num_boxes;
14+ uint32_t index;
15
16-void default_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
17- pixman_rectangle16_t * rectangles,
18- uint32_t num_rectangles)
19-{
20- while (num_rectangles--)
21- wld_fill_rectangle(drawable, color, &rectangles[num_rectangles]);
22+ boxes = pixman_region32_rectangles(region, &num_boxes);
23+
24+ for (index = 0; index < num_boxes; ++index)
25+ {
26+ wld_fill_rectangle(drawable, color, boxes[index].x1, boxes[index].y1,
27+ boxes[index].x2 - boxes[index].x1,
28+ boxes[index].y2 - boxes[index].y1);
29+ }
30 }
31
32 void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
33- pixman_rectangle16_t * rectangle)
34+ int32_t x, int32_t y, uint32_t width, uint32_t height)
35 {
36- drawable->interface->fill_rectangle(drawable, color, rectangle);
37+ drawable->interface->fill_rectangle(drawable, color, x, y, width, height);
38 }
39
40-void wld_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
41- pixman_rectangle16_t * rectangles,
42- uint32_t num_rectangles)
43+void wld_fill_region(struct wld_drawable * drawable, uint32_t color,
44+ pixman_region32_t * region)
45 {
46- drawable->interface->fill_rectangles(drawable, color, rectangles,
47- num_rectangles);
48+ drawable->interface->fill_region(drawable, color, region);
49 }
50
51 void wld_draw_text_utf8_n(struct wld_drawable * drawable,
M
intel.c
+6,
-6
1@@ -50,7 +50,8 @@ _Static_assert(offsetof(struct intel_drawable, drm) == 0,
2 "Non-zero offset of base field");
3
4 static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
5- pixman_rectangle16_t * rectangle);
6+ int32_t x, int32_t y,
7+ uint32_t width, uint32_t height);
8 static void intel_draw_text_utf8(struct wld_drawable * drawable,
9 struct font * font, uint32_t color,
10 int32_t x, int32_t y,
11@@ -60,7 +61,7 @@ static void intel_destroy(struct wld_drawable * drawable);
12
13 const static struct wld_draw_interface intel_draw = {
14 .fill_rectangle = &intel_fill_rectangle,
15- .fill_rectangles = &default_fill_rectangles,
16+ .fill_region = &default_fill_region,
17 .draw_text_utf8 = &intel_draw_text_utf8,
18 .flush = &intel_flush,
19 .destroy = &intel_destroy
20@@ -125,14 +126,13 @@ struct wld_drawable * wld_intel_create_drawable
21 }
22
23 static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
24- pixman_rectangle16_t * rectangle)
25+ int32_t x, int32_t y,
26+ uint32_t width, uint32_t height)
27 {
28 struct intel_drawable * intel = (void *) drawable;
29
30 xy_color_blt(&intel->context->batch, intel->bo, intel->drm.pitch,
31- rectangle->x, rectangle->y,
32- rectangle->x + rectangle->width,
33- rectangle->y + rectangle->height, color);
34+ x, y, x + width, y + height, color);
35 }
36
37 static void intel_draw_text_utf8(struct wld_drawable * drawable,
M
pixman.c
+26,
-12
1@@ -46,10 +46,11 @@ struct pixman_drawable
2 _Static_assert(offsetof(struct pixman_drawable, base) == 0,
3 "Non-zero offset of base field");
4
5-static void pixman_fill_rectangles(struct wld_drawable * drawable,
6- uint32_t color,
7- pixman_rectangle16_t * rectangles,
8- uint32_t num_rectangles);
9+static void pixman_fill_rectangle(struct wld_drawable * drawable,
10+ uint32_t color, int32_t x, int32_t y,
11+ uint32_t width, uint32_t height);
12+static void pixman_fill_region(struct wld_drawable * drawable, uint32_t color,
13+ pixman_region32_t * region);
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@@ -58,8 +59,8 @@ static void pixman_flush(struct wld_drawable * drawable);
18 static void pixman_destroy(struct wld_drawable * drawable);
19
20 const static struct wld_draw_interface pixman_draw = {
21- .fill_rectangle = &default_fill_rectangle,
22- .fill_rectangles = &pixman_fill_rectangles,
23+ .fill_rectangle = &pixman_fill_rectangle,
24+ .fill_region = &pixman_fill_region,
25 .draw_text_utf8 = &pixman_draw_text_utf8,
26 .flush = &pixman_flush,
27 .destroy = &pixman_destroy
28@@ -129,16 +130,29 @@ struct wld_drawable * wld_pixman_create_drawable
29 return NULL;
30 }
31
32-static void pixman_fill_rectangles(struct wld_drawable * drawable,
33- uint32_t color,
34- pixman_rectangle16_t * rectangles,
35- uint32_t num_rectangles)
36+static void pixman_fill_rectangle(struct wld_drawable * drawable,
37+ uint32_t color, int32_t x, int32_t y,
38+ uint32_t width, uint32_t height)
39 {
40 struct pixman_drawable * pixman = (void *) drawable;
41 pixman_color_t pixman_color = PIXMAN_COLOR(color);
42+ pixman_box32_t box = { x, y, x + width, y + height };
43
44- pixman_image_fill_rectangles(PIXMAN_OP_SRC, pixman->image, &pixman_color,
45- num_rectangles, rectangles);
46+ pixman_image_fill_boxes(PIXMAN_OP_SRC, pixman->image, &pixman_color,
47+ 1, &box);
48+}
49+
50+static void pixman_fill_region(struct wld_drawable * drawable, uint32_t color,
51+ pixman_region32_t * region)
52+{
53+ struct pixman_drawable * pixman = (void *) drawable;
54+ pixman_color_t pixman_color = PIXMAN_COLOR(color);
55+ pixman_box32_t * boxes;
56+ int num_boxes;
57+
58+ boxes = pixman_region32_rectangles(region, &num_boxes);
59+ pixman_image_fill_boxes(PIXMAN_OP_SRC, pixman->image, &pixman_color,
60+ num_boxes, boxes);
61 }
62
63 static inline uint8_t reverse(uint8_t byte)
+11,
-16
1@@ -59,12 +59,10 @@ static void sync_done(void * data, struct wl_callback * callback,
2 uint32_t msecs);
3
4 static void wayland_fill_rectangle(struct wld_drawable * drawable,
5- uint32_t color,
6- pixman_rectangle16_t * rectangles);
7-static void wayland_fill_rectangles(struct wld_drawable * drawable,
8- uint32_t color,
9- pixman_rectangle16_t * rectangles,
10- uint32_t num_rectangles);
11+ uint32_t color, int32_t x, int32_t y,
12+ uint32_t width, uint32_t height);
13+static void wayland_fill_region(struct wld_drawable * drawable, uint32_t color,
14+ pixman_region32_t * region);
15 static void wayland_draw_text_utf8(struct wld_drawable * drawable,
16 struct font * font, uint32_t color,
17 int32_t x, int32_t y,
18@@ -78,7 +76,7 @@ const struct wl_callback_listener sync_listener = {
19
20 const struct wld_draw_interface wayland_draw = {
21 .fill_rectangle = &wayland_fill_rectangle,
22- .fill_rectangles = &wayland_fill_rectangles,
23+ .fill_region = &wayland_fill_region,
24 .draw_text_utf8 = &wayland_draw_text_utf8,
25 .flush = &wayland_flush,
26 .destroy = &wayland_destroy
27@@ -256,23 +254,20 @@ void sync_done(void * data, struct wl_callback * callback, uint32_t msecs)
28 }
29
30 static void wayland_fill_rectangle(struct wld_drawable * drawable,
31- uint32_t color,
32- pixman_rectangle16_t * rectangle)
33+ uint32_t color, int32_t x, int32_t y,
34+ uint32_t width, uint32_t height)
35 {
36 struct wayland_drawable * wayland = (void *) drawable;
37
38- wld_fill_rectangle(BACKBUF(wayland).drawable, color, rectangle);
39+ wld_fill_rectangle(BACKBUF(wayland).drawable, color, x, y, width, height);
40 }
41
42-static void wayland_fill_rectangles(struct wld_drawable * drawable,
43- uint32_t color,
44- pixman_rectangle16_t * rectangles,
45- uint32_t num_rectangles)
46+static void wayland_fill_region(struct wld_drawable * drawable, uint32_t color,
47+ pixman_region32_t * region)
48 {
49 struct wayland_drawable * wayland = (void *) drawable;
50
51- wld_fill_rectangles(BACKBUF(wayland).drawable, color,
52- rectangles, num_rectangles);
53+ wld_fill_region(BACKBUF(wayland).drawable, color, region);
54 }
55
56 static void wayland_draw_text_utf8(struct wld_drawable * drawable,
+7,
-16
1@@ -79,10 +79,10 @@ _Static_assert(offsetof(struct font, base) == 0,
2 struct wld_draw_interface
3 {
4 void (* fill_rectangle)(struct wld_drawable * drawable, uint32_t color,
5- pixman_rectangle16_t * rectangle);
6- void (* fill_rectangles)(struct wld_drawable * drawable, uint32_t color,
7- pixman_rectangle16_t * rectangle,
8- uint32_t num_rectangles);
9+ int32_t x, int32_t y,
10+ uint32_t width, uint32_t height);
11+ void (* fill_region)(struct wld_drawable * drawable, uint32_t color,
12+ pixman_region32_t * region);
13 void (* draw_text_utf8)(struct wld_drawable * drawable,
14 struct font * font, uint32_t color,
15 int32_t x, int32_t y,
16@@ -110,19 +110,10 @@ static inline uint8_t format_bytes_per_pixel(enum wld_format format)
17 }
18
19 /**
20- * This default fill_rectangle method is implemented as fill_rectangles with a
21- * length parameter of 1.
22- */
23-void default_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
24- pixman_rectangle16_t * rectangle);
25-
26-/**
27- * This default fill_rectangles method is implemented in terms of the singular
28- * fill_rectangle.
29+ * This default fill_region method is implemented in terms of fill_rectangle.
30 */
31-void default_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
32- pixman_rectangle16_t * rectangles,
33- uint32_t num_rectangles);
34+void default_fill_region(struct wld_drawable * drawable, uint32_t color,
35+ pixman_region32_t * region);
36
37 #endif
38
M
wld.h
+3,
-4
1@@ -124,11 +124,10 @@ struct wld_drawable
2 void wld_destroy_drawable(struct wld_drawable * drawable);
3
4 void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
5- pixman_rectangle16_t * rectangle);
6+ int32_t x, int32_t y, uint32_t width, uint32_t height);
7
8-void wld_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
9- pixman_rectangle16_t * rectangles,
10- uint32_t num_rectangles);
11+void wld_fill_region(struct wld_drawable * drawable, uint32_t color,
12+ pixman_region32_t * region);
13
14 void wld_draw_text_utf8_n(struct wld_drawable * drawable,
15 struct wld_font * font, uint32_t color,