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

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)
 
std::shared_ptr< TextureCreateTextureForFixture (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 23 of file golden_playground_test.h.

Member Typedef Documentation

◆ AiksPlaygroundCallback

using impeller::GoldenPlaygroundTest::AiksPlaygroundCallback = std::function<std::optional<Picture>(AiksContext& renderer)>

Definition at line 27 of file golden_playground_test.h.

Constructor & Destructor Documentation

◆ GoldenPlaygroundTest()

impeller::GoldenPlaygroundTest::GoldenPlaygroundTest ( )
default

Definition at line 116 of file golden_playground_test_mac.cc.

117  : typographer_context_(TypographerContextSkia::Make()),
118  pimpl_(new GoldenPlaygroundTest::GoldenPlaygroundTestImpl()) {}

◆ ~GoldenPlaygroundTest()

impeller::GoldenPlaygroundTest::~GoldenPlaygroundTest ( )
overridedefault

Member Function Documentation

◆ CreateTextureForFixture()

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

Definition at line 221 of file golden_playground_test_mac.cc.

223  {
224  std::shared_ptr<fml::Mapping> mapping =
225  flutter::testing::OpenFixtureAsMapping(fixture_name);
226  auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
227  enable_mipmapping);
228  if (result) {
229  result->SetLabel(fixture_name);
230  }
231  return result;
232 }

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

◆ GetBackend()

PlaygroundBackend impeller::GoldenPlaygroundTest::GetBackend ( ) const

Definition at line 184 of file golden_playground_test_mac.cc.

184  {
185  return GetParam();
186 }

◆ GetContentScale()

Point impeller::GoldenPlaygroundTest::GetContentScale ( ) const

Definition at line 267 of file golden_playground_test_mac.cc.

267  {
268  return pimpl_->screenshotter->GetPlayground().GetContentScale();
269 }

◆ GetContext()

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

Definition at line 244 of file golden_playground_test_mac.cc.

244  {
245  return pimpl_->screenshotter->GetPlayground().GetContext();
246 }

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

◆ GetSecondsElapsed()

Scalar impeller::GoldenPlaygroundTest::GetSecondsElapsed ( ) const

Definition at line 271 of file golden_playground_test_mac.cc.

271  {
272  return 0.0f;
273 }

◆ GetWindowSize()

ISize impeller::GoldenPlaygroundTest::GetWindowSize ( ) const

Definition at line 275 of file golden_playground_test_mac.cc.

275  {
276  return pimpl_->window_size;
277 }

◆ ImGuiBegin()

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

Definition at line 215 of file golden_playground_test_mac.cc.

217  {
218  return false;
219 }

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

248  {
249  if (GetParam() == PlaygroundBackend::kMetal) {
250  /// On Metal we create a context for each test.
251  return GetContext();
252  } else if (GetParam() == PlaygroundBackend::kVulkan) {
253  bool enable_vulkan_validations = true;
254  FML_CHECK(!pimpl_->test_vulkan_playground)
255  << "We don't support creating multiple contexts for one test";
256  pimpl_->test_vulkan_playground =
257  MakeVulkanPlayground(enable_vulkan_validations);
258  pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
259  pimpl_->test_vulkan_playground);
260  return pimpl_->test_vulkan_playground->GetContext();
261  } else {
262  /// On OpenGL we create a context for each test.
263  return GetContext();
264  }
265 }

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

◆ OpenAssetAsRuntimeStage()

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

Definition at line 234 of file golden_playground_test_mac.cc.

235  {
236  const std::shared_ptr<fml::Mapping> fixture =
237  flutter::testing::OpenFixtureAsMapping(asset_name);
238  if (!fixture || fixture->GetSize() == 0) {
239  return {};
240  }
241  return RuntimeStage::DecodeRuntimeStages(fixture);
242 }

References impeller::RuntimeStage::DecodeRuntimeStages().

◆ OpenPlaygroundHere() [1/2]

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

Definition at line 196 of file golden_playground_test_mac.cc.

198  { // NOLINT(performance-unnecessary-value-param)
199  AiksContext renderer(GetContext(), typographer_context_);
200 
201  std::optional<Picture> picture;
202  std::unique_ptr<testing::Screenshot> screenshot;
203  for (int i = 0; i < 2; ++i) {
204  picture = callback(renderer);
205  if (!picture.has_value()) {
206  return false;
207  }
208  screenshot = pimpl_->screenshotter->MakeScreenshot(
209  renderer, picture.value(), pimpl_->window_size);
210  }
211 
212  return SaveScreenshot(std::move(screenshot));
213 }

References GetContext().

◆ OpenPlaygroundHere() [2/2]

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

Definition at line 188 of file golden_playground_test_mac.cc.

188  {
189  AiksContext renderer(GetContext(), typographer_context_);
190 
191  auto screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, picture,
192  pimpl_->window_size);
193  return SaveScreenshot(std::move(screenshot));
194 }

References GetContext().

◆ SetCapabilities()

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

Definition at line 283 of file golden_playground_test_mac.cc.

284  {
285  return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
286 }

◆ SetTypographerContext()

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

Definition at line 122 of file golden_playground_test_mac.cc.

123  {
124  typographer_context_ = std::move(typographer_context);
125 };

◆ SetUp()

void impeller::GoldenPlaygroundTest::SetUp ( )

Definition at line 131 of file golden_playground_test_mac.cc.

131  {
132  std::filesystem::path testing_assets_path =
133  flutter::testing::GetTestingAssetsPath();
134  std::filesystem::path target_path = testing_assets_path.parent_path()
135  .parent_path()
136  .parent_path()
137  .parent_path();
138  std::filesystem::path icd_path = target_path / "vk_swiftshader_icd.json";
139  setenv("VK_ICD_FILENAMES", icd_path.c_str(), 1);
140 
141  switch (GetParam()) {
143  pimpl_->screenshotter = std::make_unique<testing::MetalScreenshotter>();
144  break;
146  const std::unique_ptr<PlaygroundImpl>& playground =
147  GetSharedVulkanPlayground(/*enable_validations=*/true);
148  pimpl_->screenshotter =
149  std::make_unique<testing::VulkanScreenshotter>(playground);
150  break;
151  }
153  FML_CHECK(::glfwInit() == GLFW_TRUE);
154  PlaygroundSwitches playground_switches;
155  playground_switches.use_angle = true;
156  pimpl_->test_opengl_playground = PlaygroundImpl::Create(
157  PlaygroundBackend::kOpenGLES, playground_switches);
158  pimpl_->screenshotter = std::make_unique<testing::VulkanScreenshotter>(
159  pimpl_->test_opengl_playground);
160  break;
161  }
162  }
163  if (GetParam() == PlaygroundBackend::kMetal) {
164  pimpl_->screenshotter = std::make_unique<testing::MetalScreenshotter>();
165  } else if (GetParam() == PlaygroundBackend::kVulkan) {
166  const std::unique_ptr<PlaygroundImpl>& playground =
167  GetSharedVulkanPlayground(/*enable_validations=*/true);
168  pimpl_->screenshotter =
169  std::make_unique<testing::VulkanScreenshotter>(playground);
170  }
171 
172  std::string test_name = GetTestName();
173  if (std::find(kSkipTests.begin(), kSkipTests.end(), test_name) !=
174  kSkipTests.end()) {
175  GTEST_SKIP_(
176  "GoldenPlaygroundTest doesn't support interactive playground tests "
177  "yet.");
178  }
179 
181  "gpu_string", GetContext()->DescribeGpuModel());
182 }

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 66 of file golden_playground_test_stub.cc.

66 {}

◆ TearDown()

void impeller::GoldenPlaygroundTest::TearDown ( )

Definition at line 127 of file golden_playground_test_mac.cc.

127  {
128  ASSERT_FALSE(dlopen("/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
129 }

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

71 { 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:60
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::GoldenPlaygroundTest::GetContext
std::shared_ptr< Context > GetContext() const
Definition: golden_playground_test_mac.cc:244
impeller::kSkipTests
static const std::vector< std::string > kSkipTests
Definition: golden_playground_test_mac.cc:64
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:436
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:32