jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 "vk/GrVkExtensions.h" |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame^] | 9 | |
| 10 | // Can remove this once we get rid of the extension flags. |
| 11 | #include "vk/GrVkBackendContext.h" |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 12 | |
| 13 | #include "SkTSearch.h" |
| 14 | #include "SkTSort.h" |
| 15 | |
| 16 | namespace { // This cannot be static because it is used as a template parameter. |
| 17 | inline bool extension_compare(const SkString& a, const SkString& b) { |
| 18 | return strcmp(a.c_str(), b.c_str()) < 0; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | // finds the index of ext in strings or a negative result if ext is not found. |
| 23 | static int find_string(const SkTArray<SkString>& strings, const char ext[]) { |
| 24 | if (strings.empty()) { |
| 25 | return -1; |
| 26 | } |
| 27 | SkString extensionStr(ext); |
| 28 | int idx = SkTSearch<SkString, extension_compare>(&strings.front(), |
| 29 | strings.count(), |
| 30 | extensionStr, |
| 31 | sizeof(SkString)); |
| 32 | return idx; |
| 33 | } |
| 34 | |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame^] | 35 | void GrVkExtensions::init(uint32_t instanceExtensionCount, |
| 36 | const char* const* instanceExtensions, |
| 37 | uint32_t deviceExtensionCount, |
| 38 | const char* const* deviceExtensions) { |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 39 | SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 40 | |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame^] | 41 | for (uint32_t i = 0; i < instanceExtensionCount; ++i) { |
| 42 | const char* extension = instanceExtensions[i]; |
| 43 | // if not already in the list, add it |
| 44 | if (find_string(fExtensionStrings, extension) < 0) { |
| 45 | fExtensionStrings.push_back() = extension; |
| 46 | SkTQSort(&fExtensionStrings.front(), &fExtensionStrings.back(), cmp); |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame^] | 49 | for (uint32_t i = 0; i < deviceExtensionCount; ++i) { |
| 50 | const char* extension = deviceExtensions[i]; |
| 51 | // if not already in the list, add it |
| 52 | if (find_string(fExtensionStrings, extension) < 0) { |
| 53 | fExtensionStrings.push_back() = extension; |
| 54 | SkTQSort(&fExtensionStrings.front(), &fExtensionStrings.back(), cmp); |
Greg Daniel | dc13c21 | 2018-06-28 23:29:35 +0000 | [diff] [blame] | 55 | } |
Greg Daniel | dc13c21 | 2018-06-28 23:29:35 +0000 | [diff] [blame] | 56 | } |
jvanverth | fd7bd45 | 2016-03-25 06:29:52 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame^] | 59 | bool GrVkExtensions::hasExtension(const char ext[]) const { |
| 60 | return find_string(fExtensionStrings, ext) >= 0; |
jvanverth | d2497f3 | 2016-03-18 12:39:05 -0700 | [diff] [blame] | 61 | } |
| 62 | |