| 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:77

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

265 {
266 std::shared_ptr<Texture> texture =
267 CreateTextureForFixture(fixture_name, enable_mipmapping);
268 return DlImageImpeller::Make(texture);
269 }
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:250

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

252 {
253 std::shared_ptr<fml::Mapping> mapping =
254 flutter::testing::OpenFixtureAsMapping(fixture_name);
255 auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
256 enable_mipmapping);
257 if (result) {
258 result->SetLabel(fixture_name);
259 }
260 return result;
261 }
impeller::GoldenPlaygroundTest::GetContext
std::shared_ptr< Context > GetContext() const
Definition: golden_playground_test_mac.cc:281
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:432

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

307 {
308 return pimpl_->screenshotter->GetPlayground().GetContentScale();
309 }

## ◆ GetContext()

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

Definition at line 281 of file golden_playground_test_mac.cc.

281 {
282 if (!pimpl_->screenshotter) {
283 return nullptr;
284 }
285 return pimpl_->screenshotter->GetPlayground().GetContext();
286 }

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

## ◆ GetSecondsElapsed()

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

Definition at line 311 of file golden_playground_test_mac.cc.

311 {
312 return 0.0f;
313 }

## ◆ GetWindowSize()

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

Definition at line 315 of file golden_playground_test_mac.cc.

315 {
316 return pimpl_->window_size;
317 }

## ◆ ImGuiBegin()

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

Definition at line 244 of file golden_playground_test_mac.cc.

246 {
247 return false;
248 }

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

288 {
289 if (GetParam() == PlaygroundBackend::kMetal) {
290 /// On Metal we create a context for each test.
291 return GetContext();
292 } else if (GetParam() == PlaygroundBackend::kVulkan) {
293 bool enable_vulkan_validations = true;
294 FML_CHECK(!pimpl_->test_vulkan_playground)
295 << "We don't support creating multiple contexts for one test";
296 pimpl_->test_vulkan_playground =
297 MakeVulkanPlayground(enable_vulkan_validations);
298 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
299 pimpl_->test_vulkan_playground);
300 return pimpl_->test_vulkan_playground->GetContext();
301 } else {
302 /// On OpenGL we create a context for each test.
303 return GetContext();
304 }
305 }
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 328 of file golden_playground_test_mac.cc.

329 {
330 AiksContext renderer(GetContext(), typographer_context_);
331
332 return pimpl_->screenshotter->MakeScreenshot(
333 renderer, DisplayListToTexture(list, pimpl_->window_size, renderer));
334 }
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:1291

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

## ◆ OpenAssetAsRuntimeStage()

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

Definition at line 271 of file golden_playground_test_mac.cc.

272 {
273 const std::shared_ptr<fml::Mapping> fixture =
274 flutter::testing::OpenFixtureAsMapping(asset_name);
275 if (!fixture || fixture->GetSize() == 0) {
276 return {};
277 }
278 return RuntimeStage::DecodeRuntimeStages(fixture);
279 }
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 for (int i = 0; i < 2; ++i) {
231 auto display_list = callback();
232 auto texture =
233 DisplayListToTexture(display_list, pimpl_->window_size, renderer);
234 screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, texture);
235 }
236 return SaveScreenshot(std::move(screenshot));
237 }
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(), and SaveScreenshot().

## ◆ OpenPlaygroundHere() [3/4]

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

Definition at line 239 of file golden_playground_test_mac.cc.

240 {
241 return OpenPlaygroundHere([&list]() { return list; });
242 }
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 323 of file golden_playground_test_mac.cc.

324 {
325 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
326 }

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