[gtk/matthiasc/color-profile-rebased: 843/875] gdk: Take a color space in gdk_texture_download_surface
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profile-rebased: 843/875] gdk: Take a color space in gdk_texture_download_surface
- Date: Wed, 28 Sep 2022 18:51:54 +0000 (UTC)
commit 1bfb80e35423992bb69cae088225dee2b6f1e85e
Author: Benjamin Otte <otte redhat com>
Date: Sun Sep 26 01:04:15 2021 +0200
gdk: Take a color space in gdk_texture_download_surface
This way, the resulting surface can contain the pixels
in the desired color space.
gdk/gdktexture.c | 35 +++++++++++++++++++++++++++++------
gdk/gdktextureprivate.h | 3 ++-
gdk/win32/gdkcairocontext-win32.c | 2 +-
gdk/x11/gdksurface-x11.c | 2 +-
gsk/broadway/gskbroadwayrenderer.c | 2 +-
gsk/gl/gskgliconlibrary.c | 2 +-
gsk/gskrendernodeimpl.c | 2 +-
gsk/gskrendernodeparser.c | 2 +-
gsk/vulkan/gskvulkanrenderer.c | 2 +-
9 files changed, 38 insertions(+), 14 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 42fd71641d..ca64cda61b 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -42,6 +42,7 @@
#include <glib/gi18n-lib.h>
#include "gdkcolorspace.h"
#include "gdkcairo.h"
+#include "gdkmemoryformatprivate.h"
#include "gdkmemorytextureprivate.h"
#include "gdkpaintable.h"
#include "gdksnapshot.h"
@@ -720,23 +721,45 @@ gdk_texture_do_download (GdkTexture *texture,
GDK_TEXTURE_GET_CLASS (texture)->download (texture, format, color_space, data, stride);
}
+/*<private>
+ * gdk_texture_download_surface:
+ * @texture: the texture to download
+ * @color_space: (nullable): The target color space or %NULL for the default sRGB
+ *
+ * Downloads the texture into a newly created Cairo surface.
+ *
+ * Returns: A new Cairo surface.
+ **/
cairo_surface_t *
-gdk_texture_download_surface (GdkTexture *texture)
+gdk_texture_download_surface (GdkTexture *texture,
+ GdkColorSpace *color_space)
{
cairo_surface_t *surface;
cairo_status_t surface_status;
+
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
texture->width, texture->height);
+ if (color_space != NULL)
+ gdk_cairo_surface_set_color_space (surface, color_space);
+ else
+ color_space = gdk_color_space_get_srgb ();
surface_status = cairo_surface_status (surface);
if (surface_status != CAIRO_STATUS_SUCCESS)
- g_warning ("%s: surface error: %s", __FUNCTION__,
- cairo_status_to_string (surface_status));
+ {
+ g_warning ("%s: surface error: %s", __FUNCTION__,
+ cairo_status_to_string (surface_status));
+ }
+ else
+ {
+ gdk_texture_do_download (texture,
+ GDK_MEMORY_DEFAULT,
+ color_space,
+ cairo_image_surface_get_data (surface),
+ cairo_image_surface_get_stride (surface));
+ }
- gdk_texture_download (texture,
- cairo_image_surface_get_data (surface),
- cairo_image_surface_get_stride (surface));
cairo_surface_mark_dirty (surface);
return surface;
diff --git a/gdk/gdktextureprivate.h b/gdk/gdktextureprivate.h
index 9d852ab2c7..26e027b440 100644
--- a/gdk/gdktextureprivate.h
+++ b/gdk/gdktextureprivate.h
@@ -39,7 +39,8 @@ struct _GdkTextureClass {
gboolean gdk_texture_can_load (GBytes *bytes);
GdkTexture * gdk_texture_new_for_surface (cairo_surface_t *surface);
-cairo_surface_t * gdk_texture_download_surface (GdkTexture *texture);
+cairo_surface_t * gdk_texture_download_surface (GdkTexture *texture,
+ GdkColorSpace *color_space);
void gdk_texture_do_download (GdkTexture *texture,
GdkMemoryFormat format,
diff --git a/gdk/win32/gdkcairocontext-win32.c b/gdk/win32/gdkcairocontext-win32.c
index 0ae273700b..e17fc194e8 100644
--- a/gdk/win32/gdkcairocontext-win32.c
+++ b/gdk/win32/gdkcairocontext-win32.c
@@ -47,7 +47,7 @@ create_cairo_surface_for_surface (GdkSurface *surface,
cairo_surface = cairo_win32_surface_create_with_format (hdc, CAIRO_FORMAT_ARGB32);
cairo_surface_set_device_scale (cairo_surface, scale, scale);
- gdk_cairo_surface_set_color_profile (cairo_surface, gdk_surface_get_color_profile (surface));
+ gdk_cairo_surface_set_color_space (cairo_surface, gdk_surface_get_color_space (surface));
return cairo_surface;
}
diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c
index 86c84d3fd4..d7a4f4ae64 100644
--- a/gdk/x11/gdksurface-x11.c
+++ b/gdk/x11/gdksurface-x11.c
@@ -3185,7 +3185,7 @@ gdk_surface_update_icon (GdkSurface *surface,
toplevel->icon_pixmap = gdk_x11_surface_create_pixmap_surface (surface, width, height);
- cairo_surface = gdk_texture_download_surface (best_icon);
+ cairo_surface = gdk_texture_download_surface (best_icon, NULL);
cr = cairo_create (toplevel->icon_pixmap);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
diff --git a/gsk/broadway/gskbroadwayrenderer.c b/gsk/broadway/gskbroadwayrenderer.c
index 5ac62e7ee0..92e6f8260a 100644
--- a/gsk/broadway/gskbroadwayrenderer.c
+++ b/gsk/broadway/gskbroadwayrenderer.c
@@ -449,7 +449,7 @@ get_colorized_texture (GdkTexture *texture,
const graphene_matrix_t *color_matrix,
const graphene_vec4_t *color_offset)
{
- cairo_surface_t *surface = gdk_texture_download_surface (texture);
+ cairo_surface_t *surface = gdk_texture_download_surface (texture, NULL);
cairo_surface_t *image_surface;
graphene_vec4_t pixel;
guint32* pixel_data;
diff --git a/gsk/gl/gskgliconlibrary.c b/gsk/gl/gskgliconlibrary.c
index 4d7d50734f..b4d1b1b975 100644
--- a/gsk/gl/gskgliconlibrary.c
+++ b/gsk/gl/gskgliconlibrary.c
@@ -106,7 +106,7 @@ gsk_gl_icon_library_add (GskGLIconLibrary *self,
icon_data->source_texture = g_object_ref (key);
/* actually upload the texture */
- surface = gdk_texture_download_surface (key);
+ surface = gdk_texture_download_surface (key, NULL);
surface_data = cairo_image_surface_get_data (surface);
gdk_gl_context_push_debug_group_printf (gdk_gl_context_get_current (),
"Uploading texture");
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 36505cd24e..99ae7493b8 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -1493,7 +1493,7 @@ gsk_texture_node_draw (GskRenderNode *node,
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
- surface = gdk_texture_download_surface (self->texture);
+ surface = gdk_texture_download_surface (self->texture, gdk_cairo_get_color_space (cr));
pattern = cairo_pattern_create_for_surface (surface);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
index 25943ec305..2adc8cd39e 100644
--- a/gsk/gskrendernodeparser.c
+++ b/gsk/gskrendernodeparser.c
@@ -1416,7 +1416,7 @@ parse_cairo_node (GtkCssParser *parser)
else if (pixels != NULL)
{
cairo_t *cr = gsk_cairo_node_get_draw_context (node);
- surface = gdk_texture_download_surface (pixels);
+ surface = gdk_texture_download_surface (pixels, gdk_texture_get_color_space (pixels));
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);
diff --git a/gsk/vulkan/gskvulkanrenderer.c b/gsk/vulkan/gskvulkanrenderer.c
index 86f7984805..1a40c0dad8 100644
--- a/gsk/vulkan/gskvulkanrenderer.c
+++ b/gsk/vulkan/gskvulkanrenderer.c
@@ -342,7 +342,7 @@ gsk_vulkan_renderer_ref_texture_image (GskVulkanRenderer *self,
if (data)
return g_object_ref (data->image);
- surface = gdk_texture_download_surface (texture);
+ surface = gdk_texture_download_surface (texture,NULL);
image = gsk_vulkan_image_new_from_data (uploader,
cairo_image_surface_get_data (surface),
cairo_image_surface_get_width (surface),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]