[gtk/wip/otte/color-profiles: 18/18] FIXME: Add crude color management impl for cairo
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/color-profiles: 18/18] FIXME: Add crude color management impl for cairo
- Date: Sun, 26 Sep 2021 00:47:40 +0000 (UTC)
commit e284a34da103013b26fe0c31575a4d80dc558bb1
Author: Benjamin Otte <otte redhat com>
Date: Sun Sep 26 02:44:54 2021 +0200
FIXME: Add crude color management impl for cairo
It runs at 2fps here, but it runs.
gsk/gskcairorenderer.c | 43 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/gsk/gskcairorenderer.c b/gsk/gskcairorenderer.c
index 074b54b97f..34625c66a8 100644
--- a/gsk/gskcairorenderer.c
+++ b/gsk/gskcairorenderer.c
@@ -25,6 +25,8 @@
#include "gskdebugprivate.h"
#include "gskrendererprivate.h"
#include "gskrendernodeprivate.h"
+
+#include "gdk/gdkcolorprofileprivate.h"
#include "gdk/gdktextureprivate.h"
#ifdef G_ENABLE_DEBUG
@@ -40,6 +42,7 @@ struct _GskCairoRenderer
GdkCairoContext *cairo_context;
+ gboolean color_managed;
#ifdef G_ENABLE_DEBUG
ProfileTimers profile_timers;
#endif
@@ -77,8 +80,8 @@ gsk_cairo_renderer_do_render (GskRenderer *renderer,
cairo_t *cr,
GskRenderNode *root)
{
-#ifdef G_ENABLE_DEBUG
GskCairoRenderer *self = GSK_CAIRO_RENDERER (renderer);
+#ifdef G_ENABLE_DEBUG
GskProfiler *profiler;
gint64 cpu_time;
#endif
@@ -88,7 +91,41 @@ gsk_cairo_renderer_do_render (GskRenderer *renderer,
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
#endif
- gsk_render_node_draw (root, cr);
+ if (!self->color_managed ||
+ gdk_color_profile_is_linear (gdk_cairo_get_color_profile (cr)))
+ {
+ gsk_render_node_draw (root, cr);
+ }
+ else
+ {
+ GdkSurface *surface = gsk_renderer_get_surface (renderer);
+ cairo_surface_t *cairo_surface;
+ cairo_t *cr2;
+ GdkTexture *color_correct;
+
+ /* We can't use cairo_push_group() here, because we'd lose the
+ * color profile information. */
+ cairo_surface = gdk_surface_create_similar_surface (surface,
+ CAIRO_CONTENT_COLOR_ALPHA,
+ gdk_surface_get_width (surface),
+ gdk_surface_get_height (surface));
+ gdk_cairo_surface_set_color_profile (cairo_surface,
+ gdk_color_profile_get_srgb_linear ());
+
+ cr2 = cairo_create (cairo_surface);
+ gsk_render_node_draw (root, cr2);
+ cairo_destroy (cr2);
+
+ color_correct = gdk_texture_new_for_surface (cairo_surface);
+ cairo_surface_destroy (cairo_surface);
+ cairo_surface = gdk_texture_download_surface (color_correct,
+ gdk_cairo_get_color_profile (cr));
+ g_object_unref (color_correct);
+
+ cairo_set_source_surface (cr, cairo_surface, 0, 0);
+ cairo_paint (cr);
+ cairo_surface_destroy (cairo_surface);
+ }
#ifdef G_ENABLE_DEBUG
cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
@@ -173,6 +210,8 @@ gsk_cairo_renderer_class_init (GskCairoRendererClass *klass)
static void
gsk_cairo_renderer_init (GskCairoRenderer *self)
{
+ self->color_managed = TRUE;
+
#ifdef G_ENABLE_DEBUG
GskProfiler *profiler = gsk_renderer_get_profiler (GSK_RENDERER (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]