gskglrenderer: First class support of repeating-linear-gradient

This commit is contained in:
Fabio Lagalla 2021-01-26 12:46:22 +01:00
parent b15902bf44
commit 976a05f6eb
5 changed files with 15 additions and 1 deletions

View File

@ -1452,6 +1452,7 @@ render_linear_gradient_node (GskGLRenderer *self,
ops_set_linear_gradient (builder, ops_set_linear_gradient (builder,
n_color_stops, n_color_stops,
stops, stops,
gsk_render_node_get_node_type (node) == GSK_REPEATING_LINEAR_GRADIENT_NODE,
builder->dx + start->x, builder->dx + start->x,
builder->dy + start->y, builder->dy + start->y,
builder->dx + end->x, builder->dx + end->x,
@ -3044,6 +3045,7 @@ apply_linear_gradient_op (const Program *program,
glUniform4f (program->linear_gradient.points_location, glUniform4f (program->linear_gradient.points_location,
op->start_point[0], op->start_point[1], op->start_point[0], op->start_point[1],
op->end_point[0] - op->start_point[0], op->end_point[1] - op->start_point[1]); op->end_point[0] - op->start_point[0], op->end_point[1] - op->start_point[1]);
glUniform1i (program->linear_gradient.repeat_location, op->repeat);
} }
static inline void static inline void
@ -3385,6 +3387,7 @@ gsk_gl_renderer_create_programs (GskGLRenderer *self,
/* linear gradient */ /* linear gradient */
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, color_stops); INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, color_stops);
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, num_color_stops); INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, num_color_stops);
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, repeat);
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, points); INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, points);
/* radial gradient */ /* radial gradient */
@ -3742,6 +3745,8 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
break; break;
case GSK_LINEAR_GRADIENT_NODE: case GSK_LINEAR_GRADIENT_NODE:
/* Intentional fall-through */
case GSK_REPEATING_LINEAR_GRADIENT_NODE:
render_linear_gradient_node (self, node, builder); render_linear_gradient_node (self, node, builder);
break; break;
@ -3812,7 +3817,6 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
render_gl_shader_node (self, node, builder); render_gl_shader_node (self, node, builder);
break; break;
case GSK_REPEATING_LINEAR_GRADIENT_NODE:
case GSK_REPEATING_RADIAL_GRADIENT_NODE: case GSK_REPEATING_RADIAL_GRADIENT_NODE:
case GSK_CAIRO_NODE: case GSK_CAIRO_NODE:
default: default:

View File

@ -859,6 +859,7 @@ void
ops_set_linear_gradient (RenderOpBuilder *self, ops_set_linear_gradient (RenderOpBuilder *self,
guint n_color_stops, guint n_color_stops,
const GskColorStop *color_stops, const GskColorStop *color_stops,
bool repeat,
float start_x, float start_x,
float start_y, float start_y,
float end_x, float end_x,
@ -912,6 +913,7 @@ ops_set_linear_gradient (RenderOpBuilder *self,
sizeof (GskColorStop) * real_n_color_stops); sizeof (GskColorStop) * real_n_color_stops);
} }
op->repeat = repeat;
op->start_point[0] = start_x; op->start_point[0] = start_x;
op->start_point[1] = start_y; op->start_point[1] = start_y;
op->end_point[0] = end_x; op->end_point[0] = end_x;

View File

@ -119,6 +119,7 @@ struct _Program
int num_color_stops_location; int num_color_stops_location;
int color_stops_location; int color_stops_location;
int points_location; int points_location;
int repeat_location;
} linear_gradient; } linear_gradient;
struct { struct {
int num_color_stops_location; int num_color_stops_location;
@ -315,6 +316,7 @@ void ops_set_unblurred_outset_shadow (RenderOpBuilder *se
void ops_set_linear_gradient (RenderOpBuilder *self, void ops_set_linear_gradient (RenderOpBuilder *self,
guint n_color_stops, guint n_color_stops,
const GskColorStop *color_stops, const GskColorStop *color_stops,
bool repeat,
float start_x, float start_x,
float start_y, float start_y,
float end_x, float end_x,

View File

@ -146,6 +146,7 @@ typedef struct
IntUniformValue n_color_stops; IntUniformValue n_color_stops;
float start_point[2]; float start_point[2];
float end_point[2]; float end_point[2];
bool repeat;
} OpLinearGradient; } OpLinearGradient;
typedef struct typedef struct

View File

@ -46,6 +46,7 @@ uniform highp int u_num_color_stops; // Why? Because it works like this.
#endif #endif
uniform float u_color_stops[6 * 5]; uniform float u_color_stops[6 * 5];
uniform bool u_repeat;
_NOPERSPECTIVE_ _IN_ vec4 info; _NOPERSPECTIVE_ _IN_ vec4 info;
@ -65,6 +66,10 @@ vec4 get_color(int index) {
void main() { void main() {
float offset = dot(info.xy, info.zw); float offset = dot(info.xy, info.zw);
if (u_repeat) {
offset = fract(offset);
}
if (offset < get_offset(0)) { if (offset < get_offset(0)) {
gskSetOutputColor(gsk_scaled_premultiply(get_color(0), u_alpha)); gskSetOutputColor(gsk_scaled_premultiply(get_color(0), u_alpha));
return; return;