| Flutter Impeller |

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
impeller::Playground Class Referenceabstract

`#include <playground.h>`

Inheritance diagram for impeller::Playground:

## 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 (PlaygroundSwitches switches)
virtual | ~Playground ()
void | SetupContext (PlaygroundBackend backend, const PlaygroundSwitches &switches)
void | SetupWindow ()
void | TeardownWindow ()
bool | IsPlaygroundEnabled () const
Point | GetCursorPosition () const
ISize | GetWindowSize () 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
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

## 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
virtual bool | ShouldKeepRendering () const
void | SetWindowSize (ISize size)

## Protected Attributes
const PlaygroundSwitches | switches_

## Detailed Description

Definition at line 48 of file playground.h.

## Member Typedef Documentation

## ◆ GLProcAddressResolver

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

Definition at line 118 of file playground.h.

## ◆ RenderCallback

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

Definition at line 81 of file playground.h.

## ◆ SinglePassCallback

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

Definition at line 50 of file playground.h.

## ◆ VKProcAddressResolver

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

Definition at line 121 of file playground.h.

## Constructor & Destructor Documentation

## ◆ Playground()

impeller::Playground::Playground | ( | PlaygroundSwitches | switches | ) |
| explicit

Definition at line 84 of file playground.cc.

84 : switches_(switches) {
85 InitializeGLFWOnce();
86 SetupSwiftshaderOnce(switches_.use_swiftshader);
87 }
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:126
impeller::InitializeGLFWOnce
static void InitializeGLFWOnce()
Definition: playground.cc:58
impeller::SetupSwiftshaderOnce
void SetupSwiftshaderOnce(bool use_swiftshader)
Find and setup the installable client driver for a locally built SwiftShader at known paths....
Definition: swiftshader_utilities.cc:54
impeller::PlaygroundSwitches::use_swiftshader
bool use_swiftshader
Definition: switches.h:28

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

## ◆ ~Playground()

impeller::Playground::~Playground | ( |  | ) |
| virtual default

## Member Function Documentation

## ◆ CreateGLProcAddressResolver()

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

Definition at line 519 of file playground.cc.

520 {
521 return impl_->CreateGLProcAddressResolver();
522 }

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 457 of file playground.cc.

458 {
459 std::array<DecompressedImage, 6> images;
460 for (size_t i = 0; i < fixture_names.size(); i++) {
461 auto image = DecodeImageRGBA(
462 LoadFixtureImageCompressed(OpenAssetAsMapping(fixture_names[i])));
463 if (!image.has_value()) {
464 return nullptr;
465 }
466 images[i] = image.value();
467 }
468
469 TextureDescriptor texture_descriptor;
470 texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
471 texture_descriptor.type = TextureType::kTextureCube;
472 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
473 texture_descriptor.size = images[0].GetSize();
474 texture_descriptor.mip_count = 1u;
475
476 auto texture =
477 context_->GetResourceAllocator()->CreateTexture(texture_descriptor);
478 if (!texture) {
479 VALIDATION_LOG << "Could not allocate texture cube.";
480 return nullptr;
481 }
482 texture->SetLabel("Texture cube");
483
484 auto cmd_buffer = context_->CreateCommandBuffer();
485 auto blit_pass = cmd_buffer->CreateBlitPass();
486 for (size_t i = 0; i < fixture_names.size(); i++) {
487 auto device_buffer = context_->GetResourceAllocator()->CreateBufferWithCopy(
488 *images[i].GetAllocation());
489 blit_pass->AddCopy(DeviceBuffer::AsBufferView(device_buffer), texture, {},
490 "", /*mip_level=*/0, /*slice=*/i);
491 }
492
493 if (!blit_pass->EncodeCommands() ||
494 !context_->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok()) {
495 VALIDATION_LOG << "Could not upload texture to device memory.";
496 return nullptr;
497 }
498
499 return texture;
500 }
impeller::DeviceBuffer::AsBufferView
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
Definition: device_buffer.cc:18
impeller::Playground::LoadFixtureImageCompressed
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed(std::shared_ptr< fml::Mapping > mapping)
Definition: playground.cc:360
impeller::Playground::OpenAssetAsMapping
virtual std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const =0
impeller::Playground::DecodeImageRGBA
static std::optional< DecompressedImage > DecodeImageRGBA(const std::shared_ptr< CompressedImage > &compressed)
Definition: playground.cc:371
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::TextureType::kTextureCube
@ kTextureCube
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::DeviceBuffer::AsBufferView(), DecodeImageRGBA(), impeller::TextureDescriptor::format, 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 445 of file playground.cc.

447 {
448 auto texture = CreateTextureForMapping(
449 context_, OpenAssetAsMapping(fixture_name), enable_mipmapping);
450 if (texture == nullptr) {
451 return nullptr;
452 }
453 texture->SetLabel(fixture_name);
454 return texture;
455 }
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:432

References CreateTextureForMapping(), 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 432 of file playground.cc.

435 {
436 auto image = Playground::DecodeImageRGBA(
437 Playground::LoadFixtureImageCompressed(std::move(mapping)));
438 if (!image.has_value()) {
439 return nullptr;
440 }
441 return CreateTextureForDecompressedImage(context, image.value(),
442 enable_mipmapping);
443 }
impeller::CreateTextureForDecompressedImage
static std::shared_ptr< Texture > CreateTextureForDecompressedImage(const std::shared_ptr< Context > &context, DecompressedImage &decompressed_image, bool enable_mipmapping)
Definition: playground.cc:390

References 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 524 of file playground.cc.

525 {
526 return impl_->CreateVKProcAddressResolver();
527 }

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

## ◆ DecodeImageRGBA()

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

Definition at line 371 of file playground.cc.

372 {
373 if (compressed == nullptr) {
374 return std::nullopt;
375 }
376 // The decoded image is immediately converted into RGBA as that format is
377 // known to be supported everywhere. For image sources that don't need 32
378 // bit pixel strides, this is overkill. Since this is a test fixture we
379 // aren't necessarily trying to eke out memory savings here and instead
380 // favor simplicity.
381 auto image = compressed->Decode().ConvertToRGBA();
382 if (!image.IsValid()) {
383 VALIDATION_LOG << "Could not decode image.";
384 return std::nullopt;
385 }
386
387 return image;
388 }

References VALIDATION_LOG.

Referenced by CreateTextureCubeForFixture(), and CreateTextureForMapping().

## ◆ GetContentScale()

Point impeller::Playground::GetContentScale | ( |  | ) | const

Definition at line 189 of file playground.cc.

189 {
190 return impl_->GetContentScale();
191 }

Referenced by impeller::testing::CanRenderConicalGradientWithDithering(), impeller::testing::CanRenderSweepGradientWithDithering(), and impeller::testing::MaskBlurVariantTest().

## ◆ GetContext()

std::shared_ptr< Context > impeller::Playground::GetContext | ( |  | ) | const

Definition at line 91 of file playground.cc.

91 {
92 return context_;
93 }

Referenced by impeller::DlPlayground::CreateDlImageForFixture(), impeller::EntityPlayground::GetContentContext(), impeller::interop::testing::PlaygroundTest::GetInteropContext(), impeller::testing::RendererDartTest::GetIsolate(), impeller::testing::BlendFilterContentsTest::MakeTexture(), impeller::testing::GaussianBlurFilterContentsTest::MakeTexture(), impeller::testing::MatrixFilterContentsTest::MakeTexture(), impeller::AiksPlayground::OpenPlaygroundHere(), impeller::DlPlayground::OpenPlaygroundHere(), impeller::EntityPlayground::OpenPlaygroundHere(), OpenPlaygroundHere(), impeller::RuntimeStagePlayground::RegisterStage(), and impeller::testing::RendererDartTest::RenderDartToPlayground().

## ◆ GetCursorPosition()

Point impeller::Playground::GetCursorPosition | ( |  | ) | const

Definition at line 181 of file playground.cc.

181 {
182 return cursor_position_;
183 }

## ◆ GetSecondsElapsed()

Scalar impeller::Playground::GetSecondsElapsed | ( |  | ) | const

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

Definition at line 193 of file playground.cc.

193 {
194 return (fml::TimePoint::Now().ToEpochDelta() - start_time_).ToSecondsF();
195 }

## ◆ GetWindowSize()

ISize impeller::Playground::GetWindowSize | ( |  | ) | const

Definition at line 185 of file playground.cc.

185 {
186 return window_size_;
187 }

Referenced by impeller::testing::RendererDartTest::GetRenderedTextureFromDart(), OpenPlaygroundHere(), and impeller::testing::RendererDartTest::RunDartFunctionWithWindowSize().

## ◆ GetWindowTitle()

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

Implemented in impeller::PlaygroundTest, and impeller::ComputePlaygroundTest.

Referenced by OpenPlaygroundHere().

## ◆ IsPlaygroundEnabled()

bool impeller::Playground::IsPlaygroundEnabled | ( |  | ) | const

Definition at line 147 of file playground.cc.

147 {
148 return switches_.enable_playground;
149 }
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:17

References impeller::PlaygroundSwitches::enable_playground, and switches_.

Referenced by impeller::testing::RendererDartTest::RenderDartToPlayground().

## ◆ LoadFixtureImageCompressed()

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

Definition at line 360 of file playground.cc.

361 {
362 auto compressed_image = CompressedImageSkia::Create(std::move(mapping));
363 if (!compressed_image) {
364 VALIDATION_LOG << "Could not create compressed image.";
365 return nullptr;
366 }
367
368 return compressed_image;
369 }
impeller::CompressedImageSkia::Create
static std::shared_ptr< CompressedImage > Create(std::shared_ptr< const fml::Mapping > allocation)
Definition: compressed_image_skia.cc:18

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

Referenced by CreateTextureCubeForFixture(), and CreateTextureForMapping().

## ◆ MakeContext()

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

Definition at line 95 of file playground.cc.

95 {
96 // Playgrounds are already making a context for each test, so we can just
97 // return the `context_`.
98 return context_;
99 }

## ◆ OpenAssetAsMapping()

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

Implemented in impeller::PlaygroundTest, and impeller::ComputePlaygroundTest.

Referenced by CreateTextureCubeForFixture(), and CreateTextureForFixture().

## ◆ OpenPlaygroundHere() [1/2]

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

Definition at line 201 of file playground.cc.

202 {
203 if (!switches_.enable_playground) {
204 return true;
205 }
206
207 if (!render_callback) {
208 return true;
209 }
210
211 IMGUI_CHECKVERSION();
212 ImGui::CreateContext();
213 fml::ScopedCleanupClosure destroy_imgui_context(
214 []() { ImGui::DestroyContext(); });
215 ImGui::StyleColorsDark();
216
217 auto& io = ImGui::GetIO();
218 io.IniFilename = nullptr;
219 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
220 io.ConfigWindowsResizeFromEdges = true;
221
222 auto window = reinterpret_cast<GLFWwindow*>(impl_->GetWindowHandle());
223 if (!window) {
224 return false;
225 }
226 ::glfwSetWindowTitle(window, GetWindowTitle().c_str());
227 ::glfwSetWindowUserPointer(window, this);
228 ::glfwSetWindowSizeCallback(
229 window, [](GLFWwindow* window, int width, int height) -> void {
230 auto playground =
231 reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window));
232 if (!playground) {
233 return;
234 }
235 playground->SetWindowSize(ISize{width, height}.Max({}));
236 });
237 ::glfwSetKeyCallback(window, &PlaygroundKeyCallback);
238 ::glfwSetCursorPosCallback(window, [](GLFWwindow* window, double x,
239 double y) {
240 reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window))
241 ->SetCursorPosition({static_cast<Scalar>(x), static_cast<Scalar>(y)});
242 });
243
244 ImGui_ImplGlfw_InitForOther(window, true);
245 fml::ScopedCleanupClosure shutdown_imgui([]() { ImGui_ImplGlfw_Shutdown(); });
246
247 ImGui_ImplImpeller_Init(context_);
248 fml::ScopedCleanupClosure shutdown_imgui_impeller(
249 []() { ImGui_ImplImpeller_Shutdown(); });
250
251 ImGui::SetNextWindowPos({10, 10});
252
253 ::glfwSetWindowSize(window, GetWindowSize().width, GetWindowSize().height);
254 ::glfwSetWindowPos(window, 200, 100);
255 ::glfwShowWindow(window);
256
257 while (true) {
258 #if FML_OS_MACOSX
259 fml::ScopedNSAutoreleasePool pool;
260 #endif
261 ::glfwPollEvents();
262
263 if (::glfwWindowShouldClose(window)) {
264 return true;
265 }
266
267 ImGui_ImplGlfw_NewFrame();
268
269 auto surface = impl_->AcquireSurfaceFrame(context_);
270 RenderTarget render_target = surface->GetRenderTarget();
271
272 ImGui::NewFrame();
273 ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(),
274 ImGuiDockNodeFlags_PassthruCentralNode);
275 bool result = render_callback(render_target);
276 ImGui::Render();
277
278 // Render ImGui overlay.
279 {
280 auto buffer = context_->CreateCommandBuffer();
281 if (!buffer) {
282 VALIDATION_LOG << "Could not create command buffer.";
283 return false;
284 }
285 buffer->SetLabel("ImGui Command Buffer");
286
287 auto color0 = render_target.GetColorAttachment(0);
288 color0.load_action = LoadAction::kLoad;
289 if (color0.resolve_texture) {
290 color0.texture = color0.resolve_texture;
291 color0.resolve_texture = nullptr;
292 color0.store_action = StoreAction::kStore;
293 }
294 render_target.SetColorAttachment(color0, 0);
295 render_target.SetStencilAttachment(std::nullopt);
296 render_target.SetDepthAttachment(std::nullopt);
297
298 auto pass = buffer->CreateRenderPass(render_target);
299 if (!pass) {
300 VALIDATION_LOG << "Could not create render pass.";
301 return false;
302 }
303 pass->SetLabel("ImGui Render Pass");
304 if (!host_buffer_) {
305 host_buffer_ = HostBuffer::Create(context_->GetResourceAllocator(),
306 context_->GetIdleWaiter());
307 }
308
309 ImGui_ImplImpeller_RenderDrawData(ImGui::GetDrawData(), *pass,
310 *host_buffer_);
311
312 pass->EncodeCommands();
313
314 if (!context_->GetCommandQueue()->Submit({buffer}).ok()) {
315 return false;
316 }
317 }
318
319 if (!result || !surface->Present()) {
320 return false;
321 }
322
323 if (!ShouldKeepRendering()) {
324 break;
325 }
326 }
327
328 ::glfwHideWindow(window);
329
330 return true;
331 }
impeller::HostBuffer::Create
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter)
Definition: host_buffer.cc:21
impeller::Playground::Playground
Playground(PlaygroundSwitches switches)
Definition: playground.cc:84
impeller::Playground::ShouldKeepRendering
virtual bool ShouldKeepRendering() const
Definition: playground.cc:506
impeller::Playground::GetWindowSize
ISize GetWindowSize() const
Definition: playground.cc:185
impeller::Playground::GetWindowTitle
virtual std::string GetWindowTitle() const =0
x
int32_t x
Definition: dl_golden_unittests.cc:458
ImGui_ImplImpeller_RenderDrawData
void ImGui_ImplImpeller_RenderDrawData(ImDrawData *draw_data, impeller::RenderPass &render_pass, impeller::HostBuffer &host_buffer)
Definition: imgui_impl_impeller.cc:139
ImGui_ImplImpeller_Init
bool ImGui_ImplImpeller_Init(const std::shared_ptr< impeller::Context > &context)
Definition: imgui_impl_impeller.cc:57
ImGui_ImplImpeller_Shutdown
void ImGui_ImplImpeller_Shutdown()
Definition: imgui_impl_impeller.cc:132
impeller::android::testing::CreateContext
std::shared_ptr< Context > CreateContext()
Definition: ahb_texture_source_vk_unittests.cc:19
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::PlaygroundKeyCallback
static void PlaygroundKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: playground.cc:168
impeller::LoadAction::kLoad
@ kLoad
impeller::StoreAction::kStore
@ kStore
impeller::ISize
ISize64 ISize
Definition: size.h:162
impeller::TSize::Max
constexpr TSize Max(const TSize &o) const
Definition: size.h:97

References impeller::HostBuffer::Create(), impeller::android::testing::CreateContext(), impeller::PlaygroundSwitches::enable_playground, impeller::RenderTarget::GetColorAttachment(), 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(), switches_, 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 333 of file playground.cc.

333 {
334 return OpenPlaygroundHere(
335 [context = GetContext(), &pass_callback](RenderTarget& render_target) {
336 auto buffer = context->CreateCommandBuffer();
337 if (!buffer) {
338 return false;
339 }
340 buffer->SetLabel("Playground Command Buffer");
341
342 auto pass = buffer->CreateRenderPass(render_target);
343 if (!pass) {
344 return false;
345 }
346 pass->SetLabel("Playground Render Pass");
347
348 if (!pass_callback(*pass)) {
349 return false;
350 }
351
352 pass->EncodeCommands();
353 if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
354 return false;
355 }
356 return true;
357 });
358 }
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:201
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91

References GetContext(), and OpenPlaygroundHere().

## ◆ SetCapabilities()

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

Definition at line 510 of file playground.cc.

511 {
512 return impl_->SetCapabilities(capabilities);
513 }

## ◆ SetupContext()

void impeller::Playground::SetupContext | ( | PlaygroundBackend | backend,
|  | const PlaygroundSwitches & | switches
| ) |  |

Definition at line 125 of file playground.cc.

126 {
127 FML_CHECK(SupportsBackend(backend));
128
129 impl_ = PlaygroundImpl::Create(backend, switches);
130 if (!impl_) {
131 FML_LOG(WARNING) << "PlaygroundImpl::Create failed.";
132 return;
133 }
134
135 context_ = impl_->GetContext();
136 }
impeller::Playground::SupportsBackend
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:101
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:25

References impeller::PlaygroundImpl::Create(), and SupportsBackend().

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

## ◆ SetupWindow()

void impeller::Playground::SetupWindow | ( |  | ) |

Definition at line 138 of file playground.cc.

138 {
139 if (!context_) {
140 FML_LOG(WARNING) << "Asked to set up a window with no context (call "
141 "SetupContext first).";
142 return;
143 }
144 start_time_ = fml::TimePoint::Now().ToEpochDelta();
145 }

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

## ◆ SetWindowSize()

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

Definition at line 502 of file playground.cc.

502 {
503 window_size_ = size;
504 }

Referenced by OpenPlaygroundHere().

## ◆ ShouldKeepRendering()

bool impeller::Playground::ShouldKeepRendering | ( |  | ) | const
| protected virtual

Definition at line 506 of file playground.cc.

506 {
507 return true;
508 }

Referenced by OpenPlaygroundHere().

## ◆ ShouldOpenNewPlaygrounds()

bool impeller::Playground::ShouldOpenNewPlaygrounds | ( |  | ) |
| static

Definition at line 164 of file playground.cc.

164 {
165 return gShouldOpenNewPlaygrounds;
166 }
impeller::gShouldOpenNewPlaygrounds
static std::atomic_bool gShouldOpenNewPlaygrounds
Definition: playground.cc:162

References impeller::gShouldOpenNewPlaygrounds.

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

## ◆ SupportsBackend()

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

Definition at line 101 of file playground.cc.

101 {
102 switch (backend) {
103 case PlaygroundBackend::kMetal:
104 #if IMPELLER_ENABLE_METAL
105 return true;
106 #else // IMPELLER_ENABLE_METAL
107 return false;
108 #endif // IMPELLER_ENABLE_METAL
109 case PlaygroundBackend::kOpenGLES:
110 #if IMPELLER_ENABLE_OPENGLES
111 return true;
112 #else // IMPELLER_ENABLE_OPENGLES
113 return false;
114 #endif // IMPELLER_ENABLE_OPENGLES
115 case PlaygroundBackend::kVulkan:
116 #if IMPELLER_ENABLE_VULKAN
117 return PlaygroundImplVK::IsVulkanDriverPresent();
118 #else // IMPELLER_ENABLE_VULKAN
119 return false;
120 #endif // IMPELLER_ENABLE_VULKAN
121 }
122 FML_UNREACHABLE();
123 }
impeller::PlaygroundImplVK::IsVulkanDriverPresent
static bool IsVulkanDriverPresent()
Definition: playground_impl_vk.cc:224
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PlaygroundBackend::kVulkan
@ kVulkan

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

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

## ◆ TeardownWindow()

void impeller::Playground::TeardownWindow | ( |  | ) |

Definition at line 151 of file playground.cc.

151 {
152 if (host_buffer_) {
153 host_buffer_.reset();
154 }
155 if (context_) {
156 context_->Shutdown();
157 }
158 context_.reset();
159 impl_.reset();
160 }

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 515 of file playground.cc.

515 {
516 return switches_.enable_playground;
517 }

References impeller::PlaygroundSwitches::enable_playground, and switches_.

## Member Data Documentation

## ◆ switches_

const PlaygroundSwitches impeller::Playground::switches_
| protected

Definition at line 126 of file playground.h.

Referenced by impeller::interop::testing::PlaygroundTest::CreateContext(), impeller::PlaygroundTest::GetWindowTitle(), IsPlaygroundEnabled(), OpenPlaygroundHere(), impeller::DlPlayground::OpenPlaygroundHere(), impeller::EntityPlayground::OpenPlaygroundHere(), Playground(), impeller::ComputePlaygroundTest::SetUp(), impeller::PlaygroundTest::SetUp(), and WillRenderSomething().

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

- impeller/playground/playground.h
- impeller/playground/playground.cc