gl renderer: Fall back to cairo if gradients use too many stops

This commit is contained in:
Timm Bäder 2020-09-21 21:19:19 +02:00
parent 12cc178756
commit 8d7b3bade3
3 changed files with 51 additions and 35 deletions

View File

@ -1175,21 +1175,29 @@ render_linear_gradient_node (GskGLRenderer *self,
GskRenderNode *node,
RenderOpBuilder *builder)
{
const int n_color_stops = MIN (8, gsk_linear_gradient_node_get_n_color_stops (node));
const GskColorStop *stops = gsk_linear_gradient_node_peek_color_stops (node, NULL);
const graphene_point_t *start = gsk_linear_gradient_node_peek_start (node);
const graphene_point_t *end = gsk_linear_gradient_node_peek_end (node);
const int n_color_stops = gsk_linear_gradient_node_get_n_color_stops (node);
ops_set_program (builder, &self->programs->linear_gradient_program);
ops_set_linear_gradient (builder,
n_color_stops,
stops,
builder->dx + start->x,
builder->dy + start->y,
builder->dx + end->x,
builder->dy + end->y);
if (n_color_stops < GL_MAX_GRADIENT_STOPS)
{
const GskColorStop *stops = gsk_linear_gradient_node_peek_color_stops (node, NULL);
const graphene_point_t *start = gsk_linear_gradient_node_peek_start (node);
const graphene_point_t *end = gsk_linear_gradient_node_peek_end (node);
load_vertex_data (ops_draw (builder, NULL), node, builder);
ops_set_program (builder, &self->programs->linear_gradient_program);
ops_set_linear_gradient (builder,
n_color_stops,
stops,
builder->dx + start->x,
builder->dy + start->y,
builder->dx + end->x,
builder->dy + end->y);
load_vertex_data (ops_draw (builder, NULL), node, builder);
}
else
{
render_fallback_node (self, node, builder);
}
}
static inline void
@ -1197,25 +1205,33 @@ render_radial_gradient_node (GskGLRenderer *self,
GskRenderNode *node,
RenderOpBuilder *builder)
{
const int n_color_stops = MIN (8, gsk_radial_gradient_node_get_n_color_stops (node));
const GskColorStop *stops = gsk_radial_gradient_node_peek_color_stops (node, NULL);
const graphene_point_t *center = gsk_radial_gradient_node_peek_center (node);
const float start = gsk_radial_gradient_node_get_start (node);
const float end = gsk_radial_gradient_node_get_end (node);
const float hradius = gsk_radial_gradient_node_get_hradius (node);
const float vradius = gsk_radial_gradient_node_get_vradius (node);
const int n_color_stops = gsk_radial_gradient_node_get_n_color_stops (node);
ops_set_program (builder, &self->programs->radial_gradient_program);
ops_set_radial_gradient (builder,
n_color_stops,
stops,
builder->dx + center->x,
builder->dy + center->y,
start, end,
hradius * builder->scale_x,
vradius * builder->scale_y);
if (n_color_stops < GL_MAX_GRADIENT_STOPS)
{
const GskColorStop *stops = gsk_radial_gradient_node_peek_color_stops (node, NULL);
const graphene_point_t *center = gsk_radial_gradient_node_peek_center (node);
const float start = gsk_radial_gradient_node_get_start (node);
const float end = gsk_radial_gradient_node_get_end (node);
const float hradius = gsk_radial_gradient_node_get_hradius (node);
const float vradius = gsk_radial_gradient_node_get_vradius (node);
load_vertex_data (ops_draw (builder, NULL), node, builder);
ops_set_program (builder, &self->programs->radial_gradient_program);
ops_set_radial_gradient (builder,
n_color_stops,
stops,
builder->dx + center->x,
builder->dy + center->y,
start, end,
hradius * builder->scale_x,
vradius * builder->scale_y);
load_vertex_data (ops_draw (builder, NULL), node, builder);
}
else
{
render_fallback_node (self, node, builder);
}
}
static inline gboolean

View File

@ -909,7 +909,7 @@ ops_set_linear_gradient (RenderOpBuilder *self,
{
ProgramState *current_program_state = get_current_program_state (self);
OpLinearGradient *op;
const guint real_n_color_stops = MIN (MAX_GRADIENT_STOPS, n_color_stops);
const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
g_assert (current_program_state);
@ -972,7 +972,7 @@ ops_set_radial_gradient (RenderOpBuilder *self,
float hradius,
float vradius)
{
const guint real_n_color_stops = MIN (MAX_GRADIENT_STOPS, n_color_stops);
const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
OpRadialGradient *op;
/* TODO: State tracking? */

View File

@ -14,7 +14,7 @@
#define GL_N_VERTICES 6
#define GL_N_PROGRAMS 14
#define MAX_GRADIENT_STOPS 8
#define GL_MAX_GRADIENT_STOPS 8
typedef struct
{
@ -147,13 +147,13 @@ typedef struct
} unblurred_outset_shadow;
struct {
int n_color_stops;
GskColorStop color_stops[MAX_GRADIENT_STOPS];
GskColorStop color_stops[GL_MAX_GRADIENT_STOPS];
float start_point[2];
float end_point[2];
} linear_gradient;
struct {
int n_color_stops;
GskColorStop color_stops[MAX_GRADIENT_STOPS];
GskColorStop color_stops[GL_MAX_GRADIENT_STOPS];
float center[2];
float start;
float end;