gpu: Implement conic gradients
This commit is contained in:
@@ -819,6 +819,26 @@ gsk_gpu_node_processor_create_radial_gradient_pattern (GskGpuNodeProcessor *self
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gsk_gpu_node_processor_create_conic_gradient_pattern (GskGpuNodeProcessor *self,
|
||||
GskGpuBufferWriter *writer,
|
||||
GskRenderNode *node,
|
||||
GskGpuShaderImage *images,
|
||||
gsize n_images,
|
||||
gsize *out_n_images)
|
||||
{
|
||||
gsk_gpu_buffer_writer_append_uint (writer, GSK_GPU_PATTERN_CONIC_GRADIENT);
|
||||
gsk_gpu_buffer_writer_append_point (writer,
|
||||
gsk_conic_gradient_node_get_center (node),
|
||||
&self->offset);
|
||||
gsk_gpu_buffer_writer_append_float (writer, gsk_conic_gradient_node_get_angle (node));
|
||||
gsk_gpu_buffer_writer_append_color_stops (writer,
|
||||
gsk_conic_gradient_node_get_color_stops (node, NULL),
|
||||
gsk_conic_gradient_node_get_n_color_stops (node));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gsk_gpu_node_processor_create_glyph_pattern (GskGpuNodeProcessor *self,
|
||||
GskGpuBufferWriter *writer,
|
||||
@@ -1017,8 +1037,8 @@ static const struct
|
||||
},
|
||||
[GSK_CONIC_GRADIENT_NODE] = {
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
gsk_gpu_node_processor_add_node_as_pattern,
|
||||
gsk_gpu_node_processor_create_conic_gradient_pattern,
|
||||
},
|
||||
[GSK_BORDER_NODE] = {
|
||||
0,
|
||||
|
||||
@@ -38,5 +38,6 @@ typedef enum {
|
||||
GSK_GPU_PATTERN_REPEATING_LINEAR_GRADIENT,
|
||||
GSK_GPU_PATTERN_RADIAL_GRADIENT,
|
||||
GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT,
|
||||
GSK_GPU_PATTERN_CONIC_GRADIENT,
|
||||
} GskGpuPatternType;
|
||||
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
#define GSK_GPU_PATTERN_REPEATING_LINEAR_GRADIENT 7u
|
||||
#define GSK_GPU_PATTERN_RADIAL_GRADIENT 8u
|
||||
#define GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT 9u
|
||||
#define GSK_GPU_PATTERN_CONIC_GRADIENT 10u
|
||||
|
||||
#endif
|
||||
|
||||
@@ -165,6 +165,23 @@ radial_gradient_pattern (inout uint reader,
|
||||
return gradient_get_color (gradient, offset - d_offset, offset + d_offset);
|
||||
}
|
||||
|
||||
vec4
|
||||
conic_gradient_pattern (inout uint reader,
|
||||
vec2 pos)
|
||||
{
|
||||
vec2 center = read_vec2 (reader);
|
||||
float angle = read_float (reader);
|
||||
Gradient gradient = read_gradient (reader);
|
||||
|
||||
/* scaling modifies angles, so be sure to use right coordinate system */
|
||||
pos = pos / push.scale - center;
|
||||
float offset = atan (pos.y, pos.x);
|
||||
offset = fract (degrees (offset + angle) / 360.0);
|
||||
float d_offset = 0.5 * fwidth (offset);
|
||||
|
||||
return gradient_get_color (gradient, offset - d_offset, offset + d_offset);
|
||||
}
|
||||
|
||||
vec4
|
||||
color_pattern (inout uint reader)
|
||||
{
|
||||
@@ -214,6 +231,9 @@ pattern (uint reader,
|
||||
case GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT:
|
||||
color = radial_gradient_pattern (reader, pos, true);
|
||||
break;
|
||||
case GSK_GPU_PATTERN_CONIC_GRADIENT:
|
||||
color = conic_gradient_pattern (reader, pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user