| 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 namespace {
19 bool DoesSupportWideGamutTests() {
20 #ifdef __arm64__
21 return true;
22 #else
23 return false;
24 #endif
25 }
26 } // namespace
27
28 void PlaygroundTest::SetUp() {
29 if (!Playground::SupportsBackend(GetParam())) {
30 GTEST_SKIP_("Playground doesn't support this backend type.");
31 return;
32 }
33
34 if (!Playground::ShouldOpenNewPlaygrounds()) {
35 GTEST_SKIP_("Skipping due to user action.");
36 return;
37 }
38
39 ImpellerValidationErrorsSetFatal(true);
40
41 // Test names that end with "WideGamut" will render with wide gamut support.
42 std::string test_name = flutter::testing::GetCurrentTestName();
43 PlaygroundSwitches switches = switches_;
44 switches.enable_wide_gamut =
45 test_name.find("WideGamut/") != std::string::npos;
46
47 if (switches.enable_wide_gamut && (GetParam() != PlaygroundBackend::kMetal ||
48 !DoesSupportWideGamutTests())) {
49 GTEST_SKIP_("This backend doesn't yet support wide gamut.");
50 return;
51 }
52
53 SetupContext(GetParam(), switches);
54 SetupWindow();
55 }
56
57 PlaygroundBackend PlaygroundTest::GetBackend() const {
58 return GetParam();
59 }
60
61 void PlaygroundTest::TearDown() {
62 TeardownWindow();
63 }
64
65 // |Playground|
66 std::unique_ptr<fml::Mapping> PlaygroundTest::OpenAssetAsMapping(
67 std::string asset_name) const {
68 return flutter::testing::OpenFixtureAsMapping(asset_name);
69 }
70
71 RuntimeStage::Map PlaygroundTest::OpenAssetAsRuntimeStage(
72 const char* asset_name) const {
73 const std::shared_ptr<fml::Mapping> fixture =
74 flutter::testing::OpenFixtureAsMapping(asset_name);
75 if (!fixture || fixture->GetSize() == 0) {
76 return {};
77 }
78 return RuntimeStage::DecodeRuntimeStages(fixture);
79 }
80
81 // |Playground|
82 std::string PlaygroundTest::GetWindowTitle() const {
83 std::stringstream stream;
84 stream << "Impeller Playground for '"
85 << flutter::testing::GetCurrentTestName() << "' ";
86 switch (GetBackend()) {
87 case PlaygroundBackend::kMetal:
88 break;
89 case PlaygroundBackend::kOpenGLES:
90 if (switches_.use_angle) {
91 stream << " (Angle) ";
92 }
93 break;
94 case PlaygroundBackend::kVulkan:
95 if (switches_.use_swiftshader) {
96 stream << " (SwiftShader) ";
97 }
98 break;
99 }
100 stream << " (Press ESC to quit)";
101 return stream.str();
102 }
103
104 // |Playground|
105 bool PlaygroundTest::ShouldKeepRendering() const {
106 if (!switches_.timeout.has_value()) {
107 return true;
108 }
109
110 if (SecondsF{GetSecondsElapsed()} > switches_.timeout.value()) {
111 return false;
112 }
113
114 return true;
115 }
116
117 } // namespace impeller
timing.h
impeller::Playground::ShouldOpenNewPlaygrounds
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:167
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:196
impeller::RuntimeStage::DecodeRuntimeStages
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
Definition: runtime_stage.cc:61
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PlaygroundSwitches::enable_wide_gamut
bool enable_wide_gamut
Definition: switches.h:35
impeller::PlaygroundBackend
PlaygroundBackend
Definition: playground.h:27
validation.h
impeller::PlaygroundSwitches::use_swiftshader
bool use_swiftshader
Definition: switches.h:27
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:66
impeller::PlaygroundTest::SetUp
void SetUp() override
Definition: playground_test.cc:28
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:71
impeller::Playground
Definition: playground.h:48
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:61
impeller::Playground::SetupWindow
void SetupWindow()
Definition: playground.cc:137
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:118
impeller::PlaygroundSwitches::timeout
std::optional< std::chrono::milliseconds > timeout
Definition: switches.h:20
impeller::Playground::SetupContext
void SetupContext(PlaygroundBackend backend, const PlaygroundSwitches &switches)
Definition: playground.cc:124
impeller::PlaygroundSwitches::use_angle
bool use_angle
Definition: switches.h:33
impeller::PlaygroundTest::GetWindowTitle
std::string GetWindowTitle() const override
Definition: playground_test.cc:82
impeller::ImpellerValidationErrorsSetFatal
void ImpellerValidationErrorsSetFatal(bool fatal)
Definition: validation.cc:16
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
impeller::PlaygroundSwitches
Definition: switches.h:15
impeller::Playground::SupportsBackend
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:100
impeller::Playground::TeardownWindow
void TeardownWindow()
Definition: playground.cc:156
impeller::PlaygroundTest::~PlaygroundTest
virtual ~PlaygroundTest()
impeller
Definition: aiks_blend_unittests.cc:18
playground_test.h
impeller::PlaygroundTest::GetBackend
PlaygroundBackend GetBackend() const
Definition: playground_test.cc:57
impeller::RuntimeStage::Map
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:24