Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
gpu_surface_vulkan_impeller_unittests.cc
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#include <vulkan/vulkan.h>
6
11#include "gtest/gtest.h"
12#include "impeller/entity/vk/entity_shaders_vk.h"
13#include "impeller/entity/vk/framebuffer_blend_shaders_vk.h"
14#include "impeller/entity/vk/modern_shaders_vk.h"
16
17namespace flutter {
18namespace testing {
19
20std::vector<std::shared_ptr<fml::Mapping>> ShaderLibraryMappings() {
21 return {
22 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
23 impeller_entity_shaders_vk_length),
24 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_vk_data,
25 impeller_modern_shaders_vk_length),
26 std::make_shared<fml::NonOwnedMapping>(
27 impeller_framebuffer_blend_shaders_vk_data,
28 impeller_framebuffer_blend_shaders_vk_length),
29 };
30}
31
33 public:
35 : vk_(fml::MakeRefCounted<vulkan::VulkanProcTable>(
36 vkGetInstanceProcAddr)),
37 test_context_(fml::MakeRefCounted<TestVulkanContext>()) {}
38
39 const vulkan::VulkanProcTable& vk() override { return *vk_; }
40
42 if (!test_surface_ || surface_size_ != size) {
43 test_surface_ = TestVulkanSurface::Create(*test_context_, size);
44 surface_size_ = size;
45 }
46
47 return {
48 .struct_size = sizeof(FlutterVulkanImage),
49 .image = test_surface_
50 ? reinterpret_cast<uint64_t>(test_surface_->GetImage())
51 : 0u,
52 .format = VK_FORMAT_R8G8B8A8_UNORM,
53 };
54 }
55
56 bool PresentImage(VkImage image, VkFormat format) override { return true; }
57
58 private:
61 std::unique_ptr<TestVulkanSurface> test_surface_;
62 DlISize surface_size_ = {};
63};
64
65TEST(GPUSurfaceVulkanImpeller, DisposesThreadLocalResources) {
66 impeller::ContextVK::Settings context_settings;
67 context_settings.proc_address_callback = vkGetInstanceProcAddr;
69 auto context = impeller::ContextVK::Create(std::move(context_settings));
70
72
73 std::unique_ptr<Surface> surface =
74 std::make_unique<GPUSurfaceVulkanImpeller>(&delegate, context);
75
76 // Add a command pool to the global map.
77 auto pool = context->GetCommandPoolRecycler()->Get();
79
80 // Check that AcquireFrame disposes thread local resources and removes
81 // the pool from the global map.
82 auto frame = surface->AcquireFrame(DlISize(100, 100));
84}
85
86TEST(GPUSurfaceVulkanImpeller, RecreatesTransientsWhenFrameSizeChanges) {
87 impeller::ContextVK::Settings context_settings;
88 context_settings.proc_address_callback = vkGetInstanceProcAddr;
90 auto context = impeller::ContextVK::Create(std::move(context_settings));
91
93
94 auto surface = std::make_unique<GPUSurfaceVulkanImpeller>(&delegate, context);
95
96 auto frame = surface->AcquireFrame(DlISize(100, 100));
97 ASSERT_NE(frame, nullptr);
98 auto transients = surface->transients_;
99 ASSERT_NE(transients, nullptr);
100 EXPECT_EQ(surface->transients_size_, impeller::ISize(100, 100));
101
102 frame = surface->AcquireFrame(DlISize(100, 100));
103 ASSERT_NE(frame, nullptr);
104 EXPECT_EQ(surface->transients_, transients);
105 EXPECT_EQ(surface->transients_size_, impeller::ISize(100, 100));
106
107 frame = surface->AcquireFrame(DlISize(200, 100));
108 ASSERT_NE(frame, nullptr);
109 EXPECT_NE(surface->transients_, transients);
110 EXPECT_EQ(surface->transients_size_, impeller::ISize(200, 100));
111}
112
113} // namespace testing
114} // namespace flutter
Interface implemented by all platform surfaces that can present a Vulkan backing store to the "screen...
const vulkan::VulkanProcTable & vk() override
Obtain a reference to the Vulkan implementation's proc table.
FlutterVulkanImage AcquireImage(const DlISize &size) override
Called by the engine to fetch a VkImage for writing the next frame.
bool PresentImage(VkImage image, VkFormat format) override
Called by the engine once a frame has been rendered to the image and it's ready to be bound for furth...
static std::unique_ptr< TestVulkanSurface > Create(const TestVulkanContext &context, const DlISize &surface_size)
static int GetGlobalPoolCount(const ContextVK &context)
static std::shared_ptr< ContextVK > Create(Settings settings)
FlutterVulkanImage * image
VkSurfaceKHR surface
Definition main.cc:65
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappings()
TEST(NativeAssetsManagerTest, NoAvailableAssets)
impeller::ISize32 DlISize
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::vector< std::shared_ptr< fml::Mapping > > shader_libraries_data
Definition context_vk.h:81
PFN_vkGetInstanceProcAddr proc_address_callback
Definition context_vk.h:80