util: add class for storing extensions strings
[platform/core/uifw/vulkan-wsi-tizen.git] / util / extension_list.hpp
1 /*
2  * Copyright (c) 2019, 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #pragma once
25
26 #include "util/custom_allocator.hpp"
27
28 #include <vector>
29 #include <algorithm>
30
31 #include <vulkan/vulkan.h>
32 #include <vulkan/vk_layer.h>
33
34 namespace util
35 {
36
37 class extension_list
38 {
39 public:
40    extension_list(const util::allocator& allocator);
41
42    extension_list(const extension_list &rhs) = delete;
43    const extension_list &operator=(const extension_list &rhs) = delete;
44
45    /**
46     * @brief Obtain a vector of #VkExtensionProperties equivalent to this extension_list object.
47     */
48    const util::vector<VkExtensionProperties> &get_extension_props() const
49    {
50       return m_ext_props;
51    }
52
53    /**
54     * @brief Get the allocator used to manage the memory of this object.
55     */
56    const util::allocator get_allocator() const
57    {
58       return m_alloc;
59    }
60
61    /**
62     * @brief Append pointers to extension strings to the given vector.
63     *
64     * @warning Pointers in the vector are referring to string allocated in this extension_list and will become invalid
65     * if the extension_list is modified (e.g. by adding/removing elements.)
66     *
67     * @param[out] out A vector of C strings to which all extension are appended.
68     *
69     * @return A boolean indicating whether the operation was successful. If this is @c false, then @p out is
70     * unmodified.
71     */
72    bool get_extension_strings(util::vector<const char*> &out) const;
73
74    bool contains(const extension_list &req) const;
75    bool contains(const char *ext) const;
76    void remove(const char *ext);
77    VkResult add(const char *ext);
78    VkResult add(VkExtensionProperties ext_prop);
79    VkResult add(const char **ext_list, uint32_t count);
80    VkResult add(const extension_list &ext_list);
81    VkResult add(const struct VkEnumerateInstanceExtensionPropertiesChain *chain);
82    VkResult add(PFN_vkEnumerateInstanceExtensionProperties fpEnumerateInstanceExtensionProperties);
83    VkResult add(VkPhysicalDevice dev);
84    VkResult add(const char *const *extensions, uint32_t count);
85    VkResult add(const VkExtensionProperties *props, uint32_t count);
86
87 private:
88    util::allocator m_alloc;
89    util::vector<VkExtensionProperties> m_ext_props;
90 };
91 } // namespace util