Flutter Engine
The Flutter Engine
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
10
11namespace impeller {
12
15
17
18namespace {
19bool DoesSupportWideGamutTests() {
20#ifdef __arm64__
21 return true;
22#else
23 return false;
24#endif
25}
26} // namespace
27
29 if (!Playground::SupportsBackend(GetParam())) {
30 GTEST_SKIP_("Playground doesn't support this backend type.");
31 return;
32 }
33
35 GTEST_SKIP_("Skipping due to user action.");
36 return;
37 }
38
40
41 // Test names that end with "WideGamut" will render with wide gamut support.
42 std::string test_name = flutter::testing::GetCurrentTestName();
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);
55}
56
58 return GetParam();
59}
60
63}
64
65// |Playground|
66std::unique_ptr<fml::Mapping> PlaygroundTest::OpenAssetAsMapping(
67 std::string asset_name) const {
69}
70
72 const char* asset_name) const {
73 const std::shared_ptr<fml::Mapping> fixture =
75 if (!fixture || fixture->GetSize() == 0) {
76 return {};
77 }
79}
80
81// |Playground|
82std::string PlaygroundTest::GetWindowTitle() const {
83 std::stringstream stream;
84 stream << "Impeller Playground for '"
86 switch (GetBackend()) {
88 break;
90 if (switches_.use_angle) {
91 stream << " (Angle) ";
92 }
93 break;
96 stream << " (SwiftShader) ";
97 }
98 break;
99 }
100 stream << " (Press ESC to quit)";
101 return stream.str();
102}
103
104// |Playground|
105bool 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
std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const override
std::string GetWindowTitle() const override
PlaygroundBackend GetBackend() const
RuntimeStage::Map OpenAssetAsRuntimeStage(const char *asset_name) const
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:167
void SetupContext(PlaygroundBackend backend, const PlaygroundSwitches &switches)
Definition: playground.cc:124
const PlaygroundSwitches switches_
Definition: playground.h:118
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:100
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
Definition: playground.cc:196
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:24
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:15
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
Definition: testing.cc:59
const fml::CommandLine & GetArgsForProcess()
Definition: test_args.cc:12
PlaygroundBackend
Definition: playground.h:27
std::chrono::duration< float > SecondsF
Definition: timing.h:13
void ImpellerValidationErrorsSetFatal(bool fatal)
Definition: validation.cc:16
std::optional< std::chrono::milliseconds > timeout
Definition: switches.h:20