Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::Playground Class Referenceabstract

#include <playground.h>

Inheritance diagram for impeller::Playground:
impeller::ComputePlaygroundTest impeller::PlaygroundTest impeller::AiksPlayground impeller::DlPlayground impeller::EntityPlayground impeller::PlaygroundTestWithGoldens impeller::RuntimeStagePlayground impeller::interop::testing::PlaygroundTest impeller::testing::RendererDartTest impeller::AiksPlaygroundWithGoldens impeller::DlPlaygroundWithGoldens 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.
 
std::shared_ptr< ContextGetContext () const
 
std::shared_ptr< ContextMakeContext () const
 
ContentContextGetContentContext () const
 
std::shared_ptr< TypographerContextGetTypographerContext () const
 
bool ShouldWriteGoldenImage ()
 Whether this instance will write a golden image of the output from |OpenPlaygroundHere|.
 
void SetEnableWriteGolden (bool write_golden)
 Sets a particular test to either write a golden or not, false by default.
 
bool OpenPlaygroundHere (const RenderCallback &render_callback)
 
bool OpenPlaygroundHere (const SinglePassCallback &pass_callback)
 
std::shared_ptr< TextureCreateTextureForFixture (const char *fixture_name, bool enable_mipmapping=false) const
 
std::shared_ptr< TextureCreateTextureCubeForFixture (std::array< const char *, 6 > fixture_names) const
 
virtual std::unique_ptr< fml::MappingOpenAssetAsMapping (std::string asset_name) const =0
 
virtual std::string GetWindowTitle () const =0
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities)
 
GLProcAddressResolver CreateGLProcAddressResolver () const
 
VKProcAddressResolver CreateVKProcAddressResolver () const
 
void SetGPUDisabled (bool disabled) const
 Mark the GPU as unavilable.
 
RuntimeStageBackend GetRuntimeStageBackend () const
 
bool InitializePipelineDescriptorForRendering (PipelineDescriptor &desc) const
 Initializes the provided |PipelineDescriptor| with appropriate default values to match the conditions under which a pipeline will be rendered.
 

Static Public Member Functions

static void OnTearDownTestEnvironment ()
 
static bool ShouldOpenNewPlaygrounds ()
 
static std::shared_ptr< CompressedImageLoadFixtureImageCompressed (std::shared_ptr< fml::Mapping > mapping)
 
static std::optional< DecompressedImageDecodeImageRGBA (const std::shared_ptr< CompressedImage > &compressed)
 
static std::shared_ptr< TextureCreateTextureForMapping (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.
 
bool PlatformSupportsWideGamutTests () const
 Returns true if the platform can support wide gamuts.
 
bool RenderingSupportsMSAA () const
 Returns true if the rendering path supports MSAA rendering.
 
SampleCount GetDefaultSampleCount () const
 Returns the default sample count of the rendering path.
 
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.
 
const PlaygroundSwitchesGetSwitches () 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.
 
void SetTypographerContext (std::shared_ptr< TypographerContext > typographer_context)
 
void SetWindowSize (ISize size)
 
virtual testing::GoldenDigestManagerGetGoldenDigestManager () const
 

Detailed Description

Definition at line 42 of file playground.h.

Member Typedef Documentation

◆ GLProcAddressResolver

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

Definition at line 119 of file playground.h.

◆ RenderCallback

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

Definition at line 77 of file playground.h.

◆ SinglePassCallback

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

Definition at line 44 of file playground.h.

◆ VKProcAddressResolver

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

Definition at line 122 of file playground.h.

Constructor & Destructor Documentation

◆ Playground()

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

Definition at line 125 of file playground.cc.

127 : backend_(backend), switches_(switches) {
128 InitializeGLFWOnce();
130}
void SetupSwiftshaderOnce(bool use_swiftshader)
Find and setup the installable client driver for a locally built SwiftShader at known paths....

References flutter::testing::SetupSwiftshaderOnce(), and impeller::PlaygroundSwitches::use_swiftshader.

◆ ~Playground()

impeller::Playground::~Playground ( )
virtualdefault

Member Function Documentation

◆ CreateGLProcAddressResolver()

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

Definition at line 775 of file playground.cc.

776 {
777 return GetImpl()->CreateGLProcAddressResolver();
778}

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

717 {
718 std::array<DecompressedImage, 6> images;
719 for (size_t i = 0; i < fixture_names.size(); i++) {
720 auto image = DecodeImageRGBA(
722 if (!image.has_value()) {
723 return nullptr;
724 }
725 images[i] = image.value();
726 }
727
728 TextureDescriptor texture_descriptor;
729 texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
730 texture_descriptor.type = TextureType::kTextureCube;
731 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
732 texture_descriptor.size = images[0].GetSize();
733 texture_descriptor.mip_count = 1u;
734
735 auto texture =
736 GetContext()->GetResourceAllocator()->CreateTexture(texture_descriptor);
737 if (!texture) {
738 VALIDATION_LOG << "Could not allocate texture cube.";
739 return nullptr;
740 }
741 texture->SetLabel("Texture cube");
742
743 auto cmd_buffer = GetContext()->CreateCommandBuffer();
744 auto blit_pass = cmd_buffer->CreateBlitPass();
745 for (size_t i = 0; i < fixture_names.size(); i++) {
746 auto device_buffer =
747 GetContext()->GetResourceAllocator()->CreateBufferWithCopy(
748 *images[i].GetAllocation());
749 blit_pass->AddCopy(DeviceBuffer::AsBufferView(device_buffer), texture, {},
750 "", /*mip_level=*/0, /*slice=*/i);
751 }
752
753 if (!blit_pass->EncodeCommands() ||
754 !GetContext()->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok()) {
755 VALIDATION_LOG << "Could not upload texture to device memory.";
756 return nullptr;
757 }
758
759 return texture;
760}
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)
std::shared_ptr< Context > GetContext() const
virtual std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const =0
static std::optional< DecompressedImage > DecodeImageRGBA(const std::shared_ptr< CompressedImage > &compressed)
FlutterVulkanImage * image
FlTexture * texture
std::array< MockImage, 3 > images
uint32_t format
The VkFormat of the image (for example: VK_FORMAT_R8G8B8A8_UNORM).
Definition embedder.h:940
#define VALIDATION_LOG
Definition validation.h:91

References impeller::DeviceBuffer::AsBufferView(), DecodeImageRGBA(), impeller::TextureDescriptor::format, GetContext(), i, image, images, impeller::kDevicePrivate, impeller::kR8G8B8A8UNormInt, impeller::kTextureCube, LoadFixtureImageCompressed(), impeller::TextureDescriptor::mip_count, OpenAssetAsMapping(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, texture, 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 704 of file playground.cc.

706 {
708 GetContext(), OpenAssetAsMapping(fixture_name), enable_mipmapping);
709 if (texture == nullptr) {
710 return nullptr;
711 }
712 texture->SetLabel(fixture_name);
713 return texture;
714}
static std::shared_ptr< Texture > CreateTextureForMapping(const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)

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

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

694 {
696 Playground::LoadFixtureImageCompressed(std::move(mapping)));
697 if (!image.has_value()) {
698 return nullptr;
699 }
701 enable_mipmapping);
702}
static std::shared_ptr< Texture > CreateTextureForDecompressedImage(const std::shared_ptr< Context > &context, DecompressedImage &decompressed_image, bool enable_mipmapping)
std::shared_ptr< ContextGLES > context

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

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

◆ CreateVKProcAddressResolver()

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

Definition at line 780 of file playground.cc.

781 {
782 return GetImpl()->CreateVKProcAddressResolver();
783}

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

◆ DecodeImageRGBA()

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

Definition at line 630 of file playground.cc.

631 {
632 if (compressed == nullptr) {
633 return std::nullopt;
634 }
635 // The decoded image is immediately converted into RGBA as that format is
636 // known to be supported everywhere. For image sources that don't need 32
637 // bit pixel strides, this is overkill. Since this is a test fixture we
638 // aren't necessarily trying to eke out memory savings here and instead
639 // favor simplicity.
640 auto image = compressed->Decode().ConvertToRGBA();
641 if (!image.IsValid()) {
642 VALIDATION_LOG << "Could not decode image.";
643 return std::nullopt;
644 }
645
646 return image;
647}

References image, and 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 134 of file playground.cc.

134 {
135 FML_CHECK(!context_) << "Must be called before a context is created.";
136 switches_.can_share_context = false;
137}
#define FML_CHECK(condition)
Definition logging.h:104

References impeller::PlaygroundSwitches::can_share_context, and FML_CHECK.

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

190 {
191 FML_CHECK(!context_) << "Must be called before a context is created.";
193 return false;
194 }
195 switches_.enable_wide_gamut = true;
196 return true;
197}
bool PlatformSupportsWideGamutTests() const
Returns true if the platform can support wide gamuts.

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

◆ GetContentContext()

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

Definition at line 219 of file playground.cc.

219 {
220 if (!content_context_) {
221 content_context_ =
222 std::make_unique<ContentContext>(GetContext(), GetTypographerContext());
223 FML_CHECK(content_context_) << "Failed to create ContentContext";
224 }
225 return *content_context_;
226}
std::shared_ptr< TypographerContext > GetTypographerContext() const

References FML_CHECK, GetContext(), and GetTypographerContext().

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

◆ GetContentScale()

Point impeller::Playground::GetContentScale ( ) const

◆ GetContext()

◆ GetCursorPosition()

Point impeller::Playground::GetCursorPosition ( ) const

Definition at line 336 of file playground.cc.

336 {
337 return cursor_position_;
338}

◆ GetDefaultSampleCount()

SampleCount impeller::Playground::GetDefaultSampleCount ( ) const
protected

Returns the default sample count of the rendering path.

Definition at line 175 of file playground.cc.

175 {
177}
bool RenderingSupportsMSAA() const
Returns true if the rendering path supports MSAA rendering.

References impeller::kCount1, impeller::kCount4, and RenderingSupportsMSAA().

Referenced by InitializePipelineDescriptorForRendering().

◆ GetGoldenDigestManager()

testing::GoldenDigestManager * impeller::Playground::GetGoldenDigestManager ( ) const
protectedvirtual

Reimplemented in impeller::PlaygroundTest.

Definition at line 121 of file playground.cc.

121 {
122 return nullptr;
123}

Referenced by OpenPlaygroundHere().

◆ GetRuntimeStageBackend()

RuntimeStageBackend impeller::Playground::GetRuntimeStageBackend ( ) const

Definition at line 789 of file playground.cc.

789 {
790 return GetImpl()->GetRuntimeStageBackend();
791}

◆ GetSecondsElapsed()

Scalar impeller::Playground::GetSecondsElapsed ( ) const

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

Definition at line 352 of file playground.cc.

352 {
353 return (fml::TimePoint::Now().ToEpochDelta() - start_time_).ToSecondsF();
354}
static TimePoint Now()
Definition time_point.cc:49

References fml::TimePoint::Now().

◆ 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 183 of file playground.h.

183{ 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 228 of file playground.cc.

228 {
229 if (!typographer_context_) {
230 typographer_context_ = TypographerContextSkia::Make();
231 }
232 return typographer_context_;
233}
static std::shared_ptr< TypographerContext > Make()

References impeller::TypographerContextSkia::Make().

Referenced by GetContentContext(), and impeller::DlPlayground::MakeScreenshot().

◆ GetWindowBounds()

IRect impeller::Playground::GetWindowBounds ( ) const

Definition at line 344 of file playground.cc.

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

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

◆ GetWindowSize()

◆ GetWindowTitle()

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

◆ InitializePipelineDescriptorForRendering()

bool impeller::Playground::InitializePipelineDescriptorForRendering ( PipelineDescriptor desc) const

Initializes the provided |PipelineDescriptor| with appropriate default values to match the conditions under which a pipeline will be rendered.

Definition at line 179 of file playground.cc.

180 {
181 // Match the golden/verirication harness render target:
182 // - msaa or single samples depending on the Context
183 // - no depth or stencil
184 desc.SetSampleCount(GetDefaultSampleCount());
185 desc.ClearStencilAttachments();
186 desc.ClearDepthAttachment();
187 return true;
188}
SampleCount GetDefaultSampleCount() const
Returns the default sample count of the rendering path.

References impeller::PipelineDescriptor::ClearDepthAttachment(), impeller::PipelineDescriptor::ClearStencilAttachments(), GetDefaultSampleCount(), and impeller::PipelineDescriptor::SetSampleCount().

Referenced by impeller::testing::CreateDefaultPipeline(), impeller::testing::DrawCompressedTextureGolden(), and impeller::testing::DrawManuallyMippedTextureGolden().

◆ IsPlaygroundEnabled()

◆ LoadFixtureImageCompressed()

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

Definition at line 619 of file playground.cc.

620 {
621 auto compressed_image = CompressedImageSkia::Create(std::move(mapping));
622 if (!compressed_image) {
623 VALIDATION_LOG << "Could not create compressed image.";
624 return nullptr;
625 }
626
627 return compressed_image;
628}
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 206 of file playground.cc.

206 {
207 // This method is used to get a unique context that is not shared with
208 // other playground tests. It requires that the test has called the
209 // |EnsureContextIsUnique| method before it calls this method. We
210 // verify those conditions here and then set up the context.
211 FML_CHECK(!context_) << "MakeContext can only be called once";
212 FML_CHECK(!switches_.can_share_context)
213 << "MakeContext should only be called after EnsureContextIsUnique()";
214 SetupContext();
215
216 return context_;
217}

References impeller::PlaygroundSwitches::can_share_context, and FML_CHECK.

◆ OnTearDownTestEnvironment()

void impeller::Playground::OnTearDownTestEnvironment ( )
static

Definition at line 115 of file playground.cc.

115 {
116 if (glfw_initialized_) {
117 ::glfwTerminate();
118 }
119}

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

446 {
447 std::shared_ptr<Context> context = GetContext();
449
450 if (!render_callback) {
451 return true;
452 }
453
454 auto window = reinterpret_cast<GLFWwindow*>(impl_->GetWindowHandle());
455 if (!window) {
456 return false;
457 }
458 ::glfwSetWindowSize(window, GetWindowSize().width, GetWindowSize().height);
459
460 bool writing_golden = GetGoldenDigestManager() && should_write_golden_;
461 if (!switches_.enable_playground || writing_golden) {
462 bool success = RenderImage(render_callback, false);
463 if (success && writing_golden) {
464 // Render twice for a golden result so the second pass observes warmed
465 // pipeline and resource caches.
466 success = RenderImage(render_callback, true);
467 }
468 if (!success || !switches_.enable_playground) {
469 return success;
470 }
471 }
472 FML_CHECK(switches_.enable_playground);
473
474 IMGUI_CHECKVERSION();
475 ImGui::CreateContext();
476 fml::ScopedCleanupClosure destroy_imgui_context(
477 []() { ImGui::DestroyContext(); });
478 ImGui::StyleColorsDark();
479
480 auto& io = ImGui::GetIO();
481 io.IniFilename = nullptr;
482 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
483 io.ConfigWindowsResizeFromEdges = true;
484
485 ::glfwSetWindowTitle(window, GetWindowTitle().c_str());
486 ::glfwSetWindowUserPointer(window, this);
487 ::glfwSetWindowSizeCallback(
488 window, [](GLFWwindow* window, int width, int height) -> void {
489 auto playground =
490 reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window));
491 if (!playground) {
492 return;
493 }
494 playground->SetWindowSize(ISize{width, height}.Max({}));
495 });
496 ::glfwSetKeyCallback(window, &PlaygroundKeyCallback);
497 ::glfwSetCursorPosCallback(window, [](GLFWwindow* window, double x,
498 double y) {
499 reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window))
500 ->SetCursorPosition({static_cast<Scalar>(x), static_cast<Scalar>(y)});
501 });
502
503 ImGui_ImplGlfw_InitForOther(window, true);
504 fml::ScopedCleanupClosure shutdown_imgui([]() { ImGui_ImplGlfw_Shutdown(); });
505
507 fml::ScopedCleanupClosure shutdown_imgui_impeller(
508 []() { ImGui_ImplImpeller_Shutdown(); });
509
510 ImGui::SetNextWindowPos({10, 10});
511
512 ::glfwSetWindowPos(window, 200, 100);
513 ::glfwShowWindow(window);
514
515 while (true) {
516#if FML_OS_MACOSX
518#endif
519 ::glfwPollEvents();
520
521 if (::glfwWindowShouldClose(window)) {
522 return true;
523 }
524
525 ImGui_ImplGlfw_NewFrame();
526
527 auto surface = GetImpl()->AcquireSurfaceFrame(context);
528 RenderTarget render_target = surface->GetRenderTarget();
529
530 ImGui::NewFrame();
531 ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(),
532 ImGuiDockNodeFlags_PassthruCentralNode);
533 bool result = render_callback(render_target);
534 ImGui::Render();
535
536 // Render ImGui overlay.
537 {
538 auto buffer = context->CreateCommandBuffer();
539 if (!buffer) {
540 VALIDATION_LOG << "Could not create command buffer.";
541 return false;
542 }
543 buffer->SetLabel("ImGui Command Buffer");
544
545 auto color0 = render_target.GetColorAttachment(0);
546 color0.load_action = LoadAction::kLoad;
547 if (color0.resolve_texture) {
548 color0.texture = color0.resolve_texture;
549 color0.resolve_texture = nullptr;
550 color0.store_action = StoreAction::kStore;
551 }
552 render_target.SetColorAttachment(color0, 0);
553 render_target.SetStencilAttachment(std::nullopt);
554 render_target.SetDepthAttachment(std::nullopt);
555
556 auto pass = buffer->CreateRenderPass(render_target);
557 if (!pass) {
558 VALIDATION_LOG << "Could not create render pass.";
559 return false;
560 }
561 pass->SetLabel("ImGui Render Pass");
562 if (!host_buffer_) {
563 host_buffer_ = HostBuffer::Create(
564 context->GetResourceAllocator(), context->GetIdleWaiter(),
565 context->GetCapabilities()->GetMinimumUniformAlignment());
566 }
567
568 ImGui_ImplImpeller_RenderDrawData(ImGui::GetDrawData(), *pass,
569 *host_buffer_);
570
571 pass->EncodeCommands();
572
573 if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
574 return false;
575 }
576 }
577
578 if (!result || !surface->Present()) {
579 return false;
580 }
581
582 if (!ShouldKeepRendering()) {
583 break;
584 }
585 }
586
587 ::glfwHideWindow(window);
588
589 return true;
590}
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition closure.h:32
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, std::shared_ptr< const GpuSubmissionTracker > submission_tracker=nullptr)
virtual bool ShouldKeepRendering() const
ISize GetWindowSize() const
virtual std::string GetWindowTitle() const =0
virtual testing::GoldenDigestManager * GetGoldenDigestManager() const
Playground(PlaygroundBackend backend, const PlaygroundSwitches &switches)
int32_t x
GLFWwindow * window
Definition main.cc:60
VkSurfaceKHR surface
Definition main.cc:65
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()
double y
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98
float Scalar
Definition scalar.h:19
static void PlaygroundKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
ISize64 ISize
Definition size.h:162
int32_t height
int32_t width
constexpr TSize Max(const TSize &o) const
Definition size.h:97

References context, impeller::HostBuffer::Create(), impeller::PlaygroundSwitches::enable_playground, FML_CHECK, impeller::RenderTarget::GetColorAttachment(), GetContext(), GetGoldenDigestManager(), GetWindowSize(), GetWindowTitle(), height, 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(), surface, VALIDATION_LOG, width, window, x, and y.

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

◆ OpenPlaygroundHere() [2/2]

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

Definition at line 592 of file playground.cc.

592 {
593 return OpenPlaygroundHere(
594 [context = GetContext(), &pass_callback](RenderTarget& render_target) {
595 auto buffer = context->CreateCommandBuffer();
596 if (!buffer) {
597 return false;
598 }
599 buffer->SetLabel("Playground Command Buffer");
600
601 auto pass = buffer->CreateRenderPass(render_target);
602 if (!pass) {
603 return false;
604 }
605 pass->SetLabel("Playground Render Pass");
606
607 if (!pass_callback(*pass)) {
608 return false;
609 }
610
611 pass->EncodeCommands();
612 if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
613 return false;
614 }
615 return true;
616 });
617}
bool OpenPlaygroundHere(const RenderCallback &render_callback)

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

◆ PlatformSupportsWideGamutTests()

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

Returns true if the platform can support wide gamuts.

Definition at line 139 of file playground.cc.

139 {
140#if __arm64__ && FML_OS_MACOSX
141 switch (backend_) {
144 return true;
148 return false;
149 }
150#else
151 return false;
152#endif
153}

References impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, and impeller::kVulkan.

Referenced by EnsureContextSupportsWideGamut().

◆ RenderingSupportsMSAA()

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

Returns true if the rendering path supports MSAA rendering.

Definition at line 155 of file playground.cc.

155 {
156 // We could call GetContext(), but we don't want to cause it to be
157 // created just yet. So, we make some assumptions here. If they are
158 // insufficient then we should beef them up rather than just calling
159 // GetContext() if we can.
160 // Also, technically, we should check if it supports OffscreenMSAA
161 // which might be a subset of supporting MSAA on screen, but for now
162 // they seem to be closely related.
163 switch (backend_) {
166 return true;
169 return false;
171 return true;
172 }
173}

References impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kOpenGLESSDF, and impeller::kVulkan.

Referenced by GetDefaultSampleCount().

◆ SetCapabilities()

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

Definition at line 770 of file playground.cc.

771 {
772 return GetImpl()->SetCapabilities(capabilities);
773}

◆ SetEnableWriteGolden()

void impeller::Playground::SetEnableWriteGolden ( bool  write_golden)

Sets a particular test to either write a golden or not, false by default.

Definition at line 364 of file playground.cc.

364 {
365 should_write_golden_ = write_golden;
366}

Referenced by impeller::PlaygroundTest::SetUp().

◆ SetGPUDisabled()

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

Mark the GPU as unavilable.

Only supported on the Metal backend.

Definition at line 785 of file playground.cc.

785 {
786 GetImpl()->SetGPUDisabled(value);
787}

References value.

◆ SetTypographerContext()

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

Definition at line 235 of file playground.cc.

236 {
237 FML_CHECK(!typographer_context_)
238 << "SetTypographerContext called after it has already been initialized";
239 typographer_context_ = std::move(typographer_context);
240}

References FML_CHECK.

◆ SetWindowSize()

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

Definition at line 762 of file playground.cc.

762 {
763 window_size_ = size;
764}
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size

Referenced by OpenPlaygroundHere().

◆ ShouldKeepRendering()

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

Definition at line 766 of file playground.cc.

766 {
767 return true;
768}

Referenced by OpenPlaygroundHere().

◆ ShouldOpenNewPlaygrounds()

bool impeller::Playground::ShouldOpenNewPlaygrounds ( )
static

Definition at line 319 of file playground.cc.

319 {
321}
static std::atomic_bool gShouldOpenNewPlaygrounds

References impeller::gShouldOpenNewPlaygrounds.

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

◆ ShouldWriteGoldenImage()

bool impeller::Playground::ShouldWriteGoldenImage ( )

Whether this instance will write a golden image of the output from |OpenPlaygroundHere|.

Definition at line 360 of file playground.cc.

360 {
361 return should_write_golden_;
362}

◆ SupportsBackend()

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

Definition at line 242 of file playground.cc.

242 {
243 switch (backend) {
246#if IMPELLER_ENABLE_METAL
247 return true;
248#else // IMPELLER_ENABLE_METAL
249 return false;
250#endif // IMPELLER_ENABLE_METAL
253#if IMPELLER_ENABLE_OPENGLES
254 return true;
255#else // IMPELLER_ENABLE_OPENGLES
256 return false;
257#endif // IMPELLER_ENABLE_OPENGLES
259#if IMPELLER_ENABLE_VULKAN
261#else // IMPELLER_ENABLE_VULKAN
262 return false;
263#endif // IMPELLER_ENABLE_VULKAN
264 }
266}
#define FML_UNREACHABLE()
Definition logging.h:128

References FML_UNREACHABLE, 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 301 of file playground.cc.

301 {
302 if (content_context_) {
303 FML_CHECK(context_);
304 [[maybe_unused]] auto result = context_->FlushCommandBuffers();
305 content_context_.reset();
306 }
307 if (host_buffer_) {
308 host_buffer_.reset();
309 }
310 if (context_) {
311 context_->Shutdown();
312 }
313 context_.reset();
314 impl_.reset();
315}

References FML_CHECK.

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


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