[gtk/wip/chergert/gdk-macos-gl-renderer] macos: cleanup pixelFormat creation
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/gdk-macos-gl-renderer] macos: cleanup pixelFormat creation
- Date: Wed, 28 Oct 2020 21:53:07 +0000 (UTC)
commit 291d4cd009ea129257c93f52944ed12fbc58b464
Author: Christian Hergert <chergert redhat com>
Date: Wed Oct 28 14:53:48 2020 -0700
macos: cleanup pixelFormat creation
This doesn't really need to be part of the GL view because we don't use
it there for anything.
gdk/macos/GdkMacosGLView.c | 33 ---------------------------------
gdk/macos/GdkMacosGLView.h | 7 +------
gdk/macos/gdkmacosglcontext.c | 39 ++++++++++++++++++++++++++++++++++++---
3 files changed, 37 insertions(+), 42 deletions(-)
---
diff --git a/gdk/macos/GdkMacosGLView.c b/gdk/macos/GdkMacosGLView.c
index ca7b600783..ce84f98218 100644
--- a/gdk/macos/GdkMacosGLView.c
+++ b/gdk/macos/GdkMacosGLView.c
@@ -32,39 +32,6 @@
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-+(NSOpenGLPixelFormat *)defaultPixelFormat
-{
- static const NSOpenGLPixelFormatAttribute attrs[] = {
- NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
- NSOpenGLPFAAccelerated,
- NSOpenGLPFADoubleBuffer,
-
- (NSOpenGLPixelFormatAttribute)nil
- };
-
- return [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
-}
-
--(id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat*)format
-{
- self = [super initWithFrame:frameRect];
-
- if (self != nil)
- _pixelFormat = [format retain];
-
- return self;
-}
-
--(void)setPixelFormat:(NSOpenGLPixelFormat*)pixelFormat
-{
- _pixelFormat = pixelFormat;
-}
-
--(NSOpenGLPixelFormat*)pixelFormat
-{
- return _pixelFormat;
-}
-
-(void)lockFocus
{
NSOpenGLContext *context;
diff --git a/gdk/macos/GdkMacosGLView.h b/gdk/macos/GdkMacosGLView.h
index c30928910e..320b1a163b 100644
--- a/gdk/macos/GdkMacosGLView.h
+++ b/gdk/macos/GdkMacosGLView.h
@@ -29,16 +29,11 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@interface GdkMacosGLView : GdkMacosBaseView
{
- NSOpenGLContext *_openGLContext;
- NSOpenGLPixelFormat *_pixelFormat;
+ NSOpenGLContext *_openGLContext;
}
-+(NSOpenGLPixelFormat*)defaultPixelFormat;
--(id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat*)format;
-(void)setOpenGLContext:(NSOpenGLContext*)context;
-(NSOpenGLContext *)openGLContext;
--(void)setPixelFormat:(NSOpenGLPixelFormat*)pixelFormat;
--(NSOpenGLPixelFormat*)pixelFormat;
-(void)invalidateRegion:(const cairo_region_t *)region;
G_GNUC_END_IGNORE_DEPRECATIONS
diff --git a/gdk/macos/gdkmacosglcontext.c b/gdk/macos/gdkmacosglcontext.c
index abc36960b0..9ecef3dafa 100644
--- a/gdk/macos/gdkmacosglcontext.c
+++ b/gdk/macos/gdkmacosglcontext.c
@@ -33,7 +33,6 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
G_DEFINE_TYPE (GdkMacosGLContext, gdk_macos_gl_context, GDK_TYPE_GL_CONTEXT)
-static NSOpenGLPixelFormat *pixelFormat;
static NSOpenGLContext *
get_ns_open_gl_context (GdkMacosGLContext *self,
@@ -53,6 +52,35 @@ get_ns_open_gl_context (GdkMacosGLContext *self,
return self->gl_context;
}
+static NSOpenGLPixelFormat *
+create_pixel_format (int major,
+ int minor,
+ GError **error)
+{
+ NSOpenGLPixelFormatAttribute attrs[] = {
+ NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
+ NSOpenGLPFAAccelerated,
+ NSOpenGLPFADoubleBuffer,
+
+ (NSOpenGLPixelFormatAttribute)nil
+ };
+
+ if (major == 3 && minor == 2)
+ attrs[1] = NSOpenGLProfileVersion3_2Core;
+ else if (major == 4 && minor == 1)
+ attrs[1] = NSOpenGLProfileVersion4_1Core;
+
+ NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
+
+ if (format == NULL)
+ g_set_error (error,
+ GDK_GL_ERROR,
+ GDK_GL_ERROR_NOT_AVAILABLE,
+ "Failed to create pixel format");
+
+ return g_steal_pointer (&format);
+}
+
static NSView *
ensure_gl_view (GdkMacosGLContext *self)
{
@@ -71,7 +99,7 @@ ensure_gl_view (GdkMacosGLContext *self)
NSRect frame;
frame = [[nswindow contentView] bounds];
- nsview = [[GdkMacosGLView alloc] initWithFrame:frame pixelFormat:pixelFormat];
+ nsview = [[GdkMacosGLView alloc] initWithFrame:frame];
[nsview setWantsBestResolutionOpenGLSurface:YES];
[nsview setPostsFrameChangedNotifications: YES];
[nsview setNeedsDisplay:YES];
@@ -91,6 +119,7 @@ gdk_macos_gl_context_real_realize (GdkGLContext *context,
NSView *nsview;
NSOpenGLContext *shared_gl_context = nil;
NSOpenGLContext *gl_context;
+ NSOpenGLPixelFormat *pixelFormat;
GdkGLContext *shared;
GdkGLContext *shared_data;
GLint sync_to_framerate = 1;
@@ -133,9 +162,14 @@ gdk_macos_gl_context_real_realize (GdkGLContext *context,
g_message ("Creating NSOpenGLContext (version %d.%d)",
major, minor));
+ if (!(pixelFormat = create_pixel_format (major, minor, error)))
+ return FALSE;
+
gl_context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
shareContext:shared_gl_context];
+ [pixelFormat release];
+
if (gl_context == nil)
{
g_set_error_literal (error,
@@ -182,7 +216,6 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
-
if (self->needs_resize)
{
self->needs_resize = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]