aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-02-18 22:50:52 +0100
committerDavid Robillard <d@drobilla.net>2020-02-18 23:20:02 +0100
commit0059c630d7406f672c113d6dc6da78810160ddbb (patch)
tree789ede3ed59b6301245b823654e31662adeda726 /pugl
parent2bae8905a97aa8a29826c78311c826d61f075e0e (diff)
downloadpugl-0059c630d7406f672c113d6dc6da78810160ddbb.tar.gz
pugl-0059c630d7406f672c113d6dc6da78810160ddbb.tar.bz2
pugl-0059c630d7406f672c113d6dc6da78810160ddbb.zip
Pass expose event to backend enter and leave functions
This is needed for clipping. Unfortunately, the puglEnterContext() and puglLeaveContext() API was not suitable for this, but this shouldn't matter in user code because it is only used for setup, and is slated for removal anyway. Instead, just call the backend functions directly in the implementation.
Diffstat (limited to 'pugl')
-rw-r--r--pugl/detail/implementation.c24
-rw-r--r--pugl/detail/mac_cairo.m8
-rw-r--r--pugl/detail/mac_gl.m6
-rw-r--r--pugl/detail/types.h8
-rw-r--r--pugl/detail/win.c8
-rw-r--r--pugl/detail/win_cairo.c36
-rw-r--r--pugl/detail/win_gl.c8
-rw-r--r--pugl/detail/x11.c11
-rw-r--r--pugl/detail/x11_cairo.c8
-rw-r--r--pugl/detail/x11_gl.c6
-rw-r--r--pugl/pugl_stub.h8
11 files changed, 65 insertions, 66 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c
index df87276..917efa6 100644
--- a/pugl/detail/implementation.c
+++ b/pugl/detail/implementation.c
@@ -228,14 +228,22 @@ puglGetContext(PuglView* view)
PuglStatus
puglEnterContext(PuglView* view, bool drawing)
{
- view->backend->enter(view, drawing);
+ const PuglEventExpose expose = {
+ PUGL_EXPOSE, 0, 0, 0, view->frame.width, view->frame.height, 0};
+
+ view->backend->enter(view, drawing ? &expose : NULL);
+
return PUGL_SUCCESS;
}
PuglStatus
puglLeaveContext(PuglView* view, bool drawing)
{
- view->backend->leave(view, drawing);
+ const PuglEventExpose expose = {
+ PUGL_EXPOSE, 0, 0, 0, view->frame.width, view->frame.height, 0};
+
+ view->backend->leave(view, drawing ? &expose : NULL);
+
return PUGL_SUCCESS;
}
@@ -287,16 +295,14 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event)
case PUGL_NOTHING:
break;
case PUGL_CONFIGURE:
- puglEnterContext(view, false);
+ view->backend->enter(view, NULL);
view->eventFunc(view, event);
- puglLeaveContext(view, false);
+ view->backend->leave(view, NULL);
break;
case PUGL_EXPOSE:
- if (event->expose.count == 0) {
- puglEnterContext(view, true);
- view->eventFunc(view, event);
- puglLeaveContext(view, true);
- }
+ view->backend->enter(view, &event->expose);
+ view->eventFunc(view, event);
+ view->backend->leave(view, &event->expose);
break;
default:
view->eventFunc(view, event);
diff --git a/pugl/detail/mac_cairo.m b/pugl/detail/mac_cairo.m
index 6b9f36c..40f5026 100644
--- a/pugl/detail/mac_cairo.m
+++ b/pugl/detail/mac_cairo.m
@@ -93,10 +93,10 @@ puglMacCairoDestroy(PuglView* view)
}
static PuglStatus
-puglMacCairoEnter(PuglView* view, bool drawing)
+puglMacCairoEnter(PuglView* view, const PuglEventExpose* expose)
{
PuglCairoView* const drawView = (PuglCairoView*)view->impl->drawView;
- if (!drawing) {
+ if (!expose) {
return PUGL_SUCCESS;
}
@@ -114,10 +114,10 @@ puglMacCairoEnter(PuglView* view, bool drawing)
}
static PuglStatus
-puglMacCairoLeave(PuglView* view, bool drawing)
+puglMacCairoLeave(PuglView* view, const PuglEventExpose* expose)
{
PuglCairoView* const drawView = (PuglCairoView*)view->impl->drawView;
- if (!drawing) {
+ if (!expose) {
return PUGL_SUCCESS;
}
diff --git a/pugl/detail/mac_gl.m b/pugl/detail/mac_gl.m
index 145b614..07df642 100644
--- a/pugl/detail/mac_gl.m
+++ b/pugl/detail/mac_gl.m
@@ -125,7 +125,7 @@ puglMacGlDestroy(PuglView* view)
}
static PuglStatus
-puglMacGlEnter(PuglView* view, bool PUGL_UNUSED(drawing))
+puglMacGlEnter(PuglView* view, const PuglEventExpose* PUGL_UNUSED(expose))
{
PuglOpenGLView* const drawView = (PuglOpenGLView*)view->impl->drawView;
@@ -134,11 +134,11 @@ puglMacGlEnter(PuglView* view, bool PUGL_UNUSED(drawing))
}
static PuglStatus
-puglMacGlLeave(PuglView* view, bool drawing)
+puglMacGlLeave(PuglView* view, const PuglEventExpose* expose)
{
PuglOpenGLView* const drawView = (PuglOpenGLView*)view->impl->drawView;
- if (drawing) {
+ if (expose) {
[[drawView openGLContext] flushBuffer];
}
diff --git a/pugl/detail/types.h b/pugl/detail/types.h
index 7b2934f..656c34d 100644
--- a/pugl/detail/types.h
+++ b/pugl/detail/types.h
@@ -96,11 +96,11 @@ struct PuglBackendImpl {
/** Destroy surface and drawing context. */
PuglStatus (*destroy)(PuglView*);
- /** Enter drawing context, for drawing if parameter is true. */
- PuglStatus (*enter)(PuglView*, bool);
+ /** Enter drawing context, for drawing if expose is non-null. */
+ PuglStatus (*enter)(PuglView*, const PuglEventExpose*);
- /** Leave drawing context, after drawing if parameter is true. */
- PuglStatus (*leave)(PuglView*, bool);
+ /** Leave drawing context, after drawing if expose is non-null. */
+ PuglStatus (*leave)(PuglView*, const PuglEventExpose*);
/** Resize drawing context to the given width and height. */
PuglStatus (*resize)(PuglView*, int, int);
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 6ef9255..1b86d3c 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -947,9 +947,9 @@ puglSetClipboard(PuglView* const view,
}
static PuglStatus
-puglWinStubEnter(PuglView* view, bool drawing)
+puglWinStubEnter(PuglView* view, const PuglEventExpose* expose)
{
- if (drawing) {
+ if (expose) {
PAINTSTRUCT ps;
BeginPaint(view->impl->hwnd, &ps);
}
@@ -958,9 +958,9 @@ puglWinStubEnter(PuglView* view, bool drawing)
}
static PuglStatus
-puglWinStubLeave(PuglView* view, bool drawing)
+puglWinStubLeave(PuglView* view, const PuglEventExpose* expose)
{
- if (drawing) {
+ if (expose) {
PAINTSTRUCT ps;
EndPaint(view->impl->hwnd, &ps);
SwapBuffers(view->impl->hdc);
diff --git a/pugl/detail/win_cairo.c b/pugl/detail/win_cairo.c
index 7966b07..84761a3 100644
--- a/pugl/detail/win_cairo.c
+++ b/pugl/detail/win_cairo.c
@@ -110,39 +110,37 @@ puglWinCairoDestroy(PuglView* view)
}
static PuglStatus
-puglWinCairoEnter(PuglView* view, bool drawing)
+puglWinCairoEnter(PuglView* view, const PuglEventExpose* expose)
{
PuglInternals* const impl = view->impl;
PuglWinCairoSurface* const surface = (PuglWinCairoSurface*)impl->surface;
- if (!drawing) {
- return PUGL_SUCCESS;
- }
- PAINTSTRUCT ps;
- BeginPaint(view->impl->hwnd, &ps);
- cairo_save(surface->cr);
+ if (expose) {
+ PAINTSTRUCT ps;
+ BeginPaint(view->impl->hwnd, &ps);
+ cairo_save(surface->cr);
+ }
return PUGL_SUCCESS;
}
static PuglStatus
-puglWinCairoLeave(PuglView* view, bool drawing)
+puglWinCairoLeave(PuglView* view, const PuglEventExpose* expose)
{
PuglInternals* const impl = view->impl;
PuglWinCairoSurface* const surface = (PuglWinCairoSurface*)impl->surface;
- if (!drawing) {
- return PUGL_SUCCESS;
- }
- cairo_restore(surface->cr);
- cairo_surface_flush(surface->surface);
- BitBlt(impl->hdc,
- 0, 0, (int)view->frame.width, (int)view->frame.height,
- surface->drawDc, 0, 0, SRCCOPY);
+ if (expose) {
+ cairo_restore(surface->cr);
+ cairo_surface_flush(surface->surface);
+ BitBlt(impl->hdc,
+ 0, 0, (int)view->frame.width, (int)view->frame.height,
+ surface->drawDc, 0, 0, SRCCOPY);
- PAINTSTRUCT ps;
- EndPaint(view->impl->hwnd, &ps);
- SwapBuffers(view->impl->hdc);
+ PAINTSTRUCT ps;
+ EndPaint(view->impl->hwnd, &ps);
+ SwapBuffers(view->impl->hdc);
+ }
return PUGL_SUCCESS;
}
diff --git a/pugl/detail/win_gl.c b/pugl/detail/win_gl.c
index ee3b032..c09e23a 100644
--- a/pugl/detail/win_gl.c
+++ b/pugl/detail/win_gl.c
@@ -246,13 +246,13 @@ puglWinGlDestroy(PuglView* view)
}
static PuglStatus
-puglWinGlEnter(PuglView* view, bool drawing)
+puglWinGlEnter(PuglView* view, const PuglEventExpose* expose)
{
PuglWinGlSurface* surface = (PuglWinGlSurface*)view->impl->surface;
wglMakeCurrent(view->impl->hdc, surface->hglrc);
- if (drawing) {
+ if (expose) {
PAINTSTRUCT ps;
BeginPaint(view->impl->hwnd, &ps);
}
@@ -261,9 +261,9 @@ puglWinGlEnter(PuglView* view, bool drawing)
}
static PuglStatus
-puglWinGlLeave(PuglView* view, bool drawing)
+puglWinGlLeave(PuglView* view, const PuglEventExpose* expose)
{
- if (drawing) {
+ if (expose) {
PAINTSTRUCT ps;
EndPaint(view->impl->hwnd, &ps);
SwapBuffers(view->impl->hdc);
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index b62e62d..38f10d0 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -744,16 +744,11 @@ puglDispatchEvents(PuglWorld* world)
PuglEvent* const expose = &view->impl->pendingExpose;
if (configure->type || expose->type) {
- const bool mustExpose = expose->type && expose->expose.count == 0;
- puglEnterContext(view, mustExpose);
-
+ view->backend->enter(view, &expose->expose);
flushPendingConfigure(view);
+ view->eventFunc(view, expose);
+ view->backend->leave(view, &expose->expose);
- if (mustExpose) {
- view->eventFunc(view, &view->impl->pendingExpose);
- }
-
- puglLeaveContext(view, mustExpose);
configure->type = 0;
expose->type = 0;
}
diff --git a/pugl/detail/x11_cairo.c b/pugl/detail/x11_cairo.c
index 9d3ec16..7a02dcd 100644
--- a/pugl/detail/x11_cairo.c
+++ b/pugl/detail/x11_cairo.c
@@ -79,12 +79,12 @@ puglX11CairoDestroy(PuglView* view)
}
static PuglStatus
-puglX11CairoEnter(PuglView* view, bool drawing)
+puglX11CairoEnter(PuglView* view, const PuglEventExpose* expose)
{
PuglInternals* const impl = view->impl;
PuglX11CairoSurface* const surface = (PuglX11CairoSurface*)impl->surface;
- if (drawing) {
+ if (expose) {
surface->cr = cairo_create(surface->front);
if (!surface->cr || cairo_status(surface->cr)) {
return PUGL_CREATE_CONTEXT_FAILED;
@@ -95,12 +95,12 @@ puglX11CairoEnter(PuglView* view, bool drawing)
}
static PuglStatus
-puglX11CairoLeave(PuglView* view, bool drawing)
+puglX11CairoLeave(PuglView* view, const PuglEventExpose* expose)
{
PuglInternals* const impl = view->impl;
PuglX11CairoSurface* const surface = (PuglX11CairoSurface*)impl->surface;
- if (drawing) {
+ if (expose) {
// Destroy front context that was used by the user for drawing
cairo_destroy(surface->cr);
diff --git a/pugl/detail/x11_gl.c b/pugl/detail/x11_gl.c
index d325f9d..d3807f2 100644
--- a/pugl/detail/x11_gl.c
+++ b/pugl/detail/x11_gl.c
@@ -165,7 +165,7 @@ puglX11GlDestroy(PuglView* view)
}
static PuglStatus
-puglX11GlEnter(PuglView* view, bool PUGL_UNUSED(drawing))
+puglX11GlEnter(PuglView* view, const PuglEventExpose* PUGL_UNUSED(expose))
{
PuglX11GlSurface* surface = (PuglX11GlSurface*)view->impl->surface;
glXMakeCurrent(view->impl->display, view->impl->win, surface->ctx);
@@ -173,11 +173,11 @@ puglX11GlEnter(PuglView* view, bool PUGL_UNUSED(drawing))
}
static PuglStatus
-puglX11GlLeave(PuglView* view, bool drawing)
+puglX11GlLeave(PuglView* view, const PuglEventExpose* expose)
{
PuglX11GlSurface* surface = (PuglX11GlSurface*)view->impl->surface;
- if (drawing && surface->double_buffered) {
+ if (expose && surface->double_buffered) {
glXSwapBuffers(view->impl->display, view->impl->win);
}
diff --git a/pugl/pugl_stub.h b/pugl/pugl_stub.h
index 40d1036..f50f96b 100644
--- a/pugl/pugl_stub.h
+++ b/pugl/pugl_stub.h
@@ -71,18 +71,18 @@ puglStubDestroy(PuglView* view)
}
static inline PuglStatus
-puglStubEnter(PuglView* view, bool drawing)
+puglStubEnter(PuglView* view, const PuglEventExpose* expose)
{
(void)view;
- (void)drawing;
+ (void)expose;
return PUGL_SUCCESS;
}
static inline PuglStatus
-puglStubLeave(PuglView* view, bool drawing)
+puglStubLeave(PuglView* view, const PuglEventExpose* expose)
{
(void)view;
- (void)drawing;
+ (void)expose;
return PUGL_SUCCESS;
}