Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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() { GetMutableProcTable().name.proc = real_proc; } \
22 decltype(name)* real_proc; \
23 } disable##name;
24
25TEST(ToolkitAndroidTest, CanCreateProcTable) {
26 ProcTable proc_table;
27 ASSERT_TRUE(proc_table.IsValid());
28}
29
30TEST(ToolkitAndroidTest, GuardsAgainstZeroSizedDescriptors) {
32 ASSERT_GT(desc.size.width, 0u);
33 ASSERT_GT(desc.size.height, 0u);
34}
35
36TEST(ToolkitAndroidTest, CanCreateHardwareBuffer) {
38 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
39 }
42 ASSERT_TRUE(desc.IsAllocatable());
43 HardwareBuffer buffer(desc);
44 ASSERT_TRUE(buffer.IsValid());
45}
46
47TEST(ToolkitAndroidTest, CanGetHardwareBufferIDs) {
49 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
50 }
52 if (!GetProcTable().AHardwareBuffer_getId.IsAvailable()) {
53 GTEST_SKIP() << "Hardware buffer IDs are not available on this platform.";
54 }
56 ASSERT_TRUE(desc.IsAllocatable());
57 HardwareBuffer buffer(desc);
58 ASSERT_TRUE(buffer.IsValid());
59 ASSERT_TRUE(buffer.GetSystemUniqueID().has_value());
60}
61
62TEST(ToolkitAndroidTest, HardwareBufferNullIDIfAPIUnavailable) {
63 DISABLE_ANDROID_PROC(AHardwareBuffer_getId);
64 ASSERT_FALSE(HardwareBuffer::GetSystemUniqueID(nullptr).has_value());
65}
66
67TEST(ToolkitAndroidTest, CanDescribeHardwareBufferHandles) {
69 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
70 }
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}
81
82TEST(ToolkitAndroidTest, CanApplySurfaceTransaction) {
84 GTEST_SKIP() << "Surface controls are not supported on this platform.";
85 }
87 SurfaceTransaction transaction;
88 ASSERT_TRUE(transaction.IsValid());
90 ASSERT_TRUE(transaction.Apply([&event](auto) { event.Signal(); }));
91 event.Wait();
92}
93
94TEST(ToolkitAndroidTest, SurfacControlsAreAvailable) {
96 GTEST_SKIP() << "Surface controls are not supported on this platform.";
97 }
99}
100
101TEST(ToolkitAndroidTest, ChoreographerIsAvailable) {
103 GTEST_SKIP() << "Choreographer is not supported on this platform.";
104 }
106}
107
108TEST(ToolkitAndroidTest, CanPostAndNotWaitForFrameCallbacks) {
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}
116
117TEST(ToolkitAndroidTest, CanPostAndWaitForFrameCallbacks) {
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}
134
135} // 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(AndroidAHBSwapchainTest, AHBSwapchainNoFenceWaitAfterAcquireNextImageFailure)
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: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
#define DISABLE_ANDROID_PROC(name)