| 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 // |Playground|
60 std::string PlaygroundTest::GetWindowTitle() const {
61 std::stringstream stream;
62 stream << "Impeller Playground for '"
63 << flutter::testing::GetCurrentTestName() << "' ";
64 switch (GetBackend()) {
65 case PlaygroundBackend::kMetal:
66 break;
67 case PlaygroundBackend::kOpenGLES:
68 if (switches_.use_angle) {
69 stream << " (Angle) ";
70 }
71 break;
72 case PlaygroundBackend::kVulkan:
73 if (switches_.use_swiftshader) {
74 stream << " (SwiftShader) ";
75 }
76 break;
77 }
78 stream << " (Press ESC to quit)";
79 return stream.str();
80 }
81
82 // |Playground|
83 bool PlaygroundTest::ShouldKeepRendering() const {
84 if (!switches_.timeout.has_value()) {
85 return true;
86 }
87
88 if (SecondsF{GetSecondsElapsed()} > switches_.timeout.value()) {
89 return false;
90 }
91
92 return true;
93 }
94
95 } // namespace impeller
timing.h
impeller::Playground::ShouldOpenNewPlaygrounds
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:161
impeller::PlaygroundBackend::kVulkan
@ kVulkan
impeller::Playground::GetSecondsElapsed
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
Definition: playground.cc:190
impeller::RuntimeStage::DecodeRuntimeStages
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
Definition: runtime_stage.cc:60
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PlaygroundBackend
PlaygroundBackend
Definition: playground.h:29
validation.h
impeller::PlaygroundSwitches::use_swiftshader
bool use_swiftshader
Definition: switches.h:28
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::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:39
impeller::Playground::SetupWindow
void SetupWindow()
Definition: playground.cc:135
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:117
impeller::PlaygroundSwitches::timeout
std::optional< std::chrono::milliseconds > timeout
Definition: switches.h:21
impeller::PlaygroundSwitches::use_angle
bool use_angle
Definition: switches.h:34
impeller::PlaygroundTest::GetWindowTitle
std::string GetWindowTitle() const override
Definition: playground_test.cc:60
impeller::ImpellerValidationErrorsSetFatal
void ImpellerValidationErrorsSetFatal(bool fatal)
Definition: validation.cc:16
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
impeller::PlaygroundSwitches
Definition: switches.h:16
impeller::Playground::SetupContext
void SetupContext(PlaygroundBackend backend)
Definition: playground.cc:123
impeller::Playground::SupportsBackend
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:99
impeller::Playground::TeardownWindow
void TeardownWindow()
Definition: playground.cc:150
impeller::PlaygroundTest::~PlaygroundTest
virtual ~PlaygroundTest()
impeller
Definition: aiks_blur_unittests.cc:20
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:23