1 #ifndef __OP_BUFFER_H__
2 #define __OP_BUFFER_H__
3
4 #include <gdk/gdk.h>
5 #include <gsk/gsk.h>
6 #include <graphene.h>
7
8 #include "gskgldriverprivate.h"
9
10 typedef struct _Program Program;
11
12 typedef enum
13 {
14 OP_NONE = 0,
15 OP_CHANGE_OPACITY = 1,
16 OP_CHANGE_COLOR = 2,
17 OP_CHANGE_PROJECTION = 3,
18 OP_CHANGE_MODELVIEW = 4,
19 OP_CHANGE_PROGRAM = 5,
20 OP_CHANGE_RENDER_TARGET = 6,
21 OP_CHANGE_CLIP = 7,
22 OP_CHANGE_VIEWPORT = 8,
23 OP_CHANGE_SOURCE_TEXTURE = 9,
24 OP_CHANGE_REPEAT = 10,
25 OP_CHANGE_LINEAR_GRADIENT = 11,
26 OP_CHANGE_RADIAL_GRADIENT = 12,
27 OP_CHANGE_COLOR_MATRIX = 13,
28 OP_CHANGE_BLUR = 14,
29 OP_CHANGE_INSET_SHADOW = 15,
30 OP_CHANGE_OUTSET_SHADOW = 16,
31 OP_CHANGE_BORDER = 17,
32 OP_CHANGE_BORDER_COLOR = 18,
33 OP_CHANGE_BORDER_WIDTH = 19,
34 OP_CHANGE_CROSS_FADE = 20,
35 OP_CHANGE_UNBLURRED_OUTSET_SHADOW = 21,
36 OP_CLEAR = 22,
37 OP_DRAW = 23,
38 OP_DUMP_FRAMEBUFFER = 24,
39 OP_PUSH_DEBUG_GROUP = 25,
40 OP_POP_DEBUG_GROUP = 26,
41 OP_CHANGE_BLEND = 27,
42 OP_CHANGE_GL_SHADER_ARGS = 28,
43 OP_CHANGE_EXTRA_SOURCE_TEXTURE = 29,
44 OP_CHANGE_CONIC_GRADIENT = 30,
45 OP_LAST
46 } OpKind;
47
48
49 typedef struct { int value; guint send: 1; } IntUniformValue;
50 typedef struct { float value; guint send: 1; } FloatUniformValue;
51 typedef struct { float value[2]; guint send: 1; } Float2UniformValue;
52 typedef struct { GskRoundedRect value; guint send: 1; guint send_corners: 1; } RRUniformValue;
53 typedef struct { const GdkRGBA *value; guint send: 1; } RGBAUniformValue;
54 typedef struct { const graphene_vec4_t *value; guint send: 1; } Vec4UniformValue;
55 typedef struct { const GskColorStop *value; guint send: 1; } ColorStopUniformValue;
56 typedef struct { const graphene_matrix_t *value; guint send: 1; } MatrixUniformValue;
57
58 /* OpNode are allocated within OpBuffer.pos, but we keep
59 * a secondary index into the locations of that buffer
60 * from OpBuffer.index. This allows peeking at the kind
61 * and quickly replacing existing entries when necessary.
62 */
63 typedef struct
64 {
65 RRUniformValue outline;
66 FloatUniformValue spread;
67 Float2UniformValue offset;
68 RGBAUniformValue color;
69 } OpShadow;
70
71 typedef struct
72 {
73 RRUniformValue outline;
74 } OpOutsetShadow;
75
76 typedef struct
77 {
78 guint pos;
79 OpKind kind;
80 } OpBufferEntry;
81
82 typedef struct
83 {
84 guint8 *buf;
85 gsize buflen;
86 gsize bufpos;
87 GArray *index;
88 } OpBuffer;
89
90 typedef struct
91 {
92 float opacity;
93 } OpOpacity;
94
95 typedef struct
96 {
97 graphene_matrix_t matrix;
98 } OpMatrix;
99
100 typedef struct
101 {
102 const Program *program;
103 } OpProgram;
104
105 typedef struct
106 {
107 const GdkRGBA *rgba;
108 } OpColor;
109
110 typedef struct
111 {
112 int render_target_id;
113 } OpRenderTarget;
114
115 typedef struct
116 {
117 GskRoundedRect clip;
118 guint send_corners: 1;
119 } OpClip;
120
121 typedef struct
122 {
123 graphene_rect_t viewport;
124 } OpViewport;
125
126 typedef struct
127 {
128 int texture_id;
129 } OpTexture;
130
131 typedef struct
132 {
133 int texture_id;
134 int idx;
135 } OpExtraTexture;
136
137 typedef struct
138 {
139 gsize vao_offset;
140 gsize vao_size;
141 } OpDraw;
142
143 typedef struct
144 {
145 ColorStopUniformValue color_stops;
146 IntUniformValue n_color_stops;
147 float start_point[2];
148 float end_point[2];
149 gboolean repeat;
150 } OpLinearGradient;
151
152 typedef struct
153 {
154 ColorStopUniformValue color_stops;
155 IntUniformValue n_color_stops;
156 float start;
157 float end;
158 float radius[2];
159 float center[2];
160 gboolean repeat;
161 } OpRadialGradient;
162
163 typedef struct
164 {
165 ColorStopUniformValue color_stops;
166 IntUniformValue n_color_stops;
167 float center[2];
168 float angle;
169 } OpConicGradient;
170
171 typedef struct
172 {
173 MatrixUniformValue matrix;
174 Vec4UniformValue offset;
175 } OpColorMatrix;
176
177 typedef struct
178 {
179 float radius;
180 graphene_size_t size;
181 float dir[2];
182 } OpBlur;
183
184 typedef struct
185 {
186 float widths[4];
187 const GdkRGBA *color;
188 GskRoundedRect outline;
189 } OpBorder;
190
191 typedef struct
192 {
193 float progress;
194 int source2;
195 } OpCrossFade;
196
197 typedef struct
198 {
199 char *filename;
200 int width;
201 int height;
202 } OpDumpFrameBuffer;
203
204 typedef struct
205 {
206 char text[64];
207 } OpDebugGroup;
208
209 typedef struct
210 {
211 int source2;
212 int mode;
213 } OpBlend;
214
215 typedef struct
216 {
217 float child_bounds[4];
218 float texture_rect[4];
219 } OpRepeat;
220
221 typedef struct
222 {
223 float size[2];
224 GskGLShader *shader;
225 const guchar *uniform_data;
226 } OpGLShader;
227
228 void op_buffer_init (OpBuffer *buffer);
229 void op_buffer_destroy (OpBuffer *buffer);
230 void op_buffer_clear (OpBuffer *buffer);
231 gpointer op_buffer_add (OpBuffer *buffer,
232 OpKind kind);
233
234 typedef struct
235 {
236 GArray *index;
237 OpBuffer *buffer;
238 guint pos;
239 } OpBufferIter;
240
241 static inline void
op_buffer_iter_init(OpBufferIter * iter,OpBuffer * buffer)242 op_buffer_iter_init (OpBufferIter *iter,
243 OpBuffer *buffer)
244 {
245 iter->index = buffer->index;
246 iter->buffer = buffer;
247 iter->pos = 1; /* Skip first OP_NONE */
248 }
249
250 static inline gpointer
op_buffer_iter_next(OpBufferIter * iter,OpKind * kind)251 op_buffer_iter_next (OpBufferIter *iter,
252 OpKind *kind)
253 {
254 const OpBufferEntry *entry;
255
256 if (iter->pos == iter->index->len)
257 return NULL;
258
259 entry = &g_array_index (iter->index, OpBufferEntry, iter->pos);
260
261 iter->pos++;
262
263 *kind = entry->kind;
264 return &iter->buffer->buf[entry->pos];
265 }
266
267 static inline void
op_buffer_pop_tail(OpBuffer * buffer)268 op_buffer_pop_tail (OpBuffer *buffer)
269 {
270 /* Never truncate the first OP_NONE */
271 if G_LIKELY (buffer->index->len > 0)
272 buffer->index->len--;
273 }
274
275 static inline gpointer
op_buffer_peek_tail(OpBuffer * buffer,OpKind * kind)276 op_buffer_peek_tail (OpBuffer *buffer,
277 OpKind *kind)
278 {
279 const OpBufferEntry *entry;
280
281 entry = &g_array_index (buffer->index, OpBufferEntry, buffer->index->len - 1);
282 *kind = entry->kind;
283 return &buffer->buf[entry->pos];
284 }
285
286 static inline gpointer
op_buffer_peek_tail_checked(OpBuffer * buffer,OpKind kind)287 op_buffer_peek_tail_checked (OpBuffer *buffer,
288 OpKind kind)
289 {
290 const OpBufferEntry *entry;
291
292 entry = &g_array_index (buffer->index, OpBufferEntry, buffer->index->len - 1);
293
294 if (entry->kind == kind)
295 return &buffer->buf[entry->pos];
296
297 return NULL;
298 }
299
300 static inline guint
op_buffer_n_ops(OpBuffer * buffer)301 op_buffer_n_ops (OpBuffer *buffer)
302 {
303 return buffer->index->len - 1;
304 }
305
306 #endif /* __OP_BUFFER_H__ */
307