From 6a3159df3e41cfef6d94ff52f2cf9c5375254243 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 26 Jul 2019 23:17:27 +0200 Subject: 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. --- pugl/pugl_cairo_backend.h | 33 +++++++++++++++++++++++++++++++++ pugl/pugl_gl_backend.h | 33 +++++++++++++++++++++++++++++++++ pugl/pugl_x11.c | 26 +++++++++++++------------- pugl/pugl_x11.h | 2 +- pugl/pugl_x11_cairo.c | 8 ++++---- pugl/pugl_x11_cairo.h | 22 ---------------------- pugl/pugl_x11_gl.c | 8 ++++---- pugl/pugl_x11_gl.h | 22 ---------------------- 8 files changed, 88 insertions(+), 66 deletions(-) create mode 100644 pugl/pugl_cairo_backend.h create mode 100644 pugl/pugl_gl_backend.h delete mode 100644 pugl/pugl_x11_cairo.h delete mode 100644 pugl/pugl_x11_gl.h (limited to 'pugl') diff --git a/pugl/pugl_cairo_backend.h b/pugl/pugl_cairo_backend.h new file mode 100644 index 0000000..b48915e --- /dev/null +++ b/pugl/pugl_cairo_backend.h @@ -0,0 +1,33 @@ +/* + Copyright 2012-2019 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef PUGL_CAIRO_BACKEND_H +#define PUGL_CAIRO_BACKEND_H + +#include "pugl/pugl_internal_types.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_gl_backend.h b/pugl/pugl_gl_backend.h new file mode 100644 index 0000000..11f4e4b --- /dev/null +++ b/pugl/pugl_gl_backend.h @@ -0,0 +1,33 @@ +/* + Copyright 2012-2019 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef PUGL_GL_BACKEND_H +#define PUGL_GL_BACKEND_H + +#include "pugl/pugl_internal_types.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 @@ -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 #include @@ -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_cairo.h b/pugl/pugl_x11_cairo.h deleted file mode 100644 index 085cc0b..0000000 --- a/pugl/pugl_x11_cairo.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - Copyright 2012-2019 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#ifndef PUGL_X11_CAIRO_H -#define PUGL_X11_CAIRO_H - -PuglBackend puglGetX11CairoBackend(void); - -#endif // PUGL_X11_CAIRO_H 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 #include @@ -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; } diff --git a/pugl/pugl_x11_gl.h b/pugl/pugl_x11_gl.h deleted file mode 100644 index 66cd8f3..0000000 --- a/pugl/pugl_x11_gl.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - Copyright 2012-2019 David Robillard - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#ifndef PUGL_X11_GL_H -#define PUGL_X11_GL_H - -PuglBackend puglGetX11GlBackend(void); - -#endif // PUGL_X11_GL_H -- cgit v1.2.1