Use the surface colorstate in begin_frame

begin_frame is the place where we make decisions about the format,
depth and colorstate for our rendering. Make these calls take the
surface color state into account.

In particular, if the surface colorstate is suitable for GL_SRGB,
and we don't need high depth, set things up for that.
This commit is contained in:
Matthias Clasen 2024-07-14 10:21:39 -04:00
parent 52d2975af3
commit 53d99f5521
3 changed files with 25 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

@ -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