Merge branch 'ngl-clip-classification' into 'master'

Ngl clip classification

See merge request GNOME/gtk!3274
This commit is contained in:
Matthias Clasen 2021-03-08 20:20:50 +00:00
commit 07ca46e92c
8 changed files with 368 additions and 147 deletions

View File

@ -523,6 +523,7 @@ get_shader_string (GBytes *bytes)
GskNglProgram *
gsk_ngl_compiler_compile (GskNglCompiler *self,
const char *name,
const char *clip,
GError **error)
{
char version[32];
@ -561,9 +562,10 @@ gsk_ngl_compiler_compile (GskNglCompiler *self,
vertex_id = glCreateShader (GL_VERTEX_SHADER);
glShaderSource (vertex_id,
9,
10,
(const char *[]) {
version, debug, legacy, gl3, gles,
clip,
get_shader_string (self->all_preamble),
get_shader_string (self->vertex_preamble),
get_shader_string (self->vertex_source),
@ -575,6 +577,7 @@ gsk_ngl_compiler_compile (GskNglCompiler *self,
strlen (legacy),
strlen (gl3),
strlen (gles),
strlen (clip),
g_bytes_get_size (self->all_preamble),
g_bytes_get_size (self->vertex_preamble),
g_bytes_get_size (self->vertex_source),
@ -592,9 +595,10 @@ gsk_ngl_compiler_compile (GskNglCompiler *self,
fragment_id = glCreateShader (GL_FRAGMENT_SHADER);
glShaderSource (fragment_id,
9,
10,
(const char *[]) {
version, debug, legacy, gl3, gles,
clip,
get_shader_string (self->all_preamble),
get_shader_string (self->fragment_preamble),
get_shader_string (self->fragment_source),
@ -606,6 +610,7 @@ gsk_ngl_compiler_compile (GskNglCompiler *self,
strlen (legacy),
strlen (gl3),
strlen (gles),
strlen (clip),
g_bytes_get_size (self->all_preamble),
g_bytes_get_size (self->fragment_preamble),
g_bytes_get_size (self->fragment_source),

View File

@ -62,6 +62,7 @@ void gsk_ngl_compiler_bind_attribute (GskNglCompiler
void gsk_ngl_compiler_clear_attributes (GskNglCompiler *self);
GskNglProgram *gsk_ngl_compiler_compile (GskNglCompiler *self,
const char *name,
const char *clip,
GError **error);
G_END_DECLS

View File

@ -225,6 +225,10 @@ gsk_ngl_driver_dispose (GObject *object)
#define GSK_NGL_NO_UNIFORMS
#define GSK_NGL_ADD_UNIFORM(pos, KEY, name)
#define GSK_NGL_DEFINE_PROGRAM(name, resource, uniforms) \
GSK_NGL_DELETE_PROGRAM(name); \
GSK_NGL_DELETE_PROGRAM(name ## _no_clip); \
GSK_NGL_DELETE_PROGRAM(name ## _rect_clip);
#define GSK_NGL_DELETE_PROGRAM(name) \
G_STMT_START { \
if (self->name) \
gsk_ngl_program_delete (self->name); \
@ -349,34 +353,38 @@ gsk_ngl_driver_load_programs (GskNglDriver *self,
#define GSK_NGL_ADD_UNIFORM(pos, KEY, name) \
gsk_ngl_program_add_uniform (program, #name, UNIFORM_##KEY);
#define GSK_NGL_DEFINE_PROGRAM(name, resource, uniforms) \
G_STMT_START { \
gsk_ngl_compiler_set_source_from_resource (compiler, GSK_NGL_COMPILER_ALL, resource); \
GSK_NGL_COMPILE_PROGRAM(name ## _no_clip, uniforms, "#define NO_CLIP 1\n"); \
GSK_NGL_COMPILE_PROGRAM(name ## _rect_clip, uniforms, "#define RECT_CLIP 1\n"); \
GSK_NGL_COMPILE_PROGRAM(name, uniforms, "");
#define GSK_NGL_COMPILE_PROGRAM(name, uniforms, clip) \
G_STMT_START { \
GskNglProgram *program; \
gboolean have_alpha; \
gboolean have_source; \
\
gsk_ngl_compiler_set_source_from_resource (compiler, GSK_NGL_COMPILER_ALL, resource); \
\
if (!(program = gsk_ngl_compiler_compile (compiler, #name, error))) \
goto failure; \
\
gboolean have_alpha; \
gboolean have_source; \
\
if (!(program = gsk_ngl_compiler_compile (compiler, #name, clip, error))) \
goto failure; \
\
have_alpha = gsk_ngl_program_add_uniform (program, "u_alpha", UNIFORM_SHARED_ALPHA); \
have_source = gsk_ngl_program_add_uniform (program, "u_source", UNIFORM_SHARED_SOURCE); \
gsk_ngl_program_add_uniform (program, "u_clip_rect", UNIFORM_SHARED_CLIP_RECT); \
gsk_ngl_program_add_uniform (program, "u_viewport", UNIFORM_SHARED_VIEWPORT); \
gsk_ngl_program_add_uniform (program, "u_projection", UNIFORM_SHARED_PROJECTION); \
gsk_ngl_program_add_uniform (program, "u_modelview", UNIFORM_SHARED_MODELVIEW); \
\
uniforms \
\
\
uniforms \
\
gsk_ngl_program_uniforms_added (program, have_source); \
\
if (have_alpha) \
\
if (have_alpha) \
gsk_ngl_program_set_uniform1f (program, UNIFORM_SHARED_ALPHA, 0, 1.0f); \
\
*(GskNglProgram **)(((guint8 *)self) + G_STRUCT_OFFSET (GskNglDriver, name)) = \
g_steal_pointer (&program); \
\
*(GskNglProgram **)(((guint8 *)self) + G_STRUCT_OFFSET (GskNglDriver, name)) = \
g_steal_pointer (&program); \
} G_STMT_END;
# include "gsknglprograms.defs"
#undef GSK_NGL_DEFINE_PROGRAM_CLIP
#undef GSK_NGL_DEFINE_PROGRAM
#undef GSK_NGL_ADD_UNIFORM
@ -1038,7 +1046,7 @@ gsk_ngl_driver_lookup_shader (GskNglDriver *self,
gsk_ngl_compiler_bind_attribute (compiler, "aPosition", 0);
gsk_ngl_compiler_bind_attribute (compiler, "aUv", 1);
if ((program = gsk_ngl_compiler_compile (compiler, NULL, error)))
if ((program = gsk_ngl_compiler_compile (compiler, NULL, "", error)))
{
gboolean have_alpha;

View File

@ -106,7 +106,10 @@ struct _GskNglDriver
#define GSK_NGL_NO_UNIFORMS
#define GSK_NGL_ADD_UNIFORM(pos, KEY, name)
#define GSK_NGL_DEFINE_PROGRAM(name, resource, uniforms) GskNglProgram *name;
#define GSK_NGL_DEFINE_PROGRAM(name, resource, uniforms) \
GskNglProgram *name ## _no_clip; \
GskNglProgram *name ## _rect_clip; \
GskNglProgram *name;
# include "gsknglprograms.defs"
#undef GSK_NGL_NO_UNIFORMS
#undef GSK_NGL_ADD_UNIFORM

View File

@ -80,6 +80,7 @@ typedef struct _GskNglRenderClip
{
GskRoundedRect rect;
guint is_rectilinear : 1;
guint is_fully_contained : 1;
} GskNglRenderClip;
typedef struct _GskNglRenderModelview
@ -154,6 +155,7 @@ struct _GskNglRenderJob
/* Cached pointers */
const GskNglRenderClip *current_clip;
const GskNglRenderModelview *current_modelview;
GskNglProgram *current_program;
/* If we should be rendering red zones over fallback nodes */
guint debug_fallback : 1;
@ -583,6 +585,32 @@ gsk_ngl_render_job_push_clip (GskNglRenderJob *job,
clip = &g_array_index (job->clip, GskNglRenderClip, job->clip->len - 1);
memcpy (&clip->rect, rect, sizeof *rect);
clip->is_rectilinear = gsk_rounded_rect_is_rectilinear (rect);
clip->is_fully_contained = FALSE;
job->current_clip = clip;
}
static void
gsk_ngl_render_job_push_contained_clip (GskNglRenderJob *job)
{
GskNglRenderClip *clip;
GskNglRenderClip *old_clip;
g_assert (job != NULL);
g_assert (job->clip != NULL);
g_assert (job->clip->len > 0);
job->driver->stamps[UNIFORM_SHARED_CLIP_RECT]++;
old_clip = &g_array_index (job->clip, GskNglRenderClip, job->clip->len - 1);
g_array_set_size (job->clip, job->clip->len + 1);
clip = &g_array_index (job->clip, GskNglRenderClip, job->clip->len - 1);
memcpy (&clip->rect.bounds, &old_clip->rect.bounds, sizeof (graphene_rect_t));
memset (clip->rect.corner, 0, sizeof clip->rect.corner);
clip->is_rectilinear = TRUE;
clip->is_fully_contained = TRUE;
job->current_clip = clip;
}
@ -742,13 +770,108 @@ gsk_ngl_render_job_transform_rounded_rect (GskNglRenderJob *job,
memcpy (out_rect->corner, rect->corner, sizeof rect->corner);
}
static inline void
rounded_rect_get_inner (const GskRoundedRect *rect,
graphene_rect_t *inner)
{
float left = MAX (rect->corner[GSK_CORNER_TOP_LEFT].width, rect->corner[GSK_CORNER_BOTTOM_LEFT].width);
float right = MAX (rect->corner[GSK_CORNER_TOP_RIGHT].width, rect->corner[GSK_CORNER_BOTTOM_RIGHT].width);
float top = MAX (rect->corner[GSK_CORNER_TOP_LEFT].height, rect->corner[GSK_CORNER_TOP_RIGHT].height);
float bottom = MAX (rect->corner[GSK_CORNER_BOTTOM_LEFT].height, rect->corner[GSK_CORNER_BOTTOM_RIGHT].height);
inner->origin.x = rect->bounds.origin.x + left;
inner->size.width = rect->bounds.size.width - (left + right);
inner->origin.y = rect->bounds.origin.y + top;
inner->size.height = rect->bounds.size.height - (top + bottom);
}
static inline gboolean
gsk_ngl_render_job_node_overlaps_clip (GskNglRenderJob *job,
const GskRenderNode *node)
interval_contains (float p1, float w1,
float p2, float w2)
{
if (p2 < p1)
return FALSE;
if (p2 + w2 > p1 + w1)
return FALSE;
return TRUE;
}
static inline gboolean
gsk_ngl_render_job_update_clip (GskNglRenderJob *job,
const GskRenderNode *node,
gboolean *pushed_clip)
{
graphene_rect_t transformed_bounds;
gboolean no_clip = FALSE;
gboolean rect_clip = FALSE;
*pushed_clip = FALSE;
if (job->current_clip->is_fully_contained)
{
/* Already fully contained - no further checks needed */
return TRUE;
}
gsk_ngl_render_job_transform_bounds (job, &node->bounds, &transformed_bounds);
return rect_intersects (&job->current_clip->rect.bounds, &transformed_bounds);
if (!rect_intersects (&job->current_clip->rect.bounds, &transformed_bounds))
{
/* Completely clipped away */
return FALSE;
}
if (job->current_clip->is_rectilinear)
{
if (rect_contains_rect (&job->current_clip->rect.bounds, &transformed_bounds))
no_clip = TRUE;
else
rect_clip = TRUE;
}
else if (gsk_rounded_rect_contains_rect (&job->current_clip->rect, &transformed_bounds))
{
no_clip = TRUE;
}
else
{
graphene_rect_t inner;
rounded_rect_get_inner (&job->current_clip->rect, &inner);
if (interval_contains (inner.origin.x, inner.size.width,
transformed_bounds.origin.x, transformed_bounds.size.width) ||
interval_contains (inner.origin.y, inner.size.height,
transformed_bounds.origin.y, transformed_bounds.size.height))
rect_clip = TRUE;
}
if (no_clip)
{
/* This node is completely contained inside the clip.
* Record this fact on the clip stack, so we don't do more work
* for child nodes.
*/
gsk_ngl_render_job_push_contained_clip (job);
*pushed_clip = TRUE;
}
else if (rect_clip && !job->current_clip->is_rectilinear)
{
graphene_rect_t rect;
/* The clip gets simpler for this node */
graphene_rect_intersection (&job->current_clip->rect.bounds, &transformed_bounds, &rect);
gsk_ngl_render_job_push_clip (job, &GSK_ROUNDED_RECT_INIT_FROM_RECT (rect));
*pushed_clip = TRUE;
}
return TRUE;
}
/* load_vertex_data_with_region */
@ -911,6 +1034,8 @@ static inline void
gsk_ngl_render_job_begin_draw (GskNglRenderJob *job,
GskNglProgram *program)
{
job->current_program = program;
gsk_ngl_command_queue_begin_draw (job->command_queue,
program->program_info,
job->viewport.size.width,
@ -953,6 +1078,13 @@ gsk_ngl_render_job_begin_draw (GskNglRenderJob *job,
job->alpha);
}
#define CHOOSE_PROGRAM(job,name) \
(job->current_clip->is_fully_contained \
? job->driver->name ## _no_clip \
: (job->current_clip->is_rectilinear \
? job->driver->name ## _rect_clip \
: job->driver->name))
static inline void
gsk_ngl_render_job_split_draw (GskNglRenderJob *job)
{
@ -963,6 +1095,8 @@ static inline void
gsk_ngl_render_job_end_draw (GskNglRenderJob *job)
{
gsk_ngl_command_queue_end_draw (job->command_queue);
job->current_program = NULL;
}
static inline void
@ -994,8 +1128,8 @@ gsk_ngl_render_job_visit_as_fallback (GskNglRenderJob *job,
if (cached_id != 0)
{
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D, GL_TEXTURE0, cached_id);
gsk_ngl_render_job_draw_offscreen_rect (job, &node->bounds);
@ -1073,8 +1207,8 @@ gsk_ngl_render_job_visit_as_fallback (GskNglRenderJob *job,
gsk_ngl_driver_cache_texture (job->driver, &key, texture_id);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -1133,20 +1267,20 @@ blur_offscreen (GskNglRenderJob *job,
/* Begin drawing the first horizontal pass, using offscreen as the
* source texture for the program.
*/
gsk_ngl_render_job_begin_draw (job, job->driver->blur);
gsk_ngl_program_set_uniform_texture (job->driver->blur,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blur));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
offscreen->texture_id);
gsk_ngl_program_set_uniform1f (job->driver->blur,
gsk_ngl_program_set_uniform1f (job->current_program,
UNIFORM_BLUR_RADIUS, 0,
blur_radius_x);
gsk_ngl_program_set_uniform2f (job->driver->blur,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_BLUR_SIZE, 0,
texture_to_blur_width,
texture_to_blur_height);
gsk_ngl_program_set_uniform2f (job->driver->blur,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_BLUR_DIR, 0,
1, 0);
gsk_ngl_render_job_draw_coords (job, 0, 0, texture_to_blur_width, texture_to_blur_height);
@ -1157,20 +1291,20 @@ blur_offscreen (GskNglRenderJob *job,
gsk_ngl_command_queue_clear (job->command_queue, 0, &job->viewport);
/* Draw using blur program with first pass as source texture */
gsk_ngl_render_job_begin_draw (job, job->driver->blur);
gsk_ngl_program_set_uniform_texture (job->driver->blur,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blur));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
pass1->texture_id);
gsk_ngl_program_set_uniform1f (job->driver->blur,
gsk_ngl_program_set_uniform1f (job->current_program,
UNIFORM_BLUR_RADIUS, 0,
blur_radius_y);
gsk_ngl_program_set_uniform2f (job->driver->blur,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_BLUR_SIZE, 0,
texture_to_blur_width,
texture_to_blur_height);
gsk_ngl_program_set_uniform2f (job->driver->blur,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_BLUR_DIR, 0,
0, 1);
gsk_ngl_render_job_draw_coords (job, 0, 0, texture_to_blur_width, texture_to_blur_height);
@ -1246,8 +1380,8 @@ static inline void
gsk_ngl_render_job_visit_color_node (GskNglRenderJob *job,
const GskRenderNode *node)
{
gsk_ngl_render_job_begin_draw (job, job->driver->color);
gsk_ngl_program_set_uniform_color (job->driver->color,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, color));
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_COLOR_COLOR, 0,
gsk_color_node_get_color (node));
gsk_ngl_render_job_draw_rect (job, &node->bounds);
@ -1270,18 +1404,18 @@ gsk_ngl_render_job_visit_linear_gradient_node (GskNglRenderJob *job,
g_assert (n_color_stops < MAX_GRADIENT_STOPS);
gsk_ngl_render_job_begin_draw (job, job->driver->linear_gradient);
gsk_ngl_program_set_uniform1i (job->driver->linear_gradient,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, linear_gradient));
gsk_ngl_program_set_uniform1i (job->current_program,
UNIFORM_LINEAR_GRADIENT_NUM_COLOR_STOPS, 0,
n_color_stops);
gsk_ngl_program_set_uniform1fv (job->driver->linear_gradient,
gsk_ngl_program_set_uniform1fv (job->current_program,
UNIFORM_LINEAR_GRADIENT_COLOR_STOPS, 0,
n_color_stops * 5,
(const float *)stops);
gsk_ngl_program_set_uniform4f (job->driver->linear_gradient,
gsk_ngl_program_set_uniform4f (job->current_program,
UNIFORM_LINEAR_GRADIENT_POINTS, 0,
x1, y1, x2 - x1, y2 - y1);
gsk_ngl_program_set_uniform1i (job->driver->linear_gradient,
gsk_ngl_program_set_uniform1i (job->current_program,
UNIFORM_LINEAR_GRADIENT_REPEAT, 0,
repeat);
gsk_ngl_render_job_draw_rect (job, &node->bounds);
@ -1302,15 +1436,15 @@ gsk_ngl_render_job_visit_conic_gradient_node (GskNglRenderJob *job,
g_assert (n_color_stops < MAX_GRADIENT_STOPS);
gsk_ngl_render_job_begin_draw (job, job->driver->conic_gradient);
gsk_ngl_program_set_uniform1i (job->driver->conic_gradient,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, conic_gradient));
gsk_ngl_program_set_uniform1i (job->current_program,
UNIFORM_CONIC_GRADIENT_NUM_COLOR_STOPS, 0,
n_color_stops);
gsk_ngl_program_set_uniform1fv (job->driver->conic_gradient,
gsk_ngl_program_set_uniform1fv (job->current_program,
UNIFORM_CONIC_GRADIENT_COLOR_STOPS, 0,
n_color_stops * 5,
(const float *)stops);
gsk_ngl_program_set_uniform4f (job->driver->conic_gradient,
gsk_ngl_program_set_uniform4f (job->current_program,
UNIFORM_CONIC_GRADIENT_GEOMETRY, 0,
job->offset_x + center->x,
job->offset_y + center->y,
@ -1337,21 +1471,21 @@ gsk_ngl_render_job_visit_radial_gradient_node (GskNglRenderJob *job,
g_assert (n_color_stops < MAX_GRADIENT_STOPS);
gsk_ngl_render_job_begin_draw (job, job->driver->radial_gradient);
gsk_ngl_program_set_uniform1i (job->driver->radial_gradient,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, radial_gradient));
gsk_ngl_program_set_uniform1i (job->current_program,
UNIFORM_RADIAL_GRADIENT_NUM_COLOR_STOPS, 0,
n_color_stops);
gsk_ngl_program_set_uniform1fv (job->driver->radial_gradient,
gsk_ngl_program_set_uniform1fv (job->current_program,
UNIFORM_RADIAL_GRADIENT_COLOR_STOPS, 0,
n_color_stops * 5,
(const float *)stops);
gsk_ngl_program_set_uniform1i (job->driver->radial_gradient,
gsk_ngl_program_set_uniform1i (job->current_program,
UNIFORM_RADIAL_GRADIENT_REPEAT, 0,
repeat);
gsk_ngl_program_set_uniform2f (job->driver->radial_gradient,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_RADIAL_GRADIENT_RANGE, 0,
scale, bias);
gsk_ngl_program_set_uniform4f (job->driver->radial_gradient,
gsk_ngl_program_set_uniform4f (job->current_program,
UNIFORM_RADIAL_GRADIENT_GEOMETRY, 0,
job->offset_x + center->x,
job->offset_y + center->y,
@ -1409,8 +1543,8 @@ gsk_ngl_render_job_visit_clipped_child (GskNglRenderJob *job,
g_assert (offscreen.texture_id);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -1507,8 +1641,8 @@ gsk_ngl_render_job_visit_rounded_clip_node (GskNglRenderJob *job,
g_assert (offscreen.texture_id);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -1560,17 +1694,17 @@ gsk_ngl_render_job_visit_uniform_border_node (GskNglRenderJob *job,
gsk_ngl_render_job_transform_rounded_rect (job, rounded_outline, &outline);
gsk_ngl_render_job_begin_draw (job, job->driver->inset_shadow);
gsk_ngl_program_set_uniform_rounded_rect (job->driver->inset_shadow,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, inset_shadow));
gsk_ngl_program_set_uniform_rounded_rect (job->current_program,
UNIFORM_INSET_SHADOW_OUTLINE_RECT, 0,
&outline);
gsk_ngl_program_set_uniform_color (job->driver->inset_shadow,
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_INSET_SHADOW_COLOR, 0,
&colors[0]);
gsk_ngl_program_set_uniform1f (job->driver->inset_shadow,
gsk_ngl_program_set_uniform1f (job->current_program,
UNIFORM_INSET_SHADOW_SPREAD, 0,
widths[0]);
gsk_ngl_program_set_uniform2f (job->driver->inset_shadow,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_INSET_SHADOW_OFFSET, 0,
0, 0);
gsk_ngl_render_job_draw_rect (job, &node->bounds);
@ -1683,6 +1817,7 @@ gsk_ngl_render_job_visit_border_node (GskNglRenderJob *job,
};
int indices[4] = { 0, 1, 2, 3 };
GskRoundedRect outline;
GskNglProgram *program;
/* We sort them by color */
sort_border_sides (colors, indices);
@ -1690,11 +1825,13 @@ gsk_ngl_render_job_visit_border_node (GskNglRenderJob *job,
/* Prepare outline */
gsk_ngl_render_job_transform_rounded_rect (job, rounded_outline, &outline);
gsk_ngl_program_set_uniform4fv (job->driver->border,
program = CHOOSE_PROGRAM (job, border);
gsk_ngl_program_set_uniform4fv (program,
UNIFORM_BORDER_WIDTHS, 0,
1,
widths);
gsk_ngl_program_set_uniform_rounded_rect (job->driver->border,
gsk_ngl_program_set_uniform_rounded_rect (program,
UNIFORM_BORDER_OUTLINE_RECT, 0,
&outline);
@ -1705,8 +1842,8 @@ gsk_ngl_render_job_visit_border_node (GskNglRenderJob *job,
if (widths[indices[i]] <= 0)
continue;
gsk_ngl_render_job_begin_draw (job, job->driver->border);
gsk_ngl_program_set_uniform4fv (job->driver->border,
gsk_ngl_render_job_begin_draw (job, program);
gsk_ngl_program_set_uniform4fv (job->current_program,
UNIFORM_BORDER_COLOR, 0,
1,
(const float *)&colors[indices[i]]);
@ -1811,8 +1948,8 @@ gsk_ngl_render_job_visit_transform_node (GskNglRenderJob *job,
*/
gsk_ngl_render_job_push_modelview (job, transform);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -1839,17 +1976,17 @@ gsk_ngl_render_job_visit_unblurred_inset_shadow_node (GskNglRenderJob *job,
gsk_ngl_render_job_transform_rounded_rect (job, outline, &transformed_outline);
gsk_ngl_render_job_begin_draw (job, job->driver->inset_shadow);
gsk_ngl_program_set_uniform_rounded_rect (job->driver->inset_shadow,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, inset_shadow));
gsk_ngl_program_set_uniform_rounded_rect (job->current_program,
UNIFORM_INSET_SHADOW_OUTLINE_RECT, 0,
&transformed_outline);
gsk_ngl_program_set_uniform_color (job->driver->inset_shadow,
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_INSET_SHADOW_COLOR, 0,
gsk_inset_shadow_node_get_color (node));
gsk_ngl_program_set_uniform1f (job->driver->inset_shadow,
gsk_ngl_program_set_uniform1f (job->current_program,
UNIFORM_INSET_SHADOW_SPREAD, 0,
gsk_inset_shadow_node_get_spread (node));
gsk_ngl_program_set_uniform2f (job->driver->inset_shadow,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_INSET_SHADOW_OFFSET, 0,
gsk_inset_shadow_node_get_dx (node),
gsk_inset_shadow_node_get_dy (node));
@ -1942,17 +2079,17 @@ gsk_ngl_render_job_visit_blurred_inset_shadow_node (GskNglRenderJob *job,
gsk_ngl_render_job_transform_rounded_rect (job, &outline_to_blur, &transformed_outline);
/* Actual inset shadow outline drawing */
gsk_ngl_render_job_begin_draw (job, job->driver->inset_shadow);
gsk_ngl_program_set_uniform_rounded_rect (job->driver->inset_shadow,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, inset_shadow));
gsk_ngl_program_set_uniform_rounded_rect (job->current_program,
UNIFORM_INSET_SHADOW_OUTLINE_RECT, 0,
&transformed_outline);
gsk_ngl_program_set_uniform_color (job->driver->inset_shadow,
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_INSET_SHADOW_COLOR, 0,
gsk_inset_shadow_node_get_color (node));
gsk_ngl_program_set_uniform1f (job->driver->inset_shadow,
gsk_ngl_program_set_uniform1f (job->current_program,
UNIFORM_INSET_SHADOW_SPREAD, 0,
spread * MAX (scale_x, scale_y));
gsk_ngl_program_set_uniform2f (job->driver->inset_shadow,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_INSET_SHADOW_OFFSET, 0,
offset_x * scale_x,
offset_y * scale_y);
@ -2012,8 +2149,8 @@ gsk_ngl_render_job_visit_blurred_inset_shadow_node (GskNglRenderJob *job,
offscreen.area.x2 = tx2;
offscreen.area.y2 = ty2;
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -2051,17 +2188,17 @@ gsk_ngl_render_job_visit_unblurred_outset_shadow_node (GskNglRenderJob *job,
gsk_ngl_render_job_transform_rounded_rect (job, outline, &transformed_outline);
gsk_ngl_render_job_begin_draw (job, job->driver->unblurred_outset_shadow);
gsk_ngl_program_set_uniform_rounded_rect (job->driver->unblurred_outset_shadow,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, unblurred_outset_shadow));
gsk_ngl_program_set_uniform_rounded_rect (job->current_program,
UNIFORM_UNBLURRED_OUTSET_SHADOW_OUTLINE_RECT, 0,
&transformed_outline);
gsk_ngl_program_set_uniform_color (job->driver->unblurred_outset_shadow,
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_UNBLURRED_OUTSET_SHADOW_COLOR, 0,
gsk_outset_shadow_node_get_color (node));
gsk_ngl_program_set_uniform1f (job->driver->unblurred_outset_shadow,
gsk_ngl_program_set_uniform1f (job->current_program,
UNIFORM_UNBLURRED_OUTSET_SHADOW_SPREAD, 0,
spread);
gsk_ngl_program_set_uniform2f (job->driver->unblurred_outset_shadow,
gsk_ngl_program_set_uniform2f (job->current_program,
UNIFORM_UNBLURRED_OUTSET_SHADOW_OFFSET, 0,
dx, dy);
@ -2207,8 +2344,8 @@ gsk_ngl_render_job_visit_blurred_outset_shadow_node (GskNglRenderJob *job,
gsk_ngl_command_queue_clear (job->command_queue, 0, &job->viewport);
/* Draw the outline using color program */
gsk_ngl_render_job_begin_draw (job, job->driver->color);
gsk_ngl_program_set_uniform_color (job->driver->color,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, color));
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_COLOR_COLOR, 0,
&white);
gsk_ngl_render_job_draw (job, 0, 0, texture_width, texture_height);
@ -2253,16 +2390,16 @@ gsk_ngl_render_job_visit_blurred_outset_shadow_node (GskNglRenderJob *job,
offscreen.texture_id = blurred_texture_id;
init_full_texture_region (&offscreen);
gsk_ngl_render_job_begin_draw (job, job->driver->outset_shadow);
gsk_ngl_program_set_uniform_color (job->driver->outset_shadow,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, outset_shadow));
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_OUTSET_SHADOW_COLOR, 0,
color);
gsk_ngl_program_set_uniform_texture (job->driver->outset_shadow,
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
blurred_texture_id);
gsk_ngl_program_set_uniform_rounded_rect (job->driver->outset_shadow,
gsk_ngl_program_set_uniform_rounded_rect (job->current_program,
UNIFORM_OUTSET_SHADOW_OUTLINE_RECT, 0,
&transformed_outline);
gsk_ngl_render_job_load_vertices_from_offscreen (job,
@ -2276,16 +2413,16 @@ gsk_ngl_render_job_visit_blurred_outset_shadow_node (GskNglRenderJob *job,
return;
}
gsk_ngl_render_job_begin_draw (job, job->driver->outset_shadow);
gsk_ngl_program_set_uniform_color (job->driver->outset_shadow,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, outset_shadow));
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_OUTSET_SHADOW_COLOR, 0,
color);
gsk_ngl_program_set_uniform_texture (job->driver->outset_shadow,
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
blurred_texture_id);
gsk_ngl_program_set_uniform_rounded_rect (job->driver->outset_shadow,
gsk_ngl_program_set_uniform_rounded_rect (job->current_program,
UNIFORM_OUTSET_SHADOW_OUTLINE_RECT, 0,
&transformed_outline);
@ -2483,18 +2620,18 @@ gsk_ngl_render_job_visit_cross_fade_node (GskNglRenderJob *job,
g_assert (offscreen_end.texture_id);
gsk_ngl_render_job_begin_draw (job, job->driver->cross_fade);
gsk_ngl_program_set_uniform_texture (job->driver->cross_fade,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, cross_fade));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
offscreen_start.texture_id);
gsk_ngl_program_set_uniform_texture (job->driver->cross_fade,
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_CROSS_FADE_SOURCE2, 0,
GL_TEXTURE_2D,
GL_TEXTURE1,
offscreen_end.texture_id);
gsk_ngl_program_set_uniform1f (job->driver->cross_fade,
gsk_ngl_program_set_uniform1f (job->current_program,
UNIFORM_CROSS_FADE_PROGRESS, 0,
progress);
gsk_ngl_render_job_load_vertices_from_offscreen (job, &node->bounds, &offscreen_end);
@ -2529,8 +2666,8 @@ gsk_ngl_render_job_visit_opacity_node (GskNglRenderJob *job,
g_assert (offscreen.texture_id);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -2562,9 +2699,9 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job,
float y = offset->y + job->offset_y;
GskNglGlyphLibrary *library = job->driver->glyphs;
GskNglCommandBatch *batch;
GskNglProgram *program;
int x_position = 0;
GskNglGlyphKey lookup;
GskNglProgram *program;
guint last_texture = 0;
GskNglDrawVertex *vertices;
guint used = 0;
@ -2575,11 +2712,11 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job,
/* If the font has color glyphs, we don't need to recolor anything */
if (!force_color && gsk_text_node_has_color_glyphs (node))
{
program = job->driver->blit;
program = CHOOSE_PROGRAM (job, blit);
}
else
{
program = job->driver->coloring;
program = CHOOSE_PROGRAM (job, coloring);
gsk_ngl_program_set_uniform_color (program, UNIFORM_COLORING_COLOR, 0, color);
}
@ -2587,6 +2724,7 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job,
lookup.scale = (guint) (text_scale * 1024);
gsk_ngl_render_job_begin_draw (job, program);
batch = gsk_ngl_command_queue_get_batch (job->command_queue);
vertices = gsk_ngl_command_queue_add_n_vertices (job->command_queue, num_glyphs);
@ -2771,13 +2909,13 @@ gsk_ngl_render_job_visit_shadow_node (GskNglRenderJob *job,
}
gsk_ngl_render_job_offset (job, dx, dy);
gsk_ngl_render_job_begin_draw (job, job->driver->coloring);
gsk_ngl_program_set_uniform_texture (job->driver->coloring,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, coloring));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
offscreen.texture_id);
gsk_ngl_program_set_uniform_color (job->driver->coloring,
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_COLORING_COLOR, 0,
&shadow->color);
gsk_ngl_render_job_load_vertices_from_offscreen (job, &bounds, &offscreen);
@ -2828,8 +2966,8 @@ gsk_ngl_render_job_visit_blur_node (GskNglRenderJob *job,
if (cache_texture)
gsk_ngl_driver_cache_texture (job->driver, &key, offscreen.texture_id);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -2867,8 +3005,8 @@ gsk_ngl_render_job_visit_blend_node (GskNglRenderJob *job,
if (!gsk_ngl_render_job_visit_node_with_offscreen (job, top_child, &top_offscreen))
{
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -2880,18 +3018,18 @@ gsk_ngl_render_job_visit_blend_node (GskNglRenderJob *job,
g_assert (top_offscreen.was_offscreen);
gsk_ngl_render_job_begin_draw (job, job->driver->blend);
gsk_ngl_program_set_uniform_texture (job->driver->blend,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blend));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
bottom_offscreen.texture_id);
gsk_ngl_program_set_uniform_texture (job->driver->blend,
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_BLEND_SOURCE2, 0,
GL_TEXTURE_2D,
GL_TEXTURE1,
top_offscreen.texture_id);
gsk_ngl_program_set_uniform1i (job->driver->blend,
gsk_ngl_program_set_uniform1i (job->current_program,
UNIFORM_BLEND_MODE, 0,
gsk_blend_node_get_blend_mode (node));
gsk_ngl_render_job_draw_offscreen_rect (job, &node->bounds);
@ -2919,16 +3057,16 @@ gsk_ngl_render_job_visit_color_matrix_node (GskNglRenderJob *job,
graphene_vec4_to_float (gsk_color_matrix_node_get_color_offset (node), offset);
gsk_ngl_render_job_begin_draw (job, job->driver->color_matrix);
gsk_ngl_program_set_uniform_texture (job->driver->color_matrix,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, color_matrix));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
offscreen.texture_id);
gsk_ngl_program_set_uniform_matrix (job->driver->color_matrix,
gsk_ngl_program_set_uniform_matrix (job->current_program,
UNIFORM_COLOR_MATRIX_COLOR_MATRIX, 0,
gsk_color_matrix_node_get_color_matrix (node));
gsk_ngl_program_set_uniform4fv (job->driver->color_matrix,
gsk_ngl_program_set_uniform4fv (job->current_program,
UNIFORM_COLOR_MATRIX_COLOR_OFFSET, 0,
1,
offset);
@ -2942,8 +3080,8 @@ gsk_ngl_render_job_visit_gl_shader_node_fallback (GskNglRenderJob *job,
{
static const GdkRGBA pink = { 255 / 255., 105 / 255., 180 / 255., 1.0 };
gsk_ngl_render_job_begin_draw (job, job->driver->color);
gsk_ngl_program_set_uniform_color (job->driver->color,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, color));
gsk_ngl_program_set_uniform_color (job->current_program,
UNIFORM_COLOR_COLOR, 0,
&pink);
gsk_ngl_render_job_draw_rect (job, &node->bounds);
@ -3108,8 +3246,8 @@ gsk_ngl_render_job_visit_texture_node (GskNglRenderJob *job,
g_assert (offscreen.texture_id);
g_assert (offscreen.was_offscreen == FALSE);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -3133,7 +3271,7 @@ gsk_ngl_render_job_visit_texture_node (GskNglRenderJob *job,
g_assert (slices != NULL);
g_assert (n_slices > 0);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
for (guint i = 0; i < n_slices; i ++)
{
@ -3148,7 +3286,7 @@ gsk_ngl_render_job_visit_texture_node (GskNglRenderJob *job,
if (i > 0)
gsk_ngl_render_job_split_draw (job);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
@ -3223,19 +3361,19 @@ gsk_ngl_render_job_visit_repeat_node (GskNglRenderJob *job,
if (!gsk_ngl_render_job_visit_node_with_offscreen (job, child, &offscreen))
g_assert_not_reached ();
gsk_ngl_render_job_begin_draw (job, job->driver->repeat);
gsk_ngl_program_set_uniform_texture (job->driver->repeat,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, repeat));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,
offscreen.texture_id);
gsk_ngl_program_set_uniform4f (job->driver->repeat,
gsk_ngl_program_set_uniform4f (job->current_program,
UNIFORM_REPEAT_CHILD_BOUNDS, 0,
(node->bounds.origin.x - child_bounds->origin.x) / child_bounds->size.width,
(node->bounds.origin.y - child_bounds->origin.y) / child_bounds->size.height,
node->bounds.size.width / child_bounds->size.width,
node->bounds.size.height / child_bounds->size.height);
gsk_ngl_program_set_uniform4f (job->driver->repeat,
gsk_ngl_program_set_uniform4f (job->current_program,
UNIFORM_REPEAT_TEXTURE_RECT, 0,
offscreen.area.x,
offscreen.was_offscreen ? offscreen.area.y2 : offscreen.area.y,
@ -3249,13 +3387,17 @@ static void
gsk_ngl_render_job_visit_node (GskNglRenderJob *job,
const GskRenderNode *node)
{
gboolean has_clip;
g_assert (job != NULL);
g_assert (node != NULL);
g_assert (GSK_IS_NGL_DRIVER (job->driver));
g_assert (GSK_IS_NGL_COMMAND_QUEUE (job->command_queue));
if (node_is_invisible (node) ||
!gsk_ngl_render_job_node_overlaps_clip (job, node))
if (node_is_invisible (node))
return;
if (!gsk_ngl_render_job_update_clip (job, node, &has_clip))
return;
switch (gsk_render_node_get_node_type (node))
@ -3403,6 +3545,9 @@ gsk_ngl_render_job_visit_node (GskNglRenderJob *job,
g_assert_not_reached ();
break;
}
if (has_clip)
gsk_ngl_render_job_pop_clip (job);
}
static gboolean
@ -3609,8 +3754,8 @@ gsk_ngl_render_job_render_flipped (GskNglRenderJob *job,
gsk_ngl_render_job_set_alpha (job, 1.0f);
gsk_ngl_command_queue_bind_framebuffer (job->command_queue, job->framebuffer);
gsk_ngl_command_queue_clear (job->command_queue, 0, &job->viewport);
gsk_ngl_render_job_begin_draw (job, job->driver->blit);
gsk_ngl_program_set_uniform_texture (job->driver->blit,
gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit));
gsk_ngl_program_set_uniform_texture (job->current_program,
UNIFORM_SHARED_SOURCE, 0,
GL_TEXTURE_2D,
GL_TEXTURE0,

View File

@ -50,16 +50,24 @@ gsk_rounded_rect_coverage (GskRoundedRect r, vec2 p)
p.x >= r.bounds.z || p.y >= r.bounds.w)
return 0.0;
vec2 rad_tl = r.corner_points1.xy - r.bounds.xy;
vec2 rad_tr = r.corner_points1.zw - r.bounds.zy;
vec2 rad_br = r.corner_points2.xy - r.bounds.zw;
vec2 rad_bl = r.corner_points2.zw - r.bounds.xw;
vec2 ref_tl = r.corner_points1.xy;
vec2 ref_tr = r.corner_points1.zw;
vec2 ref_br = r.corner_points2.xy;
vec2 ref_bl = r.corner_points2.zw;
if (p.x >= ref_tl.x && p.x >= ref_bl.x &&
p.x <= ref_tr.x && p.x <= ref_br.x)
return 1.0;
if (p.y >= ref_tl.y && p.y >= ref_tr.y &&
p.y <= ref_bl.y && p.y <= ref_br.y)
return 1.0;
vec2 rad_tl = r.corner_points1.xy - r.bounds.xy;
vec2 rad_tr = r.corner_points1.zw - r.bounds.zy;
vec2 rad_br = r.corner_points2.xy - r.bounds.zw;
vec2 rad_bl = r.corner_points2.zw - r.bounds.xw;
float d_tl = gsk_ellipsis_coverage(p, ref_tl, rad_tl);
float d_tr = gsk_ellipsis_coverage(p, ref_tr, rad_tr);
float d_br = gsk_ellipsis_coverage(p, ref_br, rad_br);
@ -75,6 +83,16 @@ gsk_rounded_rect_coverage (GskRoundedRect r, vec2 p)
return 1.0 - dot(vec4(is_out), corner_coverages);
}
float
gsk_rect_coverage (vec4 r, vec2 p)
{
if (p.x < r.x || p.y < r.y ||
p.x >= r.z || p.y >= r.w)
return 0.0;
return 1.0;
}
vec4 GskTexture(sampler2D sampler, vec2 texCoords) {
#if defined(GSK_GLES) || defined(GSK_LEGACY)
return texture2D(sampler, texCoords);
@ -101,14 +119,21 @@ vec2 gsk_get_frag_coord() {
}
void gskSetOutputColor(vec4 color) {
vec2 f = gsk_get_frag_coord();
vec4 result;
// We do *NOT* transform the clip rect here since we already
// need to do that on the CPU.
#if defined(GSK_GLES) || defined(GSK_LEGACY)
gl_FragColor = color * gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect), f);
#if defined(NO_CLIP)
result = color;
#elif defined(RECT_CLIP)
result = color * gsk_rect_coverage(gsk_get_bounds(u_clip_rect),
gsk_get_frag_coord());
#else
outputColor = color * gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect), f);
result = color * gsk_rounded_rect_coverage(gsk_create_rect(u_clip_rect),
gsk_get_frag_coord());
#endif
#if defined(GSK_GLES) || defined(GSK_LEGACY)
gl_FragColor = result;
#else
outputColor = result;
#endif
/*outputColor = color;*/
}

View File

@ -38,6 +38,12 @@ gsk_create_rect(vec4[3] data)
return GskRoundedRect(bounds, corner_points1, corner_points2);
}
vec4
gsk_get_bounds(vec4[3] data)
{
return vec4(data[0].xy, data[0].xy + data[0].zw);
}
vec4 gsk_premultiply(vec4 c) {
return vec4(c.rgb * c.a, c.a);
}

View File

@ -87,6 +87,33 @@ test_intersects_rect (void)
#undef HALF_THE_POINTS
}
static void
test_contains_point (void)
{
GskRoundedRect rect;
gsk_rounded_rect_init (&rect,
&GRAPHENE_RECT_INIT (0, 0, 100, 100),
&GRAPHENE_SIZE_INIT (0, 0),
&GRAPHENE_SIZE_INIT (10, 10),
&GRAPHENE_SIZE_INIT (10, 20),
&GRAPHENE_SIZE_INIT (20, 10));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (50, 50)));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (0, 0)));
g_assert_false (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (100, 0)));
g_assert_false (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (100, 100)));
g_assert_false (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (0, 100)));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (0, 50)));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (50, 0)));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (50, 100)));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (100, 50)));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (95, 5)));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (95, 90)));
g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (10, 95)));
}
int
main (int argc,
char *argv[])
@ -95,6 +122,7 @@ main (int argc,
g_test_add_func ("/rounded-rect/contains-rect", test_contains_rect);
g_test_add_func ("/rounded-rect/intersects-rect", test_intersects_rect);
g_test_add_func ("/rounded-rect/contains-point", test_contains_point);
return g_test_run ();
}