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

127 : typographer_context_(TypographerContextSkia::Make()),
128 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 323 of file golden_playground_test_mac.cc.

325 {
326 std::shared_ptr<Texture> texture =
327 CreateTextureForFixture(fixture_name, enable_mipmapping);
329}
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 310 of file golden_playground_test_mac.cc.

312 {
313 std::shared_ptr<fml::Mapping> mapping =
315 auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
316 enable_mipmapping);
317 if (result) {
318 result->SetLabel(fixture_name);
319 }
320 return result;
321}
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 228 of file golden_playground_test_mac.cc.

228 {
229 return GetParam();
230}

◆ GetContentScale()

Point impeller::GoldenPlaygroundTest::GetContentScale ( ) const

Definition at line 367 of file golden_playground_test_mac.cc.

367 {
368 return pimpl_->screenshotter->GetPlayground().GetContentScale();
369}

◆ GetContext()

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

Definition at line 341 of file golden_playground_test_mac.cc.

341 {
342 if (!pimpl_->screenshotter) {
343 return nullptr;
344 }
345 return pimpl_->screenshotter->GetPlayground().GetContext();
346}

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

◆ GetRuntimeStageBackend()

RuntimeStageBackend impeller::GoldenPlaygroundTest::GetRuntimeStageBackend ( ) const

Definition at line 405 of file golden_playground_test_mac.cc.

405 {
406 return pimpl_->screenshotter->GetPlayground().GetRuntimeStageBackend();
407}

◆ GetSecondsElapsed()

Scalar impeller::GoldenPlaygroundTest::GetSecondsElapsed ( ) const

Definition at line 371 of file golden_playground_test_mac.cc.

371 {
372 return 0.0f;
373}

◆ GetWindowBounds()

IRect impeller::GoldenPlaygroundTest::GetWindowBounds ( ) const

Definition at line 379 of file golden_playground_test_mac.cc.

379 {
380 return IRect::MakeSize(pimpl_->window_size);
381}
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 375 of file golden_playground_test_mac.cc.

375 {
376 return pimpl_->window_size;
377}

◆ ImGuiBegin()

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

Definition at line 304 of file golden_playground_test_mac.cc.

306 {
307 return false;
308}

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

On OpenGL we create a context for each test.

Definition at line 348 of file golden_playground_test_mac.cc.

348 {
349 if (GetParam() == PlaygroundBackend::kMetal) {
350 /// On Metal we create a context for each test.
351 return GetContext();
352 } else if (GetParam() == PlaygroundBackend::kVulkan) {
353 bool enable_vulkan_validations = true;
354 FML_CHECK(!pimpl_->test_vulkan_playground)
355 << "We don't support creating multiple contexts for one test";
356 pimpl_->test_vulkan_playground =
357 MakeVulkanPlayground(enable_vulkan_validations);
358 pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
359 pimpl_->test_vulkan_playground);
360 return pimpl_->test_vulkan_playground->GetContext();
361 } else {
362 /// On OpenGL we create a context for each test.
363 return GetContext();
364 }
365}
#define FML_CHECK(condition)
Definition logging.h:104

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

◆ MakeScreenshot()

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

Definition at line 392 of file golden_playground_test_mac.cc.

393 {
394 AiksContext renderer(GetContext(), typographer_context_);
395 Point content_scale =
396 pimpl_->screenshotter->GetPlayground().GetContentScale();
397
398 ISize physical_window_size(
399 std::round(pimpl_->window_size.width * content_scale.x),
400 std::round(pimpl_->window_size.height * content_scale.y));
401 return pimpl_->screenshotter->MakeScreenshot(
402 renderer, DisplayListToTexture(list, physical_window_size, renderer));
403}
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 331 of file golden_playground_test_mac.cc.

332 {
333 const std::shared_ptr<fml::Mapping> fixture =
335 if (!fixture || fixture->GetSize() == 0) {
336 return absl::NotFoundError("Asset not found or empty.");
337 }
338 return RuntimeStage::DecodeRuntimeStages(fixture);
339}
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 232 of file golden_playground_test_mac.cc.

233 {
234 AiksContext renderer(GetContext(), typographer_context_);
235
236 std::unique_ptr<testing::Screenshot> screenshot;
237 Point content_scale =
238 pimpl_->screenshotter->GetPlayground().GetContentScale();
239
240 ISize physical_window_size(
241 std::round(pimpl_->window_size.width * content_scale.x),
242 std::round(pimpl_->window_size.height * content_scale.y));
243 for (int i = 0; i < 2; ++i) {
244 auto display_list = callback();
245 auto texture =
246 DisplayListToTexture(display_list, physical_window_size, renderer);
247 screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, texture);
248 }
249 return SaveScreenshot(std::move(screenshot));
250}
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 257 of file golden_playground_test_mac.cc.

258 {
259 AiksContext renderer(GetContext(), typographer_context_);
260 std::shared_ptr<Context> context = GetContext();
261 Point content_scale =
262 pimpl_->screenshotter->GetPlayground().GetContentScale();
263 ISize size(std::round(pimpl_->window_size.width * content_scale.x),
264 std::round(pimpl_->window_size.height * content_scale.y));
265
266 std::unique_ptr<testing::Screenshot> screenshot;
267 // Render twice so the second pass observes warmed pipeline and resource
268 // caches, matching the display list path above.
269 for (int i = 0; i < 2; ++i) {
270 RenderTargetAllocator render_target_allocator(
271 context->GetResourceAllocator());
272 RenderTarget render_target = render_target_allocator.CreateOffscreen(
273 *context, size, /*mip_count=*/1, "Golden Render Pass",
275 /*stencil_attachment_config=*/std::nullopt);
276 if (!render_target.IsValid()) {
277 return false;
278 }
279 std::shared_ptr<CommandBuffer> command_buffer =
280 context->CreateCommandBuffer();
281 if (!command_buffer) {
282 return false;
283 }
284 std::shared_ptr<RenderPass> render_pass =
285 command_buffer->CreateRenderPass(render_target);
286 if (!render_pass) {
287 return false;
288 }
289 if (!callback(*render_pass)) {
290 return false;
291 }
292 if (!render_pass->EncodeCommands()) {
293 return false;
294 }
295 if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) {
296 return false;
297 }
298 screenshot = pimpl_->screenshotter->MakeScreenshot(
299 renderer, render_target.GetRenderTargetTexture());
300 }
301 return SaveScreenshot(std::move(screenshot));
302}
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

References callback, impeller::RenderTargetAllocator::CreateOffscreen(), GetContext(), impeller::RenderTarget::GetRenderTargetTexture(), i, impeller::RenderTarget::IsValid(), impeller::RenderTarget::kDefaultColorAttachmentConfig, 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 252 of file golden_playground_test_mac.cc.

253 {
254 return OpenPlaygroundHere([&list]() { return list; });
255}
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 100 of file golden_playground_test_mac.cc.

102 {
103 if (!screenshot || !screenshot->GetBytes()) {
104 FML_LOG(ERROR) << "Failed to collect screenshot for test " << GetTestName();
105 return false;
106 }
107 std::string test_name = GetTestName();
108 std::string filename = GetGoldenFilename(postfix);
110 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
111 if (!screenshot->WriteToPNG(
113 FML_LOG(ERROR) << "Failed to write screenshot to " << filename;
114 return false;
115 }
116 return true;
117}
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 387 of file golden_playground_test_mac.cc.

388 {
389 return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
390}

◆ SetTypographerContext()

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

Definition at line 132 of file golden_playground_test_mac.cc.

133 {
134 typographer_context_ = std::move(typographer_context);
135};

◆ SetUp()

void impeller::GoldenPlaygroundTest::SetUp ( )

Definition at line 156 of file golden_playground_test_mac.cc.

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

◆ SetWindowSize()

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

Definition at line 76 of file golden_playground_test_stub.cc.

76{}

◆ TearDown()

void impeller::GoldenPlaygroundTest::TearDown ( )

Definition at line 137 of file golden_playground_test_mac.cc.

137 {
138 ASSERT_FALSE(dlopen("/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
139
140 auto context = GetContext();
141 if (context) {
142 context->DisposeThreadLocalCachedResources();
143 }
144}

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