Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::android::testing Namespace Reference

Classes

class  FakeSurfaceControl
 
struct  UniqueAHardwareBufferTraits
 

Typedefs

using UniqueAHardwareBuffer = fml::UniqueObject< AHardwareBuffer *, UniqueAHardwareBufferTraits >
 

Functions

 TEST (AndroidAHBSwapchainTest, AHBSwapchainNoFenceWaitAfterAcquireNextImageFailure)
 
UniqueAHardwareBuffer AllocateAHardwareBuffer (const AHardwareBuffer_Desc &desc)
 
std::shared_ptr< ContextVKCreateContext ()
 
 TEST (AndroidVulkanTest, CanImportRGBA)
 
 TEST (AndroidVulkanTest, CanImportWithYUB)
 
 TEST (AndroidVulkanTest, CreateImageViewForOpaqueAlpha)
 
 FML_TEST_CLASS (AndroidAHBSwapchainTest, AHBSwapchainNoFenceWaitAfterAcquireNextImageFailure)
 
 TEST (ToolkitAndroidTest, CanCreateProcTable)
 
 TEST (ToolkitAndroidTest, GuardsAgainstZeroSizedDescriptors)
 
 TEST (ToolkitAndroidTest, CanCreateHardwareBuffer)
 
 TEST (ToolkitAndroidTest, CanGetHardwareBufferIDs)
 
 TEST (ToolkitAndroidTest, HardwareBufferNullIDIfAPIUnavailable)
 
 TEST (ToolkitAndroidTest, CanDescribeHardwareBufferHandles)
 
 TEST (ToolkitAndroidTest, CanApplySurfaceTransaction)
 
 TEST (ToolkitAndroidTest, SurfacControlsAreAvailable)
 
 TEST (ToolkitAndroidTest, ChoreographerIsAvailable)
 
 TEST (ToolkitAndroidTest, CanPostAndNotWaitForFrameCallbacks)
 
 TEST (ToolkitAndroidTest, CanPostAndWaitForFrameCallbacks)
 

Variables

const std::vector< std::string > kAndroidDeviceExtensions
 

Typedef Documentation

◆ UniqueAHardwareBuffer

Function Documentation

◆ AllocateAHardwareBuffer()

UniqueAHardwareBuffer impeller::android::testing::AllocateAHardwareBuffer ( const AHardwareBuffer_Desc &  desc)

Definition at line 27 of file ahb_texture_source_vk_unittests.cc.

28 {
29 AHardwareBuffer* buffer = nullptr;
30 EXPECT_EQ(AHardwareBuffer_allocate(&desc, &buffer), 0);
31 return UniqueAHardwareBuffer(buffer);
32}

Referenced by TEST(), and TEST().

◆ CreateContext()

std::shared_ptr< ContextVK > impeller::android::testing::CreateContext ( )

Definition at line 35 of file ahb_texture_source_vk_unittests.cc.

35 {
36 auto vulkan_dylib = fml::NativeLibrary::Create("libvulkan.so");
37 auto instance_proc_addr =
38 vulkan_dylib->ResolveFunction<PFN_vkGetInstanceProcAddr>(
39 "vkGetInstanceProcAddr");
40
41 if (!instance_proc_addr.has_value()) {
42 VALIDATION_LOG << "Could not setup Vulkan proc table.";
43 return nullptr;
44 }
45
47 settings.proc_address_callback = instance_proc_addr.value();
48 settings.shader_libraries_data = {};
49 settings.enable_validation = false;
50 settings.enable_gpu_tracing = false;
51 settings.enable_surface_control = false;
52
53 return ContextVK::Create(std::move(settings));
54}
static fml::RefPtr< NativeLibrary > Create(const char *path)
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
#define VALIDATION_LOG
Definition validation.h:91

References fml::NativeLibrary::Create(), impeller::ContextVK::Create(), impeller::ContextVK::Settings::enable_gpu_tracing, impeller::ContextVK::Settings::enable_surface_control, impeller::ContextVK::Settings::enable_validation, impeller::ContextVK::Settings::proc_address_callback, impeller::ContextVK::Settings::shader_libraries_data, and VALIDATION_LOG.

Referenced by TEST(), TEST(), and TEST().

◆ FML_TEST_CLASS()

impeller::android::testing::FML_TEST_CLASS ( AndroidAHBSwapchainTest  ,
AHBSwapchainNoFenceWaitAfterAcquireNextImageFailure   
)

◆ TEST() [1/15]

impeller::android::testing::TEST ( AndroidAHBSwapchainTest  ,
AHBSwapchainNoFenceWaitAfterAcquireNextImageFailure   
)

Definition at line 33 of file ahb_swapchain_vk_unittests.cc.

34 {
35 bool wait_for_fences_called = false;
36 auto const context =
38 .SetDeviceExtensions(kAndroidDeviceExtensions)
40 [](VkDevice, VkSwapchainKHR, uint64_t, VkSemaphore, VkFence,
41 uint32_t*) -> VkResult { return VK_ERROR_SURFACE_LOST_KHR; })
42 .SetWaitForFencesCallback([&](VkDevice, uint32_t, const VkFence*,
43 VkBool32, uint64_t) -> VkResult {
44 wait_for_fences_called = true;
45 return VK_SUCCESS;
46 })
47 .Build();
48
49 auto ahb_swapchain = std::shared_ptr<AHBSwapchainVK>(new AHBSwapchainVK(
50 context, std::make_shared<FakeSurfaceControl>(), {}, {100, 100}, false));
51
52 auto image = ahb_swapchain->AcquireNextDrawable();
53 EXPECT_FALSE(image);
54
55 ahb_swapchain->AcquireNextDrawable();
56 EXPECT_FALSE(wait_for_fences_called);
57}
The implementation of a swapchain that uses hardware buffers presented to a given surface control on ...
MockVulkanContextBuilder & SetDeviceExtensions(const std::vector< std::string > &device_extensions)
Definition mock_vulkan.h:92
MockVulkanContextBuilder SetAcquireNextImageCallback(std::function< std::remove_pointer_t< PFN_vkAcquireNextImageKHR > > acquire_next_image_callback)
FlutterVulkanImage * image

References image, kAndroidDeviceExtensions, impeller::testing::MockVulkanContextBuilder::SetAcquireNextImageCallback(), and impeller::testing::MockVulkanContextBuilder::SetDeviceExtensions().

◆ TEST() [2/15]

impeller::android::testing::TEST ( AndroidVulkanTest  ,
CanImportRGBA   
)

Definition at line 56 of file ahb_texture_source_vk_unittests.cc.

56 {
57 if (!HardwareBuffer::IsAvailableOnPlatform()) {
58 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
59 }
60
62 desc.size = ISize{1, 1};
63 desc.format = HardwareBufferFormat::kR8G8B8A8UNormInt;
64 desc.usage = HardwareBufferUsageFlags::kSampledImage;
65
66 auto ahb = std::make_unique<HardwareBuffer>(desc);
67 ASSERT_TRUE(ahb);
68 auto context_vk = CreateContext();
69 ASSERT_TRUE(context_vk);
70
71 AHBTextureSourceVK source(context_vk, std::move(ahb),
72 /*is_swapchain_image=*/false);
73
74 EXPECT_TRUE(source.IsValid());
75 EXPECT_EQ(source.GetYUVConversion(), nullptr);
76
77 context_vk->Shutdown();
78}
A texture source that wraps an instance of AHardwareBuffer.
A descriptor use to specify hardware buffer allocations.

References CreateContext(), impeller::android::HardwareBufferDescriptor::format, impeller::AHBTextureSourceVK::GetYUVConversion(), impeller::android::HardwareBuffer::IsAvailableOnPlatform(), impeller::AHBTextureSourceVK::IsValid(), impeller::android::kR8G8B8A8UNormInt, impeller::android::kSampledImage, impeller::android::HardwareBufferDescriptor::size, and impeller::android::HardwareBufferDescriptor::usage.

◆ TEST() [3/15]

impeller::android::testing::TEST ( AndroidVulkanTest  ,
CanImportWithYUB   
)

Definition at line 80 of file ahb_texture_source_vk_unittests.cc.

80 {
81 if (!HardwareBuffer::IsAvailableOnPlatform()) {
82 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
83 }
84
85 AHardwareBuffer_Desc desc;
86 desc.width = 16;
87 desc.height = 16;
88 desc.format = AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420;
89 desc.stride = 0;
90 desc.layers = 1;
91 desc.rfu0 = 0;
92 desc.rfu1 = 0;
93 desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
94 AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK |
95 AHARDWAREBUFFER_USAGE_CPU_READ_MASK;
96
97 EXPECT_EQ(AHardwareBuffer_isSupported(&desc), 1);
98
99 UniqueAHardwareBuffer buffer = AllocateAHardwareBuffer(desc);
100 ASSERT_TRUE(buffer.is_valid());
101
102 auto context_vk = CreateContext();
103 ASSERT_TRUE(context_vk);
104
105 AHBTextureSourceVK source(context_vk, buffer.get(), desc);
106
107 EXPECT_TRUE(source.IsValid());
108 EXPECT_NE(source.GetYUVConversion(), nullptr);
109
110 context_vk->Shutdown();
111}

References AllocateAHardwareBuffer(), CreateContext(), impeller::AHBTextureSourceVK::GetYUVConversion(), impeller::android::HardwareBuffer::IsAvailableOnPlatform(), and impeller::AHBTextureSourceVK::IsValid().

◆ TEST() [4/15]

impeller::android::testing::TEST ( AndroidVulkanTest  ,
CreateImageViewForOpaqueAlpha   
)

Definition at line 113 of file ahb_texture_source_vk_unittests.cc.

113 {
114 if (!HardwareBuffer::IsAvailableOnPlatform()) {
115 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
116 }
117
118 AHardwareBuffer_Desc desc;
119 desc.width = 16;
120 desc.height = 16;
121 desc.format = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
122 desc.stride = 0;
123 desc.layers = 1;
124 desc.rfu0 = 0;
125 desc.rfu1 = 0;
126 desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
127 AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK |
128 AHARDWAREBUFFER_USAGE_CPU_READ_MASK;
129
130 EXPECT_EQ(AHardwareBuffer_isSupported(&desc), 1);
131
132 UniqueAHardwareBuffer buffer = AllocateAHardwareBuffer(desc);
133 ASSERT_TRUE(buffer.is_valid());
134
135 auto context_vk = CreateContext();
136 ASSERT_TRUE(context_vk);
137
139 ASSERT_EQ(context_vk->GetDevice().getAndroidHardwareBufferPropertiesANDROID(
140 buffer.get(), &ahb_props.get()),
141 vk::Result::eSuccess);
142
143 auto image = AHBTextureSourceVK::CreateVKImageWrapperForAndroidHarwareBuffer(
144 context_vk->GetDevice(), ahb_props, desc);
145 ASSERT_TRUE(image);
146
147 auto image_info = AHBTextureSourceVK::CreateImageViewInfo(
148 image.get(), nullptr, ahb_props, desc);
149
150 EXPECT_EQ(image_info.get().components.a, vk::ComponentSwizzle::eOne);
151
152 context_vk->Shutdown();
153}
vk::StructureChain< vk::AndroidHardwareBufferPropertiesANDROID, vk::AndroidHardwareBufferFormatPropertiesANDROID > AHBProperties

References AllocateAHardwareBuffer(), CreateContext(), impeller::AHBTextureSourceVK::CreateImageViewInfo(), impeller::AHBTextureSourceVK::CreateVKImageWrapperForAndroidHarwareBuffer(), image, and impeller::android::HardwareBuffer::IsAvailableOnPlatform().

◆ TEST() [5/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
CanApplySurfaceTransaction   
)

Definition at line 82 of file toolkit_android_unittests.cc.

82 {
83 if (!SurfaceTransaction::IsAvailableOnPlatform()) {
84 GTEST_SKIP() << "Surface controls are not supported on this platform.";
85 }
86 ASSERT_TRUE(SurfaceTransaction::IsAvailableOnPlatform());
87 SurfaceTransaction transaction;
88 ASSERT_TRUE(transaction.IsValid());
90 ASSERT_TRUE(transaction.Apply([&event](auto) { event.Signal(); }));
91 event.Wait();
92}
A wrapper for ASurfaceTransaction. https://developer.android.com/ndk/reference/group/native-activity#...
bool Apply(OnCompleteCallback callback=nullptr)
Applies the updated encoded in the transaction and invokes the callback when the updated are complete...

References impeller::android::SurfaceTransaction::Apply(), impeller::android::SurfaceTransaction::IsAvailableOnPlatform(), and impeller::android::SurfaceTransaction::IsValid().

◆ TEST() [6/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
CanCreateHardwareBuffer   
)

Definition at line 36 of file toolkit_android_unittests.cc.

36 {
37 if (!HardwareBuffer::IsAvailableOnPlatform()) {
38 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
39 }
40 ASSERT_TRUE(HardwareBuffer::IsAvailableOnPlatform());
41 auto desc = HardwareBufferDescriptor::MakeForSwapchainImage({100, 100});
42 ASSERT_TRUE(desc.IsAllocatable());
43 HardwareBuffer buffer(desc);
44 ASSERT_TRUE(buffer.IsValid());
45}

References impeller::android::HardwareBuffer::IsAvailableOnPlatform(), and impeller::android::HardwareBufferDescriptor::MakeForSwapchainImage().

◆ TEST() [7/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
CanCreateProcTable   
)

Definition at line 25 of file toolkit_android_unittests.cc.

25 {
26 ProcTable proc_table;
27 ASSERT_TRUE(proc_table.IsValid());
28}
The table of Android procs that are resolved dynamically.
Definition proc_table.h:102
bool IsValid() const
If a valid proc table could be setup. This may fail in case of setup on non-Android platforms.
Definition proc_table.cc:65

References impeller::android::ProcTable::IsValid().

◆ TEST() [8/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
CanDescribeHardwareBufferHandles   
)

Definition at line 67 of file toolkit_android_unittests.cc.

67 {
68 if (!HardwareBuffer::IsAvailableOnPlatform()) {
69 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
70 }
71 ASSERT_TRUE(HardwareBuffer::IsAvailableOnPlatform());
72 auto desc = HardwareBufferDescriptor::MakeForSwapchainImage({100, 100});
73 ASSERT_TRUE(desc.IsAllocatable());
74 HardwareBuffer buffer(desc);
75 ASSERT_TRUE(buffer.IsValid());
76 auto a_desc = HardwareBuffer::Describe(buffer.GetHandle());
77 ASSERT_TRUE(a_desc.has_value());
78 ASSERT_EQ(a_desc->width, 100u); // NOLINT
79 ASSERT_EQ(a_desc->height, 100u); // NOLINT
80}

References impeller::android::HardwareBuffer::Describe(), impeller::android::HardwareBuffer::IsAvailableOnPlatform(), and impeller::android::HardwareBufferDescriptor::MakeForSwapchainImage().

◆ TEST() [9/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
CanGetHardwareBufferIDs   
)

Definition at line 47 of file toolkit_android_unittests.cc.

47 {
48 if (!HardwareBuffer::IsAvailableOnPlatform()) {
49 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
50 }
51 ASSERT_TRUE(HardwareBuffer::IsAvailableOnPlatform());
52 if (!GetProcTable().AHardwareBuffer_getId.IsAvailable()) {
53 GTEST_SKIP() << "Hardware buffer IDs are not available on this platform.";
54 }
55 auto desc = HardwareBufferDescriptor::MakeForSwapchainImage({100, 100});
56 ASSERT_TRUE(desc.IsAllocatable());
57 HardwareBuffer buffer(desc);
58 ASSERT_TRUE(buffer.IsValid());
59 ASSERT_TRUE(buffer.GetSystemUniqueID().has_value());
60}
const ProcTable & GetProcTable()
Definition proc_table.cc:12

References impeller::android::GetProcTable(), impeller::android::HardwareBuffer::IsAvailableOnPlatform(), and impeller::android::HardwareBufferDescriptor::MakeForSwapchainImage().

◆ TEST() [10/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
CanPostAndNotWaitForFrameCallbacks   
)

Definition at line 108 of file toolkit_android_unittests.cc.

108 {
109 if (!Choreographer::IsAvailableOnPlatform()) {
110 GTEST_SKIP() << "Choreographer is not supported on this platform.";
111 }
112 const auto& choreographer = Choreographer::GetInstance();
113 ASSERT_TRUE(choreographer.IsValid());
114 ASSERT_TRUE(choreographer.PostFrameCallback([](auto) {}));
115}

References impeller::android::Choreographer::GetInstance(), and impeller::android::Choreographer::IsAvailableOnPlatform().

◆ TEST() [11/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
CanPostAndWaitForFrameCallbacks   
)

Definition at line 117 of file toolkit_android_unittests.cc.

117 {
118 if (!Choreographer::IsAvailableOnPlatform()) {
119 GTEST_SKIP() << "Choreographer is not supported on this platform.";
120 }
121 if ((true)) {
122 GTEST_SKIP()
123 << "Disabled till the test harness is in an Android activity. "
124 "Running it without one will hang because the choreographer "
125 "frame callback will never execute.";
126 }
127 const auto& choreographer = Choreographer::GetInstance();
128 ASSERT_TRUE(choreographer.IsValid());
130 ASSERT_TRUE(choreographer.PostFrameCallback(
131 [&event](auto point) { event.Signal(); }));
132 event.Wait();
133}

References impeller::android::Choreographer::GetInstance(), and impeller::android::Choreographer::IsAvailableOnPlatform().

◆ TEST() [12/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
ChoreographerIsAvailable   
)

Definition at line 101 of file toolkit_android_unittests.cc.

101 {
102 if (!Choreographer::IsAvailableOnPlatform()) {
103 GTEST_SKIP() << "Choreographer is not supported on this platform.";
104 }
105 ASSERT_TRUE(Choreographer::IsAvailableOnPlatform());
106}

References impeller::android::Choreographer::IsAvailableOnPlatform().

◆ TEST() [13/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
GuardsAgainstZeroSizedDescriptors   
)

Definition at line 30 of file toolkit_android_unittests.cc.

30 {
31 auto desc = HardwareBufferDescriptor::MakeForSwapchainImage({0, 0});
32 ASSERT_GT(desc.size.width, 0u);
33 ASSERT_GT(desc.size.height, 0u);
34}

References impeller::android::HardwareBufferDescriptor::MakeForSwapchainImage().

◆ TEST() [14/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
HardwareBufferNullIDIfAPIUnavailable   
)

Definition at line 62 of file toolkit_android_unittests.cc.

62 {
63 DISABLE_ANDROID_PROC(AHardwareBuffer_getId);
64 ASSERT_FALSE(HardwareBuffer::GetSystemUniqueID(nullptr).has_value());
65}
#define DISABLE_ANDROID_PROC(name)

References DISABLE_ANDROID_PROC, and impeller::android::HardwareBuffer::GetSystemUniqueID().

◆ TEST() [15/15]

impeller::android::testing::TEST ( ToolkitAndroidTest  ,
SurfacControlsAreAvailable   
)

Definition at line 94 of file toolkit_android_unittests.cc.

94 {
95 if (!SurfaceControl::IsAvailableOnPlatform()) {
96 GTEST_SKIP() << "Surface controls are not supported on this platform.";
97 }
98 ASSERT_TRUE(SurfaceControl::IsAvailableOnPlatform());
99}

References impeller::android::SurfaceControl::IsAvailableOnPlatform().

Variable Documentation

◆ kAndroidDeviceExtensions

const std::vector<std::string> impeller::android::testing::kAndroidDeviceExtensions
Initial value:
= {
"VK_KHR_swapchain",
"VK_ANDROID_external_memory_android_hardware_buffer",
"VK_KHR_sampler_ycbcr_conversion",
"VK_KHR_external_memory",
"VK_EXT_queue_family_foreign",
"VK_KHR_dedicated_allocation",
}

Definition at line 15 of file ahb_swapchain_vk_unittests.cc.

15 {
16 "VK_KHR_swapchain",
17 "VK_ANDROID_external_memory_android_hardware_buffer",
18 "VK_KHR_sampler_ycbcr_conversion",
19 "VK_KHR_external_memory",
20 "VK_EXT_queue_family_foreign",
21 "VK_KHR_dedicated_allocation",
22};

Referenced by TEST().