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

Static Public Member Functions

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

Protected Member Functions

void SetWindowSize (ISize size)
 

Detailed Description

Definition at line 25 of file golden_playground_test.h.

Member Typedef Documentation

◆ AiksDlPlaygroundCallback

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

Definition at line 31 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 119 of file golden_playground_test_mac.cc.

120  : typographer_context_(TypographerContextSkia::Make()),
121  pimpl_(new GoldenPlaygroundTest::GoldenPlaygroundTestImpl()) {}

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

280  {
281  std::shared_ptr<Texture> texture =
282  CreateTextureForFixture(fixture_name, enable_mipmapping);
283  return DlImageImpeller::Make(texture);
284 }

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

267  {
268  std::shared_ptr<fml::Mapping> mapping =
269  flutter::testing::OpenFixtureAsMapping(fixture_name);
270  auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
271  enable_mipmapping);
272  if (result) {
273  result->SetLabel(fixture_name);
274  }
275  return result;
276 }

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

Referenced by CreateDlImageForFixture().

◆ GetBackend()

PlaygroundBackend impeller::GoldenPlaygroundTest::GetBackend ( ) const

Definition at line 201 of file golden_playground_test_mac.cc.

201  {
202  return GetParam();
203 }

◆ GetContentScale()

Point impeller::GoldenPlaygroundTest::GetContentScale ( ) const

Definition at line 319 of file golden_playground_test_mac.cc.

319  {
320  return pimpl_->screenshotter->GetPlayground().GetContentScale();
321 }

◆ GetContext()

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

Definition at line 296 of file golden_playground_test_mac.cc.

296  {
297  return pimpl_->screenshotter->GetPlayground().GetContext();
298 }

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

◆ GetSecondsElapsed()

Scalar impeller::GoldenPlaygroundTest::GetSecondsElapsed ( ) const

Definition at line 323 of file golden_playground_test_mac.cc.

323  {
324  return 0.0f;
325 }

◆ GetWindowSize()

ISize impeller::GoldenPlaygroundTest::GetWindowSize ( ) const

Definition at line 327 of file golden_playground_test_mac.cc.

327  {
328  return pimpl_->window_size;
329 }

◆ ImGuiBegin()

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

Definition at line 259 of file golden_playground_test_mac.cc.

261  {
262  return false;
263 }

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

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

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

◆ OpenAssetAsRuntimeStage()

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

Definition at line 286 of file golden_playground_test_mac.cc.

287  {
288  const std::shared_ptr<fml::Mapping> fixture =
289  flutter::testing::OpenFixtureAsMapping(asset_name);
290  if (!fixture || fixture->GetSize() == 0) {
291  return {};
292  }
293  return RuntimeStage::DecodeRuntimeStages(fixture);
294 }

References impeller::RuntimeStage::DecodeRuntimeStages().

◆ OpenPlaygroundHere() [1/4]

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

Definition at line 232 of file golden_playground_test_mac.cc.

234  { // NOLINT(performance-unnecessary-value-param)
235  AiksContext renderer(GetContext(), typographer_context_);
236 
237  std::optional<Picture> picture;
238  std::unique_ptr<testing::Screenshot> screenshot;
239  for (int i = 0; i < 2; ++i) {
240  picture = callback(renderer);
241  if (!picture.has_value()) {
242  return false;
243  }
244  screenshot = pimpl_->screenshotter->MakeScreenshot(
245  renderer, picture.value(), pimpl_->window_size);
246  }
247 
248  return SaveScreenshot(std::move(screenshot));
249 }

References GetContext().

◆ OpenPlaygroundHere() [2/4]

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

Definition at line 213 of file golden_playground_test_mac.cc.

214  {
215  AiksContext renderer(GetContext(), typographer_context_);
216 
217  std::optional<Picture> picture;
218  std::unique_ptr<testing::Screenshot> screenshot;
219  for (int i = 0; i < 2; ++i) {
220  auto display_list = callback();
221  DlDispatcher dispatcher;
222  display_list->Dispatch(dispatcher);
223  Picture picture = dispatcher.EndRecordingAsPicture();
224 
225  screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, picture,
226  pimpl_->window_size);
227  }
228 
229  return SaveScreenshot(std::move(screenshot));
230 }

References impeller::DlDispatcherBase::EndRecordingAsPicture(), and GetContext().

◆ OpenPlaygroundHere() [3/4]

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

Definition at line 251 of file golden_playground_test_mac.cc.

252  {
253  DlDispatcher dispatcher;
254  list->Dispatch(dispatcher);
255  Picture picture = dispatcher.EndRecordingAsPicture();
256  return OpenPlaygroundHere(std::move(picture));
257 }

References impeller::DlDispatcherBase::EndRecordingAsPicture(), and OpenPlaygroundHere().

◆ OpenPlaygroundHere() [4/4]

bool impeller::GoldenPlaygroundTest::OpenPlaygroundHere ( Picture  picture)

Definition at line 205 of file golden_playground_test_mac.cc.

205  {
206  AiksContext renderer(GetContext(), typographer_context_);
207 
208  auto screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, picture,
209  pimpl_->window_size);
210  return SaveScreenshot(std::move(screenshot));
211 }

References GetContext().

Referenced by OpenPlaygroundHere().

◆ SetCapabilities()

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

Definition at line 335 of file golden_playground_test_mac.cc.

336  {
337  return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
338 }

◆ SetTypographerContext()

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

Definition at line 125 of file golden_playground_test_mac.cc.

126  {
127  typographer_context_ = std::move(typographer_context);
128 };

◆ SetUp()

void impeller::GoldenPlaygroundTest::SetUp ( )

Definition at line 144 of file golden_playground_test_mac.cc.

144  {
145  std::filesystem::path testing_assets_path =
146  flutter::testing::GetTestingAssetsPath();
147  std::filesystem::path target_path = testing_assets_path.parent_path()
148  .parent_path()
149  .parent_path()
150  .parent_path();
151  std::filesystem::path icd_path = target_path / "vk_swiftshader_icd.json";
152  setenv("VK_ICD_FILENAMES", icd_path.c_str(), 1);
153 
154  std::string test_name = GetTestName();
155  bool enable_wide_gamut = test_name.find("WideGamut_") != std::string::npos;
156  switch (GetParam()) {
158  if (!DoesSupportWideGamutTests()) {
159  GTEST_SKIP_(
160  "This metal device doesn't support wide gamut golden tests.");
161  }
162  pimpl_->screenshotter =
163  std::make_unique<testing::MetalScreenshotter>(enable_wide_gamut);
164  break;
166  if (enable_wide_gamut) {
167  GTEST_SKIP_("Vulkan doesn't support wide gamut golden tests.");
168  }
169  const std::unique_ptr<PlaygroundImpl>& playground =
170  GetSharedVulkanPlayground(/*enable_validations=*/true);
171  pimpl_->screenshotter =
172  std::make_unique<testing::VulkanScreenshotter>(playground);
173  break;
174  }
176  if (enable_wide_gamut) {
177  GTEST_SKIP_("OpenGLES doesn't support wide gamut golden tests.");
178  }
179  FML_CHECK(::glfwInit() == GLFW_TRUE);
180  PlaygroundSwitches playground_switches;
181  playground_switches.use_angle = true;
182  pimpl_->test_opengl_playground = PlaygroundImpl::Create(
183  PlaygroundBackend::kOpenGLES, playground_switches);
184  pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
185  pimpl_->test_opengl_playground);
186  break;
187  }
188  }
189 
190  if (std::find(kSkipTests.begin(), kSkipTests.end(), test_name) !=
191  kSkipTests.end()) {
192  GTEST_SKIP_(
193  "GoldenPlaygroundTest doesn't support interactive playground tests "
194  "yet.");
195  }
196 
198  "gpu_string", GetContext()->DescribeGpuModel());
199 }

References impeller::testing::GoldenDigest::AddDimension(), impeller::PlaygroundImpl::Create(), 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 83 of file golden_playground_test_stub.cc.

83 {}

◆ TearDown()

void impeller::GoldenPlaygroundTest::TearDown ( )

Definition at line 130 of file golden_playground_test_mac.cc.

130  {
131  ASSERT_FALSE(dlopen("/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
132 }

◆ WillRenderSomething()

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

TODO(https://github.com/flutter/flutter/issues/139950): Remove this. Returns true if OpenPlaygroundHere will actually render anything.

Definition at line 83 of file golden_playground_test.h.

83 { return true; }

The documentation for this class was generated from the following files:
impeller::PlaygroundBackend::kVulkan
@ kVulkan
impeller::RuntimeStage::DecodeRuntimeStages
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
Definition: runtime_stage.cc:61
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::GoldenPlaygroundTest::OpenPlaygroundHere
bool OpenPlaygroundHere(Picture picture)
Definition: golden_playground_test_mac.cc:205
impeller::GoldenPlaygroundTest::GetContext
std::shared_ptr< Context > GetContext() const
Definition: golden_playground_test_mac.cc:296
impeller::DlImageImpeller::Make
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Definition: dl_image_impeller.cc:12
impeller::kSkipTests
static const std::vector< std::string > kSkipTests
Definition: golden_playground_test_mac.cc:67
impeller::GoldenPlaygroundTest::CreateTextureForFixture
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: golden_playground_test_mac.cc:265
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:25
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
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:441
impeller::testing::GoldenDigest::Instance
static GoldenDigest * Instance()
Definition: golden_digest.cc:18
impeller::testing::GoldenDigest::AddDimension
void AddDimension(const std::string &name, const std::string &value)
Definition: golden_digest.cc:27
impeller::TypographerContextSkia::Make
static std::shared_ptr< TypographerContext > Make()
Definition: typographer_context_skia.cc:78