Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
single_frame_codec_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
7#include <memory>
8
15
16// CREATE_NATIVE_ENTRY is leaky by design
17// NOLINTBEGIN(clang-analyzer-core.StackAddressEscape)
18
19#pragma GCC diagnostic ignored "-Wunreachable-code"
20
21namespace flutter {
22namespace testing {
23
24TEST_F(ShellTest, SingleFrameCodecAccuratelyReportsSize) {
25 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
26
27 auto validate_codec = [](Dart_NativeArguments args) {
28 auto handle = Dart_GetNativeArgument(args, 0);
29 intptr_t peer = 0;
30 Dart_Handle result = Dart_GetNativeInstanceField(
32 ASSERT_FALSE(Dart_IsError(result));
33 };
34 auto finish = [message_latch](Dart_NativeArguments args) {
35 message_latch->Signal();
36 };
37
38 Settings settings = CreateSettingsForFixture();
39 TaskRunners task_runners("test", // label
40 GetCurrentTaskRunner(), // platform
41 CreateNewThread(), // raster
42 CreateNewThread(), // ui
43 CreateNewThread() // io
44 );
45
46 AddNativeCallback("ValidateCodec", CREATE_NATIVE_ENTRY(validate_codec));
47 AddNativeCallback("Finish", CREATE_NATIVE_ENTRY(finish));
48
49 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
50
51 ASSERT_TRUE(shell->IsSetup());
52 auto configuration = RunConfiguration::InferFromSettings(settings);
53 configuration.SetEntrypoint("createSingleFrameCodec");
54
55 shell->RunEngine(std::move(configuration), [](auto result) {
56 ASSERT_EQ(result, Engine::RunStatus::Success);
57 });
58
59 message_latch->Wait();
60 DestroyShell(std::move(shell), task_runners);
61}
62
63TEST_F(ShellTest, SingleFrameCodecHandlesNoGpu) {
64#ifndef FML_OS_MACOSX
65 GTEST_SKIP() << "Only works on macOS currently.";
66#endif
67
68 Settings settings = CreateSettingsForFixture();
69 settings.enable_impeller = true;
70 TaskRunners task_runners("test", // label
71 GetCurrentTaskRunner(), // platform
72 CreateNewThread(), // raster
73 CreateNewThread(), // ui
74 CreateNewThread() // io
75 );
76 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
77 ASSERT_TRUE(shell->IsSetup());
78
79 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
80 auto finish = [message_latch](Dart_NativeArguments args) {
81 message_latch->Signal();
82 };
83 AddNativeCallback("Finish", CREATE_NATIVE_ENTRY(finish));
84
85 auto turn_off_gpu = [&](Dart_NativeArguments args) {
86 auto handle = Dart_GetNativeArgument(args, 0);
87 bool value = true;
88 ASSERT_TRUE(Dart_IsBoolean(handle));
89 Dart_BooleanValue(handle, &value);
90 TurnOffGPU(shell.get(), value);
91 };
92 AddNativeCallback("TurnOffGPU", CREATE_NATIVE_ENTRY(turn_off_gpu));
93
94 auto flush_awaiting_tasks = [&](Dart_NativeArguments args) {
95 fml::WeakPtr io_manager = shell->GetIOManager();
96 task_runners.GetIOTaskRunner()->PostTask([io_manager] {
97 if (io_manager) {
98 std::shared_ptr<impeller::Context> impeller_context =
99 io_manager->GetImpellerContext();
100 // This will cause the stored tasks to overflow and start throwing them
101 // away.
102 for (int i = 0; i < impeller::Context::kMaxTasksAwaitingGPU; i++) {
103 impeller_context->StoreTaskForGPU([] {}, [] {});
104 }
105 }
106 });
107 };
108 AddNativeCallback("FlushGpuAwaitingTasks",
109 CREATE_NATIVE_ENTRY(flush_awaiting_tasks));
110
111 auto configuration = RunConfiguration::InferFromSettings(settings);
112 configuration.SetEntrypoint("singleFrameCodecHandlesNoGpu");
113
114 shell->RunEngine(std::move(configuration), [](auto result) {
115 ASSERT_EQ(result, Engine::RunStatus::Success);
116 });
117
118 message_latch->Wait();
119 DestroyShell(std::move(shell), task_runners);
120}
121
122} // namespace testing
123} // namespace flutter
124
125// NOLINTEND(clang-analyzer-core.StackAddressEscape)
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
fml::RefPtr< fml::TaskRunner > GetIOTaskRunner() const
virtual void PostTask(const fml::closure &task) override
static constexpr int32_t kMaxTasksAwaitingGPU
Definition context.h:79
int32_t value
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
TEST_F(DisplayListTest, Defaults)
#define CREATE_NATIVE_ENTRY(native_entry)