| Flutter Impeller |

Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
impeller::GoldenPlaygroundTest Class Reference

`#include <golden_playground_test.h>`

Inheritance diagram for impeller::GoldenPlaygroundTest:

## Classes
struct | GoldenPlaygroundTestImpl

## Public Types
using | AiksPlaygroundCallback = std::function< std::optional< Picture >(AiksContext &renderer)>
using | AiksDlPlaygroundCallback = std::function< sk_sp< flutter::DisplayList >()>

## Public Member Functions
| GoldenPlaygroundTest ()
| ~GoldenPlaygroundTest () override
void | SetUp ()
void | TearDown ()
PlaygroundBackend | GetBackend () const
void | SetTypographerContext (std::shared_ptr< TypographerContext > typographer_context)
bool | OpenPlaygroundHere (Picture picture)
bool | OpenPlaygroundHere (AiksPlaygroundCallback callback)
bool | OpenPlaygroundHere (const AiksDlPlaygroundCallback &callback)
bool | OpenPlaygroundHere (const sk_sp< flutter::DisplayList > &list)
std::unique_ptr< testing::Screenshot > | MakeScreenshot (const sk_sp< flutter::DisplayList > &list)
std::shared_ptr< Texture > | CreateTextureForFixture (const char *fixture_name, bool enable_mipmapping=false) const
sk_sp< flutter::DlImage > | CreateDlImageForFixture (const char *fixture_name, bool enable_mipmapping=false) const
RuntimeStage::Map | OpenAssetAsRuntimeStage (const char *asset_name) const
std::shared_ptr< Context > | GetContext () const
std::shared_ptr< Context > | MakeContext () const
Point | GetContentScale () const
Scalar | GetSecondsElapsed () const
ISize | GetWindowSize () const
fml::Status | SetCapabilities (const std::shared_ptr< Capabilities > &capabilities)
bool | WillRenderSomething () const
| Returns true if `OpenPlaygroundHere` will actually render anything. More...

## Static Public Member Functions
static bool | SaveScreenshot (std::unique_ptr< testing::Screenshot > screenshot, const std::string &postfix="")
static bool | ImGuiBegin (const char *name, bool *p_open, ImGuiWindowFlags flags)

## Protected Member Functions
void | SetWindowSize (ISize size)

## Detailed Description

Definition at line 26 of file golden_playground_test.h.

## Member Typedef Documentation

## ◆ AiksDlPlaygroundCallback

using impeller::GoldenPlaygroundTest::AiksDlPlaygroundCallback = std::function<sk_sp<flutter::DisplayList>()>

Definition at line 32 of file golden_playground_test.h.

## ◆ AiksPlaygroundCallback

using impeller::GoldenPlaygroundTest::AiksPlaygroundCallback = std::function<std::optional<Picture>(AiksContext& renderer)>

Definition at line 29 of file golden_playground_test.h.

## Constructor & Destructor Documentation

## ◆ GoldenPlaygroundTest()

impeller::GoldenPlaygroundTest::GoldenPlaygroundTest | ( |  | ) |
| default

Definition at line 122 of file golden_playground_test_mac.cc.

123 : typographer_context_(TypographerContextSkia::Make()),
124 pimpl_(new GoldenPlaygroundTest::GoldenPlaygroundTestImpl()) {}
impeller::TypographerContextSkia::Make
static std::shared_ptr< TypographerContext > Make()
Definition: typographer_context_skia.cc:76

## ◆ ~GoldenPlaygroundTest()

impeller::GoldenPlaygroundTest::~GoldenPlaygroundTest | ( |  | ) |
| override default

## Member Function Documentation

## ◆ CreateDlImageForFixture()

sk_sp< flutter::DlImage > impeller::GoldenPlaygroundTest::CreateDlImageForFixture | ( | const char * | fixture_name,
|  | bool | enable_mipmapping = `false`
| ) |  | const

Definition at line 269 of file golden_playground_test_mac.cc.

271 {
272 std::shared_ptr<Texture> texture =
273 CreateTextureForFixture(fixture_name, enable_mipmapping);
274 return DlImageImpeller::Make(texture);
275 }
impeller::DlImageImpeller::Make
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Definition: dl_image_impeller.cc:23
impeller::GoldenPlaygroundTest::CreateTextureForFixture
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: golden_playground_test_mac.cc:256

References CreateTextureForFixture(), and impeller::DlImageImpeller::Make().

## ◆ CreateTextureForFixture()

std::shared_ptr< Texture > impeller::GoldenPlaygroundTest::CreateTextureForFixture | ( | const char * | fixture_name,
|  | bool | enable_mipmapping = `false`
| ) |  | const

Definition at line 256 of file golden_playground_test_mac.cc.

258 {
259 std::shared_ptr<fml::Mapping> mapping =
260 flutter::testing::OpenFixtureAsMapping(fixture_name);
261 auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
262 enable_mipmapping);
263 if (result) {
264 result->SetLabel(fixture_name);
265 }
266 return result;
267 }
impeller::GoldenPlaygroundTest::GetContext
std::shared_ptr< Context > GetContext() const
Definition: golden_playground_test_mac.cc:287
impeller::Playground::CreateTextureForMapping
static std::shared_ptr< Texture > CreateTextureForMapping(const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
Definition: playground.cc:433

References impeller::Playground::CreateTextureForMapping(), and GetContext().

Referenced by CreateDlImageForFixture().

## ◆ GetBackend()

PlaygroundBackend impeller::GoldenPlaygroundTest::GetBackend | ( |  | ) | const

Definition at line 221 of file golden_playground_test_mac.cc.

221 {
222 return GetParam();
223 }

## ◆ GetContentScale()

Point impeller::GoldenPlaygroundTest::GetContentScale | ( |  | ) | const

Definition at line 313 of file golden_playground_test_mac.cc.

313 {
314 return pimpl_->screenshotter->GetPlayground().GetContentScale();
315 }

## ◆ GetContext()

std::shared_ptr< Context > impeller::GoldenPlaygroundTest::GetContext | ( |  | ) | const

Definition at line 287 of file golden_playground_test_mac.cc.

287 {
288 if (!pimpl_->screenshotter) {
289 return nullptr;
290 }
291 return pimpl_->screenshotter->GetPlayground().GetContext();
292 }

Referenced by CreateTextureForFixture(), MakeContext(), MakeScreenshot(), OpenPlaygroundHere(), SetUp(), and TearDown().

## ◆ GetSecondsElapsed()

Scalar impeller::GoldenPlaygroundTest::GetSecondsElapsed | ( |  | ) | const

Definition at line 317 of file golden_playground_test_mac.cc.

317 {
318 return 0.0f;
319 }

## ◆ GetWindowSize()

ISize impeller::GoldenPlaygroundTest::GetWindowSize | ( |  | ) | const

Definition at line 321 of file golden_playground_test_mac.cc.

321 {
322 return pimpl_->window_size;
323 }

## ◆ ImGuiBegin()

bool impeller::GoldenPlaygroundTest::ImGuiBegin | ( | const char * | name,
|  | bool * | p_open,
|  | ImGuiWindowFlags | flags
| ) |  |
| static

Definition at line 250 of file golden_playground_test_mac.cc.

252 {
253 return false;
254 }

## ◆ MakeContext()

std::shared_ptr< Context > impeller::GoldenPlaygroundTest::MakeContext | ( |  | ) | const

On Metal we create a context for each test.

On OpenGL we create a context for each test.

Definition at line 294 of file golden_playground_test_mac.cc.

294 {
295 if (GetParam() == PlaygroundBackend::kMetal) {
296 /// On Metal we create a context for each test.
297 return GetContext();
298 } else if (GetParam() == PlaygroundBackend::kVulkan) {
299 bool enable_vulkan_validations = true;
300 FML_CHECK(!pimpl_->test_vulkan_playground)
301 << "We don't support creating multiple contexts for one test";
302 pimpl_->test_vulkan_playground =
303 MakeVulkanPlayground(enable_vulkan_validations);
304 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
305 pimpl_->test_vulkan_playground);
306 return pimpl_->test_vulkan_playground->GetContext();
307 } else {
308 /// On OpenGL we create a context for each test.
309 return GetContext();
310 }
311 }
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PlaygroundBackend::kVulkan
@ kVulkan

References GetContext(), impeller::kMetal, and impeller::kVulkan.

## ◆ MakeScreenshot()

std::unique_ptr< testing::Screenshot > impeller::GoldenPlaygroundTest::MakeScreenshot | ( | const sk_sp< flutter::DisplayList > & | list | ) |

Definition at line 334 of file golden_playground_test_mac.cc.

335 {
336 AiksContext renderer(GetContext(), typographer_context_);
337 Point content_scale =
338 pimpl_->screenshotter->GetPlayground().GetContentScale();
339
340 ISize physical_window_size(
341 std::round(pimpl_->window_size.width * content_scale.x),
342 std::round(pimpl_->window_size.height * content_scale.y));
343 return pimpl_->screenshotter->MakeScreenshot(
344 renderer, DisplayListToTexture(list, physical_window_size, renderer));
345 }
impeller::DisplayListToTexture
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips)
Render the provided display list to a texture with the given size.
Definition: dl_dispatcher.cc:1224
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::ISize
ISize64 ISize
Definition: size.h:162

References impeller::DisplayListToTexture(), GetContext(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ OpenAssetAsRuntimeStage()

RuntimeStage::Map impeller::GoldenPlaygroundTest::OpenAssetAsRuntimeStage | ( | const char * | asset_name | ) | const

Definition at line 277 of file golden_playground_test_mac.cc.

278 {
279 const std::shared_ptr<fml::Mapping> fixture =
280 flutter::testing::OpenFixtureAsMapping(asset_name);
281 if (!fixture || fixture->GetSize() == 0) {
282 return {};
283 }
284 return RuntimeStage::DecodeRuntimeStages(fixture);
285 }
impeller::RuntimeStage::DecodeRuntimeStages
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
Definition: runtime_stage.cc:62

References impeller::RuntimeStage::DecodeRuntimeStages().

## ◆ OpenPlaygroundHere() [1/4]

bool impeller::GoldenPlaygroundTest::OpenPlaygroundHere | ( | AiksPlaygroundCallback | callback | ) |

## ◆ OpenPlaygroundHere() [2/4]

bool impeller::GoldenPlaygroundTest::OpenPlaygroundHere | ( | const AiksDlPlaygroundCallback & | callback | ) |

Definition at line 225 of file golden_playground_test_mac.cc.

226 {
227 AiksContext renderer(GetContext(), typographer_context_);
228
229 std::unique_ptr<testing::Screenshot> screenshot;
230 Point content_scale =
231 pimpl_->screenshotter->GetPlayground().GetContentScale();
232
233 ISize physical_window_size(
234 std::round(pimpl_->window_size.width * content_scale.x),
235 std::round(pimpl_->window_size.height * content_scale.y));
236 for (int i = 0; i < 2; ++i) {
237 auto display_list = callback();
238 auto texture =
239 DisplayListToTexture(display_list, physical_window_size, renderer);
240 screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, texture);
241 }
242 return SaveScreenshot(std::move(screenshot));
243 }
impeller::GoldenPlaygroundTest::SaveScreenshot
static bool SaveScreenshot(std::unique_ptr< testing::Screenshot > screenshot, const std::string &postfix="")
Definition: golden_playground_test_mac.cc:96

References impeller::DisplayListToTexture(), GetContext(), SaveScreenshot(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## ◆ OpenPlaygroundHere() [3/4]

bool impeller::GoldenPlaygroundTest::OpenPlaygroundHere | ( | const sk_sp< flutter::DisplayList > & | list | ) |

Definition at line 245 of file golden_playground_test_mac.cc.

246 {
247 return OpenPlaygroundHere([&list]() { return list; });
248 }
impeller::GoldenPlaygroundTest::OpenPlaygroundHere
bool OpenPlaygroundHere(Picture picture)

References OpenPlaygroundHere().

## ◆ OpenPlaygroundHere() [4/4]

bool impeller::GoldenPlaygroundTest::OpenPlaygroundHere | ( | Picture | picture | ) |

Referenced by OpenPlaygroundHere().

## ◆ SaveScreenshot()

bool impeller::GoldenPlaygroundTest::SaveScreenshot | ( | std::unique_ptr< testing::Screenshot > | screenshot,
|  | const std::string & | postfix = `""`
| ) |  |
| static

Definition at line 96 of file golden_playground_test_mac.cc.

98 {
99 if (!screenshot || !screenshot->GetBytes()) {
100 FML_LOG(ERROR) << "Failed to collect screenshot for test " << GetTestName();
101 return false;
102 }
103 std::string test_name = GetTestName();
104 std::string filename = GetGoldenFilename(postfix);
105 testing::GoldenDigest::Instance()->AddImage(
106 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
107 if (!screenshot->WriteToPNG(
108 testing::WorkingDirectory::Instance()->GetFilenamePath(filename))) {
109 FML_LOG(ERROR) << "Failed to write screenshot to " << filename;
110 return false;
111 }
112 return true;
113 }
impeller::testing::GoldenDigest::Instance
static GoldenDigest * Instance()
Definition: golden_digest.cc:18
impeller::testing::GoldenDigest::AddImage
void AddImage(const std::string &test_name, const std::string &filename, int32_t width, int32_t height)
Definition: golden_digest.cc:34
impeller::testing::WorkingDirectory::GetFilenamePath
std::string GetFilenamePath(const std::string &filename) const
Definition: working_directory.cc:23
impeller::testing::WorkingDirectory::Instance
static WorkingDirectory * Instance()
Definition: working_directory.cc:16

References impeller::testing::GoldenDigest::AddImage(), impeller::testing::WorkingDirectory::GetFilenamePath(), impeller::testing::GoldenDigest::Instance(), and impeller::testing::WorkingDirectory::Instance().

Referenced by OpenPlaygroundHere().

## ◆ SetCapabilities()

fml::Status impeller::GoldenPlaygroundTest::SetCapabilities | ( | const std::shared_ptr< Capabilities > & | capabilities | ) |

Definition at line 329 of file golden_playground_test_mac.cc.

330 {
331 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
332 }

## ◆ SetTypographerContext()

void impeller::GoldenPlaygroundTest::SetTypographerContext | ( | std::shared_ptr< TypographerContext > | typographer_context | ) |

Definition at line 128 of file golden_playground_test_mac.cc.

129 {
130 typographer_context_ = std::move(typographer_context);
131 };

## ◆ SetUp()

void impeller::GoldenPlaygroundTest::SetUp | ( |  | ) |

Definition at line 152 of file golden_playground_test_mac.cc.

152 {
153 std::filesystem::path testing_assets_path =
154 flutter::testing::GetTestingAssetsPath();
155 std::filesystem::path target_path = testing_assets_path.parent_path()
156 .parent_path()
157 .parent_path()
158 .parent_path();
159 std::filesystem::path icd_path = target_path / "vk_swiftshader_icd.json";
160 setenv("VK_ICD_FILENAMES", icd_path.c_str(), 1);
161
162 std::string test_name = GetTestName();
163 PlaygroundSwitches switches;
164 switches.enable_wide_gamut =
165 test_name.find("WideGamut_") != std::string::npos;
166 switches.flags.antialiased_lines =
167 test_name.find("ExperimentAntialiasLines_") != std::string::npos;
168 switch (GetParam()) {
169 case PlaygroundBackend::kMetal:
170 if (!DoesSupportWideGamutTests()) {
171 GTEST_SKIP()
172 << "This metal device doesn't support wide gamut golden tests.";
173 }
174 pimpl_->screenshotter =
175 std::make_unique<testing::MetalScreenshotter>(switches);
176 break;
177 case PlaygroundBackend::kVulkan: {
178 if (switches.enable_wide_gamut) {
179 GTEST_SKIP() << "Vulkan doesn't support wide gamut golden tests.";
180 }
181 if (switches.flags.antialiased_lines) {
182 GTEST_SKIP()
183 << "Vulkan doesn't support antialiased lines golden tests.";
184 }
185 const std::unique_ptr<PlaygroundImpl>& playground =
186 GetSharedVulkanPlayground(/*enable_validations=*/true);
187 pimpl_->screenshotter =
188 std::make_unique<testing::VulkanScreenshotter>(playground);
189 break;
190 }
191 case PlaygroundBackend::kOpenGLES: {
192 if (switches.enable_wide_gamut) {
193 GTEST_SKIP() << "OpenGLES doesn't support wide gamut golden tests.";
194 }
195 if (switches.flags.antialiased_lines) {
196 GTEST_SKIP()
197 << "OpenGLES doesn't support antialiased lines golden tests.";
198 }
199 FML_CHECK(::glfwInit() == GLFW_TRUE);
200 PlaygroundSwitches playground_switches;
201 playground_switches.use_angle = true;
202 pimpl_->test_opengl_playground = PlaygroundImpl::Create(
203 PlaygroundBackend::kOpenGLES, playground_switches);
204 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
205 pimpl_->test_opengl_playground);
206 break;
207 }
208 }
209
210 if (std::find(kSkipTests.begin(), kSkipTests.end(), test_name) !=
211 kSkipTests.end()) {
212 GTEST_SKIP()
213 << "GoldenPlaygroundTest doesn't support interactive playground tests "
214 "yet.";
215 }
216
217 testing::GoldenDigest::Instance()->AddDimension(
218 "gpu_string", GetContext()->DescribeGpuModel());
219 }
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:25
impeller::testing::GoldenDigest::AddDimension
void AddDimension(const std::string &name, const std::string &value)
Definition: golden_digest.cc:27
impeller::kSkipTests
static const std::vector< std::string > kSkipTests
Definition: golden_playground_test_mac.cc:69
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES

References impeller::testing::GoldenDigest::AddDimension(), impeller::Flags::antialiased_lines, impeller::PlaygroundImpl::Create(), impeller::PlaygroundSwitches::enable_wide_gamut, impeller::PlaygroundSwitches::flags, GetContext(), impeller::testing::GoldenDigest::Instance(), impeller::kMetal, impeller::kOpenGLES, impeller::kSkipTests, impeller::kVulkan, and impeller::PlaygroundSwitches::use_angle.

## ◆ SetWindowSize()

void impeller::GoldenPlaygroundTest::SetWindowSize | ( | ISize | size | ) |
| protected

Definition at line 71 of file golden_playground_test_stub.cc.

71 {}

## ◆ TearDown()

void impeller::GoldenPlaygroundTest::TearDown | ( |  | ) |

Definition at line 133 of file golden_playground_test_mac.cc.

133 {
134 ASSERT_FALSE(dlopen("/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
135
136 auto context = GetContext();
137 if (context) {
138 context->DisposeThreadLocalCachedResources();
139 }
140 }

References GetContext().

## ◆ WillRenderSomething()

bool impeller::GoldenPlaygroundTest::WillRenderSomething | ( |  | ) | const
| inline

Returns true if `OpenPlaygroundHere` will actually render anything.

Definition at line 89 of file golden_playground_test.h.

89 { return true; }

The documentation for this class was generated from the following files:

- impeller/golden_tests/golden_playground_test.h
- impeller/golden_tests/golden_playground_test_mac.cc
- impeller/golden_tests/golden_playground_test_stub.cc