Flutter Impeller
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::ScreenshotMakeScreenshot (const sk_sp< flutter::DisplayList > &list)
 
std::shared_ptr< TextureCreateTextureForFixture (const char *fixture_name, bool enable_mipmapping=false) const
 
sk_sp< flutter::DlImage > CreateDlImageForFixture (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
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities)
 
bool WillRenderSomething () const
 Returns true if OpenPlaygroundHere will actually render anything. More...
 
RuntimeStageBackend GetRuntimeStageBackend () const
 

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

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

Definition at line 33 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()) {}
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 272 of file golden_playground_test_mac.cc.

274  {
275  std::shared_ptr<Texture> texture =
276  CreateTextureForFixture(fixture_name, enable_mipmapping);
277  return DlImageImpeller::Make(texture);
278 }
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

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

261  {
262  std::shared_ptr<fml::Mapping> mapping =
263  flutter::testing::OpenFixtureAsMapping(fixture_name);
264  auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
265  enable_mipmapping);
266  if (result) {
267  result->SetLabel(fixture_name);
268  }
269  return result;
270 }
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)
Definition: playground.cc:437

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

Referenced by CreateDlImageForFixture().

◆ GetBackend()

PlaygroundBackend impeller::GoldenPlaygroundTest::GetBackend ( ) const

Definition at line 224 of file golden_playground_test_mac.cc.

224  {
225  return GetParam();
226 }

◆ GetContentScale()

Point impeller::GoldenPlaygroundTest::GetContentScale ( ) const

Definition at line 316 of file golden_playground_test_mac.cc.

316  {
317  return pimpl_->screenshotter->GetPlayground().GetContentScale();
318 }

◆ GetContext()

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

Definition at line 290 of file golden_playground_test_mac.cc.

290  {
291  if (!pimpl_->screenshotter) {
292  return nullptr;
293  }
294  return pimpl_->screenshotter->GetPlayground().GetContext();
295 }

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

◆ GetRuntimeStageBackend()

RuntimeStageBackend impeller::GoldenPlaygroundTest::GetRuntimeStageBackend ( ) const

Definition at line 350 of file golden_playground_test_mac.cc.

350  {
351  return pimpl_->screenshotter->GetPlayground().GetRuntimeStageBackend();
352 }

◆ GetSecondsElapsed()

Scalar impeller::GoldenPlaygroundTest::GetSecondsElapsed ( ) const

Definition at line 320 of file golden_playground_test_mac.cc.

320  {
321  return 0.0f;
322 }

◆ GetWindowSize()

ISize impeller::GoldenPlaygroundTest::GetWindowSize ( ) const

Definition at line 324 of file golden_playground_test_mac.cc.

324  {
325  return pimpl_->window_size;
326 }

◆ ImGuiBegin()

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

Definition at line 253 of file golden_playground_test_mac.cc.

255  {
256  return false;
257 }

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

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

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

338  {
339  AiksContext renderer(GetContext(), typographer_context_);
340  Point content_scale =
341  pimpl_->screenshotter->GetPlayground().GetContentScale();
342 
343  ISize physical_window_size(
344  std::round(pimpl_->window_size.width * content_scale.x),
345  std::round(pimpl_->window_size.height * content_scale.y));
346  return pimpl_->screenshotter->MakeScreenshot(
347  renderer, DisplayListToTexture(list, physical_window_size, renderer));
348 }
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 280 of file golden_playground_test_mac.cc.

281  {
282  const std::shared_ptr<fml::Mapping> fixture =
283  flutter::testing::OpenFixtureAsMapping(asset_name);
284  if (!fixture || fixture->GetSize() == 0) {
285  return absl::NotFoundError("Asset not found or empty.");
286  }
287  return RuntimeStage::DecodeRuntimeStages(fixture);
288 }
static absl::StatusOr< Map > DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)

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

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

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

249  {
250  return OpenPlaygroundHere([&list]() { return list; });
251 }
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);
106  test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
107  if (!screenshot->WriteToPNG(
109  FML_LOG(ERROR) << "Failed to write screenshot to " << filename;
110  return false;
111  }
112  return true;
113 }
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()

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

333  {
334  return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
335 }

◆ 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()) {
170  switches.flags.use_sdfs = true;
171  [[fallthrough]];
173  if (!DoesSupportWideGamutTests()) {
174  GTEST_SKIP()
175  << "This metal device doesn't support wide gamut golden tests.";
176  }
177  pimpl_->screenshotter =
178  std::make_unique<testing::MetalScreenshotter>(switches);
179  break;
181  if (switches.enable_wide_gamut) {
182  GTEST_SKIP() << "Vulkan doesn't support wide gamut golden tests.";
183  }
184  if (switches.flags.antialiased_lines) {
185  GTEST_SKIP()
186  << "Vulkan doesn't support antialiased lines golden tests.";
187  }
188  const std::unique_ptr<PlaygroundImpl>& playground =
189  GetSharedVulkanPlayground(/*enable_validations=*/true);
190  pimpl_->screenshotter =
191  std::make_unique<testing::VulkanScreenshotter>(playground);
192  break;
193  }
195  if (switches.enable_wide_gamut) {
196  GTEST_SKIP() << "OpenGLES doesn't support wide gamut golden tests.";
197  }
198  if (switches.flags.antialiased_lines) {
199  GTEST_SKIP()
200  << "OpenGLES doesn't support antialiased lines golden tests.";
201  }
202  FML_CHECK(::glfwInit() == GLFW_TRUE);
203  PlaygroundSwitches playground_switches;
204  playground_switches.use_angle = true;
205  pimpl_->test_opengl_playground = PlaygroundImpl::Create(
206  PlaygroundBackend::kOpenGLES, playground_switches);
207  pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
208  pimpl_->test_opengl_playground);
209  break;
210  }
211  }
212 
213  if (std::find(kSkipTests.begin(), kSkipTests.end(), test_name) !=
214  kSkipTests.end()) {
215  GTEST_SKIP()
216  << "GoldenPlaygroundTest doesn't support interactive playground tests "
217  "yet.";
218  }
219 
221  "gpu_string", GetContext()->DescribeGpuModel());
222 }
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
void AddDimension(const std::string &name, const std::string &value)
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, GetContext(), 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 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 91 of file golden_playground_test.h.

91 { return true; }

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