diff --git a/dgl/Base.hpp b/dgl/Base.hpp index dc6bdb8f..24a7cb01 100644 --- a/dgl/Base.hpp +++ b/dgl/Base.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2016 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * 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 @@ -184,15 +184,6 @@ enum Key { kKeySuper }; -/** - Type of graphics context. - */ -enum ContextType -{ - kContextGL, - kContextCairo -}; - // ----------------------------------------------------------------------- // Base DGL classes @@ -211,15 +202,9 @@ public: */ struct Context { - ContextType type; - union { -#ifdef HAVE_DGL - struct { /* nothing for now */ } gl; -#endif #ifdef HAVE_DCAIRO - struct { cairo_t* graphics; } cairo; + cairo_t* cairo; #endif - }; }; // ----------------------------------------------------------------------- diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index f6124273..118008d7 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2019 Filipe Coelho * * 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 @@ -213,15 +213,6 @@ struct Window::PrivateData { return; } -#ifdef HAVE_DGL - const ContextType contextType = kContextGL; -#endif -#ifdef HAVE_DCAIRO - const ContextType contextType = kContextCairo; -#endif - fContext.type = contextType; - - puglInitContextType(fView, (PuglContextType)contextType); puglInitUserResizable(fView, fResizable); puglInitWindowSize(fView, static_cast(fWidth), static_cast(fHeight)); diff --git a/dgl/src/pugl/pugl.h b/dgl/src/pugl/pugl.h index a2ffa85d..898ef056 100644 --- a/dgl/src/pugl/pugl.h +++ b/dgl/src/pugl/pugl.h @@ -1,5 +1,6 @@ /* Copyright 2012-2014 David Robillard + Copyright 2012-2019 Filipe Coelho Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -273,20 +274,6 @@ puglInitUserResizable(PuglView* view, bool resizable); PUGL_API void puglInitTransientFor(PuglView* view, uintptr_t parent); -/** - Drawing context type. -*/ -typedef enum { - PUGL_GL, - PUGL_CAIRO -} PuglContextType; - -/** - Set the context type before creating a window. -*/ -PUGL_API void -puglInitContextType(PuglView* view, PuglContextType type); - /** @} */ @@ -365,8 +352,8 @@ puglGetHandle(PuglView* view); /** Get the drawing context. - For PUGL_GL contexts, this is unused and returns NULL. - For PUGL_CAIRO contexts, this returns a pointer to a cairo_t. + For Cairo contexts, this returns a pointer to a cairo_t. + For everything else, this is unused and returns NULL. */ PUGL_API void* puglGetContext(PuglView* view); diff --git a/dgl/src/pugl/pugl_internal.h b/dgl/src/pugl/pugl_internal.h index b8d9ca93..0a353275 100644 --- a/dgl/src/pugl/pugl_internal.h +++ b/dgl/src/pugl/pugl_internal.h @@ -1,5 +1,6 @@ /* Copyright 2012-2014 David Robillard + Copyright 2012-2019 Filipe Coelho Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -41,7 +42,6 @@ struct PuglViewImpl { PuglInternals* impl; PuglNativeWindow parent; - PuglContextType ctx_type; uintptr_t transient_parent; int width; @@ -141,12 +141,6 @@ puglCreate(PuglNativeWindow parent, return view; } -void -puglInitContextType(PuglView* view, PuglContextType type) -{ - view->ctx_type = type; -} - void puglSetHandle(PuglView* view, PuglHandle handle) { diff --git a/dgl/src/pugl/pugl_osx.m b/dgl/src/pugl/pugl_osx.m index 4e5ba89c..18191628 100644 --- a/dgl/src/pugl/pugl_osx.m +++ b/dgl/src/pugl/pugl_osx.m @@ -1,5 +1,6 @@ /* Copyright 2012 David Robillard + Copyright 2012-2019 Filipe Coelho Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -774,25 +775,23 @@ void puglEnterContext(PuglView* view) { #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - [[view->impl->glview openGLContext] makeCurrentContext]; - } + [[view->impl->glview openGLContext] makeCurrentContext]; #endif } void puglLeaveContext(PuglView* view, bool flush) { + if (flush) { #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL && flush) { if (view->impl->glview->doubleBuffered) { [[view->impl->glview openGLContext] flushBuffer]; } else { glFlush(); } //[NSOpenGLContext clearCurrentContext]; - } #endif + } } int @@ -804,14 +803,10 @@ puglCreateWindow(PuglView* view, const char* title) [NSApplication sharedApplication]; #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - impl->glview = [PuglOpenGLView new]; - } + impl->glview = [PuglOpenGLView new]; #endif #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - impl->cairoview = [PuglCairoView new]; - } + impl->cairoview = [PuglCairoView new]; #endif if (!impl->view) { @@ -925,9 +920,7 @@ void* puglGetContext(PuglView* view) { #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - return [view->impl->cairoview cairoContext]; - } + return [view->impl->cairoview cairoContext]; #endif return NULL; diff --git a/dgl/src/pugl/pugl_win.cpp b/dgl/src/pugl/pugl_win.cpp index a731b877..445820bd 100644 --- a/dgl/src/pugl/pugl_win.cpp +++ b/dgl/src/pugl/pugl_win.cpp @@ -1,5 +1,6 @@ /* Copyright 2012-2014 David Robillard + Copyright 2012-2019 Filipe Coelho Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -90,9 +91,7 @@ void puglEnterContext(PuglView* view) { #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - wglMakeCurrent(view->impl->hdc, view->impl->hglrc); - } + wglMakeCurrent(view->impl->hdc, view->impl->hglrc); #endif } @@ -100,13 +99,11 @@ void puglLeaveContext(PuglView* view, bool flush) { #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - if (flush) { - glFlush(); - SwapBuffers(view->impl->hdc); - } - wglMakeCurrent(NULL, NULL); + if (flush) { + glFlush(); + SwapBuffers(view->impl->hdc); } + wglMakeCurrent(NULL, NULL); #endif } @@ -181,31 +178,29 @@ puglCreateWindow(PuglView* view, const char* title) SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view); #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - impl->hdc = GetDC(impl->hwnd); - - PIXELFORMATDESCRIPTOR pfd; - ZeroMemory(&pfd, sizeof(pfd)); - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 24; - pfd.cDepthBits = 16; - pfd.iLayerType = PFD_MAIN_PLANE; - - int format = ChoosePixelFormat(impl->hdc, &pfd); - SetPixelFormat(impl->hdc, format, &pfd); - - impl->hglrc = wglCreateContext(impl->hdc); - if (!impl->hglrc) { - ReleaseDC (impl->hwnd, impl->hdc); - DestroyWindow (impl->hwnd); - UnregisterClass (impl->wc.lpszClassName, NULL); - free((void*)impl->wc.lpszClassName); - free(impl); - return 1; - } + impl->hdc = GetDC(impl->hwnd); + + PIXELFORMATDESCRIPTOR pfd; + ZeroMemory(&pfd, sizeof(pfd)); + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 24; + pfd.cDepthBits = 16; + pfd.iLayerType = PFD_MAIN_PLANE; + + int format = ChoosePixelFormat(impl->hdc, &pfd); + SetPixelFormat(impl->hdc, format, &pfd); + + impl->hglrc = wglCreateContext(impl->hdc); + if (!impl->hglrc) { + ReleaseDC (impl->hwnd, impl->hdc); + DestroyWindow (impl->hwnd); + UnregisterClass (impl->wc.lpszClassName, NULL); + free((void*)impl->wc.lpszClassName); + free(impl); + return 1; } #endif @@ -234,17 +229,13 @@ puglDestroy(PuglView* view) PuglInternals* const impl = view->impl; #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - wglMakeCurrent(NULL, NULL); - wglDeleteContext(impl->hglrc); - ReleaseDC(impl->hwnd, impl->hdc); - } + wglMakeCurrent(NULL, NULL); + wglDeleteContext(impl->hglrc); + ReleaseDC(impl->hwnd, impl->hdc); #endif #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - cairo_destroy(impl->buffer_cr); - cairo_surface_destroy(impl->buffer_surface); - } + cairo_destroy(impl->buffer_cr); + cairo_surface_destroy(impl->buffer_surface); #endif DestroyWindow(impl->hwnd); UnregisterClass(impl->wc.lpszClassName, NULL); @@ -282,26 +273,24 @@ puglDisplay(PuglView* view) cairo_surface_t *ws = NULL; cairo_surface_t *bs = NULL; - if (view->ctx_type == PUGL_CAIRO) { - HDC hdc = impl->paintHdc; - bc = impl->buffer_cr; - bs = impl->buffer_surface; - int w = view->width; - int h = view->height; - int bw = bs ? cairo_image_surface_get_width(bs) : -1; - int bh = bs ? cairo_image_surface_get_height(bs) : -1; - ws = hdc ? cairo_win32_surface_create(hdc) : NULL; - wc = ws ? cairo_create(ws) : NULL; - if (wc && (!bc || bw != w || bh != h)) { - cairo_destroy(bc); - cairo_surface_destroy(bs); - bs = cairo_surface_create_similar_image(ws, CAIRO_FORMAT_ARGB32, w, h); - bc = bs ? cairo_create(bs) : NULL; - impl->buffer_cr = bc; - impl->buffer_surface = bs; - } - success = wc != NULL && bc != NULL; + HDC hdc = impl->paintHdc; + bc = impl->buffer_cr; + bs = impl->buffer_surface; + int w = view->width; + int h = view->height; + int bw = bs ? cairo_image_surface_get_width(bs) : -1; + int bh = bs ? cairo_image_surface_get_height(bs) : -1; + ws = hdc ? cairo_win32_surface_create(hdc) : NULL; + wc = ws ? cairo_create(ws) : NULL; + if (wc && (!bc || bw != w || bh != h)) { + cairo_destroy(bc); + cairo_surface_destroy(bs); + bs = cairo_surface_create_similar_image(ws, CAIRO_FORMAT_ARGB32, w, h); + bc = bs ? cairo_create(bs) : NULL; + impl->buffer_cr = bc; + impl->buffer_surface = bs; } + success = wc != NULL && bc != NULL; #endif if (success) { @@ -310,20 +299,16 @@ puglDisplay(PuglView* view) view->displayFunc(view); } #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - cairo_set_source_surface(wc, bs, 0, 0); - cairo_paint(wc); - } + cairo_set_source_surface(wc, bs, 0, 0); + cairo_paint(wc); #endif } puglLeaveContext(view, success); #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - cairo_destroy(wc); - cairo_surface_destroy(ws); - } + cairo_destroy(wc); + cairo_surface_destroy(ws); #endif return; @@ -561,9 +546,7 @@ void* puglGetContext(PuglView* view) { #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - return view->impl->buffer_cr; - } + return view->impl->buffer_cr; #endif return NULL; diff --git a/dgl/src/pugl/pugl_x11.c b/dgl/src/pugl/pugl_x11.c index a0dee411..44202830 100644 --- a/dgl/src/pugl/pugl_x11.c +++ b/dgl/src/pugl/pugl_x11.c @@ -2,6 +2,7 @@ Copyright 2012-2014 David Robillard Copyright 2011-2012 Ben Loftis, Harrison Consoles Copyright 2013,2015 Robin Gareus + Copyright 2012-2019 Filipe Coelho Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -129,9 +130,7 @@ void puglEnterContext(PuglView* view) { #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - glXMakeCurrent(view->impl->display, view->impl->win, view->impl->ctx); - } + glXMakeCurrent(view->impl->display, view->impl->win, view->impl->ctx); #endif } @@ -139,15 +138,13 @@ void puglLeaveContext(PuglView* view, bool flush) { #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - if (flush) { - glFlush(); - if (view->impl->doubleBuffered) { - glXSwapBuffers(view->impl->display, view->impl->win); - } + if (flush) { + glFlush(); + if (view->impl->doubleBuffered) { + glXSwapBuffers(view->impl->display, view->impl->win); } - glXMakeCurrent(view->impl->display, None, NULL); } + glXMakeCurrent(view->impl->display, None, NULL); #endif } @@ -170,30 +167,26 @@ puglCreateWindow(PuglView* view, const char* title) XVisualInfo* vi = NULL; #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - impl->doubleBuffered = True; - vi = glXChooseVisual(impl->display, impl->screen, attrListDblMS); + impl->doubleBuffered = True; + vi = glXChooseVisual(impl->display, impl->screen, attrListDblMS); - if (!vi) { - vi = glXChooseVisual(impl->display, impl->screen, attrListDbl); + if (!vi) { + vi = glXChooseVisual(impl->display, impl->screen, attrListDbl); #ifdef PUGL_VERBOSE - printf("puGL: multisampling (antialiasing) is not available\n"); + printf("puGL: multisampling (antialiasing) is not available\n"); #endif - } + } - if (!vi) { - vi = glXChooseVisual(impl->display, impl->screen, attrListSgl); - impl->doubleBuffered = False; - } + if (!vi) { + vi = glXChooseVisual(impl->display, impl->screen, attrListSgl); + impl->doubleBuffered = False; } #endif #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - XVisualInfo pat; - int n; - pat.screen = impl->screen; - vi = XGetVisualInfo(impl->display, VisualScreenMask, &pat, &n); - } + XVisualInfo pat; + int n; + pat.screen = impl->screen; + vi = XGetVisualInfo(impl->display, VisualScreenMask, &pat, &n); #endif if (!vi) { @@ -211,15 +204,13 @@ puglCreateWindow(PuglView* view, const char* title) #endif #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - impl->ctx = glXCreateContext(impl->display, vi, 0, GL_TRUE); - - if (!impl->ctx) { - XFree(vi); - XCloseDisplay(impl->display); - free(impl); - return 1; - } + impl->ctx = glXCreateContext(impl->display, vi, 0, GL_TRUE); + + if (!impl->ctx) { + XFree(vi); + XCloseDisplay(impl->display); + free(impl); + return 1; } #endif @@ -247,9 +238,7 @@ puglCreateWindow(PuglView* view, const char* title) if (!impl->win) { #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - glXDestroyContext(impl->display, impl->ctx); - } + glXDestroyContext(impl->display, impl->ctx); #endif XFree(vi); XCloseDisplay(impl->display); @@ -258,25 +247,23 @@ puglCreateWindow(PuglView* view, const char* title) } #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - impl->xlib_surface = cairo_xlib_surface_create( - impl->display, impl->win, vi->visual, view->width, view->height); - if (impl->xlib_surface == NULL || cairo_surface_status(impl->xlib_surface) != CAIRO_STATUS_SUCCESS) { - printf("puGL: failed to create cairo surface\n"); - } - else { - impl->xlib_cr = cairo_create(impl->xlib_surface); - } - if (impl->xlib_cr == NULL || cairo_status(impl->xlib_cr) != CAIRO_STATUS_SUCCESS) { - cairo_destroy(impl->xlib_cr); - cairo_surface_destroy(impl->xlib_surface); - XDestroyWindow(impl->display, impl->win); - XFree(vi); - XCloseDisplay(impl->display); - free(impl); - printf("puGL: failed to create cairo context\n"); - return 1; - } + impl->xlib_surface = cairo_xlib_surface_create( + impl->display, impl->win, vi->visual, view->width, view->height); + if (impl->xlib_surface == NULL || cairo_surface_status(impl->xlib_surface) != CAIRO_STATUS_SUCCESS) { + printf("puGL: failed to create cairo surface\n"); + } + else { + impl->xlib_cr = cairo_create(impl->xlib_surface); + } + if (impl->xlib_cr == NULL || cairo_status(impl->xlib_cr) != CAIRO_STATUS_SUCCESS) { + cairo_destroy(impl->xlib_cr); + cairo_surface_destroy(impl->xlib_surface); + XDestroyWindow(impl->display, impl->win); + XFree(vi); + XCloseDisplay(impl->display); + free(impl); + printf("puGL: failed to create cairo context\n"); + return 1; } #endif @@ -328,17 +315,13 @@ puglDestroy(PuglView* view) #endif #ifdef PUGL_HAVE_GL - if (view->ctx_type == PUGL_GL) { - glXDestroyContext(impl->display, impl->ctx); - } + glXDestroyContext(impl->display, impl->ctx); #endif #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - cairo_destroy(impl->xlib_cr); - cairo_destroy(impl->buffer_cr); - cairo_surface_destroy(impl->xlib_surface); - cairo_surface_destroy(impl->buffer_surface); - } + cairo_destroy(impl->xlib_cr); + cairo_destroy(impl->buffer_cr); + cairo_surface_destroy(impl->xlib_surface); + cairo_surface_destroy(impl->buffer_surface); #endif XDestroyWindow(impl->display, impl->win); XCloseDisplay(impl->display); @@ -383,28 +366,26 @@ puglDisplay(PuglView* view) puglEnterContext(view); #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - cairo_t* bc = impl->buffer_cr; - cairo_surface_t* xs = impl->xlib_surface; - cairo_surface_t* bs = impl->buffer_surface; - int w = cairo_xlib_surface_get_width(xs); - int h = cairo_xlib_surface_get_height(xs); - - int bw = bs ? cairo_image_surface_get_width(bs) : -1; - int bh = bs ? cairo_image_surface_get_height(bs) : -1; - if (!bc || bw != w || bh != h) { - cairo_destroy(bc); - cairo_surface_destroy(bs); - bs = cairo_surface_create_similar_image(xs, CAIRO_FORMAT_ARGB32, w, h); - bc = bs ? cairo_create(bs) : NULL; - impl->buffer_cr = bc; - impl->buffer_surface = bs; - } - - if (!bc) { - puglLeaveContext(view, false); - return; - } + cairo_t* bc = impl->buffer_cr; + cairo_surface_t* xs = impl->xlib_surface; + cairo_surface_t* bs = impl->buffer_surface; + int w = cairo_xlib_surface_get_width(xs); + int h = cairo_xlib_surface_get_height(xs); + + int bw = bs ? cairo_image_surface_get_width(bs) : -1; + int bh = bs ? cairo_image_surface_get_height(bs) : -1; + if (!bc || bw != w || bh != h) { + cairo_destroy(bc); + cairo_surface_destroy(bs); + bs = cairo_surface_create_similar_image(xs, CAIRO_FORMAT_ARGB32, w, h); + bc = bs ? cairo_create(bs) : NULL; + impl->buffer_cr = bc; + impl->buffer_surface = bs; + } + + if (!bc) { + puglLeaveContext(view, false); + return; } #endif @@ -414,11 +395,9 @@ puglDisplay(PuglView* view) } #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - cairo_t* xc = impl->xlib_cr; - cairo_set_source_surface(xc, impl->buffer_surface, 0, 0); - cairo_paint(xc); - } + cairo_t* xc = impl->xlib_cr; + cairo_set_source_surface(xc, impl->buffer_surface, 0, 0); + cairo_paint(xc); #endif puglLeaveContext(view, true); @@ -683,12 +662,10 @@ puglProcessEvents(PuglView* view) if (conf_width != -1) { #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - // Resize surfaces/contexts before dispatching - view->redisplay = true; - cairo_xlib_surface_set_size(view->impl->xlib_surface, - conf_width, conf_height); - } + // Resize surfaces/contexts before dispatching + view->redisplay = true; + cairo_xlib_surface_set_size(view->impl->xlib_surface, + conf_width, conf_height); #endif puglReshape(view, conf_width, conf_height); } @@ -726,9 +703,7 @@ void* puglGetContext(PuglView* view) { #ifdef PUGL_HAVE_CAIRO - if (view->ctx_type == PUGL_CAIRO) { - return view->impl->buffer_cr; - } + return view->impl->buffer_cr; #endif return NULL;