mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-common
synced 2026-01-02 22:52:21 +00:00
Replace custom region implementation with pixman_region32_t
pixman_region32_t is an efficient well tested region implementation (its the one used in X) that we already depend on via pixman and use in some places. No need to have a custom region implementation.
This commit is contained in:
parent
962bc74ed9
commit
2afb5544da
@ -1130,11 +1130,14 @@ void canvas_put_image(CairoCanvas *canvas, const SpiceRect *dest, const uint8_t
|
||||
cairo_save(cairo);
|
||||
|
||||
if (clip) {
|
||||
const SpiceRect *now = clip->rects;
|
||||
const SpiceRect *end = clip->rects + clip->num_rects;
|
||||
int num_rects;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles((pixman_region32_t *)clip,
|
||||
&num_rects);
|
||||
const pixman_box32_t *now = rects;
|
||||
const pixman_box32_t *end = rects + num_rects;
|
||||
for (; now < end; now++) {
|
||||
cairo_rectangle(cairo, now->left, now->top, now->right - now->left,
|
||||
now->bottom - now->top);
|
||||
cairo_rectangle(cairo, now->x1, now->y1, now->x2 - now->x1,
|
||||
now->y2 - now->y1);
|
||||
}
|
||||
cairo_clip(cairo);
|
||||
}
|
||||
@ -2137,23 +2140,16 @@ void canvas_read_bits(CairoCanvas *canvas, uint8_t *dest, int dest_stride, const
|
||||
}
|
||||
}
|
||||
|
||||
void canvas_group_start(CairoCanvas *canvas, int n_clip_rects, SpiceRect *clip_rects)
|
||||
void canvas_group_start(CairoCanvas *canvas, QRegion *region)
|
||||
{
|
||||
pixman_region32_t dest_region;
|
||||
|
||||
pixman_region32_fini(&canvas->canvas_region);
|
||||
spice_pixman_region32_init_rects(&canvas->canvas_region,
|
||||
clip_rects, n_clip_rects);
|
||||
|
||||
pixman_region32_init_rect(&dest_region,
|
||||
0, 0,
|
||||
pixman_image_get_width(canvas->image),
|
||||
pixman_image_get_height(canvas->image));
|
||||
|
||||
/* Make sure we always clip to canvas size */
|
||||
pixman_region32_intersect(&canvas->canvas_region, &canvas->canvas_region, &dest_region);
|
||||
pixman_region32_init_rect(&canvas->canvas_region,
|
||||
0, 0,
|
||||
pixman_image_get_width (canvas->image),
|
||||
pixman_image_get_height (canvas->image));
|
||||
|
||||
pixman_region32_fini(&dest_region);
|
||||
pixman_region32_intersect(&canvas->canvas_region, &canvas->canvas_region, region);
|
||||
}
|
||||
|
||||
void canvas_group_end(CairoCanvas *canvas)
|
||||
|
||||
@ -52,7 +52,7 @@ void canvas_put_image(CairoCanvas *canvas, const SpiceRect *dest, const uint8_t
|
||||
#endif
|
||||
void canvas_clear(CairoCanvas *canvas);
|
||||
void canvas_read_bits(CairoCanvas *canvas, uint8_t *dest, int dest_stride, const SpiceRect *area);
|
||||
void canvas_group_start(CairoCanvas *canvas, int n_clip_rects, SpiceRect *clip_rects);
|
||||
void canvas_group_start(CairoCanvas *canvas, QRegion *region);
|
||||
void canvas_group_end(CairoCanvas *canvas);
|
||||
void canvas_set_addr_delta(CairoCanvas *canvas, SPICE_ADDRESS delta);
|
||||
#ifdef CAIRO_CANVAS_ACCESS_TEST
|
||||
|
||||
@ -164,6 +164,13 @@ static GLCPath get_path(GLCanvas *canvas, void *addr)
|
||||
(dest)->height = (src)->bottom - (src)->top; \
|
||||
}
|
||||
|
||||
#define SET_GLC_BOX(dest, src) { \
|
||||
(dest)->x = (src)->x1; \
|
||||
(dest)->y = (src)->y1; \
|
||||
(dest)->width = (src)->x2 - (src)->x1; \
|
||||
(dest)->height = (src)->y2 - (src)->y1; \
|
||||
}
|
||||
|
||||
static void set_clip(GLCanvas *canvas, SpiceRect *bbox, SpiceClip *clip)
|
||||
{
|
||||
GLCRect rect;
|
||||
@ -706,14 +713,21 @@ void gl_canvas_read_pixels(GLCanvas *canvas, uint8_t *dest, int dest_stride, con
|
||||
glc_read_pixels(canvas->glc, area->left, area->top, &image);
|
||||
}
|
||||
|
||||
void gl_canvas_set_top_mask(GLCanvas *canvas, int num_rect, const SpiceRect *rects)
|
||||
void gl_canvas_set_top_mask(GLCanvas *canvas, QRegion *region)
|
||||
{
|
||||
GLCRect *glc_rects = (GLCRect *)malloc(num_rect * sizeof(GLCRect));
|
||||
GLCRect *now = glc_rects;
|
||||
GLCRect *end = glc_rects + num_rect;
|
||||
GLCRect *glc_rects;
|
||||
GLCRect *now, *end;
|
||||
int num_rect;
|
||||
pixman_box32_t *rects;
|
||||
|
||||
rects = pixman_region32_rectangles(region, &num_rect);
|
||||
|
||||
glc_rects = (GLCRect *)malloc(num_rect * sizeof(GLCRect));
|
||||
now = glc_rects;
|
||||
end = glc_rects + num_rect;
|
||||
|
||||
for (; now < end; now++, rects++) {
|
||||
SET_GLC_RECT(now, rects);
|
||||
SET_GLC_BOX(now, rects);
|
||||
}
|
||||
glc_mask_rects(canvas->glc, num_rect, glc_rects, GLC_MASK_B);
|
||||
|
||||
@ -733,15 +747,18 @@ void gl_canvas_put_image(GLCanvas *canvas, const SpiceRect *dest, const uint8_t
|
||||
glc_clip_reset(canvas->glc);
|
||||
|
||||
if (clip) {
|
||||
int num_rects;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles((pixman_region32_t *)clip,
|
||||
&num_rects);
|
||||
GLCRect rect;
|
||||
if (clip->num_rects == 0) {
|
||||
if (num_rects == 0) {
|
||||
rect.x = rect.y = rect.width = rect.height = 0;
|
||||
glc_clip_rect(canvas->glc, &rect, GLC_CLIP_OP_SET);
|
||||
} else {
|
||||
SET_GLC_RECT(&rect, clip->rects);
|
||||
SET_GLC_BOX(&rect, rects);
|
||||
glc_clip_rect(canvas->glc, &rect, GLC_CLIP_OP_SET);
|
||||
for (i = 1; i < clip->num_rects; i++) {
|
||||
SET_GLC_RECT(&rect, clip->rects + i);
|
||||
for (i = 1; i < num_rects; i++) {
|
||||
SET_GLC_BOX(&rect, rects + i);
|
||||
glc_clip_rect(canvas->glc, &rect, GLC_CLIP_OP_OR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ void gl_canvas_put_image(GLCanvas *canvas, const SpiceRect *dest, const uint8_t
|
||||
|
||||
void gl_canvas_clear(GLCanvas *canvas);
|
||||
|
||||
void gl_canvas_set_top_mask(GLCanvas *canvas, int num_rect, const SpiceRect *rects);
|
||||
void gl_canvas_set_top_mask(GLCanvas *canvas, QRegion *region);
|
||||
void gl_canvas_clear_top_mask(GLCanvas *canvas);
|
||||
|
||||
#ifdef CAIRO_CANVAS_ACCESS_TEST
|
||||
|
||||
1440
common/region.c
1440
common/region.c
File diff suppressed because it is too large
Load Diff
@ -21,20 +21,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <spice/draw.h>
|
||||
#include <pixman_utils.h>
|
||||
|
||||
#define REGION_USE_IMPROVED
|
||||
|
||||
#define RECTS_BUF_SIZE 4
|
||||
|
||||
typedef struct QRegion {
|
||||
uint32_t num_rects;
|
||||
SpiceRect bbox;
|
||||
SpiceRect *rects;
|
||||
uint32_t rects_size;
|
||||
SpiceRect buf[RECTS_BUF_SIZE];
|
||||
} QRegion;
|
||||
|
||||
#ifdef REGION_USE_IMPROVED
|
||||
typedef pixman_region32_t QRegion;
|
||||
|
||||
#define REGION_TEST_LEFT_EXCLUSIVE (1 << 0)
|
||||
#define REGION_TEST_RIGHT_EXCLUSIVE (1 << 1)
|
||||
@ -42,16 +31,13 @@ typedef struct QRegion {
|
||||
#define REGION_TEST_ALL \
|
||||
(REGION_TEST_LEFT_EXCLUSIVE | REGION_TEST_RIGHT_EXCLUSIVE | REGION_TEST_SHARED)
|
||||
|
||||
#endif
|
||||
|
||||
void region_init(QRegion *rgn);
|
||||
void region_clear(QRegion *rgn);
|
||||
void region_destroy(QRegion *rgn);
|
||||
void region_clone(QRegion *dest, const QRegion *src);
|
||||
SpiceRect *region_dup_rects(const QRegion *rgn, uint32_t *num_rects);
|
||||
|
||||
#ifdef REGION_USE_IMPROVED
|
||||
int region_test(const QRegion *rgn, const QRegion *other_rgn, int query);
|
||||
#endif
|
||||
int region_is_valid(const QRegion *rgn);
|
||||
int region_is_empty(const QRegion *rgn);
|
||||
int region_is_equal(const QRegion *rgn1, const QRegion *rgn2);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user