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"
10 
11 namespace impeller {
12 
14  : Playground(PlaygroundSwitches{flutter::testing::GetArgsForProcess()}) {}
15 
17 
19  if (!Playground::SupportsBackend(GetParam())) {
20  GTEST_SKIP_("Playground doesn't support this backend type.");
21  return;
22  }
23 
25  GTEST_SKIP_("Skipping due to user action.");
26  return;
27  }
28 
30 
31  SetupContext(GetParam());
32  SetupWindow();
33 }
34 
36  return GetParam();
37 }
38 
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 std::shared_ptr<RuntimeStage> PlaygroundTest::OpenAssetAsRuntimeStage(
50  const char* asset_name) const {
51  auto fixture = flutter::testing::OpenFixtureAsMapping(asset_name);
52  if (!fixture || fixture->GetSize() == 0) {
53  return nullptr;
54  }
55  auto stage = std::make_unique<RuntimeStage>(std::move(fixture));
56  if (!stage->IsValid()) {
57  return nullptr;
58  }
59  return stage;
60 }
61 
62 static std::string FormatWindowTitle(const std::string& test_name) {
63  std::stringstream stream;
64  stream << "Impeller Playground for '" << test_name << "' (Press ESC to quit)";
65  return stream.str();
66 }
67 
68 // |Playground|
69 std::string PlaygroundTest::GetWindowTitle() const {
70  return FormatWindowTitle(flutter::testing::GetCurrentTestName());
71 }
72 
73 // |Playground|
74 bool PlaygroundTest::ShouldKeepRendering() const {
75  if (!switches_.timeout.has_value()) {
76  return true;
77  }
78 
79  if (SecondsF{GetSecondsElapsed()} > switches_.timeout.value()) {
80  return false;
81  }
82 
83  return true;
84 }
85 
86 } // 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::PlaygroundBackend
PlaygroundBackend
Definition: playground.h:25
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:12
impeller::Playground
Definition: playground.h:33
impeller::FormatWindowTitle
static std::string FormatWindowTitle(const std::string &test_name)
Definition: compute_playground_test.cc:57
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:39
impeller::PlaygroundTest::OpenAssetAsRuntimeStage
std::shared_ptr< RuntimeStage > OpenAssetAsRuntimeStage(const char *asset_name) const
Definition: playground_test.cc:49
impeller::Playground::SetupWindow
void SetupWindow()
Definition: playground.cc:126
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:91
impeller::PlaygroundSwitches::timeout
std::optional< std::chrono::milliseconds > timeout
Definition: switches.h:20
impeller::PlaygroundTest::GetWindowTitle
std::string GetWindowTitle() const override
Definition: playground_test.cc:69
impeller::ImpellerValidationErrorsSetFatal
void ImpellerValidationErrorsSetFatal(bool fatal)
Definition: validation.cc:16
impeller::PlaygroundSwitches
Definition: switches.h:15
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