OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "gl/GrGLExtensions.h" | 8 #include "gl/GrGLExtensions.h" |
9 #include "gl/GrGLDefines.h" | 9 #include "gl/GrGLDefines.h" |
10 #include "gl/GrGLUtil.h" | 10 #include "gl/GrGLUtil.h" |
11 | 11 |
12 #include "SkTSearch.h" | 12 #include "SkTSearch.h" |
13 #include "SkTSort.h" | 13 #include "SkTSort.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 inline bool extension_compare(const SkString& a, const SkString& b) { | 16 inline bool extension_compare(const SkString& a, const SkString& b) { |
17 return strcmp(a.c_str(), b.c_str()) < 0; | 17 return strcmp(a.c_str(), b.c_str()) < 0; |
18 } | 18 } |
19 } | 19 } |
20 | 20 |
21 bool GrGLExtensions::init(GrGLStandard standard, | 21 bool GrGLExtensions::init(GrGLStandard standard, |
22 GrGLGetStringProc getString, | 22 GrGLGetStringProc getString, |
23 GrGLGetStringiProc getStringi, | 23 GrGLGetStringiProc getStringi, |
24 GrGLGetIntegervProc getIntegerv) { | 24 GrGLGetIntegervProc getIntegerv) { |
25 fStrings.reset(); | 25 fInitialized = false; |
| 26 fStrings->reset(); |
| 27 |
26 if (NULL == getString) { | 28 if (NULL == getString) { |
27 return false; | 29 return false; |
28 } | 30 } |
29 | 31 |
30 // glGetStringi and indexed extensions were added in version 3.0 of desktop
GL and ES. | 32 // glGetStringi and indexed extensions were added in version 3.0 of desktop
GL and ES. |
31 const GrGLubyte* verString = getString(GR_GL_VERSION); | 33 const GrGLubyte* verString = getString(GR_GL_VERSION); |
32 if (NULL == verString) { | 34 if (NULL == verString) { |
33 return false; | 35 return false; |
34 } | 36 } |
35 GrGLVersion version = GrGLGetVersionFromString((const char*) verString); | 37 GrGLVersion version = GrGLGetVersionFromString((const char*) verString); |
36 bool indexed = version >= GR_GL_VER(3, 0); | 38 bool indexed = version >= GR_GL_VER(3, 0); |
37 | 39 |
38 if (indexed) { | 40 if (indexed) { |
39 if (NULL == getStringi || NULL == getIntegerv) { | 41 if (NULL == getStringi || NULL == getIntegerv) { |
40 return false; | 42 return false; |
41 } | 43 } |
42 GrGLint extensionCnt = 0; | 44 GrGLint extensionCnt = 0; |
43 getIntegerv(GR_GL_NUM_EXTENSIONS, &extensionCnt); | 45 getIntegerv(GR_GL_NUM_EXTENSIONS, &extensionCnt); |
44 fStrings.push_back_n(extensionCnt); | 46 fStrings->push_back_n(extensionCnt); |
45 for (int i = 0; i < extensionCnt; ++i) { | 47 for (int i = 0; i < extensionCnt; ++i) { |
46 const char* ext = (const char*) getStringi(GR_GL_EXTENSIONS, i); | 48 const char* ext = (const char*) getStringi(GR_GL_EXTENSIONS, i); |
47 fStrings[i] = ext; | 49 (*fStrings)[i] = ext; |
48 } | 50 } |
49 } else { | 51 } else { |
50 const char* extensions = (const char*) getString(GR_GL_EXTENSIONS); | 52 const char* extensions = (const char*) getString(GR_GL_EXTENSIONS); |
51 if (NULL == extensions) { | 53 if (NULL == extensions) { |
52 return false; | 54 return false; |
53 } | 55 } |
54 while (true) { | 56 while (true) { |
55 // skip over multiple spaces between extensions | 57 // skip over multiple spaces between extensions |
56 while (' ' == *extensions) { | 58 while (' ' == *extensions) { |
57 ++extensions; | 59 ++extensions; |
58 } | 60 } |
59 // quit once we reach the end of the string. | 61 // quit once we reach the end of the string. |
60 if ('\0' == *extensions) { | 62 if ('\0' == *extensions) { |
61 break; | 63 break; |
62 } | 64 } |
63 // we found an extension | 65 // we found an extension |
64 size_t length = strcspn(extensions, " "); | 66 size_t length = strcspn(extensions, " "); |
65 fStrings.push_back().set(extensions, length); | 67 fStrings->push_back().set(extensions, length); |
66 extensions += length; | 68 extensions += length; |
67 } | 69 } |
68 } | 70 } |
69 if (!fStrings.empty()) { | 71 if (!fStrings->empty()) { |
70 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; | 72 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
71 SkTQSort(&fStrings.front(), &fStrings.back(), cmp); | 73 SkTQSort(&fStrings->front(), &fStrings->back(), cmp); |
72 } | 74 } |
| 75 fInitialized = true; |
73 return true; | 76 return true; |
74 } | 77 } |
75 | 78 |
76 bool GrGLExtensions::has(const char* ext) const { | 79 bool GrGLExtensions::has(const char* ext) const { |
77 if (fStrings.empty()) { | 80 if (fStrings->empty()) { |
78 return false; | 81 return false; |
79 } | 82 } |
80 SkString extensionStr(ext); | 83 SkString extensionStr(ext); |
81 int idx = SkTSearch<SkString, extension_compare>(&fStrings.front(), | 84 int idx = SkTSearch<SkString, extension_compare>(&fStrings->front(), |
82 fStrings.count(), | 85 fStrings->count(), |
83 extensionStr, | 86 extensionStr, |
84 sizeof(SkString)); | 87 sizeof(SkString)); |
85 return idx >= 0; | 88 return idx >= 0; |
86 } | 89 } |
87 | 90 |
88 void GrGLExtensions::print(const char* sep) const { | 91 void GrGLExtensions::print(const char* sep) const { |
89 if (NULL == sep) { | 92 if (NULL == sep) { |
90 sep = " "; | 93 sep = " "; |
91 } | 94 } |
92 int cnt = fStrings.count(); | 95 int cnt = fStrings->count(); |
93 for (int i = 0; i < cnt; ++i) { | 96 for (int i = 0; i < cnt; ++i) { |
94 GrPrintf("%s%s", fStrings[i].c_str(), (i < cnt - 1) ? sep : ""); | 97 GrPrintf("%s%s", (*fStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); |
95 } | 98 } |
96 } | 99 } |
OLD | NEW |