Flutter Engine
 
Loading...
Searching...
No Matches
path_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
16namespace flutter {
17namespace testing {
18
19TEST_F(ShellTest, PathVolatilityOldPathsBecomeNonVolatile) {
20 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
21
22 auto native_validate_path = [message_latch](Dart_NativeArguments args) {
23 auto handle = Dart_GetNativeArgument(args, 0);
24 intptr_t peer = 0;
25 Dart_Handle result = Dart_GetNativeInstanceField(
27 EXPECT_FALSE(Dart_IsError(result));
28 CanvasPath* path = reinterpret_cast<CanvasPath*>(peer);
29 EXPECT_TRUE(path);
30
31 for (uint32_t i = 0; i <= DlPath::kMaxVolatileUses * 2; i++) {
32 EXPECT_TRUE(path->path().IsVolatile());
33 EXPECT_TRUE(path->path().GetSkPath().isVolatile());
34 // Getting the SkPath without expressing intent for rendering will not
35 // progress towards non-volatility
36 }
37 EXPECT_TRUE(path->path().IsVolatile());
38 EXPECT_TRUE(path->path().GetSkPath().isVolatile());
39
40 for (uint32_t i = 0; i < DlPath::kMaxVolatileUses; i++) {
41 path->path().WillRenderSkPath();
42 EXPECT_TRUE(path->path().IsVolatile());
43 EXPECT_TRUE(path->path().GetSkPath().isVolatile());
44 }
45 // One last intent to render will make it non-volatile
46 path->path().WillRenderSkPath();
47 EXPECT_FALSE(path->path().IsVolatile());
48 EXPECT_FALSE(path->path().GetSkPath().isVolatile());
49
50 DlPath saved_path = path->path();
51 path->addOval(10, 10, 20, 20);
52
53 // Meanwhile if the path being constructed by the CanvasPath object
54 // is changed further, new paths extracted via path() are again volatile.
55 EXPECT_TRUE(path->path().IsVolatile());
56 EXPECT_TRUE(path->path().GetSkPath().isVolatile());
57
58 // But the saved versions copied before the changes are still non-volatile
59 EXPECT_FALSE(saved_path.IsVolatile());
60 EXPECT_FALSE(saved_path.GetSkPath().isVolatile());
61
62 message_latch->Signal();
63 };
64
65 Settings settings = CreateSettingsForFixture();
66 TaskRunners task_runners("test", // label
67 GetCurrentTaskRunner(), // platform
68 CreateNewThread(), // raster
69 CreateNewThread(), // ui
70 CreateNewThread() // io
71 );
72
73 AddNativeCallback("ValidatePath", CREATE_NATIVE_ENTRY(native_validate_path));
74
75 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
76
77 ASSERT_TRUE(shell->IsSetup());
78 auto configuration = RunConfiguration::InferFromSettings(settings);
79 configuration.SetEntrypoint("createPath");
80
81 shell->RunEngine(std::move(configuration), [](auto result) {
82 ASSERT_EQ(result, Engine::RunStatus::Success);
83 });
84
85 message_latch->Wait();
86
87 DestroyShell(std::move(shell), task_runners);
88}
89
90// Screen diffing tests use deterministic rendering. Allowing a path to be
91// volatile or not for an individual frame can result in minor pixel differences
92// that cause the test to fail.
93// If deterministic rendering is enabled, the tracker should be disabled and
94// paths should always be non-volatile.
95TEST_F(ShellTest, DeterministicRenderingDisablesPathVolatility) {
96 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
97
98 auto native_validate_path = [message_latch](Dart_NativeArguments args) {
99 auto handle = Dart_GetNativeArgument(args, 0);
100 intptr_t peer = 0;
101 Dart_Handle result = Dart_GetNativeInstanceField(
102 handle, tonic::DartWrappable::kPeerIndex, &peer);
103 EXPECT_FALSE(Dart_IsError(result));
104 CanvasPath* path = reinterpret_cast<CanvasPath*>(peer);
105 EXPECT_TRUE(path);
106
107 for (uint32_t i = 0; i <= DlPath::kMaxVolatileUses * 2; i++) {
108 EXPECT_FALSE(path->path().IsVolatile());
109 EXPECT_FALSE(path->path().GetSkPath().isVolatile());
110 path->path().WillRenderSkPath();
111 }
112 EXPECT_FALSE(path->path().IsVolatile());
113 EXPECT_FALSE(path->path().GetSkPath().isVolatile());
114
115 message_latch->Signal();
116 };
117
118 Settings settings = CreateSettingsForFixture();
120 TaskRunners task_runners("test", // label
121 GetCurrentTaskRunner(), // platform
122 CreateNewThread(), // raster
123 CreateNewThread(), // ui
124 CreateNewThread() // io
125 );
126
127 AddNativeCallback("ValidatePath", CREATE_NATIVE_ENTRY(native_validate_path));
128
129 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
130
131 ASSERT_TRUE(shell->IsSetup());
132 auto configuration = RunConfiguration::InferFromSettings(settings);
133 configuration.SetEntrypoint("createPath");
134
135 shell->RunEngine(std::move(configuration), [](auto result) {
136 ASSERT_EQ(result, Engine::RunStatus::Success);
137 });
138
139 message_latch->Wait();
140
141 DestroyShell(std::move(shell), task_runners);
142}
143
144} // namespace testing
145} // namespace flutter
static constexpr uint32_t kMaxVolatileUses
Definition dl_path.h:21
const SkPath & GetSkPath() const
Definition dl_path.cc:116
bool IsVolatile() const
Definition dl_path.cc:253
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...
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
TEST_F(DisplayListTest, Defaults)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
bool skia_deterministic_rendering_on_cpu
Definition settings.h:318
#define CREATE_NATIVE_ENTRY(native_entry)