macos: use opaque GL context when possible

This is better for situations where the window is decorated and therefore we can
rely on window system clipping of rounded corners.
This commit is contained in:
Christian Hergert 2020-11-05 13:34:29 -08:00
parent ec5b5e8aaa
commit bf3e1e5b40
3 changed files with 28 additions and 16 deletions

View File

@ -21,6 +21,7 @@
#include "gdkmacosglcontext-private.h" #include "gdkmacosglcontext-private.h"
#include "gdkmacossurface-private.h" #include "gdkmacossurface-private.h"
#include "gdkmacostoplevelsurface-private.h"
#include "gdkinternals.h" #include "gdkinternals.h"
#include "gdkintl.h" #include "gdkintl.h"
@ -174,7 +175,6 @@ gdk_macos_gl_context_real_realize (GdkGLContext *context,
GdkGLContext *shared_data; GdkGLContext *shared_data;
GdkGLContext *existing; GdkGLContext *existing;
GLint sync_to_framerate = 1; GLint sync_to_framerate = 1;
GLint opaque = 0;
GLint validate = 0; GLint validate = 0;
int major, minor; int major, minor;
@ -225,7 +225,6 @@ gdk_macos_gl_context_real_realize (GdkGLContext *context,
} }
[gl_context setValues:&sync_to_framerate forParameter:NSOpenGLCPSwapInterval]; [gl_context setValues:&sync_to_framerate forParameter:NSOpenGLCPSwapInterval];
[gl_context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
[gl_context setValues:&validate forParameter:NSOpenGLContextParameterStateValidation]; [gl_context setValues:&validate forParameter:NSOpenGLContextParameterStateValidation];
self->dummy_window = [[NSWindow alloc] initWithContentRect:NSZeroRect self->dummy_window = [[NSWindow alloc] initWithContentRect:NSZeroRect
@ -280,6 +279,9 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
if (self->needs_resize) if (self->needs_resize)
{ {
GdkSurface *surface = gdk_draw_context_get_surface (context);
GLint opaque;
self->needs_resize = FALSE; self->needs_resize = FALSE;
if (self->dummy_view != NULL) if (self->dummy_view != NULL)
@ -291,6 +293,16 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
[self->dummy_view setFrame:frame]; [self->dummy_view setFrame:frame];
} }
/* Possibly update our opaque setting depending on a resize. We can
* rely on getting a resize if decoarated is changed, so this reduces
* how much we adjust the parameter.
*/
if (GDK_IS_MACOS_TOPLEVEL_SURFACE (surface))
opaque = GDK_MACOS_TOPLEVEL_SURFACE (surface)->decorated;
else
opaque = FALSE;
[self->gl_context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
[self->gl_context update]; [self->gl_context update];
} }

View File

@ -24,13 +24,24 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _GdkMacosToplevelSurface GdkMacosToplevelSurface;
typedef struct _GdkMacosToplevelSurfaceClass GdkMacosToplevelSurfaceClass;
#define GDK_TYPE_MACOS_TOPLEVEL_SURFACE (_gdk_macos_toplevel_surface_get_type()) #define GDK_TYPE_MACOS_TOPLEVEL_SURFACE (_gdk_macos_toplevel_surface_get_type())
#define GDK_MACOS_TOPLEVEL_SURFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_MACOS_TOPLEVEL_SURFACE, GdkMacosToplevelSurface)) #define GDK_MACOS_TOPLEVEL_SURFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_MACOS_TOPLEVEL_SURFACE, GdkMacosToplevelSurface))
#define GDK_IS_MACOS_TOPLEVEL_SURFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_MACOS_TOPLEVEL_SURFACE)) #define GDK_IS_MACOS_TOPLEVEL_SURFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_MACOS_TOPLEVEL_SURFACE))
typedef struct _GdkMacosToplevelSurface GdkMacosToplevelSurface;
typedef struct _GdkMacosToplevelSurfaceClass GdkMacosToplevelSurfaceClass;
struct _GdkMacosToplevelSurface
{
GdkMacosSurface parent_instance;
guint decorated : 1;
};
struct _GdkMacosToplevelSurfaceClass
{
GdkMacosSurfaceClass parent_instance;
};
GType _gdk_macos_toplevel_surface_get_type (void); GType _gdk_macos_toplevel_surface_get_type (void);
GdkMacosSurface *_gdk_macos_toplevel_surface_new (GdkMacosDisplay *display, GdkMacosSurface *_gdk_macos_toplevel_surface_new (GdkMacosDisplay *display,
GdkSurface *parent, GdkSurface *parent,

View File

@ -29,17 +29,6 @@
#include "gdkmacostoplevelsurface-private.h" #include "gdkmacostoplevelsurface-private.h"
#include "gdkmacosutils-private.h" #include "gdkmacosutils-private.h"
struct _GdkMacosToplevelSurface
{
GdkMacosSurface parent_instance;
guint decorated : 1;
};
struct _GdkMacosToplevelSurfaceClass
{
GdkMacosSurfaceClass parent_instance;
};
static void static void
_gdk_macos_toplevel_surface_fullscreen (GdkMacosToplevelSurface *self) _gdk_macos_toplevel_surface_fullscreen (GdkMacosToplevelSurface *self)
{ {