Fix bug in _cairo_gl_has_extension
[platform/core/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  * Copyright © 2011,2015 Samsung Research America, Inc - Silicon Valley
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it either under the terms of the GNU Lesser General Public
11  * License version 2.1 as published by the Free Software Foundation
12  * (the "LGPL") or, at your option, under the terms of the Mozilla
13  * Public License Version 1.1 (the "MPL"). If you do not alter this
14  * notice, a recipient may use your version of this file under either
15  * the MPL or the LGPL.
16  *
17  * You should have received a copy of the LGPL along with this library
18  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
20  * You should have received a copy of the MPL along with this library
21  * in the file COPYING-MPL-1.1
22  *
23  * The contents of this file are subject to the Mozilla Public License
24  * Version 1.1 (the "License"); you may not use this file except in
25  * compliance with the License. You may obtain a copy of the License at
26  * http://www.mozilla.org/MPL/
27  *
28  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
29  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
30  * the specific language governing rights and limitations.
31  *
32  * The Original Code is the cairo graphics library.
33  *
34  * The Initial Developer of the Original Code is Red Hat, Inc.
35  *
36  * Contributor(s):
37  *      Benjamin Otte <otte@gnome.org>
38  *      Carl Worth <cworth@cworth.org>
39  *      Chris Wilson <chris@chris-wilson.co.uk>
40  *      Eric Anholt <eric@anholt.net>
41  *      T. Zachary Laine <whatwasthataddress@gmail.com>
42  *      Alexandros Frantzis <alexandros.frantzis@linaro.org>
43  *      Henry Song <hsong@sisa.samsung.com>
44  */
45
46 #ifndef CAIRO_GL_PRIVATE_H
47 #define CAIRO_GL_PRIVATE_H
48
49 #define GL_GLEXT_PROTOTYPES
50
51 #include "cairoint.h"
52
53 #include "cairo-gl.h"
54 #include "cairo-gl-gradient-private.h"
55
56 #include "cairo-device-private.h"
57 #include "cairo-error-private.h"
58 #include "cairo-rtree-private.h"
59 #include "cairo-scaled-font-private.h"
60 #include "cairo-spans-compositor-private.h"
61 #include "cairo-array-private.h"
62 #include "cairo-stroke-dash-private.h"
63
64 #include <assert.h>
65
66 #if CAIRO_HAS_EVASGL_SURFACE
67   #include <Evas_GL.h>
68 #else
69   #if CAIRO_HAS_GL_SURFACE
70   #if CAIRO_HAS_CGL_FUNCTIONS
71   #include <OpenGL/gl.h>
72   #include <OpenGL/glext.h>
73   #else
74   #include <GL/gl.h>
75   #include <GL/glext.h>
76   #endif
77   #elif CAIRO_HAS_GLESV2_SURFACE
78   #include <GLES2/gl2.h>
79   #include <GLES2/gl2ext.h>
80   #elif CAIRO_HAS_GLESV3_SURFACE
81   #include <GLES3/gl3.h>
82   #include <GLES3/gl3ext.h>
83   #endif
84 #endif
85
86 #include "cairo-gl-ext-def-private.h"
87
88 #define DEBUG_GL 0
89
90 #define CAIRO_GL_ENUM_UNINITIALIZED 0xFFFF
91
92 #if DEBUG_GL && __GNUC__
93 #define UNSUPPORTED(reason) ({ \
94     fprintf (stderr, \
95              "cairo-gl: hit unsupported operation in %s(), line %d: %s\n", \
96              __FUNCTION__, __LINE__, reason); \
97     CAIRO_INT_STATUS_UNSUPPORTED; \
98 })
99 #else
100 #define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED
101 #endif
102
103 #define CAIRO_GL_VERSION_ENCODE(major, minor) ( \
104           ((major) * 256)                       \
105         + ((minor) *   1))
106
107 /* maximal number of shaders we keep in the cache.
108  * Random number that is hopefully big enough to not cause many cache evictions. */
109 #define CAIRO_GL_MAX_SHADERS_PER_CONTEXT 64
110
111 /* VBO size that we allocate, smaller size means we gotta flush more often,
112  * but larger means hogging more memory and can cause trouble for drivers
113  * (especially on embedded devices). Use the CAIRO_GL_VBO_SIZE environment
114  * variable to set this to a different size. */
115 #define CAIRO_GL_VBO_SIZE_DEFAULT (256*1024)
116
117 #define MIN_IMAGE_CACHE_WIDTH 512
118 #define MIN_IMAGE_CACHE_HEIGHT 512
119 #define MAX_IMAGE_CACHE_WIDTH 2048
120 #define MAX_IMAGE_CACHE_HEIGHT 2048
121 #define IMAGE_CACHE_MIN_SIZE 1
122 #define IMAGE_CACHE_MAX_SIZE 256
123 #define MIN_SCRATCH_SIZE 32
124 #define MAX_SCRATCH_SIZE 1024
125
126 typedef struct _cairo_gl_surface cairo_gl_surface_t;
127 typedef struct _cairo_gl_image   cairo_gl_image_t;
128
129 /* Mali or SGX driver */
130 typedef enum _cairo_gl_multisample_ext_type {
131     CAIRO_GL_EXT_MULTISAMPLE_TO_TEXTURE,
132     CAIRO_GL_IMG_MULTISAMPLE_TO_TEXTURE,
133     CAIRO_GL_NONE_MULTISAMPLE_TO_TEXTURE
134 } cairo_gl_multisample_ext_type;
135
136 /* GL blur stages */
137 typedef enum _cairo_blur_stage {
138     CAIRO_GL_BLUR_STAGE_NONE,
139     CAIRO_GL_BLUR_STAGE_0,      /* shrink stage  */
140     CAIRO_GL_BLUR_STAGE_1,      /* x/y pass      */
141     CAIRO_GL_BLUR_STAGE_2       /* enlarge stage */
142 } cairo_blur_stage_t;
143
144 /* GL flavor */
145 typedef enum cairo_gl_flavor {
146     CAIRO_GL_FLAVOR_NONE = 0,
147     CAIRO_GL_FLAVOR_DESKTOP = 1,
148     CAIRO_GL_FLAVOR_ES2 = 2,
149     CAIRO_GL_FLAVOR_ES3 = 3
150 } cairo_gl_flavor_t;
151
152 /* The order here is sensitive because of the logic of 
153  *_cairo_gl_shader_uniform_for_texunit. */
154 typedef enum cairo_gl_uniform_t {
155     CAIRO_GL_UNIFORM_TEXDIMS,    /* "source_texdims" */
156     CAIRO_GL_UNIFORM_TEXGEN,     /* "source_texgen" */
157     CAIRO_GL_UNIFORM_CONSTANT,   /* "source_constant" */
158     CAIRO_GL_UNIFORM_SAMPLER,    /* "source_sampler" */
159     CAIRO_GL_UNIFORM_A,          /* "source_a" */
160     CAIRO_GL_UNIFORM_CIRCLE_D,   /* "source_circle_d" */
161     CAIRO_GL_UNIFORM_RADIUS_0,   /* "source_radius_0" */
162     CAIRO_GL_UNIFORM_BLUR_RADIUS,/* "source_blur_radius" */
163     CAIRO_GL_UNIFORM_BLURS,      /* "source_blurs" */
164     CAIRO_GL_UNIFORM_BLUR_STEP,  /* "source_blurstep" */
165     CAIRO_GL_UNIFORM_BLUR_X_AXIS, /* "source_blur_x_axis" */
166     CAIRO_GL_UNIFORM_BLUR_Y_AXIS, /* "source_blur_y_axis" */
167     CAIRO_GL_UNIFORM_ALPHA,       /* "source_alpha */
168     CAIRO_GL_UNIFORM_COLOR_1,     /* "source_color_1 */
169     CAIRO_GL_UNIFORM_COLOR_2,     /* "source_color_2 */
170     CAIRO_GL_UNIFORM_OFFSET_1,    /* "source_offset_1 */
171     CAIRO_GL_UNIFORM_OFFSET_2,    /* "source_offset_2 */
172
173     CAIRO_GL_UNIFORM_MASK_TEXDIMS,      /* "mask_texdims" */
174     CAIRO_GL_UNIFORM_MASK_TEXGEN,       /* "mask_texgen" */
175     CAIRO_GL_UNIFORM_MASK_CONSTANT,     /* "mask_constant" */
176     CAIRO_GL_UNIFORM_MASK_SAMPLER,      /* "mask_sampler" */
177     CAIRO_GL_UNIFORM_MASK_A,            /* "mask_a" */
178     CAIRO_GL_UNIFORM_MASK_CIRCLE_D,     /* "mask_circle_d" */
179     CAIRO_GL_UNIFORM_MASK_RADIUS_0,     /* "mask_radius_0" */
180     CAIRO_GL_UNIFORM_MASK_BLUR_RADIUS,  /* "mask_blur_radius */
181     CAIRO_GL_UNIFORM_MASK_BLURS,        /* "mask_blurs */
182     CAIRO_GL_UNIFORM_MASK_BLUR_STEP,    /* "mask_blur_step" */
183     CAIRO_GL_UNIFORM_MASK_BLUR_X_AXIS,   /* "mask_blur_x_axis" */
184     CAIRO_GL_UNIFORM_MASK_BLUR_Y_AXIS,   /* "mask_blur_y_axis" */
185     CAIRO_GL_UNIFORM_MASK_ALPHA,         /* "mask_alpha" */
186     CAIRO_GL_UNIFORM_MASK_COLOR_1,        /* "mask_color_1" */
187     CAIRO_GL_UNIFORM_MASK_COLOR_2,        /* "mask_color_2" */
188     CAIRO_GL_UNIFORM_MASK_OFFSET_1,       /* "mask_offset_1 */
189     CAIRO_GL_UNIFORM_MASK_OFFSET_2,       /* "mask_offset_2 */
190
191     CAIRO_GL_UNIFORM_PROJECTION_MATRIX, /* "ModelViewProjectionMatrix" */
192
193
194     CAIRO_GL_UNIFORM_MAX
195 } cairo_gl_uniform_t;
196
197 /* Indices for vertex attributes used by BindAttribLocation etc */
198 enum {
199     CAIRO_GL_VERTEX_ATTRIB_INDEX = 0,
200     CAIRO_GL_COLOR_ATTRIB_INDEX  = 1,
201     CAIRO_GL_COVERAGE_ATTRIB_INDEX  = 2,
202     CAIRO_GL_TEXCOORD0_ATTRIB_INDEX = 3,
203     CAIRO_GL_TEXCOORD1_ATTRIB_INDEX = 4,
204     CAIRO_GL_START_COORD0_ATTRIB_INDEX = 5,
205     CAIRO_GL_START_COORD1_ATTRIB_INDEX = 6,
206     CAIRO_GL_STOP_COORD0_ATTRIB_INDEX = 7,
207     CAIRO_GL_STOP_COORD1_ATTRIB_INDEX = 8
208 };
209
210 typedef enum cairo_gl_operand_type {
211     CAIRO_GL_OPERAND_NONE,
212     CAIRO_GL_OPERAND_CONSTANT,
213     CAIRO_GL_OPERAND_TEXTURE,
214     CAIRO_GL_OPERAND_LINEAR_GRADIENT,
215     CAIRO_GL_OPERAND_RADIAL_GRADIENT_A0,
216     CAIRO_GL_OPERAND_RADIAL_GRADIENT_NONE,
217     CAIRO_GL_OPERAND_RADIAL_GRADIENT_EXT,
218     CAIRO_GL_OPERAND_GAUSSIAN,
219
220     CAIRO_GL_OPERAND_COUNT
221 } cairo_gl_operand_type_t;
222
223 typedef enum cairo_gl_draw_mode {
224     CAIRO_GL_VERTEX,
225     CAIRO_GL_LINE_STRIP,
226     CAIRO_GL_LINES
227 } cairo_gl_draw_mode_t;
228
229 /* This union structure describes a potential source or mask operand to the
230  * compositing equation.
231  */
232 typedef struct cairo_gl_operand {
233     cairo_gl_operand_type_t type;
234     int pass; /* 0 none, 1, x-axis, 2, y-axis */
235     union {
236         struct {
237             GLuint tex;
238             cairo_gl_surface_t *surface;
239             cairo_gl_surface_t *owns_surface;
240             cairo_surface_attributes_t attributes;
241             int texgen;
242             cairo_bool_t use_atlas;
243             cairo_extend_t extend;
244             struct { float x, y; } p1, p2;
245             float coef[17];        /* max 1x/x1 kernel size */
246             int x_radius;
247             int y_radius;
248         } texture;
249         struct {
250             GLfloat color[4];
251             cairo_bool_t encode_as_attribute;
252         } constant;
253         struct {
254             cairo_gl_gradient_t *gradient;
255             cairo_matrix_t m;
256             cairo_circle_double_t circle_d;
257             double radius_0, a;
258             cairo_extend_t extend;
259             int texgen;
260         } gradient;
261     };
262     unsigned int vertex_offset;
263 } cairo_gl_operand_t;
264
265 typedef struct cairo_gl_source {
266     cairo_surface_t base;
267     cairo_gl_operand_t operand;
268 } cairo_gl_source_t;
269
270 struct _cairo_gl_surface {
271     cairo_surface_t base;
272     cairo_gl_operand_t operand;
273
274     int width, height;
275
276     GLuint tex; /* GL texture object containing our data. */
277     GLuint fb; /* GL framebuffer object wrapping our data. */
278     GLuint depth_stencil; /* GL renderbuffer object for holding stencil buffer clip. */
279
280     GLuint msaa_rb; /* The ARB MSAA path uses a renderbuffer. */
281     GLuint msaa_fb;
282     GLuint msaa_depth_stencil;
283
284     cairo_bool_t stencil_and_msaa_caps_initialized;
285     cairo_bool_t supports_stencil; /* Stencil support for for non-texture surfaces. */
286     cairo_bool_t supports_msaa;
287     cairo_bool_t num_samples;
288     cairo_bool_t force_no_msaa;
289     cairo_bool_t msaa_active; /* Whether the multisampling
290                                  framebuffer is active or not. */
291     cairo_bool_t content_synced; /* texture and renderbuffer content
292                                     synced */
293     cairo_bool_t content_cleared; /* last draw is glClear */
294     cairo_clip_t *clip_on_stencil_buffer;
295
296     int owns_tex;
297     cairo_bool_t needs_update;
298     cairo_bool_t size_changed;
299
300     cairo_region_t *clip_region;
301     GLuint bounded_tex;         /* bounded tex for non-texture surface */
302
303     /* Indicate whether we need to cache it in image_cache. */
304     cairo_bool_t needs_to_cache;
305     cairo_bool_t force_no_cache;
306     double image_content_scale_x;
307     double image_content_scale_y;
308     cairo_blur_stage_t blur_stage;
309     /* Damage is too expensive to check, we use this flag. */
310     cairo_bool_t content_changed;
311     cairo_gl_image_t *image_node;
312 };
313
314 typedef struct cairo_gl_glyph_cache {
315     cairo_rtree_t rtree;
316     cairo_gl_surface_t *surface;
317 } cairo_gl_glyph_cache_t;
318
319 typedef enum cairo_gl_tex {
320     CAIRO_GL_TEX_SOURCE = 0,
321     CAIRO_GL_TEX_MASK = 1,
322     CAIRO_GL_TEX_TEMP = 2
323 } cairo_gl_tex_t;
324
325 typedef struct cairo_gl_shader {
326     GLuint fragment_shader;
327     GLuint program;
328     GLint mvp_location;
329     GLint constant_location[2];
330     GLint a_location[2];
331     GLint circle_d_location[2];
332     GLint radius_0_location[2];
333     GLint texdims_location[2];
334     GLint texgen_location[2];
335     GLint blur_radius_location[2];
336     GLint blurs_location[2];
337     GLint blur_step_location[2];
338     GLint blur_x_axis_location[2];
339     GLint blur_y_axis_location[2];
340     GLint alpha_location[2];
341     GLint color_1_location[2];
342     GLint color_2_location[2];
343     GLint offset_1_location[2];
344     GLint offset_2_location[2];
345 } cairo_gl_shader_t;
346
347 typedef struct _cairo_gl_image_cache {
348     cairo_rtree_t rtree;
349     cairo_gl_surface_t *surface;
350     cairo_bool_t copy_success;
351 } cairo_gl_image_cache_t;
352
353 struct _cairo_gl_image {
354     cairo_rtree_node_t node;
355     cairo_surface_t *original_surface;
356     struct { float x, y; } p1, p2;
357     cairo_gl_context_t *ctx;
358 };
359
360 typedef enum cairo_gl_shader_in {
361     CAIRO_GL_SHADER_IN_NORMAL,
362     CAIRO_GL_SHADER_IN_CA_SOURCE,
363     CAIRO_GL_SHADER_IN_CA_SOURCE_ALPHA,
364
365     CAIRO_GL_SHADER_IN_COUNT
366 } cairo_gl_shader_in_t;
367
368
369 typedef struct _cairo_gl_hairline_closure
370 {
371     cairo_gl_context_t *ctx;
372     double tolerance;
373     cairo_stroker_dash_t dash;
374     cairo_matrix_t *ctm;
375     cairo_matrix_t *ctm_inverse;
376     cairo_point_t current_point;
377
378     cairo_point_t stroke_first_point;  /* First stroke point at move_to. */
379     double stroke_first_dx;
380     double stroke_first_dy;
381     cairo_bool_t stroke_first_capped;
382     cairo_bool_t moved_to_stroke_first_point;
383
384     cairo_line_cap_t cap_style;
385
386     cairo_bool_t line_last_capped;
387
388     cairo_point_t line_last_point;
389     double line_last_dx;
390     double line_last_dy;
391
392     cairo_bool_t initialized;
393 } cairo_gl_hairline_closure_t;
394
395 typedef enum cairo_gl_var_type {
396   CAIRO_GL_VAR_NONE,
397   CAIRO_GL_VAR_TEXCOORDS,
398   CAIRO_GL_VAR_TEXGEN,
399   CAIRO_GL_VAR_COLOR,
400 } cairo_gl_var_type_t;
401
402 typedef enum cairo_gl_primitive_type {
403     CAIRO_GL_PRIMITIVE_TYPE_TRIANGLES,
404     CAIRO_GL_PRIMITIVE_TYPE_TRISTRIPS
405 } cairo_gl_primitive_type_t;
406
407 typedef void (*cairo_gl_emit_rect_t) (cairo_gl_context_t *ctx,
408                                       GLfloat x1, GLfloat y1,
409                                       GLfloat x2, GLfloat y2);
410
411 typedef void (*cairo_gl_emit_span_t) (cairo_gl_context_t *ctx,
412                                       GLfloat x1, GLfloat y1,
413                                       GLfloat x2, GLfloat y2,
414                                       uint8_t alpha);
415
416 typedef void (*cairo_gl_emit_glyph_t) (cairo_gl_context_t *ctx,
417                                        GLfloat x1, GLfloat y1,
418                                        GLfloat x2, GLfloat y2,
419                                        GLfloat glyph_x1, GLfloat glyph_y1,
420                                        GLfloat glyph_x2, GLfloat glyph_y2);
421
422 #define cairo_gl_var_type_hash(src,mask,src_atlas_extend,mask_atlas_extend,src_use_atlas,mask_use_atlas,spans,dest) ((spans) << 13) | ((mask) << 10 | (src << 7) | (mask_atlas_extend << 5) | (src_atlas_extend << 3) | (mask_use_atlas << 2) | (src_use_atlas << 1) | (dest))
423 #define CAIRO_GL_VAR_TYPE_MAX (1 << 14)
424
425 typedef void (*cairo_gl_generic_func_t)(void);
426 typedef cairo_gl_generic_func_t (*cairo_gl_get_proc_addr_func_t)(void *data, const char *procname);
427
428 typedef struct _cairo_gl_dispatch {
429     /* common */
430     void (*ActiveTexture) (GLenum texture);
431     void (*BindTexture) (GLenum target, GLuint texture);
432     void (*BlendFunc) (GLenum sfactor, GLenum dfactor);
433     void (*BlendFuncSeparate) (GLenum srcRGB, GLenum dstRGB,
434                                GLenum srcAlpha, GLenum dstAlpha);
435     void (*Clear) (GLbitfield mask);
436     void (*ClearColor) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
437     void (*ClearStencil) (GLint s);
438     void (*ColorMask) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
439     void (*DeleteTextures) (GLsizei n, const GLuint *textures);
440     void (*DepthMask) (GLboolean flag);
441     void (*Disable) (GLenum cap);
442     void (*DrawArrays) (GLenum mode, GLint first, GLsizei count);
443     void (*DrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
444     void (*Enable) (GLenum cap);
445     void (*Flush) (void);
446     void (*GenTextures) (GLsizei n, GLuint *textures);
447     void (*GetBooleanv) (GLenum pname, GLboolean *data);
448     GLenum (*GetError) (void);
449     void (*GetFloatv) (GLenum pname, GLfloat *data);
450     void (*GetIntegerv) (GLenum pname, GLint *data);
451     const GLubyte *(*GetString) (GLenum pname);
452     const GLubyte *(*GetStringi) (GLenum pname, GLuint i);
453     void (*PixelStorei) (GLenum pname, GLint param);
454     void (*ReadPixels) (GLint x, GLint y, GLsizei width, GLsizei height,
455                         GLenum format, GLenum type, GLvoid *data);
456     void (*Scissor) (GLint x, GLint y, GLsizei width, GLsizei height);
457     void (*StencilFunc) (GLenum func, GLint ref, GLuint mask);
458     void (*StencilMask) (GLuint mask);
459     void (*StencilOp) (GLenum sfail, GLenum dpfail, GLenum dppass);
460     void (*TexSubImage2D) (GLenum target, GLint level,
461                            GLint xoffset, GLint yoffset,
462                            GLsizei width, GLsizei height,
463                            GLenum format, GLenum type, const GLvoid *data);
464     void (*TexImage2D) (GLenum target, GLint level, GLenum internalformat,
465                         GLsizei width, GLsizei height,
466                         GLint border, GLenum format,
467                         GLenum type, const GLvoid *data);
468     void (*TexParameteri) (GLenum target, GLenum pname, GLint param);
469 #if defined(CAIRO_HAS_GL_SURFACE) || defined(CAIRO_HAS_EVASGL_SURFACE)
470     void (*DrawBuffer) (GLenum buf);
471     void (*ReadBuffer) (GLenum buf);
472 #endif
473     void (*Viewport) (GLint x, GLint y, GLsizei width, GLsizei height);
474
475     /* Buffers */
476     void (*GenBuffers) (GLsizei n, GLuint *buffers);
477     void (*DeleteBuffers) (GLsizei n, const GLuint *buffers);
478     void (*BindBuffer) (GLenum target, GLuint buffer);
479     void (*BufferData) (GLenum target, GLsizeiptr size,
480                           const GLvoid* data, GLenum usage);
481     void (*BufferSubData) (GLenum target, GLintptr offset,
482                            GLsizeiptr size, const GLvoid *data);
483     GLvoid *(*MapBuffer) (GLenum target, GLenum access);
484     GLboolean (*UnmapBuffer) (GLenum target);
485     void (*GenVertexArrays) (GLsizei n, GLuint *arrays);
486     void (*BindVertexArray) (GLuint array);
487     void (*DeleteVertexArrays) (GLsizei n, const GLuint *arrays);
488
489     /* Shaders */
490     GLuint (*CreateShader) (GLenum type);
491     void (*ShaderSource) (GLuint shader, GLsizei count,
492                             const GLchar** string, const GLint* length);
493     void (*CompileShader) (GLuint shader);
494     void (*GetShaderiv) (GLuint shader, GLenum pname, GLint *params);
495     void (*GetShaderInfoLog) (GLuint shader, GLsizei bufSize,
496                                 GLsizei *length, GLchar *infoLog);
497     void (*DeleteShader) (GLuint shader);
498
499     /* Programs */
500     GLuint (*CreateProgram) (void);
501     void (*AttachShader) (GLuint program, GLuint shader);
502     void (*DeleteProgram) (GLuint program);
503     void (*LinkProgram) (GLuint program);
504     void (*UseProgram) (GLuint program);
505     void (*GetProgramiv) (GLuint program, GLenum pname, GLint *params);
506     void (*GetProgramInfoLog) (GLuint program, GLsizei bufSize,
507                                  GLsizei *length, GLchar *infoLog);
508
509     /* Uniforms */
510     GLint (*GetUniformLocation) (GLuint program, const GLchar* name);
511     void (*Uniform1f) (GLint location, GLfloat x);
512     void (*Uniform2f) (GLint location, GLfloat x, GLfloat y);
513     void (*Uniform3f) (GLint location, GLfloat x, GLfloat y, GLfloat z);
514     void (*Uniform4f) (GLint location, GLfloat x, GLfloat y, GLfloat z,
515                          GLfloat w);
516     void (*Uniform1fv) (GLint location, GLsizei count, const GLfloat *v);
517
518     void (*UniformMatrix3fv) (GLint location, GLsizei count,
519                                 GLboolean transpose, const GLfloat *value);
520     void (*UniformMatrix4fv) (GLint location, GLsizei count,
521                               GLboolean transpose, const GLfloat *value);
522     void (*Uniform1i) (GLint location, GLint x);
523
524     /* Attributes */
525     void (*BindAttribLocation) (GLuint program, GLuint index,
526                                 const GLchar *name);
527     void (*VertexAttribPointer) (GLuint index, GLint size, GLenum type,
528                                  GLboolean normalized, GLsizei stride,
529                                  const GLvoid *pointer);
530     void (*EnableVertexAttribArray) (GLuint index);
531     void (*DisableVertexAttribArray) (GLuint index);
532
533     /* Framebuffer objects */
534     void (*GenFramebuffers) (GLsizei n, GLuint* framebuffers);
535     void (*BindFramebuffer) (GLenum target, GLuint framebuffer);
536     void (*FramebufferTexture2D) (GLenum target, GLenum attachment,
537                                     GLenum textarget, GLuint texture,
538                                     GLint level);
539     GLenum (*CheckFramebufferStatus) (GLenum target);
540     void (*DeleteFramebuffers) (GLsizei n, const GLuint* framebuffers);
541     void (*GenRenderbuffers) (GLsizei n, GLuint *renderbuffers);
542     void (*BindRenderbuffer) (GLenum target, GLuint renderbuffer);
543     void (*RenderbufferStorage) (GLenum target, GLenum internal_format,
544                                  GLsizei width, GLsizei height);
545     void (*FramebufferRenderbuffer) (GLenum target, GLenum attachment,
546                                      GLenum renderbuffer_ttarget, GLuint renderbuffer);
547     void (*DeleteRenderbuffers) (GLsizei n, GLuint *renderbuffers);
548     void (*BlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
549                              GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
550                              GLbitfield mask, GLenum filter);
551     void (*RenderbufferStorageMultisample) (GLenum target, GLsizei samples,
552                                             GLenum internalformat,
553                                             GLsizei width, GLsizei height);
554     void (*FramebufferTexture2DMultisample) (GLenum target, GLenum attachment,
555                                              GLenum textarget, GLuint texture,
556                                              GLint level, GLsizei samples);
557 } cairo_gl_dispatch_t;
558
559 typedef struct _cairo_gl_states {
560     cairo_rectangle_int_t viewport_box;
561
562     GLclampf clear_red;
563     GLclampf clear_green;
564     GLclampf clear_blue;
565     GLclampf clear_alpha;
566
567     cairo_bool_t blend_enabled;
568
569     GLenum src_color_factor;
570     GLenum dst_color_factor;
571     GLenum src_alpha_factor;
572     GLenum dst_alpha_factor;
573
574     GLenum active_texture;
575
576     cairo_bool_t depth_mask;
577
578     cairo_bool_t scissor_test_enabled;
579     cairo_bool_t stencil_test_enabled;
580
581     GLuint bound_vbo;
582     GLuint bound_vao;
583     GLuint bound_ibo;
584 } cairo_gl_states_t;
585
586 struct _cairo_gl_context {
587     cairo_device_t base;
588
589     const cairo_compositor_t *compositor;
590
591     GLint max_framebuffer_size;
592     GLint max_texture_size;
593     GLint max_textures;
594     GLenum tex_target;
595
596     GLint num_samples;
597     cairo_bool_t supports_msaa;
598     char *vb;
599     GLuint vbo;
600     GLuint vao;
601     GLuint ibo;
602
603     cairo_bool_t has_shader_support;
604
605     GLuint vertex_shaders[CAIRO_GL_VAR_TYPE_MAX];
606     cairo_gl_shader_t fill_rectangles_shader;
607     cairo_cache_t shaders;
608
609     cairo_cache_t gradients;
610
611     /* cache[0] for gray font, cache[1] for rgba component alpha
612      * cache[2] for color glyph */
613     cairo_gl_glyph_cache_t glyph_cache[3];
614     cairo_list_t fonts;
615
616     cairo_gl_surface_t *current_target;
617     cairo_operator_t current_operator;
618     cairo_gl_shader_t *pre_shader; /* for component alpha */
619     cairo_gl_shader_t *current_shader;
620
621     cairo_gl_operand_t operands[2];
622     cairo_bool_t spans;
623
624     unsigned int vbo_size;
625     unsigned int vb_offset;
626     unsigned int vertex_size;
627     cairo_region_t *clip_region;
628
629     cairo_gl_primitive_type_t primitive_type;
630     cairo_array_t tristrip_indices;
631
632     cairo_bool_t has_mesa_pack_invert;
633     cairo_gl_dispatch_t dispatch;
634     GLfloat modelviewprojection_matrix[16];
635     cairo_gl_flavor_t gl_flavor;
636     cairo_bool_t has_map_buffer;
637     cairo_bool_t has_packed_depth_stencil;
638     cairo_bool_t has_npot_repeat;
639     cairo_bool_t can_read_bgra;
640     cairo_bool_t is_gl33;
641
642     cairo_bool_t thread_aware;
643
644     cairo_gl_image_cache_t *image_cache;
645     cairo_gl_draw_mode_t draw_mode;
646     cairo_gl_states_t states_cache;
647
648     /* Intermediate mask surface for glyph rendering. Created on first access, enlarged on demand. */
649     cairo_gl_surface_t *glyph_mask;
650     /* Intermediate blur surface for gaussian blur. Created on first access, enlarged on demand. */
651     cairo_gl_surface_t *source_scratch_surfaces[2];
652     cairo_gl_surface_t *mask_scratch_surfaces[2];
653     cairo_gl_surface_t *shadow_scratch_surfaces[3];
654     cairo_gl_surface_t *shadow_masks[4];
655     cairo_bool_t source_scratch_in_use;
656     cairo_bool_t has_angle_multisampling;
657     cairo_gl_multisample_ext_type msaa_type;
658
659     void (*acquire) (void *ctx);
660     void (*release) (void *ctx);
661
662     void (*make_current) (void *ctx, cairo_gl_surface_t *surface);
663     void (*swap_buffers)(void *ctx, cairo_gl_surface_t *surface);
664     void (*destroy) (void *ctx);
665 };
666
667 typedef struct _cairo_gl_composite {
668     cairo_gl_surface_t *dst;
669     cairo_operator_t op;
670     cairo_region_t *clip_region;
671
672     cairo_gl_operand_t src;
673     cairo_gl_operand_t mask;
674     cairo_bool_t spans;
675
676     cairo_clip_t *clip;
677     cairo_bool_t multisample;
678 } cairo_gl_composite_t;
679
680 typedef struct _cairo_gl_font {
681     cairo_scaled_font_private_t         base;
682     cairo_device_t                      *device;
683     cairo_list_t                        link;
684 } cairo_gl_font_t;
685
686 static cairo_always_inline GLenum
687 _cairo_gl_get_error (cairo_gl_context_t *ctx)
688 {
689     GLenum err = ctx->dispatch.GetError();
690
691     if (unlikely (err))
692         while (ctx->dispatch.GetError ());
693
694     return err;
695 }
696
697 static inline cairo_device_t *
698 _cairo_gl_context_create_in_error (cairo_status_t status)
699 {
700     return (cairo_device_t *) _cairo_device_create_in_error (status);
701 }
702
703 cairo_private cairo_status_t
704 _cairo_gl_context_init (cairo_gl_context_t *ctx);
705
706 cairo_private void
707 _cairo_gl_context_reset (cairo_gl_context_t *ctx);
708
709 cairo_private void
710 _cairo_gl_surface_init (cairo_device_t *device,
711                         cairo_gl_surface_t *surface,
712                         cairo_content_t content,
713                         int width, int height);
714
715 static cairo_always_inline cairo_bool_t cairo_warn
716 _cairo_gl_surface_is_texture (cairo_gl_surface_t *surface)
717 {
718     return surface->tex != 0;
719 }
720
721 cairo_private cairo_status_t
722 _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
723                               cairo_image_surface_t *src,
724                               int src_x, int src_y,
725                               int width, int height,
726                               int dst_x, int dst_y,
727                               cairo_bool_t force_flush);
728
729 cairo_private cairo_int_status_t
730 _cairo_gl_surface_resolve_multisampling (cairo_gl_surface_t *surface);
731
732 static cairo_always_inline cairo_bool_t
733 _cairo_gl_device_has_glsl (cairo_device_t *device)
734 {
735     return ((cairo_gl_context_t *) device)->has_shader_support;
736 }
737
738 static cairo_always_inline cairo_bool_t
739 _cairo_gl_device_requires_power_of_two_textures (cairo_device_t *device)
740 {
741     return ((cairo_gl_context_t *) device)->tex_target == GL_TEXTURE_RECTANGLE;
742 }
743
744 static cairo_always_inline cairo_status_t cairo_warn
745 _cairo_gl_context_acquire (cairo_device_t *device,
746                            cairo_gl_context_t **ctx)
747 {
748     cairo_status_t status;
749
750     status = cairo_device_acquire (device);
751     if (unlikely (status))
752         return status;
753
754     /* clear potential previous GL errors */
755     _cairo_gl_get_error ((cairo_gl_context_t *) device);
756
757     *ctx = (cairo_gl_context_t *) device;
758     return CAIRO_STATUS_SUCCESS;
759 }
760
761 static cairo_always_inline cairo_warn cairo_status_t
762 _cairo_gl_context_release (cairo_gl_context_t *ctx, cairo_status_t status)
763 {
764     GLenum err;
765
766     err = _cairo_gl_get_error (ctx);
767
768     if (unlikely (err)) {
769         cairo_status_t new_status;
770         new_status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
771         if (status == CAIRO_STATUS_SUCCESS)
772             status = new_status;
773     }
774
775     cairo_device_release (&(ctx)->base);
776
777     return status;
778 }
779
780 cairo_private void
781 _cairo_gl_context_set_destination (cairo_gl_context_t *ctx,
782                                    cairo_gl_surface_t *surface,
783                                    cairo_bool_t multisampling);
784
785 cairo_private void
786 _cairo_gl_context_bind_framebuffer (cairo_gl_context_t *ctx,
787                                     cairo_gl_surface_t *surface,
788                                     cairo_bool_t multisampling);
789
790 cairo_private cairo_gl_emit_rect_t
791 _cairo_gl_context_choose_emit_rect (cairo_gl_context_t *ctx);
792
793 cairo_private void
794 _cairo_gl_context_emit_rect (cairo_gl_context_t *ctx,
795                              GLfloat x1, GLfloat y1,
796                              GLfloat x2, GLfloat y2);
797
798 cairo_private cairo_gl_emit_span_t
799 _cairo_gl_context_choose_emit_span (cairo_gl_context_t *ctx);
800
801 cairo_private cairo_gl_emit_glyph_t
802 _cairo_gl_context_choose_emit_glyph (cairo_gl_context_t *ctx,
803                                      const cairo_bool_t is_color_glyph);
804
805 cairo_private void
806 _cairo_gl_context_activate (cairo_gl_context_t *ctx,
807                             cairo_gl_tex_t      tex_unit);
808
809 cairo_private cairo_bool_t
810 _cairo_gl_operator_is_supported (cairo_operator_t op);
811
812 cairo_private cairo_bool_t
813 _cairo_gl_ensure_stencil (cairo_gl_context_t *ctx,
814                           cairo_gl_surface_t *surface);
815
816 static cairo_always_inline void
817 _disable_stencil_buffer (cairo_gl_context_t *ctx)
818 {
819     if (ctx->states_cache.stencil_test_enabled == TRUE) {
820         ctx->dispatch.Disable (GL_STENCIL_TEST);
821         ctx->states_cache.stencil_test_enabled = FALSE;
822     }
823 }
824
825 static cairo_always_inline void
826 _disable_scissor_buffer (cairo_gl_context_t *ctx)
827 {
828     if (ctx->states_cache.scissor_test_enabled == TRUE) {
829         ctx->dispatch.Disable (GL_SCISSOR_TEST);
830         ctx->states_cache.scissor_test_enabled = FALSE;
831     }
832 }
833
834 static cairo_always_inline void
835 _enable_stencil_buffer (cairo_gl_context_t *ctx)
836 {
837     if (ctx->states_cache.stencil_test_enabled == FALSE) {
838         ctx->dispatch.Enable (GL_STENCIL_TEST);
839         ctx->states_cache.stencil_test_enabled = TRUE;
840     }
841 }
842
843 static cairo_always_inline void
844 _enable_scissor_buffer (cairo_gl_context_t *ctx)
845 {
846     if (ctx->states_cache.scissor_test_enabled == FALSE) {
847         ctx->dispatch.Enable (GL_SCISSOR_TEST);
848         ctx->states_cache.scissor_test_enabled = TRUE;
849     }
850 }
851
852 static cairo_always_inline void
853 _cairo_gl_ensure_drawbuffers (cairo_gl_context_t *ctx)
854 {
855     GLint vbo, ibo, vao;
856
857     if ((ctx->vao != 0 && 
858          (ctx->vao != ctx->states_cache.bound_vao))) {
859         ctx->dispatch.GetIntegerv (GL_VERTEX_ARRAY_BINDING, &vao);
860         if (vao != (GLint)ctx->states_cache.bound_vao) {
861             ctx->dispatch.BindVertexArray (ctx->vao);
862             ctx->states_cache.bound_vao = ctx->vao;
863
864             ctx->dispatch.BindBuffer (GL_ARRAY_BUFFER, ctx->vbo);
865             ctx->states_cache.bound_vbo = ctx->vbo;
866
867             ctx->dispatch.BindBuffer (GL_ELEMENT_ARRAY_BUFFER, ctx->ibo);
868             ctx->states_cache.bound_ibo = ctx->ibo;
869         }
870     }
871
872     if ((ctx->vbo != 0 &&
873          (ctx->vbo != ctx->states_cache.bound_vbo))) {
874         ctx->dispatch.GetIntegerv (GL_ARRAY_BUFFER_BINDING, &vbo);
875         if (vbo != (GLint)ctx->states_cache.bound_vbo) {
876             ctx->dispatch.BindBuffer (GL_ARRAY_BUFFER, ctx->vbo);
877         }
878         ctx->states_cache.bound_vbo = ctx->vbo;
879     }
880
881     if ((ctx->ibo != 0 &&
882          (ctx->ibo != ctx->states_cache.bound_ibo))) {
883         ctx->dispatch.GetIntegerv (GL_ELEMENT_ARRAY_BUFFER_BINDING, &ibo);
884         if (ibo != (GLint)ctx->states_cache.bound_ibo) {
885             ctx->dispatch.BindBuffer (GL_ELEMENT_ARRAY_BUFFER, ctx->ibo);
886         }
887         ctx->states_cache.bound_ibo = ctx->ibo;
888     }
889 }
890
891 cairo_private cairo_status_t
892 _cairo_gl_composite_init (cairo_gl_composite_t *setup,
893                           cairo_operator_t op,
894                           cairo_gl_surface_t *dst,
895                           cairo_bool_t has_component_alpha);
896
897 cairo_private void
898 _cairo_gl_composite_fini (cairo_gl_composite_t *setup);
899
900 cairo_private cairo_status_t
901 _cairo_gl_composite_set_operator (cairo_gl_composite_t *setup,
902                                   cairo_operator_t op,
903                                   cairo_bool_t assume_component_alpha);
904
905 cairo_private void
906 _cairo_gl_composite_set_clip_region (cairo_gl_composite_t *setup,
907                                      cairo_region_t *clip_region);
908
909 cairo_private void
910 _cairo_gl_composite_set_clip(cairo_gl_composite_t *setup,
911                              cairo_clip_t *clip);
912
913 cairo_private cairo_int_status_t
914 _cairo_gl_composite_set_source (cairo_gl_composite_t *setup,
915                                 const cairo_pattern_t *pattern,
916                                 const cairo_rectangle_int_t *sample,
917                                 const cairo_rectangle_int_t *extents,
918                                 cairo_bool_t use_texgen,
919                                 cairo_bool_t encode_color_as_attribute);
920
921 cairo_private void
922 _cairo_gl_composite_set_solid_source (cairo_gl_composite_t *setup,
923                                       const cairo_color_t *color);
924
925 cairo_private void
926 _cairo_gl_composite_set_source_operand (cairo_gl_composite_t *setup,
927                                         const cairo_gl_operand_t *source);
928
929 cairo_private cairo_int_status_t
930 _cairo_gl_composite_set_mask (cairo_gl_composite_t *setup,
931                               const cairo_pattern_t *pattern,
932                               const cairo_rectangle_int_t *sample,
933                               const cairo_rectangle_int_t *extents,
934                               cairo_bool_t use_texgen);
935
936 cairo_private void
937 _cairo_gl_composite_set_mask_operand (cairo_gl_composite_t *setup,
938                                       const cairo_gl_operand_t *mask);
939
940 cairo_private void
941 _cairo_gl_composite_set_spans (cairo_gl_composite_t *setup);
942
943 cairo_private void
944 _cairo_gl_composite_set_multisample (cairo_gl_composite_t *setup);
945
946 cairo_private cairo_status_t
947 _cairo_gl_composite_begin (cairo_gl_composite_t *setup,
948                            cairo_gl_context_t **ctx);
949
950 cairo_private cairo_status_t
951 _cairo_gl_set_operands_and_operator (cairo_gl_composite_t *setup,
952                                      cairo_gl_context_t *ctx);
953
954 cairo_private void
955 _cairo_gl_composite_flush (cairo_gl_context_t *ctx);
956
957 cairo_private cairo_int_status_t
958 _cairo_gl_composite_emit_quad_as_tristrip (cairo_gl_context_t   *ctx,
959                                            cairo_gl_composite_t *setup,
960                                            const cairo_point_t   quad[4]);
961
962 cairo_private cairo_int_status_t
963 _cairo_gl_composite_emit_int_quad_as_tristrip (cairo_gl_context_t *ctx,
964                                                cairo_gl_composite_t *setup,
965                                                const int         quad[8]);
966
967 cairo_private cairo_int_status_t
968 _cairo_gl_composite_emit_triangle_as_tristrip (cairo_gl_context_t       *ctx,
969                                                cairo_gl_composite_t     *setup,
970                                                const cairo_point_t       triangle[3]);
971
972 cairo_private cairo_int_status_t
973 _cairo_gl_composite_emit_triangle_fan (cairo_gl_context_t     *ctx,
974                                        cairo_gl_composite_t   *setup,
975                                        const cairo_point_t    *fan,
976                                        int                     count);
977
978 cairo_private cairo_int_status_t
979 _cairo_gl_composite_emit_point_as_tristrip_line (cairo_gl_context_t  *ctx,
980                                                  const cairo_point_t point[2],
981                                                  cairo_bool_t        start_point);
982
983 cairo_private cairo_int_status_t
984 _cairo_gl_composite_emit_point_as_single_line (cairo_gl_context_t  *ctx,
985                                                 const cairo_point_t point[2]);
986
987 cairo_private void
988 _cairo_gl_context_destroy_operand (cairo_gl_context_t *ctx,
989                                    cairo_gl_tex_t tex_unit);
990
991 cairo_private cairo_bool_t
992 _cairo_gl_get_image_format_and_type (cairo_gl_flavor_t flavor,
993                                      pixman_format_code_t pixman_format,
994                                      GLenum *internal_format, GLenum *format,
995                                      GLenum *type, cairo_bool_t *has_alpha,
996                                      cairo_bool_t *needs_swap);
997
998 cairo_private void
999 _cairo_gl_glyph_cache_init (cairo_gl_glyph_cache_t *cache);
1000
1001 cairo_private void
1002 _cairo_gl_glyph_cache_fini (cairo_gl_context_t *ctx,
1003                             cairo_gl_glyph_cache_t *cache);
1004
1005 cairo_private cairo_int_status_t
1006 _cairo_gl_surface_show_glyphs (void                     *abstract_dst,
1007                                cairo_operator_t          op,
1008                                const cairo_pattern_t    *source,
1009                                cairo_glyph_t            *glyphs,
1010                                int                       num_glyphs,
1011                                cairo_scaled_font_t      *scaled_font,
1012                                const cairo_clip_t       *clip,
1013                                int                      *remaining_glyphs);
1014
1015 cairo_private cairo_status_t
1016 _cairo_gl_context_init_shaders (cairo_gl_context_t *ctx);
1017
1018 cairo_private void
1019 _cairo_gl_context_fini_shaders (cairo_gl_context_t *ctx);
1020
1021 static cairo_always_inline cairo_bool_t
1022 _cairo_gl_context_is_flushed (cairo_gl_context_t *ctx)
1023 {
1024     return ctx->vb_offset == 0;
1025 }
1026
1027 cairo_private cairo_status_t
1028 _cairo_gl_get_shader_by_type (cairo_gl_context_t *ctx,
1029                               cairo_gl_operand_t *source,
1030                               cairo_gl_operand_t *mask,
1031                               cairo_bool_t use_coverage,
1032                               cairo_gl_shader_in_t in,
1033                               cairo_gl_shader_t **shader);
1034
1035 cairo_private cairo_gl_uniform_t
1036 _cairo_gl_shader_uniform_for_texunit (cairo_gl_uniform_t uniform,
1037                                       cairo_gl_tex_t tex_unit);
1038
1039 cairo_private void
1040 _cairo_gl_shader_bind_float (cairo_gl_context_t *ctx,
1041                              GLint location,
1042                              float value);
1043
1044 cairo_private void
1045 _cairo_gl_shader_bind_float_array (cairo_gl_context_t *ctx,
1046                                    GLint location,
1047                                    int num, float *values);
1048
1049 cairo_private void
1050 _cairo_gl_shader_bind_int (cairo_gl_context_t *ctx,
1051                              GLint location,
1052                              int value);
1053
1054 cairo_private void
1055 _cairo_gl_shader_bind_vec2 (cairo_gl_context_t *ctx,
1056                             GLint location,
1057                             float value0, float value1);
1058
1059 cairo_private void
1060 _cairo_gl_shader_bind_vec3 (cairo_gl_context_t *ctx,
1061                             GLint location,
1062                             float value0,
1063                             float value1,
1064                             float value2);
1065
1066 cairo_private void
1067 _cairo_gl_shader_bind_vec4 (cairo_gl_context_t *ctx,
1068                             GLint location,
1069                             float value0, float value1,
1070                             float value2, float value3);
1071
1072 cairo_private void
1073 _cairo_gl_shader_bind_matrix (cairo_gl_context_t *ctx,
1074                               GLint location,
1075                               const cairo_matrix_t* m);
1076
1077 cairo_private void
1078 _cairo_gl_shader_bind_matrix4f (cairo_gl_context_t *ctx,
1079                                 GLint location,
1080                                 GLfloat* gl_m);
1081
1082 cairo_private void
1083 _cairo_gl_set_shader (cairo_gl_context_t *ctx,
1084                       cairo_gl_shader_t *shader);
1085
1086 cairo_private void
1087 _cairo_gl_shader_fini (cairo_gl_context_t *ctx, cairo_gl_shader_t *shader);
1088
1089 cairo_private int
1090 _cairo_gl_get_version (cairo_gl_dispatch_t *dispatch);
1091
1092 cairo_private int
1093 _cairo_glsl_get_version (cairo_gl_dispatch_t *dispatch);
1094
1095 cairo_private cairo_gl_flavor_t
1096 _cairo_gl_get_flavor (cairo_gl_dispatch_t *dispatch);
1097
1098 cairo_private unsigned long
1099 _cairo_gl_get_vbo_size (void);
1100
1101 cairo_private cairo_bool_t
1102 _cairo_gl_has_extension (cairo_gl_dispatch_t *dispatch, const char *ext);
1103
1104 cairo_private cairo_status_t
1105 _cairo_gl_dispatch_init(cairo_gl_dispatch_t *dispatch,
1106                         cairo_gl_get_proc_addr_func_t get_proc_addr,
1107                         void *data);
1108
1109 cairo_private cairo_int_status_t
1110 _cairo_gl_operand_init (cairo_gl_operand_t *operand,
1111                         const cairo_pattern_t *pattern,
1112                         cairo_gl_surface_t *dst,
1113                         const cairo_rectangle_int_t *sample,
1114                         const cairo_rectangle_int_t *extents,
1115                         cairo_bool_t use_texgen,
1116                         cairo_bool_t encode_color_as_attribute);
1117
1118 cairo_private void
1119 _cairo_gl_solid_operand_init (cairo_gl_operand_t *operand,
1120                               const cairo_color_t *color);
1121
1122 cairo_private cairo_filter_t
1123 _cairo_gl_operand_get_filter (cairo_gl_operand_t *operand);
1124
1125 cairo_private GLint
1126 _cairo_gl_operand_get_gl_filter (cairo_gl_operand_t *operand);
1127
1128 cairo_private cairo_extend_t
1129 _cairo_gl_operand_get_extend (cairo_gl_operand_t *operand);
1130
1131 cairo_private cairo_extend_t
1132 _cairo_gl_operand_get_atlas_extend (cairo_gl_operand_t *operand);
1133
1134 cairo_private unsigned int
1135 _cairo_gl_operand_get_vertex_size (const cairo_gl_operand_t *operand);
1136
1137 cairo_private cairo_bool_t
1138 _cairo_gl_operand_get_use_atlas (cairo_gl_operand_t *operand);
1139
1140 cairo_private cairo_bool_t
1141 _cairo_gl_operand_needs_setup (cairo_gl_operand_t *dest,
1142                                cairo_gl_operand_t *source,
1143                                unsigned int        vertex_offset);
1144
1145 cairo_private void
1146 _cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx,
1147                                   cairo_gl_operand_t *operand,
1148                                   cairo_gl_tex_t      tex_unit);
1149
1150 cairo_private void
1151 _cairo_gl_operand_emit (cairo_gl_operand_t *operand,
1152                         GLfloat ** vb,
1153                         GLfloat x,
1154                         GLfloat y);
1155
1156 cairo_private void
1157 _cairo_gl_operand_copy (cairo_gl_operand_t *dst,
1158                         const cairo_gl_operand_t *src);
1159
1160 cairo_private void
1161 _cairo_gl_operand_translate (cairo_gl_operand_t *operand,
1162                              double tx, double ty);
1163
1164 cairo_private void
1165 _cairo_gl_operand_destroy (cairo_gl_operand_t *operand);
1166
1167 cairo_private const cairo_compositor_t *
1168 _cairo_gl_msaa_compositor_get (void);
1169
1170 cairo_private const cairo_compositor_t *
1171 _cairo_gl_span_compositor_get (void);
1172
1173 cairo_private const cairo_compositor_t *
1174 _cairo_gl_traps_compositor_get (void);
1175
1176 cairo_private cairo_int_status_t
1177 _cairo_gl_check_composite_glyphs (const cairo_composite_rectangles_t *extents,
1178                                   cairo_scaled_font_t *scaled_font,
1179                                   cairo_glyph_t *glyphs,
1180                                   int *num_glyphs);
1181
1182 cairo_private cairo_int_status_t
1183 _cairo_gl_composite_glyphs (void                        *_dst,
1184                             cairo_operator_t             op,
1185                             cairo_surface_t             *_src,
1186                             int                          src_x,
1187                             int                          src_y,
1188                             int                          dst_x,
1189                             int                          dst_y,
1190                             cairo_composite_glyphs_info_t *info);
1191
1192 cairo_private cairo_int_status_t
1193 _cairo_gl_composite_glyphs_with_clip (void                          *_dst,
1194                                       cairo_operator_t               op,
1195                                       cairo_surface_t               *_src,
1196                                       int                            src_x,
1197                                       int                            src_y,
1198                                       int                            dst_x,
1199                                       int                            dst_y,
1200                                       cairo_composite_glyphs_info_t *info,
1201                                       cairo_clip_t                  *clip);
1202
1203 cairo_private void
1204 _cairo_gl_image_node_destroy (cairo_rtree_node_t *node);
1205
1206 cairo_private void
1207 _cairo_gl_image_node_fini (void *data);
1208
1209 cairo_private void
1210 _cairo_gl_image_cache_unlock (cairo_gl_context_t *ctx);
1211
1212 cairo_private cairo_int_status_t
1213 _cairo_gl_image_cache_init (cairo_gl_context_t *ctx, int width, int height,
1214                             cairo_gl_image_cache_t **image_cache);
1215 cairo_private void
1216 _cairo_gl_image_cache_fini (cairo_gl_context_t *ctx);
1217
1218 cairo_private void
1219 _cairo_gl_ensure_framebuffer (cairo_gl_context_t *ctx,
1220                               cairo_gl_surface_t *surface);
1221
1222 cairo_private cairo_surface_t *
1223 _cairo_gl_surface_create_scratch (cairo_gl_context_t   *ctx,
1224                                   cairo_content_t       content,
1225                                   int                   width,
1226                                   int                   height);
1227
1228 cairo_private cairo_surface_t *
1229 _cairo_gl_surface_create_scratch_for_caching (cairo_gl_context_t *ctx,
1230                                               cairo_content_t content,
1231                                               int width,
1232                                               int height);
1233
1234 cairo_private cairo_surface_t *
1235 _cairo_gl_pattern_to_source (cairo_surface_t *dst,
1236                              const cairo_pattern_t *pattern,
1237                              cairo_bool_t is_mask,
1238                              const cairo_rectangle_int_t *extents,
1239                              const cairo_rectangle_int_t *sample,
1240                              int *src_x, int *src_y);
1241
1242 cairo_private cairo_int_status_t
1243 _cairo_gl_msaa_compositor_draw_clip (cairo_gl_context_t *ctx,
1244                                      cairo_gl_composite_t *setup,
1245                                      cairo_clip_t *clip);
1246
1247 cairo_private cairo_surface_t *
1248 _cairo_gl_white_source (void);
1249
1250 cairo_private void
1251 _cairo_gl_scissor_to_rectangle (cairo_gl_surface_t *surface,
1252                                 const cairo_rectangle_int_t *r);
1253
1254 static inline cairo_gl_operand_t *
1255 source_to_operand (cairo_surface_t *surface)
1256 {
1257     cairo_gl_source_t *source = (cairo_gl_source_t *)surface;
1258     return source ? &source->operand : NULL;
1259 }
1260
1261 static inline void
1262 _cairo_gl_glyph_cache_unlock (cairo_gl_glyph_cache_t *cache)
1263 {
1264     _cairo_rtree_unpin (&cache->rtree);
1265 }
1266
1267
1268
1269 cairo_private cairo_bool_t
1270 _cairo_gl_hairline_style_is_hairline (const cairo_stroke_style_t *style,
1271                                       const cairo_matrix_t       *ctm);
1272
1273 cairo_private cairo_status_t
1274 _cairo_gl_hairline_move_to (void *closure,
1275                             const cairo_point_t *point);
1276
1277 cairo_private cairo_status_t
1278 _cairo_gl_hairline_line_to (void *closure,
1279                             const cairo_point_t *point);
1280
1281 cairo_private cairo_status_t
1282 _cairo_gl_hairline_line_to_dashed (void *closure,
1283                                    const cairo_point_t *point);
1284
1285 cairo_private cairo_status_t
1286 _cairo_gl_hairline_curve_to (void *closure,
1287                              const cairo_point_t *p0,
1288                              const cairo_point_t *p1,
1289                              const cairo_point_t *p2);
1290
1291 cairo_private cairo_status_t
1292 _cairo_gl_hairline_close_path (void *closure);
1293
1294 cairo_private cairo_status_t
1295 _cairo_gl_path_fixed_stroke_to_hairline (const cairo_path_fixed_t *path,
1296                                          cairo_gl_hairline_closure_t *closure,
1297                                          const cairo_stroke_style_t *style,
1298                                          const cairo_matrix_t *ctm,
1299                                          const cairo_matrix_t *ctm_inverse,
1300                                          cairo_path_fixed_move_to_func_t *move_to,
1301                                          cairo_path_fixed_line_to_func_t *line_to,
1302                                          cairo_path_fixed_curve_to_func_t *curve_to,
1303                                          cairo_path_fixed_close_path_func_t *close_path);
1304
1305 cairo_private cairo_gl_surface_t *
1306 _cairo_gl_gaussian_filter (cairo_gl_surface_t *dst,
1307                            const cairo_surface_pattern_t *pattern,
1308                            cairo_gl_surface_t *src,
1309                            cairo_rectangle_int_t *extents_out);
1310
1311 static inline cairo_bool_t
1312 _cairo_gl_surface_is_scratch (cairo_gl_context_t *ctx,
1313                               cairo_gl_surface_t *surface)
1314 {
1315     int i;
1316
1317     for (i = 0; i < 2; i++) {
1318         if (surface == ctx->source_scratch_surfaces[i] ||
1319             surface == ctx->mask_scratch_surfaces[i] ||
1320             surface == ctx->shadow_scratch_surfaces[i])
1321             return TRUE;
1322     }
1323
1324     if (surface == ctx->shadow_scratch_surfaces[2])
1325         return TRUE;
1326
1327     return FALSE;
1328 }
1329
1330 slim_hidden_proto (cairo_gl_surface_create);
1331 slim_hidden_proto (cairo_gl_surface_create_for_texture);
1332
1333 #endif /* CAIRO_GL_PRIVATE_H */