Files
gtk/gsk/gpu/gskgpucolorstatesprivate.h
Benjamin Otte 77ed264714 gpu: Introduce gsk_gpu_color_states_create_equal()
This is a function that's meant to be used whenever both color states
of the shader are equal. In that case no colorspace conversion code
needs to be created and shaders can be shared.
2024-07-11 14:57:20 +02:00

66 lines
2.4 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 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);
}
#define DEFAULT_COLOR_STATES (gsk_gpu_color_states_create (GDK_COLOR_STATE_SRGB, TRUE, GDK_COLOR_STATE_SRGB, TRUE))