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 { // This cannot be static because it is used as a template parameter. |
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 | |
robertphillips
2014/01/22 20:12:06
remove space between '=' and '('?
bsalomon
2014/01/23 16:16:09
Done.
| |
38 GrGLExtensions& GrGLExtensions::operator= (const GrGLExtensions& that) { | |
39 *fStrings = *that.fStrings; | |
40 fInitialized = that.fInitialized; | |
41 return *this; | |
42 } | |
43 | |
21 bool GrGLExtensions::init(GrGLStandard standard, | 44 bool GrGLExtensions::init(GrGLStandard standard, |
22 GrGLGetStringProc getString, | 45 GrGLGetStringProc getString, |
23 GrGLGetStringiProc getStringi, | 46 GrGLGetStringiProc getStringi, |
24 GrGLGetIntegervProc getIntegerv) { | 47 GrGLGetIntegervProc getIntegerv) { |
25 fInitialized = false; | 48 fInitialized = false; |
26 fStrings->reset(); | 49 fStrings->reset(); |
27 | 50 |
28 if (NULL == getString) { | 51 if (NULL == getString) { |
29 return false; | 52 return false; |
30 } | 53 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 } | 92 } |
70 } | 93 } |
71 if (!fStrings->empty()) { | 94 if (!fStrings->empty()) { |
72 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; | 95 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
73 SkTQSort(&fStrings->front(), &fStrings->back(), cmp); | 96 SkTQSort(&fStrings->front(), &fStrings->back(), cmp); |
74 } | 97 } |
75 fInitialized = true; | 98 fInitialized = true; |
76 return true; | 99 return true; |
77 } | 100 } |
78 | 101 |
79 bool GrGLExtensions::has(const char* ext) const { | 102 bool GrGLExtensions::has(const char ext[]) const { |
80 if (fStrings->empty()) { | 103 SkASSERT(fInitialized); |
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 { | |
81 return false; | 119 return false; |
82 } | 120 } |
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; | |
89 } | 121 } |
90 | 122 |
91 void GrGLExtensions::print(const char* sep) const { | 123 void GrGLExtensions::print(const char* sep) const { |
92 if (NULL == sep) { | 124 if (NULL == sep) { |
93 sep = " "; | 125 sep = " "; |
94 } | 126 } |
95 int cnt = fStrings->count(); | 127 int cnt = fStrings->count(); |
96 for (int i = 0; i < cnt; ++i) { | 128 for (int i = 0; i < cnt; ++i) { |
97 GrPrintf("%s%s", (*fStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); | 129 GrPrintf("%s%s", (*fStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); |
98 } | 130 } |
99 } | 131 } |
OLD | NEW |