diff --git a/engine/src/flutter/impeller/entity/entity_unittests.cc b/engine/src/flutter/impeller/entity/entity_unittests.cc index b915a5bb12d..c4bdf04e8aa 100644 --- a/engine/src/flutter/impeller/entity/entity_unittests.cc +++ b/engine/src/flutter/impeller/entity/entity_unittests.cc @@ -2053,8 +2053,7 @@ TEST_P(EntityTest, RuntimeEffect) { Scalar iTime; Vector2 iResolution; } frag_uniforms = { - .iTime = static_cast( - fml::TimePoint::Now().ToEpochDelta().ToSecondsF()), + .iTime = static_cast(GetSecondsElapsed()), .iResolution = Vector2(GetWindowSize().width, GetWindowSize().height), }; auto uniform_data = std::make_shared>(); diff --git a/engine/src/flutter/impeller/playground/playground_test.cc b/engine/src/flutter/impeller/playground/playground_test.cc index 024c4d52174..fab9d75a55e 100644 --- a/engine/src/flutter/impeller/playground/playground_test.cc +++ b/engine/src/flutter/impeller/playground/playground_test.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "flutter/fml/time/time_point.h" + #include "impeller/playground/playground_test.h" namespace impeller { @@ -22,6 +24,8 @@ void PlaygroundTest::SetUp() { } SetupWindow(GetParam()); + + start_time_ = fml::TimePoint::Now().ToEpochDelta(); } void PlaygroundTest::TearDown() { @@ -59,4 +63,8 @@ std::string PlaygroundTest::GetWindowTitle() const { return FormatWindowTitle(flutter::testing::GetCurrentTestName()); } +Scalar PlaygroundTest::GetSecondsElapsed() const { + return (fml::TimePoint::Now().ToEpochDelta() - start_time_).ToSecondsF(); +} + } // namespace impeller diff --git a/engine/src/flutter/impeller/playground/playground_test.h b/engine/src/flutter/impeller/playground/playground_test.h index 351cbc0c954..26db90635cb 100644 --- a/engine/src/flutter/impeller/playground/playground_test.h +++ b/engine/src/flutter/impeller/playground/playground_test.h @@ -7,7 +7,9 @@ #include #include "flutter/fml/macros.h" +#include "flutter/fml/time/time_delta.h" #include "flutter/testing/testing.h" +#include "impeller/geometry/scalar.h" #include "impeller/playground/playground.h" namespace impeller { @@ -33,7 +35,13 @@ class PlaygroundTest : public Playground, // |Playground| std::string GetWindowTitle() const override; + /// @brief Get the amount of time elapsed from the start of the playground + /// test's execution. + Scalar GetSecondsElapsed() const; + private: + fml::TimeDelta start_time_; + FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundTest); }; diff --git a/engine/src/flutter/impeller/renderer/renderer_unittests.cc b/engine/src/flutter/impeller/renderer/renderer_unittests.cc index 32b4f5623bf..4a1a52ca02b 100644 --- a/engine/src/flutter/impeller/renderer/renderer_unittests.cc +++ b/engine/src/flutter/impeller/renderer/renderer_unittests.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/fml/time/time_point.h" #include "flutter/testing/testing.h" #include "impeller/base/strings.h" #include "impeller/fixtures/array.frag.h" @@ -92,7 +91,7 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) { pass.GetTransientsBuffer().EmplaceUniform(uniforms)); FS::FrameInfo frame_info; - frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF(); + frame_info.current_time = GetSecondsElapsed(); frame_info.cursor_position = GetCursorPosition(); frame_info.window_size.x = GetWindowSize().width; frame_info.window_size.y = GetWindowSize().height; @@ -181,7 +180,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) { cmd.BindVertices(vertex_buffer); VS::UniformBuffer uniforms; - Scalar time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF(); + Scalar time = GetSecondsElapsed(); euler_angles = Vector3(0.19 * time, 0.7 * time, 0.43 * time); uniforms.mvp = @@ -244,7 +243,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) { cmd.BindVertices(vertex_buffer); FS::FrameInfo frame_info; - frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF(); + frame_info.current_time = GetSecondsElapsed(); frame_info.cursor_position = GetCursorPosition(); frame_info.window_size.x = GetWindowSize().width; frame_info.window_size.y = GetWindowSize().height; @@ -359,7 +358,7 @@ TEST_P(RendererTest, CanRenderToTexture) { cmd.BindVertices(vertex_buffer); FS::FrameInfo frame_info; - frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF(); + frame_info.current_time = GetSecondsElapsed(); frame_info.cursor_position = GetCursorPosition(); frame_info.window_size.x = GetWindowSize().width; frame_info.window_size.y = GetWindowSize().height; @@ -722,7 +721,7 @@ TEST_P(RendererTest, TheImpeller) { FS::FragInfo fs_uniform; fs_uniform.texture_size = Point(size); - fs_uniform.time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF(); + fs_uniform.time = GetSecondsElapsed(); FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(fs_uniform)); FS::BindBlueNoise(cmd, blue_noise, noise_sampler); @@ -768,7 +767,7 @@ TEST_P(RendererTest, ArrayUniforms) { VS::BindVertInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(vs_uniform)); - auto time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF(); + auto time = GetSecondsElapsed(); auto y_pos = [&time](float x) { return 400 + 10 * std::cos(time * 5 + x / 6); };