gpu: Return color state when uploading textures

We want to allow for the possibility that we can automatically
convert from srgb to srgb-linear by picking the right image
format, so we need the upload operation to return the proper
color state for the image that it created.

For now, we do nothing with the returned information.
This commit is contained in:
Matthias Clasen
2024-06-17 16:15:25 -04:00
parent c6bb894507
commit b710e72e1e
3 changed files with 25 additions and 10 deletions

View File

@@ -403,17 +403,26 @@ gsk_gpu_frame_get_last_op (GskGpuFrame *self)
}
GskGpuImage *
gsk_gpu_frame_upload_texture (GskGpuFrame *self,
gboolean with_mipmap,
GdkTexture *texture)
gsk_gpu_frame_upload_texture (GskGpuFrame *self,
gboolean with_mipmap,
GdkTexture *texture,
GdkColorState **out_color_state)
{
GskGpuFramePrivate *priv = gsk_gpu_frame_get_instance_private (self);
GskGpuImage *image;
GdkColorState *color_state;
image = GSK_GPU_FRAME_GET_CLASS (self)->upload_texture (self, with_mipmap, texture);
if (gsk_gpu_image_get_flags (image) & GSK_GPU_IMAGE_SRGB)
color_state = GDK_COLOR_STATE_SRGB_LINEAR;
else
color_state = gdk_texture_get_color_state (texture);
if (image)
gsk_gpu_device_cache_texture_image (priv->device, texture, priv->timestamp, image, gdk_texture_get_color_state (texture));
gsk_gpu_device_cache_texture_image (priv->device, texture, priv->timestamp, image, color_state);
*out_color_state = color_state;
return image;
}
@@ -708,10 +717,11 @@ gsk_gpu_frame_download_texture (GskGpuFrame *self,
{
GskGpuFramePrivate *priv = gsk_gpu_frame_get_instance_private (self);
GskGpuImage *image;
GdkColorState *color_state;
image = gsk_gpu_device_lookup_texture_image (priv->device, texture, GDK_COLOR_STATE_SRGB, timestamp);
if (image == NULL)
image = gsk_gpu_frame_upload_texture (self, FALSE, texture);
image = gsk_gpu_frame_upload_texture (self, FALSE, texture, &color_state);
if (image == NULL)
{
g_critical ("Could not upload texture");

View File

@@ -58,7 +58,8 @@ gpointer gsk_gpu_frame_alloc_op (GskGpuF
gsize size);
GskGpuImage * gsk_gpu_frame_upload_texture (GskGpuFrame *self,
gboolean with_mipmap,
GdkTexture *texture);
GdkTexture *texture,
GdkColorState **out_color_state);
GskGpuDescriptors * gsk_gpu_frame_create_descriptors (GskGpuFrame *self);
gsize gsk_gpu_frame_reserve_vertex_data (GskGpuFrame *self,
gsize size);

View File

@@ -811,6 +811,7 @@ gsk_gpu_get_node_as_image (GskGpuFrame *frame,
graphene_rect_t *out_bounds)
{
GskGpuImage *result;
GdkColorState *image_color_state;
switch ((guint) gsk_render_node_get_node_type (node))
{
@@ -821,7 +822,7 @@ gsk_gpu_get_node_as_image (GskGpuFrame *frame,
gint64 timestamp = gsk_gpu_frame_get_timestamp (frame);
result = gsk_gpu_device_lookup_texture_image (device, texture, gdk_texture_get_color_state (texture), timestamp);
if (result == NULL)
result = gsk_gpu_frame_upload_texture (frame, FALSE, texture);
result = gsk_gpu_frame_upload_texture (frame, FALSE, texture, &image_color_state);
if (result)
{
@@ -1954,6 +1955,7 @@ gsk_gpu_node_processor_add_texture_node (GskGpuNodeProcessor *self,
GskGpuImage *image;
GdkTexture *texture;
gint64 timestamp;
GdkColorState *image_color_state;
device = gsk_gpu_frame_get_device (self->frame);
texture = gsk_texture_node_get_texture (node);
@@ -1962,7 +1964,7 @@ gsk_gpu_node_processor_add_texture_node (GskGpuNodeProcessor *self,
image = gsk_gpu_device_lookup_texture_image (device, texture, gdk_texture_get_color_state (texture), timestamp);
if (image == NULL)
{
image = gsk_gpu_frame_upload_texture (self->frame, FALSE, texture);
image = gsk_gpu_frame_upload_texture (self->frame, FALSE, texture, &image_color_state);
if (image == NULL)
{
GSK_DEBUG (FALLBACK, "Unsupported texture format %u for size %dx%d",
@@ -2029,6 +2031,7 @@ gsk_gpu_node_processor_create_texture_pattern (GskGpuPatternWriter *self,
guint32 descriptor;
GskGpuImage *image;
GskGpuSampler sampler;
GdkColorState *image_color_state;
device = gsk_gpu_frame_get_device (self->frame);
texture = gsk_texture_node_get_texture (node);
@@ -2037,7 +2040,7 @@ gsk_gpu_node_processor_create_texture_pattern (GskGpuPatternWriter *self,
image = gsk_gpu_device_lookup_texture_image (device, texture, gdk_texture_get_color_state (texture), timestamp);
if (image == NULL)
{
image = gsk_gpu_frame_upload_texture (self->frame, FALSE, texture);
image = gsk_gpu_frame_upload_texture (self->frame, FALSE, texture, &image_color_state);
if (image == NULL)
return FALSE;
}
@@ -2087,6 +2090,7 @@ gsk_gpu_node_processor_add_texture_scale_node (GskGpuNodeProcessor *self,
gint64 timestamp;
guint32 descriptor;
gboolean need_mipmap, need_offscreen;
GdkColorState *image_color_state;
need_offscreen = self->modelview != NULL ||
!graphene_vec2_equal (&self->scale, graphene_vec2_one ());
@@ -2134,7 +2138,7 @@ gsk_gpu_node_processor_add_texture_scale_node (GskGpuNodeProcessor *self,
image = gsk_gpu_device_lookup_texture_image (device, texture, gdk_texture_get_color_state (texture), timestamp);
if (image == NULL)
{
image = gsk_gpu_frame_upload_texture (self->frame, need_mipmap, texture);
image = gsk_gpu_frame_upload_texture (self->frame, need_mipmap, texture, &image_color_state);
if (image == NULL)
{
GSK_DEBUG (FALLBACK, "Unsupported texture format %u for size %dx%d",