Flutter Impeller
impeller::Playground Class Referenceabstract

#include <playground.h>

Inheritance diagram for impeller::Playground:
impeller::ComputePlaygroundTest impeller::PlaygroundTest impeller::AiksPlayground impeller::DlPlayground impeller::EntityPlayground impeller::RuntimeStagePlayground impeller::interop::testing::PlaygroundTest impeller::testing::RendererDartTest impeller::testing::BlendFilterContentsTest impeller::testing::GaussianBlurFilterContentsTest impeller::testing::MatrixFilterContentsTest impeller::testing::MorphologyFilterContentsTest

Public Types

using SinglePassCallback = std::function< bool(RenderPass &pass)>
 
using RenderCallback = std::function< bool(RenderTarget &render_target)>
 
using GLProcAddressResolver = std::function< void *(const char *proc_name)>
 
using VKProcAddressResolver = std::function< void *(void *instance, const char *proc_name)>
 

Public Member Functions

 Playground (PlaygroundBackend backend, const PlaygroundSwitches &switches)
 
virtual ~Playground ()
 
bool IsPlaygroundEnabled () const
 
Point GetCursorPosition () const
 
ISize GetWindowSize () const
 
IRect GetWindowBounds () const
 
Point GetContentScale () const
 
Scalar GetSecondsElapsed () const
 Get the amount of time elapsed from the start of the playground's execution. More...
 
std::shared_ptr< Context > GetContext () const
 
std::shared_ptr< Context > MakeContext () const
 
ContentContext & GetContentContext () const
 
std::shared_ptr< TypographerContext > GetTypographerContext () const
 
bool OpenPlaygroundHere (const RenderCallback &render_callback)
 
bool OpenPlaygroundHere (SinglePassCallback pass_callback)
 
std::shared_ptr< Texture > CreateTextureForFixture (const char *fixture_name, bool enable_mipmapping=false) const
 
std::shared_ptr< Texture > CreateTextureCubeForFixture (std::array< const char *, 6 > fixture_names) const
 
virtual std::unique_ptr< fml::Mapping > OpenAssetAsMapping (std::string asset_name) const =0
 
virtual std::string GetWindowTitle () const =0
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities)
 
bool WillRenderSomething () const
 Returns true if OpenPlaygroundHere will actually render anything. More...
 
GLProcAddressResolver CreateGLProcAddressResolver () const
 
VKProcAddressResolver CreateVKProcAddressResolver () const
 
void SetGPUDisabled (bool disabled) const
 Mark the GPU as unavilable. More...
 
RuntimeStageBackend GetRuntimeStageBackend () const
 

Static Public Member Functions

static bool ShouldOpenNewPlaygrounds ()
 
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed (std::shared_ptr< fml::Mapping > mapping)
 
static std::optional< DecompressedImage > DecodeImageRGBA (const std::shared_ptr< CompressedImage > &compressed)
 
static std::shared_ptr< Texture > CreateTextureForMapping (const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
 
static bool SupportsBackend (PlaygroundBackend backend)
 

Protected Member Functions

void TearDownContextData ()
 
virtual bool ShouldKeepRendering () const
 
virtual void EnsureContextIsUnique ()
 Make sure that when the context is later created that it will not be shared with any other playgrounds. More...
 
bool PlatformSupportsWideGamutTests () const
 Returns true if the platform can support wide gamuts. More...
 
virtual bool EnsureContextSupportsWideGamut ()
 Make sure that when the context is later created that it will support wide gamuts if the platform supports it. Returns whether the platform supports wide gamut. More...
 
virtual void EnsureContextSupportsAntialiasLines ()
 Make sure that when the context is later created that it will support the experimental AA lines flag. More...
 
const PlaygroundSwitches & GetSwitches () const
 Return an unmodifiable reference to the current switches. The switches might change at the start of a test as it has a brief opportunity to call any of the Ensure* methods that define the environment it expects, but should be stable by the time any subsequent methods that might perform work are called. More...
 
void SetTypographerContext (std::shared_ptr< TypographerContext > typographer_context)
 
void SetWindowSize (ISize size)
 

Detailed Description

Definition at line 37 of file playground.h.

Member Typedef Documentation

◆ GLProcAddressResolver

using impeller::Playground::GLProcAddressResolver = std::function<void*(const char* proc_name)>

Definition at line 107 of file playground.h.

◆ RenderCallback

using impeller::Playground::RenderCallback = std::function<bool(RenderTarget& render_target)>

Definition at line 70 of file playground.h.

◆ SinglePassCallback

using impeller::Playground::SinglePassCallback = std::function<bool(RenderPass& pass)>

Definition at line 39 of file playground.h.

◆ VKProcAddressResolver

using impeller::Playground::VKProcAddressResolver = std::function<void*(void* instance, const char* proc_name)>

Definition at line 110 of file playground.h.

Constructor & Destructor Documentation

◆ Playground()

impeller::Playground::Playground ( PlaygroundBackend  backend,
const PlaygroundSwitches &  switches 
)
explicit

Definition at line 90 of file playground.cc.

92  : backend_(backend), switches_(switches) {
94  flutter::testing::SetupSwiftshaderOnce(switches_.use_swiftshader);
95 }
static void InitializeGLFWOnce()
Definition: playground.cc:64

References impeller::InitializeGLFWOnce(), and impeller::PlaygroundSwitches::use_swiftshader.

◆ ~Playground()

impeller::Playground::~Playground ( )
virtualdefault

Member Function Documentation

◆ CreateGLProcAddressResolver()

Playground::GLProcAddressResolver impeller::Playground::CreateGLProcAddressResolver ( ) const

Definition at line 610 of file playground.cc.

611  {
612  return GetImpl()->CreateGLProcAddressResolver();
613 }

Referenced by impeller::interop::testing::PlaygroundTest::CreateContext().

◆ CreateTextureCubeForFixture()

std::shared_ptr< Texture > impeller::Playground::CreateTextureCubeForFixture ( std::array< const char *, 6 >  fixture_names) const

Definition at line 547 of file playground.cc.

548  {
549  std::array<DecompressedImage, 6> images;
550  for (size_t i = 0; i < fixture_names.size(); i++) {
551  auto image = DecodeImageRGBA(
553  if (!image.has_value()) {
554  return nullptr;
555  }
556  images[i] = image.value();
557  }
558 
559  TextureDescriptor texture_descriptor;
560  texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
561  texture_descriptor.type = TextureType::kTextureCube;
562  texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
563  texture_descriptor.size = images[0].GetSize();
564  texture_descriptor.mip_count = 1u;
565 
566  auto texture =
567  GetContext()->GetResourceAllocator()->CreateTexture(texture_descriptor);
568  if (!texture) {
569  VALIDATION_LOG << "Could not allocate texture cube.";
570  return nullptr;
571  }
572  texture->SetLabel("Texture cube");
573 
574  auto cmd_buffer = GetContext()->CreateCommandBuffer();
575  auto blit_pass = cmd_buffer->CreateBlitPass();
576  for (size_t i = 0; i < fixture_names.size(); i++) {
577  auto device_buffer =
578  GetContext()->GetResourceAllocator()->CreateBufferWithCopy(
579  *images[i].GetAllocation());
580  blit_pass->AddCopy(DeviceBuffer::AsBufferView(device_buffer), texture, {},
581  "", /*mip_level=*/0, /*slice=*/i);
582  }
583 
584  if (!blit_pass->EncodeCommands() ||
585  !GetContext()->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok()) {
586  VALIDATION_LOG << "Could not upload texture to device memory.";
587  return nullptr;
588  }
589 
590  return texture;
591 }
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed(std::shared_ptr< fml::Mapping > mapping)
Definition: playground.cc:450
virtual std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const =0
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:126
static std::optional< DecompressedImage > DecodeImageRGBA(const std::shared_ptr< CompressedImage > &compressed)
Definition: playground.cc:461
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::DeviceBuffer::AsBufferView(), DecodeImageRGBA(), impeller::TextureDescriptor::format, GetContext(), impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::kTextureCube, LoadFixtureImageCompressed(), impeller::TextureDescriptor::mip_count, OpenAssetAsMapping(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::TextureDescriptor::type, and VALIDATION_LOG.

◆ CreateTextureForFixture()

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

Definition at line 535 of file playground.cc.

537  {
538  auto texture = CreateTextureForMapping(
539  GetContext(), OpenAssetAsMapping(fixture_name), enable_mipmapping);
540  if (texture == nullptr) {
541  return nullptr;
542  }
543  texture->SetLabel(fixture_name);
544  return texture;
545 }
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:522

References CreateTextureForMapping(), GetContext(), and OpenAssetAsMapping().

◆ CreateTextureForMapping()

std::shared_ptr< Texture > impeller::Playground::CreateTextureForMapping ( const std::shared_ptr< Context > &  context,
std::shared_ptr< fml::Mapping >  mapping,
bool  enable_mipmapping = false 
)
static

Definition at line 522 of file playground.cc.

525  {
526  auto image = Playground::DecodeImageRGBA(
527  Playground::LoadFixtureImageCompressed(std::move(mapping)));
528  if (!image.has_value()) {
529  return nullptr;
530  }
531  return CreateTextureForDecompressedImage(context, image.value(),
532  enable_mipmapping);
533 }
static std::shared_ptr< Texture > CreateTextureForDecompressedImage(const std::shared_ptr< Context > &context, DecompressedImage &decompressed_image, bool enable_mipmapping)
Definition: playground.cc:480
std::shared_ptr< ContextGLES > context

References context, impeller::CreateTextureForDecompressedImage(), DecodeImageRGBA(), and LoadFixtureImageCompressed().

Referenced by impeller::DlPlayground::CreateDlImageForFixture(), impeller::GoldenPlaygroundTest::CreateTextureForFixture(), and CreateTextureForFixture().

◆ CreateVKProcAddressResolver()

Playground::VKProcAddressResolver impeller::Playground::CreateVKProcAddressResolver ( ) const

Definition at line 615 of file playground.cc.

616  {
617  return GetImpl()->CreateVKProcAddressResolver();
618 }

Referenced by impeller::interop::testing::PlaygroundTest::CreateContext().

◆ DecodeImageRGBA()

std::optional< DecompressedImage > impeller::Playground::DecodeImageRGBA ( const std::shared_ptr< CompressedImage > &  compressed)
static

Definition at line 461 of file playground.cc.

462  {
463  if (compressed == nullptr) {
464  return std::nullopt;
465  }
466  // The decoded image is immediately converted into RGBA as that format is
467  // known to be supported everywhere. For image sources that don't need 32
468  // bit pixel strides, this is overkill. Since this is a test fixture we
469  // aren't necessarily trying to eke out memory savings here and instead
470  // favor simplicity.
471  auto image = compressed->Decode().ConvertToRGBA();
472  if (!image.IsValid()) {
473  VALIDATION_LOG << "Could not decode image.";
474  return std::nullopt;
475  }
476 
477  return image;
478 }

References VALIDATION_LOG.

Referenced by CreateTextureCubeForFixture(), CreateTextureForMapping(), and impeller::interop::testing::PlaygroundTest::OpenAssetAsHPPTexture().

◆ EnsureContextIsUnique()

void impeller::Playground::EnsureContextIsUnique ( )
protectedvirtual

Make sure that when the context is later created that it will not be shared with any other playgrounds.

Must be called before any other method except for the Ensure family of methods.

Definition at line 99 of file playground.cc.

99  {
100  FML_CHECK(!context_) << "Must be called before a context is created.";
101  switches_.can_share_context = false;
102 }

References impeller::PlaygroundSwitches::can_share_context.

◆ EnsureContextSupportsAntialiasLines()

void impeller::Playground::EnsureContextSupportsAntialiasLines ( )
protectedvirtual

Make sure that when the context is later created that it will support the experimental AA lines flag.

Must be called before any other method except for the Ensure family of methods.

Definition at line 121 of file playground.cc.

121  {
122  FML_CHECK(!context_) << "Must be called before a context is created.";
123  switches_.flags.antialiased_lines = true;
124 }
bool antialiased_lines
When turned on DrawLine will use the experimental antialiased path.
Definition: flags.h:11

References impeller::Flags::antialiased_lines, and impeller::PlaygroundSwitches::flags.

◆ EnsureContextSupportsWideGamut()

bool impeller::Playground::EnsureContextSupportsWideGamut ( )
protectedvirtual

Make sure that when the context is later created that it will support wide gamuts if the platform supports it. Returns whether the platform supports wide gamut.

Must be called before any other method except for the Ensure family of methods.

Callers should abort (such as via GTEST_SKIP) if the method returns false if their behavior depends on the wide gamut support.

See also
PlatformSupportsWideGamut()

Definition at line 112 of file playground.cc.

112  {
113  FML_CHECK(!context_) << "Must be called before a context is created.";
115  return false;
116  }
117  switches_.enable_wide_gamut = true;
118  return true;
119 }
bool PlatformSupportsWideGamutTests() const
Returns true if the platform can support wide gamuts.
Definition: playground.cc:104

References impeller::PlaygroundSwitches::enable_wide_gamut, and PlatformSupportsWideGamutTests().

◆ GetContentContext()

ContentContext & impeller::Playground::GetContentContext ( ) const

Definition at line 146 of file playground.cc.

146  {
147  if (!content_context_) {
148  content_context_ =
149  std::make_unique<ContentContext>(GetContext(), GetTypographerContext());
150  FML_CHECK(content_context_) << "Failed to create ContentContext";
151  }
152  return *content_context_;
153 }
std::shared_ptr< TypographerContext > GetTypographerContext() const
Definition: playground.cc:155

References GetContext(), and GetTypographerContext().

Referenced by impeller::testing::BlendFilterContentsTest::MakeTexture(), impeller::testing::GaussianBlurFilterContentsTest::MakeTexture(), impeller::testing::MatrixFilterContentsTest::MakeTexture(), impeller::testing::MorphologyFilterContentsTest::MakeTexture(), and impeller::EntityPlayground::OpenPlaygroundHere().

◆ GetContentScale()

Point impeller::Playground::GetContentScale ( ) const

◆ GetContext()

◆ GetCursorPosition()

Point impeller::Playground::GetCursorPosition ( ) const

Definition at line 263 of file playground.cc.

263  {
264  return cursor_position_;
265 }

◆ GetRuntimeStageBackend()

RuntimeStageBackend impeller::Playground::GetRuntimeStageBackend ( ) const

Definition at line 624 of file playground.cc.

624  {
625  return GetImpl()->GetRuntimeStageBackend();
626 }

◆ GetSecondsElapsed()

Scalar impeller::Playground::GetSecondsElapsed ( ) const

Get the amount of time elapsed from the start of the playground's execution.

Definition at line 279 of file playground.cc.

279  {
280  return (fml::TimePoint::Now().ToEpochDelta() - start_time_).ToSecondsF();
281 }

◆ GetSwitches()

const PlaygroundSwitches& impeller::Playground::GetSwitches ( ) const
inlineprotected

Return an unmodifiable reference to the current switches. The switches might change at the start of a test as it has a brief opportunity to call any of the Ensure* methods that define the environment it expects, but should be stable by the time any subsequent methods that might perform work are called.

Definition at line 167 of file playground.h.

167 { return switches_; }

Referenced by impeller::interop::testing::PlaygroundTest::CreateContext(), and impeller::PlaygroundTest::GetWindowTitle().

◆ GetTypographerContext()

std::shared_ptr< TypographerContext > impeller::Playground::GetTypographerContext ( ) const

Definition at line 155 of file playground.cc.

155  {
156  if (!typographer_context_) {
157  typographer_context_ = TypographerContextSkia::Make();
158  }
159  return typographer_context_;
160 }
static std::shared_ptr< TypographerContext > Make()

References impeller::TypographerContextSkia::Make().

Referenced by GetContentContext().

◆ GetWindowBounds()

IRect impeller::Playground::GetWindowBounds ( ) const

Definition at line 271 of file playground.cc.

271  {
272  return IRect::MakeSize(window_size_);
273 }
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150

References impeller::TRect< T >::MakeSize().

◆ GetWindowSize()

ISize impeller::Playground::GetWindowSize ( ) const

◆ GetWindowTitle()

virtual std::string impeller::Playground::GetWindowTitle ( ) const
pure virtual

◆ IsPlaygroundEnabled()

bool impeller::Playground::IsPlaygroundEnabled ( ) const

◆ LoadFixtureImageCompressed()

std::shared_ptr< CompressedImage > impeller::Playground::LoadFixtureImageCompressed ( std::shared_ptr< fml::Mapping >  mapping)
static

Definition at line 450 of file playground.cc.

451  {
452  auto compressed_image = CompressedImageSkia::Create(std::move(mapping));
453  if (!compressed_image) {
454  VALIDATION_LOG << "Could not create compressed image.";
455  return nullptr;
456  }
457 
458  return compressed_image;
459 }
static std::shared_ptr< CompressedImage > Create(std::shared_ptr< const fml::Mapping > allocation)

References impeller::CompressedImageSkia::Create(), and VALIDATION_LOG.

Referenced by CreateTextureCubeForFixture(), CreateTextureForMapping(), and impeller::interop::testing::PlaygroundTest::OpenAssetAsHPPTexture().

◆ MakeContext()

std::shared_ptr< Context > impeller::Playground::MakeContext ( ) const

Definition at line 133 of file playground.cc.

133  {
134  // This method is used to get a unique context that is not shared with
135  // other playground tests. It requires that the test has called the
136  // |EnsureContextIsUnique| method before it calls this method. We
137  // verify those conditions here and then set up the context.
138  FML_CHECK(!context_) << "MakeContext can only be called once";
139  FML_CHECK(!switches_.can_share_context)
140  << "MakeContext should only be called after EnsureContextIsUnique()";
141  SetupContext();
142 
143  return context_;
144 }

References impeller::PlaygroundSwitches::can_share_context.

◆ OpenAssetAsMapping()

virtual std::unique_ptr<fml::Mapping> impeller::Playground::OpenAssetAsMapping ( std::string  asset_name) const
pure virtual

◆ OpenPlaygroundHere() [1/2]

bool impeller::Playground::OpenPlaygroundHere ( const RenderCallback &  render_callback)

Definition at line 287 of file playground.cc.

288  {
289  std::shared_ptr<Context> context = GetContext();
290  FML_CHECK(context);
291 
292  if (!switches_.enable_playground) {
293  return true;
294  }
295 
296  if (!render_callback) {
297  return true;
298  }
299 
300  IMGUI_CHECKVERSION();
302  fml::ScopedCleanupClosure destroy_imgui_context(
303  []() { ImGui::DestroyContext(); });
304  ImGui::StyleColorsDark();
305 
306  auto& io = ImGui::GetIO();
307  io.IniFilename = nullptr;
308  io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
309  io.ConfigWindowsResizeFromEdges = true;
310 
311  auto window = reinterpret_cast<GLFWwindow*>(GetImpl()->GetWindowHandle());
312  if (!window) {
313  return false;
314  }
315  ::glfwSetWindowTitle(window, GetWindowTitle().c_str());
316  ::glfwSetWindowUserPointer(window, this);
317  ::glfwSetWindowSizeCallback(
318  window, [](GLFWwindow* window, int width, int height) -> void {
319  auto playground =
320  reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window));
321  if (!playground) {
322  return;
323  }
324  playground->SetWindowSize(ISize{width, height}.Max({}));
325  });
326  ::glfwSetKeyCallback(window, &PlaygroundKeyCallback);
327  ::glfwSetCursorPosCallback(window, [](GLFWwindow* window, double x,
328  double y) {
329  reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window))
330  ->SetCursorPosition({static_cast<Scalar>(x), static_cast<Scalar>(y)});
331  });
332 
333  ImGui_ImplGlfw_InitForOther(window, true);
334  fml::ScopedCleanupClosure shutdown_imgui([]() { ImGui_ImplGlfw_Shutdown(); });
335 
337  fml::ScopedCleanupClosure shutdown_imgui_impeller(
338  []() { ImGui_ImplImpeller_Shutdown(); });
339 
340  ImGui::SetNextWindowPos({10, 10});
341 
342  ::glfwSetWindowSize(window, GetWindowSize().width, GetWindowSize().height);
343  ::glfwSetWindowPos(window, 200, 100);
344  ::glfwShowWindow(window);
345 
346  while (true) {
347 #if FML_OS_MACOSX
348  fml::ScopedNSAutoreleasePool pool;
349 #endif
350  ::glfwPollEvents();
351 
352  if (::glfwWindowShouldClose(window)) {
353  return true;
354  }
355 
356  ImGui_ImplGlfw_NewFrame();
357 
358  auto surface = GetImpl()->AcquireSurfaceFrame(context);
359  RenderTarget render_target = surface->GetRenderTarget();
360 
361  ImGui::NewFrame();
362  ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(),
363  ImGuiDockNodeFlags_PassthruCentralNode);
364  bool result = render_callback(render_target);
365  ImGui::Render();
366 
367  // Render ImGui overlay.
368  {
369  auto buffer = context->CreateCommandBuffer();
370  if (!buffer) {
371  VALIDATION_LOG << "Could not create command buffer.";
372  return false;
373  }
374  buffer->SetLabel("ImGui Command Buffer");
375 
376  auto color0 = render_target.GetColorAttachment(0);
377  color0.load_action = LoadAction::kLoad;
378  if (color0.resolve_texture) {
379  color0.texture = color0.resolve_texture;
380  color0.resolve_texture = nullptr;
381  color0.store_action = StoreAction::kStore;
382  }
383  render_target.SetColorAttachment(color0, 0);
384  render_target.SetStencilAttachment(std::nullopt);
385  render_target.SetDepthAttachment(std::nullopt);
386 
387  auto pass = buffer->CreateRenderPass(render_target);
388  if (!pass) {
389  VALIDATION_LOG << "Could not create render pass.";
390  return false;
391  }
392  pass->SetLabel("ImGui Render Pass");
393  if (!host_buffer_) {
394  host_buffer_ = HostBuffer::Create(
395  context->GetResourceAllocator(), context->GetIdleWaiter(),
396  context->GetCapabilities()->GetMinimumUniformAlignment());
397  }
398 
399  ImGui_ImplImpeller_RenderDrawData(ImGui::GetDrawData(), *pass,
400  *host_buffer_);
401 
402  pass->EncodeCommands();
403 
404  if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
405  return false;
406  }
407  }
408 
409  if (!result || !surface->Present()) {
410  return false;
411  }
412 
413  if (!ShouldKeepRendering()) {
414  break;
415  }
416  }
417 
418  ::glfwHideWindow(window);
419 
420  return true;
421 }
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter, size_t minimum_uniform_alignment)
Definition: host_buffer.cc:21
virtual bool ShouldKeepRendering() const
Definition: playground.cc:597
ISize GetWindowSize() const
Definition: playground.cc:267
virtual std::string GetWindowTitle() const =0
Playground(PlaygroundBackend backend, const PlaygroundSwitches &switches)
Definition: playground.cc:90
int32_t x
void ImGui_ImplImpeller_RenderDrawData(ImDrawData *draw_data, impeller::RenderPass &render_pass, impeller::HostBuffer &host_buffer)
bool ImGui_ImplImpeller_Init(const std::shared_ptr< impeller::Context > &context)
void ImGui_ImplImpeller_Shutdown()
std::shared_ptr< ContextVK > CreateContext()
float Scalar
Definition: scalar.h:19
static void PlaygroundKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: playground.cc:250
ISize64 ISize
Definition: size.h:162
constexpr TSize Max(const TSize &o) const
Definition: size.h:97

References context, impeller::HostBuffer::Create(), impeller::android::testing::CreateContext(), impeller::PlaygroundSwitches::enable_playground, impeller::RenderTarget::GetColorAttachment(), GetContext(), GetWindowSize(), GetWindowTitle(), ImGui_ImplImpeller_Init(), ImGui_ImplImpeller_RenderDrawData(), ImGui_ImplImpeller_Shutdown(), impeller::kLoad, impeller::kStore, impeller::Attachment::load_action, impeller::TSize< T >::Max(), impeller::PlaygroundKeyCallback(), impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetDepthAttachment(), impeller::RenderTarget::SetStencilAttachment(), SetWindowSize(), ShouldKeepRendering(), VALIDATION_LOG, and x.

Referenced by impeller::AiksPlayground::OpenPlaygroundHere(), impeller::DlPlayground::OpenPlaygroundHere(), impeller::EntityPlayground::OpenPlaygroundHere(), impeller::interop::testing::PlaygroundTest::OpenPlaygroundHere(), OpenPlaygroundHere(), impeller::testing::RendererDartTest::RenderDartToPlayground(), and impeller::testing::TEST_P().

◆ OpenPlaygroundHere() [2/2]

bool impeller::Playground::OpenPlaygroundHere ( SinglePassCallback  pass_callback)

Definition at line 423 of file playground.cc.

423  {
424  return OpenPlaygroundHere(
425  [context = GetContext(), &pass_callback](RenderTarget& render_target) {
426  auto buffer = context->CreateCommandBuffer();
427  if (!buffer) {
428  return false;
429  }
430  buffer->SetLabel("Playground Command Buffer");
431 
432  auto pass = buffer->CreateRenderPass(render_target);
433  if (!pass) {
434  return false;
435  }
436  pass->SetLabel("Playground Render Pass");
437 
438  if (!pass_callback(*pass)) {
439  return false;
440  }
441 
442  pass->EncodeCommands();
443  if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
444  return false;
445  }
446  return true;
447  });
448 }
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:287

References context, GetContext(), and OpenPlaygroundHere().

◆ PlatformSupportsWideGamutTests()

bool impeller::Playground::PlatformSupportsWideGamutTests ( ) const
protected

Returns true if the platform can support wide gamuts.

Definition at line 104 of file playground.cc.

104  {
105 #if __arm64__ && FML_OS_MACOSX
106  return backend_ == PlaygroundBackend::kMetal;
107 #else
108  return false;
109 #endif
110 }

References impeller::kMetal.

Referenced by EnsureContextSupportsWideGamut().

◆ SetCapabilities()

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

Definition at line 601 of file playground.cc.

602  {
603  return GetImpl()->SetCapabilities(capabilities);
604 }

◆ SetGPUDisabled()

void impeller::Playground::SetGPUDisabled ( bool  disabled) const

Mark the GPU as unavilable.

Only supported on the Metal backend.

Definition at line 620 of file playground.cc.

620  {
621  GetImpl()->SetGPUDisabled(value);
622 }
int32_t value

References value.

◆ SetTypographerContext()

void impeller::Playground::SetTypographerContext ( std::shared_ptr< TypographerContext >  typographer_context)
protected

Definition at line 162 of file playground.cc.

163  {
164  FML_CHECK(!typographer_context_)
165  << "SetTypographerContext called after it has already been initialized";
166  typographer_context_ = std::move(typographer_context);
167 }

◆ SetWindowSize()

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

Definition at line 593 of file playground.cc.

593  {
594  window_size_ = size;
595 }

Referenced by OpenPlaygroundHere().

◆ ShouldKeepRendering()

bool impeller::Playground::ShouldKeepRendering ( ) const
protectedvirtual

Definition at line 597 of file playground.cc.

597  {
598  return true;
599 }

Referenced by OpenPlaygroundHere().

◆ ShouldOpenNewPlaygrounds()

bool impeller::Playground::ShouldOpenNewPlaygrounds ( )
static

Definition at line 246 of file playground.cc.

246  {
248 }
static std::atomic_bool gShouldOpenNewPlaygrounds
Definition: playground.cc:244

References impeller::gShouldOpenNewPlaygrounds.

Referenced by impeller::ComputePlaygroundTest::SetUp(), and impeller::PlaygroundTest::SetUp().

◆ SupportsBackend()

bool impeller::Playground::SupportsBackend ( PlaygroundBackend  backend)
static

Definition at line 169 of file playground.cc.

169  {
170  switch (backend) {
173 #if IMPELLER_ENABLE_METAL
174  return true;
175 #else // IMPELLER_ENABLE_METAL
176  return false;
177 #endif // IMPELLER_ENABLE_METAL
180 #if IMPELLER_ENABLE_OPENGLES
181  return true;
182 #else // IMPELLER_ENABLE_OPENGLES
183  return false;
184 #endif // IMPELLER_ENABLE_OPENGLES
186 #if IMPELLER_ENABLE_VULKAN
188 #else // IMPELLER_ENABLE_VULKAN
189  return false;
190 #endif // IMPELLER_ENABLE_VULKAN
191  }
192  FML_UNREACHABLE();
193 }

References impeller::PlaygroundImplVK::IsVulkanDriverPresent(), impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, and impeller::kVulkan.

Referenced by impeller::ComputePlaygroundTest::SetUp(), and impeller::PlaygroundTest::SetUp().

◆ TearDownContextData()

void impeller::Playground::TearDownContextData ( )
protected

Definition at line 228 of file playground.cc.

228  {
229  if (content_context_) {
230  FML_CHECK(context_);
231  [[maybe_unused]] auto result = context_->FlushCommandBuffers();
232  content_context_.reset();
233  }
234  if (host_buffer_) {
235  host_buffer_.reset();
236  }
237  if (context_) {
238  context_->Shutdown();
239  }
240  context_.reset();
241  impl_.reset();
242 }

Referenced by impeller::ComputePlaygroundTest::TearDown(), and impeller::PlaygroundTest::TearDown().

◆ WillRenderSomething()

bool impeller::Playground::WillRenderSomething ( ) const

Returns true if OpenPlaygroundHere will actually render anything.

Definition at line 606 of file playground.cc.

606  {
607  return switches_.enable_playground;
608 }

References impeller::PlaygroundSwitches::enable_playground.


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