[gtk/wip/chergert/macos-iosurface] cleanups and remove failed experiments
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/macos-iosurface] cleanups and remove failed experiments
- Date: Wed, 9 Feb 2022 23:12:05 +0000 (UTC)
commit 33398aa0a0b08c126d80c88404d1faa61020540d
Author: Christian Hergert <christian hergert me>
Date: Wed Feb 9 15:11:31 2022 -0800
cleanups and remove failed experiments
gdk/macos/gdkmacosbuffer.c | 2 +-
gdk/macos/gdkmacoscairocontext.c | 28 ++++----
gdk/macos/gdkmacossurface-private.h | 130 +++++++++++++++++-------------------
gdk/macos/gdkmacossurface.c | 59 +++++-----------
4 files changed, 95 insertions(+), 124 deletions(-)
---
diff --git a/gdk/macos/gdkmacosbuffer.c b/gdk/macos/gdkmacosbuffer.c
index 5a19612fac..1ec8554640 100644
--- a/gdk/macos/gdkmacosbuffer.c
+++ b/gdk/macos/gdkmacosbuffer.c
@@ -229,7 +229,7 @@ _gdk_macos_buffer_set_damage (GdkMacosBuffer *self,
return;
g_clear_pointer (&self->damage, cairo_region_destroy);
- self->damage = damage;
+ self->damage = cairo_region_reference (damage);
}
gpointer
diff --git a/gdk/macos/gdkmacoscairocontext.c b/gdk/macos/gdkmacoscairocontext.c
index d3d48392e5..e80db6d569 100644
--- a/gdk/macos/gdkmacoscairocontext.c
+++ b/gdk/macos/gdkmacoscairocontext.c
@@ -61,7 +61,7 @@ _gdk_macos_cairo_context_cairo_create (GdkCairoContext *cairo_context)
GdkMacosCairoContext *self = (GdkMacosCairoContext *)cairo_context;
const cairo_region_t *damage;
cairo_surface_t *image_surface;
- GdkMacosBuffer *back;
+ GdkMacosBuffer *buffer;
GdkSurface *surface;
NSWindow *nswindow;
cairo_t *cr;
@@ -78,13 +78,13 @@ _gdk_macos_cairo_context_cairo_create (GdkCairoContext *cairo_context)
nswindow = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
opaque = [nswindow isOpaque];
- back = _gdk_macos_surface_get_back_buffer (GDK_MACOS_SURFACE (surface));
- damage = _gdk_macos_buffer_get_damage (back);
- width = _gdk_macos_buffer_get_width (back);
- height = _gdk_macos_buffer_get_height (back);
- scale = _gdk_macos_buffer_get_device_scale (back);
- stride = _gdk_macos_buffer_get_stride (back);
- data = _gdk_macos_buffer_get_data (back);
+ buffer = _gdk_macos_surface_get_buffer (GDK_MACOS_SURFACE (surface));
+ damage = _gdk_macos_buffer_get_damage (buffer);
+ width = _gdk_macos_buffer_get_width (buffer);
+ height = _gdk_macos_buffer_get_height (buffer);
+ scale = _gdk_macos_buffer_get_device_scale (buffer);
+ stride = _gdk_macos_buffer_get_stride (buffer);
+ data = _gdk_macos_buffer_get_data (buffer);
/* Instead of forcing cairo to do everything through a CGContext,
* we just use an image surface backed by an IOSurfaceRef mapped
@@ -107,10 +107,10 @@ _gdk_macos_cairo_context_cairo_create (GdkCairoContext *cairo_context)
cairo_surface_set_device_scale (image_surface, scale, scale);
/* Lock the buffer so we can modify it safely */
- _gdk_macos_buffer_lock (back);
+ _gdk_macos_buffer_lock (buffer);
cairo_surface_set_user_data (image_surface,
&buffer_key,
- g_object_ref (back),
+ g_object_ref (buffer),
unlock_buffer);
if (!(cr = cairo_create (image_surface)))
@@ -164,7 +164,7 @@ _gdk_macos_cairo_context_begin_frame (GdkDrawContext *draw_context,
cairo_region_t *region)
{
GdkMacosCairoContext *self = (GdkMacosCairoContext *)draw_context;
- GdkMacosBuffer *back;
+ GdkMacosBuffer *buffer;
GdkSurface *surface;
g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
@@ -173,9 +173,9 @@ _gdk_macos_cairo_context_begin_frame (GdkDrawContext *draw_context,
[CATransaction setDisableActions:YES];
surface = gdk_draw_context_get_surface (draw_context);
- back = _gdk_macos_surface_get_back_buffer (GDK_MACOS_SURFACE (surface));
+ buffer = _gdk_macos_surface_get_buffer (GDK_MACOS_SURFACE (surface));
- _gdk_macos_buffer_set_damage (back, cairo_region_copy (region));
+ _gdk_macos_buffer_set_damage (buffer, region);
}
static void
@@ -197,7 +197,7 @@ _gdk_macos_cairo_context_surface_resized (GdkDrawContext *draw_context)
{
g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (draw_context));
- /* Do nothing, our next begin_frame will get a new back buffer */
+ /* Do nothing, next begin_frame will get new buffer */
}
static void
diff --git a/gdk/macos/gdkmacossurface-private.h b/gdk/macos/gdkmacossurface-private.h
index e73f2437f6..17686a04ee 100644
--- a/gdk/macos/gdkmacossurface-private.h
+++ b/gdk/macos/gdkmacossurface-private.h
@@ -41,14 +41,12 @@ struct _GdkMacosSurface
{
GdkSurface parent_instance;
- GdkMacosBuffer *buffers[2];
- GdkMacosBuffer *front_buffer;
-
GList main;
GList sorted;
GList frame;
GdkMacosWindow *window;
+ GdkMacosBuffer *buffer;
GPtrArray *monitors;
cairo_region_t *input_region;
cairo_region_t *opaque_region;
@@ -66,7 +64,6 @@ struct _GdkMacosSurface
guint did_initial_present : 1;
guint geometry_dirty : 1;
- guint back_buffer : 1;
};
struct _GdkMacosSurfaceClass
@@ -74,71 +71,68 @@ struct _GdkMacosSurfaceClass
GdkSurfaceClass parent_class;
};
-GdkMacosSurface *_gdk_macos_surface_new (GdkMacosDisplay *display,
- GdkSurfaceType surface_type,
- GdkSurface *parent,
- int x,
- int y,
- int width,
- int height);
-NSWindow *_gdk_macos_surface_get_native (GdkMacosSurface *self);
-CGDirectDisplayID _gdk_macos_surface_get_screen_id (GdkMacosSurface *self);
-const char *_gdk_macos_surface_get_title (GdkMacosSurface *self);
-void _gdk_macos_surface_set_title (GdkMacosSurface *self,
- const char *title);
-void _gdk_macos_surface_get_shadow (GdkMacosSurface *self,
- int *top,
- int *right,
- int *bottom,
- int *left);
-void _gdk_macos_surface_set_shadow (GdkMacosSurface *self,
- int top,
- int right,
- int bottom,
- int left);
-NSView *_gdk_macos_surface_get_view (GdkMacosSurface *self);
-gboolean _gdk_macos_surface_get_modal_hint (GdkMacosSurface *self);
-void _gdk_macos_surface_set_modal_hint (GdkMacosSurface *self,
- gboolean modal_hint);
-void _gdk_macos_surface_set_geometry_hints (GdkMacosSurface *self,
- const GdkGeometry *geometry,
- GdkSurfaceHints geom_mask);
-void _gdk_macos_surface_resize (GdkMacosSurface *self,
- int width,
- int height);
-void _gdk_macos_surface_update_fullscreen_state (GdkMacosSurface *self);
-void _gdk_macos_surface_update_position (GdkMacosSurface *self);
-void _gdk_macos_surface_show (GdkMacosSurface *self);
-void _gdk_macos_surface_publish_timings (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);
-void _gdk_macos_surface_synthesize_null_key (GdkMacosSurface *self);
-void _gdk_macos_surface_move (GdkMacosSurface *self,
- int x,
- int y);
-void _gdk_macos_surface_move_resize (GdkMacosSurface *self,
- int x,
- int y,
- int width,
- int height);
-gboolean _gdk_macos_surface_is_tracking (GdkMacosSurface *self,
- NSTrackingArea *area);
-void _gdk_macos_surface_monitor_changed (GdkMacosSurface *self);
-GdkMonitor *_gdk_macos_surface_get_best_monitor (GdkMacosSurface *self);
-void _gdk_macos_surface_reposition_children (GdkMacosSurface *self);
-void _gdk_macos_surface_set_opacity (GdkMacosSurface *self,
- double opacity);
-void _gdk_macos_surface_get_root_coords (GdkMacosSurface *self,
- int *x,
- int *y);
+GdkMacosSurface *_gdk_macos_surface_new (GdkMacosDisplay *display,
+ GdkSurfaceType surface_type,
+ GdkSurface *parent,
+ int x,
+ int y,
+ int width,
+ int height);
+NSWindow *_gdk_macos_surface_get_native (GdkMacosSurface *self);
+CGDirectDisplayID _gdk_macos_surface_get_screen_id (GdkMacosSurface *self);
+const char *_gdk_macos_surface_get_title (GdkMacosSurface *self);
+void _gdk_macos_surface_set_title (GdkMacosSurface *self,
+ const char *title);
+void _gdk_macos_surface_get_shadow (GdkMacosSurface *self,
+ int *top,
+ int *right,
+ int *bottom,
+ int *left);
+void _gdk_macos_surface_set_shadow (GdkMacosSurface *self,
+ int top,
+ int right,
+ int bottom,
+ int left);
+NSView *_gdk_macos_surface_get_view (GdkMacosSurface *self);
+gboolean _gdk_macos_surface_get_modal_hint (GdkMacosSurface *self);
+void _gdk_macos_surface_set_modal_hint (GdkMacosSurface *self,
+ gboolean modal_hint);
+void _gdk_macos_surface_set_geometry_hints (GdkMacosSurface *self,
+ const GdkGeometry *geometry,
+ GdkSurfaceHints geom_mask);
+void _gdk_macos_surface_resize (GdkMacosSurface *self,
+ int width,
+ int height);
+void _gdk_macos_surface_update_fullscreen_state (GdkMacosSurface *self);
+void _gdk_macos_surface_update_position (GdkMacosSurface *self);
+void _gdk_macos_surface_show (GdkMacosSurface *self);
+void _gdk_macos_surface_publish_timings (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_synthesize_null_key (GdkMacosSurface *self);
+void _gdk_macos_surface_move (GdkMacosSurface *self,
+ int x,
+ int y);
+void _gdk_macos_surface_move_resize (GdkMacosSurface *self,
+ int x,
+ int y,
+ int width,
+ int height);
+gboolean _gdk_macos_surface_is_tracking (GdkMacosSurface *self,
+ NSTrackingArea *area);
+void _gdk_macos_surface_monitor_changed (GdkMacosSurface *self);
+GdkMonitor *_gdk_macos_surface_get_best_monitor (GdkMacosSurface *self);
+void _gdk_macos_surface_reposition_children (GdkMacosSurface *self);
+void _gdk_macos_surface_set_opacity (GdkMacosSurface *self,
+ double opacity);
+void _gdk_macos_surface_get_root_coords (GdkMacosSurface *self,
+ int *x,
+ int *y);
void _gdk_macos_surface_update_size (GdkMacosSurface *self);
-GdkMacosBuffer *_gdk_macos_surface_get_back_buffer (GdkMacosSurface *self);
-GdkMacosBuffer *_gdk_macos_surface_get_front_buffer (GdkMacosSurface *self);
+GdkMacosBuffer *_gdk_macos_surface_get_buffer (GdkMacosSurface *self);
void _gdk_macos_surface_swap_buffers (GdkMacosSurface *self,
const cairo_region_t *damage);
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index 80e3a19425..cd66c5924f 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -822,16 +822,6 @@ _gdk_macos_surface_acquire_context (GdkMacosSurface *self,
return cg_context;
}
-void
-_gdk_macos_surface_release_context (GdkMacosSurface *self,
- CGContextRef cg_context)
-{
- g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
-
- CGContextRestoreGState (cg_context);
- CGContextSetAllowsAntialiasing (cg_context, TRUE);
-}
-
void
_gdk_macos_surface_synthesize_null_key (GdkMacosSurface *self)
{
@@ -864,6 +854,7 @@ static void
gdk_macos_surface_update_buffers (GdkMacosSurface *self)
{
GdkMacosDisplay *display;
+ GdkMacosBuffer *buffer;
double scale;
guint width;
guint height;
@@ -874,24 +865,20 @@ gdk_macos_surface_update_buffers (GdkMacosSurface *self)
width = GDK_SURFACE (self)->width * scale;
height = GDK_SURFACE (self)->height * scale;
- g_print ("Creating new buffers: %dx%d\n", width, height);
-
+ /* Create replacement buffer. We always use 4-byte and 32-bit BGRA for
+ * our surface as that can work with both Cairo and GL. The GdkMacosTile
+ * handles opaque regions for the compositor, so using 3-byte/24-bit is
+ * not a necessary optimization.
+ */
display = GDK_MACOS_DISPLAY (gdk_surface_get_display (GDK_SURFACE (self)));
+ buffer = _gdk_macos_buffer_new (display, width, height, scale, 4, 32);
- for (guint i = 0; i < G_N_ELEMENTS (self->buffers); i++)
+ /* If we failed, just keep the old buffer around. */
+ if (buffer != NULL)
{
- GdkMacosBuffer *buffer = _gdk_macos_buffer_new (display, width, height, scale, 4, 32);
-
- if (buffer != NULL)
- {
- g_print ("%p replaced with %p\n", self->buffers[i], buffer);
- g_clear_object (&self->buffers[i]);
- self->buffers[i] = buffer;
- }
+ g_clear_object (&self->buffer);
+ self->buffer = buffer;
}
-
- self->front_buffer = self->buffers[0];
- self->back_buffer = 1;
}
void
@@ -1124,33 +1111,23 @@ _gdk_macos_surface_update_size (GdkMacosSurface *self)
}
GdkMacosBuffer *
-_gdk_macos_surface_get_back_buffer (GdkMacosSurface *self)
-{
- g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
-
- return self->buffers[self->back_buffer];
-}
-
-GdkMacosBuffer *
-_gdk_macos_surface_get_front_buffer (GdkMacosSurface *self)
+_gdk_macos_surface_get_buffer (GdkMacosSurface *self)
{
g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
- return self->front_buffer;
+ return self->buffer;
}
void
_gdk_macos_surface_swap_buffers (GdkMacosSurface *self,
const cairo_region_t *damage)
{
- GdkMacosBuffer *buffer;
-
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
g_return_if_fail (damage != NULL);
- buffer = self->buffers[self->back_buffer];
- self->front_buffer = buffer;
- //self->back_buffer = (self->back_buffer + 1) % G_N_ELEMENTS (self->buffers);
-
- [self->window swapBuffer:buffer withDamage:damage];
+ /* This code looks like it swaps buffers, but since the IOSurfaceRef
+ * appears to be retained on the other side, we really just ask all
+ * of the GdkMacosTile CALayer's to update their contents.
+ */
+ [self->window swapBuffer:self->buffer withDamage:damage];
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]