[gtk/wip/chergert/quartz4u] macos: add helper to acquire/release cgcontextref



commit 1ac6a8caea5d1dda6c2675fae6ae7fdd1c3c310e
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 5 18:00:46 2020 -0700

    macos: add helper to acquire/release cgcontextref

 gdk/macos/gdkmacossurface-private.h |  5 ++++
 gdk/macos/gdkmacossurface.c         | 46 +++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
---
diff --git a/gdk/macos/gdkmacossurface-private.h b/gdk/macos/gdkmacossurface-private.h
index 466cb13a99..9962fb5f86 100644
--- a/gdk/macos/gdkmacossurface-private.h
+++ b/gdk/macos/gdkmacossurface-private.h
@@ -85,6 +85,11 @@ void               _gdk_macos_surface_show                    (GdkMacosSurface
 void               _gdk_macos_surface_thaw                    (GdkMacosSurface    *self,
                                                                gint64              
predicted_presentation_time,
                                                                gint64              refresh_interval);
+CGContextRef       _gdk_macos_surface_acquire_context         (GdkMacosSurface    *self,
+                                                               gboolean            clear_scale,
+                                                               gboolean            antialias);
+void               _gdk_macos_surface_release_context         (GdkMacosSurface    *self,
+                                                               CGContextRef        cg_context);
 
 G_END_DECLS
 
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index 880cf6c0b0..fd532986ba 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -786,3 +786,49 @@ _gdk_macos_surface_show (GdkMacosSurface *self)
         gdk_surface_invalidate_rect (GDK_SURFACE (self), NULL);
     }
 }
+
+CGContextRef
+_gdk_macos_surface_acquire_context (GdkMacosSurface *self,
+                                    gboolean         clear_scale,
+                                    gboolean         antialias)
+{
+  CGContextRef cg_context;
+  NSWindow *native;
+
+  g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
+
+  if (GDK_SURFACE_DESTROYED (self))
+    return NULL;
+
+  if (!(cg_context = [[NSGraphicsContext currentContext] CGContext]))
+    return NULL;
+
+  CGContextSaveGState (cg_context);
+
+  if (!antialias)
+    CGContextSetAllowsAntialiasing (cg_context, antialias);
+
+  if (clear_scale)
+    {
+      CGSize scale;
+
+      scale = CGSizeMake (1.0, 1.0);
+      scale = CGContextConvertSizeToDeviceSpace (cg_context, scale);
+
+      CGContextScaleCTM (cg_context, 1.0 / scale.width, 1.0 / scale.height);
+    }
+
+  return cg_context;
+}
+
+void
+_gdk_macos_surface_release_context (GdkMacosSurface *self,
+                                    CGContextRef     cg_context)
+{
+  NSWindow *native;
+
+  g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
+
+  CGContextRestoreGState (cg_context);
+  CGContextSetAllowsAntialiasing (cg_context, TRUE);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]