Merge branch 'wip/chergert/gdk-macos-for-master' into 'master'

macos: various GL context cleanups

See merge request GNOME/gtk!2929
This commit is contained in:
Matthias Clasen 2020-12-08 00:06:19 +00:00
commit adc4bcbd24
2 changed files with 40 additions and 16 deletions

View File

@ -82,7 +82,9 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-(BOOL)isOpaque
{
return NO;
if ([self window])
return [[self window] isOpaque];
return YES;
}
-(BOOL)isFlipped

View File

@ -101,7 +101,7 @@ create_pixel_format (int major,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFABackingStore,
NSOpenGLPFAColorSize, 32,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
(NSOpenGLPixelFormatAttribute)nil
@ -173,11 +173,13 @@ gdk_macos_gl_context_real_realize (GdkGLContext *context,
NSOpenGLContext *shared_gl_context = nil;
NSOpenGLContext *gl_context;
NSOpenGLPixelFormat *pixelFormat;
CGLContextObj cgl_context;
GdkGLContext *shared;
GdkGLContext *shared_data;
NSOpenGLContext *existing;
GLint sync_to_framerate = 1;
GLint validate = 0;
GLint swapRect[4];
int major, minor;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
@ -226,8 +228,19 @@ gdk_macos_gl_context_real_realize (GdkGLContext *context,
return FALSE;
}
[gl_context setValues:&sync_to_framerate forParameter:NSOpenGLCPSwapInterval];
[gl_context setValues:&validate forParameter:NSOpenGLContextParameterStateValidation];
cgl_context = [gl_context CGLContextObj];
swapRect[0] = 0;
swapRect[1] = 0;
swapRect[2] = surface->width;
swapRect[3] = surface->height;
CGLSetParameter (cgl_context, kCGLCPSwapRectangle, swapRect);
CGLSetParameter (cgl_context, kCGLCPSwapInterval, &sync_to_framerate);
CGLEnable (cgl_context, kCGLCESwapRectangle);
if (validate)
CGLEnable (cgl_context, kCGLCEStateValidation);
self->dummy_window = [[NSWindow alloc] initWithContentRect:NSZeroRect
styleMask:0
@ -259,9 +272,12 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
cairo_region_t *painted)
{
GdkMacosGLContext *self = (GdkMacosGLContext *)context;
GdkSurface *surface;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
surface = gdk_draw_context_get_surface (context);
/* If begin frame is called, that means we are trying to draw to
* the NSWindow using our view. That might be a GdkMacosCairoView
* but we need it to be a GL view. Also, only in this case do we
@ -271,17 +287,31 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
if (!self->is_attached &&
gdk_gl_context_get_shared_context (GDK_GL_CONTEXT (context)))
{
CGLContextObj glctx = [self->gl_context CGLContextObj];
GLint swapRect[4];
ensure_gl_view (self);
g_clear_pointer (&self->damage, cairo_region_destroy);
self->damage = cairo_region_copy (painted);
cairo_region_get_extents (painted, &self->flush_rect);
/* Coordinates are in display coordinates, where as flush_rect is
* in GDK coordinates. Must flip Y to match display coordinates where
* 0,0 is the bottom-left corner.
*/
swapRect[0] = self->flush_rect.x; /* left */
swapRect[1] = surface->height - self->flush_rect.y; /* bottom */
swapRect[2] = self->flush_rect.width; /* width */
swapRect[3] = self->flush_rect.height; /* height */
CGLSetParameter (glctx, kCGLCPSwapRectangle, swapRect);
}
if (self->needs_resize)
{
GdkSurface *surface = gdk_draw_context_get_surface (context);
CGLContextObj cgl_context = [self->gl_context CGLContextObj];
GLint opaque;
self->needs_resize = FALSE;
@ -302,7 +332,8 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
opaque = GDK_MACOS_TOPLEVEL_SURFACE (surface)->decorated;
else
opaque = FALSE;
[self->gl_context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
CGLSetParameter (cgl_context, kCGLCPSurfaceOpacity, &opaque);
[self->gl_context update];
}
@ -311,8 +342,7 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
if (!self->is_attached)
{
GdkMacosSurface *surface = GDK_MACOS_SURFACE (gdk_draw_context_get_surface (context));
NSView *nsview = _gdk_macos_surface_get_view (surface);
NSView *nsview = _gdk_macos_surface_get_view (GDK_MACOS_SURFACE (surface));
g_assert (self->gl_context != NULL);
g_assert (GDK_IS_MACOS_GL_VIEW (nsview));
@ -332,14 +362,6 @@ gdk_macos_gl_context_end_frame (GdkDrawContext *context,
GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->end_frame (context, painted);
/* We want to limit how much gets moved to the front buffer so here
* we adjust the clip rectangle before flushBuffer is called.
*/
G_STATIC_ASSERT (sizeof (GLint) == sizeof (int));
[self->gl_context
setValues:(GLint *)&self->flush_rect
forParameter:NSOpenGLCPSwapRectangle];
[self->gl_context flushBuffer];
}