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 "SkMakeUnique.h" |
12 #include "SkTSearch.h" | 13 #include "SkTSearch.h" |
13 #include "SkTSort.h" | 14 #include "SkTSort.h" |
14 | 15 |
15 namespace { // This cannot be static because it is used as a template parameter. | 16 namespace { // This cannot be static because it is used as a template parameter. |
16 inline bool extension_compare(const SkString& a, const SkString& b) { | 17 inline bool extension_compare(const SkString& a, const SkString& b) { |
17 return strcmp(a.c_str(), b.c_str()) < 0; | 18 return strcmp(a.c_str(), b.c_str()) < 0; |
18 } | 19 } |
19 } | 20 } |
20 | 21 |
21 // finds the index of ext in strings or a negative result if ext is not found. | 22 // finds the index of ext in strings or a negative result if ext is not found. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 fStrings->push_back_n(extensionCnt); | 93 fStrings->push_back_n(extensionCnt); |
93 for (int i = 0; i < extensionCnt; ++i) { | 94 for (int i = 0; i < extensionCnt; ++i) { |
94 const char* ext = (const char*) getStringi(GR_GL_EXTENSIONS, i); | 95 const char* ext = (const char*) getStringi(GR_GL_EXTENSIONS, i); |
95 (*fStrings)[i] = ext; | 96 (*fStrings)[i] = ext; |
96 } | 97 } |
97 } else { | 98 } else { |
98 const char* extensions = (const char*) getString(GR_GL_EXTENSIONS); | 99 const char* extensions = (const char*) getString(GR_GL_EXTENSIONS); |
99 if (!extensions) { | 100 if (!extensions) { |
100 return false; | 101 return false; |
101 } | 102 } |
102 eat_space_sep_strings(fStrings, extensions); | 103 eat_space_sep_strings(fStrings.get(), extensions); |
103 } | 104 } |
104 if (queryString) { | 105 if (queryString) { |
105 const char* extensions = queryString(eglDisplay, GR_EGL_EXTENSIONS); | 106 const char* extensions = queryString(eglDisplay, GR_EGL_EXTENSIONS); |
106 | 107 |
107 eat_space_sep_strings(fStrings, extensions); | 108 eat_space_sep_strings(fStrings.get(), extensions); |
108 } | 109 } |
109 if (!fStrings->empty()) { | 110 if (!fStrings->empty()) { |
110 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; | 111 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
111 SkTQSort(&fStrings->front(), &fStrings->back(), cmp); | 112 SkTQSort(&fStrings->front(), &fStrings->back(), cmp); |
112 } | 113 } |
113 fInitialized = true; | 114 fInitialized = true; |
114 return true; | 115 return true; |
115 } | 116 } |
116 | 117 |
117 bool GrGLExtensions::has(const char ext[]) const { | 118 bool GrGLExtensions::has(const char ext[]) const { |
118 SkASSERT(fInitialized); | 119 SkASSERT(fInitialized); |
119 return find_string(*fStrings, ext) >= 0; | 120 return find_string(*fStrings, ext) >= 0; |
120 } | 121 } |
121 | 122 |
122 bool GrGLExtensions::remove(const char ext[]) { | 123 bool GrGLExtensions::remove(const char ext[]) { |
123 SkASSERT(fInitialized); | 124 SkASSERT(fInitialized); |
124 int idx = find_string(*fStrings, ext); | 125 int idx = find_string(*fStrings, ext); |
125 if (idx >= 0) { | 126 if (idx < 0) { |
126 // This is not terribly effecient but we really only expect this functio
n to be called at | |
127 // most a handful of times when our test programs start. | |
128 SkAutoTDelete< SkTArray<SkString> > oldStrings(fStrings.release()); | |
129 fStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1)); | |
130 fStrings->push_back_n(idx, &oldStrings->front()); | |
131 fStrings->push_back_n(oldStrings->count() - idx - 1, &(*oldStrings)[idx]
+ 1); | |
132 return true; | |
133 } else { | |
134 return false; | 127 return false; |
135 } | 128 } |
| 129 |
| 130 // This is not terribly effecient but we really only expect this function to
be called at |
| 131 // most a handful of times when our test programs start. |
| 132 fStrings->removeShuffle(idx); |
| 133 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
| 134 SkTInsertionSort(&(fStrings->operator[](idx)), &fStrings->back(), cmp); |
| 135 return true; |
136 } | 136 } |
137 | 137 |
138 void GrGLExtensions::add(const char ext[]) { | 138 void GrGLExtensions::add(const char ext[]) { |
139 int idx = find_string(*fStrings, ext); | 139 int idx = find_string(*fStrings, ext); |
140 if (idx < 0) { | 140 if (idx < 0) { |
141 // This is not the most effecient approach since we end up doing a full
sort of the | 141 // This is not the most effecient approach since we end up looking at al
l of the |
142 // extensions after the add | 142 // extensions after the add |
143 fStrings->push_back().set(ext); | 143 fStrings->emplace_back(ext); |
144 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; | 144 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
145 SkTQSort(&fStrings->front(), &fStrings->back(), cmp); | 145 SkTInsertionSort(&fStrings->front(), &fStrings->back(), cmp); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 void GrGLExtensions::print(const char* sep) const { | 149 void GrGLExtensions::print(const char* sep) const { |
150 if (nullptr == sep) { | 150 if (nullptr == sep) { |
151 sep = " "; | 151 sep = " "; |
152 } | 152 } |
153 int cnt = fStrings->count(); | 153 int cnt = fStrings->count(); |
154 for (int i = 0; i < cnt; ++i) { | 154 for (int i = 0; i < cnt; ++i) { |
155 SkDebugf("%s%s", (*fStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); | 155 SkDebugf("%s%s", (*fStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); |
156 } | 156 } |
157 } | 157 } |
OLD | NEW |