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 int 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()); | 17 return strcmp(a.c_str(), b.c_str()) < 0; |
18 } | 18 } |
19 } | 19 } |
20 | 20 |
21 bool GrGLExtensions::init(GrGLBinding binding, | 21 bool GrGLExtensions::init(GrGLBinding binding, |
22 GrGLGetStringProc getString, | 22 GrGLGetStringProc getString, |
23 GrGLGetStringiProc getStringi, | 23 GrGLGetStringiProc getStringi, |
24 GrGLGetIntegervProc getIntegerv) { | 24 GrGLGetIntegervProc getIntegerv) { |
25 fStrings.reset(); | 25 fStrings.reset(); |
26 if (NULL == getString) { | 26 if (NULL == getString) { |
27 return false; | 27 return false; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 if ('\0' == *extensions) { | 60 if ('\0' == *extensions) { |
61 break; | 61 break; |
62 } | 62 } |
63 // we found an extension | 63 // we found an extension |
64 size_t length = strcspn(extensions, " "); | 64 size_t length = strcspn(extensions, " "); |
65 fStrings.push_back().set(extensions, length); | 65 fStrings.push_back().set(extensions, length); |
66 extensions += length; | 66 extensions += length; |
67 } | 67 } |
68 } | 68 } |
69 if (0 != fStrings.count()) { | 69 if (0 != fStrings.count()) { |
70 SkTSearchCompareLTFunctor<SkString, extension_compare> cmp; | 70 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
71 SkTQSort(&fStrings.front(), &fStrings.back(), cmp); | 71 SkTQSort(&fStrings.front(), &fStrings.back(), cmp); |
72 } | 72 } |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 bool GrGLExtensions::has(const char* ext) const { | 76 bool GrGLExtensions::has(const char* ext) const { |
77 SkString extensionStr(ext); | 77 SkString extensionStr(ext); |
78 int idx = SkTSearch<SkString, extension_compare>(&fStrings.front(), | 78 int idx = SkTSearch<SkString, extension_compare>(&fStrings.front(), |
79 fStrings.count(), | 79 fStrings.count(), |
80 extensionStr, | 80 extensionStr, |
81 sizeof(SkString)); | 81 sizeof(SkString)); |
82 return idx >= 0; | 82 return idx >= 0; |
83 } | 83 } |
84 | 84 |
85 void GrGLExtensions::print(const char* sep) const { | 85 void GrGLExtensions::print(const char* sep) const { |
86 if (NULL == sep) { | 86 if (NULL == sep) { |
87 sep = " "; | 87 sep = " "; |
88 } | 88 } |
89 int cnt = fStrings.count(); | 89 int cnt = fStrings.count(); |
90 for (int i = 0; i < cnt; ++i) { | 90 for (int i = 0; i < cnt; ++i) { |
91 GrPrintf("%s%s", fStrings[i].c_str(), (i < cnt - 1) ? sep : ""); | 91 GrPrintf("%s%s", fStrings[i].c_str(), (i < cnt - 1) ? sep : ""); |
92 } | 92 } |
93 } | 93 } |
OLD | NEW |