[gtk/wip/chergert/quartz4u] macos: render backbuffer during drawRects



commit e7e1baf388ce0ed010e0c429713d54f5f98c8171
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 5 18:03:21 2020 -0700

    macos: render backbuffer during drawRects
    
    This can be done a lot better for cairo. We might be able to use a quartz
    image surface for one, but also we still need to keep the full backbuffer
    contents around between each render so that we don't have gaps.

 gdk/macos/GdkMacosCairoView.c | 44 ++++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 24 deletions(-)
---
diff --git a/gdk/macos/GdkMacosCairoView.c b/gdk/macos/GdkMacosCairoView.c
index 6a51b8f7a3..6efac3b130 100644
--- a/gdk/macos/GdkMacosCairoView.c
+++ b/gdk/macos/GdkMacosCairoView.c
@@ -24,9 +24,11 @@
 #include <CoreGraphics/CoreGraphics.h>
 #include <cairo-quartz.h>
 
+#include "gdkinternals.h"
+
 #import "GdkMacosCairoView.h"
 
-#include "gdkinternals.h"
+#include "gdkmacossurface-private.h"
 
 @implementation GdkMacosCairoView
 
@@ -70,44 +72,38 @@
 
 -(void)drawRect:(NSRect)rect
 {
+  GdkMacosSurface *gdkSurface;
+  CGContextRef cg_context;
   cairo_surface_t *dest;
   cairo_t *cr;
-  guint n_rects;
+  int scale_factor;
 
   if (self->surface == NULL || self->region == NULL)
     return;
 
-  dest = cairo_quartz_surface_create_for_cg_context (NSGraphicsContext.currentContext.CGContext,
-                                                     self.bounds.size.width,
-                                                     self.bounds.size.height);
-  cr = cairo_create (dest);
-
-#if 0
-  n_rects = cairo_region_num_rectangles (self->region);
+  gdkSurface = [self getGdkSurface];
+  cg_context = _gdk_macos_surface_acquire_context (gdkSurface, TRUE, TRUE);
+  scale_factor = gdk_surface_get_scale_factor (GDK_SURFACE (gdkSurface));
 
-  g_print ("drawRect: %d rects\n", n_rects);
+  dest = cairo_quartz_surface_create_for_cg_context (cg_context,
+                                                     self.bounds.size.width * scale_factor,
+                                                     self.bounds.size.height * scale_factor);
+  cairo_surface_set_device_scale (dest, scale_factor, scale_factor);
 
-  for (guint i = 0; i < n_rects; i++)
-    {
-      cairo_rectangle_int_t r;
-
-      cairo_region_get_rectangle (self->region, i, &r);
-      cairo_rectangle (cr, r.x, r.y, r.width, r.height);
-    }
+  cr = cairo_create (dest);
 
   cairo_set_source_surface (cr, self->surface, 0, 0);
-  cairo_rectangle (cr, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
-  cairo_paint (cr);
-#endif
+  gdk_cairo_region (cr, self->region);
+  cairo_clip (cr);
 
-  cairo_rectangle (cr, 0, 0, self.bounds.size.width, self.bounds.size.height);
-  cairo_set_source_rgb (cr, 0, 0, 0);
-  cairo_fill (cr);
+  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+  cairo_paint (cr);
 
   cairo_destroy (cr);
-
   cairo_surface_flush (dest);
   cairo_surface_destroy (dest);
+
+  _gdk_macos_surface_release_context (gdkSurface, cg_context);
 }
 
 @end


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