2017-11-22 20:02:50 +00:00
|
|
|
#include "gskglrenderopsprivate.h"
|
2019-06-02 07:55:11 +00:00
|
|
|
#include "gsktransform.h"
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2020-07-24 16:30:36 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GskRoundedRect rect;
|
|
|
|
bool is_rectilinear;
|
|
|
|
} ClipStackEntry;
|
|
|
|
|
2018-12-05 09:36:43 +00:00
|
|
|
static inline gboolean
|
|
|
|
rect_equal (const graphene_rect_t *a,
|
|
|
|
const graphene_rect_t *b)
|
|
|
|
{
|
|
|
|
return memcmp (a, b, sizeof (graphene_rect_t)) == 0;
|
|
|
|
}
|
|
|
|
|
2020-01-24 12:17:09 +00:00
|
|
|
static inline gboolean G_GNUC_PURE
|
2019-12-14 14:43:12 +00:00
|
|
|
rounded_rect_equal (const GskRoundedRect *r1,
|
|
|
|
const GskRoundedRect *r2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!r1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (r1->bounds.origin.x != r2->bounds.origin.x ||
|
|
|
|
r1->bounds.origin.y != r2->bounds.origin.y ||
|
|
|
|
r1->bounds.size.width != r2->bounds.size.width ||
|
|
|
|
r1->bounds.size.height != r2->bounds.size.height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
if (r1->corner[i].width != r2->corner[i].width ||
|
|
|
|
r1->corner[i].height != r2->corner[i].height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-01-24 12:17:09 +00:00
|
|
|
static inline gboolean G_GNUC_PURE
|
2019-12-14 14:41:32 +00:00
|
|
|
rounded_rect_corners_equal (const GskRoundedRect *r1,
|
|
|
|
const GskRoundedRect *r2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!r1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i ++)
|
|
|
|
if (r1->corner[i].width != r2->corner[i].width ||
|
|
|
|
r1->corner[i].height != r2->corner[i].height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
static inline ProgramState *
|
|
|
|
get_current_program_state (RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
if (!builder->current_program)
|
|
|
|
return NULL;
|
|
|
|
|
2020-09-18 07:15:03 +00:00
|
|
|
return &builder->current_program->state;
|
2019-07-26 12:49:36 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 16:52:35 +00:00
|
|
|
void
|
|
|
|
ops_finish (RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
if (builder->mv_stack)
|
|
|
|
g_array_free (builder->mv_stack, TRUE);
|
2019-04-24 15:55:14 +00:00
|
|
|
builder->mv_stack = NULL;
|
2018-12-30 14:25:01 +00:00
|
|
|
|
|
|
|
if (builder->clip_stack)
|
|
|
|
g_array_free (builder->clip_stack, TRUE);
|
2019-04-24 15:55:14 +00:00
|
|
|
builder->clip_stack = NULL;
|
|
|
|
|
|
|
|
builder->dx = 0;
|
|
|
|
builder->dy = 0;
|
2019-11-29 13:40:20 +00:00
|
|
|
builder->scale_x = 1;
|
|
|
|
builder->scale_y = 1;
|
2019-04-24 15:55:14 +00:00
|
|
|
builder->current_modelview = NULL;
|
|
|
|
builder->current_clip = NULL;
|
2020-05-24 06:31:40 +00:00
|
|
|
builder->clip_is_rectilinear = TRUE;
|
2019-04-24 15:55:14 +00:00
|
|
|
builder->current_render_target = 0;
|
|
|
|
builder->current_texture = 0;
|
|
|
|
builder->current_program = NULL;
|
|
|
|
graphene_matrix_init_identity (&builder->current_projection);
|
|
|
|
builder->current_viewport = GRAPHENE_RECT_INIT (0, 0, 0, 0);
|
2018-11-26 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 07:12:09 +00:00
|
|
|
/* Debugging only! */
|
|
|
|
void
|
|
|
|
ops_dump_framebuffer (RenderOpBuilder *builder,
|
|
|
|
const char *filename,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpDumpFrameBuffer *op;
|
2018-12-02 07:12:09 +00:00
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_DUMP_FRAMEBUFFER);
|
2019-10-11 14:23:33 +00:00
|
|
|
op->filename = g_strdup (filename);
|
|
|
|
op->width = width;
|
|
|
|
op->height = height;
|
2018-12-02 07:12:09 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 11:28:11 +00:00
|
|
|
void
|
|
|
|
ops_push_debug_group (RenderOpBuilder *builder,
|
|
|
|
const char *text)
|
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpDebugGroup *op;
|
2019-04-24 11:28:11 +00:00
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_PUSH_DEBUG_GROUP);
|
2019-10-11 14:23:33 +00:00
|
|
|
strncpy (op->text, text, sizeof(op->text) - 1);
|
|
|
|
op->text[sizeof(op->text) - 1] = 0; /* Ensure zero terminated */
|
2019-04-24 11:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ops_pop_debug_group (RenderOpBuilder *builder)
|
|
|
|
{
|
2019-10-09 22:41:53 +00:00
|
|
|
ops_begin (builder, OP_POP_DEBUG_GROUP);
|
2019-04-24 11:28:11 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 09:20:50 +00:00
|
|
|
float
|
|
|
|
ops_get_scale (const RenderOpBuilder *builder)
|
|
|
|
{
|
2018-11-26 16:52:35 +00:00
|
|
|
g_assert (builder->mv_stack != NULL);
|
|
|
|
g_assert (builder->mv_stack->len >= 1);
|
2018-08-12 15:42:58 +00:00
|
|
|
|
2018-11-28 08:30:27 +00:00
|
|
|
/* TODO: Use two separate values */
|
2019-11-29 13:40:20 +00:00
|
|
|
return MAX (builder->scale_x, builder->scale_y);
|
2018-10-06 07:23:26 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 16:52:35 +00:00
|
|
|
static void
|
2019-06-02 07:55:11 +00:00
|
|
|
extract_matrix_metadata (GskTransform *transform,
|
|
|
|
OpsMatrixMetadata *md)
|
2018-11-26 16:52:35 +00:00
|
|
|
{
|
2019-12-16 05:41:07 +00:00
|
|
|
float dummy;
|
|
|
|
|
2019-06-02 07:55:11 +00:00
|
|
|
switch (gsk_transform_get_category (transform))
|
2019-02-23 06:50:51 +00:00
|
|
|
{
|
2019-03-01 06:51:23 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_IDENTITY:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE:
|
2019-02-23 06:50:51 +00:00
|
|
|
md->scale_x = 1;
|
|
|
|
md->scale_y = 1;
|
|
|
|
break;
|
|
|
|
|
2019-06-02 09:39:25 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_2D_AFFINE:
|
|
|
|
gsk_transform_to_affine (transform,
|
|
|
|
&md->scale_x, &md->scale_y,
|
2019-12-16 05:41:07 +00:00
|
|
|
&dummy, &dummy);
|
2019-06-02 09:39:25 +00:00
|
|
|
break;
|
|
|
|
|
2019-03-01 06:51:23 +00:00
|
|
|
case GSK_TRANSFORM_CATEGORY_UNKNOWN:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_ANY:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_3D:
|
|
|
|
case GSK_TRANSFORM_CATEGORY_2D:
|
2019-02-23 06:50:51 +00:00
|
|
|
{
|
|
|
|
graphene_vec3_t col1;
|
|
|
|
graphene_vec3_t col2;
|
2019-06-02 07:55:11 +00:00
|
|
|
graphene_matrix_t m;
|
2019-02-23 06:50:51 +00:00
|
|
|
|
2019-06-02 07:55:11 +00:00
|
|
|
gsk_transform_to_matrix (transform, &m);
|
|
|
|
|
2019-06-02 09:39:25 +00:00
|
|
|
/* TODO: 90% sure this is incorrect. But we should never hit this code
|
|
|
|
* path anyway. */
|
2019-02-23 06:50:51 +00:00
|
|
|
graphene_vec3_init (&col1,
|
2019-06-02 07:55:11 +00:00
|
|
|
graphene_matrix_get_value (&m, 0, 0),
|
|
|
|
graphene_matrix_get_value (&m, 1, 0),
|
|
|
|
graphene_matrix_get_value (&m, 2, 0));
|
2019-02-23 06:50:51 +00:00
|
|
|
|
|
|
|
graphene_vec3_init (&col2,
|
2019-06-02 07:55:11 +00:00
|
|
|
graphene_matrix_get_value (&m, 0, 1),
|
|
|
|
graphene_matrix_get_value (&m, 1, 1),
|
|
|
|
graphene_matrix_get_value (&m, 2, 1));
|
2019-02-23 06:50:51 +00:00
|
|
|
|
|
|
|
md->scale_x = graphene_vec3_length (&col1);
|
|
|
|
md->scale_y = graphene_vec3_length (&col2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{}
|
|
|
|
}
|
2018-11-26 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 07:23:26 +00:00
|
|
|
void
|
|
|
|
ops_transform_bounds_modelview (const RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *src,
|
|
|
|
graphene_rect_t *dst)
|
|
|
|
{
|
2020-01-21 09:00:51 +00:00
|
|
|
graphene_rect_t r = *src;
|
|
|
|
|
2018-11-26 16:52:35 +00:00
|
|
|
g_assert (builder->mv_stack != NULL);
|
|
|
|
g_assert (builder->mv_stack->len >= 1);
|
|
|
|
|
2020-01-21 09:00:51 +00:00
|
|
|
r.origin.x += builder->dx;
|
|
|
|
r.origin.y += builder->dy;
|
2018-11-29 07:09:02 +00:00
|
|
|
|
2020-01-21 09:00:51 +00:00
|
|
|
gsk_transform_transform_bounds (builder->current_modelview, &r, dst);
|
2018-11-29 07:09:02 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:56:44 +00:00
|
|
|
void
|
|
|
|
ops_init (RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
memset (builder, 0, sizeof (*builder));
|
|
|
|
|
|
|
|
builder->current_opacity = 1.0f;
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
op_buffer_init (&builder->render_ops);
|
2019-10-11 17:59:58 +00:00
|
|
|
builder->vertices = g_array_new (FALSE, TRUE, sizeof (GskQuadVertex));
|
2019-04-24 10:56:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 11:38:55 +00:00
|
|
|
void
|
|
|
|
ops_free (RenderOpBuilder *builder)
|
|
|
|
{
|
2019-10-11 17:59:58 +00:00
|
|
|
g_array_unref (builder->vertices);
|
2019-10-11 14:23:33 +00:00
|
|
|
op_buffer_destroy (&builder->render_ops);
|
2019-07-06 11:38:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-22 20:02:50 +00:00
|
|
|
void
|
|
|
|
ops_set_program (RenderOpBuilder *builder,
|
2020-09-18 07:15:03 +00:00
|
|
|
Program *program)
|
2017-11-22 20:02:50 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpProgram *op;
|
2020-09-18 07:15:03 +00:00
|
|
|
ProgramState *program_state = NULL;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
|
|
|
if (builder->current_program == program)
|
|
|
|
return;
|
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_PROGRAM);
|
|
|
|
op->program = program;
|
|
|
|
|
2017-11-22 20:02:50 +00:00
|
|
|
builder->current_program = program;
|
|
|
|
|
2020-09-18 07:15:03 +00:00
|
|
|
program_state = &program->state;
|
2018-12-02 13:17:18 +00:00
|
|
|
|
2019-12-14 14:43:12 +00:00
|
|
|
if (memcmp (&builder->current_projection, &program_state->projection, sizeof (graphene_matrix_t)) != 0)
|
2017-11-22 20:02:50 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpMatrix *opm;
|
|
|
|
|
|
|
|
opm = ops_begin (builder, OP_CHANGE_PROJECTION);
|
|
|
|
opm->matrix = builder->current_projection;
|
2018-12-02 13:17:18 +00:00
|
|
|
program_state->projection = builder->current_projection;
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:07:26 +00:00
|
|
|
if (program_state->modelview == NULL ||
|
2019-06-02 07:55:11 +00:00
|
|
|
!gsk_transform_equal (builder->current_modelview, program_state->modelview))
|
2017-11-22 20:02:50 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpMatrix *opm;
|
|
|
|
|
|
|
|
opm = ops_begin (builder, OP_CHANGE_MODELVIEW);
|
|
|
|
gsk_transform_to_matrix (builder->current_modelview, &opm->matrix);
|
2019-07-06 11:38:55 +00:00
|
|
|
gsk_transform_unref (program_state->modelview);
|
2019-06-02 07:55:11 +00:00
|
|
|
program_state->modelview = gsk_transform_ref (builder->current_modelview);
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
|
|
|
|
2019-12-14 14:43:12 +00:00
|
|
|
if (!rect_equal (&builder->current_viewport, &program_state->viewport))
|
2017-11-22 20:02:50 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpViewport *opv;
|
|
|
|
|
|
|
|
opv = ops_begin (builder, OP_CHANGE_VIEWPORT);
|
|
|
|
opv->viewport = builder->current_viewport;
|
2018-12-02 13:17:18 +00:00
|
|
|
program_state->viewport = builder->current_viewport;
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
|
|
|
|
2019-12-14 14:43:12 +00:00
|
|
|
if (!rounded_rect_equal (builder->current_clip, &program_state->clip))
|
2017-11-22 20:02:50 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpClip *opc;
|
|
|
|
|
|
|
|
opc = ops_begin (builder, OP_CHANGE_CLIP);
|
|
|
|
opc->clip = *builder->current_clip;
|
2019-12-14 14:41:32 +00:00
|
|
|
opc->send_corners = !rounded_rect_corners_equal (builder->current_clip, &program_state->clip);
|
2018-12-30 14:25:01 +00:00
|
|
|
program_state->clip = *builder->current_clip;
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
2017-12-07 16:30:02 +00:00
|
|
|
|
2018-12-02 13:17:18 +00:00
|
|
|
if (program_state->opacity != builder->current_opacity)
|
2017-12-07 16:30:02 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpOpacity *opo;
|
|
|
|
|
|
|
|
opo = ops_begin (builder, OP_CHANGE_OPACITY);
|
|
|
|
opo->opacity = builder->current_opacity;
|
2018-12-02 13:17:18 +00:00
|
|
|
program_state->opacity = builder->current_opacity;
|
2017-12-07 16:30:02 +00:00
|
|
|
}
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 14:25:01 +00:00
|
|
|
static void
|
2017-11-22 20:02:50 +00:00
|
|
|
ops_set_clip (RenderOpBuilder *builder,
|
|
|
|
const GskRoundedRect *clip)
|
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpClip *op;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
if (current_program_state &&
|
2019-12-14 14:41:32 +00:00
|
|
|
rounded_rect_equal (¤t_program_state->clip, clip))
|
2019-01-17 07:22:00 +00:00
|
|
|
return;
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
if (!(op = op_buffer_peek_tail_checked (&builder->render_ops, OP_CHANGE_CLIP)))
|
2019-12-14 14:41:32 +00:00
|
|
|
{
|
|
|
|
op = op_buffer_add (&builder->render_ops, OP_CHANGE_CLIP);
|
|
|
|
op->send_corners = !current_program_state ||
|
|
|
|
!rounded_rect_corners_equal (¤t_program_state->clip, clip);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the op before sent the corners, this one needs, too */
|
|
|
|
op->send_corners |= !current_program_state ||
|
|
|
|
!rounded_rect_corners_equal (¤t_program_state->clip, clip);
|
|
|
|
}
|
2019-10-11 14:23:33 +00:00
|
|
|
|
|
|
|
op->clip = *clip;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2019-12-14 14:41:32 +00:00
|
|
|
if (current_program_state)
|
2019-07-26 12:49:36 +00:00
|
|
|
current_program_state->clip = *clip;
|
2018-12-30 14:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ops_push_clip (RenderOpBuilder *self,
|
|
|
|
const GskRoundedRect *clip)
|
|
|
|
{
|
2020-07-24 16:30:36 +00:00
|
|
|
ClipStackEntry entry;
|
|
|
|
|
2018-12-30 14:25:01 +00:00
|
|
|
if (G_UNLIKELY (self->clip_stack == NULL))
|
2020-07-24 16:30:36 +00:00
|
|
|
self->clip_stack = g_array_new (FALSE, TRUE, sizeof (ClipStackEntry));
|
2018-12-30 14:25:01 +00:00
|
|
|
|
|
|
|
g_assert (self->clip_stack != NULL);
|
|
|
|
|
2020-07-24 16:30:36 +00:00
|
|
|
entry.rect = *clip;
|
|
|
|
entry.is_rectilinear = gsk_rounded_rect_is_rectilinear (clip);
|
|
|
|
g_array_append_val (self->clip_stack, entry);
|
|
|
|
self->current_clip = &g_array_index (self->clip_stack, ClipStackEntry, self->clip_stack->len - 1).rect;
|
|
|
|
self->clip_is_rectilinear = entry.is_rectilinear;
|
2018-12-30 14:25:01 +00:00
|
|
|
ops_set_clip (self, clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ops_pop_clip (RenderOpBuilder *self)
|
|
|
|
{
|
2020-07-24 16:30:36 +00:00
|
|
|
const ClipStackEntry *head;
|
2018-12-30 14:25:01 +00:00
|
|
|
|
|
|
|
g_assert (self->clip_stack);
|
|
|
|
g_assert (self->clip_stack->len >= 1);
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2018-12-30 14:25:01 +00:00
|
|
|
self->clip_stack->len --;
|
2020-07-24 16:30:36 +00:00
|
|
|
head = &g_array_index (self->clip_stack, ClipStackEntry, self->clip_stack->len - 1);
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2018-12-30 14:25:01 +00:00
|
|
|
if (self->clip_stack->len >= 1)
|
|
|
|
{
|
2020-07-24 16:30:36 +00:00
|
|
|
self->current_clip = &head->rect;
|
|
|
|
self->clip_is_rectilinear = head->is_rectilinear;
|
|
|
|
ops_set_clip (self, &head->rect);
|
2018-12-30 14:25:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->current_clip = NULL;
|
2020-05-24 06:31:40 +00:00
|
|
|
self->clip_is_rectilinear = TRUE;
|
2018-12-30 14:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ops_has_clip (RenderOpBuilder *self)
|
|
|
|
{
|
|
|
|
return self->clip_stack != NULL &&
|
|
|
|
self->clip_stack->len > 1;
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 16:52:35 +00:00
|
|
|
static void
|
2019-06-02 07:55:11 +00:00
|
|
|
ops_set_modelview_internal (RenderOpBuilder *builder,
|
|
|
|
GskTransform *transform)
|
2017-11-22 20:02:50 +00:00
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpMatrix *op;
|
2019-06-02 07:55:11 +00:00
|
|
|
|
2019-06-29 06:57:27 +00:00
|
|
|
#if 0
|
|
|
|
XXX This is not possible if we want pop() to work.
|
2017-12-21 17:09:32 +00:00
|
|
|
if (builder->current_program &&
|
2019-06-02 07:55:11 +00:00
|
|
|
gsk_transform_equal (builder->current_program_state->modelview, transform))
|
2018-11-26 16:52:35 +00:00
|
|
|
return;
|
2019-06-29 06:57:27 +00:00
|
|
|
#endif
|
2017-12-03 19:16:01 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
if (!(op = op_buffer_peek_tail_checked (&builder->render_ops, OP_CHANGE_MODELVIEW)))
|
|
|
|
op = op_buffer_add (&builder->render_ops, OP_CHANGE_MODELVIEW);
|
|
|
|
|
2019-12-19 12:03:22 +00:00
|
|
|
gsk_transform_to_matrix (transform, &op->matrix);
|
2017-11-22 20:02:50 +00:00
|
|
|
|
|
|
|
if (builder->current_program != NULL)
|
2019-07-26 12:49:36 +00:00
|
|
|
{
|
|
|
|
gsk_transform_unref (current_program_state->modelview);
|
|
|
|
current_program_state->modelview = gsk_transform_ref (transform);
|
|
|
|
}
|
2018-11-26 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
/**
|
|
|
|
* ops_set_modelview:
|
|
|
|
* @builder
|
|
|
|
* @transform: (transfer full): The new modelview transform
|
|
|
|
*
|
|
|
|
* This sets the modelview to the given one without looking at the
|
2019-02-23 06:50:51 +00:00
|
|
|
* one that's currently set */
|
2018-11-26 16:52:35 +00:00
|
|
|
void
|
2019-06-02 07:55:11 +00:00
|
|
|
ops_set_modelview (RenderOpBuilder *builder,
|
|
|
|
GskTransform *transform)
|
2018-11-26 16:52:35 +00:00
|
|
|
{
|
|
|
|
MatrixStackEntry *entry;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (builder->mv_stack == NULL))
|
2018-12-30 14:25:01 +00:00
|
|
|
builder->mv_stack = g_array_new (FALSE, TRUE, sizeof (MatrixStackEntry));
|
2018-11-26 16:52:35 +00:00
|
|
|
|
|
|
|
g_assert (builder->mv_stack != NULL);
|
|
|
|
|
|
|
|
g_array_set_size (builder->mv_stack, builder->mv_stack->len + 1);
|
|
|
|
entry = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1);
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
entry->transform = transform;
|
2019-02-23 06:50:51 +00:00
|
|
|
|
|
|
|
entry->metadata.dx_before = builder->dx;
|
|
|
|
entry->metadata.dy_before = builder->dy;
|
2019-07-26 12:49:36 +00:00
|
|
|
extract_matrix_metadata (entry->transform, &entry->metadata);
|
2019-02-23 06:50:51 +00:00
|
|
|
|
|
|
|
builder->dx = 0;
|
|
|
|
builder->dy = 0;
|
2019-06-02 07:55:11 +00:00
|
|
|
builder->current_modelview = entry->transform;
|
2019-11-29 13:40:20 +00:00
|
|
|
builder->scale_x = entry->metadata.scale_x;
|
|
|
|
builder->scale_y = entry->metadata.scale_y;
|
2019-06-02 07:55:11 +00:00
|
|
|
ops_set_modelview_internal (builder, entry->transform);
|
2019-02-23 06:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This sets the given modelview to the one we get when multiplying
|
|
|
|
* the given modelview with the current one. */
|
|
|
|
void
|
2019-06-02 07:55:11 +00:00
|
|
|
ops_push_modelview (RenderOpBuilder *builder,
|
|
|
|
GskTransform *transform)
|
2019-02-23 06:50:51 +00:00
|
|
|
{
|
|
|
|
MatrixStackEntry *entry;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (builder->mv_stack == NULL))
|
|
|
|
builder->mv_stack = g_array_new (FALSE, TRUE, sizeof (MatrixStackEntry));
|
|
|
|
|
|
|
|
g_assert (builder->mv_stack != NULL);
|
|
|
|
|
|
|
|
g_array_set_size (builder->mv_stack, builder->mv_stack->len + 1);
|
|
|
|
entry = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1);
|
|
|
|
|
|
|
|
if (G_LIKELY (builder->mv_stack->len >= 2))
|
|
|
|
{
|
|
|
|
const MatrixStackEntry *cur;
|
2019-06-02 09:39:25 +00:00
|
|
|
GskTransform *t = NULL;
|
2019-02-23 06:50:51 +00:00
|
|
|
|
|
|
|
cur = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 2);
|
|
|
|
/* Multiply given matrix with current modelview */
|
|
|
|
|
2019-06-03 13:54:25 +00:00
|
|
|
t = gsk_transform_translate (gsk_transform_ref (cur->transform),
|
2019-07-26 14:27:39 +00:00
|
|
|
&(graphene_point_t) { builder->dx, builder->dy});
|
2019-06-02 09:39:25 +00:00
|
|
|
t = gsk_transform_transform (t, transform);
|
2019-06-02 07:55:11 +00:00
|
|
|
entry->transform = t;
|
2019-02-23 06:50:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-02 07:55:11 +00:00
|
|
|
entry->transform = gsk_transform_ref (transform);
|
2019-02-23 06:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
entry->metadata.dx_before = builder->dx;
|
|
|
|
entry->metadata.dy_before = builder->dy;
|
2019-06-02 08:25:39 +00:00
|
|
|
extract_matrix_metadata (entry->transform, &entry->metadata);
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2019-02-23 06:50:51 +00:00
|
|
|
builder->dx = 0;
|
|
|
|
builder->dy = 0;
|
2019-11-29 13:40:20 +00:00
|
|
|
builder->scale_x = entry->metadata.scale_x;
|
|
|
|
builder->scale_y = entry->metadata.scale_y;
|
2019-06-02 07:55:11 +00:00
|
|
|
builder->current_modelview = entry->transform;
|
|
|
|
ops_set_modelview_internal (builder, entry->transform);
|
2018-11-26 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ops_pop_modelview (RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
const MatrixStackEntry *head;
|
|
|
|
|
|
|
|
g_assert (builder->mv_stack);
|
|
|
|
g_assert (builder->mv_stack->len >= 1);
|
|
|
|
|
2019-02-23 06:50:51 +00:00
|
|
|
head = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1);
|
|
|
|
builder->dx = head->metadata.dx_before;
|
|
|
|
builder->dy = head->metadata.dy_before;
|
2019-06-02 07:55:11 +00:00
|
|
|
gsk_transform_unref (head->transform);
|
2019-02-23 06:50:51 +00:00
|
|
|
|
2018-11-26 16:52:35 +00:00
|
|
|
builder->mv_stack->len --;
|
|
|
|
head = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1);
|
|
|
|
|
|
|
|
if (builder->mv_stack->len >= 1)
|
|
|
|
{
|
2019-11-29 13:40:20 +00:00
|
|
|
builder->scale_x = head->metadata.scale_x;
|
|
|
|
builder->scale_y = head->metadata.scale_y;
|
2019-06-02 07:55:11 +00:00
|
|
|
builder->current_modelview = head->transform;
|
|
|
|
ops_set_modelview_internal (builder, head->transform);
|
2018-11-26 16:52:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
builder->current_modelview = NULL;
|
|
|
|
}
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
graphene_matrix_t
|
|
|
|
ops_set_projection (RenderOpBuilder *builder,
|
|
|
|
const graphene_matrix_t *projection)
|
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2017-11-22 20:02:50 +00:00
|
|
|
graphene_matrix_t prev_mv;
|
2019-10-11 14:23:33 +00:00
|
|
|
OpMatrix *op;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
if (!(op = op_buffer_peek_tail_checked (&builder->render_ops, OP_CHANGE_PROJECTION)))
|
|
|
|
op = op_buffer_add (&builder->render_ops, OP_CHANGE_PROJECTION);
|
|
|
|
|
|
|
|
op->matrix = *projection;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
|
|
|
if (builder->current_program != NULL)
|
2019-07-26 12:49:36 +00:00
|
|
|
current_program_state->projection = *projection;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
|
|
|
prev_mv = builder->current_projection;
|
|
|
|
builder->current_projection = *projection;
|
|
|
|
|
|
|
|
return prev_mv;
|
|
|
|
}
|
|
|
|
|
|
|
|
graphene_rect_t
|
|
|
|
ops_set_viewport (RenderOpBuilder *builder,
|
|
|
|
const graphene_rect_t *viewport)
|
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpViewport *op;
|
2017-11-22 20:02:50 +00:00
|
|
|
graphene_rect_t prev_viewport;
|
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
if (current_program_state != NULL &&
|
|
|
|
rect_equal (¤t_program_state->viewport, viewport))
|
|
|
|
return current_program_state->viewport;
|
2018-12-05 09:36:43 +00:00
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_VIEWPORT);
|
|
|
|
op->viewport = *viewport;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2020-07-24 18:01:49 +00:00
|
|
|
if (current_program_state != NULL)
|
2019-07-26 12:49:36 +00:00
|
|
|
current_program_state->viewport = *viewport;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
|
|
|
prev_viewport = builder->current_viewport;
|
|
|
|
builder->current_viewport = *viewport;
|
|
|
|
|
|
|
|
return prev_viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ops_set_texture (RenderOpBuilder *builder,
|
|
|
|
int texture_id)
|
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpTexture *op;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
|
|
|
if (builder->current_texture == texture_id)
|
|
|
|
return;
|
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_SOURCE_TEXTURE);
|
|
|
|
op->texture_id = texture_id;
|
2017-11-22 20:02:50 +00:00
|
|
|
builder->current_texture = texture_id;
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
void
|
|
|
|
ops_set_extra_texture (RenderOpBuilder *builder,
|
|
|
|
int texture_id,
|
|
|
|
int idx)
|
|
|
|
{
|
|
|
|
OpExtraTexture *op;
|
|
|
|
|
|
|
|
op = ops_begin (builder, OP_CHANGE_EXTRA_SOURCE_TEXTURE);
|
|
|
|
op->texture_id = texture_id;
|
|
|
|
op->idx = idx;
|
|
|
|
}
|
|
|
|
|
2017-11-22 20:02:50 +00:00
|
|
|
int
|
|
|
|
ops_set_render_target (RenderOpBuilder *builder,
|
|
|
|
int render_target_id)
|
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpRenderTarget *op;
|
2017-11-22 20:02:50 +00:00
|
|
|
int prev_render_target;
|
|
|
|
|
|
|
|
if (builder->current_render_target == render_target_id)
|
|
|
|
return render_target_id;
|
|
|
|
|
|
|
|
prev_render_target = builder->current_render_target;
|
2018-12-05 09:37:02 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
if (!(op = op_buffer_peek_tail_checked (&builder->render_ops, OP_CHANGE_RENDER_TARGET)))
|
|
|
|
op = op_buffer_add (&builder->render_ops, OP_CHANGE_RENDER_TARGET);
|
|
|
|
|
|
|
|
op->render_target_id = render_target_id;
|
2018-12-05 09:37:02 +00:00
|
|
|
|
2017-11-22 20:02:50 +00:00
|
|
|
builder->current_render_target = render_target_id;
|
|
|
|
|
|
|
|
return prev_render_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
ops_set_opacity (RenderOpBuilder *builder,
|
|
|
|
float opacity)
|
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpOpacity *op;
|
2017-11-22 20:02:50 +00:00
|
|
|
float prev_opacity;
|
|
|
|
|
|
|
|
if (builder->current_opacity == opacity)
|
|
|
|
return opacity;
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
if (!(op = op_buffer_peek_tail_checked (&builder->render_ops, OP_CHANGE_OPACITY)))
|
|
|
|
op = op_buffer_add (&builder->render_ops, OP_CHANGE_OPACITY);
|
|
|
|
|
|
|
|
op->opacity = opacity;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
|
|
|
prev_opacity = builder->current_opacity;
|
|
|
|
builder->current_opacity = opacity;
|
|
|
|
|
2017-12-07 16:30:02 +00:00
|
|
|
if (builder->current_program != NULL)
|
2019-07-26 12:49:36 +00:00
|
|
|
current_program_state->opacity = opacity;
|
2017-12-07 16:30:02 +00:00
|
|
|
|
2017-11-22 20:02:50 +00:00
|
|
|
return prev_opacity;
|
|
|
|
}
|
|
|
|
|
2017-11-24 12:18:45 +00:00
|
|
|
void
|
|
|
|
ops_set_color (RenderOpBuilder *builder,
|
|
|
|
const GdkRGBA *color)
|
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpColor *op;
|
2017-11-24 12:18:45 +00:00
|
|
|
|
2019-12-17 12:06:02 +00:00
|
|
|
if (gdk_rgba_equal (color, ¤t_program_state->color))
|
2017-11-24 12:18:45 +00:00
|
|
|
return;
|
|
|
|
|
2019-12-17 12:06:02 +00:00
|
|
|
current_program_state->color = *color;
|
2017-11-24 12:18:45 +00:00
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_COLOR);
|
2019-12-10 14:08:47 +00:00
|
|
|
op->rgba = color;
|
2017-11-24 12:18:45 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 16:03:30 +00:00
|
|
|
void
|
|
|
|
ops_set_gl_shader_args (RenderOpBuilder *builder,
|
|
|
|
GskGLShader *shader,
|
|
|
|
float width,
|
|
|
|
float height,
|
|
|
|
const guchar *uniform_data)
|
|
|
|
{
|
2020-09-29 09:52:39 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2020-09-18 16:03:30 +00:00
|
|
|
OpGLShader *op;
|
2020-09-29 09:52:39 +00:00
|
|
|
gsize args_size = gsk_gl_shader_get_args_size (shader);
|
|
|
|
|
|
|
|
if (current_program_state)
|
|
|
|
{
|
|
|
|
if (current_program_state->gl_shader.width == width &&
|
|
|
|
current_program_state->gl_shader.height == height &&
|
|
|
|
current_program_state->gl_shader.uniform_data_len == args_size &&
|
|
|
|
memcmp (current_program_state->gl_shader.uniform_data, uniform_data, args_size) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
current_program_state->gl_shader.width = width;
|
|
|
|
current_program_state->gl_shader.height = height;
|
|
|
|
if (args_size > sizeof (current_program_state->gl_shader.uniform_data))
|
|
|
|
current_program_state->gl_shader.uniform_data_len = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current_program_state->gl_shader.uniform_data_len = args_size;
|
|
|
|
memcpy (current_program_state->gl_shader.uniform_data, uniform_data, args_size);
|
|
|
|
}
|
|
|
|
}
|
2020-09-18 16:03:30 +00:00
|
|
|
|
|
|
|
op = ops_begin (builder, OP_CHANGE_GL_SHADER_ARGS);
|
|
|
|
op->shader = shader;
|
|
|
|
op->size[0] = width;
|
|
|
|
op->size[1] = height;
|
|
|
|
op->uniform_data = uniform_data;
|
|
|
|
}
|
|
|
|
|
2017-12-03 18:15:33 +00:00
|
|
|
void
|
|
|
|
ops_set_color_matrix (RenderOpBuilder *builder,
|
|
|
|
const graphene_matrix_t *matrix,
|
|
|
|
const graphene_vec4_t *offset)
|
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpColorMatrix *op;
|
2020-07-24 15:29:22 +00:00
|
|
|
bool offset_equal;
|
|
|
|
|
|
|
|
offset_equal = memcmp (offset,
|
|
|
|
¤t_program_state->color_matrix.offset,
|
|
|
|
sizeof (graphene_vec4_t)) == 0;
|
2017-12-03 18:15:33 +00:00
|
|
|
|
|
|
|
if (memcmp (matrix,
|
2019-07-26 12:49:36 +00:00
|
|
|
¤t_program_state->color_matrix.matrix,
|
2017-12-03 18:15:33 +00:00
|
|
|
sizeof (graphene_matrix_t)) == 0 &&
|
2020-07-24 15:29:22 +00:00
|
|
|
offset_equal)
|
2017-12-03 18:15:33 +00:00
|
|
|
return;
|
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
current_program_state->color_matrix.matrix = *matrix;
|
2017-12-03 18:15:33 +00:00
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_COLOR_MATRIX);
|
2019-12-16 05:32:36 +00:00
|
|
|
op->matrix = matrix;
|
2020-07-24 15:29:22 +00:00
|
|
|
|
|
|
|
if (!offset_equal)
|
|
|
|
{
|
|
|
|
op->offset.value = offset;
|
|
|
|
op->offset.send = TRUE;
|
|
|
|
|
|
|
|
current_program_state->color_matrix.offset = *offset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->offset.send = FALSE;
|
2017-12-03 18:15:33 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 07:38:42 +00:00
|
|
|
void
|
2018-03-15 16:27:19 +00:00
|
|
|
ops_set_border (RenderOpBuilder *builder,
|
|
|
|
const GskRoundedRect *outline)
|
2017-12-05 07:38:42 +00:00
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpBorder *op;
|
2017-12-05 07:38:42 +00:00
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
if (memcmp (¤t_program_state->border.outline,
|
2018-03-15 16:27:19 +00:00
|
|
|
outline, sizeof (GskRoundedRect)) == 0)
|
2017-12-05 07:38:42 +00:00
|
|
|
return;
|
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
current_program_state->border.outline = *outline;
|
2018-03-15 17:17:57 +00:00
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_BORDER);
|
2019-10-11 14:23:33 +00:00
|
|
|
op->outline = *outline;
|
2018-12-05 09:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ops_set_border_width (RenderOpBuilder *builder,
|
|
|
|
const float *widths)
|
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpBorder *op;
|
2018-12-05 09:44:11 +00:00
|
|
|
|
2020-07-24 18:01:49 +00:00
|
|
|
g_assert (current_program_state);
|
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
if (memcmp (current_program_state->border.widths,
|
2018-12-05 09:44:11 +00:00
|
|
|
widths, sizeof (float) * 4) == 0)
|
|
|
|
return;
|
|
|
|
|
2019-07-26 12:49:36 +00:00
|
|
|
memcpy (¤t_program_state->border.widths,
|
2018-12-05 09:44:11 +00:00
|
|
|
widths, sizeof (float) * 4);
|
|
|
|
|
2019-10-09 22:41:53 +00:00
|
|
|
op = ops_begin (builder, OP_CHANGE_BORDER_WIDTH);
|
2019-10-11 14:23:33 +00:00
|
|
|
op->widths[0] = widths[0];
|
|
|
|
op->widths[1] = widths[1];
|
|
|
|
op->widths[2] = widths[2];
|
|
|
|
op->widths[3] = widths[3];
|
2017-12-05 07:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ops_set_border_color (RenderOpBuilder *builder,
|
|
|
|
const GdkRGBA *color)
|
|
|
|
{
|
2019-07-26 12:49:36 +00:00
|
|
|
ProgramState *current_program_state = get_current_program_state (builder);
|
2019-10-11 14:23:33 +00:00
|
|
|
OpBorder *op;
|
2017-12-05 07:38:42 +00:00
|
|
|
|
2019-12-17 12:06:02 +00:00
|
|
|
if (gdk_rgba_equal (color, ¤t_program_state->border.color))
|
2019-10-11 14:23:33 +00:00
|
|
|
return;
|
2017-12-05 07:38:42 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
op = op_buffer_add (&builder->render_ops, OP_CHANGE_BORDER_COLOR);
|
2019-12-10 14:08:47 +00:00
|
|
|
op->color = color;
|
|
|
|
|
2019-12-17 12:06:02 +00:00
|
|
|
current_program_state->border.color = *color;
|
2017-12-05 07:38:42 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 08:06:16 +00:00
|
|
|
GskQuadVertex *
|
2017-11-22 20:02:50 +00:00
|
|
|
ops_draw (RenderOpBuilder *builder,
|
|
|
|
const GskQuadVertex vertex_data[GL_N_VERTICES])
|
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
OpDraw *op;
|
2017-11-22 20:02:50 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
if ((op = op_buffer_peek_tail_checked (&builder->render_ops, OP_DRAW)))
|
2017-11-23 18:49:41 +00:00
|
|
|
{
|
2019-10-11 17:59:58 +00:00
|
|
|
op->vao_size += GL_N_VERTICES;
|
2017-11-23 18:49:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
op = op_buffer_add (&builder->render_ops, OP_DRAW);
|
2019-10-11 18:10:56 +00:00
|
|
|
op->vao_offset = builder->vertices->len;
|
2019-10-11 14:23:33 +00:00
|
|
|
op->vao_size = GL_N_VERTICES;
|
2017-11-23 18:49:41 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 08:06:16 +00:00
|
|
|
if (vertex_data)
|
|
|
|
{
|
|
|
|
g_array_append_vals (builder->vertices, vertex_data, GL_N_VERTICES);
|
|
|
|
return NULL; /* Better not use this on the caller side */
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_set_size (builder->vertices, builder->vertices->len + GL_N_VERTICES);
|
|
|
|
return &g_array_index (builder->vertices, GskQuadVertex, builder->vertices->len - GL_N_VERTICES);
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 06:50:51 +00:00
|
|
|
/* The offset is only valid for the current modelview.
|
|
|
|
* Setting a new modelview will add the offset to that matrix
|
|
|
|
* and reset the internal offset to 0. */
|
2017-12-09 17:26:29 +00:00
|
|
|
void
|
|
|
|
ops_offset (RenderOpBuilder *builder,
|
|
|
|
float x,
|
|
|
|
float y)
|
|
|
|
{
|
2018-04-11 16:09:30 +00:00
|
|
|
builder->dx += x;
|
|
|
|
builder->dy += y;
|
2017-12-09 17:26:29 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
gpointer
|
2019-10-09 22:41:53 +00:00
|
|
|
ops_begin (RenderOpBuilder *builder,
|
2019-10-11 14:23:33 +00:00
|
|
|
OpKind kind)
|
2017-11-22 20:02:50 +00:00
|
|
|
{
|
2019-10-11 14:23:33 +00:00
|
|
|
return op_buffer_add (&builder->render_ops, kind);
|
|
|
|
}
|
2019-10-09 22:41:53 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
void
|
|
|
|
ops_reset (RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
op_buffer_clear (&builder->render_ops);
|
2019-10-11 17:59:58 +00:00
|
|
|
g_array_set_size (builder->vertices, 0);
|
2019-10-11 14:23:33 +00:00
|
|
|
}
|
2019-10-09 22:41:53 +00:00
|
|
|
|
2019-10-11 14:23:33 +00:00
|
|
|
OpBuffer *
|
|
|
|
ops_get_buffer (RenderOpBuilder *builder)
|
|
|
|
{
|
|
|
|
return &builder->render_ops;
|
2017-11-22 20:02:50 +00:00
|
|
|
}
|
2020-07-24 06:49:24 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ops_set_inset_shadow (RenderOpBuilder *self,
|
|
|
|
const GskRoundedRect outline,
|
|
|
|
float spread,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
float dx,
|
|
|
|
float dy)
|
|
|
|
{
|
|
|
|
ProgramState *current_program_state = get_current_program_state (self);
|
|
|
|
OpShadow *op;
|
|
|
|
|
2020-07-24 18:01:49 +00:00
|
|
|
g_assert (current_program_state);
|
|
|
|
|
2020-07-24 06:49:24 +00:00
|
|
|
op = ops_begin (self, OP_CHANGE_INSET_SHADOW);
|
|
|
|
|
|
|
|
if (!rounded_rect_equal (&outline, ¤t_program_state->inset_shadow.outline))
|
|
|
|
{
|
|
|
|
op->outline.value = outline;
|
|
|
|
op->outline.send = TRUE;
|
|
|
|
op->outline.send_corners = !rounded_rect_corners_equal (¤t_program_state->inset_shadow.outline,
|
|
|
|
&outline);
|
|
|
|
current_program_state->inset_shadow.outline = outline;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->outline.send = FALSE;
|
|
|
|
|
|
|
|
if (spread != current_program_state->inset_shadow.spread)
|
|
|
|
{
|
|
|
|
op->spread.value = spread;
|
|
|
|
op->spread.send = TRUE;
|
|
|
|
|
|
|
|
current_program_state->inset_shadow.spread = spread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->spread.send = FALSE;
|
|
|
|
|
|
|
|
if (!gdk_rgba_equal (color, ¤t_program_state->inset_shadow.color))
|
|
|
|
{
|
|
|
|
op->color.value = color;
|
|
|
|
op->color.send = TRUE;
|
|
|
|
|
|
|
|
current_program_state->inset_shadow.color = *color;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->color.send = FALSE;
|
|
|
|
|
|
|
|
if (dx != current_program_state->inset_shadow.dx ||
|
|
|
|
dy != current_program_state->inset_shadow.dy)
|
|
|
|
{
|
|
|
|
op->offset.value[0] = dx;
|
|
|
|
op->offset.value[1] = dy;
|
|
|
|
op->offset.send = TRUE;
|
|
|
|
|
|
|
|
current_program_state->inset_shadow.dx = dx;
|
|
|
|
current_program_state->inset_shadow.dy = dy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->offset.send = FALSE;
|
2020-07-25 10:12:02 +00:00
|
|
|
|
|
|
|
if (!op->outline.send &&
|
|
|
|
!op->spread.send &&
|
|
|
|
!op->offset.send &&
|
|
|
|
!op->color.send)
|
|
|
|
{
|
|
|
|
op_buffer_pop_tail (&self->render_ops);
|
|
|
|
}
|
2020-07-24 06:49:24 +00:00
|
|
|
}
|
|
|
|
void
|
|
|
|
ops_set_unblurred_outset_shadow (RenderOpBuilder *self,
|
|
|
|
const GskRoundedRect outline,
|
|
|
|
float spread,
|
|
|
|
const GdkRGBA *color,
|
|
|
|
float dx,
|
|
|
|
float dy)
|
|
|
|
{
|
|
|
|
ProgramState *current_program_state = get_current_program_state (self);
|
|
|
|
OpShadow *op;
|
|
|
|
|
2020-07-24 18:01:49 +00:00
|
|
|
g_assert (current_program_state);
|
|
|
|
|
2020-07-24 06:49:24 +00:00
|
|
|
op = ops_begin (self, OP_CHANGE_UNBLURRED_OUTSET_SHADOW);
|
|
|
|
|
|
|
|
if (!rounded_rect_equal (&outline, ¤t_program_state->unblurred_outset_shadow.outline))
|
|
|
|
{
|
|
|
|
op->outline.value = outline;
|
|
|
|
op->outline.send = TRUE;
|
|
|
|
op->outline.send_corners = !rounded_rect_corners_equal (¤t_program_state->unblurred_outset_shadow.outline,
|
|
|
|
&outline);
|
|
|
|
current_program_state->unblurred_outset_shadow.outline = outline;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->outline.send = FALSE;
|
|
|
|
|
|
|
|
if (spread != current_program_state->unblurred_outset_shadow.spread)
|
|
|
|
{
|
|
|
|
op->spread.value = spread;
|
|
|
|
op->spread.send = TRUE;
|
|
|
|
|
|
|
|
current_program_state->unblurred_outset_shadow.spread = spread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->spread.send = FALSE;
|
|
|
|
|
|
|
|
if (!gdk_rgba_equal (color, ¤t_program_state->unblurred_outset_shadow.color))
|
|
|
|
{
|
|
|
|
op->color.value = color;
|
|
|
|
op->color.send = TRUE;
|
|
|
|
|
|
|
|
current_program_state->unblurred_outset_shadow.color = *color;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->color.send = FALSE;
|
|
|
|
|
|
|
|
if (dx != current_program_state->unblurred_outset_shadow.dx ||
|
|
|
|
dy != current_program_state->unblurred_outset_shadow.dy)
|
|
|
|
{
|
|
|
|
op->offset.value[0] = dx;
|
|
|
|
op->offset.value[1] = dy;
|
|
|
|
op->offset.send = TRUE;
|
|
|
|
|
|
|
|
current_program_state->unblurred_outset_shadow.dx = dx;
|
|
|
|
current_program_state->unblurred_outset_shadow.dy = dy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->offset.send = FALSE;
|
|
|
|
}
|
2020-07-24 18:45:22 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ops_set_linear_gradient (RenderOpBuilder *self,
|
|
|
|
guint n_color_stops,
|
|
|
|
const GskColorStop *color_stops,
|
|
|
|
float start_x,
|
|
|
|
float start_y,
|
|
|
|
float end_x,
|
|
|
|
float end_y)
|
|
|
|
{
|
|
|
|
ProgramState *current_program_state = get_current_program_state (self);
|
|
|
|
OpLinearGradient *op;
|
2020-09-21 19:19:19 +00:00
|
|
|
const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
|
2020-07-24 18:45:22 +00:00
|
|
|
|
|
|
|
g_assert (current_program_state);
|
|
|
|
|
|
|
|
op = ops_begin (self, OP_CHANGE_LINEAR_GRADIENT);
|
|
|
|
|
|
|
|
/* We always save the n_color_stops value in the op so the renderer can use it in
|
|
|
|
* cases where we send the color stops, but not n_color_stops */
|
|
|
|
op->n_color_stops.value = real_n_color_stops;
|
|
|
|
if (current_program_state->linear_gradient.n_color_stops != real_n_color_stops)
|
|
|
|
{
|
|
|
|
op->n_color_stops.send = TRUE;
|
|
|
|
current_program_state->linear_gradient.n_color_stops = real_n_color_stops;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->n_color_stops.send = FALSE;
|
|
|
|
|
|
|
|
op->color_stops.send = FALSE;
|
|
|
|
if (!op->n_color_stops.send)
|
|
|
|
{
|
|
|
|
g_assert (current_program_state->linear_gradient.n_color_stops == real_n_color_stops);
|
|
|
|
|
|
|
|
for (guint i = 0; i < real_n_color_stops; i ++)
|
|
|
|
{
|
|
|
|
const GskColorStop *s1 = &color_stops[i];
|
|
|
|
const GskColorStop *s2 = ¤t_program_state->linear_gradient.color_stops[i];
|
|
|
|
|
|
|
|
if (s1->offset != s2->offset ||
|
|
|
|
!gdk_rgba_equal (&s1->color, &s2->color))
|
|
|
|
{
|
|
|
|
op->color_stops.send = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
op->color_stops.send = TRUE;
|
|
|
|
|
|
|
|
if (op->color_stops.send)
|
|
|
|
{
|
|
|
|
op->color_stops.value = color_stops;
|
|
|
|
memcpy (¤t_program_state->linear_gradient.color_stops,
|
|
|
|
color_stops,
|
|
|
|
sizeof (GskColorStop) * real_n_color_stops);
|
|
|
|
}
|
|
|
|
|
|
|
|
op->start_point[0] = start_x;
|
|
|
|
op->start_point[1] = start_y;
|
|
|
|
op->end_point[0] = end_x;
|
|
|
|
op->end_point[1] = end_y;
|
|
|
|
}
|
2020-09-18 12:42:36 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ops_set_radial_gradient (RenderOpBuilder *self,
|
|
|
|
guint n_color_stops,
|
|
|
|
const GskColorStop *color_stops,
|
|
|
|
float center_x,
|
|
|
|
float center_y,
|
|
|
|
float start,
|
|
|
|
float end,
|
|
|
|
float hradius,
|
|
|
|
float vradius)
|
|
|
|
{
|
2020-09-21 19:19:19 +00:00
|
|
|
const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
|
2020-09-18 12:42:36 +00:00
|
|
|
OpRadialGradient *op;
|
|
|
|
|
|
|
|
/* TODO: State tracking? */
|
|
|
|
|
|
|
|
op = ops_begin (self, OP_CHANGE_RADIAL_GRADIENT);
|
|
|
|
op->n_color_stops.value = real_n_color_stops;
|
|
|
|
op->n_color_stops.send = true;
|
|
|
|
op->color_stops.value = color_stops;
|
|
|
|
op->color_stops.send = true;
|
|
|
|
op->center[0] = center_x;
|
|
|
|
op->center[1] = center_y;
|
|
|
|
op->radius[0] = hradius;
|
|
|
|
op->radius[1] = vradius;
|
|
|
|
op->start = start;
|
|
|
|
op->end = end;
|
|
|
|
}
|
2020-12-03 05:02:18 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ops_set_conic_gradient (RenderOpBuilder *self,
|
|
|
|
guint n_color_stops,
|
|
|
|
const GskColorStop *color_stops,
|
|
|
|
float center_x,
|
|
|
|
float center_y,
|
|
|
|
float rotation)
|
|
|
|
{
|
|
|
|
const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
|
|
|
|
OpConicGradient *op;
|
|
|
|
|
|
|
|
/* TODO: State tracking? */
|
|
|
|
|
|
|
|
op = ops_begin (self, OP_CHANGE_CONIC_GRADIENT);
|
|
|
|
op->n_color_stops.value = real_n_color_stops;
|
|
|
|
op->n_color_stops.send = true;
|
|
|
|
op->color_stops.value = color_stops;
|
|
|
|
op->color_stops.send = true;
|
|
|
|
op->center[0] = center_x;
|
|
|
|
op->center[1] = center_y;
|
|
|
|
op->rotation = rotation;
|
|
|
|
}
|
|
|
|
|