| 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 ImpellerValidationErrorsSetCallback(
16 [](const char* message, const char* file, int line) -> bool {
17 // GTEST_MESSAGE_AT_ can only be used in a function that returns void.
18 // Hence the goofy lambda. The failure message and location will still
19 // be correct however.
20 //
21 // https://google.github.io/googletest/advanced.html#assertion-placement
22 [message, file, line]() -> void {
23 GTEST_MESSAGE_AT_(file, line, "Impeller Validation Error",
24 ::testing::TestPartResult::kFatalFailure)
25 << message;
26 }();
27 return true;
28 });
29 }
30
31 PlaygroundTest::~PlaygroundTest() {
32 ImpellerValidationErrorsSetCallback(nullptr);
33 }
34
35 namespace {
36 bool DoesSupportWideGamutTests() {
37 #ifdef __arm64__
38 return true;
39 #else
40 return false;
41 #endif
42 }
43 } // namespace
44
45 void PlaygroundTest::SetUp() {
46 if (!Playground::SupportsBackend(GetParam())) {
47 GTEST_SKIP() << "Playground doesn't support this backend type.";
48 return;
49 }
50
51 if (!Playground::ShouldOpenNewPlaygrounds()) {
52 GTEST_SKIP() << "Skipping due to user action.";
53 return;
54 }
55
56 // Test names that end with "WideGamut" will render with wide gamut support.
57 std::string test_name = flutter::testing::GetCurrentTestName();
58 PlaygroundSwitches switches = switches_;
59 switches.enable_wide_gamut =
60 test_name.find("WideGamut/") != std::string::npos;
61
62 if (switches.enable_wide_gamut && (GetParam() != PlaygroundBackend::kMetal ||
63 !DoesSupportWideGamutTests())) {
64 GTEST_SKIP() << "This backend doesn't yet support wide gamut.";
65 return;
66 }
67
68 SetupContext(GetParam(), switches);
69 SetupWindow();
70 }
71
72 PlaygroundBackend PlaygroundTest::GetBackend() const {
73 return GetParam();
74 }
75
76 void PlaygroundTest::TearDown() {
77 TeardownWindow();
78 }
79
80 // |Playground|
81 std::unique_ptr<fml::Mapping> PlaygroundTest::OpenAssetAsMapping(
82 std::string asset_name) const {
83 return flutter::testing::OpenFixtureAsMapping(asset_name);
84 }
85
86 RuntimeStage::Map PlaygroundTest::OpenAssetAsRuntimeStage(
87 const char* asset_name) const {
88 const std::shared_ptr<fml::Mapping> fixture =
89 flutter::testing::OpenFixtureAsMapping(asset_name);
90 if (!fixture || fixture->GetSize() == 0) {
91 return {};
92 }
93 return RuntimeStage::DecodeRuntimeStages(fixture);
94 }
95
96 // |Playground|
97 std::string PlaygroundTest::GetWindowTitle() const {
98 std::stringstream stream;
99 stream << "Impeller Playground for '"
100 << flutter::testing::GetCurrentTestName() << "' ";
101 switch (GetBackend()) {
102 case PlaygroundBackend::kMetal:
103 break;
104 case PlaygroundBackend::kOpenGLES:
105 if (switches_.use_angle) {
106 stream << " (Angle) ";
107 }
108 break;
109 case PlaygroundBackend::kVulkan:
110 if (switches_.use_swiftshader) {
111 stream << " (SwiftShader) ";
112 }
113 break;
114 }
115 stream << " (Press ESC to quit)";
116 return stream.str();
117 }
118
119 // |Playground|
120 bool PlaygroundTest::ShouldKeepRendering() const {
121 if (!switches_.timeout.has_value()) {
122 return true;
123 }
124
125 if (SecondsF{GetSecondsElapsed()} > switches_.timeout.value()) {
126 return false;
127 }
128
129 return true;
130 }
131
132 } // namespace impeller
timing.h
impeller::Playground::ShouldOpenNewPlaygrounds
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:164
impeller::PlaygroundBackend::kVulkan
@ kVulkan
playground_test.h
impeller::Playground::GetSecondsElapsed
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
Definition: playground.cc:193
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:81
impeller::PlaygroundTest::SetUp
void SetUp() override
Definition: playground_test.cc:45
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:86
impeller::Playground
Definition: playground.h:48
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:76
impeller::Playground::SetupWindow
void SetupWindow()
Definition: playground.cc:138
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:122
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:125
impeller::PlaygroundSwitches::use_angle
bool use_angle
Definition: switches.h:33
impeller::PlaygroundTest::GetWindowTitle
std::string GetWindowTitle() const override
Definition: playground_test.cc:97
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
impeller::PlaygroundSwitches
Definition: switches.h:15
impeller::Playground::SupportsBackend
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:101
impeller::Playground::TeardownWindow
void TeardownWindow()
Definition: playground.cc:151
impeller::PlaygroundTest::~PlaygroundTest
virtual ~PlaygroundTest()
Definition: playground_test.cc:31
impeller
Definition: allocation.cc:12
impeller::PlaygroundTest::GetBackend
PlaygroundBackend GetBackend() const
Definition: playground_test.cc:72
impeller::RuntimeStage::Map
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:24
impeller::ImpellerValidationErrorsSetCallback
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback)
Sets a callback that callers (usually tests) can set to intercept validation failures.
Definition: validation.cc:21