aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-07-23 20:56:32 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-07-23 20:56:32 +0200
commite88541398483552b60e699d0de3552c48b12523a (patch)
treebb55abd3ae79281eaa22b26f520d155c3a8609b1
parentf0bf08fa367ccf8ba995ee63846ac5b0148b6dd1 (diff)
parentdbf470541409019c08635be0757519d1dcdc9e82 (diff)
downloadtracker.lv2-e88541398483552b60e699d0de3552c48b12523a.zip
tracker.lv2-e88541398483552b60e699d0de3552c48b12523a.tar.gz
tracker.lv2-e88541398483552b60e699d0de3552c48b12523a.tar.bz2
tracker.lv2-e88541398483552b60e699d0de3552c48b12523a.tar.xz
Merge commit 'dbf470541409019c08635be0757519d1dcdc9e82'
-rw-r--r--subprojects/d2tk/VERSION2
-rw-r--r--subprojects/d2tk/d2tk/base.h4
-rw-r--r--subprojects/d2tk/d2tk/core.h5
-rw-r--r--subprojects/d2tk/example/example.c4
-rw-r--r--subprojects/d2tk/meson.build16
-rw-r--r--subprojects/d2tk/src/backend_cairo.c37
-rw-r--r--subprojects/d2tk/src/backend_nanovg.c75
-rw-r--r--subprojects/d2tk/src/base.c20
-rw-r--r--subprojects/d2tk/src/core.c24
-rw-r--r--subprojects/d2tk/src/core_internal.h13
-rw-r--r--subprojects/d2tk/test/base.c27
-rw-r--r--subprojects/d2tk/test/core.c69
12 files changed, 288 insertions, 8 deletions
diff --git a/subprojects/d2tk/VERSION b/subprojects/d2tk/VERSION
index 105b719..8bb0d09 100644
--- a/subprojects/d2tk/VERSION
+++ b/subprojects/d2tk/VERSION
@@ -1 +1 @@
-0.1.737
+0.1.747
diff --git a/subprojects/d2tk/d2tk/base.h b/subprojects/d2tk/d2tk/base.h
index 547749b..5a213f1 100644
--- a/subprojects/d2tk/d2tk/base.h
+++ b/subprojects/d2tk/d2tk/base.h
@@ -390,6 +390,10 @@ D2TK_API void
d2tk_base_bitmap(d2tk_base_t *base, uint32_t w, uint32_t h, uint32_t stride,
const uint32_t *argb, const d2tk_rect_t *rect, d2tk_align_t align);
+D2TK_API void
+d2tk_base_custom(d2tk_base_t *base, uint32_t size, const void *data,
+ const d2tk_rect_t *rect, d2tk_core_custom_t custom);
+
D2TK_API d2tk_state_t
d2tk_base_meter(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
const int32_t *value);
diff --git a/subprojects/d2tk/d2tk/core.h b/subprojects/d2tk/d2tk/core.h
index 586de73..f3bac84 100644
--- a/subprojects/d2tk/d2tk/core.h
+++ b/subprojects/d2tk/d2tk/core.h
@@ -33,6 +33,7 @@ typedef struct _d2tk_widget_t d2tk_widget_t;
typedef struct _d2tk_point_t d2tk_point_t;
typedef struct _d2tk_core_t d2tk_core_t;
typedef struct _d2tk_core_driver_t d2tk_core_driver_t;
+typedef void (*d2tk_core_custom_t)(void *ctx, uint32_t size, const void *data);
typedef enum _d2tk_align_t {
D2TK_ALIGN_NONE = 0,
@@ -177,6 +178,10 @@ d2tk_core_bitmap(d2tk_core_t *core, const d2tk_rect_t *rect, uint32_t w,
uint32_t h, uint32_t stride, const uint32_t *argb, d2tk_align_t align);
D2TK_API void
+d2tk_core_custom(d2tk_core_t *core, const d2tk_rect_t *rect, uint32_t size,
+ const void *data, d2tk_core_custom_t custom);
+
+D2TK_API void
d2tk_core_stroke_width(d2tk_core_t *core, d2tk_coord_t width);
D2TK_API void
diff --git a/subprojects/d2tk/example/example.c b/subprojects/d2tk/example/example.c
index f41c4eb..2247646 100644
--- a/subprojects/d2tk/example/example.c
+++ b/subprojects/d2tk/example/example.c
@@ -220,8 +220,8 @@ _render_c_mix(d2tk_base_t *base, const d2tk_rect_t *rect)
case 13:
{
static const uint32_t argb [4] = {
- 0xffff0000, 0x7f007f00,
- 0x00000000, 0x3f3f3f00
+ 0xffffcf00, 0x7f7f6700,
+ 0x7f7f6700, 0x00000000
};
d2tk_base_bitmap(base, 2, 2, 2*sizeof(uint32_t), argb, bnd,
diff --git a/subprojects/d2tk/meson.build b/subprojects/d2tk/meson.build
index 4e1f4dd..5160e87 100644
--- a/subprojects/d2tk/meson.build
+++ b/subprojects/d2tk/meson.build
@@ -67,7 +67,10 @@ bin_srcs = [
]
pugl_srcs = [
- join_paths('src', 'frontend_pugl.c'),
+ join_paths('src', 'frontend_pugl.c')
+]
+
+pugl_bin_srcs = [
join_paths('example', 'd2tk_pugl.c')
]
@@ -82,7 +85,10 @@ cairo_srcs = [
]
fbdev_srcs = [
- join_paths('src', 'frontend_fbdev.c'),
+ join_paths('src', 'frontend_fbdev.c')
+]
+
+fbdev_bin_srcs = [
join_paths('example', 'd2tk_fbdev.c')
]
@@ -126,7 +132,7 @@ if freetype_dep.found() and pixman_dep.found() and cairo_dep.found() and (host_m
link_args : links,
sources : [lib_srcs, cairo_srcs, pugl_srcs])
- executable('d2tk.cairo', [bin_srcs],
+ executable('d2tk.cairo', [bin_srcs, pugl_bin_srcs],
c_args : c_args,
include_directories : inc_dir,
dependencies: d2tk_cairo,
@@ -139,7 +145,7 @@ if freetype_dep.found() and pixman_dep.found() and cairo_dep.found() and (host_m
link_args : links,
sources : [lib_srcs, cairo_srcs, fbdev_srcs])
- executable('d2tk.fbdev', [bin_srcs],
+ executable('d2tk.fbdev', [bin_srcs, fbdev_bin_srcs],
c_args : c_args,
include_directories : inc_dir,
dependencies: d2tk_fbdev,
@@ -153,7 +159,7 @@ d2tk_nanovg = declare_dependency(
link_args : links,
sources : [lib_srcs, nanovg_srcs, pugl_srcs])
-executable('d2tk.nanovg', [bin_srcs],
+executable('d2tk.nanovg', [bin_srcs, pugl_bin_srcs],
c_args : c_args,
include_directories : inc_dir,
dependencies: d2tk_nanovg,
diff --git a/subprojects/d2tk/src/backend_cairo.c b/subprojects/d2tk/src/backend_cairo.c
index 9ab0f5b..b1a8dee 100644
--- a/subprojects/d2tk/src/backend_cairo.c
+++ b/subprojects/d2tk/src/backend_cairo.c
@@ -710,6 +710,43 @@ d2tk_cairo_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
_d2tk_cairo_surf_draw(ctx, surf, xo, yo, body->align,
&D2TK_RECT(body->x, body->y, body->w, body->h));
} break;
+ case D2TK_INSTR_CUSTOM:
+ {
+ const d2tk_body_custom_t *body = &com->body->custom;
+
+ const uint64_t hash = d2tk_hash(body->data, body->size);
+ uintptr_t *sprite = d2tk_core_get_sprite(core, hash, SPRITE_TYPE_SURF);
+ assert(sprite);
+
+ if(!*sprite)
+ {
+ const size_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
+ body->w);
+ const size_t bufsz = stride * body->h;
+ void *buf = calloc(1, bufsz);
+ cairo_surface_t *surf = cairo_image_surface_create_for_data(buf,
+ CAIRO_FORMAT_ARGB32, body->w, body->h, stride);
+ assert(surf);
+
+ const cairo_user_data_key_t key = { 0 };
+ cairo_surface_set_user_data(surf, &key, buf, _d2tk_cairo_buf_free);
+
+ cairo_t *ctx2 = cairo_create(surf);
+
+ body->custom(ctx2, body->size, body->data);
+
+ cairo_surface_flush(surf);
+ cairo_destroy(ctx2);
+
+ *sprite = (uintptr_t)surf;
+ }
+
+ cairo_surface_t *surf = (cairo_surface_t *)*sprite;
+ assert(surf);
+
+ _d2tk_cairo_surf_draw(ctx, surf, xo, yo, D2TK_ALIGN_LEFT | D2TK_ALIGN_TOP,
+ &D2TK_RECT(body->x, body->y, body->w, body->h));
+ } break;
case D2TK_INSTR_STROKE_WIDTH:
{
const d2tk_body_stroke_width_t *body = &com->body->stroke_width;
diff --git a/subprojects/d2tk/src/backend_nanovg.c b/subprojects/d2tk/src/backend_nanovg.c
index 5d78813..6f9a411 100644
--- a/subprojects/d2tk/src/backend_nanovg.c
+++ b/subprojects/d2tk/src/backend_nanovg.c
@@ -757,6 +757,81 @@ d2tk_nanovg_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
_d2tk_nanovg_surf_draw(ctx, img, xo, yo, body->align,
&D2TK_RECT(body->x, body->y, body->w, body->h));
} break;
+ case D2TK_INSTR_CUSTOM:
+ {
+ const d2tk_body_custom_t *body = &com->body->custom;
+ const uint64_t hash = d2tk_hash(body->data, body->size);
+
+ if(pass == 0)
+ {
+ if(true) // cached
+ {
+ uintptr_t *sprite = d2tk_core_get_sprite(core, hash, SPRITE_TYPE_FBO);
+ assert(sprite);
+
+ if(!*sprite)
+ {
+#ifdef D2TK_DEBUG
+ //fprintf(stderr, "\tcreating sprite\n");
+#endif
+ NVGLUframebuffer *fbo = nvgluCreateFramebuffer(ctx, body->w, body->h, NVG_IMAGE_NEAREST);
+ assert(fbo);
+
+ nvgluBindFramebuffer(fbo);
+
+ glViewport(0, 0, body->w, body->h);
+ glClearColor(0.f, 0.f, 0.f, 0.f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+ nvgBeginFrame(ctx, body->w, body->h, 1.f);
+ nvgSave(ctx);
+
+ body->custom(ctx, body->size, body->data);
+
+ nvgRestore(ctx);
+ nvgEndFrame(ctx);
+
+ nvgluBindFramebuffer(NULL);
+
+ *sprite = (uintptr_t )fbo;
+ }
+ else
+ {
+#ifdef D2TK_DEBUG
+ //fprintf(stderr, "\texisting sprite\n");
+#endif
+ }
+ }
+ }
+ else if(pass == 1)
+ {
+ nvgSave(ctx);
+ if(clip)
+ {
+ nvgScissor(ctx, clip->x0, clip->y0, clip->w, clip->h);
+ }
+
+ if(true) // cached
+ {
+ uintptr_t *sprite = d2tk_core_get_sprite(core, hash, SPRITE_TYPE_FBO);
+ assert(sprite && *sprite);
+
+ NVGLUframebuffer *fbo = (NVGLUframebuffer *)*sprite;
+ assert(fbo);
+
+ // paint pre-rendered sprite
+ const NVGpaint pat = nvgImagePattern(ctx, body->x, body->y,
+ body->w, body->h, 0, fbo->image, 1.0f);
+ nvgBeginPath(ctx);
+ nvgRect(ctx, body->x, body->y, body->w, body->h);
+ nvgStrokeWidth(ctx, 0);
+ nvgFillPaint(ctx, pat);
+ nvgFill(ctx);
+ }
+
+ nvgRestore(ctx);
+ }
+ } break;
case D2TK_INSTR_STROKE_WIDTH:
{
const d2tk_body_stroke_width_t *body = &com->body->stroke_width;
diff --git a/subprojects/d2tk/src/base.c b/subprojects/d2tk/src/base.c
index 8bb0072..6abe25b 100644
--- a/subprojects/d2tk/src/base.c
+++ b/subprojects/d2tk/src/base.c
@@ -1887,6 +1887,26 @@ d2tk_base_bitmap(d2tk_base_t *base, uint32_t w, uint32_t h, uint32_t stride,
}
}
+D2TK_API void
+d2tk_base_custom(d2tk_base_t *base, uint32_t size, const void *data,
+ const d2tk_rect_t *rect, d2tk_core_custom_t custom)
+{
+ const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
+ data, size, //FIXME
+ NULL);
+
+ d2tk_core_t *core = base->core;;
+
+ D2TK_CORE_WIDGET(core, hash, widget)
+ {
+ const size_t ref = d2tk_core_bbox_push(core, true, rect);
+
+ d2tk_core_custom(core, rect, size, data, custom);
+
+ d2tk_core_bbox_pop(core, ref);
+ }
+}
+
static inline void
_d2tk_base_draw_meter(d2tk_core_t *core, const d2tk_rect_t *rect,
d2tk_state_t state, int32_t value, const d2tk_style_t *style)
diff --git a/subprojects/d2tk/src/core.c b/subprojects/d2tk/src/core.c
index 1c6fc3c..79e76af 100644
--- a/subprojects/d2tk/src/core.c
+++ b/subprojects/d2tk/src/core.c
@@ -1064,6 +1064,30 @@ d2tk_core_bitmap(d2tk_core_t *core, const d2tk_rect_t *rect, uint32_t w,
}
D2TK_API void
+d2tk_core_custom(d2tk_core_t *core, const d2tk_rect_t *rect, uint32_t size,
+ const void *data, d2tk_core_custom_t custom)
+{
+ const size_t len = sizeof(d2tk_body_custom_t);
+ d2tk_body_t *body = _d2tk_append_request(core, len, D2TK_INSTR_CUSTOM);
+
+ if(body)
+ {
+ body->custom.x = rect->x;
+ body->custom.y = rect->y;
+ body->custom.w = rect->w;
+ body->custom.h = rect->h;
+ body->custom.size = size;
+ body->custom.data = data;
+ body->custom.custom = custom;
+
+ body->custom.x -= core->ref.x;
+ body->custom.y -= core->ref.y;
+
+ _d2tk_append_advance(core, len);
+ }
+}
+
+D2TK_API void
d2tk_core_stroke_width(d2tk_core_t *core, d2tk_coord_t width)
{
const size_t len = sizeof(d2tk_body_stroke_width_t);
diff --git a/subprojects/d2tk/src/core_internal.h b/subprojects/d2tk/src/core_internal.h
index 96f93ab..91c1ef0 100644
--- a/subprojects/d2tk/src/core_internal.h
+++ b/subprojects/d2tk/src/core_internal.h
@@ -55,6 +55,7 @@ typedef struct _d2tk_body_font_size_t d2tk_body_font_size_t;
typedef struct _d2tk_body_text_t d2tk_body_text_t;
typedef struct _d2tk_body_image_t d2tk_body_image_t;
typedef struct _d2tk_body_bitmap_t d2tk_body_bitmap_t;
+typedef struct _d2tk_body_custom_t d2tk_body_custom_t;
typedef struct _d2tk_body_stroke_width_t d2tk_body_stroke_width_t;
typedef struct _d2tk_body_bbox_t d2tk_body_bbox_t;
typedef union _d2tk_body_t d2tk_body_t;
@@ -180,6 +181,16 @@ struct _d2tk_body_bitmap_t {
} surf;
};
+struct _d2tk_body_custom_t {
+ d2tk_coord_t x;
+ d2tk_coord_t y;
+ d2tk_coord_t w;
+ d2tk_coord_t h;
+ uint32_t size;
+ const void *data;
+ d2tk_core_custom_t custom;
+};
+
struct _d2tk_body_stroke_width_t {
d2tk_coord_t width;
};
@@ -207,6 +218,7 @@ union _d2tk_body_t {
d2tk_body_font_size_t font_size;
d2tk_body_text_t text;
d2tk_body_image_t image;
+ d2tk_body_custom_t custom;
d2tk_body_bitmap_t bitmap;
d2tk_body_stroke_width_t stroke_width;
d2tk_body_bbox_t bbox;
@@ -236,6 +248,7 @@ typedef enum _d2tk_instr_t {
D2TK_INSTR_TEXT,
D2TK_INSTR_IMAGE,
D2TK_INSTR_BITMAP,
+ D2TK_INSTR_CUSTOM,
D2TK_INSTR_STROKE_WIDTH
} d2tk_instr_t;
diff --git a/subprojects/d2tk/test/base.c b/subprojects/d2tk/test/base.c
index 93271b3..9580977 100644
--- a/subprojects/d2tk/test/base.c
+++ b/subprojects/d2tk/test/base.c
@@ -1425,6 +1425,32 @@ _test_bitmap()
d2tk_base_free(base);
}
+static const uint32_t custom_data;
+
+static void
+_custom(void *ctx, uint32_t size, const void *data)
+{
+ assert(ctx == NULL);
+ assert(size == sizeof(custom_data));
+ assert(data == &custom_data);
+}
+
+static void
+_test_custom()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = NULL
+ };
+
+ d2tk_base_t *base = d2tk_base_new(&d2tk_mock_driver_lazy, &ctx);
+ const d2tk_rect_t rect = D2TK_RECT(0, 0, DIM_W, DIM_H);
+ assert(base);
+
+ d2tk_base_custom(base, sizeof(custom_data), &custom_data, &rect, _custom);
+
+ d2tk_base_free(base);
+}
+
static void
_test_meter()
{
@@ -1833,6 +1859,7 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
_test_toggle();
_test_image();
_test_bitmap();
+ _test_custom();
_test_meter();
_test_combo();
_test_combo_scroll_up();
diff --git a/subprojects/d2tk/test/core.c b/subprojects/d2tk/test/core.c
index 3a8ca81..7c5b45a 100644
--- a/subprojects/d2tk/test/core.c
+++ b/subprojects/d2tk/test/core.c
@@ -1230,6 +1230,74 @@ _test_bitmap()
#undef BITMAP_STRIDE
#undef BITMAP_ALIGN
+#define CUSTOM_X 10
+#define CUSTOM_Y 20
+#define CUSTOM_W 30
+#define CUSTOM_H 40
+#define CUSTOM_SIZE 0
+#define CUSTOM_DATA NULL
+
+static void
+_custom(void *ctx, uint32_t size, const void *data)
+{
+ assert(ctx == NULL);
+ assert(size == CUSTOM_SIZE);
+ assert(data == CUSTOM_DATA);
+}
+
+static void
+_check_custom(const d2tk_com_t *com, const d2tk_clip_t *clip)
+{
+ assert(clip->x0 == CLIP_X);
+ assert(clip->y0 == CLIP_Y);
+ assert(clip->x1 == CLIP_X + CLIP_W);
+ assert(clip->y1 == CLIP_Y + CLIP_H);
+ assert(clip->w == CLIP_W);
+ assert(clip->h == CLIP_H);
+
+ assert(com->size == sizeof(d2tk_body_custom_t));
+ assert(com->instr == D2TK_INSTR_CUSTOM);
+ assert(com->body->custom.x == CUSTOM_X - CLIP_X);
+ assert(com->body->custom.y == CUSTOM_Y - CLIP_Y);
+ assert(com->body->custom.w == CUSTOM_W);
+ assert(com->body->custom.h == CUSTOM_H);
+ assert(com->body->custom.size == CUSTOM_SIZE);
+ assert(com->body->custom.data == CUSTOM_DATA);
+ assert(com->body->custom.custom == _custom);
+}
+
+static void
+_test_custom()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = _check_custom
+ };
+
+ d2tk_core_t *core = d2tk_core_new(&d2tk_mock_driver, &ctx);
+ assert(core);
+
+ d2tk_core_set_dimensions(core, DIM_W, DIM_H);
+
+ d2tk_core_pre(core);
+ const ssize_t ref = d2tk_core_bbox_push(core, true,
+ &D2TK_RECT(CLIP_X, CLIP_Y, CLIP_W, CLIP_H));
+ assert(ref >= 0);
+
+ d2tk_core_custom(core, &D2TK_RECT(CUSTOM_X, CUSTOM_Y, CUSTOM_W, CUSTOM_H),
+ CUSTOM_SIZE, CUSTOM_DATA, _custom);
+
+ d2tk_core_bbox_pop(core, ref);
+ d2tk_core_post(core);
+ d2tk_core_free(core);
+}
+
+#undef CUSTOM_X
+#undef CUSTOM_Y
+#undef CUSTOM_W
+#undef CUSTOM_H
+#undef CUSTOM_SIZE
+#undef CUSTOM_DATA
+
#define STROKE_WIDTH 2
static void
@@ -1373,6 +1441,7 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
_test_text();
_test_image();
_test_bitmap();
+ _test_custom();
_test_stroke_width();
_test_triple();