Merge branch 'surface-color-state' into 'main'

surface: Add a color state

See merge request GNOME/gtk!7456
This commit is contained in:
Matthias Clasen
2024-07-14 17:21:51 +00:00
5 changed files with 61 additions and 11 deletions

View File

@@ -617,27 +617,33 @@ gdk_gl_context_real_begin_frame (GdkDrawContext *draw_context,
{
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
G_GNUC_UNUSED GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
GdkSurface *surface;
GdkSurface *surface = gdk_draw_context_get_surface (draw_context);
GdkColorState *color_state;
cairo_region_t *damage;
double scale;
int ww, wh;
int i;
surface = gdk_draw_context_get_surface (draw_context);
color_state = gdk_surface_get_color_state (surface);
scale = gdk_gl_context_get_scale (context);
depth = gdk_memory_depth_merge (depth, gdk_color_state_get_depth (color_state));
g_assert (depth != GDK_MEMORY_U8_SRGB || gdk_color_state_get_no_srgb_tf (color_state) != NULL);
#ifdef HAVE_EGL
if (priv->egl_context)
*out_depth = gdk_surface_ensure_egl_surface (surface, depth);
else
*out_depth = gdk_color_state_get_depth (GDK_COLOR_STATE_SRGB);
*out_depth = GDK_MEMORY_U8;
if (*out_depth == GDK_MEMORY_U8_SRGB)
*out_color_state = GDK_COLOR_STATE_SRGB_LINEAR;
*out_color_state = gdk_color_state_get_no_srgb_tf (color_state);
else
*out_color_state = GDK_COLOR_STATE_SRGB;
*out_color_state = color_state;
#else
*out_color_state = GDK_COLOR_STATE_SRGB;
*out_depth = gdk_color_state_get_depth (GDK_COLOR_STATE_SRGB);
*out_color_state = gdk_color_state_get_srgb ();
*out_depth = GDK_MEMORY_U8;
#endif
damage = GDK_GL_CONTEXT_GET_CLASS (context)->get_damage (context);

View File

@@ -76,6 +76,8 @@ struct _GdkSurfacePrivate
#endif
gpointer widget;
GdkColorState *color_state;
};
enum {
@@ -475,6 +477,8 @@ gdk_surface_event_marshallerv (GClosure *closure,
static void
gdk_surface_init (GdkSurface *surface)
{
GdkSurfacePrivate *priv = gdk_surface_get_instance_private (surface);
/* 0-initialization is good for all other fields. */
surface->state = 0;
@@ -488,6 +492,8 @@ gdk_surface_init (GdkSurface *surface)
NULL, g_object_unref);
surface->subsurfaces = g_ptr_array_new ();
priv->color_state = gdk_color_state_ref (gdk_color_state_get_srgb ());
}
static double
@@ -745,6 +751,7 @@ static void
gdk_surface_finalize (GObject *object)
{
GdkSurface *surface = GDK_SURFACE (object);
GdkSurfacePrivate *priv = gdk_surface_get_instance_private (surface);
g_clear_handle_id (&surface->request_motion_id, g_source_remove);
@@ -773,6 +780,8 @@ gdk_surface_finalize (GObject *object)
g_ptr_array_unref (surface->subsurfaces);
g_clear_pointer (&priv->color_state, gdk_color_state_unref);
G_OBJECT_CLASS (gdk_surface_parent_class)->finalize (object);
}
@@ -3105,3 +3114,26 @@ gdk_surface_get_subsurface (GdkSurface *surface,
{
return g_ptr_array_index (surface->subsurfaces, idx);
}
GdkColorState *
gdk_surface_get_color_state (GdkSurface *surface)
{
GdkSurfacePrivate *priv = gdk_surface_get_instance_private (surface);
return priv->color_state;
}
void
gdk_surface_set_color_state (GdkSurface *surface,
GdkColorState *color_state)
{
GdkSurfacePrivate *priv = gdk_surface_get_instance_private (surface);
if (gdk_color_state_equal (priv->color_state, color_state))
return;
gdk_color_state_unref (priv->color_state);
priv->color_state = gdk_color_state_ref (color_state);
gdk_surface_invalidate_rect (surface, NULL);
}

View File

@@ -353,4 +353,8 @@ gsize gdk_surface_get_n_subsurfaces (GdkSurface *surface);
GdkSubsurface * gdk_surface_get_subsurface (GdkSurface *surface,
gsize idx);
GdkColorState * gdk_surface_get_color_state (GdkSurface *surface);
void gdk_surface_set_color_state (GdkSurface *surface,
GdkColorState *color_state);
G_END_DECLS

View File

@@ -642,9 +642,16 @@ gdk_vulkan_context_begin_frame (GdkDrawContext *draw_context,
{
GdkVulkanContext *context = GDK_VULKAN_CONTEXT (draw_context);
GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
GdkSurface *surface = gdk_draw_context_get_surface (draw_context);
GdkColorState *color_state;
VkResult acquire_result;
guint i;
color_state = gdk_surface_get_color_state (surface);
depth = gdk_memory_depth_merge (depth, gdk_color_state_get_depth (color_state));
g_assert (depth != GDK_MEMORY_U8_SRGB || gdk_color_state_get_no_srgb_tf (color_state) != NULL);
if (depth != priv->current_depth && depth != GDK_MEMORY_NONE)
{
if (priv->formats[depth].vk_format.format != priv->formats[priv->current_depth].vk_format.format ||
@@ -695,9 +702,9 @@ gdk_vulkan_context_begin_frame (GdkDrawContext *draw_context,
cairo_region_union (region, priv->regions[priv->draw_index]);
if (priv->current_depth == GDK_MEMORY_U8_SRGB)
*out_color_state = GDK_COLOR_STATE_SRGB_LINEAR;
*out_color_state = gdk_color_state_get_no_srgb_tf (color_state);
else
*out_color_state = GDK_COLOR_STATE_SRGB;
*out_color_state = color_state;
*out_depth = priv->current_depth;
}

View File

@@ -154,6 +154,7 @@ gdk_wayland_cairo_context_begin_frame (GdkDrawContext *draw_context,
const cairo_region_t *surface_region;
GSList *l;
cairo_t *cr;
GdkSurface *surface = gdk_draw_context_get_surface (draw_context);
if (self->cached_surface)
self->paint_surface = g_steal_pointer (&self->cached_surface);
@@ -176,8 +177,8 @@ gdk_wayland_cairo_context_begin_frame (GdkDrawContext *draw_context,
cairo_fill (cr);
cairo_destroy (cr);
*out_color_state = GDK_COLOR_STATE_SRGB;
*out_depth = gdk_color_state_get_depth (GDK_COLOR_STATE_SRGB);
*out_color_state = gdk_surface_get_color_state (surface);
*out_depth = GDK_MEMORY_U8;
}
static void