From 3c9a8a2ed86d08da842e11d32065da43b5bfdc77 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 27 Oct 2019 13:05:00 +0100 Subject: Move platform stub configuration code to platform headers This allows backends which use basic software rendering (like Cairo) to share the common basic window format setup code. --- pugl/detail/win.h | 24 ++++++++++++++++++++++++ pugl/detail/win_cairo.c | 24 +++++------------------- pugl/detail/x11.h | 13 +++++++++++++ pugl/detail/x11_cairo.c | 15 +-------------- 4 files changed, 43 insertions(+), 33 deletions(-) (limited to 'pugl') diff --git a/pugl/detail/win.h b/pugl/detail/win.h index 6d89759..e9056b7 100644 --- a/pugl/detail/win.h +++ b/pugl/detail/win.h @@ -113,3 +113,27 @@ puglWinCreateWindow(const PuglView* const view, return PUGL_SUCCESS; } + +static inline PuglStatus +puglWinStubConfigure(PuglView* view) +{ + PuglInternals* const impl = view->impl; + PuglStatus st = PUGL_SUCCESS; + + if ((st = puglWinCreateWindow(view, "Pugl", &impl->hwnd, &impl->hdc))) { + return st; + } + + impl->pfd = puglWinGetPixelFormatDescriptor(view->hints); + impl->pfId = ChoosePixelFormat(impl->hdc, &impl->pfd); + + if (!SetPixelFormat(impl->hdc, impl->pfId, &impl->pfd)) { + ReleaseDC(impl->hwnd, impl->hdc); + DestroyWindow(impl->hwnd); + impl->hwnd = NULL; + impl->hdc = NULL; + return PUGL_SET_FORMAT_FAILED; + } + + return PUGL_SUCCESS; +} diff --git a/pugl/detail/win_cairo.c b/pugl/detail/win_cairo.c index 497711b..27765ec 100644 --- a/pugl/detail/win_cairo.c +++ b/pugl/detail/win_cairo.c @@ -80,28 +80,14 @@ puglWinCairoDestroyDrawContext(PuglView* view) static PuglStatus puglWinCairoConfigure(PuglView* view) { - PuglInternals* const impl = view->impl; - PuglStatus st = PUGL_SUCCESS; + const PuglStatus st = puglWinStubConfigure(view); - if ((st = puglWinCreateWindow(view, "Pugl", &impl->hwnd, &impl->hdc))) { - return st; - } - - impl->pfd = puglWinGetPixelFormatDescriptor(view->hints); - impl->pfId = ChoosePixelFormat(impl->hdc, &impl->pfd); - - if (!SetPixelFormat(impl->hdc, impl->pfId, &impl->pfd)) { - ReleaseDC(impl->hwnd, impl->hdc); - DestroyWindow(impl->hwnd); - impl->hwnd = NULL; - impl->hdc = NULL; - return PUGL_SET_FORMAT_FAILED; + if (!st) { + view->impl->surface = (PuglWinCairoSurface*)calloc( + 1, sizeof(PuglWinCairoSurface)); } - impl->surface = (PuglWinCairoSurface*)calloc( - 1, sizeof(PuglWinCairoSurface)); - - return PUGL_SUCCESS; + return st; } static PuglStatus diff --git a/pugl/detail/x11.h b/pugl/detail/x11.h index bfdbf60..d7990ca 100644 --- a/pugl/detail/x11.h +++ b/pugl/detail/x11.h @@ -49,3 +49,16 @@ struct PuglInternalsImpl { PuglEvent pendingConfigure; PuglEvent pendingExpose; }; + +static inline PuglStatus +puglX11StubConfigure(PuglView* view) +{ + PuglInternals* const impl = view->impl; + XVisualInfo pat = {0}; + int n = 0; + + pat.screen = impl->screen; + impl->vi = XGetVisualInfo(impl->display, VisualScreenMask, &pat, &n); + + return PUGL_SUCCESS; +} diff --git a/pugl/detail/x11_cairo.c b/pugl/detail/x11_cairo.c index 0753317..1c7df6e 100644 --- a/pugl/detail/x11_cairo.c +++ b/pugl/detail/x11_cairo.c @@ -38,19 +38,6 @@ typedef struct { cairo_t* frontCr; } PuglX11CairoSurface; -static PuglStatus -puglX11CairoConfigure(PuglView* view) -{ - PuglInternals* const impl = view->impl; - - XVisualInfo pat; - int n; - pat.screen = impl->screen; - impl->vi = XGetVisualInfo(impl->display, VisualScreenMask, &pat, &n); - - return PUGL_SUCCESS; -} - static PuglStatus puglX11CairoCreate(PuglView* view) { @@ -163,7 +150,7 @@ const PuglBackend* puglCairoBackend(void) { static const PuglBackend backend = { - puglX11CairoConfigure, + puglX11StubConfigure, puglX11CairoCreate, puglX11CairoDestroy, puglX11CairoEnter, -- cgit v1.2.1