7#include "impeller/toolkit/interop/impeller.hpp"
9#if IMPELLER_ENABLE_METAL
14#if IMPELLER_ENABLE_OPENGLES
19#if IMPELLER_ENABLE_VULKAN
31 static std::once_flag sOnceFlag;
32 std::call_once(sOnceFlag, []() {
33 std::map<std::string, void*> proc_map;
34#define IMPELLER_HPP_PROC(name) \
35 proc_map[#name] = reinterpret_cast<void*>(&name);
37#undef IMPELLER_HPP_PROC
38 hpp::gGlobalProcTable.Initialize(
39 [&](
auto name) {
return proc_map.at(
name); });
63 return Adopt<Context>(
70 [](
const char* proc_name,
void*
user_data) ->
void* {
76 &playground_gl_proc_address_callback));
87 const char* proc_name,
90 auto resolver =
reinterpret_cast<UserData*
>(
user_data)->resolver;
92 return resolver(
instance, proc_name);
97 return Adopt<Context>(
106 std::shared_ptr<impeller::Surface> shared_surface) {
108#if IMPELLER_ENABLE_METAL
114#if IMPELLER_ENABLE_OPENGLES
117 return Adopt<Surface>(
121#if IMPELLER_ENABLE_VULKAN
133 if (!interop_context) {
137 auto impeller_surface = std::make_shared<impeller::Surface>(
target);
139 *interop_context.Get(),
140 std::move(impeller_surface)
143 VALIDATION_LOG <<
"Could not wrap test surface as an interop surface.";
152 std::shared_ptr<impeller::Context> shared_context) {
154#if IMPELLER_ENABLE_METAL
159#if IMPELLER_ENABLE_OPENGLES
164#if IMPELLER_ENABLE_VULKAN
175 if (interop_context_) {
176 return interop_context_;
183 interop_context_ = std::move(
context);
184 return interop_context_;
190 return hpp::Context{c_context, hpp::AdoptTag::kAdopt};
194 std::string asset_name)
const {
195 std::shared_ptr<fml::Mapping> data =
200 return std::make_unique<hpp::Mapping>(data->GetMapping(),
208 if (!compressed_data) {
209 return {
nullptr, hpp::AdoptTag::kAdopt};
211 auto compressed_image =
213 if (!compressed_image) {
214 return {
nullptr, hpp::AdoptTag::kAdopt};
217 if (!decompressed_image.has_value()) {
218 return {
nullptr, hpp::AdoptTag::kAdopt};
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};
227 return {
nullptr, hpp::AdoptTag::kAdopt};
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]() {});
235 return hpp::Texture::WithContents(
239 .size = {rgba_decompressed_image->GetSize().
width,
240 rgba_decompressed_image->GetSize().height},
243 std::move(rgba_mapping));
bool OpenPlaygroundHere(const RenderCallback &render_callback)
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed(std::shared_ptr< fml::Mapping > mapping)
GLProcAddressResolver CreateGLProcAddressResolver() const
const PlaygroundSwitches switches_
std::shared_ptr< Context > GetContext() const
std::function< void *(void *instance, const char *proc_name)> VKProcAddressResolver
std::function< void *(const char *proc_name)> GLProcAddressResolver
static std::optional< DecompressedImage > DecodeImageRGBA(const std::shared_ptr< CompressedImage > &compressed)
VKProcAddressResolver CreateVKProcAddressResolver() const
std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const override
PlaygroundBackend GetBackend() const
static ScopedObject< Context > Create(std::function< void *(const char *gl_proc_name)> proc_address_callback)
static ScopedObject< Context > Create()
static ScopedObject< Context > Create(const Settings &settings)
hpp::Texture OpenAssetAsHPPTexture(std::string asset_name)
ScopedObject< Context > CreateContext() const
std::unique_ptr< hpp::Mapping > OpenAssetAsHPPMapping(std::string asset_name) const
ScopedObject< Context > GetInteropContext()
~PlaygroundTest() override
std::function< bool(const ScopedObject< Context > &context, const ScopedObject< Surface > &surface)> InteropPlaygroundCallback
hpp::Context GetHPPContext()
bool OpenPlaygroundHere(InteropPlaygroundCallback callback)
FlutterDesktopBinaryReply callback
#define FML_UNREACHABLE()
void *IMPELLER_NULLABLE(* ImpellerProcAddressCallback)(const char *IMPELLER_NONNULL proc_name, void *IMPELLER_NULLABLE user_data)
@ kImpellerPixelFormatRGBA8888
ProcTable gGlobalProcTable
static ScopedObject< Surface > CreateSharedSurface(PlaygroundBackend backend, Context &context, std::shared_ptr< impeller::Surface > shared_surface)
static ScopedObject< Context > CreateSharedContext(PlaygroundBackend backend, std::shared_ptr< impeller::Context > shared_context)
static void SetupImpellerHPPProcTableOnce()
IMPELLER_EXTERN_C uint32_t ImpellerGetVersion()
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateVulkanNew(uint32_t version, const ImpellerContextVulkanSettings *settings)
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateMetalNew(uint32_t version)
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateOpenGLESNew(uint32_t version, ImpellerProcAddressCallback gl_proc_address_callback, void *gl_proc_address_callback_user_data)
IMPELLER_EXTERN_C void ImpellerContextRetain(ImpellerContext context)
std::shared_ptr< ContextGLES > context
ImpellerVulkanProcAddressCallback IMPELLER_NONNULL proc_address_callback
bool enable_vulkan_validation
void *IMPELLER_NULLABLE user_data
ImpellerPixelFormat pixel_format
bool enable_vulkan_validation