Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

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