1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrGLUtil_DEFINED
#define GrGLUtil_DEFINED
#include "gl/GrGLInterface.h"
#include "GrGLDefines.h"
#include "GrStencilSettings.h"
class SkMatrix;
////////////////////////////////////////////////////////////////////////////////
typedef uint32_t GrGLVersion;
typedef uint32_t GrGLSLVersion;
typedef uint32_t GrGLDriverVersion;
#define GR_GL_VER(major, minor) ((static_cast<int>(major) << 16) | \
static_cast<int>(minor))
#define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \
static_cast<int>(minor))
#define GR_GL_DRIVER_VER(major, minor) ((static_cast<int>(major) << 16) | \
static_cast<int>(minor))
#define GR_GL_INVALID_VER GR_GL_VER(0, 0)
#define GR_GLSL_INVALID_VER GR_GLSL_VER(0, 0)
#define GR_GL_DRIVER_UNKNOWN_VER GR_GL_DRIVER_VER(0, 0)
/**
* The Vendor and Renderer enum values are lazily updated as required.
*/
enum GrGLVendor {
kARM_GrGLVendor,
kImagination_GrGLVendor,
kIntel_GrGLVendor,
kQualcomm_GrGLVendor,
kNVIDIA_GrGLVendor,
kATI_GrGLVendor,
kOther_GrGLVendor
};
enum GrGLRenderer {
kTegra2_GrGLRenderer,
kTegra3_GrGLRenderer,
kPowerVR54x_GrGLRenderer,
kPowerVRRogue_GrGLRenderer,
kAdreno3xx_GrGLRenderer,
kAdreno4xx_GrGLRenderer,
kAdreno5xx_GrGLRenderer,
kOSMesa_GrGLRenderer,
/** Either HD 6xxx or Iris 6xxx */
kIntel6xxx_GrGLRenderer,
kOther_GrGLRenderer
};
enum GrGLDriver {
kMesa_GrGLDriver,
kChromium_GrGLDriver,
kNVIDIA_GrGLDriver,
kIntel_GrGLDriver,
kANGLE_GrGLDriver,
kUnknown_GrGLDriver
};
////////////////////////////////////////////////////////////////////////////////
/**
* Some drivers want the var-int arg to be zero-initialized on input.
*/
#define GR_GL_INIT_ZERO 0
#define GR_GL_GetIntegerv(gl, e, p) \
do { \
*(p) = GR_GL_INIT_ZERO; \
GR_GL_CALL(gl, GetIntegerv(e, p)); \
} while (0)
#define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \
do { \
*(p) = GR_GL_INIT_ZERO; \
GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
} while (0)
#define GR_GL_GetNamedFramebufferAttachmentParameteriv(gl, fb, a, pname, p) \
do { \
*(p) = GR_GL_INIT_ZERO; \
GR_GL_CALL(gl, GetNamedFramebufferAttachmentParameteriv(fb, a, pname, p)); \
} while (0)
#define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \
do { \
*(p) = GR_GL_INIT_ZERO; \
GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \
} while (0)
#define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \
do { \
*(p) = GR_GL_INIT_ZERO; \
GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \
} while (0)
#define GR_GL_GetShaderPrecisionFormat(gl, st, pt, range, precision) \
do { \
(range)[0] = GR_GL_INIT_ZERO; \
(range)[1] = GR_GL_INIT_ZERO; \
(*precision) = GR_GL_INIT_ZERO; \
GR_GL_CALL(gl, GetShaderPrecisionFormat(st, pt, range, precision)); \
} while (0)
////////////////////////////////////////////////////////////////////////////////
/**
* Helpers for glGetString()
*/
// these variants assume caller already has a string from glGetString()
GrGLVersion GrGLGetVersionFromString(const char* versionString);
GrGLStandard GrGLGetStandardInUseFromString(const char* versionString);
GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString);
GrGLVendor GrGLGetVendorFromString(const char* vendorString);
GrGLRenderer GrGLGetRendererFromString(const char* rendererString);
void GrGLGetDriverInfo(GrGLStandard standard,
GrGLVendor vendor,
const char* rendererString,
const char* versionString,
GrGLDriver* outDriver,
GrGLDriverVersion* outVersion);
// these variants call glGetString()
GrGLVersion GrGLGetVersion(const GrGLInterface*);
GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*);
GrGLVendor GrGLGetVendor(const GrGLInterface*);
GrGLRenderer GrGLGetRenderer(const GrGLInterface*);
/**
* Helpers for glGetError()
*/
void GrGLCheckErr(const GrGLInterface* gl,
const char* location,
const char* call);
void GrGLClearErr(const GrGLInterface* gl);
////////////////////////////////////////////////////////////////////////////////
/**
* Macros for using GrGLInterface to make GL calls
*/
// internal macro to conditionally call glGetError based on compile-time and
// run-time flags.
#if GR_GL_CHECK_ERROR
extern bool gCheckErrorGL;
#define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \
if (gCheckErrorGL) \
GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X)
#else
#define GR_GL_CHECK_ERROR_IMPL(IFACE, X)
#endif
// internal macro to conditionally log the gl call using SkDebugf based on
// compile-time and run-time flags.
#if GR_GL_LOG_CALLS
extern bool gLogCallsGL;
#define GR_GL_LOG_CALLS_IMPL(X) \
if (gLogCallsGL) \
SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
#else
#define GR_GL_LOG_CALLS_IMPL(X)
#endif
// makes a GL call on the interface and does any error checking and logging
#define GR_GL_CALL(IFACE, X) \
do { \
GR_GL_CALL_NOERRCHECK(IFACE, X); \
GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
} while (false)
// Variant of above that always skips the error check. This is useful when
// the caller wants to do its own glGetError() call and examine the error value.
#define GR_GL_CALL_NOERRCHECK(IFACE, X) \
do { \
(IFACE)->fFunctions.f##X; \
GR_GL_LOG_CALLS_IMPL(X); \
} while (false)
// same as GR_GL_CALL but stores the return value of the gl call in RET
#define GR_GL_CALL_RET(IFACE, RET, X) \
do { \
GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \
GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
} while (false)
// same as GR_GL_CALL_RET but always skips the error check.
#define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \
do { \
(RET) = (IFACE)->fFunctions.f##X; \
GR_GL_LOG_CALLS_IMPL(X); \
} while (false)
// call glGetError without doing a redundant error check or logging.
#define GR_GL_GET_ERROR(IFACE) (IFACE)->fFunctions.fGetError()
GrGLenum GrToGLStencilFunc(GrStencilTest test);
#endif
|