| Flutter Impeller |

Public Types | Public Member Functions | List of all members
impeller::interop::testing::PlaygroundTest Class Reference

`#include <playground_test.h>`

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

## 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
PlaygroundTest & | operator= (const PlaygroundTest &)=delete
void | SetUp () override
void | TearDown () override
ScopedObject< Context > | CreateContext () const
ScopedObject< Context > | GetInteropContext ()
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::Mapping > | OpenAssetAsMapping (std::string asset_name) const override
absl::StatusOr< RuntimeStage::Map > | OpenAssetAsRuntimeStage (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
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
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...

## Additional Inherited Members
Static Public Member Functions inherited from impeller::Playground
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 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

using impeller::interop::testing::PlaygroundTest::InteropPlaygroundCallback = std::function<bool(const ScopedObject<Context>& context, const ScopedObject<Surface>& surface)>

Definition at line 42 of file playground_test.h.

## Constructor & Destructor Documentation

## ◆ PlaygroundTest() [1/2]

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

Definition at line 43 of file playground_test.cc.

43 {
44 SetupImpellerHPPProcTableOnce();
45 }
impeller::interop::testing::SetupImpellerHPPProcTableOnce
static void SetupImpellerHPPProcTableOnce()
Definition: playground_test.cc:30

References impeller::interop::testing::SetupImpellerHPPProcTableOnce().

## ◆ ~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()) {
61 case PlaygroundBackend::kMetal:
62 return Adopt<Context>(
63 ImpellerContextCreateMetalNew(ImpellerGetVersion()));
64 case PlaygroundBackend::kOpenGLES: {
65 Playground::GLProcAddressResolver playground_gl_proc_address_callback =
66 CreateGLProcAddressResolver();
67 ImpellerProcAddressCallback gl_proc_address_callback =
68 [](const char* proc_name, void* user_data) -> void* {
69 return (*reinterpret_cast<Playground::GLProcAddressResolver*>(
70 user_data))(proc_name);
71 };
72 return Adopt<Context>(ImpellerContextCreateOpenGLESNew(
73 ImpellerGetVersion(), gl_proc_address_callback,
74 &playground_gl_proc_address_callback));
75 }
76 case PlaygroundBackend::kVulkan:
77 ImpellerContextVulkanSettings settings = {};
78 struct UserData {
79 Playground::VKProcAddressResolver resolver;
80 } user_data;
81 user_data.resolver = CreateVKProcAddressResolver();
82 settings.user_data = &user_data;
83 settings.enable_vulkan_validation = switches_.enable_vulkan_validation;
84 settings.proc_address_callback = [](void* instance, //
85 const char* proc_name, //
86 void* user_data //
87 ) -> void* {
88 auto resolver = reinterpret_cast<UserData*>(user_data)->resolver;
89 if (resolver) {
90 return resolver(instance, proc_name);
91 } else {
92 return nullptr;
93 }
94 };
95 return Adopt<Context>(
96 ImpellerContextCreateVulkanNew(ImpellerGetVersion(), &settings));
97 }
98 FML_UNREACHABLE();
99 }
impeller::Playground::CreateGLProcAddressResolver
GLProcAddressResolver CreateGLProcAddressResolver() const
Definition: playground.cc:520
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:131
impeller::Playground::VKProcAddressResolver
std::function< void *(void *instance, const char *proc_name)> VKProcAddressResolver
Definition: playground.h:122
impeller::Playground::GLProcAddressResolver
std::function< void *(const char *proc_name)> GLProcAddressResolver
Definition: playground.h:118
impeller::Playground::CreateVKProcAddressResolver
VKProcAddressResolver CreateVKProcAddressResolver() const
Definition: playground.cc:525
impeller::PlaygroundTest::GetBackend
PlaygroundBackend GetBackend() const
Definition: playground_test.cc:75
ImpellerProcAddressCallback
void *IMPELLER_NULLABLE(* ImpellerProcAddressCallback)(const char *IMPELLER_NONNULL proc_name, void *IMPELLER_NULLABLE user_data)
Definition: impeller.h:347
impeller::interop::ImpellerGetVersion
IMPELLER_EXTERN_C uint32_t ImpellerGetVersion()
Definition: impeller.cc:92
impeller::interop::ImpellerContextCreateVulkanNew
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateVulkanNew(uint32_t version, const ImpellerContextVulkanSettings *settings)
Definition: impeller.cc:152
impeller::interop::ImpellerContextCreateMetalNew
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateMetalNew(uint32_t version)
Definition: impeller.cc:134
impeller::interop::ImpellerContextCreateOpenGLESNew
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateOpenGLESNew(uint32_t version, ImpellerProcAddressCallback gl_proc_address_callback, void *gl_proc_address_callback_user_data)
Definition: impeller.cc:108
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PlaygroundBackend::kVulkan
@ kVulkan
ImpellerContextVulkanSettings
Definition: impeller.h:632
ImpellerContextVulkanSettings::proc_address_callback
ImpellerVulkanProcAddressCallback IMPELLER_NONNULL proc_address_callback
Definition: impeller.h:634
ImpellerContextVulkanSettings::enable_vulkan_validation
bool enable_vulkan_validation
Definition: impeller.h:635
ImpellerContextVulkanSettings::user_data
void *IMPELLER_NULLABLE user_data
Definition: impeller.h:633
impeller::PlaygroundSwitches::enable_vulkan_validation
bool enable_vulkan_validation
Definition: switches.h:22

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

## ◆ GetHPPContext()

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

Definition at line 181 of file playground_test.cc.

181 {
182 auto c_context = GetInteropContext().GetC();
183 ImpellerContextRetain(c_context);
184 return hpp::Context{c_context, hpp::AdoptTag::kAdopt};
185 }
impeller::interop::testing::PlaygroundTest::GetInteropContext
ScopedObject< Context > GetInteropContext()
Definition: playground_test.cc:168
impeller::interop::ImpellerContextRetain
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 168 of file playground_test.cc.

168 {
169 if (interop_context_) {
170 return interop_context_;
171 }
172
173 auto context = CreateSharedContext(GetBackend(), GetContext());
174 if (!context) {
175 return nullptr;
176 }
177 interop_context_ = std::move(context);
178 return interop_context_;
179 }
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91
impeller::interop::testing::CreateSharedContext
static ScopedObject< Context > CreateSharedContext(PlaygroundBackend backend, std::shared_ptr< impeller::Context > shared_context)
Definition: playground_test.cc:146

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 187 of file playground_test.cc.

188 {
189 std::shared_ptr<fml::Mapping> data =
190 OpenAssetAsMapping(std::move(asset_name));
191 if (!data) {
192 return nullptr;
193 }
194 return std::make_unique<hpp::Mapping>(data->GetMapping(), //
195 data->GetSize(), //
196 [data]() {} //
197 );
198 }
impeller::PlaygroundTest::OpenAssetAsMapping
std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const override
Definition: playground_test.cc:84
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:69

References data, and impeller::PlaygroundTest::OpenAssetAsMapping().

## ◆ OpenAssetAsHPPTexture()

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

Definition at line 200 of file playground_test.cc.

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

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

## ◆ OpenPlaygroundHere()

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

Definition at line 127 of file playground_test.cc.

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

References impeller::interop::testing::CreateSharedSurface(), impeller::PlaygroundTest::GetBackend(), GetInteropContext(), impeller::Playground::OpenPlaygroundHere(), 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.

50 {
51 ::impeller::PlaygroundTest::SetUp();
52 }
impeller::PlaygroundTest::SetUp
void SetUp() override
Definition: playground_test.cc:45

References impeller::PlaygroundTest::SetUp().

## ◆ TearDown()

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

Definition at line 55 of file playground_test.cc.

55 {
56 ::impeller::PlaygroundTest::TearDown();
57 }
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:79

References impeller::PlaygroundTest::TearDown().

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

- impeller/toolkit/interop/playground_test.h
- impeller/toolkit/interop/playground_test.cc