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 { // This cannot be static because it is used as a template parameter. | 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 // finds the index of ext in strings or a negative result if ext is not found. | |
22 static int find_string(const SkTArray<SkString>& strings, const char ext[]) { | |
23 if (strings.empty()) { | |
24 return -1; | |
25 } | |
26 SkString extensionStr(ext); | |
27 int idx = SkTSearch<SkString, extension_compare>(&strings.front(), | |
28 strings.count(), | |
29 extensionStr, | |
30 sizeof(SkString)); | |
31 return idx; | |
32 } | |
33 | |
34 GrGLExtensions::GrGLExtensions(const GrGLExtensions& that) : fStrings(SkNEW(SkTA
rray<SkString>)) { | |
35 *this = that; | |
36 } | |
37 | |
38 GrGLExtensions& GrGLExtensions::operator=(const GrGLExtensions& that) { | |
39 *fStrings = *that.fStrings; | |
40 fInitialized = that.fInitialized; | |
41 return *this; | |
42 } | |
43 | |
44 bool GrGLExtensions::init(GrGLStandard standard, | 21 bool GrGLExtensions::init(GrGLStandard standard, |
45 GrGLGetStringProc getString, | 22 GrGLGetStringProc getString, |
46 GrGLGetStringiProc getStringi, | 23 GrGLGetStringiProc getStringi, |
47 GrGLGetIntegervProc getIntegerv) { | 24 GrGLGetIntegervProc getIntegerv) { |
48 fInitialized = false; | 25 fInitialized = false; |
49 fStrings->reset(); | 26 fStrings->reset(); |
50 | 27 |
51 if (NULL == getString) { | 28 if (NULL == getString) { |
52 return false; | 29 return false; |
53 } | 30 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 69 } |
93 } | 70 } |
94 if (!fStrings->empty()) { | 71 if (!fStrings->empty()) { |
95 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; | 72 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
96 SkTQSort(&fStrings->front(), &fStrings->back(), cmp); | 73 SkTQSort(&fStrings->front(), &fStrings->back(), cmp); |
97 } | 74 } |
98 fInitialized = true; | 75 fInitialized = true; |
99 return true; | 76 return true; |
100 } | 77 } |
101 | 78 |
102 bool GrGLExtensions::has(const char ext[]) const { | 79 bool GrGLExtensions::has(const char* ext) const { |
103 SkASSERT(fInitialized); | 80 if (fStrings->empty()) { |
104 return find_string(*fStrings, ext) >= 0; | |
105 } | |
106 | |
107 bool GrGLExtensions::remove(const char ext[]) { | |
108 SkASSERT(fInitialized); | |
109 int idx = find_string(*fStrings, ext); | |
110 if (idx >= 0) { | |
111 // This is not terribly effecient but we really only expect this functio
n to be called at | |
112 // most a handful of times when our test programs start. | |
113 SkAutoTDelete< SkTArray<SkString> > oldStrings(fStrings.detach()); | |
114 fStrings.reset(SkNEW(SkTArray<SkString>(oldStrings->count() - 1))); | |
115 fStrings->push_back_n(idx, &oldStrings->front()); | |
116 fStrings->push_back_n(oldStrings->count() - idx - 1, &(*oldStrings)[idx]
+ 1); | |
117 return true; | |
118 } else { | |
119 return false; | 81 return false; |
120 } | 82 } |
| 83 SkString extensionStr(ext); |
| 84 int idx = SkTSearch<SkString, extension_compare>(&fStrings->front(), |
| 85 fStrings->count(), |
| 86 extensionStr, |
| 87 sizeof(SkString)); |
| 88 return idx >= 0; |
121 } | 89 } |
122 | 90 |
123 void GrGLExtensions::print(const char* sep) const { | 91 void GrGLExtensions::print(const char* sep) const { |
124 if (NULL == sep) { | 92 if (NULL == sep) { |
125 sep = " "; | 93 sep = " "; |
126 } | 94 } |
127 int cnt = fStrings->count(); | 95 int cnt = fStrings->count(); |
128 for (int i = 0; i < cnt; ++i) { | 96 for (int i = 0; i < cnt; ++i) { |
129 GrPrintf("%s%s", (*fStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); | 97 GrPrintf("%s%s", (*fStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); |
130 } | 98 } |
131 } | 99 } |
OLD | NEW |