#define SANITY_CHECKS 0
+
+#define rounded_rect_top_left(r) (GRAPHENE_RECT_INIT(r->bounds.origin.x, \
+ r->bounds.origin.y, \
+ r->corner[0].width, r->corner[0].height))
+
+#define rounded_rect_top_right(r) (GRAPHENE_RECT_INIT(r->bounds.origin.x + r->bounds.size.width - r->corner[1].width, \
+ r->bounds.origin.y, \
+ r->corner[1].width, r->corner[1].height))
+
+#define rounded_rect_bottom_right(r) (GRAPHENE_RECT_INIT(r->bounds.origin.x + r->bounds.size.width - r->corner[2].width, \
+ r->bounds.origin.y + r->bounds.size.height - r->corner[2].height, \
+ r->corner[2].width, r->corner[2].height))
+
+#define rounded_rect_bottom_left(r) (GRAPHENE_RECT_INIT(r->bounds.origin.x, \
+ r->bounds.origin.y + r->bounds.size.height - r->corner[2].height, \
+ r->corner[3].width, r->corner[3].height))
+
+
+#define rounded_rect_corner0(r) rounded_rect_top_left(r)
+#define rounded_rect_corner1(r) rounded_rect_top_right(r)
+#define rounded_rect_corner2(r) rounded_rect_bottom_right(r)
+#define rounded_rect_corner3(r) rounded_rect_bottom_left(r)
+
+#define rounded_rect_corner(r, i) (rounded_rect_corner ##i(r))
+#define graphene_size_non_zero(s) (s->width > 0 && s->height > 0)
+#define rounded_rect_has_corner(r, i) (r->corner[i].width > 0 && r->corner[i].height > 0)
+
+#define rect_contains_point(r, _x, _y) (_x >= (r)->origin.x && _x <= (r)->origin.x + (r)->size.width && \
+ _y >= (r)->origin.y && _y <= (r)->origin.y + (r)->size.height)
+
enum {
NINE_SLICE_TOP_LEFT = 0,
NINE_SLICE_TOP_CENTER = 1,
GskRenderNode *child)
{
graphene_rect_t transformed_clip;
- graphene_rect_t intersection;
GskRoundedRect child_clip;
ops_transform_bounds_modelview (builder, clip, &transformed_clip);
if (builder->clip_is_rectilinear)
- {
- /* Simple case: */
- graphene_rect_intersection (&transformed_clip,
- &builder->current_clip->bounds,
- &intersection);
+ goto trivial;
- gsk_rounded_rect_init_from_rect (&child_clip, &intersection, 0.0f);
+ {
+ const GskRoundedRect *cur_clip = builder->current_clip;
+ int n_corners = 0;
+ bool corners[4];
+
+ /* Intersects with top left corner? */
+ n_corners += corners[0] = rounded_rect_has_corner (cur_clip, 0) &&
+ graphene_rect_intersection (&transformed_clip,
+ &rounded_rect_corner (cur_clip, 0), NULL);
+ /* top right? */
+ n_corners += corners[1] = rounded_rect_has_corner (cur_clip, 1) &&
+ graphene_rect_intersection (&transformed_clip,
+ &rounded_rect_corner (cur_clip, 1), NULL);
+ /* bottom right? */
+ n_corners += corners[2] = rounded_rect_has_corner (cur_clip, 2) &&
+ graphene_rect_intersection (&transformed_clip,
+ &rounded_rect_corner (cur_clip, 2), NULL);
+ /* bottom left */
+ n_corners += corners[3] = rounded_rect_has_corner (cur_clip, 3) &&
+ graphene_rect_intersection (&transformed_clip,
+ &rounded_rect_corner (cur_clip, 3), NULL);
+
+ if (n_corners == 0)
+ goto trivial;
+
+ if (corners[0] && !graphene_rect_contains_rect (&transformed_clip, &rounded_rect_corner (cur_clip, 0)))
+ goto rtt;
+ if (corners[1] && !graphene_rect_contains_rect (&transformed_clip, &rounded_rect_corner (cur_clip, 1)))
+ goto rtt;
+ if (corners[2] && !graphene_rect_contains_rect (&transformed_clip, &rounded_rect_corner (cur_clip, 2)))
+ goto rtt;
+ if (corners[3] && !graphene_rect_contains_rect (&transformed_clip, &rounded_rect_corner (cur_clip, 3)))
+ goto rtt;
+
+ /* We do intersect with at least one of the corners, but in such a way that the
+ * intersection between the two clips can still be represented by a single rounded
+ * rect in a trivial way. do that. */
+ {
+ GskRoundedRect real_intersection;
+
+ graphene_rect_intersection (&transformed_clip, &cur_clip->bounds, &real_intersection.bounds);
+
+ for (int i = 0; i < 4; i++)
+ {
+ if (corners[i])
+ real_intersection.corner[i] = cur_clip->corner[i];
+ else
+ real_intersection.corner[i].width = real_intersection.corner[i].height = 0;
+ }
- ops_push_clip (builder, &child_clip);
+ /* Draw with that new clip */
+ ops_push_clip (builder, &real_intersection);
gsk_gl_renderer_add_render_ops (self, child, builder);
ops_pop_clip (builder);
- return;
}
+ return;
+ }
- /* Intersection might end up having rounded corners again */
- if (!rounded_inner_rect_contains_rect (builder->current_clip,
- &transformed_clip))
- {
- /* well fuck */
- const float scale = ops_get_scale (builder);
- gboolean is_offscreen;
- TextureRegion region;
- GskRoundedRect scaled_clip;
-
- memset (&scaled_clip, 0, sizeof (GskRoundedRect));
-
- scaled_clip.bounds.origin.x = clip->origin.x * scale;
- scaled_clip.bounds.origin.y = clip->origin.y * scale;
- scaled_clip.bounds.size.width = clip->size.width * scale;
- scaled_clip.bounds.size.height = clip->size.height * scale;
+rtt:
+ {
+ /* well fuck */
+ const float scale = ops_get_scale (builder);
+ gboolean is_offscreen;
+ TextureRegion region;
+ GskRoundedRect scaled_clip;
+
+ memset (&scaled_clip, 0, sizeof (GskRoundedRect));
+
+ scaled_clip.bounds.origin.x = clip->origin.x * scale;
+ scaled_clip.bounds.origin.y = clip->origin.y * scale;
+ scaled_clip.bounds.size.width = clip->size.width * scale;
+ scaled_clip.bounds.size.height = clip->size.height * scale;
+
+ ops_push_clip (builder, &scaled_clip);
+ if (!add_offscreen_ops (self, builder, &child->bounds,
+ child,
+ ®ion, &is_offscreen,
+ RESET_OPACITY | FORCE_OFFSCREEN))
+ g_assert_not_reached ();
+ ops_pop_clip (builder);
- ops_push_clip (builder, &scaled_clip);
- if (!add_offscreen_ops (self, builder, &child->bounds,
- child,
- ®ion, &is_offscreen,
- RESET_OPACITY | FORCE_OFFSCREEN))
- g_assert_not_reached ();
- ops_pop_clip (builder);
+ ops_set_program (builder, &self->programs->blit_program);
+ ops_set_texture (builder, region.texture_id);
+ load_offscreen_vertex_data (ops_draw (builder, NULL), child, builder);
+ return;
+ }
- ops_set_program (builder, &self->programs->blit_program);
- ops_set_texture (builder, region.texture_id);
- load_offscreen_vertex_data (ops_draw (builder, NULL), child, builder);
- return;
- }
+trivial:
+ memset (&child_clip, 0, sizeof (GskRoundedRect));
+ graphene_rect_intersection (&transformed_clip,
+ &builder->current_clip->bounds,
+ &child_clip.bounds);
+ ops_push_clip (builder, &child_clip);
+ gsk_gl_renderer_add_render_ops (self, child, builder);
+ ops_pop_clip (builder);
+ return;
}
static inline void