From 1c4362de99ea0a02f2b912c18cab8065d797b957 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 8 Jun 2024 10:14:27 -0400 Subject: [PATCH] gpu: Pass color states through device apis --- gsk/gpu/gskgldevice.c | 18 +++++++++++------- gsk/gpu/gskgpudevice.c | 33 +++++++++++++++++++++++---------- gsk/gpu/gskgpudeviceprivate.h | 7 +++++++ gsk/gpu/gskgpunodeprocessor.c | 2 ++ gsk/gpu/gskgpurenderer.c | 7 +++++++ gsk/gpu/gskgpuuploadop.c | 2 ++ gsk/gpu/gskvulkandevice.c | 20 ++++++++++++-------- 7 files changed, 64 insertions(+), 25 deletions(-) diff --git a/gsk/gpu/gskgldevice.c b/gsk/gpu/gskgldevice.c index 308e1bb5eb..51bb9b3379 100644 --- a/gsk/gpu/gskgldevice.c +++ b/gsk/gpu/gskgldevice.c @@ -69,6 +69,7 @@ static GskGpuImage * gsk_gl_device_create_offscreen_image (GskGpuDevice *device, gboolean with_mipmap, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height) { @@ -76,7 +77,7 @@ gsk_gl_device_create_offscreen_image (GskGpuDevice *device, return gsk_gl_image_new (self, gdk_memory_depth_get_format (depth), - gdk_color_state_get_srgb (), + color_state, GSK_GPU_IMAGE_RENDERABLE | GSK_GPU_IMAGE_FILTERABLE, width, height); @@ -86,6 +87,7 @@ static GskGpuImage * gsk_gl_device_create_upload_image (GskGpuDevice *device, gboolean with_mipmap, GdkMemoryFormat format, + GdkColorState *color_state, gsize width, gsize height) { @@ -93,7 +95,7 @@ gsk_gl_device_create_upload_image (GskGpuDevice *device, return gsk_gl_image_new (self, format, - gdk_color_state_get_srgb (), + color_state, 0, width, height); @@ -102,6 +104,7 @@ gsk_gl_device_create_upload_image (GskGpuDevice *device, static GskGpuImage * gsk_gl_device_create_download_image (GskGpuDevice *device, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height) { @@ -109,22 +112,23 @@ gsk_gl_device_create_download_image (GskGpuDevice *device, return gsk_gl_image_new (self, gdk_memory_depth_get_format (depth), - gdk_color_state_get_srgb (), + color_state, GSK_GPU_IMAGE_RENDERABLE, width, height); } static GskGpuImage * -gsk_gl_device_create_atlas_image (GskGpuDevice *device, - gsize width, - gsize height) +gsk_gl_device_create_atlas_image (GskGpuDevice *device, + GdkColorState *color_state, + gsize width, + gsize height) { GskGLDevice *self = GSK_GL_DEVICE (device); return gsk_gl_image_new (self, GDK_MEMORY_DEFAULT, - gdk_color_state_get_srgb (), + color_state, GSK_GPU_IMAGE_RENDERABLE, width, height); diff --git a/gsk/gpu/gskgpudevice.c b/gsk/gpu/gskgpudevice.c index 5e0fcbd4f5..3a42bf23e9 100644 --- a/gsk/gpu/gskgpudevice.c +++ b/gsk/gpu/gskgpudevice.c @@ -229,9 +229,15 @@ static GskGpuCachedAtlas * gsk_gpu_cached_atlas_new (GskGpuDevice *device) { GskGpuCachedAtlas *self; + GdkColorState *color_state; + + color_state = gdk_color_state_get_srgb (); /* FIXME */ self = gsk_gpu_cached_new (device, &GSK_GPU_CACHED_ATLAS_CLASS, NULL); - self->image = GSK_GPU_DEVICE_GET_CLASS (device)->create_atlas_image (device, ATLAS_SIZE, ATLAS_SIZE); + self->image = GSK_GPU_DEVICE_GET_CLASS (device)->create_atlas_image (device, + color_state, + ATLAS_SIZE, + ATLAS_SIZE); return self; } @@ -689,20 +695,22 @@ GskGpuImage * gsk_gpu_device_create_offscreen_image (GskGpuDevice *self, gboolean with_mipmap, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height) { - return GSK_GPU_DEVICE_GET_CLASS (self)->create_offscreen_image (self, with_mipmap, depth, width, height); + return GSK_GPU_DEVICE_GET_CLASS (self)->create_offscreen_image (self, with_mipmap, depth, color_state, width, height); } GskGpuImage * -gsk_gpu_device_create_upload_image (GskGpuDevice *self, - gboolean with_mipmap, - GdkMemoryFormat format, - gsize width, - gsize height) +gsk_gpu_device_create_upload_image (GskGpuDevice *self, + gboolean with_mipmap, + GdkMemoryFormat format, + GdkColorState *color_state, + gsize width, + gsize height) { - return GSK_GPU_DEVICE_GET_CLASS (self)->create_upload_image (self, with_mipmap, format, width, height); + return GSK_GPU_DEVICE_GET_CLASS (self)->create_upload_image (self, with_mipmap, format, color_state, width, height); } void @@ -714,10 +722,11 @@ gsk_gpu_device_make_current (GskGpuDevice *self) GskGpuImage * gsk_gpu_device_create_download_image (GskGpuDevice *self, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height) { - return GSK_GPU_DEVICE_GET_CLASS (self)->create_download_image (self, depth, width, height); + return GSK_GPU_DEVICE_GET_CLASS (self)->create_download_image (self, depth, color_state, width, height); } /* This rounds up to the next number that has <= 2 bits set: @@ -950,7 +959,11 @@ gsk_gpu_device_lookup_glyph_image (GskGpuDevice *self, } else { - image = gsk_gpu_device_create_upload_image (self, FALSE, GDK_MEMORY_DEFAULT, rect.size.width, rect.size.height), + image = gsk_gpu_device_create_upload_image (self, + FALSE, + GDK_MEMORY_DEFAULT, + gdk_color_state_get_srgb (), /* FIXME */ + rect.size.width, rect.size.height), rect.origin.x = 0; rect.origin.y = 0; padding = 0; diff --git a/gsk/gpu/gskgpudeviceprivate.h b/gsk/gpu/gskgpudeviceprivate.h index 3424a26402..d4b3cee78f 100644 --- a/gsk/gpu/gskgpudeviceprivate.h +++ b/gsk/gpu/gskgpudeviceprivate.h @@ -27,18 +27,22 @@ struct _GskGpuDeviceClass GskGpuImage * (* create_offscreen_image) (GskGpuDevice *self, gboolean with_mipmap, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height); GskGpuImage * (* create_atlas_image) (GskGpuDevice *self, + GdkColorState *color_state, gsize width, gsize height); GskGpuImage * (* create_upload_image) (GskGpuDevice *self, gboolean with_mipmap, GdkMemoryFormat format, + GdkColorState *color_state, gsize width, gsize height); GskGpuImage * (* create_download_image) (GskGpuDevice *self, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height); void (* make_current) (GskGpuDevice *self); @@ -59,15 +63,18 @@ GskGpuImage * gsk_gpu_device_get_atlas_image (GskGpuD GskGpuImage * gsk_gpu_device_create_offscreen_image (GskGpuDevice *self, gboolean with_mipmap, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height); GskGpuImage * gsk_gpu_device_create_upload_image (GskGpuDevice *self, gboolean with_mipmap, GdkMemoryFormat format, + GdkColorState *color_state, gsize width, gsize height); GskGpuImage * gsk_gpu_device_create_download_image (GskGpuDevice *self, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height); void gsk_gpu_device_make_current (GskGpuDevice *self); diff --git a/gsk/gpu/gskgpunodeprocessor.c b/gsk/gpu/gskgpunodeprocessor.c index dce0ddf397..950f83ed6a 100644 --- a/gsk/gpu/gskgpunodeprocessor.c +++ b/gsk/gpu/gskgpunodeprocessor.c @@ -351,6 +351,7 @@ gsk_gpu_node_processor_init_draw (GskGpuNodeProcessor *self, image = gsk_gpu_device_create_offscreen_image (gsk_gpu_frame_get_device (frame), FALSE, depth, + gdk_color_state_get_srgb (), area.width, area.height); if (image == NULL) return NULL; @@ -874,6 +875,7 @@ gsk_gpu_node_processor_ensure_image (GskGpuFrame *frame, copy = gsk_gpu_device_create_offscreen_image (gsk_gpu_frame_get_device (frame), required_flags & (GSK_GPU_IMAGE_CAN_MIPMAP | GSK_GPU_IMAGE_MIPMAP) ? TRUE : FALSE, gdk_memory_format_get_depth (gsk_gpu_image_get_format (image)), + gdk_color_state_get_srgb (), width, height); if (gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_BLIT) && diff --git a/gsk/gpu/gskgpurenderer.c b/gsk/gpu/gskgpurenderer.c index 4d52693b8e..81d5866a75 100644 --- a/gsk/gpu/gskgpurenderer.c +++ b/gsk/gpu/gskgpurenderer.c @@ -261,13 +261,16 @@ gsk_gpu_renderer_fallback_render_texture (GskGpuRenderer *self, GdkTexture *texture; GdkTextureDownloader downloader; GskGpuFrame *frame; + GdkColorState *color_state; max_size = gsk_gpu_device_get_max_image_size (priv->device); depth = gsk_render_node_get_preferred_depth (root); + color_state = gdk_color_state_get_srgb (); /* FIXME */ do { image = gsk_gpu_device_create_download_image (priv->device, gsk_render_node_get_preferred_depth (root), + color_state, MIN (max_size, rounded_viewport->size.width), MIN (max_size, rounded_viewport->size.height)); max_size /= 2; @@ -292,6 +295,7 @@ gsk_gpu_renderer_fallback_render_texture (GskGpuRenderer *self, if (image == NULL) image = gsk_gpu_device_create_download_image (priv->device, depth, + color_state, MIN (image_width, width - x), MIN (image_height, height - y)); @@ -338,17 +342,20 @@ gsk_gpu_renderer_render_texture (GskRenderer *renderer, GskGpuImage *image; GdkTexture *texture; graphene_rect_t rounded_viewport; + GdkColorState *color_state; gsk_gpu_device_maybe_gc (priv->device); gsk_gpu_renderer_make_current (self); + color_state = gdk_color_state_get_srgb (); /* FIXME */ rounded_viewport = GRAPHENE_RECT_INIT (viewport->origin.x, viewport->origin.y, ceil (viewport->size.width), ceil (viewport->size.height)); image = gsk_gpu_device_create_download_image (priv->device, gsk_render_node_get_preferred_depth (root), + color_state, rounded_viewport.size.width, rounded_viewport.size.height); diff --git a/gsk/gpu/gskgpuuploadop.c b/gsk/gpu/gskgpuuploadop.c index 53535ed490..d25cbb19ca 100644 --- a/gsk/gpu/gskgpuuploadop.c +++ b/gsk/gpu/gskgpuuploadop.c @@ -304,6 +304,7 @@ gsk_gpu_upload_texture_op_try (GskGpuFrame *frame, image = gsk_gpu_device_create_upload_image (gsk_gpu_frame_get_device (frame), with_mipmap, gdk_texture_get_format (texture), + gdk_texture_get_color_state (texture), gdk_texture_get_width (texture), gdk_texture_get_height (texture)); if (image == NULL) @@ -470,6 +471,7 @@ gsk_gpu_upload_cairo_op (GskGpuFrame *frame, self->image = gsk_gpu_device_create_upload_image (gsk_gpu_frame_get_device (frame), FALSE, GDK_MEMORY_DEFAULT, + gdk_color_state_get_srgb (), ceil (graphene_vec2_get_x (scale) * viewport->size.width), ceil (graphene_vec2_get_y (scale) * viewport->size.height)); self->viewport = *viewport; diff --git a/gsk/gpu/gskvulkandevice.c b/gsk/gpu/gskvulkandevice.c index ddaba0e767..dfcbad7a7c 100644 --- a/gsk/gpu/gskvulkandevice.c +++ b/gsk/gpu/gskvulkandevice.c @@ -363,6 +363,7 @@ static GskGpuImage * gsk_vulkan_device_create_offscreen_image (GskGpuDevice *device, gboolean with_mipmap, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height) { @@ -371,20 +372,21 @@ gsk_vulkan_device_create_offscreen_image (GskGpuDevice *device, return gsk_vulkan_image_new_for_offscreen (self, with_mipmap, gdk_memory_depth_get_format (depth), - gdk_color_state_get_srgb (), + color_state, width, height); } static GskGpuImage * -gsk_vulkan_device_create_atlas_image (GskGpuDevice *device, - gsize width, - gsize height) +gsk_vulkan_device_create_atlas_image (GskGpuDevice *device, + GdkColorState *color_state, + gsize width, + gsize height) { GskVulkanDevice *self = GSK_VULKAN_DEVICE (device); return gsk_vulkan_image_new_for_atlas (self, - gdk_color_state_get_srgb (), + color_state, width, height); } @@ -393,6 +395,7 @@ static GskGpuImage * gsk_vulkan_device_create_upload_image (GskGpuDevice *device, gboolean with_mipmap, GdkMemoryFormat format, + GdkColorState *color_state, gsize width, gsize height) { @@ -401,7 +404,7 @@ gsk_vulkan_device_create_upload_image (GskGpuDevice *device, return gsk_vulkan_image_new_for_upload (self, with_mipmap, format, - gdk_color_state_get_srgb (), + color_state, width, height); } @@ -409,6 +412,7 @@ gsk_vulkan_device_create_upload_image (GskGpuDevice *device, static GskGpuImage * gsk_vulkan_device_create_download_image (GskGpuDevice *device, GdkMemoryDepth depth, + GdkColorState *color_state, gsize width, gsize height) { @@ -418,7 +422,7 @@ gsk_vulkan_device_create_download_image (GskGpuDevice *device, #ifdef HAVE_DMABUF image = gsk_vulkan_image_new_dmabuf (self, gdk_memory_depth_get_format (depth), - gdk_color_state_get_srgb (), + color_state, width, height); if (image != NULL) @@ -428,7 +432,7 @@ gsk_vulkan_device_create_download_image (GskGpuDevice *device, image = gsk_vulkan_image_new_for_offscreen (self, FALSE, gdk_memory_depth_get_format (depth), - gdk_color_state_get_srgb (), + color_state, width, height);