aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-07-18 19:26:26 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-07-18 19:26:26 +0200
commit6a388b93c2e1da1d724177f8ce9e8cf49524267a (patch)
tree58ed0537a3e5500ba9116abe9d7629ca2babb27e /src
parent5841ebb4dcf412ab2ca6fc6b84020dfbe0abb484 (diff)
downloadd2tk-6a388b93c2e1da1d724177f8ce9e8cf49524267a.tar.xz
core: prototype bitmap primitive.
Diffstat (limited to 'src')
-rw-r--r--src/backend_cairo.c7
-rw-r--r--src/backend_nanovg.c7
-rw-r--r--src/core.c26
-rw-r--r--src/core_internal.h19
4 files changed, 59 insertions, 0 deletions
diff --git a/src/backend_cairo.c b/src/backend_cairo.c
index 8d0905b..1e4d08f 100644
--- a/src/backend_cairo.c
+++ b/src/backend_cairo.c
@@ -678,6 +678,13 @@ d2tk_cairo_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
cairo_pattern_set_matrix(cairo_get_source(ctx), &matrix);
cairo_paint(ctx);
} break;
+ case D2TK_INSTR_BITMAP:
+ {
+ const d2tk_body_bitmap_t *body = &com->body->bitmap;
+
+ (void)body;
+ //FIXME
+ } break;
case D2TK_INSTR_STROKE_WIDTH:
{
const d2tk_body_stroke_width_t *body = &com->body->stroke_width;
diff --git a/src/backend_nanovg.c b/src/backend_nanovg.c
index 5e6352f..255dafa 100644
--- a/src/backend_nanovg.c
+++ b/src/backend_nanovg.c
@@ -726,6 +726,13 @@ d2tk_nanovg_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
nvgFillPaint(ctx, bg);
nvgFill(ctx);
} break;
+ case D2TK_INSTR_BITMAP:
+ {
+ const d2tk_body_bitmap_t *body = &com->body->bitmap;
+
+ (void)body;
+ //FIXME
+ } break;
case D2TK_INSTR_STROKE_WIDTH:
{
const d2tk_body_stroke_width_t *body = &com->body->stroke_width;
diff --git a/src/core.c b/src/core.c
index f688a3a..e34e87d 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1038,6 +1038,32 @@ d2tk_core_image(d2tk_core_t *core, const d2tk_rect_t *rect, size_t sz,
}
D2TK_API void
+d2tk_core_bitmap(d2tk_core_t *core, const d2tk_rect_t *rect, uint32_t w,
+ uint32_t h, const uint32_t *rgba, d2tk_align_t align)
+{
+ const size_t rgba_sz = w*h*sizeof(uint32_t);
+ const size_t len = sizeof(d2tk_body_bitmap_t) + rgba_sz;
+ d2tk_body_t *body = _d2tk_append_request(core, len, D2TK_INSTR_BITMAP);
+
+ if(body)
+ {
+ body->bitmap.x = rect->x;
+ body->bitmap.y = rect->y;
+ body->bitmap.w = rect->w;
+ body->bitmap.h = rect->h;
+ body->bitmap.align = align;
+ body->bitmap.surf.w = w;
+ body->bitmap.surf.h = h;
+ memcpy(body->bitmap.surf.rgba, rgba, rgba_sz);
+
+ body->bitmap.x -= core->ref.x;
+ body->bitmap.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/src/core_internal.h b/src/core_internal.h
index 884c71a..c1e3223 100644
--- a/src/core_internal.h
+++ b/src/core_internal.h
@@ -54,6 +54,7 @@ typedef struct _d2tk_body_font_face_t d2tk_body_font_face_t;
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_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;
@@ -165,6 +166,22 @@ struct _d2tk_body_image_t {
char path [1]; // at least zero-terminator
};
+struct _d2tk_body_bitmap_t {
+ d2tk_coord_t x;
+ d2tk_coord_t y;
+ d2tk_coord_t w;
+ d2tk_coord_t h;
+ d2tk_align_t align;
+ struct {
+ uint32_t w;
+ uint32_t h;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpedantic"
+ uint32_t rgba [0];
+#pragma GCC diagnostic pop
+ } surf;
+};
+
struct _d2tk_body_stroke_width_t {
d2tk_coord_t width;
};
@@ -192,6 +209,7 @@ union _d2tk_body_t {
d2tk_body_font_size_t font_size;
d2tk_body_text_t text;
d2tk_body_image_t image;
+ d2tk_body_bitmap_t bitmap;
d2tk_body_stroke_width_t stroke_width;
d2tk_body_bbox_t bbox;
};
@@ -219,6 +237,7 @@ typedef enum _d2tk_instr_t {
D2TK_INSTR_FONT_FACE,
D2TK_INSTR_TEXT,
D2TK_INSTR_IMAGE,
+ D2TK_INSTR_BITMAP,
D2TK_INSTR_STROKE_WIDTH
} d2tk_instr_t;