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); });
62 return Adopt<Context>(
68 [](
const char* proc_name,
void* user_data) ->
void* {
70 user_data))(proc_name);
74 &playground_gl_proc_address_callback));
85 const char* proc_name,
88 auto resolver =
reinterpret_cast<UserData*
>(user_data)->resolver;
90 return resolver(instance, proc_name);
95 return Adopt<Context>(
104 std::shared_ptr<impeller::Surface> shared_surface) {
106 #if IMPELLER_ENABLE_METAL
108 return Adopt<Surface>(
new SurfaceMTL(context, std::move(shared_surface)));
111 #if IMPELLER_ENABLE_OPENGLES
113 return Adopt<Surface>(
114 new SurfaceGLES(context, std::move(shared_surface)));
117 #if IMPELLER_ENABLE_VULKAN
119 return Adopt<Surface>(
new SurfaceVK(context, std::move(shared_surface)));
129 if (!interop_context) {
133 auto impeller_surface = std::make_shared<impeller::Surface>(target);
135 *interop_context.Get(),
136 std::move(impeller_surface)
139 VALIDATION_LOG <<
"Could not wrap test surface as an interop surface.";
142 return callback(interop_context, surface);
148 std::shared_ptr<impeller::Context> shared_context) {
150 #if IMPELLER_ENABLE_METAL
154 #if IMPELLER_ENABLE_OPENGLES
158 #if IMPELLER_ENABLE_VULKAN
169 if (interop_context_) {
170 return interop_context_;
177 interop_context_ = std::move(context);
178 return interop_context_;
184 return hpp::Context{c_context, hpp::AdoptTag::kAdopt};
188 std::string asset_name)
const {
189 std::shared_ptr<fml::Mapping>
data =
194 return std::make_unique<hpp::Mapping>(
data->GetMapping(),
202 if (!compressed_data) {
203 return {
nullptr, hpp::AdoptTag::kAdopt};
205 auto compressed_image =
207 if (!compressed_image) {
208 return {
nullptr, hpp::AdoptTag::kAdopt};
211 if (!decompressed_image.has_value()) {
212 return {
nullptr, hpp::AdoptTag::kAdopt};
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};
221 return {
nullptr, hpp::AdoptTag::kAdopt};
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]() {});
229 return hpp::Texture::WithContents(
233 .size = {rgba_decompressed_image->GetSize().width,
234 rgba_decompressed_image->GetSize().height},
237 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
std::shared_ptr< const fml::Mapping > data