OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrGLAssembleInterface.h" | 10 #include "GrGLAssembleInterface.h" |
11 #include "GrGLUtil.h" | 11 #include "GrGLUtil.h" |
12 | 12 |
13 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) | 13 #define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F) |
14 #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "
gl" #F #S) | 14 #define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "
gl" #F #S) |
15 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl
" #F) | 15 #define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl
" #F) |
16 | 16 |
| 17 #define GET_EGL_PROC_SUFFIX(F, S) functions->f ## F = (GrEGL ## F ## Proc) get(c
tx, "egl" #F #S) |
| 18 |
17 const GrGLInterface* GrGLAssembleInterface(void* ctx, GrGLGetProc get) { | 19 const GrGLInterface* GrGLAssembleInterface(void* ctx, GrGLGetProc get) { |
18 GET_PROC_LOCAL(GetString); | 20 GET_PROC_LOCAL(GetString); |
19 if (nullptr == GetString) { | 21 if (nullptr == GetString) { |
20 return nullptr; | 22 return nullptr; |
21 } | 23 } |
22 | 24 |
23 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION))
; | 25 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION))
; |
24 if (nullptr == verStr) { | 26 if (nullptr == verStr) { |
25 return nullptr; | 27 return nullptr; |
26 } | 28 } |
27 | 29 |
28 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr); | 30 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr); |
29 | 31 |
30 if (kGLES_GrGLStandard == standard) { | 32 if (kGLES_GrGLStandard == standard) { |
31 return GrGLAssembleGLESInterface(ctx, get); | 33 return GrGLAssembleGLESInterface(ctx, get); |
32 } else if (kGL_GrGLStandard == standard) { | 34 } else if (kGL_GrGLStandard == standard) { |
33 return GrGLAssembleGLInterface(ctx, get); | 35 return GrGLAssembleGLInterface(ctx, get); |
34 } | 36 } |
35 return nullptr; | 37 return nullptr; |
36 } | 38 } |
37 | 39 |
| 40 static void get_egl_query_and_display(GrEGLQueryStringProc* queryString, GrEGLDi
splay* display, |
| 41 void* ctx, GrGLGetProc get) { |
| 42 *queryString = (GrEGLQueryStringProc) get(ctx, "eglQueryString"); |
| 43 *display = GR_EGL_NO_DISPLAY; |
| 44 if (*queryString) { |
| 45 GrEGLGetCurrentDisplayProc getCurrentDisplay = |
| 46 (GrEGLGetCurrentDisplayProc) get(ctx, "eglGetCurrentDisplay"); |
| 47 if (getCurrentDisplay) { |
| 48 *display = getCurrentDisplay(); |
| 49 } else { |
| 50 *queryString = nullptr; |
| 51 } |
| 52 } |
| 53 } |
| 54 |
38 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { | 55 const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { |
39 GET_PROC_LOCAL(GetString); | 56 GET_PROC_LOCAL(GetString); |
40 GET_PROC_LOCAL(GetStringi); | 57 GET_PROC_LOCAL(GetStringi); |
41 GET_PROC_LOCAL(GetIntegerv); | 58 GET_PROC_LOCAL(GetIntegerv); |
42 | 59 |
43 // GetStringi may be nullptr depending on the GL version. | 60 // GetStringi may be nullptr depending on the GL version. |
44 if (nullptr == GetString || nullptr == GetIntegerv) { | 61 if (nullptr == GetString || nullptr == GetIntegerv) { |
45 return nullptr; | 62 return nullptr; |
46 } | 63 } |
47 | 64 |
48 const char* versionString = (const char*) GetString(GR_GL_VERSION); | 65 const char* versionString = (const char*) GetString(GR_GL_VERSION); |
49 GrGLVersion glVer = GrGLGetVersionFromString(versionString); | 66 GrGLVersion glVer = GrGLGetVersionFromString(versionString); |
50 | 67 |
51 if (glVer < GR_GL_VER(1,5) || GR_GL_INVALID_VER == glVer) { | 68 if (glVer < GR_GL_VER(1,5) || GR_GL_INVALID_VER == glVer) { |
52 // We must have array and element_array buffer objects. | 69 // We must have array and element_array buffer objects. |
53 return nullptr; | 70 return nullptr; |
54 } | 71 } |
55 | 72 |
| 73 GrEGLQueryStringProc queryString; |
| 74 GrEGLDisplay display; |
| 75 get_egl_query_and_display(&queryString, &display, ctx, get); |
56 GrGLExtensions extensions; | 76 GrGLExtensions extensions; |
57 if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv))
{ | 77 if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv, q
ueryString, |
| 78 display)) { |
58 return nullptr; | 79 return nullptr; |
59 } | 80 } |
60 | 81 |
61 GrGLInterface* interface = new GrGLInterface(); | 82 GrGLInterface* interface = new GrGLInterface(); |
62 GrGLInterface::Functions* functions = &interface->fFunctions; | 83 GrGLInterface::Functions* functions = &interface->fFunctions; |
63 | 84 |
64 GET_PROC(ActiveTexture); | 85 GET_PROC(ActiveTexture); |
65 GET_PROC(AttachShader); | 86 GET_PROC(AttachShader); |
66 GET_PROC(BindAttribLocation); | 87 GET_PROC(BindAttribLocation); |
67 GET_PROC(BindBuffer); | 88 GET_PROC(BindBuffer); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // KHR_debug defines these methods to have no suffix in an OpenGL (not E
S) context. | 484 // KHR_debug defines these methods to have no suffix in an OpenGL (not E
S) context. |
464 GET_PROC(DebugMessageControl); | 485 GET_PROC(DebugMessageControl); |
465 GET_PROC(DebugMessageInsert); | 486 GET_PROC(DebugMessageInsert); |
466 GET_PROC(DebugMessageCallback); | 487 GET_PROC(DebugMessageCallback); |
467 GET_PROC(GetDebugMessageLog); | 488 GET_PROC(GetDebugMessageLog); |
468 GET_PROC(PushDebugGroup); | 489 GET_PROC(PushDebugGroup); |
469 GET_PROC(PopDebugGroup); | 490 GET_PROC(PopDebugGroup); |
470 GET_PROC(ObjectLabel); | 491 GET_PROC(ObjectLabel); |
471 } | 492 } |
472 | 493 |
| 494 if (extensions.has("EGL_KHR_image") || extensions.has("EGL_KHR_image_base"))
{ |
| 495 GET_EGL_PROC_SUFFIX(CreateImage, KHR); |
| 496 GET_EGL_PROC_SUFFIX(DestroyImage, KHR); |
| 497 } |
| 498 |
473 interface->fStandard = kGL_GrGLStandard; | 499 interface->fStandard = kGL_GrGLStandard; |
474 interface->fExtensions.swap(&extensions); | 500 interface->fExtensions.swap(&extensions); |
475 | 501 |
476 return interface; | 502 return interface; |
477 } | 503 } |
478 | 504 |
479 const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) { | 505 const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) { |
480 GET_PROC_LOCAL(GetString); | 506 GET_PROC_LOCAL(GetString); |
481 if (nullptr == GetString) { | 507 if (nullptr == GetString) { |
482 return nullptr; | 508 return nullptr; |
483 } | 509 } |
484 | 510 |
485 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION))
; | 511 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION))
; |
486 GrGLVersion version = GrGLGetVersionFromString(verStr); | 512 GrGLVersion version = GrGLGetVersionFromString(verStr); |
487 | 513 |
488 if (version < GR_GL_VER(2,0)) { | 514 if (version < GR_GL_VER(2,0)) { |
489 return nullptr; | 515 return nullptr; |
490 } | 516 } |
491 | 517 |
492 GET_PROC_LOCAL(GetIntegerv); | 518 GET_PROC_LOCAL(GetIntegerv); |
493 GET_PROC_LOCAL(GetStringi); | 519 GET_PROC_LOCAL(GetStringi); |
| 520 GrEGLQueryStringProc queryString; |
| 521 GrEGLDisplay display; |
| 522 get_egl_query_and_display(&queryString, &display, ctx, get); |
494 GrGLExtensions extensions; | 523 GrGLExtensions extensions; |
495 if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv)
) { | 524 if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv,
queryString, |
| 525 display)) { |
496 return nullptr; | 526 return nullptr; |
497 } | 527 } |
498 | 528 |
499 GrGLInterface* interface = new GrGLInterface; | 529 GrGLInterface* interface = new GrGLInterface; |
500 GrGLInterface::Functions* functions = &interface->fFunctions; | 530 GrGLInterface::Functions* functions = &interface->fFunctions; |
501 | 531 |
502 GET_PROC(ActiveTexture); | 532 GET_PROC(ActiveTexture); |
503 GET_PROC(AttachShader); | 533 GET_PROC(AttachShader); |
504 GET_PROC(BindAttribLocation); | 534 GET_PROC(BindAttribLocation); |
505 GET_PROC(BindBuffer); | 535 GET_PROC(BindBuffer); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 // APITRACE. | 802 // APITRACE. |
773 if (!interface->fFunctions.fDebugMessageControl) { | 803 if (!interface->fFunctions.fDebugMessageControl) { |
774 extensions.remove("GL_KHR_debug"); | 804 extensions.remove("GL_KHR_debug"); |
775 } | 805 } |
776 } | 806 } |
777 | 807 |
778 if (extensions.has("GL_CHROMIUM_bind_uniform_location")) { | 808 if (extensions.has("GL_CHROMIUM_bind_uniform_location")) { |
779 GET_PROC_SUFFIX(BindUniformLocation, CHROMIUM); | 809 GET_PROC_SUFFIX(BindUniformLocation, CHROMIUM); |
780 } | 810 } |
781 | 811 |
| 812 if (extensions.has("EGL_KHR_image") || extensions.has("EGL_KHR_image_base"))
{ |
| 813 GET_EGL_PROC_SUFFIX(CreateImage, KHR); |
| 814 GET_EGL_PROC_SUFFIX(DestroyImage, KHR); |
| 815 } |
| 816 |
782 interface->fStandard = kGLES_GrGLStandard; | 817 interface->fStandard = kGLES_GrGLStandard; |
783 interface->fExtensions.swap(&extensions); | 818 interface->fExtensions.swap(&extensions); |
784 | 819 |
785 return interface; | 820 return interface; |
786 } | 821 } |
OLD | NEW |