Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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)
 
bool OpenPlaygroundHere (const Playground::SinglePassCallback &callback)
 
std::unique_ptr< testing::ScreenshotMakeScreenshot (const sk_sp< flutter::DisplayList > &list)
 
std::shared_ptr< TextureCreateTextureForFixture (const char *fixture_name, bool enable_mipmapping=false) const
 
sk_sp< flutter::DlImageCreateDlImageForFixture (const char *fixture_name, bool enable_mipmapping=false) const
 
absl::StatusOr< RuntimeStage::MapOpenAssetAsRuntimeStage (const char *asset_name) const
 
std::shared_ptr< ContextGetContext () const
 
std::shared_ptr< ContextMakeContext () const
 
Point GetContentScale () const
 
Scalar GetSecondsElapsed () const
 
ISize GetWindowSize () const
 
IRect GetWindowBounds () const
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities)
 
bool WillRenderSomething () const
 Returns true if OpenPlaygroundHere will actually render anything.
 
RuntimeStageBackend GetRuntimeStageBackend () const
 
bool IsGoldenTest ()
 

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 27 of file golden_playground_test.h.

Member Typedef Documentation

◆ AiksDlPlaygroundCallback

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

158 : typographer_context_(TypographerContextSkia::Make()),
159 pimpl_(new GoldenPlaygroundTest::GoldenPlaygroundTestImpl()) {}
static std::shared_ptr< TypographerContext > Make()

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

358 {
359 std::shared_ptr<Texture> texture =
360 CreateTextureForFixture(fixture_name, enable_mipmapping);
362}
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
FlTexture * texture

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

◆ CreateTextureForFixture()

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

Definition at line 343 of file golden_playground_test_mac.cc.

345 {
346 std::shared_ptr<fml::Mapping> mapping =
348 auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
349 enable_mipmapping);
350 if (result) {
351 result->SetLabel(fixture_name);
352 }
353 return result;
354}
std::shared_ptr< Context > GetContext() const
static std::shared_ptr< Texture > CreateTextureForMapping(const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
Definition testing.cc:58

References impeller::Playground::CreateTextureForMapping(), GetContext(), and flutter::testing::OpenFixtureAsMapping().

Referenced by CreateDlImageForFixture().

◆ GetBackend()

PlaygroundBackend impeller::GoldenPlaygroundTest::GetBackend ( ) const

Definition at line 261 of file golden_playground_test_mac.cc.

261 {
262 return GetParam();
263}

◆ GetContentScale()

Point impeller::GoldenPlaygroundTest::GetContentScale ( ) const

Definition at line 410 of file golden_playground_test_mac.cc.

410 {
411 return pimpl_->screenshotter->GetPlayground().GetContentScale();
412}

◆ GetContext()

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

Definition at line 374 of file golden_playground_test_mac.cc.

374 {
375 if (!pimpl_->screenshotter) {
376 return nullptr;
377 }
378 return pimpl_->screenshotter->GetPlayground().GetContext();
379}

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

◆ GetRuntimeStageBackend()

RuntimeStageBackend impeller::GoldenPlaygroundTest::GetRuntimeStageBackend ( ) const

Definition at line 448 of file golden_playground_test_mac.cc.

448 {
449 return pimpl_->screenshotter->GetPlayground().GetRuntimeStageBackend();
450}

◆ GetSecondsElapsed()

Scalar impeller::GoldenPlaygroundTest::GetSecondsElapsed ( ) const

Definition at line 414 of file golden_playground_test_mac.cc.

414 {
415 return 0.0f;
416}

◆ GetWindowBounds()

IRect impeller::GoldenPlaygroundTest::GetWindowBounds ( ) const

Definition at line 422 of file golden_playground_test_mac.cc.

422 {
423 return IRect::MakeSize(pimpl_->window_size);
424}
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:150

References impeller::TRect< T >::MakeSize().

◆ GetWindowSize()

ISize impeller::GoldenPlaygroundTest::GetWindowSize ( ) const

Definition at line 418 of file golden_playground_test_mac.cc.

418 {
419 return pimpl_->window_size;
420}

◆ ImGuiBegin()

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

Definition at line 337 of file golden_playground_test_mac.cc.

339 {
340 return false;
341}

◆ IsGoldenTest()

bool impeller::GoldenPlaygroundTest::IsGoldenTest ( )
inline

Definition at line 107 of file golden_playground_test.h.

107{ return true; }

◆ MakeContext()

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

On Metal we create a context for each test.

Definition at line 381 of file golden_playground_test_mac.cc.

381 {
382 if (GetParam() == PlaygroundBackend::kMetal ||
383 GetParam() == PlaygroundBackend::kMetalSDF) {
384 /// On Metal we create a context for each test.
385 return GetContext();
386 } else if (GetParam() == PlaygroundBackend::kVulkan) {
387 bool enable_vulkan_validations = true;
388 FML_CHECK(!pimpl_->test_vulkan_playground)
389 << "We don't support creating multiple contexts for one test";
390 pimpl_->test_vulkan_playground =
391 MakeVulkanPlayground(enable_vulkan_validations);
392 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
393 pimpl_->test_vulkan_playground);
394 return pimpl_->test_vulkan_playground->GetContext();
395 } else if (GetParam() == PlaygroundBackend::kOpenGLES ||
396 GetParam() == PlaygroundBackend::kOpenGLESSDF) {
397 FML_CHECK(!pimpl_->test_opengl_playground)
398 << "We don't support creating multiple contexts for one test";
399 bool use_sdfs = (GetParam() == PlaygroundBackend::kOpenGLESSDF);
400 pimpl_->test_opengl_playground = MakeOpenGLESPlayground(use_sdfs);
401 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
402 pimpl_->test_opengl_playground);
403 return pimpl_->test_opengl_playground->GetContext();
404 } else {
405 FML_CHECK(false);
406 return nullptr;
407 }
408}
#define FML_CHECK(condition)
Definition logging.h:104

References FML_CHECK, GetContext(), impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, and impeller::kVulkan.

◆ MakeScreenshot()

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

Definition at line 435 of file golden_playground_test_mac.cc.

436 {
437 AiksContext renderer(GetContext(), typographer_context_);
438 Point content_scale =
439 pimpl_->screenshotter->GetPlayground().GetContentScale();
440
441 ISize physical_window_size(
442 std::round(pimpl_->window_size.width * content_scale.x),
443 std::round(pimpl_->window_size.height * content_scale.y));
444 return pimpl_->screenshotter->MakeScreenshot(
445 renderer, DisplayListToTexture(list, physical_window_size, renderer));
446}
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips, std::optional< PixelFormat > target_pixel_format)
Render the provided display list to a texture with the given size.
TPoint< Scalar > Point
Definition point.h:426
ISize64 ISize
Definition size.h:162

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

◆ OpenAssetAsRuntimeStage()

absl::StatusOr< RuntimeStage::Map > impeller::GoldenPlaygroundTest::OpenAssetAsRuntimeStage ( const char *  asset_name) const

Definition at line 364 of file golden_playground_test_mac.cc.

365 {
366 const std::shared_ptr<fml::Mapping> fixture =
368 if (!fixture || fixture->GetSize() == 0) {
369 return absl::NotFoundError("Asset not found or empty.");
370 }
371 return RuntimeStage::DecodeRuntimeStages(fixture);
372}
static absl::StatusOr< Map > DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)

References impeller::RuntimeStage::DecodeRuntimeStages(), and flutter::testing::OpenFixtureAsMapping().

◆ OpenPlaygroundHere() [1/5]

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

◆ OpenPlaygroundHere() [2/5]

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

Definition at line 265 of file golden_playground_test_mac.cc.

266 {
267 AiksContext renderer(GetContext(), typographer_context_);
268
269 std::unique_ptr<testing::Screenshot> screenshot;
270 Point content_scale =
271 pimpl_->screenshotter->GetPlayground().GetContentScale();
272
273 ISize physical_window_size(
274 std::round(pimpl_->window_size.width * content_scale.x),
275 std::round(pimpl_->window_size.height * content_scale.y));
276 for (int i = 0; i < 2; ++i) {
277 auto display_list = callback();
278 auto texture =
279 DisplayListToTexture(display_list, physical_window_size, renderer);
280 screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, texture);
281 }
282 return SaveScreenshot(std::move(screenshot));
283}
static bool SaveScreenshot(std::unique_ptr< testing::Screenshot > screenshot, const std::string &postfix="")
FlutterDesktopBinaryReply callback

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

◆ OpenPlaygroundHere() [3/5]

bool impeller::GoldenPlaygroundTest::OpenPlaygroundHere ( const Playground::SinglePassCallback callback)

Renders callback into an offscreen render pass and saves the result as a golden image. The render target is single-sampled, uses the context's default color format, and has no depth or stencil attachment, so a pipeline built from PipelineBuilder<>::MakeDefaultPipelineDescriptor must be reduced to match by calling SetSampleCount(kCount1), ClearStencilAttachments(), and ClearDepthAttachment() on it. Calling only SetStencilAttachmentDescriptors(nullopt) leaves the stencil pixel format set and trips Metal's render pipeline validation.

Definition at line 290 of file golden_playground_test_mac.cc.

291 {
292 AiksContext renderer(GetContext(), typographer_context_);
293 std::shared_ptr<Context> context = GetContext();
294 Point content_scale =
295 pimpl_->screenshotter->GetPlayground().GetContentScale();
296 ISize size(std::round(pimpl_->window_size.width * content_scale.x),
297 std::round(pimpl_->window_size.height * content_scale.y));
298
299 std::unique_ptr<testing::Screenshot> screenshot;
300 // Render twice so the second pass observes warmed pipeline and resource
301 // caches, matching the display list path above.
302 for (int i = 0; i < 2; ++i) {
303 RenderTargetAllocator render_target_allocator(
304 context->GetResourceAllocator());
305 RenderTarget render_target = render_target_allocator.CreateOffscreen(
306 *context, size, /*mip_count=*/1, "Golden Render Pass",
308 /*stencil_attachment_config=*/std::nullopt);
309 if (!render_target.IsValid()) {
310 return false;
311 }
312 std::shared_ptr<CommandBuffer> command_buffer =
313 context->CreateCommandBuffer();
314 if (!command_buffer) {
315 return false;
316 }
317 std::shared_ptr<RenderPass> render_pass =
318 command_buffer->CreateRenderPass(render_target);
319 if (!render_pass) {
320 return false;
321 }
322 if (!callback(*render_pass)) {
323 return false;
324 }
325 if (!render_pass->EncodeCommands()) {
326 return false;
327 }
328 if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) {
329 return false;
330 }
331 screenshot = pimpl_->screenshotter->MakeScreenshot(
332 renderer, render_target.GetRenderTargetTexture());
333 }
334 return SaveScreenshot(std::move(screenshot));
335}
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
std::shared_ptr< ContextGLES > context
std::shared_ptr< RenderPass > render_pass
std::shared_ptr< CommandBuffer > command_buffer

References callback, command_buffer, context, impeller::RenderTargetAllocator::CreateOffscreen(), GetContext(), impeller::RenderTarget::GetRenderTargetTexture(), i, impeller::RenderTarget::IsValid(), impeller::RenderTarget::kDefaultColorAttachmentConfig, render_pass, SaveScreenshot(), impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

◆ OpenPlaygroundHere() [4/5]

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

Definition at line 285 of file golden_playground_test_mac.cc.

286 {
287 return OpenPlaygroundHere([&list]() { return list; });
288}
bool OpenPlaygroundHere(Picture picture)

References OpenPlaygroundHere().

◆ OpenPlaygroundHere() [5/5]

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

133 {
134 if (!screenshot || !screenshot->GetBytes()) {
135 FML_LOG(ERROR) << "Failed to collect screenshot for test " << GetTestName();
136 return false;
137 }
138 std::string test_name = GetTestName();
139 std::string filename = GetGoldenFilename(postfix);
141 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
142 if (!screenshot->WriteToPNG(
144 FML_LOG(ERROR) << "Failed to write screenshot to " << filename;
145 return false;
146 }
147 return true;
148}
static GoldenDigest * Instance()
void AddImage(const std::string &test_name, const std::string &filename, int32_t width, int32_t height)
std::string GetFilenamePath(const std::string &filename) const
static WorkingDirectory * Instance()
#define FML_LOG(severity)
Definition logging.h:101

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

Referenced by OpenPlaygroundHere(), and OpenPlaygroundHere().

◆ SetCapabilities()

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

Definition at line 430 of file golden_playground_test_mac.cc.

431 {
432 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
433}

◆ SetTypographerContext()

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

Definition at line 163 of file golden_playground_test_mac.cc.

164 {
165 typographer_context_ = std::move(typographer_context);
166};

◆ SetUp()

void impeller::GoldenPlaygroundTest::SetUp ( )

Definition at line 187 of file golden_playground_test_mac.cc.

187 {
188 std::filesystem::path testing_assets_path =
190 std::filesystem::path target_path = testing_assets_path.parent_path()
191 .parent_path()
192 .parent_path()
193 .parent_path();
194 std::filesystem::path icd_path = target_path / "vk_swiftshader_icd.json";
195 setenv("VK_ICD_FILENAMES", icd_path.c_str(), 1);
196
197 std::string test_name = GetTestName();
198 PlaygroundSwitches switches;
199 switches.enable_wide_gamut =
200 test_name.find("WideGamut_") != std::string::npos;
201 switches.flags.antialiased_lines =
202 test_name.find("ExperimentAntialiasLines_") != std::string::npos;
203 switch (GetParam()) {
205 switches.flags.use_sdfs = true;
206 [[fallthrough]];
208 if (!DoesSupportWideGamutTests()) {
209 GTEST_SKIP()
210 << "This metal device doesn't support wide gamut golden tests.";
211 }
212 pimpl_->screenshotter =
213 std::make_unique<testing::MetalScreenshotter>(switches);
214 break;
216 if (switches.enable_wide_gamut) {
217 GTEST_SKIP() << "Vulkan doesn't support wide gamut golden tests.";
218 }
219 if (switches.flags.antialiased_lines) {
220 GTEST_SKIP()
221 << "Vulkan doesn't support antialiased lines golden tests.";
222 }
223 const std::unique_ptr<PlaygroundImpl>& playground =
224 GetSharedVulkanPlayground(/*enable_validations=*/true);
225 pimpl_->screenshotter =
226 std::make_unique<testing::VulkanScreenshotter>(playground);
227 break;
228 }
230 switches.flags.use_sdfs = true;
231 [[fallthrough]];
233 if (switches.enable_wide_gamut) {
234 GTEST_SKIP() << "OpenGLES doesn't support wide gamut golden tests.";
235 }
236 if (switches.flags.antialiased_lines) {
237 GTEST_SKIP()
238 << "OpenGLES doesn't support antialiased lines golden tests.";
239 }
240 const std::unique_ptr<PlaygroundImpl>& playground =
241 GetSharedOpenGLESPlayground(switches.flags.use_sdfs);
242 ::glfwMakeContextCurrent(
243 reinterpret_cast<GLFWwindow*>(playground->GetWindowHandle()));
244 pimpl_->screenshotter =
245 std::make_unique<testing::VulkanScreenshotter>(playground);
246 break;
247 }
248 }
249
250 if (std::find(kSkipTests.begin(), kSkipTests.end(), test_name) !=
251 kSkipTests.end()) {
252 GTEST_SKIP()
253 << "GoldenPlaygroundTest doesn't support interactive playground tests "
254 "yet.";
255 }
256
258 "gpu_string", GetContext()->DescribeGpuModel());
259}
void AddDimension(const std::string &name, const std::string &value)
const char * GetTestingAssetsPath()
Returns the directory containing assets shared across all tests.
static const std::vector< std::string > kSkipTests

References impeller::testing::GoldenDigest::AddDimension(), impeller::Flags::antialiased_lines, impeller::PlaygroundSwitches::enable_wide_gamut, impeller::PlaygroundSwitches::flags, GetContext(), flutter::testing::GetTestingAssetsPath(), impeller::testing::GoldenDigest::Instance(), impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, impeller::kSkipTests, impeller::kVulkan, and impeller::Flags::use_sdfs.

◆ SetWindowSize()

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

Definition at line 80 of file golden_playground_test_stub.cc.

80{}

◆ TearDown()

void impeller::GoldenPlaygroundTest::TearDown ( )

Definition at line 168 of file golden_playground_test_mac.cc.

168 {
169 ASSERT_FALSE(dlopen("/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
170
171 auto context = GetContext();
172 if (context) {
173 context->DisposeThreadLocalCachedResources();
174 }
175}

References context, and GetContext().

◆ WillRenderSomething()

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

Returns true if OpenPlaygroundHere will actually render anything.

Definition at line 103 of file golden_playground_test.h.

103{ return true; }

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