Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e553673

Browse files
committed
test
1 parent d75cf20 commit e553673

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

lib/ui/painting/path_unittests.cc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,62 @@ TEST_F(ShellTest, PathVolatilityGCRemovesPathFromTracker) {
124124
DestroyShell(std::move(shell), std::move(task_runners));
125125
}
126126

127+
// Screen diffing tests use deterministic rendering. Allowing a path to be
128+
// volatile or not for an individual frame can result in minor pixel differences
129+
// that cause the test to fail.
130+
// If deterministic rendering is enabled, the tracker should be disabled and
131+
// paths should always be non-volatile.
132+
TEST_F(ShellTest, DeterministicRenderingDisablesPathVolatility) {
133+
auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
134+
135+
auto native_validate_path = [message_latch](Dart_NativeArguments args) {
136+
auto handle = Dart_GetNativeArgument(args, 0);
137+
intptr_t peer = 0;
138+
Dart_Handle result = Dart_GetNativeInstanceField(
139+
handle, tonic::DartWrappable::kPeerIndex, &peer);
140+
EXPECT_FALSE(Dart_IsError(result));
141+
CanvasPath* path = reinterpret_cast<CanvasPath*>(peer);
142+
EXPECT_TRUE(path);
143+
EXPECT_FALSE(path->path().isVolatile());
144+
std::shared_ptr<VolatilePathTracker> tracker =
145+
UIDartState::Current()->GetVolatilePathTracker();
146+
EXPECT_TRUE(tracker);
147+
EXPECT_FALSE(tracker->enabled());
148+
149+
for (int i = 0; i < VolatilePathTracker::kFramesOfVolatility; i++) {
150+
tracker->OnFrame();
151+
EXPECT_FALSE(path->path().isVolatile());
152+
}
153+
EXPECT_FALSE(path->path().isVolatile());
154+
message_latch->Signal();
155+
};
156+
157+
Settings settings = CreateSettingsForFixture();
158+
settings.skia_deterministic_rendering_on_cpu = true;
159+
TaskRunners task_runners("test", // label
160+
GetCurrentTaskRunner(), // platform
161+
CreateNewThread(), // raster
162+
CreateNewThread(), // ui
163+
CreateNewThread() // io
164+
);
165+
166+
AddNativeCallback("ValidatePath", CREATE_NATIVE_ENTRY(native_validate_path));
167+
168+
std::unique_ptr<Shell> shell =
169+
CreateShell(std::move(settings), std::move(task_runners));
170+
171+
ASSERT_TRUE(shell->IsSetup());
172+
auto configuration = RunConfiguration::InferFromSettings(settings);
173+
configuration.SetEntrypoint("createPath");
174+
175+
shell->RunEngine(std::move(configuration), [](auto result) {
176+
ASSERT_EQ(result, Engine::RunStatus::Success);
177+
});
178+
179+
message_latch->Wait();
180+
181+
DestroyShell(std::move(shell), std::move(task_runners));
182+
}
183+
127184
} // namespace testing
128185
} // namespace flutter

lib/ui/volatile_path_tracker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class VolatilePathTracker {
6262
// Must be called from the UI task runner.
6363
void OnFrame();
6464

65+
bool enabled() const { return enabled_; }
66+
6567
private:
6668
fml::RefPtr<fml::TaskRunner> ui_task_runner_;
6769
std::atomic_bool needs_drain_ = false;

0 commit comments

Comments
 (0)