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 
61 #include <assert.h>
62 
63 #if CAIRO_HAS_GLESV3_SURFACE
64 #include <GLES3/gl3.h>
65 #include <GLES3/gl3ext.h>
66 #elif CAIRO_HAS_GLESV2_SURFACE
67 #include <GLES2/gl2.h>
68 #include <GLES2/gl2ext.h>
69 #elif CAIRO_HAS_GL_SURFACE
70 #include <GL/gl.h>
71 #include <GL/glext.h>
72 #endif
73 
74 #include "cairo-gl-ext-def-private.h"
75 
76 #define DEBUG_GL 0
77 
78 #if DEBUG_GL && __GNUC__
79 #define UNSUPPORTED(reason) ({ \
80     fprintf (stderr, \
81 	     "cairo-gl: hit unsupported operation in %s(), line %d: %s\n", \
82 	     __FUNCTION__, __LINE__, reason); \
83     CAIRO_INT_STATUS_UNSUPPORTED; \
84 })
85 #else
86 #define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED
87 #endif
88 
89 #define CAIRO_GL_VERSION_ENCODE(major, minor) (	\
90 	  ((major) * 256)			\
91 	+ ((minor) *   1))
92 
93 /* maximal number of shaders we keep in the cache.
94  * Random number that is hopefully big enough to not cause many cache evictions. */
95 #define CAIRO_GL_MAX_SHADERS_PER_CONTEXT 64
96 
97 /* VBO size that we allocate, smaller size means we gotta flush more often,
98  * but larger means hogging more memory and can cause trouble for drivers
99  * (especially on embedded devices). Use the CAIRO_GL_VBO_SIZE environment
100  * variable to set this to a different size. */
101 #define CAIRO_GL_VBO_SIZE_DEFAULT (1024*1024)
102 
103 typedef struct _cairo_gl_surface cairo_gl_surface_t;
104 
105 /* GL flavor is the type of GL supported by the underlying platform. */
106 typedef enum cairo_gl_flavor {
107     CAIRO_GL_FLAVOR_NONE = 0,
108     CAIRO_GL_FLAVOR_DESKTOP = 1,
109     CAIRO_GL_FLAVOR_ES2 = 2,
110     CAIRO_GL_FLAVOR_ES3 = 3
111 } cairo_gl_flavor_t;
112 
113 /* Indices for vertex attributes used by BindAttribLocation, etc. */
114 enum {
115     CAIRO_GL_VERTEX_ATTRIB_INDEX = 0,
116     CAIRO_GL_COLOR_ATTRIB_INDEX  = 1,
117     CAIRO_GL_TEXCOORD0_ATTRIB_INDEX = 2,
118     CAIRO_GL_TEXCOORD1_ATTRIB_INDEX = CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + 1
119 };
120 
121 typedef enum cairo_gl_operand_type {
122     CAIRO_GL_OPERAND_NONE,
123     CAIRO_GL_OPERAND_CONSTANT,
124     CAIRO_GL_OPERAND_TEXTURE,
125     CAIRO_GL_OPERAND_LINEAR_GRADIENT,
126     CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0,
127     CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE,
128     CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT,
129 
130     CAIRO_GL_OPERAND_COUNT
131 } cairo_gl_operand_type_t;
132 
133 /* This union structure describes a potential source or mask operand to the
134  * compositing equation.
135  */
136 typedef struct cairo_gl_operand {
137     cairo_gl_operand_type_t type;
138     union {
139 	struct {
140 	    GLuint tex;
141 	    cairo_gl_surface_t *surface;
142 	    cairo_gl_surface_t *owns_surface;
143 	    cairo_surface_attributes_t attributes;
144 	    int texgen;
145 	} texture;
146 	struct {
147 	    GLfloat color[4];
148 	} constant;
149 	struct {
150 	    cairo_gl_gradient_t *gradient;
151 	    cairo_matrix_t m;
152 	    cairo_circle_double_t circle_d;
153 	    double radius_0, a;
154 	    cairo_extend_t extend;
155 	    int texgen;
156 	} gradient;
157     };
158     unsigned int vertex_offset;
159 } cairo_gl_operand_t;
160 
161 typedef struct cairo_gl_source {
162     cairo_surface_t base;
163     cairo_gl_operand_t operand;
164 } cairo_gl_source_t;
165 
166 struct _cairo_gl_surface {
167     cairo_surface_t base;
168     cairo_gl_operand_t operand;
169 
170     int width, height;
171 
172     GLuint tex; /* GL texture object containing our data. */
173     GLuint fb; /* GL framebuffer object wrapping our data. */
174     GLuint depth_stencil; /* GL renderbuffer object for holding stencil buffer clip. */
175 
176 #if CAIRO_HAS_GL_SURFACE || CAIRO_HAS_GLESV3_SURFACE
177     GLuint msaa_rb; /* The ARB MSAA path uses a renderbuffer. */
178     GLuint msaa_fb;
179 #endif
180     GLuint msaa_depth_stencil;
181 
182     cairo_bool_t stencil_and_msaa_caps_initialized;
183     cairo_bool_t supports_stencil; /* Stencil support for for non-texture surfaces. */
184     cairo_bool_t supports_msaa;
185     GLint        num_samples;
186     cairo_bool_t msaa_active; /* Whether the multisampling
187 			         framebuffer is active or not. */
188     cairo_bool_t content_in_texture; /* whether we just uploaded image
189 					to texture, used for certain
190 					gles2 extensions and glesv3 */
191     cairo_clip_t *clip_on_stencil_buffer;
192 
193     int owns_tex;
194     cairo_bool_t needs_update;
195 
196     cairo_region_t *clip_region;
197 };
198 
199 typedef struct cairo_gl_glyph_cache {
200     cairo_rtree_t rtree;
201     cairo_gl_surface_t *surface;
202 } cairo_gl_glyph_cache_t;
203 
204 typedef enum cairo_gl_tex {
205     CAIRO_GL_TEX_SOURCE = 0,
206     CAIRO_GL_TEX_MASK = 1,
207     CAIRO_GL_TEX_TEMP = 2
208 } cairo_gl_tex_t;
209 
210 typedef struct cairo_gl_shader {
211     GLuint fragment_shader;
212     GLuint program;
213     GLint mvp_location;
214     GLint constant_location[2];
215     GLint a_location[2];
216     GLint circle_d_location[2];
217     GLint radius_0_location[2];
218     GLint texdims_location[2];
219     GLint texgen_location[2];
220 } cairo_gl_shader_t;
221 
222 typedef enum cairo_gl_shader_in {
223     CAIRO_GL_SHADER_IN_NORMAL,
224     CAIRO_GL_SHADER_IN_CA_SOURCE,
225     CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA,
226 
227     CAIRO_GL_SHADER_IN_COUNT
228 } cairo_gl_shader_in_t;
229 
230 typedef enum cairo_gl_var_type {
231   CAIRO_GL_VAR_NONE,
232   CAIRO_GL_VAR_TEXCOORDS,
233   CAIRO_GL_VAR_TEXGEN,
234 } cairo_gl_var_type_t;
235 
236 typedef enum cairo_gl_primitive_type {
237     CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES,
238     CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS
239 } cairo_gl_primitive_type_t;
240 
241 typedef void (*cairo_gl_emit_rect_t) (cairo_gl_context_t *ctx,
242 				      GLfloat x1, GLfloat y1,
243 				      GLfloat x2, GLfloat y2);
244 
245 typedef void (*cairo_gl_emit_span_t) (cairo_gl_context_t *ctx,
246 				      GLfloat x1, GLfloat y1,
247 				      GLfloat x2, GLfloat y2,
248 				      uint8_t alpha);
249 
250 typedef void (*cairo_gl_emit_glyph_t) (cairo_gl_context_t *ctx,
251 				       GLfloat x1, GLfloat y1,
252 				       GLfloat x2, GLfloat y2,
253 				       GLfloat glyph_x1, GLfloat glyph_y1,
254 				       GLfloat glyph_x2, GLfloat glyph_y2);
255 
256 #define cairo_gl_var_type_hash(src,mask,spans,dest) ((spans) << 5) | ((mask) << 3 | (src << 1) | (dest))
257 #define CAIRO_GL_VAR_TYPE_MAX (1 << 6)
258 
259 typedef void (*cairo_gl_generic_func_t)(void);
260 typedef cairo_gl_generic_func_t (*cairo_gl_get_proc_addr_func_t)(const char *procname);
261 
262 typedef struct _cairo_gl_dispatch {
263     /* Buffers */
264     void (*GenBuffers) (GLsizei n, GLuint *buffers);
265     void (*BindBuffer) (GLenum target, GLuint buffer);
266     void (*BufferData) (GLenum target, GLsizeiptr size,
267 			  const GLvoid* data, GLenum usage);
268     GLvoid *(*MapBuffer) (GLenum target, GLenum access);
269     GLboolean (*UnmapBuffer) (GLenum target);
270 
271     /* Shaders */
272     GLuint (*CreateShader) (GLenum type);
273     void (*ShaderSource) (GLuint shader, GLsizei count,
274 			    const GLchar** string, const GLint* length);
275     void (*CompileShader) (GLuint shader);
276     void (*GetShaderiv) (GLuint shader, GLenum pname, GLint *params);
277     void (*GetShaderInfoLog) (GLuint shader, GLsizei bufSize,
278 				GLsizei *length, GLchar *infoLog);
279     void (*DeleteShader) (GLuint shader);
280 
281     /* Programs */
282     GLuint (*CreateProgram) (void);
283     void (*AttachShader) (GLuint program, GLuint shader);
284     void (*DeleteProgram) (GLuint program);
285     void (*LinkProgram) (GLuint program);
286     void (*UseProgram) (GLuint program);
287     void (*GetProgramiv) (GLuint program, GLenum pname, GLint *params);
288     void (*GetProgramInfoLog) (GLuint program, GLsizei bufSize,
289 				 GLsizei *length, GLchar *infoLog);
290 
291     /* Uniforms */
292     GLint (*GetUniformLocation) (GLuint program, const GLchar* name);
293     void (*Uniform1f) (GLint location, GLfloat x);
294     void (*Uniform2f) (GLint location, GLfloat x, GLfloat y);
295     void (*Uniform3f) (GLint location, GLfloat x, GLfloat y, GLfloat z);
296     void (*Uniform4f) (GLint location, GLfloat x, GLfloat y, GLfloat z,
297 			 GLfloat w);
298     void (*UniformMatrix3fv) (GLint location, GLsizei count,
299 				GLboolean transpose, const GLfloat *value);
300     void (*UniformMatrix4fv) (GLint location, GLsizei count,
301 			      GLboolean transpose, const GLfloat *value);
302     void (*Uniform1i) (GLint location, GLint x);
303 
304     /* Attributes */
305     void (*BindAttribLocation) (GLuint program, GLuint index,
306 				const GLchar *name);
307     void (*VertexAttribPointer) (GLuint index, GLint size, GLenum type,
308 				 GLboolean normalized, GLsizei stride,
309 				 const GLvoid *pointer);
310     void (*EnableVertexAttribArray) (GLuint index);
311     void (*DisableVertexAttribArray) (GLuint index);
312 
313     /* Framebuffer objects */
314     void (*GenFramebuffers) (GLsizei n, GLuint* framebuffers);
315     void (*BindFramebuffer) (GLenum target, GLuint framebuffer);
316     void (*FramebufferTexture2D) (GLenum target, GLenum attachment,
317 				    GLenum textarget, GLuint texture,
318 				    GLint level);
319     GLenum (*CheckFramebufferStatus) (GLenum target);
320     void (*DeleteFramebuffers) (GLsizei n, const GLuint* framebuffers);
321     void (*GenRenderbuffers) (GLsizei n, GLuint *renderbuffers);
322     void (*BindRenderbuffer) (GLenum target, GLuint renderbuffer);
323     void (*RenderbufferStorage) (GLenum target, GLenum internal_format,
324 				 GLsizei width, GLsizei height);
325     void (*FramebufferRenderbuffer) (GLenum target, GLenum attachment,
326 				     GLenum renderbuffer_ttarget, GLuint renderbuffer);
327     void (*DeleteRenderbuffers) (GLsizei n, GLuint *renderbuffers);
328     void (*BlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
329 			     GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
330 			     GLbitfield mask, GLenum filter);
331     void (*RenderbufferStorageMultisample) (GLenum target, GLsizei samples,
332 					    GLenum internalformat,
333 					    GLsizei width, GLsizei height);
334     void (*FramebufferTexture2DMultisample) (GLenum target, GLenum attachment,
335 					     GLenum textarget, GLuint texture,
336 					     GLint level, GLsizei samples);
337 } cairo_gl_dispatch_t;
338 
339 struct _cairo_gl_context {
340     cairo_device_t base;
341 
342     const cairo_compositor_t *compositor;
343 
344     GLuint texture_load_pbo;
345     GLint max_framebuffer_size;
346     GLint max_texture_size;
347     GLint max_textures;
348     GLenum tex_target;
349 
350     GLint num_samples;
351     cairo_bool_t supports_msaa;
352     char *vb;
353 
354     cairo_bool_t has_shader_support;
355 
356     GLuint vertex_shaders[CAIRO_GL_VAR_TYPE_MAX];
357     cairo_gl_shader_t fill_rectangles_shader;
358     cairo_cache_t shaders;
359 
360     cairo_cache_t gradients;
361 
362     cairo_gl_glyph_cache_t glyph_cache[2];
363     cairo_list_t fonts;
364 
365     cairo_gl_surface_t *current_target;
366     cairo_operator_t current_operator;
367     cairo_gl_shader_t *pre_shader; /* for component alpha */
368     cairo_gl_shader_t *current_shader;
369 
370     cairo_gl_operand_t operands[2];
371     cairo_bool_t spans;
372 
373     unsigned int vbo_size;
374     unsigned int vb_offset;
375     unsigned int vertex_size;
376     cairo_region_t *clip_region;
377     cairo_clip_t *clip;
378 
379     cairo_gl_primitive_type_t primitive_type;
380     cairo_array_t tristrip_indices;
381 
382     cairo_bool_t has_mesa_pack_invert;
383     cairo_gl_dispatch_t dispatch;
384     GLfloat modelviewprojection_matrix[16];
385     cairo_gl_flavor_t gl_flavor;
386     cairo_bool_t has_map_buffer;
387     cairo_bool_t has_packed_depth_stencil;
388     cairo_bool_t has_npot_repeat;
389     cairo_bool_t can_read_bgra;
390 
391     cairo_bool_t thread_aware;
392 
393     void (*acquire) (void *ctx);
394     void (*release) (void *ctx);
395 
396     void (*make_current) (void *ctx, cairo_gl_surface_t *surface);
397     void (*swap_buffers)(void *ctx, cairo_gl_surface_t *surface);
398     void (*destroy) (void *ctx);
399 };
400 
401 typedef struct _cairo_gl_composite {
402     cairo_gl_surface_t *dst;
403     cairo_operator_t op;
404     cairo_region_t *clip_region;
405 
406     cairo_gl_operand_t src;
407     cairo_gl_operand_t mask;
408     cairo_bool_t spans;
409 
410     cairo_clip_t *clip;
411     cairo_bool_t multisample;
412 } cairo_gl_composite_t;
413 
414 typedef struct _cairo_gl_font {
415     cairo_scaled_font_private_t		base;
416     cairo_device_t			*device;
417     cairo_list_t			link;
418 } cairo_gl_font_t;
419 
420 static cairo_always_inline GLenum
_cairo_gl_get_error(void)421 _cairo_gl_get_error (void)
422 {
423     GLenum err = glGetError();
424 
425     if (unlikely (err))
426         while (glGetError ());
427 
428     return err;
429 }
430 
431 static inline cairo_device_t *
_cairo_gl_context_create_in_error(cairo_status_t status)432 _cairo_gl_context_create_in_error (cairo_status_t status)
433 {
434     return (cairo_device_t *) _cairo_device_create_in_error (status);
435 }
436 
437 cairo_private cairo_status_t
438 _cairo_gl_context_init (cairo_gl_context_t *ctx);
439 
440 cairo_private void
441 _cairo_gl_surface_init (cairo_device_t *device,
442 			cairo_gl_surface_t *surface,
443 			cairo_content_t content,
444 			int width, int height);
445 
446 static cairo_always_inline cairo_bool_t cairo_warn
_cairo_gl_surface_is_texture(cairo_gl_surface_t * surface)447 _cairo_gl_surface_is_texture (cairo_gl_surface_t *surface)
448 {
449     return surface->tex != 0;
450 }
451 
452 cairo_private cairo_status_t
453 _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
454 			      cairo_image_surface_t *src,
455 			      int src_x, int src_y,
456 			      int width, int height,
457 			      int dst_x, int dst_y,
458 			      cairo_bool_t force_flush);
459 
460 cairo_private cairo_int_status_t
461 _cairo_gl_surface_resolve_multisampling (cairo_gl_surface_t *surface);
462 
463 static cairo_always_inline cairo_bool_t
_cairo_gl_device_has_glsl(cairo_device_t * device)464 _cairo_gl_device_has_glsl (cairo_device_t *device)
465 {
466     return ((cairo_gl_context_t *) device)->has_shader_support;
467 }
468 
469 static cairo_always_inline cairo_bool_t
_cairo_gl_device_requires_power_of_two_textures(cairo_device_t * device)470 _cairo_gl_device_requires_power_of_two_textures (cairo_device_t *device)
471 {
472     return ((cairo_gl_context_t *) device)->tex_target == GL_TEXTURE_RECTANGLE;
473 }
474 
475 static cairo_always_inline cairo_status_t cairo_warn
_cairo_gl_context_acquire(cairo_device_t * device,cairo_gl_context_t ** ctx)476 _cairo_gl_context_acquire (cairo_device_t *device,
477 			   cairo_gl_context_t **ctx)
478 {
479     cairo_status_t status;
480 
481     status = cairo_device_acquire (device);
482     if (unlikely (status))
483 	return status;
484 
485     /* clear potential previous GL errors */
486     _cairo_gl_get_error ();
487 
488     *ctx = (cairo_gl_context_t *) device;
489     return CAIRO_STATUS_SUCCESS;
490 }
491 
492 static cairo_always_inline cairo_warn cairo_status_t
_cairo_gl_context_release(cairo_gl_context_t * ctx,cairo_status_t status)493 _cairo_gl_context_release (cairo_gl_context_t *ctx, cairo_status_t status)
494 {
495     GLenum err;
496 
497     err = _cairo_gl_get_error ();
498 
499     if (unlikely (err)) {
500         cairo_status_t new_status;
501 	new_status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
502         if (status == CAIRO_STATUS_SUCCESS)
503             status = new_status;
504     }
505 
506     cairo_device_release (&(ctx)->base);
507 
508     return status;
509 }
510 
511 cairo_private void
512 _cairo_gl_context_set_destination (cairo_gl_context_t *ctx,
513 				   cairo_gl_surface_t *surface,
514 				   cairo_bool_t multisampling);
515 
516 cairo_private void
517 _cairo_gl_context_bind_framebuffer (cairo_gl_context_t *ctx,
518 				    cairo_gl_surface_t *surface,
519 				    cairo_bool_t multisampling);
520 
521 cairo_private cairo_gl_emit_rect_t
522 _cairo_gl_context_choose_emit_rect (cairo_gl_context_t *ctx);
523 
524 cairo_private void
525 _cairo_gl_context_emit_rect (cairo_gl_context_t *ctx,
526 			     GLfloat x1, GLfloat y1,
527 			     GLfloat x2, GLfloat y2);
528 
529 cairo_private cairo_gl_emit_span_t
530 _cairo_gl_context_choose_emit_span (cairo_gl_context_t *ctx);
531 
532 cairo_private cairo_gl_emit_glyph_t
533 _cairo_gl_context_choose_emit_glyph (cairo_gl_context_t *ctx);
534 
535 cairo_private void
536 _cairo_gl_context_activate (cairo_gl_context_t *ctx,
537                             cairo_gl_tex_t      tex_unit);
538 
539 cairo_private cairo_bool_t
540 _cairo_gl_operator_is_supported (cairo_operator_t op);
541 
542 cairo_private cairo_bool_t
543 _cairo_gl_ensure_stencil (cairo_gl_context_t *ctx,
544 			  cairo_gl_surface_t *surface);
545 
546 cairo_private cairo_status_t
547 _cairo_gl_composite_init (cairo_gl_composite_t *setup,
548                           cairo_operator_t op,
549                           cairo_gl_surface_t *dst,
550                           cairo_bool_t has_component_alpha);
551 
552 cairo_private void
553 _cairo_gl_composite_fini (cairo_gl_composite_t *setup);
554 
555 cairo_private cairo_status_t
556 _cairo_gl_composite_set_operator (cairo_gl_composite_t *setup,
557 				  cairo_operator_t op,
558 				  cairo_bool_t assume_component_alpha);
559 
560 cairo_private void
561 _cairo_gl_composite_set_clip_region (cairo_gl_composite_t *setup,
562                                      cairo_region_t *clip_region);
563 
564 cairo_private void
565 _cairo_gl_composite_set_clip(cairo_gl_composite_t *setup,
566 			     cairo_clip_t *clip);
567 
568 cairo_private cairo_int_status_t
569 _cairo_gl_composite_set_source (cairo_gl_composite_t *setup,
570 				const cairo_pattern_t *pattern,
571 				const cairo_rectangle_int_t *sample,
572 				const cairo_rectangle_int_t *extents,
573 				cairo_bool_t use_texgen);
574 
575 cairo_private void
576 _cairo_gl_composite_set_solid_source (cairo_gl_composite_t *setup,
577 				      const cairo_color_t *color);
578 
579 cairo_private void
580 _cairo_gl_composite_set_source_operand (cairo_gl_composite_t *setup,
581 					const cairo_gl_operand_t *source);
582 
583 cairo_private cairo_int_status_t
584 _cairo_gl_composite_set_mask (cairo_gl_composite_t *setup,
585 			      const cairo_pattern_t *pattern,
586 			      const cairo_rectangle_int_t *sample,
587 			      const cairo_rectangle_int_t *extents,
588 			      cairo_bool_t use_texgen);
589 
590 cairo_private void
591 _cairo_gl_composite_set_mask_operand (cairo_gl_composite_t *setup,
592 				      const cairo_gl_operand_t *mask);
593 
594 cairo_private void
595 _cairo_gl_composite_set_spans (cairo_gl_composite_t *setup);
596 
597 cairo_private void
598 _cairo_gl_composite_set_multisample (cairo_gl_composite_t *setup);
599 
600 cairo_private cairo_status_t
601 _cairo_gl_composite_begin (cairo_gl_composite_t *setup,
602                            cairo_gl_context_t **ctx);
603 
604 cairo_private cairo_status_t
605 _cairo_gl_set_operands_and_operator (cairo_gl_composite_t *setup,
606 				     cairo_gl_context_t *ctx);
607 
608 cairo_private void
609 _cairo_gl_composite_flush (cairo_gl_context_t *ctx);
610 
611 cairo_private cairo_int_status_t
612 _cairo_gl_composite_emit_quad_as_tristrip (cairo_gl_context_t	*ctx,
613 					   cairo_gl_composite_t	*setup,
614 					   const cairo_point_t	 quad[4]);
615 
616 cairo_private cairo_int_status_t
617 _cairo_gl_composite_emit_triangle_as_tristrip (cairo_gl_context_t	*ctx,
618 					       cairo_gl_composite_t	*setup,
619 					       const cairo_point_t	 triangle[3]);
620 
621 cairo_private void
622 _cairo_gl_context_destroy_operand (cairo_gl_context_t *ctx,
623                                    cairo_gl_tex_t tex_unit);
624 
625 cairo_private cairo_bool_t
626 _cairo_gl_get_image_format_and_type (cairo_gl_flavor_t flavor,
627 				     pixman_format_code_t pixman_format,
628 				     GLenum *internal_format, GLenum *format,
629 				     GLenum *type, cairo_bool_t *has_alpha,
630 				     cairo_bool_t *needs_swap);
631 
632 cairo_private void
633 _cairo_gl_glyph_cache_init (cairo_gl_glyph_cache_t *cache);
634 
635 cairo_private void
636 _cairo_gl_glyph_cache_fini (cairo_gl_context_t *ctx,
637 			    cairo_gl_glyph_cache_t *cache);
638 
639 cairo_private cairo_int_status_t
640 _cairo_gl_surface_show_glyphs (void			*abstract_dst,
641 			       cairo_operator_t		 op,
642 			       const cairo_pattern_t	*source,
643 			       cairo_glyph_t		*glyphs,
644 			       int			 num_glyphs,
645 			       cairo_scaled_font_t	*scaled_font,
646 			       const cairo_clip_t	*clip,
647 			       int			*remaining_glyphs);
648 
649 cairo_private cairo_status_t
650 _cairo_gl_context_init_shaders (cairo_gl_context_t *ctx);
651 
652 cairo_private void
653 _cairo_gl_context_fini_shaders (cairo_gl_context_t *ctx);
654 
655 static cairo_always_inline cairo_bool_t
_cairo_gl_context_is_flushed(cairo_gl_context_t * ctx)656 _cairo_gl_context_is_flushed (cairo_gl_context_t *ctx)
657 {
658     return ctx->vb_offset == 0;
659 }
660 
661 cairo_private cairo_status_t
662 _cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx,
663                               cairo_gl_operand_t *source,
664                               cairo_gl_operand_t *mask,
665 			      cairo_bool_t use_coverage,
666                               cairo_gl_shader_in_t in,
667                               cairo_gl_shader_t **shader);
668 
669 cairo_private void
670 _cairo_gl_shader_bind_float (cairo_gl_context_t *ctx,
671 			     GLint location,
672 			     float value);
673 
674 cairo_private void
675 _cairo_gl_shader_bind_vec2 (cairo_gl_context_t *ctx,
676 			    GLint location,
677 			    float value0, float value1);
678 
679 cairo_private void
680 _cairo_gl_shader_bind_vec3 (cairo_gl_context_t *ctx,
681 			    GLint location,
682 			    float value0,
683 			    float value1,
684 			    float value2);
685 
686 cairo_private void
687 _cairo_gl_shader_bind_vec4 (cairo_gl_context_t *ctx,
688 			    GLint location,
689 			    float value0, float value1,
690 			    float value2, float value3);
691 
692 cairo_private void
693 _cairo_gl_shader_bind_matrix (cairo_gl_context_t *ctx,
694 			      GLint location,
695 			      const cairo_matrix_t* m);
696 
697 cairo_private void
698 _cairo_gl_shader_bind_matrix4f (cairo_gl_context_t *ctx,
699 				GLint location,
700 				GLfloat* gl_m);
701 
702 cairo_private void
703 _cairo_gl_set_shader (cairo_gl_context_t *ctx,
704 		      cairo_gl_shader_t *shader);
705 
706 cairo_private void
707 _cairo_gl_shader_fini (cairo_gl_context_t *ctx, cairo_gl_shader_t *shader);
708 
709 cairo_private int
710 _cairo_gl_get_version (void);
711 
712 cairo_private cairo_gl_flavor_t
713 _cairo_gl_get_flavor (void);
714 
715 cairo_private unsigned long
716 _cairo_gl_get_vbo_size (void);
717 
718 cairo_private cairo_bool_t
719 _cairo_gl_has_extension (const char *ext);
720 
721 cairo_private cairo_status_t
722 _cairo_gl_dispatch_init(cairo_gl_dispatch_t *dispatch,
723 			cairo_gl_get_proc_addr_func_t get_proc_addr);
724 
725 cairo_private cairo_int_status_t
726 _cairo_gl_operand_init (cairo_gl_operand_t *operand,
727 		        const cairo_pattern_t *pattern,
728 		        cairo_gl_surface_t *dst,
729 			const cairo_rectangle_int_t *sample,
730 			const cairo_rectangle_int_t *extents,
731 			cairo_bool_t use_texgen);
732 
733 cairo_private void
734 _cairo_gl_solid_operand_init (cairo_gl_operand_t *operand,
735 	                      const cairo_color_t *color);
736 
737 cairo_private cairo_filter_t
738 _cairo_gl_operand_get_filter (cairo_gl_operand_t *operand);
739 
740 cairo_private GLint
741 _cairo_gl_operand_get_gl_filter (cairo_gl_operand_t *operand);
742 
743 cairo_private cairo_extend_t
744 _cairo_gl_operand_get_extend (cairo_gl_operand_t *operand);
745 
746 cairo_private unsigned int
747 _cairo_gl_operand_get_vertex_size (const cairo_gl_operand_t *operand);
748 
749 cairo_private cairo_bool_t
750 _cairo_gl_operand_needs_setup (cairo_gl_operand_t *dest,
751                                cairo_gl_operand_t *source,
752                                unsigned int        vertex_offset);
753 
754 cairo_private void
755 _cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx,
756                                   cairo_gl_operand_t *operand,
757                                   cairo_gl_tex_t      tex_unit);
758 
759 cairo_private void
760 _cairo_gl_operand_emit (cairo_gl_operand_t *operand,
761                         GLfloat ** vb,
762                         GLfloat x,
763                         GLfloat y);
764 
765 cairo_private void
766 _cairo_gl_operand_copy (cairo_gl_operand_t *dst,
767 			const cairo_gl_operand_t *src);
768 
769 cairo_private void
770 _cairo_gl_operand_translate (cairo_gl_operand_t *operand,
771 			     double tx, double ty);
772 
773 cairo_private void
774 _cairo_gl_operand_destroy (cairo_gl_operand_t *operand);
775 
776 cairo_private const cairo_compositor_t *
777 _cairo_gl_msaa_compositor_get (void);
778 
779 cairo_private const cairo_compositor_t *
780 _cairo_gl_span_compositor_get (void);
781 
782 cairo_private const cairo_compositor_t *
783 _cairo_gl_traps_compositor_get (void);
784 
785 cairo_private cairo_int_status_t
786 _cairo_gl_check_composite_glyphs (const cairo_composite_rectangles_t *extents,
787 				  cairo_scaled_font_t *scaled_font,
788 				  cairo_glyph_t *glyphs,
789 				  int *num_glyphs);
790 
791 cairo_private cairo_int_status_t
792 _cairo_gl_composite_glyphs (void			*_dst,
793 			    cairo_operator_t		 op,
794 			    cairo_surface_t		*_src,
795 			    int				 src_x,
796 			    int				 src_y,
797 			    int				 dst_x,
798 			    int				 dst_y,
799 			    cairo_composite_glyphs_info_t *info);
800 
801 cairo_private cairo_int_status_t
802 _cairo_gl_composite_glyphs_with_clip (void			    *_dst,
803 				      cairo_operator_t		     op,
804 				      cairo_surface_t		    *_src,
805 				      int			     src_x,
806 				      int			     src_y,
807 				      int			     dst_x,
808 				      int			     dst_y,
809 				      cairo_composite_glyphs_info_t *info,
810 				      cairo_clip_t		    *clip);
811 
812 cairo_private void
813 _cairo_gl_ensure_framebuffer (cairo_gl_context_t *ctx,
814                               cairo_gl_surface_t *surface);
815 
816 cairo_private cairo_surface_t *
817 _cairo_gl_surface_create_scratch (cairo_gl_context_t   *ctx,
818 				  cairo_content_t	content,
819 				  int			width,
820 				  int			height);
821 
822 cairo_private cairo_surface_t *
823 _cairo_gl_surface_create_scratch_for_caching (cairo_gl_context_t *ctx,
824 					      cairo_content_t content,
825 					      int width,
826 					      int height);
827 
828 cairo_private cairo_surface_t *
829 _cairo_gl_pattern_to_source (cairo_surface_t *dst,
830 			     const cairo_pattern_t *pattern,
831 			     cairo_bool_t is_mask,
832 			     const cairo_rectangle_int_t *extents,
833 			     const cairo_rectangle_int_t *sample,
834 			     int *src_x, int *src_y);
835 
836 cairo_private cairo_int_status_t
837 _cairo_gl_msaa_compositor_draw_clip (cairo_gl_context_t *ctx,
838 				     cairo_gl_composite_t *setup,
839 				     cairo_clip_t *clip);
840 
841 cairo_private cairo_surface_t *
842 _cairo_gl_white_source (void);
843 
844 cairo_private void
845 _cairo_gl_scissor_to_rectangle (cairo_gl_surface_t *surface,
846 				const cairo_rectangle_int_t *r);
847 
848 static inline cairo_gl_operand_t *
source_to_operand(cairo_surface_t * surface)849 source_to_operand (cairo_surface_t *surface)
850 {
851     cairo_gl_source_t *source = (cairo_gl_source_t *)surface;
852     return source ? &source->operand : NULL;
853 }
854 
855 static inline void
_cairo_gl_glyph_cache_unlock(cairo_gl_glyph_cache_t * cache)856 _cairo_gl_glyph_cache_unlock (cairo_gl_glyph_cache_t *cache)
857 {
858     _cairo_rtree_unpin (&cache->rtree);
859 }
860 
861 
862 slim_hidden_proto (cairo_gl_surface_create);
863 slim_hidden_proto (cairo_gl_surface_create_for_texture);
864 
865 #endif /* CAIRO_GL_PRIVATE_H */
866