d23b8a5eec369e54ddc8e0d9d7595b6aaf23ab33
[framework/graphics/cairo.git] / src / cairo-gl.h
1 /* Cairo - a vector graphics library with display and print output
2  *
3  * Copyright © 2009 Eric Anholt
4  * Copyright © 2009 Chris Wilson
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it either under the terms of the GNU Lesser General Public
8  * License version 2.1 as published by the Free Software Foundation
9  * (the "LGPL") or, at your option, under the terms of the Mozilla
10  * Public License Version 1.1 (the "MPL"). If you do not alter this
11  * notice, a recipient may use your version of this file under either
12  * the MPL or the LGPL.
13  *
14  * You should have received a copy of the LGPL along with this library
15  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
17  * You should have received a copy of the MPL along with this library
18  * in the file COPYING-MPL-1.1
19  *
20  * The contents of this file are subject to the Mozilla Public License
21  * Version 1.1 (the "License"); you may not use this file except in
22  * compliance with the License. You may obtain a copy of the License at
23  * http://www.mozilla.org/MPL/
24  *
25  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27  * the specific language governing rights and limitations.
28  *
29  * The Original Code is the cairo graphics library.
30  *
31  * The Initial Developer of the Original Code is Eric Anholt.
32  */
33
34 /**
35  * @file cairo-gl.h
36  *
37  * The cairo-gl backend provides an implementation of possibly
38  * hardware-accelerated cairo rendering by targeting the OpenGL API.
39  * The goal of the cairo-gl backend is to provide better performance
40  * with equal functionality to cairo-image where possible.  It does
41  * not directly provide for applying additional OpenGL effects to
42  * cairo surfaces.
43  *
44  * Cairo-gl allows interoperability with other GL rendering through GL
45  * context sharing.  Cairo-gl surfaces are created in reference to a
46  * #cairo_device_t, which represents an GL context created by the user.
47  * When that GL context is created with its sharePtr set to another
48  * context (or vice versa), its objects (textures backing cairo-gl
49  * surfaces) can be accessed in the other OpenGL context.  This allows
50  * cairo-gl to maintain its drawing state in one context while the
51  * user's 3D rendering occurs in the user's other context.
52  *
53  * However, as only one context can be current to a thread at a time,
54  * cairo-gl may make its context current to the thread on any cairo
55  * call which interacts with a cairo-gl surface or the cairo-gl
56  * device.  As a result, the user must make their own context current
57  * between any cairo calls and their own OpenGL rendering.
58  */
59
60 #ifndef CAIRO_GL_H
61 #define CAIRO_GL_H
62
63 #include "cairo.h"
64
65 #if CAIRO_HAS_GL_SURFACE || CAIRO_HAS_GLESV2_SURFACE
66
67 CAIRO_BEGIN_DECLS
68
69 cairo_public cairo_surface_t *
70 cairo_gl_surface_create (cairo_device_t *device,
71                          cairo_content_t content,
72                          int width, int height);
73
74 cairo_public cairo_surface_t *
75 cairo_gl_surface_create_for_texture (cairo_device_t *abstract_device,
76                                      cairo_content_t content,
77                                      unsigned int tex,
78                                      int width, int height);
79 cairo_public void
80 cairo_gl_surface_set_size (cairo_surface_t *surface, int width, int height);
81
82 cairo_public int
83 cairo_gl_surface_get_width (cairo_surface_t *abstract_surface);
84
85 cairo_public int
86 cairo_gl_surface_get_height (cairo_surface_t *abstract_surface);
87
88 cairo_public void
89 cairo_gl_surface_swapbuffers (cairo_surface_t *surface);
90
91 #if CAIRO_HAS_GLX_FUNCTIONS
92 #include <GL/glx.h>
93
94 cairo_public cairo_device_t *
95 cairo_glx_device_create (Display *dpy, GLXContext gl_ctx);
96
97 cairo_public Display *
98 cairo_glx_device_get_display (cairo_device_t *device);
99
100 cairo_public GLXContext
101 cairo_glx_device_get_context (cairo_device_t *device);
102
103 cairo_public cairo_surface_t *
104 cairo_gl_surface_create_for_window (cairo_device_t *device,
105                                     Window win,
106                                     int width, int height);
107 #endif
108
109 #if CAIRO_HAS_WGL_FUNCTIONS
110 #include <windows.h>
111
112 cairo_public cairo_device_t *
113 cairo_wgl_device_create (HGLRC rc);
114
115 cairo_public HGLRC
116 cairo_wgl_device_get_context (cairo_device_t *device);
117
118 cairo_public cairo_surface_t *
119 cairo_gl_surface_create_for_dc (cairo_device_t          *device,
120                                 HDC                      dc,
121                                 int                      width,
122                                 int                      height);
123 #endif
124
125 #if CAIRO_HAS_EGL_FUNCTIONS
126 #include <EGL/egl.h>
127
128 cairo_public cairo_device_t *
129 cairo_egl_device_create (EGLDisplay dpy, EGLContext egl);
130
131 cairo_public cairo_surface_t *
132 cairo_gl_surface_create_for_egl (cairo_device_t *device,
133                                  EGLSurface      egl,
134                                  int             width,
135                                  int             height);
136
137 #endif
138
139 CAIRO_END_DECLS
140
141 #else  /* CAIRO_HAS_GL_SURFACE */
142 # error Cairo was not compiled with support for the GL backend
143 #endif /* CAIRO_HAS_GL_SURFACE */
144
145 #endif /* CAIRO_GL_H */