summaryrefslogtreecommitdiff
path: root/gsk/gl/opbuffer.h
blob: db9b5c9425933e5a50c826325955e53608b6d3c4 (plain)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#ifndef __OP_BUFFER_H__
#define __OP_BUFFER_H__

#include <gdk/gdk.h>
#include <gsk/gsk.h>
#include <graphene.h>

#include "gskgldriverprivate.h"

typedef struct _Program Program;

typedef enum
{
  OP_NONE                              =  0,
  OP_CHANGE_OPACITY                    =  1,
  OP_CHANGE_COLOR                      =  2,
  OP_CHANGE_PROJECTION                 =  3,
  OP_CHANGE_MODELVIEW                  =  4,
  OP_CHANGE_PROGRAM                    =  5,
  OP_CHANGE_RENDER_TARGET              =  6,
  OP_CHANGE_CLIP                       =  7,
  OP_CHANGE_VIEWPORT                   =  8,
  OP_CHANGE_SOURCE_TEXTURE             =  9,
  OP_CHANGE_REPEAT                     = 10,
  OP_CHANGE_LINEAR_GRADIENT            = 11,
  OP_CHANGE_RADIAL_GRADIENT            = 12,
  OP_CHANGE_COLOR_MATRIX               = 13,
  OP_CHANGE_BLUR                       = 14,
  OP_CHANGE_INSET_SHADOW               = 15,
  OP_CHANGE_OUTSET_SHADOW              = 16,
  OP_CHANGE_BORDER                     = 17,
  OP_CHANGE_BORDER_COLOR               = 18,
  OP_CHANGE_BORDER_WIDTH               = 19,
  OP_CHANGE_CROSS_FADE                 = 20,
  OP_CHANGE_UNBLURRED_OUTSET_SHADOW    = 21,
  OP_CLEAR                             = 22,
  OP_DRAW                              = 23,
  OP_DUMP_FRAMEBUFFER                  = 24,
  OP_PUSH_DEBUG_GROUP                  = 25,
  OP_POP_DEBUG_GROUP                   = 26,
  OP_CHANGE_BLEND                      = 27,
  OP_CHANGE_GL_SHADER_ARGS             = 28,
  OP_CHANGE_EXTRA_SOURCE_TEXTURE       = 29,
  OP_CHANGE_CONIC_GRADIENT             = 30,
  OP_LAST
} OpKind;


typedef struct { int value; guint send: 1; }    IntUniformValue;
typedef struct { float value; guint send: 1; }    FloatUniformValue;
typedef struct { float value[2]; guint send: 1; } Float2UniformValue;
typedef struct { GskRoundedRect value; guint send: 1; guint send_corners: 1; } RRUniformValue;
typedef struct { const GdkRGBA *value; guint send: 1; } RGBAUniformValue;
typedef struct { const graphene_vec4_t *value; guint send: 1; } Vec4UniformValue;
typedef struct { const GskColorStop *value; guint send: 1; } ColorStopUniformValue;
typedef struct { const graphene_matrix_t *value; guint send: 1; } MatrixUniformValue;

/* OpNode are allocated within OpBuffer.pos, but we keep
 * a secondary index into the locations of that buffer
 * from OpBuffer.index. This allows peeking at the kind
 * and quickly replacing existing entries when necessary.
 */
typedef struct
{
  RRUniformValue outline;
  FloatUniformValue spread;
  Float2UniformValue offset;
  RGBAUniformValue color;
} OpShadow;

typedef struct
{
  RRUniformValue outline;
} OpOutsetShadow;

typedef struct
{
  guint  pos;
  OpKind kind;
} OpBufferEntry;

typedef struct
{
  guint8  *buf;
  gsize    buflen;
  gsize    bufpos;
  GArray  *index;
} OpBuffer;

typedef struct
{
  float opacity;
} OpOpacity;

typedef struct
{
  graphene_matrix_t matrix;
} OpMatrix;

typedef struct
{
  const Program *program;
} OpProgram;

typedef struct
{
  const GdkRGBA *rgba;
} OpColor;

typedef struct
{
  int render_target_id;
} OpRenderTarget;

typedef struct
{
  GskRoundedRect clip;
  guint send_corners: 1;
} OpClip;

typedef struct
{
  graphene_rect_t viewport;
} OpViewport;

typedef struct
{
  int texture_id;
} OpTexture;

typedef struct
{
  int texture_id;
  int idx;
} OpExtraTexture;

typedef struct
{
  gsize vao_offset;
  gsize vao_size;
} OpDraw;

typedef struct
{
  ColorStopUniformValue color_stops;
  IntUniformValue n_color_stops;
  float start_point[2];
  float end_point[2];
} OpLinearGradient;

typedef struct
{
  ColorStopUniformValue color_stops;
  IntUniformValue n_color_stops;
  float start;
  float end;
  float radius[2];
  float center[2];
} OpRadialGradient;

typedef struct
{
  ColorStopUniformValue color_stops;
  IntUniformValue n_color_stops;
  float center[2];
  float rotation;
} OpConicGradient;

typedef struct
{
  MatrixUniformValue matrix;
  Vec4UniformValue offset;
} OpColorMatrix;

typedef struct
{
  float radius;
  graphene_size_t size;
  float dir[2];
} OpBlur;

typedef struct
{
  float widths[4];
  const GdkRGBA *color;
  GskRoundedRect outline;
} OpBorder;

typedef struct
{
  float progress;
  int source2;
} OpCrossFade;

typedef struct
{
  char *filename;
  int width;
  int height;
} OpDumpFrameBuffer;

typedef struct
{
  char text[64];
} OpDebugGroup;

typedef struct
{
  int source2;
  int mode;
} OpBlend;

typedef struct
{
  float child_bounds[4];
  float texture_rect[4];
} OpRepeat;

typedef struct
{
  float size[2];
  GskGLShader *shader;
  const guchar *uniform_data;
} OpGLShader;

void     op_buffer_init            (OpBuffer *buffer);
void     op_buffer_destroy         (OpBuffer *buffer);
void     op_buffer_clear           (OpBuffer *buffer);
gpointer op_buffer_add             (OpBuffer *buffer,
                                    OpKind    kind);

typedef struct
{
  GArray   *index;
  OpBuffer *buffer;
  guint     pos;
} OpBufferIter;

static inline void
op_buffer_iter_init (OpBufferIter *iter,
                     OpBuffer     *buffer)
{
  iter->index = buffer->index;
  iter->buffer = buffer;
  iter->pos = 1; /* Skip first OP_NONE */
}

static inline gpointer
op_buffer_iter_next (OpBufferIter *iter,
                     OpKind       *kind)
{
  const OpBufferEntry *entry;

  if (iter->pos == iter->index->len)
    return NULL;

  entry = &g_array_index (iter->index, OpBufferEntry, iter->pos);

  iter->pos++;

  *kind = entry->kind;
  return &iter->buffer->buf[entry->pos];
}

static inline void
op_buffer_pop_tail (OpBuffer *buffer)
{
  /* Never truncate the first OP_NONE */
  if G_LIKELY (buffer->index->len > 0)
    buffer->index->len--;
}

static inline gpointer
op_buffer_peek_tail (OpBuffer *buffer,
                     OpKind   *kind)
{
  const OpBufferEntry *entry;

  entry = &g_array_index (buffer->index, OpBufferEntry, buffer->index->len - 1);
  *kind = entry->kind;
  return &buffer->buf[entry->pos];
}

static inline gpointer
op_buffer_peek_tail_checked (OpBuffer *buffer,
                             OpKind    kind)
{
  const OpBufferEntry *entry;

  entry = &g_array_index (buffer->index, OpBufferEntry, buffer->index->len - 1);

  if (entry->kind == kind)
    return &buffer->buf[entry->pos];

  return NULL;
}

static inline guint
op_buffer_n_ops (OpBuffer *buffer)
{
  return buffer->index->len - 1;
}

#endif /* __OP_BUFFER_H__ */