aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-02 19:27:15 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-02 19:27:15 +0200
commitca9607d292923964ff60bef12f6acd83d627bf11 (patch)
treea13eb7f402975a2bdff7a942d8366f1cc7fba5cd
parent15c59a14f297f7bc446959b2ffa2fc165ece8fec (diff)
downloadd2tk-ca9607d292923964ff60bef12f6acd83d627bf11.zip
d2tk-ca9607d292923964ff60bef12f6acd83d627bf11.tar.gz
d2tk-ca9607d292923964ff60bef12f6acd83d627bf11.tar.bz2
d2tk-ca9607d292923964ff60bef12f6acd83d627bf11.tar.xz
core: only update dirty part of mask.
-rw-r--r--VERSION2
-rw-r--r--src/backend_cairo.c10
-rw-r--r--src/backend_nanovg.c14
-rw-r--r--src/core.c25
-rw-r--r--src/core_internal.h2
-rw-r--r--test/mock.c4
6 files changed, 42 insertions, 15 deletions
diff --git a/VERSION b/VERSION
index d958a5f..3566669 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.749
+0.1.751
diff --git a/src/backend_cairo.c b/src/backend_cairo.c
index b1a8dee..a96d831 100644
--- a/src/backend_cairo.c
+++ b/src/backend_cairo.c
@@ -100,12 +100,14 @@ d2tk_cairo_pre(void *data, d2tk_core_t *core __attribute((unused)),
cairo_save(ctx);
{
- uint32_t *pixels = d2tk_core_get_pixels(core);
+ d2tk_rect_t rect;
+ uint32_t *pixels = d2tk_core_get_pixels(core, &rect);
cairo_surface_t *surf = cairo_image_surface_create_for_data(
(uint8_t *)pixels, CAIRO_FORMAT_ARGB32, w, h, w*sizeof(uint32_t));
+ //FIXME reuse/update surfaces
- cairo_rectangle(ctx, 0, 0, w, h);
+ cairo_rectangle(ctx, rect.x, rect.y, rect.w, rect.h);
cairo_clip(ctx);
cairo_new_sub_path(ctx);
@@ -132,7 +134,8 @@ d2tk_cairo_post(void *data, d2tk_core_t *core __attribute__((unused)),
#ifdef D2TK_DEBUG //FIXME needs multiple buffers to work
{
- uint32_t *pixels = d2tk_core_get_pixels(core);
+ d2tk_rect_t rect;
+ uint32_t *pixels = d2tk_core_get_pixels(core, &rect);
// brighten up the pixels for proper hilighting
for(d2tk_coord_t y = 0, Y = 0; y < h; y++, Y+=w)
@@ -148,6 +151,7 @@ d2tk_cairo_post(void *data, d2tk_core_t *core __attribute__((unused)),
cairo_surface_t *surf = cairo_image_surface_create_for_data(
(uint8_t *)pixels, CAIRO_FORMAT_ARGB32, w, h, w*sizeof(uint32_t));
+ //FIXME reuse/update suface
cairo_rectangle(ctx, 0, 0, w, h);
cairo_clip(ctx);
diff --git a/src/backend_nanovg.c b/src/backend_nanovg.c
index 6f9a411..ad48e16 100644
--- a/src/backend_nanovg.c
+++ b/src/backend_nanovg.c
@@ -210,21 +210,23 @@ d2tk_nanovg_pre(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
{
// draw mask
- uint32_t *pixels = d2tk_core_get_pixels(core);
+ d2tk_rect_t rect;
+ uint32_t *pixels = d2tk_core_get_pixels(core, &rect);
if(backend->mask)
{
- nvgUpdateImage(ctx, backend->mask, (const uint8_t *)pixels);
+ nvgUpdateSubImage(ctx, backend->mask, (const uint8_t *)pixels,
+ rect.x, rect.y, rect.w, rect.h);
}
else
{
backend->mask = nvgCreateImageRGBA(ctx, w, h, NVG_IMAGE_NEAREST,
(const uint8_t *)pixels);
}
-
+
const NVGpaint bg = nvgImagePattern(ctx, 0, 0, w, h, 0, backend->mask, 1.f);
nvgBeginPath(ctx);
- nvgRect(ctx, 0, 0, w, h);
+ nvgRect(ctx, rect.x, rect.y, rect.w, rect.h);
nvgStrokeWidth(ctx, 0);
nvgFillPaint(ctx, bg);
nvgFill(ctx);
@@ -271,7 +273,8 @@ d2tk_nanovg_post(void *data, d2tk_core_t *core __attribute__((unused)),
#ifdef D2TK_DEBUG
{
- uint32_t *pixels = d2tk_core_get_pixels(core);
+ d2tk_rect_t rect;
+ uint32_t *pixels = d2tk_core_get_pixels(core, &rect);
// brighten up the pixels for proper hilighting
for(d2tk_coord_t y = 0, Y = 0; y < h; y++, Y+=w)
@@ -284,6 +287,7 @@ d2tk_nanovg_post(void *data, d2tk_core_t *core __attribute__((unused)),
}
}
}
+
if(backend->mask)
{
nvgUpdateImage(ctx, backend->mask, (const uint8_t *)pixels);
diff --git a/src/core.c b/src/core.c
index 79e76af..f04b592 100644
--- a/src/core.c
+++ b/src/core.c
@@ -358,9 +358,18 @@ _d2tk_bitmap_deinit(d2tk_bitmap_t *bitmap)
}
static inline void
-_d2tk_bitmap_reset(d2tk_bitmap_t *bitmap)
+_d2tk_bitmap_reset(d2tk_core_t *core)
{
- memset(bitmap->pixels, 0x0, bitmap->size);
+ d2tk_bitmap_t *bitmap = &core->bitmap;
+
+ for(d2tk_coord_t y = bitmap->y0, Y = y*core->w; y < bitmap->y1; y++, Y+=core->w)
+ {
+ for(d2tk_coord_t x = bitmap->x0; x < bitmap->x1; x++)
+ {
+ bitmap->pixels[Y + x] = 0x00000000;
+ }
+ }
+
bitmap->nfills = 0;
bitmap->x0 = INT_MAX;
bitmap->x1 = INT_MIN;
@@ -455,8 +464,16 @@ _d2tk_bbox_mask(d2tk_core_t *core, d2tk_com_t *com)
}
uint32_t *
-d2tk_core_get_pixels(d2tk_core_t *core)
+d2tk_core_get_pixels(d2tk_core_t *core, d2tk_rect_t *rect)
{
+ if(rect)
+ {
+ rect->x = core->bitmap.x0;
+ rect->y = core->bitmap.y0;
+ rect->w = core->bitmap.x1 - core->bitmap.x0;
+ rect->h = core->bitmap.y1 - core->bitmap.y0;
+ }
+
return core->bitmap.pixels;
}
@@ -1304,7 +1321,7 @@ d2tk_core_post(d2tk_core_t *core)
d2tk_com_t *oldcom = _d2tk_mem_get_com(oldmem);
// reset num of clipping clips
- _d2tk_bitmap_reset(bitmap);
+ _d2tk_bitmap_reset(core);
if(core->full_refresh)
{
diff --git a/src/core_internal.h b/src/core_internal.h
index 91c1ef0..d875e8b 100644
--- a/src/core_internal.h
+++ b/src/core_internal.h
@@ -295,7 +295,7 @@ d2tk_com_next(d2tk_com_t *bbox);
(BBOX) = d2tk_com_next((BBOX)))
uint32_t *
-d2tk_core_get_pixels(d2tk_core_t *core);
+d2tk_core_get_pixels(d2tk_core_t *core, d2tk_rect_t *rect);
void
d2tk_core_set_bg_color(d2tk_core_t *core, uint32_t rgba);
diff --git a/test/mock.c b/test/mock.c
index 95ef666..7e77a43 100644
--- a/test/mock.c
+++ b/test/mock.c
@@ -45,7 +45,9 @@ _d2tk_mock_post(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
assert(h == DIM_H);
assert(pass == 0);
- assert(d2tk_core_get_pixels(core));
+ d2tk_rect_t rect;
+ assert(d2tk_core_get_pixels(core, &rect));
+ assert( (rect.w != 0) && (rect.h != 0) );
return false; // do NOT enter 3rd pass
}