gl renderer: Sort border sides by color

This commit is contained in:
Timm Bäder 2017-12-05 13:46:29 +01:00
parent c9af94f6db
commit 39a241b763

View File

@ -112,6 +112,38 @@ rgba_to_float (const GdkRGBA *c,
f[3] = c->alpha; f[3] = c->alpha;
} }
static inline void
sort_border_sides (const GdkRGBA *colors,
int *indices)
{
gboolean done[4] = {0, 0, 0, 0};
int i, k;
int cur = 0;
for (i = 0; i < 3; i ++)
{
if (done[i])
continue;
indices[cur] = i;
done[i] = TRUE;
cur ++;
for (k = i + 1; k < 4; k ++)
{
if (gdk_rgba_equal (&colors[k], &colors[i]))
{
indices[cur] = k;
done[k] = TRUE;
cur ++;
}
}
if (cur >= 4)
break;
}
}
static void gsk_gl_renderer_setup_render_mode (GskGLRenderer *self); static void gsk_gl_renderer_setup_render_mode (GskGLRenderer *self);
static void add_offscreen_ops (GskGLRenderer *self, static void add_offscreen_ops (GskGLRenderer *self,
RenderOpBuilder *builder, RenderOpBuilder *builder,
@ -385,53 +417,61 @@ render_border_node (GskGLRenderer *self,
ops_set_program (builder, &self->color_program); ops_set_program (builder, &self->color_program);
} }
/* Top */ {
ops_set_border_color (builder, &colors[0]); const GskQuadVertex side_data[4][6] = {
ops_draw (builder, (const GskQuadVertex[6]) { /* Top */
{ { min_x, min_y }, { 0, 1 }, }, /* Upper left */ {
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 0, 0 }, }, /* Lower left */ { { min_x, min_y }, { 0, 1 }, }, /* Upper left */
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */ { { min_x + sizes[0].w, min_y + sizes[0].h }, { 0, 0 }, }, /* Lower left */
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */
{ { max_x - sizes[1].w, min_y + sizes[1].h }, { 1, 0 }, }, /* Lower right */ { { max_x - sizes[1].w, min_y + sizes[1].h }, { 1, 0 }, }, /* Lower right */
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 0, 0 }, }, /* Lower left */ { { min_x + sizes[0].w, min_y + sizes[0].h }, { 0, 0 }, }, /* Lower left */
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */ { { max_x, min_y }, { 1, 1 }, }, /* Upper right */
}); },
/* Right */
{
{ { max_x - sizes[1].w, min_y + sizes[1].h }, { 0, 1 }, }, /* Upper left */
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 0, 0 }, }, /* Lower left */
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */
/* Right */ { { max_x, max_y }, { 1, 0 }, }, /* Lower right */
ops_set_border_color (builder, &colors[1]); { { max_x - sizes[2].w, max_y - sizes[2].h }, { 0, 0 }, }, /* Lower left */
ops_draw (builder, (const GskQuadVertex[6]) { { { max_x, min_y }, { 1, 1 }, }, /* Upper right */
{ { max_x - sizes[1].w, min_y + sizes[1].h }, { 0, 1 }, }, /* Upper left */ },
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 0, 0 }, }, /* Lower left */ /* Bottom */
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */ {
{ { min_x + sizes[3].w, max_y - sizes[3].h }, { 0, 1 }, }, /* Upper left */
{ { min_x, max_y }, { 0, 0 }, }, /* Lower left */
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 1, 1 }, }, /* Upper right */
{ { max_x, max_y }, { 1, 0 }, }, /* Lower right */ { { max_x, max_y }, { 1, 0 }, }, /* Lower right */
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 0, 0 }, }, /* Lower left */ { { min_x , max_y }, { 0, 0 }, }, /* Lower left */
{ { max_x, min_y }, { 1, 1 }, }, /* Upper right */ { { max_x - sizes[2].w, max_y - sizes[2].h }, { 1, 1 }, }, /* Upper right */
}); },
/* Left */
{
{ { min_x, min_y }, { 0, 1 }, }, /* Upper left */
{ { min_x, max_y }, { 0, 0 }, }, /* Lower left */
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 1, 1 }, }, /* Upper right */
/* Bottom */ { { min_x + sizes[3].w, max_y - sizes[2].h }, { 1, 0 }, }, /* Lower right */
ops_set_border_color (builder, &colors[2]); { { min_x, max_y }, { 0, 0 }, }, /* Lower left */
ops_draw (builder, (const GskQuadVertex[6]) { { { min_x + sizes[0].w, min_y + sizes[0].h }, { 1, 1 }, }, /* Upper right */
{ { min_x + sizes[3].w, max_y - sizes[3].h }, { 0, 1 }, }, /* Upper left */ }
{ { min_x, max_y }, { 0, 0 }, }, /* Lower left */ };
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 1, 1 }, }, /* Upper right */ int indices[4] = { 0, 1, 2, 3 };
int i;
{ { max_x, max_y }, { 1, 0 }, }, /* Lower right */ /* We sort them by color */
{ { min_x , max_y }, { 0, 0 }, }, /* Lower left */ sort_border_sides (colors, indices);
{ { max_x - sizes[2].w, max_y - sizes[2].h }, { 1, 1 }, }, /* Upper right */
});
/* Left */ for (i = 0; i < 4; i ++)
ops_set_border_color (builder, &colors[3]); {
ops_draw (builder, (const GskQuadVertex[6]) { ops_set_border_color (builder, &colors[indices[i]]);
{ { min_x, min_y }, { 0, 1 }, }, /* Upper left */ ops_draw (builder, side_data[indices[i]]);
{ { min_x, max_y }, { 0, 0 }, }, /* Lower left */ }
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 1, 1 }, }, /* Upper right */ }
{ { min_x + sizes[3].w, max_y - sizes[2].h }, { 1, 0 }, }, /* Lower right */
{ { min_x, max_y }, { 0, 0 }, }, /* Lower left */
{ { min_x + sizes[0].w, min_y + sizes[0].h }, { 1, 1 }, }, /* Upper right */
});
if (needs_clip) if (needs_clip)
ops_set_clip (builder, &prev_clip); ops_set_clip (builder, &prev_clip);