[gtk/wip/chergert/macos-fixes: 20/23] macos: avoid unnecessarily destroying cairo_t
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/macos-fixes: 20/23] macos: avoid unnecessarily destroying cairo_t
- Date: Fri, 4 Feb 2022 03:26:38 +0000 (UTC)
commit 58159552baf9789bf1724d468a78876eac5104d0
Author: Christian Hergert <christian hergert me>
Date: Thu Feb 3 13:01:46 2022 -0800
macos: avoid unnecessarily destroying cairo_t
This avoids destroying a cairo_t when we are within the frame as it
otherwise causes the surface to unnecessarily flush.
gdk/macos/gdkmacoscairocontext.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
---
diff --git a/gdk/macos/gdkmacoscairocontext.c b/gdk/macos/gdkmacoscairocontext.c
index 2b9a91c16f..78cb61c0c1 100644
--- a/gdk/macos/gdkmacoscairocontext.c
+++ b/gdk/macos/gdkmacoscairocontext.c
@@ -34,6 +34,7 @@ struct _GdkMacosCairoContext
GdkCairoContext parent_instance;
cairo_surface_t *window_surface;
+ cairo_t *cr;
};
struct _GdkMacosCairoContextClass
@@ -77,6 +78,9 @@ _gdk_macos_cairo_context_cairo_create (GdkCairoContext *cairo_context)
g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
+ if (self->cr != NULL)
+ return cairo_reference (self->cr);
+
return cairo_create (self->window_surface);
}
@@ -95,20 +99,18 @@ _gdk_macos_cairo_context_begin_frame (GdkDrawContext *draw_context,
nswindow = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
if (self->window_surface == NULL)
+ self->window_surface = create_cairo_surface_for_surface (surface);
+
+ self->cr = cairo_create (self->window_surface);
+
+ if (![nswindow isOpaque])
{
- self->window_surface = create_cairo_surface_for_surface (surface);
- }
- else
- {
- if (![nswindow isOpaque])
- {
- cairo_t *cr = cairo_create (self->window_surface);
- gdk_cairo_region (cr, region);
- cairo_set_source_rgba (cr, 0, 0, 0, 0);
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_fill (cr);
- cairo_destroy (cr);
- }
+ cairo_save (self->cr);
+ gdk_cairo_region (self->cr, region);
+ cairo_set_source_rgba (self->cr, 0, 0, 0, 0);
+ cairo_set_operator (self->cr, CAIRO_OPERATOR_SOURCE);
+ cairo_fill (self->cr);
+ cairo_restore (self->cr);
}
}
@@ -126,6 +128,8 @@ _gdk_macos_cairo_context_end_frame (GdkDrawContext *draw_context,
surface = gdk_draw_context_get_surface (draw_context);
nsview = _gdk_macos_surface_get_view (GDK_MACOS_SURFACE (surface));
+ g_clear_pointer (&self->cr, cairo_destroy);
+
if (GDK_IS_MACOS_CAIRO_VIEW (nsview))
[(GdkMacosCairoView *)nsview setCairoSurface:self->window_surface
withDamage:painted];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]