1 #ifndef __GSK_GL_RENDER_OPS_H__ 2 #define __GSK_GL_RENDER_OPS_H__ 3 4 #include <glib.h> 5 #include <graphene.h> 6 #include <gdk/gdk.h> 7 8 #include "gskgldriverprivate.h" 9 #include "gskroundedrectprivate.h" 10 #include "gskglrenderer.h" 11 #include "gskrendernodeprivate.h" 12 13 #include "opbuffer.h" 14 15 #define GL_N_VERTICES 6 16 #define GL_N_PROGRAMS 15 17 #define GL_MAX_GRADIENT_STOPS 6 18 19 typedef struct 20 { 21 float scale_x; 22 float scale_y; 23 24 float dx_before; 25 float dy_before; 26 } OpsMatrixMetadata; 27 28 typedef struct 29 { 30 GskTransform *transform; 31 OpsMatrixMetadata metadata; 32 } MatrixStackEntry; 33 34 typedef struct 35 { 36 GskTransform *modelview; 37 GskRoundedRect clip; 38 graphene_matrix_t projection; 39 int source_texture; 40 graphene_rect_t viewport; 41 float opacity; 42 /* Per-program state */ 43 union { 44 GdkRGBA color; 45 struct { 46 graphene_matrix_t matrix; 47 graphene_vec4_t offset; 48 } color_matrix; 49 struct { 50 float widths[4]; 51 GdkRGBA color; 52 GskRoundedRect outline; 53 } border; 54 struct { 55 GskRoundedRect outline; 56 float dx; 57 float dy; 58 float spread; 59 GdkRGBA color; 60 } inset_shadow; 61 struct { 62 GskRoundedRect outline; 63 float dx; 64 float dy; 65 float spread; 66 GdkRGBA color; 67 } unblurred_outset_shadow; 68 struct { 69 int n_color_stops; 70 GskColorStop color_stops[GL_MAX_GRADIENT_STOPS]; 71 float start_point[2]; 72 float end_point[2]; 73 } linear_gradient; 74 struct { 75 int n_color_stops; 76 GskColorStop color_stops[GL_MAX_GRADIENT_STOPS]; 77 float center[2]; 78 float start; 79 float end; 80 float radius[2]; /* h/v */ 81 } radial_gradient; 82 struct { 83 float width; 84 float height; 85 int uniform_data_len; 86 guchar uniform_data[32]; 87 } gl_shader; 88 }; 89 } ProgramState; 90 91 struct _Program 92 { 93 const char *name; 94 95 int index; /* Into the renderer's program array -1 for custom */ 96 97 int id; 98 /* Common locations (gl_common)*/ 99 int source_location; 100 int position_location; 101 int uv_location; 102 int alpha_location; 103 int viewport_location; 104 int projection_location; 105 int modelview_location; 106 int clip_rect_location; 107 union { 108 struct { 109 int color_location; 110 } color; 111 struct { 112 int color_location; 113 } coloring; 114 struct { 115 int color_matrix_location; 116 int color_offset_location; 117 } color_matrix; 118 struct { 119 int num_color_stops_location; 120 int color_stops_location; 121 int points_location; 122 int repeat_location; 123 } linear_gradient; 124 struct { 125 int num_color_stops_location; 126 int color_stops_location; 127 int geometry_location; 128 int range_location; 129 int repeat_location; 130 } radial_gradient; 131 struct { 132 int num_color_stops_location; 133 int color_stops_location; 134 int geometry_location; 135 } conic_gradient; 136 struct { 137 int blur_radius_location; 138 int blur_size_location; 139 int blur_dir_location; 140 } blur; 141 struct { 142 int color_location; 143 int spread_location; 144 int offset_location; 145 int outline_rect_location; 146 } inset_shadow; 147 struct { 148 int color_location; 149 int outline_rect_location; 150 } outset_shadow; 151 struct { 152 int outline_rect_location; 153 int color_location; 154 int spread_location; 155 int offset_location; 156 } unblurred_outset_shadow; 157 struct { 158 int color_location; 159 int widths_location; 160 int outline_rect_location; 161 } border; 162 struct { 163 int source2_location; 164 int progress_location; 165 } cross_fade; 166 struct { 167 int source2_location; 168 int mode_location; 169 } blend; 170 struct { 171 int child_bounds_location; 172 int texture_rect_location; 173 } repeat; 174 struct { 175 int size_location; 176 int args_locations[8]; 177 int texture_locations[4]; 178 GError *compile_error; 179 } glshader; 180 }; 181 ProgramState state; 182 }; 183 184 typedef struct { 185 int ref_count; 186 union { 187 Program programs[GL_N_PROGRAMS]; 188 struct { 189 Program blend_program; 190 Program blit_program; 191 Program blur_program; 192 Program border_program; 193 Program color_matrix_program; 194 Program color_program; 195 Program coloring_program; 196 Program cross_fade_program; 197 Program inset_shadow_program; 198 Program linear_gradient_program; 199 Program radial_gradient_program; 200 Program conic_gradient_program; 201 Program outset_shadow_program; 202 Program repeat_program; 203 Program unblurred_outset_shadow_program; 204 }; 205 }; 206 GHashTable *custom_programs; /* GskGLShader -> Program* */ 207 } GskGLRendererPrograms; 208 209 typedef struct 210 { 211 GskGLRendererPrograms *programs; 212 Program *current_program; 213 int current_render_target; 214 int current_texture; 215 216 graphene_matrix_t current_projection; 217 graphene_rect_t current_viewport; 218 float current_opacity; 219 float dx, dy; 220 float scale_x, scale_y; 221 222 OpBuffer render_ops; 223 GArray *vertices; 224 225 GskGLRenderer *renderer; 226 227 /* Stack of modelview matrices */ 228 GArray *mv_stack; 229 GskTransform *current_modelview; 230 231 /* Same thing */ 232 GArray *clip_stack; 233 /* Pointer into clip_stack */ 234 const GskRoundedRect *current_clip; 235 bool clip_is_rectilinear; 236 } RenderOpBuilder; 237 238 239 void ops_dump_framebuffer (RenderOpBuilder *builder, 240 const char *filename, 241 int width, 242 int height); 243 void ops_init (RenderOpBuilder *builder); 244 void ops_free (RenderOpBuilder *builder); 245 void ops_reset (RenderOpBuilder *builder); 246 void ops_push_debug_group (RenderOpBuilder *builder, 247 const char *text); 248 void ops_pop_debug_group (RenderOpBuilder *builder); 249 250 void ops_finish (RenderOpBuilder *builder); 251 void ops_push_modelview (RenderOpBuilder *builder, 252 GskTransform *transform); 253 void ops_set_modelview (RenderOpBuilder *builder, 254 GskTransform *transform); 255 void ops_pop_modelview (RenderOpBuilder *builder); 256 void ops_set_program (RenderOpBuilder *builder, 257 Program *program); 258 259 void ops_push_clip (RenderOpBuilder *builder, 260 const GskRoundedRect *clip); 261 void ops_pop_clip (RenderOpBuilder *builder); 262 gboolean ops_has_clip (RenderOpBuilder *builder); 263 264 void ops_transform_bounds_modelview (const RenderOpBuilder *builder, 265 const graphene_rect_t *src, 266 graphene_rect_t *dst); 267 268 graphene_matrix_t ops_set_projection (RenderOpBuilder *builder, 269 const graphene_matrix_t *projection); 270 271 graphene_rect_t ops_set_viewport (RenderOpBuilder *builder, 272 const graphene_rect_t *viewport); 273 274 void ops_set_texture (RenderOpBuilder *builder, 275 int texture_id); 276 void ops_set_extra_texture (RenderOpBuilder *builder, 277 int texture_id, 278 int idx); 279 280 int ops_set_render_target (RenderOpBuilder *builder, 281 int render_target_id); 282 283 float ops_set_opacity (RenderOpBuilder *builder, 284 float opacity); 285 void ops_set_color (RenderOpBuilder *builder, 286 const GdkRGBA *color); 287 288 void ops_set_color_matrix (RenderOpBuilder *builder, 289 const graphene_matrix_t *matrix, 290 const graphene_vec4_t *offset); 291 292 void ops_set_border (RenderOpBuilder *builder, 293 const GskRoundedRect *outline); 294 void ops_set_border_width (RenderOpBuilder *builder, 295 const float *widths); 296 297 void ops_set_border_color (RenderOpBuilder *builder, 298 const GdkRGBA *color); 299 void ops_set_inset_shadow (RenderOpBuilder *self, 300 const GskRoundedRect outline, 301 float spread, 302 const GdkRGBA *color, 303 float dx, 304 float dy); 305 void ops_set_gl_shader_args (RenderOpBuilder *builder, 306 GskGLShader *shader, 307 float width, 308 float height, 309 const guchar *uniform_data); 310 void ops_set_unblurred_outset_shadow (RenderOpBuilder *self, 311 const GskRoundedRect outline, 312 float spread, 313 const GdkRGBA *color, 314 float dx, 315 float dy); 316 317 void ops_set_linear_gradient (RenderOpBuilder *self, 318 guint n_color_stops, 319 const GskColorStop *color_stops, 320 gboolean repeat, 321 float start_x, 322 float start_y, 323 float end_x, 324 float end_y); 325 void ops_set_radial_gradient (RenderOpBuilder *self, 326 guint n_color_stops, 327 const GskColorStop *color_stops, 328 gboolean repeat, 329 float center_x, 330 float center_y, 331 float start, 332 float end, 333 float hradius, 334 float vradius); 335 void ops_set_conic_gradient (RenderOpBuilder *self, 336 guint n_color_stops, 337 const GskColorStop *color_stops, 338 float center_x, 339 float center_y, 340 float angle); 341 342 GskQuadVertex * ops_draw (RenderOpBuilder *builder, 343 const GskQuadVertex vertex_data[GL_N_VERTICES]); 344 345 void ops_offset (RenderOpBuilder *builder, 346 float x, 347 float y); 348 349 gpointer ops_begin (RenderOpBuilder *builder, 350 OpKind kind); 351 OpBuffer *ops_get_buffer (RenderOpBuilder *builder); 352 353 #endif 354