1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#include "config.h"
#include "gskvulkanclipprivate.h"
#include "gskroundedrectprivate.h"
void
gsk_vulkan_clip_init_empty (GskVulkanClip *clip,
const graphene_rect_t *rect)
{
clip->type = GSK_VULKAN_CLIP_NONE;
gsk_rounded_rect_init_from_rect (&clip->rect, rect, 0);
}
static void
gsk_vulkan_clip_init_copy (GskVulkanClip *self,
const GskVulkanClip *src)
{
self->type = src->type;
gsk_rounded_rect_init_copy (&self->rect, &src->rect);
}
gboolean
gsk_vulkan_clip_intersect_rect (GskVulkanClip *dest,
const GskVulkanClip *src,
const graphene_rect_t *rect)
{
if (graphene_rect_contains_rect (rect, &src->rect.bounds))
{
gsk_vulkan_clip_init_copy (dest, src);
return TRUE;
}
if (!graphene_rect_intersection (rect, &src->rect.bounds, NULL))
{
dest->type = GSK_VULKAN_CLIP_ALL_CLIPPED;
return TRUE;
}
switch (src->type)
{
case GSK_VULKAN_CLIP_ALL_CLIPPED:
dest->type = GSK_VULKAN_CLIP_ALL_CLIPPED;
break;
case GSK_VULKAN_CLIP_NONE:
gsk_vulkan_clip_init_copy (dest, src);
if (graphene_rect_intersection (&dest->rect.bounds, rect, &dest->rect.bounds))
dest->type = GSK_VULKAN_CLIP_RECT;
else
dest->type = GSK_VULKAN_CLIP_ALL_CLIPPED;
break;
case GSK_VULKAN_CLIP_RECT:
gsk_vulkan_clip_init_copy (dest, src);
if (!graphene_rect_intersection (&dest->rect.bounds, rect, &dest->rect.bounds))
dest->type = GSK_VULKAN_CLIP_ALL_CLIPPED;
break;
case GSK_VULKAN_CLIP_ROUNDED_CIRCULAR:
case GSK_VULKAN_CLIP_ROUNDED:
if (gsk_rounded_rect_contains_rect (&src->rect, rect))
{
dest->type = GSK_VULKAN_CLIP_RECT;
gsk_rounded_rect_init_from_rect (&dest->rect, rect, 0);
}
else
{
/* some points of rect are inside src's rounded rect,
* some are outside. */
/* XXX: If the 2 rects don't intersect on rounded corners,
* we could actually compute a new clip here.
*/
return FALSE;
}
}
return TRUE;
}
gboolean
gsk_vulkan_clip_intersect_rounded_rect (GskVulkanClip *dest,
const GskVulkanClip *src,
const GskRoundedRect *rounded)
{
if (gsk_rounded_rect_contains_rect (rounded, &src->rect.bounds))
{
gsk_vulkan_clip_init_copy (dest, src);
return TRUE;
}
if (!graphene_rect_intersection (&rounded->bounds, &src->rect.bounds, NULL))
{
dest->type = GSK_VULKAN_CLIP_ALL_CLIPPED;
return TRUE;
}
switch (src->type)
{
case GSK_VULKAN_CLIP_ALL_CLIPPED:
dest->type = GSK_VULKAN_CLIP_ALL_CLIPPED;
break;
case GSK_VULKAN_CLIP_NONE:
dest->type = gsk_rounded_rect_is_circular (&dest->rect) ? GSK_VULKAN_CLIP_ROUNDED_CIRCULAR : GSK_VULKAN_CLIP_ROUNDED;
gsk_rounded_rect_init_copy (&dest->rect, rounded);
break;
case GSK_VULKAN_CLIP_RECT:
if (graphene_rect_contains_rect (&src->rect.bounds, &rounded->bounds))
{
dest->type = gsk_rounded_rect_is_circular (&dest->rect) ? GSK_VULKAN_CLIP_ROUNDED_CIRCULAR : GSK_VULKAN_CLIP_ROUNDED;
gsk_rounded_rect_init_copy (&dest->rect, rounded);
return TRUE;
}
/* some points of rect are inside src's rounded rect,
* some are outside. */
/* XXX: If the 2 rects don't intersect on rounded corners,
* we could actually compute a new clip here.
*/
return FALSE;
case GSK_VULKAN_CLIP_ROUNDED_CIRCULAR:
case GSK_VULKAN_CLIP_ROUNDED:
/* XXX: improve */
return FALSE;
}
return TRUE;
}
gboolean
gsk_vulkan_clip_transform (GskVulkanClip *dest,
const GskVulkanClip *src,
const graphene_matrix_t *transform,
const graphene_rect_t *viewport)
{
switch (dest->type)
{
default:
g_assert_not_reached();
return FALSE;
case GSK_VULKAN_CLIP_ALL_CLIPPED:
gsk_vulkan_clip_init_copy (dest, src);
return TRUE;
case GSK_VULKAN_CLIP_NONE:
gsk_vulkan_clip_init_empty (dest, viewport);
return TRUE;
case GSK_VULKAN_CLIP_RECT:
case GSK_VULKAN_CLIP_ROUNDED_CIRCULAR:
case GSK_VULKAN_CLIP_ROUNDED:
/* FIXME: Handle 2D operations, in particular transform and scale */
return FALSE;
}
}
gboolean
gsk_vulkan_clip_contains_rect (const GskVulkanClip *self,
const graphene_rect_t *rect)
{
switch (self->type)
{
default:
g_assert_not_reached();
case GSK_VULKAN_CLIP_ALL_CLIPPED:
return FALSE;
case GSK_VULKAN_CLIP_NONE:
return TRUE;
case GSK_VULKAN_CLIP_RECT:
return graphene_rect_contains_rect (&self->rect.bounds, rect);
case GSK_VULKAN_CLIP_ROUNDED_CIRCULAR:
case GSK_VULKAN_CLIP_ROUNDED:
return gsk_rounded_rect_contains_rect (&self->rect, rect);
}
}
|