Signed-off-by: falkTX <falktx@gmail.com>pull/99/head
@@ -1,6 +1,6 @@ | |||||
/* | /* | ||||
* DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com> | |||||
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com> | |||||
* | * | ||||
* Permission to use, copy, modify, and/or distribute this software for any purpose with | * 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 | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
@@ -184,15 +184,6 @@ enum Key { | |||||
kKeySuper | kKeySuper | ||||
}; | }; | ||||
/** | |||||
Type of graphics context. | |||||
*/ | |||||
enum ContextType | |||||
{ | |||||
kContextGL, | |||||
kContextCairo | |||||
}; | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// Base DGL classes | // Base DGL classes | ||||
@@ -211,15 +202,9 @@ public: | |||||
*/ | */ | ||||
struct Context | struct Context | ||||
{ | { | ||||
ContextType type; | |||||
union { | |||||
#ifdef HAVE_DGL | |||||
struct { /* nothing for now */ } gl; | |||||
#endif | |||||
#ifdef HAVE_DCAIRO | #ifdef HAVE_DCAIRO | ||||
struct { cairo_t* graphics; } cairo; | |||||
cairo_t* cairo; | |||||
#endif | #endif | ||||
}; | |||||
}; | }; | ||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
@@ -1,6 +1,6 @@ | |||||
/* | /* | ||||
* DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
* Copyright (C) 2012-2018 Filipe Coelho <falktx@falktx.com> | |||||
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com> | |||||
* | * | ||||
* Permission to use, copy, modify, and/or distribute this software for any purpose with | * 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 | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
@@ -213,15 +213,6 @@ struct Window::PrivateData { | |||||
return; | 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); | puglInitUserResizable(fView, fResizable); | ||||
puglInitWindowSize(fView, static_cast<int>(fWidth), static_cast<int>(fHeight)); | puglInitWindowSize(fView, static_cast<int>(fWidth), static_cast<int>(fHeight)); | ||||
@@ -1,5 +1,6 @@ | |||||
/* | /* | ||||
Copyright 2012-2014 David Robillard <http://drobilla.net> | Copyright 2012-2014 David Robillard <http://drobilla.net> | ||||
Copyright 2012-2019 Filipe Coelho <falktx@falktx.com> | |||||
Permission to use, copy, modify, and/or distribute this software for any | Permission to use, copy, modify, and/or distribute this software for any | ||||
purpose with or without fee is hereby granted, provided that the above | purpose with or without fee is hereby granted, provided that the above | ||||
@@ -273,20 +274,6 @@ puglInitUserResizable(PuglView* view, bool resizable); | |||||
PUGL_API void | PUGL_API void | ||||
puglInitTransientFor(PuglView* view, uintptr_t parent); | 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. | 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* | PUGL_API void* | ||||
puglGetContext(PuglView* view); | puglGetContext(PuglView* view); | ||||
@@ -1,5 +1,6 @@ | |||||
/* | /* | ||||
Copyright 2012-2014 David Robillard <http://drobilla.net> | Copyright 2012-2014 David Robillard <http://drobilla.net> | ||||
Copyright 2012-2019 Filipe Coelho <falktx@falktx.com> | |||||
Permission to use, copy, modify, and/or distribute this software for any | Permission to use, copy, modify, and/or distribute this software for any | ||||
purpose with or without fee is hereby granted, provided that the above | purpose with or without fee is hereby granted, provided that the above | ||||
@@ -41,7 +42,6 @@ struct PuglViewImpl { | |||||
PuglInternals* impl; | PuglInternals* impl; | ||||
PuglNativeWindow parent; | PuglNativeWindow parent; | ||||
PuglContextType ctx_type; | |||||
uintptr_t transient_parent; | uintptr_t transient_parent; | ||||
int width; | int width; | ||||
@@ -141,12 +141,6 @@ puglCreate(PuglNativeWindow parent, | |||||
return view; | return view; | ||||
} | } | ||||
void | |||||
puglInitContextType(PuglView* view, PuglContextType type) | |||||
{ | |||||
view->ctx_type = type; | |||||
} | |||||
void | void | ||||
puglSetHandle(PuglView* view, PuglHandle handle) | puglSetHandle(PuglView* view, PuglHandle handle) | ||||
{ | { | ||||
@@ -1,5 +1,6 @@ | |||||
/* | /* | ||||
Copyright 2012 David Robillard <http://drobilla.net> | Copyright 2012 David Robillard <http://drobilla.net> | ||||
Copyright 2012-2019 Filipe Coelho <falktx@falktx.com> | |||||
Permission to use, copy, modify, and/or distribute this software for any | Permission to use, copy, modify, and/or distribute this software for any | ||||
purpose with or without fee is hereby granted, provided that the above | purpose with or without fee is hereby granted, provided that the above | ||||
@@ -774,25 +775,23 @@ void | |||||
puglEnterContext(PuglView* view) | puglEnterContext(PuglView* view) | ||||
{ | { | ||||
#ifdef PUGL_HAVE_GL | #ifdef PUGL_HAVE_GL | ||||
if (view->ctx_type == PUGL_GL) { | |||||
[[view->impl->glview openGLContext] makeCurrentContext]; | |||||
} | |||||
[[view->impl->glview openGLContext] makeCurrentContext]; | |||||
#endif | #endif | ||||
} | } | ||||
void | void | ||||
puglLeaveContext(PuglView* view, bool flush) | puglLeaveContext(PuglView* view, bool flush) | ||||
{ | { | ||||
if (flush) { | |||||
#ifdef PUGL_HAVE_GL | #ifdef PUGL_HAVE_GL | ||||
if (view->ctx_type == PUGL_GL && flush) { | |||||
if (view->impl->glview->doubleBuffered) { | if (view->impl->glview->doubleBuffered) { | ||||
[[view->impl->glview openGLContext] flushBuffer]; | [[view->impl->glview openGLContext] flushBuffer]; | ||||
} else { | } else { | ||||
glFlush(); | glFlush(); | ||||
} | } | ||||
//[NSOpenGLContext clearCurrentContext]; | //[NSOpenGLContext clearCurrentContext]; | ||||
} | |||||
#endif | #endif | ||||
} | |||||
} | } | ||||
int | int | ||||
@@ -804,14 +803,10 @@ puglCreateWindow(PuglView* view, const char* title) | |||||
[NSApplication sharedApplication]; | [NSApplication sharedApplication]; | ||||
#ifdef PUGL_HAVE_GL | #ifdef PUGL_HAVE_GL | ||||
if (view->ctx_type == PUGL_GL) { | |||||
impl->glview = [PuglOpenGLView new]; | |||||
} | |||||
impl->glview = [PuglOpenGLView new]; | |||||
#endif | #endif | ||||
#ifdef PUGL_HAVE_CAIRO | #ifdef PUGL_HAVE_CAIRO | ||||
if (view->ctx_type == PUGL_CAIRO) { | |||||
impl->cairoview = [PuglCairoView new]; | |||||
} | |||||
impl->cairoview = [PuglCairoView new]; | |||||
#endif | #endif | ||||
if (!impl->view) { | if (!impl->view) { | ||||
@@ -925,9 +920,7 @@ void* | |||||
puglGetContext(PuglView* view) | puglGetContext(PuglView* view) | ||||
{ | { | ||||
#ifdef PUGL_HAVE_CAIRO | #ifdef PUGL_HAVE_CAIRO | ||||
if (view->ctx_type == PUGL_CAIRO) { | |||||
return [view->impl->cairoview cairoContext]; | |||||
} | |||||
return [view->impl->cairoview cairoContext]; | |||||
#endif | #endif | ||||
return NULL; | return NULL; | ||||
@@ -1,5 +1,6 @@ | |||||
/* | /* | ||||
Copyright 2012-2014 David Robillard <http://drobilla.net> | Copyright 2012-2014 David Robillard <http://drobilla.net> | ||||
Copyright 2012-2019 Filipe Coelho <falktx@falktx.com> | |||||
Permission to use, copy, modify, and/or distribute this software for any | Permission to use, copy, modify, and/or distribute this software for any | ||||
purpose with or without fee is hereby granted, provided that the above | purpose with or without fee is hereby granted, provided that the above | ||||
@@ -90,9 +91,7 @@ void | |||||
puglEnterContext(PuglView* view) | puglEnterContext(PuglView* view) | ||||
{ | { | ||||
#ifdef PUGL_HAVE_GL | #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 | #endif | ||||
} | } | ||||
@@ -100,13 +99,11 @@ void | |||||
puglLeaveContext(PuglView* view, bool flush) | puglLeaveContext(PuglView* view, bool flush) | ||||
{ | { | ||||
#ifdef PUGL_HAVE_GL | #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 | #endif | ||||
} | } | ||||
@@ -181,31 +178,29 @@ puglCreateWindow(PuglView* view, const char* title) | |||||
SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view); | SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view); | ||||
#ifdef PUGL_HAVE_GL | #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 | #endif | ||||
@@ -234,17 +229,13 @@ puglDestroy(PuglView* view) | |||||
PuglInternals* const impl = view->impl; | PuglInternals* const impl = view->impl; | ||||
#ifdef PUGL_HAVE_GL | #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 | #endif | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
DestroyWindow(impl->hwnd); | DestroyWindow(impl->hwnd); | ||||
UnregisterClass(impl->wc.lpszClassName, NULL); | UnregisterClass(impl->wc.lpszClassName, NULL); | ||||
@@ -282,26 +273,24 @@ puglDisplay(PuglView* view) | |||||
cairo_surface_t *ws = NULL; | cairo_surface_t *ws = NULL; | ||||
cairo_surface_t *bs = 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 | #endif | ||||
if (success) { | if (success) { | ||||
@@ -310,20 +299,16 @@ puglDisplay(PuglView* view) | |||||
view->displayFunc(view); | view->displayFunc(view); | ||||
} | } | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
} | } | ||||
puglLeaveContext(view, success); | puglLeaveContext(view, success); | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
return; | return; | ||||
@@ -561,9 +546,7 @@ void* | |||||
puglGetContext(PuglView* view) | puglGetContext(PuglView* view) | ||||
{ | { | ||||
#ifdef PUGL_HAVE_CAIRO | #ifdef PUGL_HAVE_CAIRO | ||||
if (view->ctx_type == PUGL_CAIRO) { | |||||
return view->impl->buffer_cr; | |||||
} | |||||
return view->impl->buffer_cr; | |||||
#endif | #endif | ||||
return NULL; | return NULL; | ||||
@@ -2,6 +2,7 @@ | |||||
Copyright 2012-2014 David Robillard <http://drobilla.net> | Copyright 2012-2014 David Robillard <http://drobilla.net> | ||||
Copyright 2011-2012 Ben Loftis, Harrison Consoles | Copyright 2011-2012 Ben Loftis, Harrison Consoles | ||||
Copyright 2013,2015 Robin Gareus <robin@gareus.org> | Copyright 2013,2015 Robin Gareus <robin@gareus.org> | ||||
Copyright 2012-2019 Filipe Coelho <falktx@falktx.com> | |||||
Permission to use, copy, modify, and/or distribute this software for any | Permission to use, copy, modify, and/or distribute this software for any | ||||
purpose with or without fee is hereby granted, provided that the above | purpose with or without fee is hereby granted, provided that the above | ||||
@@ -129,9 +130,7 @@ void | |||||
puglEnterContext(PuglView* view) | puglEnterContext(PuglView* view) | ||||
{ | { | ||||
#ifdef PUGL_HAVE_GL | #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 | #endif | ||||
} | } | ||||
@@ -139,15 +138,13 @@ void | |||||
puglLeaveContext(PuglView* view, bool flush) | puglLeaveContext(PuglView* view, bool flush) | ||||
{ | { | ||||
#ifdef PUGL_HAVE_GL | #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 | #endif | ||||
} | } | ||||
@@ -170,30 +167,26 @@ puglCreateWindow(PuglView* view, const char* title) | |||||
XVisualInfo* vi = NULL; | XVisualInfo* vi = NULL; | ||||
#ifdef PUGL_HAVE_GL | #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 | #ifdef PUGL_VERBOSE | ||||
printf("puGL: multisampling (antialiasing) is not available\n"); | |||||
printf("puGL: multisampling (antialiasing) is not available\n"); | |||||
#endif | #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 | #endif | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
if (!vi) { | if (!vi) { | ||||
@@ -211,15 +204,13 @@ puglCreateWindow(PuglView* view, const char* title) | |||||
#endif | #endif | ||||
#ifdef PUGL_HAVE_GL | #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 | #endif | ||||
@@ -247,9 +238,7 @@ puglCreateWindow(PuglView* view, const char* title) | |||||
if (!impl->win) { | if (!impl->win) { | ||||
#ifdef PUGL_HAVE_GL | #ifdef PUGL_HAVE_GL | ||||
if (view->ctx_type == PUGL_GL) { | |||||
glXDestroyContext(impl->display, impl->ctx); | |||||
} | |||||
glXDestroyContext(impl->display, impl->ctx); | |||||
#endif | #endif | ||||
XFree(vi); | XFree(vi); | ||||
XCloseDisplay(impl->display); | XCloseDisplay(impl->display); | ||||
@@ -258,25 +247,23 @@ puglCreateWindow(PuglView* view, const char* title) | |||||
} | } | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
@@ -328,17 +315,13 @@ puglDestroy(PuglView* view) | |||||
#endif | #endif | ||||
#ifdef PUGL_HAVE_GL | #ifdef PUGL_HAVE_GL | ||||
if (view->ctx_type == PUGL_GL) { | |||||
glXDestroyContext(impl->display, impl->ctx); | |||||
} | |||||
glXDestroyContext(impl->display, impl->ctx); | |||||
#endif | #endif | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
XDestroyWindow(impl->display, impl->win); | XDestroyWindow(impl->display, impl->win); | ||||
XCloseDisplay(impl->display); | XCloseDisplay(impl->display); | ||||
@@ -383,28 +366,26 @@ puglDisplay(PuglView* view) | |||||
puglEnterContext(view); | puglEnterContext(view); | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
@@ -414,11 +395,9 @@ puglDisplay(PuglView* view) | |||||
} | } | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
puglLeaveContext(view, true); | puglLeaveContext(view, true); | ||||
@@ -683,12 +662,10 @@ puglProcessEvents(PuglView* view) | |||||
if (conf_width != -1) { | if (conf_width != -1) { | ||||
#ifdef PUGL_HAVE_CAIRO | #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 | #endif | ||||
puglReshape(view, conf_width, conf_height); | puglReshape(view, conf_width, conf_height); | ||||
} | } | ||||
@@ -726,9 +703,7 @@ void* | |||||
puglGetContext(PuglView* view) | puglGetContext(PuglView* view) | ||||
{ | { | ||||
#ifdef PUGL_HAVE_CAIRO | #ifdef PUGL_HAVE_CAIRO | ||||
if (view->ctx_type == PUGL_CAIRO) { | |||||
return view->impl->buffer_cr; | |||||
} | |||||
return view->impl->buffer_cr; | |||||
#endif | #endif | ||||
return NULL; | return NULL; | ||||