aa9c3dc5618602f72c4c3eedc1db80bbbaf53142
[framework/graphics/cairo.git] / src / cairo-gl-private.h
1 /* cairo - a vector graphics library with display and print output
2  *
3  * Copyright © 2009 Eric Anholt
4  * Copyright © 2009 Chris Wilson
5  * Copyright © 2005,2010 Red Hat, Inc
6  * Copyright © 2011 Linaro Limited
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it either under the terms of the GNU Lesser General Public
10  * License version 2.1 as published by the Free Software Foundation
11  * (the "LGPL") or, at your option, under the terms of the Mozilla
12  * Public License Version 1.1 (the "MPL"). If you do not alter this
13  * notice, a recipient may use your version of this file under either
14  * the MPL or the LGPL.
15  *
16  * You should have received a copy of the LGPL along with this library
17  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
19  * You should have received a copy of the MPL along with this library
20  * in the file COPYING-MPL-1.1
21  *
22  * The contents of this file are subject to the Mozilla Public License
23  * Version 1.1 (the "License"); you may not use this file except in
24  * compliance with the License. You may obtain a copy of the License at
25  * http://www.mozilla.org/MPL/
26  *
27  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
28  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
29  * the specific language governing rights and limitations.
30  *
31  * The Original Code is the cairo graphics library.
32  *
33  * The Initial Developer of the Original Code is Red Hat, Inc.
34  *
35  * Contributor(s):
36  *      Benjamin Otte <otte@gnome.org>
37  *      Carl Worth <cworth@cworth.org>
38  *      Chris Wilson <chris@chris-wilson.co.uk>
39  *      Eric Anholt <eric@anholt.net>
40  *      T. Zachary Laine <whatwasthataddress@gmail.com>
41  *      Alexandros Frantzis <alexandros.frantzis@linaro.org>
42  */
43
44 #ifndef CAIRO_GL_PRIVATE_H
45 #define CAIRO_GL_PRIVATE_H
46
47 #define GL_GLEXT_PROTOTYPES
48
49 #include "cairoint.h"
50
51 #include "cairo-gl.h"
52 #include "cairo-gl-gradient-private.h"
53
54 #include "cairo-device-private.h"
55 #include "cairo-error-private.h"
56 #include "cairo-rtree-private.h"
57 #include "cairo-scaled-font-private.h"
58 #include "cairo-spans-compositor-private.h"
59 #include "cairo-array-private.h"
60 #include "cairo-stroke-dash-private.h"
61
62 #include <assert.h>
63
64 #if CAIRO_HAS_GL_SURFACE
65 #include <GL/gl.h>
66 #include <GL/glext.h>
67 #elif CAIRO_HAS_GLESV2_SURFACE
68 #include <GLES2/gl2.h>
69 #include <GLES2/gl2ext.h>
70 #endif
71
72 #include "cairo-gl-ext-def-private.h"
73
74 #define DEBUG_GL 0
75
76 #if DEBUG_GL && __GNUC__
77 #define UNSUPPORTED(reason) ({ \
78     fprintf (stderr, \
79              "cairo-gl: hit unsupported operation in %s(), line %d: %s\n", \
80              __FUNCTION__, __LINE__, reason); \
81     CAIRO_INT_STATUS_UNSUPPORTED; \
82 })
83 #else
84 #define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED
85 #endif
86
87 #define CAIRO_GL_VERSION_ENCODE(major, minor) ( \
88           ((major) * 256)                       \
89         + ((minor) *   1))
90
91 /* maximal number of shaders we keep in the cache.
92  * Random number that is hopefully big enough to not cause many cache evictions. */
93 #define CAIRO_GL_MAX_SHADERS_PER_CONTEXT 64
94
95 /* VBO size that we allocate, smaller size means we gotta flush more often */
96 #define CAIRO_GL_VBO_SIZE 16384
97
98 #define IMAGE_CACHE_WIDTH 2048
99 #define IMAGE_CACHE_HEIGHT 2048
100 #define IMAGE_CACHE_MIN_SIZE 1
101 #define IMAGE_CACHE_MAX_SIZE 256
102
103 typedef struct _cairo_gl_surface cairo_gl_surface_t;
104
105 /* GL flavor */
106 typedef enum cairo_gl_flavor {
107     CAIRO_GL_FLAVOR_NONE = 0,
108     CAIRO_GL_FLAVOR_DESKTOP = 1,
109     CAIRO_GL_FLAVOR_ES = 2
110 } cairo_gl_flavor_t;
111
112 /* Indices for vertex attributes used by BindAttribLocation etc */
113 enum {
114     CAIRO_GL_VERTEX_ATTRIB_INDEX = 0,
115     CAIRO_GL_COLOR_ATTRIB_INDEX  = 1,
116     CAIRO_GL_COVERAGE_ATTRIB_INDEX  = 2,
117     CAIRO_GL_TEXCOORD0_ATTRIB_INDEX = 3,
118     CAIRO_GL_TEXCOORD1_ATTRIB_INDEX = 4,
119     CAIRO_GL_START_COORD0_ATTRIB_INDEX = 5,
120     CAIRO_GL_START_COORD1_ATTRIB_INDEX = 6,
121     CAIRO_GL_STOP_COORD0_ATTRIB_INDEX = 7,
122     CAIRO_GL_STOP_COORD1_ATTRIB_INDEX = 8
123 };
124
125 typedef enum cairo_gl_operand_type {
126     CAIRO_GL_OPERAND_NONE,
127     CAIRO_GL_OPERAND_CONSTANT,
128     CAIRO_GL_OPERAND_TEXTURE,
129     CAIRO_GL_OPERAND_LINEAR_GRADIENT,
130     CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0,
131     CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE,
132     CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT,
133
134     CAIRO_GL_OPERAND_COUNT
135 } cairo_gl_operand_type_t;
136
137 typedef enum cairo_gl_draw_mode {
138     CAIRO_GL_VERTEX,
139     CAIRO_GL_LINE_STRIP,
140     CAIRO_GL_LINES
141 } cairo_gl_draw_mode_t;
142
143 /* This union structure describes a potential source or mask operand to the
144  * compositing equation.
145  */
146 typedef struct cairo_gl_operand {
147     cairo_gl_operand_type_t type;
148     union {
149         struct {
150             GLuint tex;
151             cairo_gl_surface_t *surface;
152             cairo_gl_surface_t *owns_surface;
153             cairo_surface_attributes_t attributes;
154             cairo_bool_t use_atlas;
155             cairo_extend_t extend;
156                 struct { float x, y; } p1, p2;
157         } texture;
158         struct {
159             GLfloat color[4];
160         } constant;
161         struct {
162             cairo_gl_gradient_t *gradient;
163             cairo_matrix_t m;
164             cairo_circle_double_t circle_d;
165             double radius_0, a;
166             cairo_extend_t extend;
167         } gradient;
168     };
169     unsigned int vertex_offset;
170     cairo_bool_t use_color_attribute;
171 } cairo_gl_operand_t;
172
173 typedef struct cairo_gl_source {
174     cairo_surface_t base;
175     cairo_gl_operand_t operand;
176 } cairo_gl_source_t;
177
178 struct _cairo_gl_surface {
179     cairo_surface_t base;
180     cairo_gl_operand_t operand;
181
182     int width, height;
183
184     GLuint tex; /* GL texture object containing our data. */
185     GLuint fb; /* GL framebuffer object wrapping our data. */
186     GLuint depth_stencil; /* GL renderbuffer object for holding stencil buffer clip. */
187
188 #if CAIRO_HAS_GL_SURFACE
189     GLuint msaa_rb; /* The ARB MSAA path uses a renderbuffer. */
190     GLuint msaa_fb;
191 #endif
192     GLuint msaa_depth_stencil;
193
194     cairo_bool_t stencil_and_msaa_caps_initialized;
195     cairo_bool_t supports_stencil; /* Stencil support for for non-texture surfaces. */
196     cairo_bool_t supports_msaa;
197     cairo_bool_t msaa_active; /* Whether the multisampling
198                                  framebuffer is active or not. */
199
200     int owns_tex;
201     cairo_bool_t needs_update;
202
203     cairo_region_t *clip_region;
204     GLuint bounded_tex;         /* bounded tex for non-texture surface */
205
206     /* Indicate whether we need to cache it in image_cache. */
207     cairo_bool_t needs_to_cache;
208     /* Damage is too expensive to check, we use this flag. */
209     cairo_bool_t content_changed;
210 };
211
212 typedef struct cairo_gl_glyph_cache {
213     cairo_rtree_t rtree;
214     cairo_gl_surface_t *surface;
215 } cairo_gl_glyph_cache_t;
216
217 typedef enum cairo_gl_tex {
218     CAIRO_GL_TEX_SOURCE = 0,
219     CAIRO_GL_TEX_MASK = 1,
220     CAIRO_GL_TEX_TEMP = 2
221 } cairo_gl_tex_t;
222
223 typedef struct cairo_gl_shader_impl cairo_gl_shader_impl_t;
224
225 typedef struct cairo_gl_shader {
226     GLuint fragment_shader;
227     GLuint program;
228     cairo_hash_table_t *uniform_cache;
229 } cairo_gl_shader_t;
230
231 typedef struct cairo_gl_image_cache {
232     cairo_rtree_t rtree;
233     cairo_gl_surface_t *surface;
234 } cairo_gl_image_cache_t;
235
236 typedef struct cairo_gl_image {
237     cairo_rtree_node_t node;
238     cairo_surface_t *original_surface;
239     struct { float x, y; } p1, p2;
240     cairo_gl_context_t *ctx;
241     cairo_bool_t node_removed;
242     cairo_bool_t user_data_removed;
243 } cairo_gl_image_t;
244
245 typedef enum cairo_gl_shader_in {
246     CAIRO_GL_SHADER_IN_NORMAL,
247     CAIRO_GL_SHADER_IN_CA_SOURCE,
248     CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA,
249
250     CAIRO_GL_SHADER_IN_COUNT
251 } cairo_gl_shader_in_t;
252
253
254 typedef struct _cairo_gl_hairline_closure
255 {
256     cairo_gl_context_t *ctx;
257     double tolerance;
258     cairo_stroker_dash_t dash;
259     cairo_matrix_t *ctm;
260     cairo_matrix_t *ctm_inverse;
261     cairo_point_t current_point;
262
263     cairo_point_t stroke_first_point;  /* First stroke point at move_to. */
264     double stroke_first_dx;
265     double stroke_first_dy;
266     cairo_bool_t stroke_first_capped;
267     cairo_bool_t moved_to_stroke_first_point;
268
269     cairo_line_cap_t cap_style;
270
271     cairo_bool_t line_last_capped;
272
273     cairo_point_t line_last_point;
274     double line_last_dx;
275     double line_last_dy;
276
277     cairo_bool_t initialized;
278 } cairo_gl_hairline_closure_t;
279
280 typedef enum cairo_gl_var_type {
281   CAIRO_GL_VAR_NONE,
282   CAIRO_GL_VAR_COLOR,
283   CAIRO_GL_VAR_TEXCOORDS,
284 } cairo_gl_var_type_t;
285
286 #define cairo_gl_var_type_hash(src,mask,src_atlas_extend,mask_atlas_extend,src_use_atlas,mask_use_atlas, spans,dest) ((spans) << 11) | ((mask) << 9 | (src << 7) | (mask_atlas_extend << 5) | (src_atlas_extend << 3) | (mask_use_atlas << 2) | (src_use_atlas << 1) | (dest))
287 #define CAIRO_GL_VAR_TYPE_MAX ((CAIRO_GL_VAR_TEXCOORDS << 11) | (CAIRO_GL_VAR_TEXCOORDS << 9) | (CAIRO_GL_VAR_TEXCOORDS << 5) | CAIRO_GL_VAR_TEXCOORDS)
288
289 typedef void (*cairo_gl_generic_func_t)(void);
290 typedef cairo_gl_generic_func_t (*cairo_gl_get_proc_addr_func_t)(const char *procname);
291
292 typedef struct _cairo_gl_dispatch {
293     /* Buffers */
294     void (*GenBuffers) (GLsizei n, GLuint *buffers);
295     void (*BindBuffer) (GLenum target, GLuint buffer);
296     void (*BufferData) (GLenum target, GLsizeiptr size,
297                           const GLvoid* data, GLenum usage);
298     GLvoid *(*MapBuffer) (GLenum target, GLenum access);
299     GLboolean (*UnmapBuffer) (GLenum target);
300
301     /* Shaders */
302     GLuint (*CreateShader) (GLenum type);
303     void (*ShaderSource) (GLuint shader, GLsizei count,
304                             const GLchar** string, const GLint* length);
305     void (*CompileShader) (GLuint shader);
306     void (*GetShaderiv) (GLuint shader, GLenum pname, GLint *params);
307     void (*GetShaderInfoLog) (GLuint shader, GLsizei bufSize,
308                                 GLsizei *length, GLchar *infoLog);
309     void (*DeleteShader) (GLuint shader);
310
311     /* Programs */
312     GLuint (*CreateProgram) (void);
313     void (*AttachShader) (GLuint program, GLuint shader);
314     void (*DeleteProgram) (GLuint program);
315     void (*LinkProgram) (GLuint program);
316     void (*UseProgram) (GLuint program);
317     void (*GetProgramiv) (GLuint program, GLenum pname, GLint *params);
318     void (*GetProgramInfoLog) (GLuint program, GLsizei bufSize,
319                                  GLsizei *length, GLchar *infoLog);
320
321     /* Uniforms */
322     GLint (*GetUniformLocation) (GLuint program, const GLchar* name);
323     void (*Uniform1f) (GLint location, GLfloat x);
324     void (*Uniform2f) (GLint location, GLfloat x, GLfloat y);
325     void (*Uniform3f) (GLint location, GLfloat x, GLfloat y, GLfloat z);
326     void (*Uniform4f) (GLint location, GLfloat x, GLfloat y, GLfloat z,
327                          GLfloat w);
328     void (*UniformMatrix3fv) (GLint location, GLsizei count,
329                                 GLboolean transpose, const GLfloat *value);
330     void (*UniformMatrix4fv) (GLint location, GLsizei count,
331                               GLboolean transpose, const GLfloat *value);
332     void (*Uniform1i) (GLint location, GLint x);
333
334     /* Attributes */
335     void (*BindAttribLocation) (GLuint program, GLuint index,
336                                 const GLchar *name);
337     void (*VertexAttribPointer) (GLuint index, GLint size, GLenum type,
338                                  GLboolean normalized, GLsizei stride,
339                                  const GLvoid *pointer);
340     void (*EnableVertexAttribArray) (GLuint index);
341     void (*DisableVertexAttribArray) (GLuint index);
342
343     /* Framebuffer objects */
344     void (*GenFramebuffers) (GLsizei n, GLuint* framebuffers);
345     void (*BindFramebuffer) (GLenum target, GLuint framebuffer);
346     void (*FramebufferTexture2D) (GLenum target, GLenum attachment,
347                                     GLenum textarget, GLuint texture,
348                                     GLint level);
349     GLenum (*CheckFramebufferStatus) (GLenum target);
350     void (*DeleteFramebuffers) (GLsizei n, const GLuint* framebuffers);
351     void (*GenRenderbuffers) (GLsizei n, GLuint *renderbuffers);
352     void (*BindRenderbuffer) (GLenum target, GLuint renderbuffer);
353     void (*RenderbufferStorage) (GLenum target, GLenum internal_format,
354                                  GLsizei width, GLsizei height);
355     void (*FramebufferRenderbuffer) (GLenum target, GLenum attachment,
356                                      GLenum renderbuffer_ttarget, GLuint renderbuffer);
357     void (*DeleteRenderbuffers) (GLsizei n, GLuint *renderbuffers);
358     void (*BlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
359                              GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
360                              GLbitfield mask, GLenum filter);
361     void (*RenderbufferStorageMultisample) (GLenum target, GLsizei samples,
362                                             GLenum internalformat,
363                                             GLsizei width, GLsizei height);
364     void (*FramebufferTexture2DMultisample) (GLenum target, GLenum attachment,
365                                              GLenum textarget, GLuint texture,
366                                              GLint level, GLsizei samples);
367 } cairo_gl_dispatch_t;
368
369 struct _cairo_gl_context {
370     cairo_device_t base;
371
372     const cairo_compositor_t *compositor;
373
374     GLuint texture_load_pbo;
375     GLuint vbo;
376     GLint max_framebuffer_size;
377     GLint max_texture_size;
378     GLint max_textures;
379     GLenum tex_target;
380
381     GLint num_samples;
382     cairo_bool_t supports_msaa;
383
384     const cairo_gl_shader_impl_t *shader_impl;
385
386     GLuint vertex_shaders[CAIRO_GL_VAR_TYPE_MAX + 1];
387     cairo_gl_shader_t fill_rectangles_shader;
388     cairo_cache_t shaders;
389
390     cairo_cache_t gradients;
391
392     cairo_gl_glyph_cache_t glyph_cache[2];
393     cairo_list_t fonts;
394
395     cairo_gl_surface_t *current_target;
396     cairo_operator_t current_operator;
397     cairo_gl_shader_t *pre_shader; /* for component alpha */
398     cairo_gl_shader_t *current_shader;
399
400     cairo_gl_operand_t operands[2];
401     cairo_bool_t spans;
402
403     char *vb;
404     char *vb_mem;
405     unsigned int vb_offset;
406     unsigned int vertex_size;
407     cairo_region_t *clip_region;
408     cairo_clip_t *clip;
409     cairo_array_t tristrip_indices;
410
411     cairo_bool_t has_mesa_pack_invert;
412     cairo_gl_dispatch_t dispatch;
413     GLfloat modelviewprojection_matrix[16];
414     cairo_gl_flavor_t gl_flavor;
415     cairo_bool_t has_map_buffer;
416     cairo_bool_t has_packed_depth_stencil;
417     cairo_bool_t has_npot_repeat;
418
419     cairo_bool_t thread_aware;
420
421     /* GL stencil and depth buffers are shared among all surfaces
422        to preserve memory. In the future this could be a pool of renderbuffers
423        with an eviction policy. */
424     GLuint shared_depth_stencil;
425     int shared_depth_stencil_width;
426     int shared_depth_stencil_height;
427     GLuint shared_msaa_depth_stencil;
428     int shared_msaa_depth_stencil_width;
429     int shared_msaa_depth_stencil_height;
430
431     cairo_gl_image_cache_t image_cache;
432     cairo_gl_draw_mode_t draw_mode;
433
434     void (*acquire) (void *ctx);
435     void (*release) (void *ctx);
436
437     void (*make_current) (void *ctx, cairo_gl_surface_t *surface);
438     void (*swap_buffers)(void *ctx, cairo_gl_surface_t *surface);
439     void (*destroy) (void *ctx);
440 };
441
442 typedef struct _cairo_gl_composite {
443     cairo_gl_surface_t *dst;
444     cairo_operator_t op;
445     cairo_region_t *clip_region;
446
447     cairo_gl_operand_t src;
448     cairo_gl_operand_t mask;
449     cairo_bool_t spans;
450
451     cairo_clip_t *clip;
452 } cairo_gl_composite_t;
453
454 typedef struct _cairo_gl_font {
455     cairo_scaled_font_private_t         base;
456     cairo_device_t                      *device;
457     cairo_list_t                        link;
458 } cairo_gl_font_t;
459
460 static cairo_always_inline GLenum
461 _cairo_gl_get_error (void)
462 {
463     GLenum err = glGetError();
464
465     if (unlikely (err))
466         while (glGetError ());
467
468     return err;
469 }
470
471 static inline cairo_device_t *
472 _cairo_gl_context_create_in_error (cairo_status_t status)
473 {
474     return (cairo_device_t *) _cairo_device_create_in_error (status);
475 }
476
477 cairo_private cairo_status_t
478 _cairo_gl_context_init (cairo_gl_context_t *ctx);
479
480 cairo_private void
481 _cairo_gl_surface_init (cairo_device_t *device,
482                         cairo_gl_surface_t *surface,
483                         cairo_content_t content,
484                         int width, int height);
485
486 static cairo_always_inline cairo_bool_t cairo_warn
487 _cairo_gl_surface_is_texture (cairo_gl_surface_t *surface)
488 {
489     return surface->tex != 0;
490 }
491
492 cairo_private cairo_status_t
493 _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
494                               cairo_image_surface_t *src,
495                               int src_x, int src_y,
496                               int width, int height,
497                               int dst_x, int dst_y);
498
499 static cairo_always_inline cairo_bool_t
500 _cairo_gl_device_has_glsl (cairo_device_t *device)
501 {
502     return ((cairo_gl_context_t *) device)->shader_impl != NULL;
503 }
504
505 static cairo_always_inline cairo_bool_t
506 _cairo_gl_device_requires_power_of_two_textures (cairo_device_t *device)
507 {
508     return ((cairo_gl_context_t *) device)->tex_target == GL_TEXTURE_RECTANGLE;
509 }
510
511 static cairo_always_inline cairo_status_t cairo_warn
512 _cairo_gl_context_acquire (cairo_device_t *device,
513                            cairo_gl_context_t **ctx)
514 {
515     cairo_status_t status;
516
517     status = cairo_device_acquire (device);
518     if (unlikely (status))
519         return status;
520
521     /* clear potential previous GL errors */
522     _cairo_gl_get_error ();
523
524     *ctx = (cairo_gl_context_t *) device;
525     return CAIRO_STATUS_SUCCESS;
526 }
527
528 static cairo_always_inline cairo_warn cairo_status_t
529 _cairo_gl_context_release (cairo_gl_context_t *ctx, cairo_status_t status)
530 {
531     GLenum err;
532
533     err = _cairo_gl_get_error ();
534
535     if (unlikely (err)) {
536         cairo_status_t new_status;
537         new_status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
538         if (status == CAIRO_STATUS_SUCCESS)
539             status = new_status;
540     }
541
542     cairo_device_release (&(ctx)->base);
543
544     return status;
545 }
546
547 cairo_private void
548 _cairo_gl_activate_surface_as_nonmultisampling (cairo_gl_context_t *ctx,
549                                                 cairo_gl_surface_t *surface);
550
551 cairo_private void
552 _cairo_gl_context_set_destination (cairo_gl_context_t *ctx,
553                                    cairo_gl_surface_t *surface,
554                                    cairo_bool_t multisampling);
555
556 cairo_private void
557 _cairo_gl_context_activate (cairo_gl_context_t *ctx,
558                             cairo_gl_tex_t      tex_unit);
559
560 cairo_private cairo_bool_t
561 _cairo_gl_operator_is_supported (cairo_operator_t op);
562
563 cairo_private cairo_bool_t
564 _cairo_gl_ensure_stencil (cairo_gl_context_t *ctx,
565                           cairo_gl_surface_t *surface);
566
567 cairo_private void
568 _disable_scissor_buffer (void);
569
570 cairo_private void
571 _disable_stencil_buffer (void);
572
573 cairo_private cairo_status_t
574 _cairo_gl_composite_init (cairo_gl_composite_t *setup,
575                           cairo_operator_t op,
576                           cairo_gl_surface_t *dst,
577                           cairo_bool_t has_component_alpha);
578
579 cairo_private void
580 _cairo_gl_composite_fini (cairo_gl_composite_t *setup);
581
582 cairo_private void
583 _cairo_gl_composite_set_clip_region (cairo_gl_composite_t *setup,
584                                      cairo_region_t *clip_region);
585
586 cairo_private void
587 _cairo_gl_composite_set_clip(cairo_gl_composite_t *setup,
588                              cairo_clip_t *clip);
589
590 cairo_private cairo_int_status_t
591 _cairo_gl_composite_set_source (cairo_gl_composite_t *setup,
592                                 const cairo_pattern_t *pattern,
593                                 const cairo_rectangle_int_t *sample,
594                                 const cairo_rectangle_int_t *extents,
595                                 cairo_bool_t use_color_attribute);
596
597 cairo_private void
598 _cairo_gl_composite_set_solid_source (cairo_gl_composite_t *setup,
599                                       const cairo_color_t *color);
600
601 cairo_private void
602 _cairo_gl_composite_set_source_operand (cairo_gl_composite_t *setup,
603                                         const cairo_gl_operand_t *source);
604
605 cairo_private cairo_int_status_t
606 _cairo_gl_composite_set_mask (cairo_gl_composite_t *setup,
607                               const cairo_pattern_t *pattern,
608                               const cairo_rectangle_int_t *sample,
609                               const cairo_rectangle_int_t *extents);
610
611 cairo_private void
612 _cairo_gl_composite_set_mask_operand (cairo_gl_composite_t *setup,
613                                       const cairo_gl_operand_t *mask);
614
615 cairo_private void
616 _cairo_gl_composite_set_spans (cairo_gl_composite_t *setup);
617
618 cairo_private cairo_status_t
619 _cairo_gl_composite_begin (cairo_gl_composite_t *setup,
620                            cairo_gl_context_t **ctx);
621
622 cairo_private cairo_status_t
623 _cairo_gl_composite_begin_multisample (cairo_gl_composite_t *setup,
624                                        cairo_gl_context_t **ctx_out,
625                                        cairo_bool_t multisampling);
626
627 cairo_private void
628 _cairo_gl_composite_emit_rect (cairo_gl_context_t *ctx,
629                                GLfloat x1,
630                                GLfloat y1,
631                                GLfloat x2,
632                                GLfloat y2,
633                                uint8_t alpha);
634
635 cairo_private void
636 _cairo_gl_composite_emit_glyph (cairo_gl_context_t *ctx,
637                                 GLfloat x1,
638                                 GLfloat y1,
639                                 GLfloat x2,
640                                 GLfloat y2,
641                                 GLfloat glyph_x1,
642                                 GLfloat glyph_y1,
643                                 GLfloat glyph_x2,
644                                 GLfloat glyph_y2);
645
646 cairo_private void
647 _cairo_gl_composite_flush (cairo_gl_context_t *ctx);
648
649 cairo_private cairo_int_status_t
650 _cairo_gl_composite_emit_quad_as_tristrip (cairo_gl_context_t   *ctx,
651                                            cairo_gl_composite_t *setup,
652                                            const cairo_point_t   quad[4]);
653
654 cairo_private cairo_int_status_t
655 _cairo_gl_composite_emit_triangle_as_tristrip (cairo_gl_context_t       *ctx,
656                                                cairo_gl_composite_t     *setup,
657                                                const cairo_point_t       triangle[3]);
658
659 cairo_private cairo_int_status_t
660 _cairo_gl_composite_emit_point_as_tristrip_line (cairo_gl_context_t  *ctx,
661                                                  const cairo_point_t point[2],
662                                                  cairo_bool_t        start_point);
663
664 cairo_private cairo_int_status_t
665 _cairo_gl_composite_emit_point_as_single_line (cairo_gl_context_t  *ctx,
666                                                 const cairo_point_t point[2]);
667
668 cairo_private void
669 _cairo_gl_context_destroy_operand (cairo_gl_context_t *ctx,
670                                    cairo_gl_tex_t tex_unit);
671
672 cairo_private cairo_bool_t
673 _cairo_gl_get_image_format_and_type (cairo_gl_flavor_t flavor,
674                                      pixman_format_code_t pixman_format,
675                                      GLenum *internal_format, GLenum *format,
676                                      GLenum *type, cairo_bool_t *has_alpha,
677                                      cairo_bool_t *needs_swap);
678
679 cairo_private void
680 _cairo_gl_glyph_cache_init (cairo_gl_glyph_cache_t *cache);
681
682 cairo_private void
683 _cairo_gl_glyph_cache_fini (cairo_gl_context_t *ctx,
684                             cairo_gl_glyph_cache_t *cache);
685
686 cairo_private cairo_int_status_t
687 _cairo_gl_surface_show_glyphs (void                     *abstract_dst,
688                                cairo_operator_t          op,
689                                const cairo_pattern_t    *source,
690                                cairo_glyph_t            *glyphs,
691                                int                       num_glyphs,
692                                cairo_scaled_font_t      *scaled_font,
693                                const cairo_clip_t       *clip,
694                                int                      *remaining_glyphs);
695
696 cairo_private cairo_status_t
697 _cairo_gl_context_init_shaders (cairo_gl_context_t *ctx);
698
699 cairo_private void
700 _cairo_gl_context_fini_shaders (cairo_gl_context_t *ctx);
701
702 static cairo_always_inline cairo_bool_t
703 _cairo_gl_context_is_flushed (cairo_gl_context_t *ctx)
704 {
705     return ctx->vb == NULL;
706 }
707
708 cairo_private cairo_status_t
709 _cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx,
710                               cairo_gl_operand_t *source,
711                               cairo_gl_operand_t *mask,
712                               cairo_bool_t use_coverage,
713                               cairo_gl_shader_in_t in,
714                               cairo_gl_shader_t **shader);
715
716 cairo_private void
717 _cairo_gl_shader_bind_float (cairo_gl_context_t *ctx,
718                              const char *name,
719                              float value);
720
721 cairo_private void
722 _cairo_gl_shader_bind_vec2 (cairo_gl_context_t *ctx,
723                             const char *name,
724                             float value0, float value1);
725
726 cairo_private void
727 _cairo_gl_shader_bind_vec3 (cairo_gl_context_t *ctx,
728                             const char *name,
729                             float value0,
730                             float value1,
731                             float value2);
732
733 cairo_private void
734 _cairo_gl_shader_bind_vec4 (cairo_gl_context_t *ctx,
735                             const char *name,
736                             float value0, float value1,
737                             float value2, float value3);
738
739 cairo_private void
740 _cairo_gl_shader_bind_matrix (cairo_gl_context_t *ctx,
741                               const char *name,
742                               cairo_matrix_t* m);
743
744 cairo_private void
745 _cairo_gl_shader_bind_matrix4f (cairo_gl_context_t *ctx,
746                                 const char *name,
747                                 GLfloat* gl_m);
748
749 cairo_private void
750 _cairo_gl_set_shader (cairo_gl_context_t *ctx,
751                       cairo_gl_shader_t *shader);
752
753 cairo_private void
754 _cairo_gl_shader_fini (cairo_gl_context_t *ctx, cairo_gl_shader_t *shader);
755
756 cairo_private int
757 _cairo_gl_get_version (void);
758
759 cairo_private cairo_gl_flavor_t
760 _cairo_gl_get_flavor (void);
761
762 cairo_private cairo_bool_t
763 _cairo_gl_has_extension (const char *ext);
764
765 cairo_private cairo_status_t
766 _cairo_gl_dispatch_init(cairo_gl_dispatch_t *dispatch,
767                         cairo_gl_get_proc_addr_func_t get_proc_addr);
768
769 cairo_private cairo_int_status_t
770 _cairo_gl_operand_init (cairo_gl_operand_t *operand,
771                         const cairo_pattern_t *pattern,
772                         cairo_gl_surface_t *dst,
773                         const cairo_rectangle_int_t *sample,
774                         const cairo_rectangle_int_t *extents,
775                         cairo_bool_t use_color_attribute);
776
777 cairo_private void
778 _cairo_gl_solid_operand_init (cairo_gl_operand_t *operand,
779                               const cairo_color_t *color);
780
781 cairo_private cairo_filter_t
782 _cairo_gl_operand_get_filter (cairo_gl_operand_t *operand);
783
784 cairo_private GLint
785 _cairo_gl_operand_get_gl_filter (cairo_gl_operand_t *operand);
786
787 cairo_private cairo_extend_t
788 _cairo_gl_operand_get_extend (cairo_gl_operand_t *operand);
789
790 cairo_private cairo_extend_t
791 _cairo_gl_operand_get_atlas_extend (cairo_gl_operand_t *operand);
792
793 cairo_private unsigned int
794 _cairo_gl_operand_get_vertex_size (cairo_gl_operand_t *operand);
795
796 cairo_private cairo_bool_t
797 _cairo_gl_operand_get_use_atlas (cairo_gl_operand_t *operand);
798
799 cairo_private cairo_bool_t
800 _cairo_gl_operand_needs_setup (cairo_gl_operand_t *dest,
801                                cairo_gl_operand_t *source,
802                                unsigned int        vertex_offset,
803                                cairo_bool_t        *needs_flush);
804
805 cairo_private void
806 _cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx,
807                                   cairo_gl_operand_t *operand,
808                                   cairo_gl_tex_t      tex_unit);
809
810 cairo_private void
811 _cairo_gl_operand_copy (cairo_gl_operand_t *dst,
812                         const cairo_gl_operand_t *src);
813
814 cairo_private void
815 _cairo_gl_operand_translate (cairo_gl_operand_t *operand,
816                              double tx, double ty);
817
818 cairo_private void
819 _cairo_gl_operand_destroy (cairo_gl_operand_t *operand);
820
821 cairo_private const cairo_compositor_t *
822 _cairo_gl_msaa_compositor_get (void);
823
824 cairo_private const cairo_compositor_t *
825 _cairo_gl_span_compositor_get (void);
826
827 cairo_private const cairo_compositor_t *
828 _cairo_gl_traps_compositor_get (void);
829
830 cairo_private cairo_int_status_t
831 _cairo_gl_check_composite_glyphs (const cairo_composite_rectangles_t *extents,
832                                   cairo_scaled_font_t *scaled_font,
833                                   cairo_glyph_t *glyphs,
834                                   int *num_glyphs);
835
836 cairo_private cairo_int_status_t
837 _cairo_gl_composite_glyphs (void                        *_dst,
838                             cairo_operator_t             op,
839                             cairo_surface_t             *_src,
840                             int                          src_x,
841                             int                          src_y,
842                             int                          dst_x,
843                             int                          dst_y,
844                             cairo_composite_glyphs_info_t *info);
845
846 cairo_int_status_t
847 _cairo_gl_composite_glyphs_with_clip (void                          *_dst,
848                                       cairo_operator_t               op,
849                                       cairo_surface_t               *_src,
850                                       int                            src_x,
851                                       int                            src_y,
852                                       int                            dst_x,
853                                       int                            dst_y,
854                                       cairo_composite_glyphs_info_t *info,
855                                       cairo_clip_t                           *clip,
856                                       cairo_bool_t                           via_msaa_compositor);
857
858 cairo_private void
859 _cairo_gl_image_node_destroy (cairo_rtree_node_t *node);
860
861 cairo_private void
862 _cairo_gl_image_node_fini (void *data);
863
864 cairo_private void
865 _cairo_gl_image_cache_unlock (cairo_gl_context_t *ctx);
866
867 cairo_int_status_t
868 _cairo_gl_image_cache_init (cairo_gl_context_t *ctx);
869
870 cairo_private void
871 _cairo_gl_ensure_framebuffer (cairo_gl_context_t *ctx,
872                               cairo_gl_surface_t *surface);
873
874 cairo_private cairo_surface_t *
875 _cairo_gl_surface_create_scratch (cairo_gl_context_t   *ctx,
876                                   cairo_content_t       content,
877                                   int                   width,
878                                   int                   height,
879                                   cairo_bool_t          true_alpha);
880
881 cairo_private cairo_surface_t *
882 _cairo_gl_pattern_to_source (cairo_surface_t *dst,
883                              const cairo_pattern_t *pattern,
884                              cairo_bool_t is_mask,
885                              const cairo_rectangle_int_t *extents,
886                              const cairo_rectangle_int_t *sample,
887                              int *src_x, int *src_y);
888
889 cairo_private cairo_int_status_t
890 _cairo_gl_msaa_compositor_draw_clip (cairo_gl_context_t *ctx,
891                                      cairo_gl_composite_t *setup,
892                                      cairo_clip_t *clip,
893                                      cairo_traps_t *traps);
894
895 cairo_private cairo_surface_t *
896 _cairo_gl_white_source (void);
897
898 static inline cairo_gl_operand_t *
899 source_to_operand (cairo_surface_t *surface)
900 {
901     cairo_gl_source_t *source = (cairo_gl_source_t *)surface;
902     return source ? &source->operand : NULL;
903 }
904
905 static inline void
906 _cairo_gl_glyph_cache_unlock (cairo_gl_glyph_cache_t *cache)
907 {
908     _cairo_rtree_unpin (&cache->rtree);
909 }
910
911 cairo_private void
912 _cairo_gl_scissor_to_extents (cairo_gl_surface_t        *surface,
913                               const cairo_rectangle_int_t       *extents);
914
915
916 cairo_private cairo_bool_t
917 _cairo_gl_hairline_style_is_hairline (const cairo_stroke_style_t *style,
918                                       const cairo_matrix_t       *ctm);
919
920 cairo_private cairo_status_t
921 _cairo_gl_hairline_move_to (void *closure,
922                             const cairo_point_t *point);
923
924 cairo_private cairo_status_t
925 _cairo_gl_hairline_line_to (void *closure,
926                             const cairo_point_t *point);
927
928 cairo_private cairo_status_t
929 _cairo_gl_hairline_line_to_dashed (void *closure,
930                                    const cairo_point_t *point);
931
932 cairo_private cairo_status_t
933 _cairo_gl_hairline_curve_to (void *closure,
934                              const cairo_point_t *p0,
935                              const cairo_point_t *p1,
936                              const cairo_point_t *p2);
937
938 cairo_private cairo_status_t
939 _cairo_gl_hairline_close_path (void *closure);
940
941 cairo_private cairo_status_t
942 _cairo_gl_path_fixed_stroke_to_hairline (const cairo_path_fixed_t *path,
943                                          cairo_gl_hairline_closure_t *closure,
944                                          const cairo_stroke_style_t *style,
945                                          const cairo_matrix_t *ctm,
946                                          const cairo_matrix_t *ctm_inverse,
947                                          cairo_path_fixed_move_to_func_t *move_to,
948                                          cairo_path_fixed_line_to_func_t *line_to,
949                                          cairo_path_fixed_curve_to_func_t *curve_to,
950                                          cairo_path_fixed_close_path_func_t *close_path);
951
952 slim_hidden_proto (cairo_gl_surface_create);
953 slim_hidden_proto (cairo_gl_surface_create_for_texture);
954
955 #endif /* CAIRO_GL_PRIVATE_H */