aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2018-08-10 13:32:46 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2018-08-10 13:32:46 +0200
commit7d050262fdee7a19dc854378db732a00f9837868 (patch)
tree025c4f62510d3ac15154daa0fb46b97c771f18b6
parentd18cc7dc31a026a84ad94ea0273218b7546b7456 (diff)
downloadcanvas_display.lv2-7d050262fdee7a19dc854378db732a00f9837868.tar.xz
prototype nanovg backend.
-rw-r--r--VERSION2
-rw-r--r--canvas.c1
-rw-r--r--canvas_display_ui.ttl2
-rw-r--r--canvas_ui.c99
-rw-r--r--meson.build12
5 files changed, 66 insertions, 50 deletions
diff --git a/VERSION b/VERSION
index b463c01..faa7104 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.3.41
+0.3.43
diff --git a/canvas.c b/canvas.c
index b6a0a21..d97945c 100644
--- a/canvas.c
+++ b/canvas.c
@@ -25,6 +25,7 @@
#include <lv2/lv2plug.in/ns/ext/log/logger.h>
#include <canvas.lv2/forge.h>
+#define LV2_CANVAS_RENDER_CAIRO
#include <canvas.lv2/render.h>
#include <lv2_extensions.h>
diff --git a/canvas_display_ui.ttl b/canvas_display_ui.ttl
index 8abc45e..951317e 100644
--- a/canvas_display_ui.ttl
+++ b/canvas_display_ui.ttl
@@ -26,5 +26,5 @@ canvas:display_ui
lv2:symbol "notify" ;
ui:protocol atom:eventTransfer
] ;
- lv2:requiredFeature ui:idleInterface, urid:map ;
+ lv2:requiredFeature ui:idleInterface, urid:map, ui:portMap ;
lv2:extensionData ui:idleInterface .
diff --git a/canvas_ui.c b/canvas_ui.c
index 66cdad0..762a719 100644
--- a/canvas_ui.c
+++ b/canvas_ui.c
@@ -22,12 +22,12 @@
#include <lv2/lv2plug.in/ns/ext/patch/patch.h>
#include <lv2/lv2plug.in/ns/extensions/ui/ui.h>
-#include <canvas.lv2/forge.h>
-#include <canvas.lv2/render.h>
-
+#include <GL/glew.h>
#include <pugl/pugl.h>
-#include <cairo/cairo.h>
+#include <canvas.lv2/forge.h>
+#define LV2_CANVAS_RENDER_NANOVG
+#include <canvas.lv2/render.h>
typedef struct _plughandle_t plughandle_t;
@@ -48,6 +48,7 @@ struct _plughandle_t {
LV2_URID patch_value;
LV2_URID patch_body;
LV2_URID atom_eventTransfer;
+ LV2_URID control_idx;
float aspect_ratio;
LV2_Atom_Tuple *graph;
@@ -55,6 +56,10 @@ struct _plughandle_t {
LV2UI_Write_Function writer;
LV2UI_Controller controller;
+ NVGcontext *ctx;
+ unsigned w;
+ unsigned h;
+
union {
LV2_Atom atom;
uint8_t buf [512];
@@ -71,7 +76,8 @@ static inline void
_event_commit(plughandle_t *handle)
{
const uint32_t sz = lv2_atom_total_size(&handle->dst.atom);
- handle->writer(handle->controller, 0, sz, handle->atom_eventTransfer, &handle->dst.atom);
+ handle->writer(handle->controller, handle->control_idx,
+ sz, handle->atom_eventTransfer, &handle->dst.atom);
}
static inline void
@@ -135,14 +141,15 @@ _input_commit(plughandle_t *handle, LV2_Atom_Forge_Frame frame [2])
static inline void
_expose(plughandle_t *handle)
{
-#ifndef _WIN32 //FIXME
- cairo_t *ctx = puglGetContext(handle->view);
+ glViewport(0, 0, handle->w, handle->h);
+ glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- if(ctx)
- {
- lv2_canvas_render(&handle->canvas, ctx, handle->graph);
- }
-#endif
+ nvgBeginFrame(handle->ctx, handle->w, handle->h, 1.f);
+
+ lv2_canvas_render(&handle->canvas, handle->ctx, handle->graph);
+
+ nvgEndFrame(handle->ctx);
}
static inline void
@@ -154,15 +161,8 @@ _close(plughandle_t *handle)
static inline void
_configure(plughandle_t *handle, const PuglEventConfigure *e)
{
-#ifndef _WIN32 //FIXME
- cairo_t *ctx = puglGetContext(handle->view);
-
- if(ctx)
- {
- cairo_surface_t *surf = cairo_get_target(ctx);
- cairo_surface_set_device_scale(surf, e->width, e->height);
- }
-#endif
+ handle->w = e->width;
+ handle->h = e->height;
}
static void
@@ -337,6 +337,7 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
return NULL;
void *parent = NULL;
+ LV2UI_Port_Map *pmap = NULL;
for(int i=0; features[i]; i++)
{
if(!strcmp(features[i]->URI, LV2_UI__parent))
@@ -345,6 +346,8 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
handle->host_resize = features[i]->data;
else if(!strcmp(features[i]->URI, LV2_URID__map))
handle->map = features[i]->data;
+ else if(!strcmp(features[i]->URI, LV2_UI__portMap))
+ pmap = features[i]->data;
}
if(!parent)
@@ -361,6 +364,16 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
free(handle);
return NULL;
}
+ if(!pmap)
+ {
+ fprintf(stderr,
+ "%s: Host does not support ui:portMap\n", descriptor->URI);
+ free(handle);
+ return NULL;
+ }
+
+ handle->control_idx = pmap->port_index(pmap->handle, "control");
+ fprintf(stderr, "control_idx: %u\n", handle->control_idx);
lv2_atom_forge_init(&handle->forge, handle->map);
@@ -379,29 +392,20 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
return NULL;
}
- const unsigned w = 640;
- const unsigned h = 640;;
+ handle->w = 640;
+ handle->h = 640;;
puglInitWindowClass(handle->view, "canvas");
puglInitWindowParent(handle->view, (intptr_t)parent);
- puglInitWindowSize(handle->view, w, h);
- puglInitWindowMinSize(handle->view, w/8, h/8);
+ puglInitWindowSize(handle->view, handle->w, handle->h);
+ puglInitWindowMinSize(handle->view, handle->w/8, handle->h/8);
//puglInitWindowAspectRatio(handle->view, 1, 1, 1, 1);
puglInitResizable(handle->view, true);
puglInitTransientFor(handle->view, (intptr_t)parent);
puglSetHandle(handle->view, handle);
puglSetEventFunc(handle->view, _event_func);
- int stat;
-#ifdef PUGL_HAVE_GL
- puglInitContextType(handle->view, PUGL_CAIRO_GL);
- stat = puglCreateWindow(handle->view, "CanvasGL");
- if(stat != 0)
-#endif
- {
- fprintf(stderr, "falling back to non-GL\n");
- puglInitContextType(handle->view, PUGL_CAIRO);
- stat = puglCreateWindow(handle->view, "Canvas");
- }
+ puglInitContextType(handle->view, PUGL_GL);
+ const int stat = puglCreateWindow(handle->view, "CanvasGL");
if(stat != 0)
{
@@ -411,17 +415,25 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
}
puglShowWindow(handle->view);
-#ifndef _WIN32 //FIXME
- cairo_t *ctx = puglGetContext(handle->view);
- cairo_surface_t *surf = cairo_get_target(ctx);
- cairo_surface_set_device_scale(surf, w, h);
-#endif
+ glewExperimental = GL_TRUE;
+ if(glewInit() != GLEW_OK)
+ {
+ free(handle);
+ return NULL;
+ }
+
+ handle->ctx = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
+ if(!handle->ctx)
+ {
+ free(handle);
+ return NULL;
+ }
const intptr_t child = puglGetNativeWindow(handle->view);
*(intptr_t *)widget = child;
if(handle->host_resize)
- handle->host_resize->ui_resize(handle->host_resize->handle, w, h);
+ handle->host_resize->ui_resize(handle->host_resize->handle, handle->w, handle->h);
lv2_canvas_init(&handle->canvas, handle->map);
@@ -440,6 +452,9 @@ cleanup(LV2UI_Handle instance)
if(handle->graph)
free(handle->graph);
+ if(handle->ctx)
+ nvgDeleteGL3(handle->ctx);
+
if(handle->view)
{
if(puglGetVisible(handle->view))
diff --git a/meson.build b/meson.build
index 35776d4..1ec946b 100644
--- a/meson.build
+++ b/meson.build
@@ -13,12 +13,13 @@ cairo_dep = dependency('cairo', version : '>=1.0.0',
static : meson.is_cross_build())
dsp_deps = [m_dep, lv2_dep, cairo_dep]
-ui_deps = [m_dep, lv2_dep, cairo_dep]
+ui_deps = [m_dep, lv2_dep]
pugl_inc = include_directories('pugl')
-canvas_inc = include_directories('canvas.lv2')
+nanovg_inc = include_directories('nanovg/src')
+canvas_inc = include_directories('canvas.lv2.new')
ardour_inc = include_directories('ardour.lv2')
-inc_dir = [pugl_inc, canvas_inc, ardour_inc]
+inc_dir = [pugl_inc, nanovg_inc, canvas_inc, ardour_inc]
inst_dir = join_paths(get_option('libdir'), 'lv2', meson.project_name())
@@ -32,21 +33,20 @@ conf_data.set('MICRO_VERSION', version[2])
add_project_arguments('-D_GNU_SOURCE', language : 'c')
add_project_arguments('-DPUGL_HAVE_GL', language : 'c')
-add_project_arguments('-DPUGL_HAVE_CAIRO', language : 'c')
cp = find_program('cp')
clone = [cp, '@INPUT@', '@OUTPUT@']
dsp_srcs = ['canvas.c']
-ui_srcs = ['canvas_ui.c']
+ui_srcs = ['canvas_ui.c', 'nanovg/src/nanovg.c']
c_args = ['-fvisibility=hidden',
'-ffast-math']
if host_machine.system() == 'linux'
conf_data.set('UI_TYPE', 'X11UI')
- ui_deps += dependency('gl')
+ ui_deps += dependency('glew')
ui_deps += dependency('x11', version : '>=1.6.0')
ui_deps += dependency('xext', version : '>=1.3.0')
ui_srcs += 'pugl/pugl/pugl_x11.c'