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>(
70 [](
const char* proc_name,
void* user_data) ->
void* {
72 user_data))(proc_name);
76 &playground_gl_proc_address_callback));
88 const char* proc_name,
91 auto resolver =
reinterpret_cast<UserData*
>(user_data)->resolver;
93 return resolver(instance, proc_name);
98 return Adopt<Context>(
107 std::shared_ptr<impeller::Surface> shared_surface) {
109 #if IMPELLER_ENABLE_METAL
115 #if IMPELLER_ENABLE_OPENGLES
118 return Adopt<Surface>(
122 #if IMPELLER_ENABLE_VULKAN
134 if (!interop_context) {
138 auto impeller_surface = std::make_shared<impeller::Surface>(target);
140 *interop_context.Get(),
141 std::move(impeller_surface)
144 VALIDATION_LOG <<
"Could not wrap test surface as an interop surface.";
147 return callback(interop_context, surface);
153 std::shared_ptr<impeller::Context> shared_context) {
155 #if IMPELLER_ENABLE_METAL
160 #if IMPELLER_ENABLE_OPENGLES
165 #if IMPELLER_ENABLE_VULKAN
176 if (interop_context_) {
177 return interop_context_;
184 interop_context_ = std::move(
context);
185 return interop_context_;
191 return hpp::Context{c_context, hpp::AdoptTag::kAdopt};
195 std::string asset_name)
const {
196 std::shared_ptr<fml::Mapping> data =
201 return std::make_unique<hpp::Mapping>(data->GetMapping(),
209 if (!compressed_data) {
210 return {
nullptr, hpp::AdoptTag::kAdopt};
212 auto compressed_image =
214 if (!compressed_image) {
215 return {
nullptr, hpp::AdoptTag::kAdopt};
218 if (!decompressed_image.has_value()) {
219 return {
nullptr, hpp::AdoptTag::kAdopt};
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};
228 return {
nullptr, hpp::AdoptTag::kAdopt};
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]() {});
236 return hpp::Texture::WithContents(
240 .size = {rgba_decompressed_image->GetSize().width,
241 rgba_decompressed_image->GetSize().height},
244 std::move(rgba_mapping));
bool OpenPlaygroundHere(const RenderCallback &render_callback)
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed(std::shared_ptr< fml::Mapping > mapping)
const PlaygroundSwitches & GetSwitches() const
Return an unmodifiable reference to the current switches. The switches might change at the start of a...
GLProcAddressResolver CreateGLProcAddressResolver() const
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)
std::shared_ptr< ContextGLES > 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