1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "gpu/config/vulkan_info.h"
6 
7 #include "gpu/ipc/common/vulkan_info.mojom.h"
8 #include "gpu/ipc/common/vulkan_info_mojom_traits.h"
9 
10 namespace gpu {
11 
12 VulkanPhysicalDeviceInfo::VulkanPhysicalDeviceInfo() = default;
13 VulkanPhysicalDeviceInfo::VulkanPhysicalDeviceInfo(
14     const VulkanPhysicalDeviceInfo& other) = default;
15 VulkanPhysicalDeviceInfo::~VulkanPhysicalDeviceInfo() = default;
16 VulkanPhysicalDeviceInfo& VulkanPhysicalDeviceInfo::operator=(
17     const VulkanPhysicalDeviceInfo& info) = default;
18 
19 VulkanInfo::VulkanInfo() = default;
20 VulkanInfo::~VulkanInfo() = default;
21 
VulkanInfo(const VulkanInfo & other)22 VulkanInfo::VulkanInfo(const VulkanInfo& other) {
23   *this = other;
24 }
25 
operator =(const VulkanInfo & other)26 VulkanInfo& VulkanInfo::operator=(const VulkanInfo& other) {
27   api_version = other.api_version;
28   used_api_version = other.used_api_version;
29   instance_extensions = other.instance_extensions;
30   instance_layers = other.instance_layers;
31   physical_devices = other.physical_devices;
32   SetEnabledInstanceExtensions(other.enabled_instance_extensions);
33   return *this;
34 }
35 
Serialize() const36 std::vector<uint8_t> VulkanInfo::Serialize() const {
37   return gpu::mojom::VulkanInfo::Serialize(this);
38 }
39 
SetEnabledInstanceExtensions(const std::vector<const char * > & extensions)40 void VulkanInfo::SetEnabledInstanceExtensions(
41     const std::vector<const char*>& extensions) {
42   enabled_instance_extensions.clear();
43   for (const auto* const extension : extensions) {
44     bool found = false;
45     for (const auto& instance_extension : instance_extensions) {
46       if (strcmp(extension, instance_extension.extensionName) == 0) {
47         enabled_instance_extensions.push_back(instance_extension.extensionName);
48         found = true;
49         break;
50       }
51     }
52     if (!found) {
53       LOG(ERROR) << "The enabled extension '" << extension
54                  << "' is not in instance_extensions!";
55     }
56   }
57 }
58 
SetEnabledInstanceExtensions(const std::vector<base::StringPiece> & extensions)59 void VulkanInfo::SetEnabledInstanceExtensions(
60     const std::vector<base::StringPiece>& extensions) {
61   enabled_instance_extensions.clear();
62   for (const auto& extension : extensions) {
63     bool found = false;
64     for (const auto& instance_extension : instance_extensions) {
65       if (extension == instance_extension.extensionName) {
66         enabled_instance_extensions.push_back(instance_extension.extensionName);
67         found = true;
68         break;
69       }
70     }
71     if (!found) {
72       LOG(ERROR) << "The enabled extension '" << extension
73                  << "' is not in instance_extensions!";
74     }
75   }
76 }
77 
78 }  // namespace gpu
79