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
 
RuntimeStage::Map OpenAssetAsRuntimeStage (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...
 

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()) {}
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 258 of file golden_playground_test_mac.cc.

260  {
261  std::shared_ptr<Texture> texture =
262  CreateTextureForFixture(fixture_name, enable_mipmapping);
263  return DlImageImpeller::Make(texture);
264 }
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 245 of file golden_playground_test_mac.cc.

247  {
248  std::shared_ptr<fml::Mapping> mapping =
249  flutter::testing::OpenFixtureAsMapping(fixture_name);
250  auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
251  enable_mipmapping);
252  if (result) {
253  result->SetLabel(fixture_name);
254  }
255  return result;
256 }
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:432

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

Referenced by CreateDlImageForFixture().

◆ GetBackend()

PlaygroundBackend impeller::GoldenPlaygroundTest::GetBackend ( ) const

Definition at line 216 of file golden_playground_test_mac.cc.

216  {
217  return GetParam();
218 }

◆ GetContentScale()

Point impeller::GoldenPlaygroundTest::GetContentScale ( ) const

Definition at line 299 of file golden_playground_test_mac.cc.

299  {
300  return pimpl_->screenshotter->GetPlayground().GetContentScale();
301 }

◆ GetContext()

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

Definition at line 276 of file golden_playground_test_mac.cc.

276  {
277  return pimpl_->screenshotter->GetPlayground().GetContext();
278 }

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

◆ GetSecondsElapsed()

Scalar impeller::GoldenPlaygroundTest::GetSecondsElapsed ( ) const

Definition at line 303 of file golden_playground_test_mac.cc.

303  {
304  return 0.0f;
305 }

◆ GetWindowSize()

ISize impeller::GoldenPlaygroundTest::GetWindowSize ( ) const

Definition at line 307 of file golden_playground_test_mac.cc.

307  {
308  return pimpl_->window_size;
309 }

◆ ImGuiBegin()

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

Definition at line 239 of file golden_playground_test_mac.cc.

241  {
242  return false;
243 }

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

280  {
281  if (GetParam() == PlaygroundBackend::kMetal) {
282  /// On Metal we create a context for each test.
283  return GetContext();
284  } else if (GetParam() == PlaygroundBackend::kVulkan) {
285  bool enable_vulkan_validations = true;
286  FML_CHECK(!pimpl_->test_vulkan_playground)
287  << "We don't support creating multiple contexts for one test";
288  pimpl_->test_vulkan_playground =
289  MakeVulkanPlayground(enable_vulkan_validations);
290  pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
291  pimpl_->test_vulkan_playground);
292  return pimpl_->test_vulkan_playground->GetContext();
293  } else {
294  /// On OpenGL we create a context for each test.
295  return GetContext();
296  }
297 }

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

321  {
322  AiksContext renderer(GetContext(), typographer_context_);
323 
324  return pimpl_->screenshotter->MakeScreenshot(
325  renderer, DisplayListToTexture(list, pimpl_->window_size, renderer));
326 }
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.

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

◆ OpenAssetAsRuntimeStage()

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

Definition at line 266 of file golden_playground_test_mac.cc.

267  {
268  const std::shared_ptr<fml::Mapping> fixture =
269  flutter::testing::OpenFixtureAsMapping(asset_name);
270  if (!fixture || fixture->GetSize() == 0) {
271  return {};
272  }
273  return RuntimeStage::DecodeRuntimeStages(fixture);
274 }
static 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 220 of file golden_playground_test_mac.cc.

221  {
222  AiksContext renderer(GetContext(), typographer_context_);
223 
224  std::unique_ptr<testing::Screenshot> screenshot;
225  for (int i = 0; i < 2; ++i) {
226  auto display_list = callback();
227  auto texture =
228  DisplayListToTexture(display_list, pimpl_->window_size, renderer);
229  screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, texture);
230  }
231  return SaveScreenshot(std::move(screenshot));
232 }
static bool SaveScreenshot(std::unique_ptr< testing::Screenshot > screenshot, const std::string &postfix="")

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

◆ OpenPlaygroundHere() [3/4]

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

Definition at line 234 of file golden_playground_test_mac.cc.

235  {
236  return OpenPlaygroundHere([&list]() { return list; });
237 }
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 315 of file golden_playground_test_mac.cc.

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

◆ 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  PlaygroundSwitches switches;
159  switches.enable_wide_gamut =
160  test_name.find("WideGamut_") != std::string::npos;
161  switches.flags.antialiased_lines =
162  test_name.find("ExperimentAntialiasLines_") != std::string::npos;
163  switch (GetParam()) {
165  if (!DoesSupportWideGamutTests()) {
166  GTEST_SKIP()
167  << "This metal device doesn't support wide gamut golden tests.";
168  }
169  pimpl_->screenshotter =
170  std::make_unique<testing::MetalScreenshotter>(switches);
171  break;
173  if (switches.enable_wide_gamut) {
174  GTEST_SKIP() << "Vulkan doesn't support wide gamut golden tests.";
175  }
176  if (switches.flags.antialiased_lines) {
177  GTEST_SKIP()
178  << "Vulkan doesn't support antialiased lines golden tests.";
179  }
180  const std::unique_ptr<PlaygroundImpl>& playground =
181  GetSharedVulkanPlayground(/*enable_validations=*/true);
182  pimpl_->screenshotter =
183  std::make_unique<testing::VulkanScreenshotter>(playground);
184  break;
185  }
187  if (switches.enable_wide_gamut) {
188  GTEST_SKIP() << "OpenGLES doesn't support wide gamut golden tests.";
189  }
190  if (switches.flags.antialiased_lines) {
191  GTEST_SKIP()
192  << "OpenGLES doesn't support antialiased lines golden tests.";
193  }
194  FML_CHECK(::glfwInit() == GLFW_TRUE);
195  PlaygroundSwitches playground_switches;
196  playground_switches.use_angle = true;
197  pimpl_->test_opengl_playground = PlaygroundImpl::Create(
198  PlaygroundBackend::kOpenGLES, playground_switches);
199  pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
200  pimpl_->test_opengl_playground);
201  break;
202  }
203  }
204 
205  if (std::find(kSkipTests.begin(), kSkipTests.end(), test_name) !=
206  kSkipTests.end()) {
207  GTEST_SKIP()
208  << "GoldenPlaygroundTest doesn't support interactive playground tests "
209  "yet.";
210  }
211 
213  "gpu_string", GetContext()->DescribeGpuModel());
214 }
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::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: