Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::interop::testing::PlaygroundTest Class Reference

#include <playground_test.h>

Inheritance diagram for impeller::interop::testing::PlaygroundTest:
impeller::PlaygroundTest impeller::Playground

Public Types

using InteropPlaygroundCallback = std::function< bool(const ScopedObject< Context > &context, const ScopedObject< Surface > &surface)>
 
- Public Types inherited from impeller::Playground
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

 PlaygroundTest ()
 
 ~PlaygroundTest () override
 
 PlaygroundTest (const PlaygroundTest &)=delete
 
PlaygroundTestoperator= (const PlaygroundTest &)=delete
 
void SetUp () override
 
void TearDown () override
 
ScopedObject< ContextCreateContext () const
 
ScopedObject< ContextGetInteropContext ()
 
hpp::Context GetHPPContext ()
 
hpp::Texture OpenAssetAsHPPTexture (std::string asset_name)
 
bool OpenPlaygroundHere (InteropPlaygroundCallback callback)
 
std::unique_ptr< hpp::Mapping > OpenAssetAsHPPMapping (std::string asset_name) const
 
- Public Member Functions inherited from impeller::PlaygroundTest
 PlaygroundTest ()
 
void SetUp () override
 
void TearDown () override
 
PlaygroundBackend GetBackend () const
 
std::unique_ptr< fml::MappingOpenAssetAsMapping (std::string asset_name) const override
 
absl::StatusOr< RuntimeStage::MapOpenAssetAsRuntimeStage (const char *asset_name) const
 
std::string GetWindowTitle () const override
 
- Public Member Functions inherited from impeller::Playground
 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
 
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
 
bool OpenPlaygroundHere (const RenderCallback &render_callback)
 
bool OpenPlaygroundHere (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
 
fml::Status SetCapabilities (const std::shared_ptr< Capabilities > &capabilities)
 
bool WillRenderSomething () const
 Returns true if OpenPlaygroundHere will actually render anything.
 
GLProcAddressResolver CreateGLProcAddressResolver () const
 
VKProcAddressResolver CreateVKProcAddressResolver () const
 
void SetGPUDisabled (bool disabled) const
 Mark the GPU as unavilable.
 
RuntimeStageBackend GetRuntimeStageBackend () const
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::Playground
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 inherited from impeller::Playground
void SetWindowSize (ISize size)
 
- Protected Attributes inherited from impeller::Playground
const PlaygroundSwitches switches_
 

Detailed Description

Definition at line 17 of file playground_test.h.

Member Typedef Documentation

◆ InteropPlaygroundCallback

Definition at line 42 of file playground_test.h.

Constructor & Destructor Documentation

◆ PlaygroundTest() [1/2]

impeller::interop::testing::PlaygroundTest::PlaygroundTest ( )

◆ ~PlaygroundTest()

impeller::interop::testing::PlaygroundTest::~PlaygroundTest ( )
overridevirtualdefault

Reimplemented from impeller::PlaygroundTest.

◆ PlaygroundTest() [2/2]

impeller::interop::testing::PlaygroundTest::PlaygroundTest ( const PlaygroundTest )
delete

Member Function Documentation

◆ CreateContext()

ScopedObject< Context > impeller::interop::testing::PlaygroundTest::CreateContext ( ) const

Definition at line 59 of file playground_test.cc.

59 {
60 switch (GetBackend()) {
63 return Adopt<Context>(
66 Playground::GLProcAddressResolver playground_gl_proc_address_callback =
68 ImpellerProcAddressCallback gl_proc_address_callback =
69 [](const char* proc_name, void* user_data) -> void* {
70 return (*reinterpret_cast<Playground::GLProcAddressResolver*>(
71 user_data))(proc_name);
72 };
73 return Adopt<Context>(ImpellerContextCreateOpenGLESNew(
74 ImpellerGetVersion(), gl_proc_address_callback,
75 &playground_gl_proc_address_callback));
76 }
79 struct UserData {
80 Playground::VKProcAddressResolver resolver;
81 } user_data;
83 settings.user_data = &user_data;
85 settings.proc_address_callback = [](void* instance, //
86 const char* proc_name, //
87 void* user_data //
88 ) -> void* {
89 auto resolver = reinterpret_cast<UserData*>(user_data)->resolver;
90 if (resolver) {
91 return resolver(instance, proc_name);
92 } else {
93 return nullptr;
94 }
95 };
96 return Adopt<Context>(
98 }
100}
GLProcAddressResolver CreateGLProcAddressResolver() const
const PlaygroundSwitches switches_
Definition playground.h:122
std::function< void *(const char *proc_name)> GLProcAddressResolver
Definition playground.h:107
VKProcAddressResolver CreateVKProcAddressResolver() const
PlaygroundBackend GetBackend() const
VkInstance instance
Definition main.cc:64
#define FML_UNREACHABLE()
Definition logging.h:128
void *IMPELLER_NULLABLE(* ImpellerProcAddressCallback)(const char *IMPELLER_NONNULL proc_name, void *IMPELLER_NULLABLE user_data)
Definition impeller.h:347
IMPELLER_EXTERN_C uint32_t ImpellerGetVersion()
Definition impeller.cc:92
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateVulkanNew(uint32_t version, const ImpellerContextVulkanSettings *settings)
Definition impeller.cc:152
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateMetalNew(uint32_t version)
Definition impeller.cc:134
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateOpenGLESNew(uint32_t version, ImpellerProcAddressCallback gl_proc_address_callback, void *gl_proc_address_callback_user_data)
Definition impeller.cc:108
ImpellerVulkanProcAddressCallback IMPELLER_NONNULL proc_address_callback
Definition impeller.h:634
void *IMPELLER_NULLABLE user_data
Definition impeller.h:633

References impeller::Playground::CreateGLProcAddressResolver(), impeller::Playground::CreateVKProcAddressResolver(), impeller::PlaygroundSwitches::enable_vulkan_validation, ImpellerContextVulkanSettings::enable_vulkan_validation, FML_UNREACHABLE, impeller::PlaygroundTest::GetBackend(), impeller::interop::ImpellerContextCreateMetalNew(), impeller::interop::ImpellerContextCreateOpenGLESNew(), impeller::interop::ImpellerContextCreateVulkanNew(), impeller::interop::ImpellerGetVersion(), instance, impeller::kMetal, impeller::kMetalSDF, impeller::kOpenGLES, impeller::kVulkan, ImpellerContextVulkanSettings::proc_address_callback, impeller::Playground::switches_, ImpellerContextVulkanSettings::user_data, and user_data.

◆ GetHPPContext()

hpp::Context impeller::interop::testing::PlaygroundTest::GetHPPContext ( )

Definition at line 184 of file playground_test.cc.

184 {
185 auto c_context = GetInteropContext().GetC();
186 ImpellerContextRetain(c_context);
187 return hpp::Context{c_context, hpp::AdoptTag::kAdopt};
188}
IMPELLER_EXTERN_C void ImpellerContextRetain(ImpellerContext context)
Definition impeller.cc:171

References GetInteropContext(), and impeller::interop::ImpellerContextRetain().

Referenced by OpenAssetAsHPPTexture().

◆ GetInteropContext()

ScopedObject< Context > impeller::interop::testing::PlaygroundTest::GetInteropContext ( )

Definition at line 171 of file playground_test.cc.

171 {
172 if (interop_context_) {
173 return interop_context_;
174 }
175
176 auto context = CreateSharedContext(GetBackend(), GetContext());
177 if (!context) {
178 return nullptr;
179 }
180 interop_context_ = std::move(context);
181 return interop_context_;
182}
std::shared_ptr< Context > GetContext() const
Definition playground.cc:94
static ScopedObject< Context > CreateSharedContext(PlaygroundBackend backend, std::shared_ptr< impeller::Context > shared_context)

References impeller::interop::testing::CreateSharedContext(), impeller::PlaygroundTest::GetBackend(), and impeller::Playground::GetContext().

Referenced by GetHPPContext(), and OpenPlaygroundHere().

◆ OpenAssetAsHPPMapping()

std::unique_ptr< hpp::Mapping > impeller::interop::testing::PlaygroundTest::OpenAssetAsHPPMapping ( std::string  asset_name) const

Definition at line 190 of file playground_test.cc.

191 {
192 std::shared_ptr<fml::Mapping> data =
193 OpenAssetAsMapping(std::move(asset_name));
194 if (!data) {
195 return nullptr;
196 }
197 return std::make_unique<hpp::Mapping>(data->GetMapping(), //
198 data->GetSize(), //
199 [data]() {} //
200 );
201}
std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const override
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36

References impeller::PlaygroundTest::OpenAssetAsMapping().

◆ OpenAssetAsHPPTexture()

hpp::Texture impeller::interop::testing::PlaygroundTest::OpenAssetAsHPPTexture ( std::string  asset_name)

Definition at line 203 of file playground_test.cc.

203 {
204 auto compressed_data = OpenAssetAsMapping(std::move(asset_name));
205 if (!compressed_data) {
206 return {nullptr, hpp::AdoptTag::kAdopt};
207 }
208 auto compressed_image =
209 LoadFixtureImageCompressed(std::move(compressed_data));
210 if (!compressed_image) {
211 return {nullptr, hpp::AdoptTag::kAdopt};
212 }
213 auto decompressed_image = DecodeImageRGBA(compressed_image);
214 if (!decompressed_image.has_value()) {
215 return {nullptr, hpp::AdoptTag::kAdopt};
216 }
217 auto rgba_decompressed_image =
218 std::make_shared<DecompressedImage>(decompressed_image->ConvertToRGBA());
219 if (!rgba_decompressed_image || !rgba_decompressed_image->IsValid()) {
220 return {nullptr, hpp::AdoptTag::kAdopt};
221 }
222 auto context = GetHPPContext();
223 if (!context) {
224 return {nullptr, hpp::AdoptTag::kAdopt};
225 }
226
227 auto rgba_mapping = std::make_unique<hpp::Mapping>(
228 rgba_decompressed_image->GetAllocation()->GetMapping(),
229 rgba_decompressed_image->GetAllocation()->GetSize(),
230 [rgba_decompressed_image]() {});
231
232 return hpp::Texture::WithContents(
233 context,
236 .size = {rgba_decompressed_image->GetSize().width,
237 rgba_decompressed_image->GetSize().height},
238 .mip_count = 1u,
239 },
240 std::move(rgba_mapping));
241}
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed(std::shared_ptr< fml::Mapping > mapping)
static std::optional< DecompressedImage > DecodeImageRGBA(const std::shared_ptr< CompressedImage > &compressed)
@ kImpellerPixelFormatRGBA8888
Definition impeller.h:425
int32_t width
ImpellerPixelFormat pixel_format
Definition impeller.h:621

References impeller::Playground::DecodeImageRGBA(), GetHPPContext(), kImpellerPixelFormatRGBA8888, impeller::Playground::LoadFixtureImageCompressed(), impeller::PlaygroundTest::OpenAssetAsMapping(), ImpellerTextureDescriptor::pixel_format, and width.

◆ OpenPlaygroundHere()

bool impeller::interop::testing::PlaygroundTest::OpenPlaygroundHere ( InteropPlaygroundCallback  callback)

Definition at line 129 of file playground_test.cc.

129 {
130 auto interop_context = GetInteropContext();
131 if (!interop_context) {
132 return false;
133 }
134 return Playground::OpenPlaygroundHere([&](RenderTarget& target) -> bool {
135 auto impeller_surface = std::make_shared<impeller::Surface>(target);
137 *interop_context.Get(), //
138 std::move(impeller_surface) //
139 );
140 if (!surface) {
141 VALIDATION_LOG << "Could not wrap test surface as an interop surface.";
142 return false;
143 }
144 return callback(interop_context, surface);
145 });
146}
bool OpenPlaygroundHere(const RenderCallback &render_callback)
VkSurfaceKHR surface
Definition main.cc:65
uint32_t * target
FlutterDesktopBinaryReply callback
static ScopedObject< Surface > CreateSharedSurface(PlaygroundBackend backend, Context &context, std::shared_ptr< impeller::Surface > shared_surface)
#define VALIDATION_LOG
Definition validation.h:91

References callback, impeller::interop::testing::CreateSharedSurface(), impeller::PlaygroundTest::GetBackend(), GetInteropContext(), impeller::Playground::OpenPlaygroundHere(), surface, target, and VALIDATION_LOG.

◆ operator=()

PlaygroundTest & impeller::interop::testing::PlaygroundTest::operator= ( const PlaygroundTest )
delete

◆ SetUp()

void impeller::interop::testing::PlaygroundTest::SetUp ( )
override

Definition at line 50 of file playground_test.cc.

References impeller::PlaygroundTest::SetUp().

◆ TearDown()

void impeller::interop::testing::PlaygroundTest::TearDown ( )
override

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