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
39 [&](
auto name) {
return proc_map.at(name); });
63 return Adopt<Context>(
69 [](
const char* proc_name,
void* user_data) ->
void* {
71 user_data))(proc_name);
75 &playground_gl_proc_address_callback));
86 const char* proc_name,
89 auto resolver =
reinterpret_cast<UserData*
>(user_data)->resolver;
91 return resolver(instance, proc_name);
96 return Adopt<Context>(
105 std::shared_ptr<impeller::Surface> shared_surface) {
107 #if IMPELLER_ENABLE_METAL
110 return Adopt<Surface>(
new SurfaceMTL(context, std::move(shared_surface)));
113 #if IMPELLER_ENABLE_OPENGLES
115 return Adopt<Surface>(
116 new SurfaceGLES(context, std::move(shared_surface)));
119 #if IMPELLER_ENABLE_VULKAN
121 return Adopt<Surface>(
new SurfaceVK(context, std::move(shared_surface)));
131 if (!interop_context) {
135 auto impeller_surface = std::make_shared<impeller::Surface>(target);
137 *interop_context.Get(),
138 std::move(impeller_surface)
141 VALIDATION_LOG <<
"Could not wrap test surface as an interop surface.";
144 return callback(interop_context, surface);
150 std::shared_ptr<impeller::Context> shared_context) {
152 #if IMPELLER_ENABLE_METAL
157 #if IMPELLER_ENABLE_OPENGLES
161 #if IMPELLER_ENABLE_VULKAN
172 if (interop_context_) {
173 return interop_context_;
180 interop_context_ = std::move(context);
181 return interop_context_;
187 return hpp::Context{c_context, hpp::AdoptTag::kAdopt};
191 std::string asset_name)
const {
192 std::shared_ptr<fml::Mapping> data =
197 return std::make_unique<hpp::Mapping>(data->GetMapping(),
205 if (!compressed_data) {
206 return {
nullptr, hpp::AdoptTag::kAdopt};
208 auto compressed_image =
210 if (!compressed_image) {
211 return {
nullptr, hpp::AdoptTag::kAdopt};
214 if (!decompressed_image.has_value()) {
215 return {
nullptr, hpp::AdoptTag::kAdopt};
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};
224 return {
nullptr, hpp::AdoptTag::kAdopt};
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]() {});
232 return hpp::Texture::WithContents(
236 .size = {rgba_decompressed_image->GetSize().width,
237 rgba_decompressed_image->GetSize().height},
240 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)
void *IMPELLER_NULLABLE(* ImpellerProcAddressCallback)(const char *IMPELLER_NONNULL proc_name, void *IMPELLER_NULLABLE user_data)
@ kImpellerPixelFormatRGBA8888
#define IMPELLER_HPP_EACH_PROC(PROC)
ProcTable gGlobalProcTable
static ScopedObject< Context > CreateSharedContext(PlaygroundBackend backend, std::shared_ptr< impeller::Context > shared_context)
static ScopedObject< Surface > CreateSharedSurface(PlaygroundBackend backend, Context &context, std::shared_ptr< impeller::Surface > shared_surface)
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)
bool Initialize(const std::function< void *(const char *function_name)> &resolver)
ImpellerVulkanProcAddressCallback IMPELLER_NONNULL proc_address_callback
bool enable_vulkan_validation
void *IMPELLER_NULLABLE user_data
ImpellerPixelFormat pixel_format
bool enable_vulkan_validation