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

Commit e39c4df

Browse files
authored
[Impeller] Fix stuttering in playgrounds due to precision issue (#37035)
1 parent e07d8a4 commit e39c4df

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

impeller/entity/entity_unittests.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,8 +2053,7 @@ TEST_P(EntityTest, RuntimeEffect) {
20532053
Scalar iTime;
20542054
Vector2 iResolution;
20552055
} frag_uniforms = {
2056-
.iTime = static_cast<Scalar>(
2057-
fml::TimePoint::Now().ToEpochDelta().ToSecondsF()),
2056+
.iTime = static_cast<Scalar>(GetSecondsElapsed()),
20582057
.iResolution = Vector2(GetWindowSize().width, GetWindowSize().height),
20592058
};
20602059
auto uniform_data = std::make_shared<std::vector<uint8_t>>();

impeller/playground/playground_test.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#include "flutter/fml/time/time_point.h"
6+
57
#include "impeller/playground/playground_test.h"
68

79
namespace impeller {
@@ -22,6 +24,8 @@ void PlaygroundTest::SetUp() {
2224
}
2325

2426
SetupWindow(GetParam());
27+
28+
start_time_ = fml::TimePoint::Now().ToEpochDelta();
2529
}
2630

2731
void PlaygroundTest::TearDown() {
@@ -59,4 +63,8 @@ std::string PlaygroundTest::GetWindowTitle() const {
5963
return FormatWindowTitle(flutter::testing::GetCurrentTestName());
6064
}
6165

66+
Scalar PlaygroundTest::GetSecondsElapsed() const {
67+
return (fml::TimePoint::Now().ToEpochDelta() - start_time_).ToSecondsF();
68+
}
69+
6270
} // namespace impeller

impeller/playground/playground_test.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include <memory>
88

99
#include "flutter/fml/macros.h"
10+
#include "flutter/fml/time/time_delta.h"
1011
#include "flutter/testing/testing.h"
12+
#include "impeller/geometry/scalar.h"
1113
#include "impeller/playground/playground.h"
1214

1315
namespace impeller {
@@ -33,7 +35,13 @@ class PlaygroundTest : public Playground,
3335
// |Playground|
3436
std::string GetWindowTitle() const override;
3537

38+
/// @brief Get the amount of time elapsed from the start of the playground
39+
/// test's execution.
40+
Scalar GetSecondsElapsed() const;
41+
3642
private:
43+
fml::TimeDelta start_time_;
44+
3745
FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundTest);
3846
};
3947

impeller/renderer/renderer_unittests.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "flutter/fml/time/time_point.h"
65
#include "flutter/testing/testing.h"
76
#include "impeller/base/strings.h"
87
#include "impeller/fixtures/array.frag.h"
@@ -92,7 +91,7 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) {
9291
pass.GetTransientsBuffer().EmplaceUniform(uniforms));
9392

9493
FS::FrameInfo frame_info;
95-
frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
94+
frame_info.current_time = GetSecondsElapsed();
9695
frame_info.cursor_position = GetCursorPosition();
9796
frame_info.window_size.x = GetWindowSize().width;
9897
frame_info.window_size.y = GetWindowSize().height;
@@ -181,7 +180,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
181180
cmd.BindVertices(vertex_buffer);
182181

183182
VS::UniformBuffer uniforms;
184-
Scalar time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
183+
Scalar time = GetSecondsElapsed();
185184
euler_angles = Vector3(0.19 * time, 0.7 * time, 0.43 * time);
186185

187186
uniforms.mvp =
@@ -244,7 +243,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) {
244243
cmd.BindVertices(vertex_buffer);
245244

246245
FS::FrameInfo frame_info;
247-
frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
246+
frame_info.current_time = GetSecondsElapsed();
248247
frame_info.cursor_position = GetCursorPosition();
249248
frame_info.window_size.x = GetWindowSize().width;
250249
frame_info.window_size.y = GetWindowSize().height;
@@ -359,7 +358,7 @@ TEST_P(RendererTest, CanRenderToTexture) {
359358
cmd.BindVertices(vertex_buffer);
360359

361360
FS::FrameInfo frame_info;
362-
frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
361+
frame_info.current_time = GetSecondsElapsed();
363362
frame_info.cursor_position = GetCursorPosition();
364363
frame_info.window_size.x = GetWindowSize().width;
365364
frame_info.window_size.y = GetWindowSize().height;
@@ -722,7 +721,7 @@ TEST_P(RendererTest, TheImpeller) {
722721

723722
FS::FragInfo fs_uniform;
724723
fs_uniform.texture_size = Point(size);
725-
fs_uniform.time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
724+
fs_uniform.time = GetSecondsElapsed();
726725
FS::BindFragInfo(cmd,
727726
pass.GetTransientsBuffer().EmplaceUniform(fs_uniform));
728727
FS::BindBlueNoise(cmd, blue_noise, noise_sampler);
@@ -768,7 +767,7 @@ TEST_P(RendererTest, ArrayUniforms) {
768767
VS::BindVertInfo(cmd,
769768
pass.GetTransientsBuffer().EmplaceUniform(vs_uniform));
770769

771-
auto time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
770+
auto time = GetSecondsElapsed();
772771
auto y_pos = [&time](float x) {
773772
return 400 + 10 * std::cos(time * 5 + x / 6);
774773
};

0 commit comments

Comments
 (0)