[gtk/matthiasc/color-profile-rebased: 14/43] gdk: Take a profile in gdk_texture_download_surface
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profile-rebased: 14/43] gdk: Take a profile in gdk_texture_download_surface
- Date: Sun, 8 May 2022 19:01:16 +0000 (UTC)
commit 71eceb59469fd06a5649311bc8ad5355dd8fb1d4
Author: Benjamin Otte <otte redhat com>
Date: Sun Sep 26 01:04:15 2021 +0200
gdk: Take a profile in gdk_texture_download_surface
This way, the resulting surface can contain the pixels
in the desired color profile.
gdk/gdktexture.c | 35 +++++++++++++++++++++++++++++------
gdk/gdktextureprivate.h | 3 ++-
gdk/x11/gdksurface-x11.c | 2 +-
gsk/broadway/gskbroadwayrenderer.c | 2 +-
gsk/gl/gskgliconlibrary.c | 2 +-
gsk/gskrendernodeimpl.c | 3 ++-
gsk/gskrendernodeparser.c | 3 ++-
gsk/vulkan/gskvulkanrenderer.c | 2 +-
8 files changed, 39 insertions(+), 13 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 72b05f050f..9b4bcd05ec 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -42,6 +42,7 @@
#include "gdkcairo.h"
#include "gdkcolorprofile.h"
#include "gdkintl.h"
+#include "gdkmemoryformatprivate.h"
#include "gdkmemorytextureprivate.h"
#include "gdkpaintable.h"
#include "gdksnapshot.h"
@@ -730,23 +731,45 @@ gdk_texture_do_download (GdkTexture *texture,
GDK_TEXTURE_GET_CLASS (texture)->download (texture, format, profile, data, stride);
}
+/*<private>
+ * gdk_texture_download_surface:
+ * @texture: the texture to download
+ * @profile: (nullable): The target color profile 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,
+ GdkColorProfile *profile)
{
cairo_surface_t *surface;
cairo_status_t surface_status;
+
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
texture->width, texture->height);
+ if (profile != NULL)
+ gdk_cairo_surface_set_color_profile (surface, profile);
+ else
+ profile = gdk_color_profile_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,
+ profile,
+ 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 37bc8ed0cf..f87ca591db 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,
+ GdkColorProfile *profile);
void gdk_texture_do_download (GdkTexture *texture,
GdkMemoryFormat format,
diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c
index 8567d83eb8..2f4a2799b0 100644
--- a/gdk/x11/gdksurface-x11.c
+++ b/gdk/x11/gdksurface-x11.c
@@ -3180,7 +3180,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 ffc934de76..51e44a4384 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 175c458848..34d30795b1 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -1493,7 +1493,8 @@ 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_profile (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 11d5e61d70..c8cc38fe76 100644
--- a/gsk/gskrendernodeparser.c
+++ b/gsk/gskrendernodeparser.c
@@ -1399,7 +1399,8 @@ 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_profile (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]