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()}) {
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 
33 }
34 
35 namespace {
36 bool DoesSupportWideGamutTests() {
37 #ifdef __arm64__
38  return true;
39 #else
40  return false;
41 #endif
42 }
43 } // namespace
44 
46  if (!Playground::SupportsBackend(GetParam())) {
47  GTEST_SKIP() << "Playground doesn't support this backend type.";
48  return;
49  }
50 
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  switches.flags.antialiased_lines =
69  test_name.find("ExperimentAntialiasLines/") != std::string::npos;
70 
71  SetupContext(GetParam(), switches);
72  SetupWindow();
73 }
74 
76  return GetParam();
77 }
78 
81 }
82 
83 // |Playground|
84 std::unique_ptr<fml::Mapping> PlaygroundTest::OpenAssetAsMapping(
85  std::string asset_name) const {
86  return flutter::testing::OpenFixtureAsMapping(asset_name);
87 }
88 
90  const char* asset_name) const {
91  const std::shared_ptr<fml::Mapping> fixture =
92  flutter::testing::OpenFixtureAsMapping(asset_name);
93  if (!fixture || fixture->GetSize() == 0) {
94  return {};
95  }
96  return RuntimeStage::DecodeRuntimeStages(fixture);
97 }
98 
99 // |Playground|
100 std::string PlaygroundTest::GetWindowTitle() const {
101  std::stringstream stream;
102  stream << "Impeller Playground for '"
103  << flutter::testing::GetCurrentTestName() << "' ";
104  switch (GetBackend()) {
106  break;
108  if (switches_.use_angle) {
109  stream << " (Angle) ";
110  }
111  break;
114  stream << " (SwiftShader) ";
115  }
116  break;
117  }
118  stream << " (Press ESC to quit)";
119  return stream.str();
120 }
121 
122 // |Playground|
123 bool PlaygroundTest::ShouldKeepRendering() const {
124  if (!switches_.timeout.has_value()) {
125  return true;
126  }
127 
128  if (SecondsF{GetSecondsElapsed()} > switches_.timeout.value()) {
129  return false;
130  }
131 
132  return true;
133 }
134 
135 } // namespace impeller
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:164
void SetupContext(PlaygroundBackend backend, const PlaygroundSwitches &switches)
Definition: playground.cc:125
const PlaygroundSwitches switches_
Definition: playground.h:131
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:101
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
Definition: playground.cc:193
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
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:24
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback)
Sets a callback that callers (usually tests) can set to intercept validation failures.
Definition: validation.cc:21
PlaygroundBackend
Definition: playground.h:27
std::chrono::duration< float > SecondsF
Definition: timing.h:13
bool antialiased_lines
When turned on DrawLine will use the experimental antialiased path.
Definition: flags.h:14
std::optional< std::chrono::milliseconds > timeout
Definition: switches.h:21