| 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 30 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()) {}

## ◆ ~GoldenPlaygroundTest()

impeller::GoldenPlaygroundTest::~GoldenPlaygroundTest | ( |  | ) |
| overridedefault

## Member Function Documentation

## ◆ CreateDlImageForFixture()

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

Definition at line 246 of file golden_playground_test_mac.cc.

248 {
249 std::shared_ptr<Texture> texture =
250 CreateTextureForFixture(fixture_name, enable_mipmapping);
251 return DlImageImpeller::Make(texture);
252 }

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 233 of file golden_playground_test_mac.cc.

235 {
236 std::shared_ptr<fml::Mapping> mapping =
237 flutter::testing::OpenFixtureAsMapping(fixture_name);
238 auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
239 enable_mipmapping);
240 if (result) {
241 result->SetLabel(fixture_name);
242 }
243 return result;
244 }

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

Referenced by CreateDlImageForFixture().

## ◆ GetBackend()

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

Definition at line 204 of file golden_playground_test_mac.cc.

204 {
205 return GetParam();
206 }

## ◆ GetContentScale()

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

Definition at line 287 of file golden_playground_test_mac.cc.

287 {
288 return pimpl_->screenshotter->GetPlayground().GetContentScale();
289 }

## ◆ GetContext()

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

Definition at line 264 of file golden_playground_test_mac.cc.

264 {
265 return pimpl_->screenshotter->GetPlayground().GetContext();
266 }

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

## ◆ GetSecondsElapsed()

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

Definition at line 291 of file golden_playground_test_mac.cc.

291 {
292 return 0.0f;
293 }

## ◆ GetWindowSize()

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

Definition at line 295 of file golden_playground_test_mac.cc.

295 {
296 return pimpl_->window_size;
297 }

## ◆ ImGuiBegin()

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

Definition at line 227 of file golden_playground_test_mac.cc.

229 {
230 return false;
231 }

## ◆ 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 268 of file golden_playground_test_mac.cc.

268 {
269 if (GetParam() == PlaygroundBackend::kMetal) {
270 /// On Metal we create a context for each test.
271 return GetContext();
272 } else if (GetParam() == PlaygroundBackend::kVulkan) {
273 bool enable_vulkan_validations = true;
274 FML_CHECK(!pimpl_->test_vulkan_playground)
275 << "We don't support creating multiple contexts for one test";
276 pimpl_->test_vulkan_playground =
277 MakeVulkanPlayground(enable_vulkan_validations);
278 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
279 pimpl_->test_vulkan_playground);
280 return pimpl_->test_vulkan_playground->GetContext();
281 } else {
282 /// On OpenGL we create a context for each test.
283 return GetContext();
284 }
285 }

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 308 of file golden_playground_test_mac.cc.

309 {
310 AiksContext renderer(GetContext(), typographer_context_);
311
312 return pimpl_->screenshotter->MakeScreenshot(
313 renderer, DisplayListToTexture(list, pimpl_->window_size, renderer));
314 }

References impeller::DisplayListToTexture(), and GetContext().

## ◆ OpenAssetAsRuntimeStage()

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

Definition at line 254 of file golden_playground_test_mac.cc.

255 {
256 const std::shared_ptr<fml::Mapping> fixture =
257 flutter::testing::OpenFixtureAsMapping(asset_name);
258 if (!fixture || fixture->GetSize() == 0) {
259 return {};
260 }
261 return RuntimeStage::DecodeRuntimeStages(fixture);
262 }

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 208 of file golden_playground_test_mac.cc.

209 {
210 AiksContext renderer(GetContext(), typographer_context_);
211
212 std::unique_ptr<testing::Screenshot> screenshot;
213 for (int i = 0; i < 2; ++i) {
214 auto display_list = callback();
215 auto texture =
216 DisplayListToTexture(display_list, pimpl_->window_size, renderer);
217 screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, texture);
218 }
219 return SaveScreenshot(std::move(screenshot));
220 }

References impeller::DisplayListToTexture(), GetContext(), and SaveScreenshot().

## ◆ OpenPlaygroundHere() [3/4]

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

Definition at line 222 of file golden_playground_test_mac.cc.

223 {
224 return OpenPlaygroundHere([&list]() { return list; });
225 }

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 }

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

Referenced by OpenPlaygroundHere().

## ◆ SetCapabilities()

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

Definition at line 303 of file golden_playground_test_mac.cc.

304 {
305 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
306 }

## ◆ 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 147 of file golden_playground_test_mac.cc.

147 {
148 std::filesystem::path testing_assets_path =
149 flutter::testing::GetTestingAssetsPath();
150 std::filesystem::path target_path = testing_assets_path.parent_path()
151 .parent_path()
152 .parent_path()
153 .parent_path();
154 std::filesystem::path icd_path = target_path / "vk_swiftshader_icd.json";
155 setenv("VK_ICD_FILENAMES", icd_path.c_str(), 1);
156
157 std::string test_name = GetTestName();
158 bool enable_wide_gamut = test_name.find("WideGamut_") != std::string::npos;
159 switch (GetParam()) {
160 case PlaygroundBackend::kMetal:
161 if (!DoesSupportWideGamutTests()) {
162 GTEST_SKIP()
163 << "This metal device doesn't support wide gamut golden tests.";
164 }
165 pimpl_->screenshotter =
166 std::make_unique<testing::MetalScreenshotter>(enable_wide_gamut);
167 break;
168 case PlaygroundBackend::kVulkan: {
169 if (enable_wide_gamut) {
170 GTEST_SKIP() << "Vulkan doesn't support wide gamut golden tests.";
171 }
172 const std::unique_ptr<PlaygroundImpl>& playground =
173 GetSharedVulkanPlayground(/*enable_validations=*/true);
174 pimpl_->screenshotter =
175 std::make_unique<testing::VulkanScreenshotter>(playground);
176 break;
177 }
178 case PlaygroundBackend::kOpenGLES: {
179 if (enable_wide_gamut) {
180 GTEST_SKIP() << "OpenGLES doesn't support wide gamut golden tests.";
181 }
182 FML_CHECK(::glfwInit() == GLFW_TRUE);
183 PlaygroundSwitches playground_switches;
184 playground_switches.use_angle = true;
185 pimpl_->test_opengl_playground = PlaygroundImpl::Create(
186 PlaygroundBackend::kOpenGLES, playground_switches);
187 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
188 pimpl_->test_opengl_playground);
189 break;
190 }
191 }
192
193 if (std::find(kSkipTests.begin(), kSkipTests.end(), test_name) !=
194 kSkipTests.end()) {
195 GTEST_SKIP()
196 << "GoldenPlaygroundTest doesn't support interactive playground tests "
197 "yet.";
198 }
199
200 testing::GoldenDigest::Instance()->AddDimension(
201 "gpu_string", GetContext()->DescribeGpuModel());
202 }

References impeller::testing::GoldenDigest::AddDimension(), impeller::PlaygroundImpl::Create(), 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 }

## ◆ 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

impeller::PlaygroundBackend::kVulkan
@ kVulkan
impeller::RuntimeStage::DecodeRuntimeStages
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
Definition: runtime_stage.cc:61
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::GoldenPlaygroundTest::OpenPlaygroundHere
bool OpenPlaygroundHere(Picture picture)
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::GoldenPlaygroundTest::GetContext
std::shared_ptr< Context > GetContext() const
Definition: golden_playground_test_mac.cc:264
impeller::GoldenPlaygroundTest::SaveScreenshot
static bool SaveScreenshot(std::unique_ptr< testing::Screenshot > screenshot, const std::string &postfix="")
Definition: golden_playground_test_mac.cc:96
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::kSkipTests
static const std::vector< std::string > kSkipTests
Definition: golden_playground_test_mac.cc:69
impeller::testing::WorkingDirectory::GetFilenamePath
std::string GetFilenamePath(const std::string &filename) const
Definition: working_directory.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:233
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:25
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
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:429
impeller::testing::GoldenDigest::Instance
static GoldenDigest * Instance()
Definition: golden_digest.cc:18
impeller::testing::GoldenDigest::AddDimension
void AddDimension(const std::string &name, const std::string &value)
Definition: golden_digest.cc:27
impeller::testing::WorkingDirectory::Instance
static WorkingDirectory * Instance()
Definition: working_directory.cc:16
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:1195
impeller::TypographerContextSkia::Make
static std::shared_ptr< TypographerContext > Make()
Definition: typographer_context_skia.cc:75