neuwld

patched neuwld library (tracked)
git clone https://git.daat.foo/neuwld.git
Log | Files | Refs | README | LICENSE

commit 3e011e5282c92015bc9dc9017137031322b40bb2
parent 13a926768551b22190aa07ffc65d72b98c9a6642
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 24 Jul 2013 23:52:32 -0700

Add copy_{rectangle,region} operations

Diffstat:
Mdrawable.c | 37+++++++++++++++++++++++++++++++++++++
Mintel.c | 20++++++++++++++++++++
Mpixman.c | 42++++++++++++++++++++++++++++++++++++++++++
Mwayland.c | 28++++++++++++++++++++++++++++
Mwld-private.h | 15+++++++++++++++
Mwld.h | 8++++++++
6 files changed, 150 insertions(+), 0 deletions(-)

diff --git a/drawable.c b/drawable.c @@ -23,6 +23,8 @@ #include "wld-private.h" +#include <assert.h> + void default_fill_region(struct wld_drawable * drawable, uint32_t color, pixman_region32_t * region) { @@ -40,6 +42,24 @@ void default_fill_region(struct wld_drawable * drawable, uint32_t color, } } +void default_copy_region(struct wld_drawable * src, struct wld_drawable * dst, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y) +{ + pixman_box32_t * box; + int num_boxes; + + box = pixman_region32_rectangles(region, &num_boxes); + + while (num_boxes--) + { + dst->interface->copy_rectangle(src, dst, box->x1, box->y1, + dst_x + box->x1, dst_y + box->y1, + box->x2 - box->x1, box->y2 - box->y1); + ++box; + } +} + void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color, int32_t x, int32_t y, uint32_t width, uint32_t height) { @@ -52,6 +72,23 @@ void wld_fill_region(struct wld_drawable * drawable, uint32_t color, drawable->interface->fill_region(drawable, color, region); } +void wld_copy_rectangle(struct wld_drawable * src, struct wld_drawable * dst, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height) +{ + assert(src->interface == dst->interface); + dst->interface->copy_rectangle(src, dst, src_x, src_y, dst_x, dst_y, + width, height); +} + +void wld_copy_region(struct wld_drawable * src, struct wld_drawable * dst, + pixman_region32_t * region, int32_t dst_x, int32_t dst_y) +{ + assert(src->interface == dst->interface); + dst->interface->copy_region(src, dst, region, dst_x, dst_y); +} + void wld_draw_text_utf8_n(struct wld_drawable * drawable, struct wld_font * font_base, uint32_t color, int32_t x, int32_t y, diff --git a/intel.c b/intel.c @@ -52,6 +52,11 @@ _Static_assert(offsetof(struct intel_drawable, drm) == 0, static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color, int32_t x, int32_t y, uint32_t width, uint32_t height); +static void intel_copy_rectangle(struct wld_drawable * src, + struct wld_drawable * dst, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height); static void intel_draw_text_utf8(struct wld_drawable * drawable, struct font * font, uint32_t color, int32_t x, int32_t y, @@ -62,6 +67,8 @@ static void intel_destroy(struct wld_drawable * drawable); const static struct wld_draw_interface intel_draw = { .fill_rectangle = &intel_fill_rectangle, .fill_region = &default_fill_region, + .copy_rectangle = &intel_copy_rectangle, + .copy_region = &default_copy_region, .draw_text_utf8 = &intel_draw_text_utf8, .flush = &intel_flush, .destroy = &intel_destroy @@ -135,6 +142,19 @@ static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color, x, y, x + width, y + height, color); } +static void intel_copy_rectangle(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height) +{ + struct intel_drawable * src = (void *) src_drawable; + struct intel_drawable * dst = (void *) dst_drawable; + + xy_src_copy_blt(&dst->context->batch, src->bo, src->drm.pitch, src_x, src_y, + dst->bo, dst->drm.pitch, dst_x, dst_y, width, height); +} + static void intel_draw_text_utf8(struct wld_drawable * drawable, struct font * font, uint32_t color, int32_t x, int32_t y, diff --git a/pixman.c b/pixman.c @@ -51,6 +51,15 @@ static void pixman_fill_rectangle(struct wld_drawable * drawable, uint32_t width, uint32_t height); static void pixman_fill_region(struct wld_drawable * drawable, uint32_t color, pixman_region32_t * region); +static void pixman_copy_rectangle(struct wld_drawable * src, + struct wld_drawable * dst, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height); +static void pixman_copy_region(struct wld_drawable * src, + struct wld_drawable * dst, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y); static void pixman_draw_text_utf8(struct wld_drawable * drawable, struct font * font, uint32_t color, int32_t x, int32_t y, @@ -61,6 +70,8 @@ static void pixman_destroy(struct wld_drawable * drawable); const static struct wld_draw_interface pixman_draw = { .fill_rectangle = &pixman_fill_rectangle, .fill_region = &pixman_fill_region, + .copy_rectangle = &pixman_copy_rectangle, + .copy_region = &pixman_copy_region, .draw_text_utf8 = &pixman_draw_text_utf8, .flush = &pixman_flush, .destroy = &pixman_destroy @@ -155,6 +166,37 @@ static void pixman_fill_region(struct wld_drawable * drawable, uint32_t color, num_boxes, boxes); } +static void pixman_copy_rectangle(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height) +{ + struct pixman_drawable * src = (void *) src_drawable; + struct pixman_drawable * dst = (void *) dst_drawable; + + pixman_image_composite32(PIXMAN_OP_SRC, src->image, NULL, dst->image, + src_x, src_y, 0, 0, dst_x, dst_y, width, height); +} + +static void pixman_copy_region(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y) +{ + struct pixman_drawable * src = (void *) src_drawable; + struct pixman_drawable * dst = (void *) dst_drawable; + + pixman_image_set_clip_region32(src->image, region); + pixman_image_composite32(PIXMAN_OP_SRC, src->image, NULL, dst->image, + region->extents.x1, region->extents.y1, 0, 0, + region->extents.x1 + dst_x, + region->extents.y1 + dst_y, + region->extents.x2 - region->extents.x1, + region->extents.y2 - region->extents.y1); + pixman_image_set_clip_region32(src->image, NULL); +} + static inline uint8_t reverse(uint8_t byte) { byte = ((byte << 1) & 0xaa) | ((byte >> 1) & 0x55); diff --git a/wayland.c b/wayland.c @@ -63,6 +63,15 @@ static void wayland_fill_rectangle(struct wld_drawable * drawable, uint32_t width, uint32_t height); static void wayland_fill_region(struct wld_drawable * drawable, uint32_t color, pixman_region32_t * region); +static void wayland_copy_rectangle(struct wld_drawable * src, + struct wld_drawable * dst, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height); +static void wayland_copy_region(struct wld_drawable * src, + struct wld_drawable * dst, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y); static void wayland_draw_text_utf8(struct wld_drawable * drawable, struct font * font, uint32_t color, int32_t x, int32_t y, @@ -77,6 +86,8 @@ const struct wl_callback_listener sync_listener = { const struct wld_draw_interface wayland_draw = { .fill_rectangle = &wayland_fill_rectangle, .fill_region = &wayland_fill_region, + .copy_rectangle = &wayland_copy_rectangle, + .copy_region = &wayland_copy_region, .draw_text_utf8 = &wayland_draw_text_utf8, .flush = &wayland_flush, .destroy = &wayland_destroy @@ -270,6 +281,23 @@ static void wayland_fill_region(struct wld_drawable * drawable, uint32_t color, wld_fill_region(BACKBUF(wayland).drawable, color, region); } +static void wayland_copy_rectangle(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height) +{ + fprintf(stderr, "wayland: Copy rectangle is not implemented\n"); +} + +static void wayland_copy_region(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y) +{ + fprintf(stderr, "wayland: Copy region is not implemented\n"); +} + static void wayland_draw_text_utf8(struct wld_drawable * drawable, struct font * font, uint32_t color, int32_t x, int32_t y, diff --git a/wld-private.h b/wld-private.h @@ -83,6 +83,14 @@ struct wld_draw_interface uint32_t width, uint32_t height); void (* fill_region)(struct wld_drawable * drawable, uint32_t color, pixman_region32_t * region); + void (* copy_rectangle)(struct wld_drawable * src, + struct wld_drawable * dst, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height); + void (* copy_region)(struct wld_drawable * src, struct wld_drawable * dst, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y); void (* draw_text_utf8)(struct wld_drawable * drawable, struct font * font, uint32_t color, int32_t x, int32_t y, @@ -115,5 +123,12 @@ static inline uint8_t format_bytes_per_pixel(enum wld_format format) void default_fill_region(struct wld_drawable * drawable, uint32_t color, pixman_region32_t * region); +/** + * This default copy_region method is implemented in terms of copy_rectangle. + */ +void default_copy_region(struct wld_drawable * src, struct wld_drawable * dst, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y); + #endif diff --git a/wld.h b/wld.h @@ -129,6 +129,14 @@ void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color, void wld_fill_region(struct wld_drawable * drawable, uint32_t color, pixman_region32_t * region); +void wld_copy_rectangle(struct wld_drawable * src, struct wld_drawable * dst, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height); + +void wld_copy_region(struct wld_drawable * src, struct wld_drawable * dst, + pixman_region32_t * region, int32_t dst_x, int32_t dst_y); + void wld_draw_text_utf8_n(struct wld_drawable * drawable, struct wld_font * font, uint32_t color, int32_t x, int32_t y,