Flutter Engine
 
Loading...
Searching...
No Matches
toolkit_android_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
12
14
15#define DISABLE_ANDROID_PROC(name) \
16 struct Disable##name { \
17 Disable##name() { \
18 real_proc = GetMutableProcTable().name.proc; \
19 GetMutableProcTable().name.proc = nullptr; \
20 } \
21 ~Disable##name() { \
22 GetMutableProcTable().name.proc = real_proc; \
23 } \
24 decltype(name)* real_proc; \
25 } disable##name;
26
27TEST(ToolkitAndroidTest, CanCreateProcTable) {
28 ProcTable proc_table;
29 ASSERT_TRUE(proc_table.IsValid());
30}
31
32TEST(ToolkitAndroidTest, GuardsAgainstZeroSizedDescriptors) {
34 ASSERT_GT(desc.size.width, 0u);
35 ASSERT_GT(desc.size.height, 0u);
36}
37
38TEST(ToolkitAndroidTest, CanCreateHardwareBuffer) {
40 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
41 }
44 ASSERT_TRUE(desc.IsAllocatable());
45 HardwareBuffer buffer(desc);
46 ASSERT_TRUE(buffer.IsValid());
47}
48
49TEST(ToolkitAndroidTest, CanGetHardwareBufferIDs) {
51 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
52 }
54 if (!GetProcTable().AHardwareBuffer_getId.IsAvailable()) {
55 GTEST_SKIP() << "Hardware buffer IDs are not available on this platform.";
56 }
58 ASSERT_TRUE(desc.IsAllocatable());
59 HardwareBuffer buffer(desc);
60 ASSERT_TRUE(buffer.IsValid());
61 ASSERT_TRUE(buffer.GetSystemUniqueID().has_value());
62}
63
64TEST(ToolkitAndroidTest, HardwareBufferNullIDIfAPIUnavailable) {
65 DISABLE_ANDROID_PROC(AHardwareBuffer_getId);
66 ASSERT_FALSE(HardwareBuffer::GetSystemUniqueID(nullptr).has_value());
67}
68
69TEST(ToolkitAndroidTest, CanDescribeHardwareBufferHandles) {
71 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
72 }
75 ASSERT_TRUE(desc.IsAllocatable());
76 HardwareBuffer buffer(desc);
77 ASSERT_TRUE(buffer.IsValid());
78 auto a_desc = HardwareBuffer::Describe(buffer.GetHandle());
79 ASSERT_TRUE(a_desc.has_value());
80 ASSERT_EQ(a_desc->width, 100u); // NOLINT
81 ASSERT_EQ(a_desc->height, 100u); // NOLINT
82}
83
84TEST(ToolkitAndroidTest, CanApplySurfaceTransaction) {
86 GTEST_SKIP() << "Surface controls are not supported on this platform.";
87 }
89 SurfaceTransaction transaction;
90 ASSERT_TRUE(transaction.IsValid());
92 ASSERT_TRUE(transaction.Apply([&event](auto) { event.Signal(); }));
93 event.Wait();
94}
95
96TEST(ToolkitAndroidTest, SurfacControlsAreAvailable) {
98 GTEST_SKIP() << "Surface controls are not supported on this platform.";
99 }
101}
102
103TEST(ToolkitAndroidTest, ChoreographerIsAvailable) {
105 GTEST_SKIP() << "Choreographer is not supported on this platform.";
106 }
108}
109
110TEST(ToolkitAndroidTest, CanPostAndNotWaitForFrameCallbacks) {
112 GTEST_SKIP() << "Choreographer is not supported on this platform.";
113 }
114 const auto& choreographer = Choreographer::GetInstance();
115 ASSERT_TRUE(choreographer.IsValid());
116 ASSERT_TRUE(choreographer.PostFrameCallback([](auto) {}));
117}
118
119TEST(ToolkitAndroidTest, CanPostAndWaitForFrameCallbacks) {
121 GTEST_SKIP() << "Choreographer is not supported on this platform.";
122 }
123 if ((true)) {
124 GTEST_SKIP()
125 << "Disabled till the test harness is in an Android activity. "
126 "Running it without one will hang because the choreographer "
127 "frame callback will never execute.";
128 }
129 const auto& choreographer = Choreographer::GetInstance();
130 ASSERT_TRUE(choreographer.IsValid());
132 ASSERT_TRUE(choreographer.PostFrameCallback(
133 [&event](auto point) { event.Signal(); }));
134 event.Wait();
135}
136
137} // namespace impeller::android::testing
static Choreographer & GetInstance()
Create or get the thread local instance of a choreographer. A message loop will be setup on the calli...
A wrapper for AHardwareBuffer https://developer.android.com/ndk/reference/group/a-hardware-buffer.
static std::optional< AHardwareBuffer_Desc > Describe(AHardwareBuffer *buffer)
std::optional< uint64_t > GetSystemUniqueID() const
Get the system wide unique ID of the hardware buffer if possible. This is only available on Android A...
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...
TEST(AndroidVulkanTest, CanImportRGBA)
const ProcTable & GetProcTable()
Definition proc_table.cc:12
static HardwareBufferDescriptor MakeForSwapchainImage(const ISize &size)
Create a descriptor of the given size that is suitable for use as a swapchain image.
The table of Android procs that are resolved dynamically.
Definition proc_table.h:97
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
#define DISABLE_ANDROID_PROC(name)