OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "gl/GrGLExtensions.h" |
| 9 #include "gl/GrGLDefines.h" |
| 10 #include "gl/GrGLUtil.h" |
| 11 |
| 12 bool GrGLExtensions::init(GrGLBinding binding, |
| 13 GrGLGetStringProc getString, |
| 14 GrGLGetStringiProc getStringi, |
| 15 GrGLGetIntegervProc getIntegerv) { |
| 16 fStrings.reset(); |
| 17 if (NULL == getString) { |
| 18 return false; |
| 19 } |
| 20 bool indexed = false; |
| 21 if (kDesktop_GrGLBinding == binding) { |
| 22 const GrGLubyte* verString = getString(GR_GL_VERSION); |
| 23 if (NULL == verString) { |
| 24 return false; |
| 25 } |
| 26 GrGLVersion version = GrGLGetVersionFromString((const char*) verString); |
| 27 indexed = version >= GR_GL_VER(3, 0); |
| 28 } |
| 29 if (indexed) { |
| 30 if (NULL == getStringi || NULL == getIntegerv) { |
| 31 return false; |
| 32 } |
| 33 GrGLint extensionCnt = 0; |
| 34 getIntegerv(GR_GL_NUM_EXTENSIONS, &extensionCnt); |
| 35 fStrings.push_back_n(extensionCnt); |
| 36 for (int i = 0; i < extensionCnt; ++i) { |
| 37 const char* ext = (const char*) getStringi(GR_GL_EXTENSIONS, i); |
| 38 fStrings[i] = ext; |
| 39 } |
| 40 } else { |
| 41 const char* extensions = (const char*) getString(GR_GL_EXTENSIONS); |
| 42 if (NULL == extensions) { |
| 43 return false; |
| 44 } |
| 45 // First count the extensions so that we don't cause the array to malloc
multiple times. |
| 46 int extensionCnt = 1; |
| 47 const char* e = (const char*) extensions; |
| 48 while (NULL != (e = strchr(e+1, ' '))) { |
| 49 e += 1; |
| 50 ++extensionCnt; |
| 51 } |
| 52 fStrings.push_back_n(extensionCnt); |
| 53 |
| 54 int i = 0; |
| 55 while (true) { |
| 56 size_t length = strcspn(extensions, " "); |
| 57 GrAssert(i < extensionCnt); |
| 58 fStrings[i].set(extensions, length); |
| 59 ++i; |
| 60 if ('\0' == extensions[length]) { |
| 61 break; |
| 62 } |
| 63 extensions += length + 1; |
| 64 } |
| 65 GrAssert(i == extensionCnt); |
| 66 } |
| 67 return true; |
| 68 } |
| 69 |
| 70 bool GrGLExtensions::has(const char* ext) const { |
| 71 // TODO: Sort the extensions and binary search. |
| 72 int count = fStrings.count(); |
| 73 for (int i = 0; i < count; ++i) { |
| 74 if (fStrings[i].equals(ext)) { |
| 75 return true; |
| 76 } |
| 77 } |
| 78 return false; |
| 79 } |
OLD | NEW |