gtk/gsk/gpu/gskgpucolorstatesprivate.h
Matthias Clasen e415ec9ca5 gsk: Use the cicp convert shader
When we the image color state is not a default one, use the cicp
convert op to convert it to the ccs. And when the target color
state is a non-default one, use the shader in the reverse direction.
2024-07-24 08:16:08 -06:00

76 lines
2.9 KiB
C

#pragma once
#include "gskgputypesprivate.h"
#include "gdk/gdkcolorstateprivate.h"
#define COLOR_SPACE_OUTPUT_PREMULTIPLIED (1u << 2)
#define COLOR_SPACE_ALT_PREMULTIPLIED (1u << 3)
#define COLOR_SPACE_OUTPUT_SHIFT 8u
#define COLOR_SPACE_ALT_SHIFT 16u
#define COLOR_SPACE_COLOR_STATE_MASK 0xFFu
static inline GskGpuColorStates
gsk_gpu_color_states_create_equal (gboolean output_is_premultiplied,
gboolean alt_is_premultiplied)
{
/* We use ID 0 here for the colorspaces - if that ever becomes an issue
* that it maps to SRGB, we need to invent something */
return (output_is_premultiplied ? COLOR_SPACE_OUTPUT_PREMULTIPLIED : 0) |
(alt_is_premultiplied ? COLOR_SPACE_ALT_PREMULTIPLIED : 0);
}
static inline GskGpuColorStates
gsk_gpu_color_states_create (GdkColorState *output_color_state,
gboolean output_is_premultiplied,
GdkColorState *alt_color_state,
gboolean alt_is_premultiplied)
{
g_assert (GDK_IS_DEFAULT_COLOR_STATE (output_color_state));
g_assert (GDK_IS_DEFAULT_COLOR_STATE (alt_color_state));
if (gdk_color_state_equal (output_color_state, alt_color_state))
return gsk_gpu_color_states_create_equal (output_is_premultiplied, alt_is_premultiplied);
return (GDK_DEFAULT_COLOR_STATE_ID (output_color_state) << COLOR_SPACE_OUTPUT_SHIFT) |
(output_is_premultiplied ? COLOR_SPACE_OUTPUT_PREMULTIPLIED : 0) |
(GDK_DEFAULT_COLOR_STATE_ID (alt_color_state) << COLOR_SPACE_ALT_SHIFT) |
(alt_is_premultiplied ? COLOR_SPACE_ALT_PREMULTIPLIED : 0);
}
static inline GskGpuColorStates
gsk_gpu_color_states_create_cicp (GdkColorState *output_color_state,
gboolean output_is_premultiplied,
gboolean cicp_is_premultiplied)
{
return (GDK_DEFAULT_COLOR_STATE_ID (output_color_state) << COLOR_SPACE_OUTPUT_SHIFT) |
(output_is_premultiplied ? COLOR_SPACE_OUTPUT_PREMULTIPLIED : 0) |
(GDK_DEFAULT_COLOR_STATE_ID (output_color_state) << COLOR_SPACE_ALT_SHIFT) |
(cicp_is_premultiplied ? COLOR_SPACE_ALT_PREMULTIPLIED : 0);
}
static inline GdkColorState *
gsk_gpu_color_states_get_output (GskGpuColorStates self)
{
return ((GdkColorState *) &gdk_default_color_states[(self >> COLOR_SPACE_OUTPUT_SHIFT) & COLOR_SPACE_COLOR_STATE_MASK]);
}
static inline gboolean
gsk_gpu_color_states_is_output_premultiplied (GskGpuColorStates self)
{
return !!(self & COLOR_SPACE_OUTPUT_PREMULTIPLIED);
}
static inline GdkColorState *
gsk_gpu_color_states_get_alt (GskGpuColorStates self)
{
return ((GdkColorState *) &gdk_default_color_states[(self >> COLOR_SPACE_ALT_SHIFT) & COLOR_SPACE_COLOR_STATE_MASK]);
}
static inline gboolean
gsk_gpu_color_states_is_alt_premultiplied (GskGpuColorStates self)
{
return !!(self & COLOR_SPACE_ALT_PREMULTIPLIED);
}