Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
ahb_texture_source_vk_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
6#include <memory>
7
9#include "gtest/gtest.h"
17
19
22
24 static AHardwareBuffer* InvalidValue() { return nullptr; }
25 static bool IsValid(AHardwareBuffer* value) { return value != nullptr; }
26 static void Free(AHardwareBuffer* value) { ::AHardwareBuffer_release(value); }
27};
28
31
33 const AHardwareBuffer_Desc& desc) {
34 AHardwareBuffer* buffer = nullptr;
35 EXPECT_EQ(AHardwareBuffer_allocate(&desc, &buffer), 0);
36 return UniqueAHardwareBuffer(buffer);
37}
38
39// Set up context.
40std::shared_ptr<ContextVK> CreateContext() {
41 auto vulkan_dylib = fml::NativeLibrary::Create("libvulkan.so");
42 auto instance_proc_addr =
43 vulkan_dylib->ResolveFunction<PFN_vkGetInstanceProcAddr>(
44 "vkGetInstanceProcAddr");
45
46 if (!instance_proc_addr.has_value()) {
47 VALIDATION_LOG << "Could not setup Vulkan proc table.";
48 return nullptr;
49 }
50
52 settings.proc_address_callback = instance_proc_addr.value();
53 settings.shader_libraries_data = {};
54 settings.enable_validation = false;
55 settings.enable_gpu_tracing = false;
56 settings.enable_surface_control = false;
57
58 return ContextVK::Create(std::move(settings));
59}
60
61TEST(AndroidVulkanTest, CanImportRGBA) {
63 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
64 }
65
67 desc.size = ISize{1, 1};
70
71 auto ahb = std::make_unique<HardwareBuffer>(desc);
72 ASSERT_TRUE(ahb);
73 auto context_vk = CreateContext();
74 ASSERT_TRUE(context_vk);
75
76 AHBTextureSourceVK source(context_vk, std::move(ahb),
77 /*is_swapchain_image=*/false);
78
79 EXPECT_TRUE(source.IsValid());
80 EXPECT_EQ(source.GetYUVConversion(), nullptr);
81
82 context_vk->Shutdown();
83}
84
85TEST(AndroidVulkanTest, CanImportWithYUB) {
87 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
88 }
89
90 AHardwareBuffer_Desc desc;
91 desc.width = 16;
92 desc.height = 16;
93 desc.format = AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420;
94 desc.stride = 0;
95 desc.layers = 1;
96 desc.rfu0 = 0;
97 desc.rfu1 = 0;
98 desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
99 AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK |
100 AHARDWAREBUFFER_USAGE_CPU_READ_MASK;
101
102 EXPECT_EQ(AHardwareBuffer_isSupported(&desc), 1);
103
105 ASSERT_TRUE(buffer.is_valid());
106
107 auto context_vk = CreateContext();
108 ASSERT_TRUE(context_vk);
109
110 AHBTextureSourceVK source(context_vk, buffer.get(), desc);
111
112 EXPECT_TRUE(source.IsValid());
113 EXPECT_NE(source.GetYUVConversion(), nullptr);
114
115 context_vk->Shutdown();
116}
117
118TEST(AndroidVulkanTest, CreateImageViewForOpaqueAlpha) {
120 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
121 }
122
123 AHardwareBuffer_Desc desc;
124 desc.width = 16;
125 desc.height = 16;
126 desc.format = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
127 desc.stride = 0;
128 desc.layers = 1;
129 desc.rfu0 = 0;
130 desc.rfu1 = 0;
131 desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
132 AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK |
133 AHARDWAREBUFFER_USAGE_CPU_READ_MASK;
134
135 EXPECT_EQ(AHardwareBuffer_isSupported(&desc), 1);
136
138 ASSERT_TRUE(buffer.is_valid());
139
140 auto context_vk = CreateContext();
141 ASSERT_TRUE(context_vk);
142
144 ASSERT_EQ(context_vk->GetDevice().getAndroidHardwareBufferPropertiesANDROID(
145 buffer.get(), &ahb_props.get()),
146 vk::Result::eSuccess);
147
149 context_vk->GetDevice(), ahb_props, desc);
150 ASSERT_TRUE(image);
151
153 image.get(), nullptr, ahb_props, desc);
154
155 EXPECT_EQ(image_info.get().components.a, vk::ComponentSwizzle::eOne);
156
157 context_vk->Shutdown();
158}
159
160TEST(AndroidVulkanTest, TextureSourceDeleteAfterContextDelete) {
161 AHardwareBuffer_Desc desc;
162 desc.width = 16;
163 desc.height = 16;
164 desc.format = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
165 desc.stride = 0;
166 desc.layers = 1;
167 desc.rfu0 = 0;
168 desc.rfu1 = 0;
169 desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
170 AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK |
171 AHARDWAREBUFFER_USAGE_CPU_READ_MASK;
172
173 EXPECT_EQ(AHardwareBuffer_isSupported(&desc), 1);
174
176 ASSERT_TRUE(buffer.is_valid());
177
180 .Build();
181
182 ASSERT_TRUE(context);
183
184 auto texture =
185 std::make_shared<AHBTextureSourceVK>(context, buffer.get(), desc);
186 ASSERT_TRUE(texture->IsValid());
187
188 // Delete the context and its VkDevice.
189 context.reset();
190
191 // Delete the AHBTextureSourceVK and verify that the destructor does not call
192 // Vulkan APIs on a VkDevice that is no longer valid.
193 texture.reset();
194}
195
196} // namespace impeller::android::testing
static fml::RefPtr< NativeLibrary > Create(const char *path)
A texture source that wraps an instance of AHardwareBuffer.
static vk::UniqueImage CreateVKImageWrapperForAndroidHarwareBuffer(const vk::Device &device, const AHBProperties &ahb_props, const AHardwareBuffer_Desc &ahb_desc)
Create a VkImage that wraps an Android hardware buffer.
std::shared_ptr< YUVConversionVK > GetYUVConversion() const override
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
vk::StructureChain< vk::AndroidHardwareBufferPropertiesANDROID, vk::AndroidHardwareBufferFormatPropertiesANDROID > AHBProperties
static ImageViewInfo CreateImageViewInfo(const vk::Image &image, const std::shared_ptr< YUVConversionVK > &yuv_conversion_wrapper, const AHBProperties &ahb_props, const AHardwareBuffer_Desc &ahb_desc)
static std::shared_ptr< ContextVK > Create(Settings settings)
MockVulkanContextBuilder & SetDeviceExtensions(const std::vector< std::string > &device_extensions)
Definition mock_vulkan.h:92
std::shared_ptr< ContextVK > Build()
Create a Vulkan context with Vulkan functions mocked. The caller is given a chance to tinker on the s...
int32_t value
FlutterVulkanImage * image
FlTexture * texture
std::shared_ptr< ContextVK > CreateContext()
TEST(AndroidAHBSwapchainTest, AHBSwapchainNoFenceWaitAfterAcquireNextImageFailure)
fml::UniqueObject< AHardwareBuffer *, UniqueAHardwareBufferTraits > UniqueAHardwareBuffer
UniqueAHardwareBuffer AllocateAHardwareBuffer(const AHardwareBuffer_Desc &desc)
const std::vector< std::string > kAndroidDeviceExtensions
std::shared_ptr< std::vector< std::string > > GetMockVulkanFunctions(VkDevice device)
std::shared_ptr< ContextGLES > context
std::vector< std::shared_ptr< fml::Mapping > > shader_libraries_data
Definition context_vk.h:85
PFN_vkGetInstanceProcAddr proc_address_callback
Definition context_vk.h:84
A descriptor use to specify hardware buffer allocations.
#define VALIDATION_LOG
Definition validation.h:91