Flutter Impeller
impeller::android::testing Namespace Reference

Classes

struct  UniqueAHardwareBufferTraits
 

Typedefs

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

Functions

UniqueAHardwareBuffer AllocateAHardwareBuffer (const AHardwareBuffer_Desc &desc)
 
std::shared_ptr< ContextVKCreateContext ()
 
 TEST (AndroidVulkanTest, CanImportRGBA)
 
 TEST (AndroidVulkanTest, CanImportWithYUB)
 
 TEST (AndroidVulkanTest, CreateImageViewForOpaqueAlpha)
 
 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)
 

Typedef Documentation

◆ UniqueAHardwareBuffer

using impeller::android::testing::UniqueAHardwareBuffer = typedef fml::UniqueObject<AHardwareBuffer*, UniqueAHardwareBufferTraits>

Definition at line 24 of file ahb_texture_source_vk_unittests.cc.

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 }
fml::UniqueObject< AHardwareBuffer *, UniqueAHardwareBufferTraits > UniqueAHardwareBuffer

Referenced by 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 }
ScopedObject< Object > Create(CtorArgs &&... args)
Definition: object.h:161
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 impeller::interop::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 impeller::Playground::OpenPlaygroundHere(), TEST(), and impeller::interop::testing::TEST_P().

◆ TEST() [1/14]

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 
61  HardwareBufferDescriptor desc;
62  desc.size = ISize{1, 1};
63  desc.format = HardwareBufferFormat::kR8G8B8A8UNormInt;
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 }
std::shared_ptr< ContextVK > CreateContext()
ISize64 ISize
Definition: size.h:162

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() [2/14]

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 
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 }
UniqueAHardwareBuffer AllocateAHardwareBuffer(const AHardwareBuffer_Desc &desc)

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

◆ TEST() [3/14]

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 
133  ASSERT_TRUE(buffer.is_valid());
134 
135  auto context_vk = CreateContext();
136  ASSERT_TRUE(context_vk);
137 
138  AHBTextureSourceVK::AHBProperties ahb_props;
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 }

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

◆ TEST() [4/14]

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());
89  fml::AutoResetWaitableEvent event;
90  ASSERT_TRUE(transaction.Apply([&event](auto) { event.Signal(); }));
91  event.Wait();
92 }

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

◆ TEST() [5/14]

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(), impeller::android::HardwareBuffer::IsValid(), and impeller::android::HardwareBufferDescriptor::MakeForSwapchainImage().

◆ TEST() [6/14]

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 }

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

◆ TEST() [7/14]

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::GetHandle(), impeller::android::HardwareBuffer::IsAvailableOnPlatform(), impeller::android::HardwareBuffer::IsValid(), and impeller::android::HardwareBufferDescriptor::MakeForSwapchainImage().

◆ TEST() [8/14]

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::GetSystemUniqueID(), impeller::android::HardwareBuffer::IsAvailableOnPlatform(), impeller::android::HardwareBuffer::IsValid(), and impeller::android::HardwareBufferDescriptor::MakeForSwapchainImage().

◆ TEST() [9/14]

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() [10/14]

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());
129  fml::AutoResetWaitableEvent event;
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() [11/14]

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() [12/14]

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() [13/14]

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() [14/14]

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().