| Flutter Impeller |

playground_test.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
5 #include "flutter/fml/time/time_point.h"
6
7 #include "impeller/base/timing.h"
8 #include "impeller/base/validation.h"
9 #include "impeller/playground/playground_test.h"
10
11 namespace impeller {
12
13 PlaygroundTest::PlaygroundTest()
14 : Playground(PlaygroundSwitches{flutter::testing::GetArgsForProcess()}) {}
15
16 PlaygroundTest::~PlaygroundTest() = default;
17
18 void PlaygroundTest::SetUp() {
19 if (!Playground::SupportsBackend(GetParam())) {
20 GTEST_SKIP_("Playground doesn't support this backend type.");
21 return;
22 }
23
24 if (!Playground::ShouldOpenNewPlaygrounds()) {
25 GTEST_SKIP_("Skipping due to user action.");
26 return;
27 }
28
29 ImpellerValidationErrorsSetFatal(true);
30
31 SetupContext(GetParam());
32 SetupWindow();
33 }
34
35 PlaygroundBackend PlaygroundTest::GetBackend() const {
36 return GetParam();
37 }
38
39 void PlaygroundTest::TearDown() {
40 TeardownWindow();
41 }
42
43 // |Playground|
44 std::unique_ptr<fml::Mapping> PlaygroundTest::OpenAssetAsMapping(
45 std::string asset_name) const {
46 return flutter::testing::OpenFixtureAsMapping(asset_name);
47 }
48
49 RuntimeStage::Map PlaygroundTest::OpenAssetAsRuntimeStage(
50 const char* asset_name) const {
51 const std::shared_ptr<fml::Mapping> fixture =
52 flutter::testing::OpenFixtureAsMapping(asset_name);
53 if (!fixture || fixture->GetSize() == 0) {
54 return {};
55 }
56 return RuntimeStage::DecodeRuntimeStages(fixture);
57 }
58
59 static std::string FormatWindowTitle(const std::string& test_name) {
60 std::stringstream stream;
61 stream << "Impeller Playground for '" << test_name << "' (Press ESC to quit)";
62 return stream.str();
63 }
64
65 // |Playground|
66 std::string PlaygroundTest::GetWindowTitle() const {
67 return FormatWindowTitle(flutter::testing::GetCurrentTestName());
68 }
69
70 // |Playground|
71 bool PlaygroundTest::ShouldKeepRendering() const {
72 if (!switches_.timeout.has_value()) {
73 return true;
74 }
75
76 if (SecondsF{GetSecondsElapsed()} > switches_.timeout.value()) {
77 return false;
78 }
79
80 return true;
81 }
82
83 } // namespace impeller
timing.h
impeller::Playground::ShouldOpenNewPlaygrounds
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:152
impeller::Playground::GetSecondsElapsed
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
Definition: playground.cc:181
impeller::RuntimeStage::DecodeRuntimeStages
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
Definition: runtime_stage.cc:72
impeller::PlaygroundBackend
PlaygroundBackend
Definition: playground.h:29
validation.h
impeller::PlaygroundTest::PlaygroundTest
PlaygroundTest()
Definition: playground_test.cc:13
impeller::PlaygroundTest::OpenAssetAsMapping
std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const override
Definition: playground_test.cc:44
impeller::PlaygroundTest::SetUp
void SetUp() override
Definition: playground_test.cc:18
impeller::SecondsF
std::chrono::duration< float > SecondsF
Definition: timing.h:13
impeller::PlaygroundTest::OpenAssetAsRuntimeStage
RuntimeStage::Map OpenAssetAsRuntimeStage(const char *asset_name) const
Definition: playground_test.cc:49
impeller::Playground
Definition: playground.h:50
impeller::FormatWindowTitle
static std::string FormatWindowTitle(const std::string &test_name)
Definition: compute_playground_test.cc:44
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:39
impeller::Playground::SetupWindow
void SetupWindow()
Definition: playground.cc:126
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:115
impeller::PlaygroundSwitches::timeout
std::optional< std::chrono::milliseconds > timeout
Definition: switches.h:21
impeller::PlaygroundTest::GetWindowTitle
std::string GetWindowTitle() const override
Definition: playground_test.cc:66
impeller::ImpellerValidationErrorsSetFatal
void ImpellerValidationErrorsSetFatal(bool fatal)
Definition: validation.cc:16
impeller::PlaygroundSwitches
Definition: switches.h:16
impeller::Playground::SetupContext
void SetupContext(PlaygroundBackend backend)
Definition: playground.cc:114
impeller::Playground::SupportsBackend
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:90
impeller::Playground::TeardownWindow
void TeardownWindow()
Definition: playground.cc:141
impeller::PlaygroundTest::~PlaygroundTest
virtual ~PlaygroundTest()
impeller
Definition: aiks_context.cc:10
playground_test.h
impeller::PlaygroundTest::GetBackend
PlaygroundBackend GetBackend() const
Definition: playground_test.cc:35
impeller::RuntimeStage::Map
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:22