Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: src/gpu/gl/GrGLExtensions.cpp

Issue 12316141: Sort GL extension strings and search to find. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkTSort.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "SkTSort.h"
14
15 namespace {
16 inline int extension_compare(const SkString* a, const SkString* b) {
17 return strcmp(a->c_str(), b->c_str());
18 }
19 }
20
12 bool GrGLExtensions::init(GrGLBinding binding, 21 bool GrGLExtensions::init(GrGLBinding binding,
13 GrGLGetStringProc getString, 22 GrGLGetStringProc getString,
14 GrGLGetStringiProc getStringi, 23 GrGLGetStringiProc getStringi,
15 GrGLGetIntegervProc getIntegerv) { 24 GrGLGetIntegervProc getIntegerv) {
16 fStrings.reset(); 25 fStrings.reset();
17 if (NULL == getString) { 26 if (NULL == getString) {
18 return false; 27 return false;
19 } 28 }
20 bool indexed = false; 29 bool indexed = false;
21 if (kDesktop_GrGLBinding == binding) { 30 if (kDesktop_GrGLBinding == binding) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 GrAssert(i < extensionCnt); 66 GrAssert(i < extensionCnt);
58 fStrings[i].set(extensions, length); 67 fStrings[i].set(extensions, length);
59 ++i; 68 ++i;
60 if ('\0' == extensions[length]) { 69 if ('\0' == extensions[length]) {
61 break; 70 break;
62 } 71 }
63 extensions += length + 1; 72 extensions += length + 1;
64 } 73 }
65 GrAssert(i == extensionCnt); 74 GrAssert(i == extensionCnt);
66 } 75 }
76 SkTSearchCompareLTFunctor<SkString, extension_compare> cmp;
77 SkTQSort(&fStrings.front(), &fStrings.back(), cmp);
67 return true; 78 return true;
68 } 79 }
69 80
70 bool GrGLExtensions::has(const char* ext) const { 81 bool GrGLExtensions::has(const char* ext) const {
71 // TODO: Sort the extensions and binary search. 82 SkString extensionStr(ext);
72 int count = fStrings.count(); 83 int idx = SkTSearch<SkString, extension_compare>(&fStrings.front(),
73 for (int i = 0; i < count; ++i) { 84 fStrings.count(),
74 if (fStrings[i].equals(ext)) { 85 extensionStr,
75 return true; 86 sizeof(SkString));
76 } 87 return idx >= 0;
77 }
78 return false;
79 } 88 }
OLDNEW
« no previous file with comments | « src/core/SkTSort.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698