diff options
author | David Robillard <d@drobilla.net> | 2019-07-26 23:17:27 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-07-28 19:06:39 +0200 |
commit | 6a3159df3e41cfef6d94ff52f2cf9c5375254243 (patch) | |
tree | b4822a4010467c9db9bb30f504405e0a84115618 /pugl | |
parent | 65e0b7d4ea463d1f8eb3231ce9703c9f91c9b270 (diff) | |
download | pugl-6a3159df3e41cfef6d94ff52f2cf9c5375254243.tar.gz pugl-6a3159df3e41cfef6d94ff52f2cf9c5375254243.tar.bz2 pugl-6a3159df3e41cfef6d94ff52f2cf9c5375254243.zip |
Give backends general names
Towards making them opaque and exposing them to the user to decouple the core
library from backends.
The general names mean that it won't be possible to build multiple backends for
one platform into the same binary, but that seems reasonable for now, and it
will make things simpler without needing to add a bunch of dispatch code. That
will still be possible if it's ever needed, though.
Diffstat (limited to 'pugl')
-rw-r--r-- | pugl/pugl_cairo_backend.h (renamed from pugl/pugl_x11_gl.h) | 19 | ||||
-rw-r--r-- | pugl/pugl_gl_backend.h (renamed from pugl/pugl_x11_cairo.h) | 19 | ||||
-rw-r--r-- | pugl/pugl_x11.c | 26 | ||||
-rw-r--r-- | pugl/pugl_x11.h | 2 | ||||
-rw-r--r-- | pugl/pugl_x11_cairo.c | 8 | ||||
-rw-r--r-- | pugl/pugl_x11_gl.c | 8 |
6 files changed, 52 insertions, 30 deletions
diff --git a/pugl/pugl_x11_gl.h b/pugl/pugl_cairo_backend.h index 66cd8f3..b48915e 100644 --- a/pugl/pugl_x11_gl.h +++ b/pugl/pugl_cairo_backend.h @@ -14,9 +14,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef PUGL_X11_GL_H -#define PUGL_X11_GL_H +#ifndef PUGL_CAIRO_BACKEND_H +#define PUGL_CAIRO_BACKEND_H -PuglBackend puglGetX11GlBackend(void); +#include "pugl/pugl_internal_types.h" -#endif // PUGL_X11_GL_H +#ifdef __cplusplus +extern "C" { +#endif + +PUGL_API const PuglBackend* +puglCairoBackend(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // PUGL_CAIRO_BACKEND_H diff --git a/pugl/pugl_x11_cairo.h b/pugl/pugl_gl_backend.h index 085cc0b..11f4e4b 100644 --- a/pugl/pugl_x11_cairo.h +++ b/pugl/pugl_gl_backend.h @@ -14,9 +14,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef PUGL_X11_CAIRO_H -#define PUGL_X11_CAIRO_H +#ifndef PUGL_GL_BACKEND_H +#define PUGL_GL_BACKEND_H -PuglBackend puglGetX11CairoBackend(void); +#include "pugl/pugl_internal_types.h" -#endif // PUGL_X11_CAIRO_H +#ifdef __cplusplus +extern "C" { +#endif + +PUGL_API const PuglBackend* +puglGlBackend(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // PUGL_GL_BACKEND_H diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 55ea94f..ff44aef 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -26,10 +26,10 @@ #include "pugl/pugl_x11.h" #ifdef PUGL_HAVE_GL -#include "pugl/pugl_x11_gl.h" +#include "pugl/pugl_gl_backend.h" #endif #ifdef PUGL_HAVE_CAIRO -#include "pugl/pugl_x11_cairo.h" +#include "pugl/pugl_cairo_backend.h" #endif #include <X11/Xatom.h> @@ -70,13 +70,13 @@ puglInitInternals(void) void puglEnterContext(PuglView* view) { - view->impl->backend.enter(view); + view->impl->backend->enter(view); } void puglLeaveContext(PuglView* view, bool flush) { - view->impl->backend.leave(view, flush); + view->impl->backend->leave(view, flush); } int @@ -97,19 +97,19 @@ puglCreateWindow(PuglView* view, const char* title) if (view->ctx_type == PUGL_GL) { #ifdef PUGL_HAVE_GL - impl->backend = puglGetX11GlBackend(); + impl->backend = puglGlBackend(); #endif } if (view->ctx_type == PUGL_CAIRO) { #ifdef PUGL_HAVE_CAIRO - impl->backend = puglGetX11CairoBackend(); + impl->backend = puglCairoBackend(); #endif } - if (!impl->backend.configure) { + if (!impl->backend->configure) { return 1; - } else if (impl->backend.configure(view) || !impl->vi) { - impl->backend.destroy(view); + } else if (impl->backend->configure(view) || !impl->vi) { + impl->backend->destroy(view); return 2; } @@ -128,7 +128,7 @@ puglCreateWindow(PuglView* view, const char* title) 0, 0, view->width, view->height, 0, impl->vi->depth, InputOutput, impl->vi->visual, CWColormap | CWEventMask, &attr); - if (impl->backend.create(view)) { + if (impl->backend->create(view)) { return 3; } @@ -211,7 +211,7 @@ puglDestroy(PuglView* view) if (view->impl->xim) { XCloseIM(view->impl->xim); } - view->impl->backend.destroy(view); + view->impl->backend->destroy(view); XDestroyWindow(view->impl->display, view->impl->win); XCloseDisplay(view->impl->display); XFree(view->impl->vi); @@ -564,7 +564,7 @@ puglProcessEvents(PuglView* view) if (config_event.type) { view->width = (int)config_event.configure.width; view->height = (int)config_event.configure.height; - impl->backend.resize(view, view->width, view->height); + impl->backend->resize(view, view->width, view->height); view->eventFunc(view, (const PuglEvent*)&config_event); } @@ -608,5 +608,5 @@ puglGetNativeWindow(PuglView* view) void* puglGetContext(PuglView* view) { - return view->impl->backend.getContext(view); + return view->impl->backend->getContext(view); } diff --git a/pugl/pugl_x11.h b/pugl/pugl_x11.h index 6efc145..18b49f7 100644 --- a/pugl/pugl_x11.h +++ b/pugl/pugl_x11.h @@ -27,7 +27,7 @@ struct PuglInternalsImpl { Window win; XIM xim; XIC xic; - PuglBackend backend; + const PuglBackend* backend; PuglSurface* surface; struct { diff --git a/pugl/pugl_x11_cairo.c b/pugl/pugl_x11_cairo.c index d045584..a0a0789 100644 --- a/pugl/pugl_x11_cairo.c +++ b/pugl/pugl_x11_cairo.c @@ -14,9 +14,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "pugl/pugl_cairo_backend.h" #include "pugl/pugl_internal_types.h" #include "pugl/pugl_x11.h" -#include "pugl/pugl_x11_cairo.h" #include <X11/Xutil.h> #include <cairo-xlib.h> @@ -118,9 +118,9 @@ puglX11CairoGetContext(PuglView* view) return surface->cr; } -PuglBackend puglGetX11CairoBackend(void) +const PuglBackend* puglCairoBackend(void) { - static const PuglBackend puglX11CairoBackend = { + static const PuglBackend backend = { puglX11CairoConfigure, puglX11CairoCreate, puglX11CairoDestroy, @@ -130,5 +130,5 @@ PuglBackend puglGetX11CairoBackend(void) puglX11CairoGetContext }; - return puglX11CairoBackend; + return &backend; } diff --git a/pugl/pugl_x11_gl.c b/pugl/pugl_x11_gl.c index a4e0f3a..46caaa0 100644 --- a/pugl/pugl_x11_gl.c +++ b/pugl/pugl_x11_gl.c @@ -14,9 +14,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "pugl/pugl_gl_backend.h" #include "pugl/pugl_internal_types.h" #include "pugl/pugl_x11.h" -#include "pugl/pugl_x11_gl.h" #include <GL/gl.h> #include <GL/glx.h> @@ -193,9 +193,9 @@ puglGetProcAddress(const char* name) return glXGetProcAddress((const GLubyte*)name); } -PuglBackend puglGetX11GlBackend(void) +const PuglBackend* puglGlBackend(void) { - static const PuglBackend puglX11GlBackend = { + static const PuglBackend backend = { puglX11GlConfigure, puglX11GlCreate, puglX11GlDestroy, @@ -205,5 +205,5 @@ PuglBackend puglGetX11GlBackend(void) puglX11GlGetContext }; - return puglX11GlBackend; + return &backend; } |