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 (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 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 TearDownContextData ()
 
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.
 
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.
 
virtual void EnsureContextSupportsAntialiasLines ()
 Make sure that when the context is later created that it will support the experimental AA lines flag.
 
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)
 

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;
87 settings.proc_address_callback = [](void* instance, //
88 const char* proc_name, //
89 void* user_data //
90 ) -> void* {
91 auto resolver = reinterpret_cast<UserData*>(user_data)->resolver;
92 if (resolver) {
93 return resolver(instance, proc_name);
94 } else {
95 return nullptr;
96 }
97 };
98 return Adopt<Context>(
100 }
102}
GLProcAddressResolver CreateGLProcAddressResolver() const
const PlaygroundSwitches & GetSwitches() const
Return an unmodifiable reference to the current switches. The switches might change at the start of a...
Definition playground.h:167
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::Playground::GetSwitches(), 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, ImpellerContextVulkanSettings::user_data, and user_data.

◆ GetHPPContext()

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

Definition at line 188 of file playground_test.cc.

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

175 {
176 if (interop_context_) {
177 return interop_context_;
178 }
179
181 if (!context) {
182 return nullptr;
183 }
184 interop_context_ = std::move(context);
185 return interop_context_;
186}
std::shared_ptr< Context > GetContext() const
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 194 of file playground_test.cc.

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

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

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