summaryrefslogtreecommitdiff
path: root/gsk/gl/gskglrenderopsprivate.h
blob: 551a1afc05d64bd3376cda7677f64d53472cf2a7 (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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#ifndef __GSK_GL_RENDER_OPS_H__
#define __GSK_GL_RENDER_OPS_H__

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

#include "gskgldriverprivate.h"
#include "gskroundedrectprivate.h"
#include "gskglrenderer.h"
#include "gskrendernodeprivate.h"

#include "opbuffer.h"

#define GL_N_VERTICES 6
#define GL_N_PROGRAMS 15
#define GL_MAX_GRADIENT_STOPS 6

typedef struct
{
  float scale_x;
  float scale_y;

  float dx_before;
  float dy_before;
} OpsMatrixMetadata;

typedef struct
{
  GskTransform *transform;
  OpsMatrixMetadata metadata;
} MatrixStackEntry;

typedef struct
{
  GskTransform *modelview;
  GskRoundedRect clip;
  graphene_matrix_t projection;
  int source_texture;
  graphene_rect_t viewport;
  float opacity;
  /* Per-program state */
  union {
    GdkRGBA color;
    struct {
      graphene_matrix_t matrix;
      graphene_vec4_t offset;
    } color_matrix;
    struct {
      float widths[4];
      GdkRGBA color;
      GskRoundedRect outline;
    } border;
    struct {
      GskRoundedRect outline;
      float dx;
      float dy;
      float spread;
      GdkRGBA color;
    } inset_shadow;
    struct {
      GskRoundedRect outline;
      float dx;
      float dy;
      float spread;
      GdkRGBA color;
    } unblurred_outset_shadow;
    struct {
      int n_color_stops;
      GskColorStop color_stops[GL_MAX_GRADIENT_STOPS];
      float start_point[2];
      float end_point[2];
    } linear_gradient;
    struct {
      int n_color_stops;
      GskColorStop color_stops[GL_MAX_GRADIENT_STOPS];
      float center[2];
      float start;
      float end;
      float radius[2]; /* h/v */
    } radial_gradient;
    struct {
      float width;
      float height;
      int uniform_data_len;
      guchar uniform_data[32];
    } gl_shader;
  };
} ProgramState;

struct _Program
{
  const char *name;

  int index;        /* Into the renderer's program array -1 for custom */

  int id;
  /* Common locations (gl_common)*/
  int source_location;
  int position_location;
  int uv_location;
  int alpha_location;
  int viewport_location;
  int projection_location;
  int modelview_location;
  int clip_rect_location;
  union {
    struct {
      int color_location;
    } color;
    struct {
      int color_location;
    } coloring;
    struct {
      int color_matrix_location;
      int color_offset_location;
    } color_matrix;
    struct {
      int num_color_stops_location;
      int color_stops_location;
      int points_location;
      int repeat_location;
    } linear_gradient;
    struct {
      int num_color_stops_location;
      int color_stops_location;
      int geometry_location;
      int range_location;
      int repeat_location;
    } radial_gradient;
    struct {
      int num_color_stops_location;
      int color_stops_location;
      int geometry_location;
    } conic_gradient;
    struct {
      int blur_radius_location;
      int blur_size_location;
      int blur_dir_location;
    } blur;
    struct {
      int color_location;
      int spread_location;
      int offset_location;
      int outline_rect_location;
    } inset_shadow;
    struct {
      int color_location;
      int outline_rect_location;
    } outset_shadow;
    struct {
      int outline_rect_location;
      int color_location;
      int spread_location;
      int offset_location;
    } unblurred_outset_shadow;
    struct {
      int color_location;
      int widths_location;
      int outline_rect_location;
    } border;
    struct {
      int source2_location;
      int progress_location;
    } cross_fade;
    struct {
      int source2_location;
      int mode_location;
    } blend;
    struct {
      int child_bounds_location;
      int texture_rect_location;
    } repeat;
    struct {
      int size_location;
      int args_locations[8];
      int texture_locations[4];
      GError *compile_error;
    } glshader;
  };
  ProgramState state;
};

typedef struct {
  int ref_count;
  union {
    Program programs[GL_N_PROGRAMS];
    struct {
      Program blend_program;
      Program blit_program;
      Program blur_program;
      Program border_program;
      Program color_matrix_program;
      Program color_program;
      Program coloring_program;
      Program cross_fade_program;
      Program inset_shadow_program;
      Program linear_gradient_program;
      Program radial_gradient_program;
      Program conic_gradient_program;
      Program outset_shadow_program;
      Program repeat_program;
      Program unblurred_outset_shadow_program;
    };
  };
  GHashTable *custom_programs; /* GskGLShader -> Program* */
} GskGLRendererPrograms;

typedef struct
{
  GskGLRendererPrograms *programs;
  Program *current_program;
  int current_render_target;
  int current_texture;

  graphene_matrix_t current_projection;
  graphene_rect_t current_viewport;
  float current_opacity;
  float dx, dy;
  float scale_x, scale_y;

  OpBuffer render_ops;
  GArray *vertices;

  GskGLRenderer *renderer;

  /* Stack of modelview matrices */
  GArray *mv_stack;
  GskTransform *current_modelview;

  /* Same thing */
  GArray *clip_stack;
  /* Pointer into clip_stack */
  const GskRoundedRect *current_clip;
  bool clip_is_rectilinear;
} RenderOpBuilder;


void              ops_dump_framebuffer   (RenderOpBuilder         *builder,
                                          const char              *filename,
                                          int                      width,
                                          int                      height);
void              ops_init               (RenderOpBuilder         *builder);
void              ops_free               (RenderOpBuilder         *builder);
void              ops_reset              (RenderOpBuilder         *builder);
void              ops_push_debug_group    (RenderOpBuilder         *builder,
                                           const char              *text);
void              ops_pop_debug_group     (RenderOpBuilder         *builder);

void              ops_finish             (RenderOpBuilder         *builder);
void              ops_push_modelview     (RenderOpBuilder         *builder,
                                          GskTransform            *transform);
void              ops_set_modelview      (RenderOpBuilder         *builder,
                                          GskTransform            *transform);
void              ops_pop_modelview      (RenderOpBuilder         *builder);
void              ops_set_program        (RenderOpBuilder         *builder,
                                          Program                 *program);

void              ops_push_clip          (RenderOpBuilder         *builder,
                                          const GskRoundedRect    *clip);
void              ops_pop_clip           (RenderOpBuilder         *builder);
gboolean          ops_has_clip           (RenderOpBuilder         *builder);

void              ops_transform_bounds_modelview (const RenderOpBuilder *builder,
                                                  const graphene_rect_t *src,
                                                  graphene_rect_t       *dst);

graphene_matrix_t ops_set_projection     (RenderOpBuilder         *builder,
                                          const graphene_matrix_t *projection);

graphene_rect_t   ops_set_viewport       (RenderOpBuilder         *builder,
                                          const graphene_rect_t   *viewport);

void              ops_set_texture        (RenderOpBuilder         *builder,
                                          int                      texture_id);
void              ops_set_extra_texture  (RenderOpBuilder         *builder,
                                          int                      texture_id,
                                          int                      idx);

int               ops_set_render_target  (RenderOpBuilder         *builder,
                                          int                      render_target_id);

float             ops_set_opacity        (RenderOpBuilder         *builder,
                                          float                    opacity);
void              ops_set_color          (RenderOpBuilder         *builder,
                                          const GdkRGBA           *color);

void              ops_set_color_matrix   (RenderOpBuilder         *builder,
                                          const graphene_matrix_t *matrix,
                                          const graphene_vec4_t   *offset);

void              ops_set_border         (RenderOpBuilder         *builder,
                                          const GskRoundedRect    *outline);
void              ops_set_border_width   (RenderOpBuilder         *builder,
                                          const float             *widths);

void              ops_set_border_color   (RenderOpBuilder         *builder,
                                          const GdkRGBA           *color);
void              ops_set_inset_shadow   (RenderOpBuilder         *self,
                                          const GskRoundedRect     outline,
                                          float                    spread,
                                          const GdkRGBA           *color,
                                          float                    dx,
                                          float                    dy);
void              ops_set_gl_shader_args (RenderOpBuilder         *builder,
                                          GskGLShader             *shader,
                                          float                    width,
                                          float                    height,
                                          const guchar            *uniform_data);
void              ops_set_unblurred_outset_shadow   (RenderOpBuilder         *self,
                                                     const GskRoundedRect     outline,
                                                     float                    spread,
                                                     const GdkRGBA           *color,
                                                     float                    dx,
                                                     float                    dy);

void              ops_set_linear_gradient (RenderOpBuilder     *self,
                                           guint                n_color_stops,
                                           const GskColorStop  *color_stops,
                                           gboolean             repeat,
                                           float                start_x,
                                           float                start_y,
                                           float                end_x,
                                           float                end_y);
void              ops_set_radial_gradient (RenderOpBuilder        *self,
                                           guint                   n_color_stops,
                                           const GskColorStop     *color_stops,
                                           gboolean                repeat,
                                           float                   center_x,
                                           float                   center_y,
                                           float                   start,
                                           float                   end,
                                           float                   hradius,
                                           float                   vradius);
void              ops_set_conic_gradient  (RenderOpBuilder        *self,
                                           guint                   n_color_stops,
                                           const GskColorStop     *color_stops,
                                           float                   center_x,
                                           float                   center_y,
                                           float                   angle);

GskQuadVertex *   ops_draw               (RenderOpBuilder        *builder,
                                          const GskQuadVertex     vertex_data[GL_N_VERTICES]);

void              ops_offset             (RenderOpBuilder        *builder,
                                          float                   x,
                                          float                   y);

gpointer          ops_begin              (RenderOpBuilder        *builder,
                                          OpKind                  kind);
OpBuffer         *ops_get_buffer         (RenderOpBuilder        *builder);

#endif