OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "gl/GrGLInterface.h" | 9 #include "gl/GrGLInterface.h" |
10 #include "gl/GrGLExtensions.h" | 10 #include "gl/GrGLExtensions.h" |
11 #include "gl/GrGLUtil.h" | 11 #include "gl/GrGLUtil.h" |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 | 14 |
15 #if GR_GL_PER_GL_FUNC_CALLBACK | 15 #if GR_GL_PER_GL_FUNC_CALLBACK |
16 namespace { | 16 namespace { |
17 void GrGLDefaultInterfaceCallback(const GrGLInterface*) {} | 17 void GrGLDefaultInterfaceCallback(const GrGLInterface*) {} |
18 } | 18 } |
19 #endif | 19 #endif |
20 | 20 |
21 GrGLInterface::GrGLInterface() { | 21 GrGLInterface::GrGLInterface() { |
22 fBindingsExported = kNone_GrGLBinding; | 22 fStandard = kNone_GrGLStandard; |
23 | 23 |
24 #if GR_GL_PER_GL_FUNC_CALLBACK | 24 #if GR_GL_PER_GL_FUNC_CALLBACK |
25 fCallback = GrGLDefaultInterfaceCallback; | 25 fCallback = GrGLDefaultInterfaceCallback; |
26 fCallbackData = 0; | 26 fCallbackData = 0; |
27 #endif | 27 #endif |
28 } | 28 } |
29 | 29 |
30 bool GrGLInterface::validate(GrGLBinding binding) const { | 30 bool GrGLInterface::validate() const { |
31 | 31 |
32 // kNone must be 0 so that the check we're about to do can never succeed if | 32 if (kNone_GrGLStandard == fStandard) { |
33 // binding == kNone. | |
34 GR_STATIC_ASSERT(kNone_GrGLBinding == 0); | |
35 | |
36 if (0 == (binding & fBindingsExported)) { | |
37 return false; | 33 return false; |
38 } | 34 } |
39 | 35 |
40 GrGLExtensions extensions; | 36 GrGLExtensions extensions; |
41 if (!extensions.init(binding, this)) { | 37 if (!extensions.init(this)) { |
42 return false; | 38 return false; |
43 } | 39 } |
44 | 40 |
45 // functions that are always required | 41 // functions that are always required |
46 if (NULL == fActiveTexture || | 42 if (NULL == fActiveTexture || |
47 NULL == fAttachShader || | 43 NULL == fAttachShader || |
48 NULL == fBindAttribLocation || | 44 NULL == fBindAttribLocation || |
49 NULL == fBindBuffer || | 45 NULL == fBindBuffer || |
50 NULL == fBindTexture || | 46 NULL == fBindTexture || |
51 NULL == fBlendFunc || | 47 NULL == fBlendFunc || |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 NULL == fGetRenderbufferParameteriv || | 130 NULL == fGetRenderbufferParameteriv || |
135 NULL == fGenFramebuffers || | 131 NULL == fGenFramebuffers || |
136 NULL == fGenRenderbuffers || | 132 NULL == fGenRenderbuffers || |
137 NULL == fRenderbufferStorage) { | 133 NULL == fRenderbufferStorage) { |
138 return false; | 134 return false; |
139 } | 135 } |
140 | 136 |
141 GrGLVersion glVer = GrGLGetVersion(this); | 137 GrGLVersion glVer = GrGLGetVersion(this); |
142 | 138 |
143 bool isCoreProfile = false; | 139 bool isCoreProfile = false; |
144 if (kDesktop_GrGLBinding == binding && glVer >= GR_GL_VER(3,2)) { | 140 if (kGL_GrGLStandard == fStandard && glVer >= GR_GL_VER(3,2)) { |
145 GrGLint profileMask; | 141 GrGLint profileMask; |
146 GR_GL_GetIntegerv(this, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); | 142 GR_GL_GetIntegerv(this, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); |
147 isCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); | 143 isCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); |
148 } | 144 } |
149 | 145 |
150 // Now check that baseline ES/Desktop fns not covered above are present | 146 // Now check that baseline ES/Desktop fns not covered above are present |
151 // and that we have fn pointers for any advertised extensions that we will | 147 // and that we have fn pointers for any advertised extensions that we will |
152 // try to use. | 148 // try to use. |
153 | 149 |
154 // these functions are part of ES2, we assume they are available | 150 // these functions are part of ES2, we assume they are available |
155 // On the desktop we assume they are available if the extension | 151 // On the desktop we assume they are available if the extension |
156 // is present or GL version is high enough. | 152 // is present or GL version is high enough. |
157 if (kES_GrGLBinding == binding) { | 153 if (kGLES_GrGLStandard == fStandard) { |
158 if (NULL == fStencilFuncSeparate || | 154 if (NULL == fStencilFuncSeparate || |
159 NULL == fStencilMaskSeparate || | 155 NULL == fStencilMaskSeparate || |
160 NULL == fStencilOpSeparate) { | 156 NULL == fStencilOpSeparate) { |
161 return false; | 157 return false; |
162 } | 158 } |
163 } else if (kDesktop_GrGLBinding == binding) { | 159 } else if (kGL_GrGLStandard == fStandard) { |
164 | 160 |
165 if (glVer >= GR_GL_VER(2,0)) { | 161 if (glVer >= GR_GL_VER(2,0)) { |
166 if (NULL == fStencilFuncSeparate || | 162 if (NULL == fStencilFuncSeparate || |
167 NULL == fStencilMaskSeparate || | 163 NULL == fStencilMaskSeparate || |
168 NULL == fStencilOpSeparate) { | 164 NULL == fStencilOpSeparate) { |
169 return false; | 165 return false; |
170 } | 166 } |
171 } | 167 } |
172 if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) { | 168 if (glVer >= GR_GL_VER(3,0) && NULL == fBindFragDataLocation) { |
173 return false; | 169 return false; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 NULL == fIsPointInFillPath || | 261 NULL == fIsPointInFillPath || |
266 NULL == fIsPointInStrokePath || | 262 NULL == fIsPointInStrokePath || |
267 NULL == fGetPathLength || | 263 NULL == fGetPathLength || |
268 NULL == fPointAlongPath) { | 264 NULL == fPointAlongPath) { |
269 return false; | 265 return false; |
270 } | 266 } |
271 } | 267 } |
272 } | 268 } |
273 | 269 |
274 // optional function on desktop before 1.3 | 270 // optional function on desktop before 1.3 |
275 if (kDesktop_GrGLBinding != binding || | 271 if (kGL_GrGLStandard != fStandard || |
276 (glVer >= GR_GL_VER(1,3)) || | 272 (glVer >= GR_GL_VER(1,3)) || |
277 extensions.has("GL_ARB_texture_compression")) { | 273 extensions.has("GL_ARB_texture_compression")) { |
278 if (NULL == fCompressedTexImage2D) { | 274 if (NULL == fCompressedTexImage2D) { |
279 return false; | 275 return false; |
280 } | 276 } |
281 } | 277 } |
282 | 278 |
283 // part of desktop GL, but not ES | 279 // part of desktop GL, but not ES |
284 if (kDesktop_GrGLBinding == binding && | 280 if (kGL_GrGLStandard == fStandard && |
285 (NULL == fGetTexLevelParameteriv || | 281 (NULL == fGetTexLevelParameteriv || |
286 NULL == fDrawBuffer || | 282 NULL == fDrawBuffer || |
287 NULL == fReadBuffer)) { | 283 NULL == fReadBuffer)) { |
288 return false; | 284 return false; |
289 } | 285 } |
290 | 286 |
291 // GL_EXT_texture_storage is part of desktop 4.2 | 287 // GL_EXT_texture_storage is part of desktop 4.2 |
292 // There is a desktop ARB extension and an ES+desktop EXT extension | 288 // There is a desktop ARB extension and an ES+desktop EXT extension |
293 if (kDesktop_GrGLBinding == binding) { | 289 if (kGL_GrGLStandard == fStandard) { |
294 if (glVer >= GR_GL_VER(4,2) || | 290 if (glVer >= GR_GL_VER(4,2) || |
295 extensions.has("GL_ARB_texture_storage") || | 291 extensions.has("GL_ARB_texture_storage") || |
296 extensions.has("GL_EXT_texture_storage")) { | 292 extensions.has("GL_EXT_texture_storage")) { |
297 if (NULL == fTexStorage2D) { | 293 if (NULL == fTexStorage2D) { |
298 return false; | 294 return false; |
299 } | 295 } |
300 } | 296 } |
301 } else if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_EXT_texture_storage
")) { | 297 } else if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_EXT_texture_storage
")) { |
302 if (NULL == fTexStorage2D) { | 298 if (NULL == fTexStorage2D) { |
303 return false; | 299 return false; |
304 } | 300 } |
305 } | 301 } |
306 | 302 |
307 if (extensions.has("GL_EXT_discard_framebuffer")) { | 303 if (extensions.has("GL_EXT_discard_framebuffer")) { |
308 // FIXME: Remove this once Chromium is updated to provide this function | 304 // FIXME: Remove this once Chromium is updated to provide this function |
309 #if 0 | 305 #if 0 |
310 if (NULL == fDiscardFramebuffer) { | 306 if (NULL == fDiscardFramebuffer) { |
311 return false; | 307 return false; |
312 } | 308 } |
313 #endif | 309 #endif |
314 } | 310 } |
315 | 311 |
316 // FBO MSAA | 312 // FBO MSAA |
317 if (kDesktop_GrGLBinding == binding) { | 313 if (kGL_GrGLStandard == fStandard) { |
318 // GL 3.0 and the ARB extension have multisample + blit | 314 // GL 3.0 and the ARB extension have multisample + blit |
319 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object
")) { | 315 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_ARB_framebuffer_object
")) { |
320 if (NULL == fRenderbufferStorageMultisample || | 316 if (NULL == fRenderbufferStorageMultisample || |
321 NULL == fBlitFramebuffer) { | 317 NULL == fBlitFramebuffer) { |
322 return false; | 318 return false; |
323 } | 319 } |
324 } else { | 320 } else { |
325 if (extensions.has("GL_EXT_framebuffer_blit") && | 321 if (extensions.has("GL_EXT_framebuffer_blit") && |
326 NULL == fBlitFramebuffer) { | 322 NULL == fBlitFramebuffer) { |
327 return false; | 323 return false; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 NULL == fFramebufferTexture2DMultisample) { | 365 NULL == fFramebufferTexture2DMultisample) { |
370 return false; | 366 return false; |
371 } | 367 } |
372 } | 368 } |
373 #endif | 369 #endif |
374 } | 370 } |
375 | 371 |
376 // On ES buffer mapping is an extension. On Desktop | 372 // On ES buffer mapping is an extension. On Desktop |
377 // buffer mapping was part of original VBO extension | 373 // buffer mapping was part of original VBO extension |
378 // which we require. | 374 // which we require. |
379 if (kDesktop_GrGLBinding == binding || extensions.has("GL_OES_mapbuffer")) { | 375 if (kGL_GrGLStandard == fStandard || extensions.has("GL_OES_mapbuffer")) { |
380 if (NULL == fMapBuffer || | 376 if (NULL == fMapBuffer || |
381 NULL == fUnmapBuffer) { | 377 NULL == fUnmapBuffer) { |
382 return false; | 378 return false; |
383 } | 379 } |
384 } | 380 } |
385 | 381 |
386 // Dual source blending | 382 // Dual source blending |
387 if (kDesktop_GrGLBinding == binding && | 383 if (kGL_GrGLStandard == fStandard && |
388 (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended")
)) { | 384 (glVer >= GR_GL_VER(3,3) || extensions.has("GL_ARB_blend_func_extended")
)) { |
389 if (NULL == fBindFragDataLocationIndexed) { | 385 if (NULL == fBindFragDataLocationIndexed) { |
390 return false; | 386 return false; |
391 } | 387 } |
392 } | 388 } |
393 | 389 |
394 // glGetStringi was added in version 3.0 of both desktop and ES. | 390 // glGetStringi was added in version 3.0 of both desktop and ES. |
395 if (glVer >= GR_GL_VER(3, 0)) { | 391 if (glVer >= GR_GL_VER(3, 0)) { |
396 if (NULL == fGetStringi) { | 392 if (NULL == fGetStringi) { |
397 return false; | 393 return false; |
398 } | 394 } |
399 } | 395 } |
400 | 396 |
401 if (kDesktop_GrGLBinding == binding) { | 397 if (kGL_GrGLStandard == fStandard) { |
402 if (glVer >= GR_GL_VER(3, 0) || extensions.has("GL_ARB_vertex_array_obje
ct")) { | 398 if (glVer >= GR_GL_VER(3, 0) || extensions.has("GL_ARB_vertex_array_obje
ct")) { |
403 if (NULL == fBindVertexArray || | 399 if (NULL == fBindVertexArray || |
404 NULL == fDeleteVertexArrays || | 400 NULL == fDeleteVertexArrays || |
405 NULL == fGenVertexArrays) { | 401 NULL == fGenVertexArrays) { |
406 return false; | 402 return false; |
407 } | 403 } |
408 } | 404 } |
409 } else { | 405 } else { |
410 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_OES_vertex_array_objec
t")) { | 406 if (glVer >= GR_GL_VER(3,0) || extensions.has("GL_OES_vertex_array_objec
t")) { |
411 if (NULL == fBindVertexArray || | 407 if (NULL == fBindVertexArray || |
412 NULL == fDeleteVertexArrays || | 408 NULL == fDeleteVertexArrays || |
413 NULL == fGenVertexArrays) { | 409 NULL == fGenVertexArrays) { |
414 return false; | 410 return false; |
415 } | 411 } |
416 } | 412 } |
417 } | 413 } |
418 | 414 |
419 return true; | 415 return true; |
420 } | 416 } |
OLD | NEW |