gskrendernode: Cache angle in conic gradients

This commit is contained in:
Fabio Lagalla 2021-01-26 16:15:12 +01:00
parent 1b698c896e
commit 0088f840fe
6 changed files with 36 additions and 14 deletions

View File

@ -1512,7 +1512,7 @@ render_conic_gradient_node (GskGLRenderer *self,
{
const GskColorStop *stops = gsk_conic_gradient_node_get_color_stops (node, NULL);
const graphene_point_t *center = gsk_conic_gradient_node_get_center (node);
const float rotation = gsk_conic_gradient_node_get_rotation (node);
const float angle = gsk_conic_gradient_node_get_angle (node);
ops_set_program (builder, &self->programs->conic_gradient_program);
ops_set_conic_gradient (builder,
@ -1520,7 +1520,7 @@ render_conic_gradient_node (GskGLRenderer *self,
stops,
builder->dx + center->x,
builder->dy + center->y,
rotation);
angle);
load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
}
@ -3079,7 +3079,6 @@ static inline void
apply_conic_gradient_op (const Program *program,
const OpConicGradient *op)
{
float angle;
float bias;
float scale;
@ -3092,14 +3091,8 @@ apply_conic_gradient_op (const Program *program,
op->n_color_stops.value * 5,
(float *)op->color_stops.value);
angle = 90.0f - op->rotation;
angle = M_PI * angle / 180.0f;
angle = fmodf (angle, 2.0f * M_PI);
if (angle < 0.0f)
angle += 2.0f * M_PI;
scale = 0.5f * M_1_PI;
bias = angle * scale + 2.0f;
bias = op->angle * scale + 2.0f;
glUniform4f (program->conic_gradient.geometry_location, op->center[0], op->center[1], scale, bias);
}

View File

@ -957,7 +957,7 @@ ops_set_conic_gradient (RenderOpBuilder *self,
const GskColorStop *color_stops,
float center_x,
float center_y,
float rotation)
float angle)
{
const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
OpConicGradient *op;
@ -971,6 +971,6 @@ ops_set_conic_gradient (RenderOpBuilder *self,
op->color_stops.send = true;
op->center[0] = center_x;
op->center[1] = center_y;
op->rotation = rotation;
op->angle = angle;
}

View File

@ -337,7 +337,7 @@ void ops_set_conic_gradient (RenderOpBuilder *self,
const GskColorStop *color_stops,
float center_x,
float center_y,
float rotation);
float angle);
GskQuadVertex * ops_draw (RenderOpBuilder *builder,
const GskQuadVertex vertex_data[GL_N_VERTICES]);

View File

@ -165,7 +165,7 @@ typedef struct
ColorStopUniformValue color_stops;
IntUniformValue n_color_stops;
float center[2];
float rotation;
float angle;
} OpConicGradient;
typedef struct

View File

@ -257,6 +257,8 @@ const graphene_point_t * gsk_conic_gradient_node_get_center (GskRenderNo
GDK_AVAILABLE_IN_ALL
float gsk_conic_gradient_node_get_rotation (GskRenderNode *node);
GDK_AVAILABLE_IN_ALL
float gsk_conic_gradient_node_get_angle (GskRenderNode *node);
GDK_AVAILABLE_IN_ALL
gsize gsk_conic_gradient_node_get_n_color_stops (GskRenderNode *node);
GDK_AVAILABLE_IN_ALL
const GskColorStop * gsk_conic_gradient_node_get_color_stops (GskRenderNode *node,

View File

@ -782,6 +782,7 @@ struct _GskConicGradientNode
graphene_point_t center;
float rotation;
float angle;
gsize n_stops;
GskColorStop *stops;
@ -1023,6 +1024,12 @@ gsk_conic_gradient_node_new (const graphene_rect_t *bounds,
self->stops = g_malloc_n (n_color_stops, sizeof (GskColorStop));
memcpy (self->stops, color_stops, n_color_stops * sizeof (GskColorStop));
self->angle = 90.f - self->rotation;
self->angle = G_PI * self->angle / 180.f;
self->angle = fmodf (self->angle, 2.f * G_PI);
if (self->angle < 0.f)
self->angle += 2.f * G_PI;
return node;
}
@ -1095,6 +1102,26 @@ gsk_conic_gradient_node_get_rotation (GskRenderNode *node)
return self->rotation;
}
/**
* gsk_conic_gradient_node_get_angle:
* @node: (type GskConicGradientNode): a #GskRenderNode for a conic gradient
*
* Retrieves the angle for the gradient in radians, normalized in [0, 2 * PI]
*
* The angle is starting at the top and going clockwise, as expressed
* in the css specification:
* angle = 90 - gsk_conic_gradient_node_get_rotation()
*
* Returns: the angle for the gradient
*/
float
gsk_conic_gradient_node_get_angle (GskRenderNode *node)
{
GskConicGradientNode *self = (GskConicGradientNode *) node;
return self->angle;
}
/*** GSK_BORDER_NODE ***/
/**