Flutter Engine
 
Loading...
Searching...
No Matches
mock_vulkan.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_TEST_MOCK_VULKAN_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_TEST_MOCK_VULKAN_H_
7
8#include <functional>
9#include <memory>
10#include <string>
11#include <vector>
12
15#include "vulkan/vulkan_core.h"
16#include "vulkan/vulkan_enums.hpp"
17
18namespace impeller {
19namespace testing {
20
21std::shared_ptr<std::vector<std::string>> GetMockVulkanFunctions(
22 VkDevice device);
23
24// A test-controlled version of |vk::Fence|.
25class MockFence final {
26 public:
27 MockFence() = default;
28
29 // Returns the result that was set in the constructor or |SetStatus|.
30 VkResult GetStatus() { return static_cast<VkResult>(result_.load()); }
31
32 // Sets the result that will be returned by `GetFenceStatus`.
33 void SetStatus(vk::Result result) { result_ = result; }
34
35 // Sets the result that will be returned by `GetFenceStatus`.
36 static void SetStatus(vk::UniqueFence& fence, vk::Result result) {
37 // Cast the fence to a MockFence and set the result.
38 VkFence raw_fence = fence.get();
39 MockFence* mock_fence = reinterpret_cast<MockFence*>(raw_fence);
40 mock_fence->SetStatus(result);
41 }
42
43 // Gets a raw pointer to manipulate the fence after it's been moved.
44 static MockFence* GetRawPointer(vk::UniqueFence& fence) {
45 // Cast the fence to a MockFence and get the result.
46 VkFence raw_fence = fence.get();
47 MockFence* mock_fence = reinterpret_cast<MockFence*>(raw_fence);
48 return mock_fence;
49 }
50
51 private:
52 std::atomic<vk::Result> result_ = vk::Result::eSuccess;
53
54 MockFence(const MockFence&) = delete;
55
56 MockFence& operator=(const MockFence&) = delete;
57};
58
60 public:
62
63 //------------------------------------------------------------------------------
64 /// @brief Create a Vulkan context with Vulkan functions mocked. The
65 /// caller is given a chance to tinker on the settings right
66 /// before a context is created.
67 ///
68 /// @return A context if one can be created.
69 ///
70 std::shared_ptr<ContextVK> Build();
71
72 /// A callback that allows the modification of the ContextVK::Settings before
73 /// the context is made.
75 const std::function<void(ContextVK::Settings&)>& settings_callback) {
76 settings_callback_ = settings_callback;
77 return *this;
78 }
79
81 const std::vector<std::string>& instance_extensions) {
82 instance_extensions_ = instance_extensions;
83 return *this;
84 }
85
87 const std::vector<std::string>& instance_layers) {
88 instance_layers_ = instance_layers;
89 return *this;
90 }
91
92 /// Set the behavior of vkGetPhysicalDeviceFormatProperties, which needs to
93 /// respond differently for different formats.
95 std::function<void(VkPhysicalDevice physicalDevice,
96 VkFormat format,
97 VkFormatProperties* pFormatProperties)>
98 format_properties_callback) {
99 format_properties_callback_ = std::move(format_properties_callback);
100 return *this;
101 }
102
104 std::function<void(VkPhysicalDevice device,
105 VkPhysicalDeviceProperties* physicalProperties)>
106 physical_properties_callback) {
107 physical_properties_callback_ = std::move(physical_properties_callback);
108 return *this;
109 }
110
112 const ContextVK::EmbedderData& embedder_data) {
113 embedder_data_ = embedder_data;
114 return *this;
115 }
116
117 private:
118 std::function<void(ContextVK::Settings&)> settings_callback_;
119 std::vector<std::string> instance_extensions_;
120 std::vector<std::string> instance_layers_;
121 std::optional<ContextVK::EmbedderData> embedder_data_;
122 std::function<void(VkPhysicalDevice physicalDevice,
123 VkFormat format,
124 VkFormatProperties* pFormatProperties)>
125 format_properties_callback_;
126 std::function<void(VkPhysicalDevice device,
127 VkPhysicalDeviceProperties* physicalProperties)>
128 physical_properties_callback_;
129};
130
131/// @brief Override the image size returned by all swapchain images.
133
134std::vector<VkImageMemoryBarrier>& GetImageMemoryBarriers(
135 VkCommandBuffer buffer);
136
137} // namespace testing
138} // namespace impeller
139
140#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_TEST_MOCK_VULKAN_H_
void SetStatus(vk::Result result)
Definition mock_vulkan.h:33
static MockFence * GetRawPointer(vk::UniqueFence &fence)
Definition mock_vulkan.h:44
static void SetStatus(vk::UniqueFence &fence, vk::Result result)
Definition mock_vulkan.h:36
MockVulkanContextBuilder & SetPhysicalPropertiesCallback(std::function< void(VkPhysicalDevice device, VkPhysicalDeviceProperties *physicalProperties)> physical_properties_callback)
MockVulkanContextBuilder SetEmbedderData(const ContextVK::EmbedderData &embedder_data)
std::shared_ptr< ContextVK > Build()
Create a Vulkan context with Vulkan functions mocked. The caller is given a chance to tinker on the s...
MockVulkanContextBuilder & SetInstanceExtensions(const std::vector< std::string > &instance_extensions)
Definition mock_vulkan.h:80
MockVulkanContextBuilder & SetInstanceLayers(const std::vector< std::string > &instance_layers)
Definition mock_vulkan.h:86
MockVulkanContextBuilder & SetPhysicalDeviceFormatPropertiesCallback(std::function< void(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties *pFormatProperties)> format_properties_callback)
Definition mock_vulkan.h:94
MockVulkanContextBuilder & SetSettingsCallback(const std::function< void(ContextVK::Settings &)> &settings_callback)
Definition mock_vulkan.h:74
VkDevice device
Definition main.cc:69
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
std::shared_ptr< std::vector< std::string > > GetMockVulkanFunctions(VkDevice device)
std::vector< VkImageMemoryBarrier > & GetImageMemoryBarriers(VkCommandBuffer buffer)
void SetSwapchainImageSize(ISize size)
Override the image size returned by all swapchain images.