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>(
67 Playground::GLProcAddressResolver playground_gl_proc_address_callback =
69 ImpellerProcAddressCallback gl_proc_address_callback =
70 [](const char* proc_name, void* user_data) -> void* {
71 return (*reinterpret_cast<Playground::GLProcAddressResolver*>(
72 user_data))(proc_name);
73 };
74 return Adopt<Context>(ImpellerContextCreateOpenGLESNew(
75 ImpellerGetVersion(), gl_proc_address_callback,
76 &playground_gl_proc_address_callback));
77 }
80 struct UserData {
81 Playground::VKProcAddressResolver resolver;
82 } user_data;
84 settings.user_data = &user_data;
86 settings.proc_address_callback = [](void* instance, //
87 const char* proc_name, //
88 void* user_data //
89 ) -> void* {
90 auto resolver = reinterpret_cast<UserData*>(user_data)->resolver;
91 if (resolver) {
92 return resolver(instance, proc_name);
93 } else {
94 return nullptr;
95 }
96 };
97 return Adopt<Context>(
99 }
101}
GLProcAddressResolver CreateGLProcAddressResolver() const
const PlaygroundSwitches switches_
Definition playground.h:123
std::function< void *(const char *proc_name)> GLProcAddressResolver
Definition playground.h:108
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::kOpenGLESSDF, 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 187 of file playground_test.cc.

187 {
188 auto c_context = GetInteropContext().GetC();
189 ImpellerContextRetain(c_context);
190 return hpp::Context{c_context, hpp::AdoptTag::kAdopt};
191}
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 174 of file playground_test.cc.

174 {
175 if (interop_context_) {
176 return interop_context_;
177 }
178
180 if (!context) {
181 return nullptr;
182 }
183 interop_context_ = std::move(context);
184 return interop_context_;
185}
std::shared_ptr< Context > GetContext() const
Definition playground.cc:96
static ScopedObject< Context > CreateSharedContext(PlaygroundBackend backend, std::shared_ptr< impeller::Context > shared_context)
std::shared_ptr< ContextGLES > context

References context, 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 193 of file playground_test.cc.

194 {
195 std::shared_ptr<fml::Mapping> data =
196 OpenAssetAsMapping(std::move(asset_name));
197 if (!data) {
198 return nullptr;
199 }
200 return std::make_unique<hpp::Mapping>(data->GetMapping(), //
201 data->GetSize(), //
202 [data]() {} //
203 );
204}
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 206 of file playground_test.cc.

206 {
207 auto compressed_data = OpenAssetAsMapping(std::move(asset_name));
208 if (!compressed_data) {
209 return {nullptr, hpp::AdoptTag::kAdopt};
210 }
211 auto compressed_image =
212 LoadFixtureImageCompressed(std::move(compressed_data));
213 if (!compressed_image) {
214 return {nullptr, hpp::AdoptTag::kAdopt};
215 }
216 auto decompressed_image = DecodeImageRGBA(compressed_image);
217 if (!decompressed_image.has_value()) {
218 return {nullptr, hpp::AdoptTag::kAdopt};
219 }
220 auto rgba_decompressed_image =
221 std::make_shared<DecompressedImage>(decompressed_image->ConvertToRGBA());
222 if (!rgba_decompressed_image || !rgba_decompressed_image->IsValid()) {
223 return {nullptr, hpp::AdoptTag::kAdopt};
224 }
225 auto context = GetHPPContext();
226 if (!context) {
227 return {nullptr, hpp::AdoptTag::kAdopt};
228 }
229
230 auto rgba_mapping = std::make_unique<hpp::Mapping>(
231 rgba_decompressed_image->GetAllocation()->GetMapping(),
232 rgba_decompressed_image->GetAllocation()->GetSize(),
233 [rgba_decompressed_image]() {});
234
235 return hpp::Texture::WithContents(
236 context,
239 .size = {rgba_decompressed_image->GetSize().width,
240 rgba_decompressed_image->GetSize().height},
241 .mip_count = 1u,
242 },
243 std::move(rgba_mapping));
244}
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 context, 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 131 of file playground_test.cc.

131 {
132 auto interop_context = GetInteropContext();
133 if (!interop_context) {
134 return false;
135 }
136 return Playground::OpenPlaygroundHere([&](RenderTarget& target) -> bool {
137 auto impeller_surface = std::make_shared<impeller::Surface>(target);
139 *interop_context.Get(), //
140 std::move(impeller_surface) //
141 );
142 if (!surface) {
143 VALIDATION_LOG << "Could not wrap test surface as an interop surface.";
144 return false;
145 }
146 return callback(interop_context, surface);
147 });
148}
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: