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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrGLUtil.h"
#include "SkMatrix.h"
#include <stdio.h>
void GrGLClearErr(const GrGLInterface* gl) {
while (GR_GL_NO_ERROR != gl->fFunctions.fGetError()) {}
}
namespace {
const char *get_error_string(uint32_t err) {
switch (err) {
case GR_GL_NO_ERROR:
return "";
case GR_GL_INVALID_ENUM:
return "Invalid Enum";
case GR_GL_INVALID_VALUE:
return "Invalid Value";
case GR_GL_INVALID_OPERATION:
return "Invalid Operation";
case GR_GL_OUT_OF_MEMORY:
return "Out of Memory";
case GR_GL_CONTEXT_LOST:
return "Context Lost";
}
return "Unknown";
}
}
void GrGLCheckErr(const GrGLInterface* gl,
const char* location,
const char* call) {
uint32_t err = GR_GL_GET_ERROR(gl);
if (GR_GL_NO_ERROR != err) {
GrPrintf("---- glGetError 0x%x(%s)", err, get_error_string(err));
if (NULL != location) {
GrPrintf(" at\n\t%s", location);
}
if (NULL != call) {
GrPrintf("\n\t\t%s", call);
}
GrPrintf("\n");
}
}
namespace {
// Mesa uses a non-standard version string of format: 1.4 Mesa <mesa_major>.<mesa_minor>.
// The mapping of from mesa version to GL version came from here: http://www.mesa3d.org/intro.html
bool get_gl_version_for_mesa(int mesaMajorVersion, int* major, int* minor) {
switch (mesaMajorVersion) {
case 2:
case 3:
case 4:
case 5:
case 6:
*major = 1;
*minor = mesaMajorVersion - 1;
return true;
case 7:
*major = 2;
*minor = 1;
return true;
case 8:
*major = 3;
*minor = 0;
return true;
case 9:
*major = 3;
*minor = 1;
return true;
case 10:
*major = 3;
*minor = 3;
return true;
default:
return false;
}
}
}
///////////////////////////////////////////////////////////////////////////////
#if GR_GL_LOG_CALLS
bool gLogCallsGL = !!(GR_GL_LOG_CALLS_START);
#endif
#if GR_GL_CHECK_ERROR
bool gCheckErrorGL = !!(GR_GL_CHECK_ERROR_START);
#endif
///////////////////////////////////////////////////////////////////////////////
GrGLStandard GrGLGetStandardInUseFromString(const char* versionString) {
if (NULL == versionString) {
SkDEBUGFAIL("NULL GL version string.");
return kNone_GrGLStandard;
}
int major, minor;
// check for desktop
int n = sscanf(versionString, "%d.%d", &major, &minor);
if (2 == n) {
return kGL_GrGLStandard;
}
// check for ES 1
char profile[2];
n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1, &major, &minor);
if (4 == n) {
// we no longer support ES1.
return kNone_GrGLStandard;
}
// check for ES2
n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor);
if (2 == n) {
return kGLES_GrGLStandard;
}
return kNone_GrGLStandard;
}
bool GrGLIsMesaFromVersionString(const char* versionString) {
int major, minor, mesaMajor, mesaMinor;
int n = sscanf(versionString, "%d.%d Mesa %d.%d", &major, &minor, &mesaMajor, &mesaMinor);
return 4 == n;
}
bool GrGLIsChromiumFromRendererString(const char* rendererString) {
return 0 == strcmp(rendererString, "Chromium");
}
GrGLVersion GrGLGetVersionFromString(const char* versionString) {
if (NULL == versionString) {
SkDEBUGFAIL("NULL GL version string.");
return 0;
}
int major, minor;
// check for mesa
int mesaMajor, mesaMinor;
int n = sscanf(versionString, "%d.%d Mesa %d.%d", &major, &minor, &mesaMajor, &mesaMinor);
if (4 == n) {
if (get_gl_version_for_mesa(mesaMajor, &major, &minor)) {
return GR_GL_VER(major, minor);
} else {
return 0;
}
}
n = sscanf(versionString, "%d.%d", &major, &minor);
if (2 == n) {
return GR_GL_VER(major, minor);
}
char profile[2];
n = sscanf(versionString, "OpenGL ES-%c%c %d.%d", profile, profile+1,
&major, &minor);
if (4 == n) {
return GR_GL_VER(major, minor);
}
n = sscanf(versionString, "OpenGL ES %d.%d", &major, &minor);
if (2 == n) {
return GR_GL_VER(major, minor);
}
return 0;
}
GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString) {
if (NULL == versionString) {
SkDEBUGFAIL("NULL GLSL version string.");
return 0;
}
int major, minor;
int n = sscanf(versionString, "%d.%d", &major, &minor);
if (2 == n) {
return GR_GLSL_VER(major, minor);
}
n = sscanf(versionString, "OpenGL ES GLSL ES %d.%d", &major, &minor);
if (2 == n) {
return GR_GLSL_VER(major, minor);
}
#ifdef SK_BUILD_FOR_ANDROID
// android hack until the gpu vender updates their drivers
n = sscanf(versionString, "OpenGL ES GLSL %d.%d", &major, &minor);
if (2 == n) {
return GR_GLSL_VER(major, minor);
}
#endif
return 0;
}
GrGLVendor GrGLGetVendorFromString(const char* vendorString) {
if (NULL != vendorString) {
if (0 == strcmp(vendorString, "ARM")) {
return kARM_GrGLVendor;
}
if (0 == strcmp(vendorString, "Imagination Technologies")) {
return kImagination_GrGLVendor;
}
if (0 == strncmp(vendorString, "Intel ", 6) || 0 == strcmp(vendorString, "Intel")) {
return kIntel_GrGLVendor;
}
if (0 == strcmp(vendorString, "Qualcomm")) {
return kQualcomm_GrGLVendor;
}
}
return kOther_GrGLVendor;
}
GrGLRenderer GrGLGetRendererFromString(const char* rendererString) {
if (NULL != rendererString) {
if (0 == strcmp(rendererString, "NVIDIA Tegra 3")) {
return kTegra3_GrGLRenderer;
} else if (0 == strcmp(rendererString, "NVIDIA Tegra")) {
return kTegra2_GrGLRenderer;
}
}
return kOther_GrGLRenderer;
}
GrGLVersion GrGLGetVersion(const GrGLInterface* gl) {
const GrGLubyte* v;
GR_GL_CALL_RET(gl, v, GetString(GR_GL_VERSION));
return GrGLGetVersionFromString((const char*) v);
}
GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface* gl) {
const GrGLubyte* v;
GR_GL_CALL_RET(gl, v, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
return GrGLGetGLSLVersionFromString((const char*) v);
}
GrGLVendor GrGLGetVendor(const GrGLInterface* gl) {
const GrGLubyte* v;
GR_GL_CALL_RET(gl, v, GetString(GR_GL_VENDOR));
return GrGLGetVendorFromString((const char*) v);
}
GrGLRenderer GrGLGetRenderer(const GrGLInterface* gl) {
const GrGLubyte* v;
GR_GL_CALL_RET(gl, v, GetString(GR_GL_RENDERER));
return GrGLGetRendererFromString((const char*) v);
}
template<> void GrGLGetMatrix<3>(GrGLfloat* dest, const SkMatrix& src) {
// Col 0
dest[0] = SkScalarToFloat(src[SkMatrix::kMScaleX]);
dest[1] = SkScalarToFloat(src[SkMatrix::kMSkewY]);
dest[2] = SkScalarToFloat(src[SkMatrix::kMPersp0]);
// Col 1
dest[3] = SkScalarToFloat(src[SkMatrix::kMSkewX]);
dest[4] = SkScalarToFloat(src[SkMatrix::kMScaleY]);
dest[5] = SkScalarToFloat(src[SkMatrix::kMPersp1]);
// Col 2
dest[6] = SkScalarToFloat(src[SkMatrix::kMTransX]);
dest[7] = SkScalarToFloat(src[SkMatrix::kMTransY]);
dest[8] = SkScalarToFloat(src[SkMatrix::kMPersp2]);
}
template<> void GrGLGetMatrix<4>(GrGLfloat* dest, const SkMatrix& src) {
// Col 0
dest[0] = SkScalarToFloat(src[SkMatrix::kMScaleX]);
dest[1] = SkScalarToFloat(src[SkMatrix::kMSkewY]);
dest[2] = 0;
dest[3] = SkScalarToFloat(src[SkMatrix::kMPersp0]);
// Col 1
dest[4] = SkScalarToFloat(src[SkMatrix::kMSkewX]);
dest[5] = SkScalarToFloat(src[SkMatrix::kMScaleY]);
dest[6] = 0;
dest[7] = SkScalarToFloat(src[SkMatrix::kMPersp1]);
// Col 2
dest[8] = 0;
dest[9] = 0;
dest[10] = 1;
dest[11] = 0;
// Col 3
dest[12] = SkScalarToFloat(src[SkMatrix::kMTransX]);
dest[13] = SkScalarToFloat(src[SkMatrix::kMTransY]);
dest[14] = 0;
dest[15] = SkScalarToFloat(src[SkMatrix::kMPersp2]);
}
|