2023-12-25 04:02:51 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskgpulineargradientopprivate.h"
|
|
|
|
|
|
|
|
#include "gskgpuframeprivate.h"
|
|
|
|
#include "gskgpuprintprivate.h"
|
|
|
|
#include "gskrectprivate.h"
|
|
|
|
|
|
|
|
#include "gpu/shaders/gskgpulineargradientinstance.h"
|
|
|
|
|
2023-12-31 17:38:43 +00:00
|
|
|
#define VARIATION_SUPERSAMPLING (1 << 0)
|
|
|
|
#define VARIATION_REPEATING (1 << 1)
|
2023-12-31 05:08:37 +00:00
|
|
|
|
2023-12-25 04:02:51 +00:00
|
|
|
typedef struct _GskGpuLinearGradientOp GskGpuLinearGradientOp;
|
|
|
|
|
|
|
|
struct _GskGpuLinearGradientOp
|
|
|
|
{
|
|
|
|
GskGpuShaderOp op;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2024-03-15 12:37:31 +00:00
|
|
|
gsk_gpu_linear_gradient_op_print_instance (GskGpuShaderOp *shader,
|
|
|
|
gpointer instance_,
|
|
|
|
GString *string)
|
2023-12-25 04:02:51 +00:00
|
|
|
{
|
2024-03-15 12:37:31 +00:00
|
|
|
GskGpuLineargradientInstance *instance = (GskGpuLineargradientInstance *) instance_;
|
2023-12-25 04:02:51 +00:00
|
|
|
|
2023-12-31 05:08:37 +00:00
|
|
|
if (shader->variation & VARIATION_REPEATING)
|
2024-03-15 12:37:31 +00:00
|
|
|
gsk_gpu_print_string (string, "repeating");
|
2023-12-25 04:02:51 +00:00
|
|
|
gsk_gpu_print_rect (string, instance->rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GskGpuShaderOpClass GSK_GPU_LINEAR_GRADIENT_OP_CLASS = {
|
|
|
|
{
|
|
|
|
GSK_GPU_OP_SIZE (GskGpuLinearGradientOp),
|
|
|
|
GSK_GPU_STAGE_SHADER,
|
|
|
|
gsk_gpu_shader_op_finish,
|
2024-03-15 12:37:31 +00:00
|
|
|
gsk_gpu_shader_op_print,
|
2023-12-25 04:02:51 +00:00
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
gsk_gpu_shader_op_vk_command,
|
|
|
|
#endif
|
|
|
|
gsk_gpu_shader_op_gl_command
|
|
|
|
},
|
|
|
|
"gskgpulineargradient",
|
2024-07-19 15:25:03 +00:00
|
|
|
gsk_gpu_lineargradient_n_textures,
|
2023-12-25 04:02:51 +00:00
|
|
|
sizeof (GskGpuLineargradientInstance),
|
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
&gsk_gpu_lineargradient_info,
|
|
|
|
#endif
|
2024-03-15 12:37:31 +00:00
|
|
|
gsk_gpu_linear_gradient_op_print_instance,
|
2024-01-04 13:52:03 +00:00
|
|
|
gsk_gpu_lineargradient_setup_attrib_locations,
|
2023-12-25 04:02:51 +00:00
|
|
|
gsk_gpu_lineargradient_setup_vao
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
|
|
|
|
GskGpuShaderClip clip,
|
2024-07-03 23:26:01 +00:00
|
|
|
GskGpuColorStates color_states,
|
gpu: Handle >7 color stops
If there are more than 7 color stops, we can split the gradient into
multiple gradients with color stops like so:
0, 1, 2, 3, 4, 5, transparent
transparent, 6, 7, 8, 9, 10, transparent
...
transparent, n-2, n-1, n
and use the new BLEND_ADD to draw them on top of each other.
Adapt the testcae that tests this to use colors that work with the fancy
algorithm we use now, so that BLEND_ADD and transitions to transparent
do not cause issues.
2023-12-25 22:58:47 +00:00
|
|
|
gboolean repeating,
|
2023-12-25 04:02:51 +00:00
|
|
|
const graphene_rect_t *rect,
|
|
|
|
const graphene_point_t *start,
|
|
|
|
const graphene_point_t *end,
|
|
|
|
const graphene_point_t *offset,
|
|
|
|
const GskColorStop *stops,
|
|
|
|
gsize n_stops)
|
|
|
|
{
|
|
|
|
GskGpuLineargradientInstance *instance;
|
2024-07-03 23:26:01 +00:00
|
|
|
GdkColorState *color_state = gsk_gpu_color_states_get_alt (color_states);
|
2023-12-25 04:02:51 +00:00
|
|
|
|
|
|
|
g_assert (n_stops > 1);
|
|
|
|
g_assert (n_stops <= 7);
|
2024-07-03 23:26:01 +00:00
|
|
|
g_assert (gsk_gpu_color_states_is_alt_premultiplied (color_states));
|
2023-12-25 04:02:51 +00:00
|
|
|
|
|
|
|
gsk_gpu_shader_op_alloc (frame,
|
|
|
|
&GSK_GPU_LINEAR_GRADIENT_OP_CLASS,
|
2024-07-03 23:26:01 +00:00
|
|
|
color_states,
|
2023-12-31 17:38:43 +00:00
|
|
|
(repeating ? VARIATION_REPEATING : 0) |
|
|
|
|
(gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_GRADIENTS) ? VARIATION_SUPERSAMPLING : 0),
|
2023-12-25 04:02:51 +00:00
|
|
|
clip,
|
|
|
|
NULL,
|
2024-07-19 16:02:06 +00:00
|
|
|
NULL,
|
2023-12-25 04:02:51 +00:00
|
|
|
&instance);
|
|
|
|
|
|
|
|
gsk_gpu_rect_to_float (rect, offset, instance->rect);
|
|
|
|
gsk_gpu_point_to_float (start, offset, instance->startend);
|
|
|
|
gsk_gpu_point_to_float (end, offset, &instance->startend[2]);
|
2024-07-03 23:26:01 +00:00
|
|
|
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 6)].color, instance->color6);
|
2023-12-25 04:02:51 +00:00
|
|
|
instance->offsets1[2] = stops[MIN (n_stops - 1, 6)].offset;
|
2024-07-03 23:26:01 +00:00
|
|
|
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 5)].color, instance->color5);
|
2023-12-25 04:02:51 +00:00
|
|
|
instance->offsets1[1] = stops[MIN (n_stops - 1, 5)].offset;
|
2024-07-03 23:26:01 +00:00
|
|
|
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 4)].color, instance->color4);
|
2023-12-25 04:02:51 +00:00
|
|
|
instance->offsets1[0] = stops[MIN (n_stops - 1, 4)].offset;
|
2024-07-03 23:26:01 +00:00
|
|
|
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 3)].color, instance->color3);
|
2023-12-25 04:02:51 +00:00
|
|
|
instance->offsets0[3] = stops[MIN (n_stops - 1, 3)].offset;
|
2024-07-03 23:26:01 +00:00
|
|
|
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 2)].color, instance->color2);
|
2023-12-25 04:02:51 +00:00
|
|
|
instance->offsets0[2] = stops[MIN (n_stops - 1, 2)].offset;
|
2024-07-03 23:26:01 +00:00
|
|
|
gdk_color_state_from_rgba (color_state, &stops[1].color, instance->color1);
|
2023-12-25 04:02:51 +00:00
|
|
|
instance->offsets0[1] = stops[1].offset;
|
2024-07-03 23:26:01 +00:00
|
|
|
gdk_color_state_from_rgba (color_state, &stops[0].color, instance->color0);
|
2023-12-25 04:02:51 +00:00
|
|
|
instance->offsets0[0] = stops[0].offset;
|
|
|
|
}
|