5#define FML_USED_ON_EMBEDDER
9#include <Foundation/Foundation.h>
10#include <QuartzCore/QuartzCore.h>
21#include "impeller/entity/mtl/entity_shaders.h"
22#include "impeller/entity/mtl/framebuffer_blend_shaders.h"
23#include "impeller/entity/mtl/modern_shaders.h"
32class TesterGPUSurfaceMetalDelegate :
public GPUSurfaceMetalDelegate {
34 explicit TesterGPUSurfaceMetalDelegate(id<MTLDevice>
device)
36 layer_ = [[CAMetalLayer alloc] init];
38 layer_.pixelFormat = MTLPixelFormatBGRA8Unorm;
41 ~TesterGPUSurfaceMetalDelegate() =
default;
44 layer_.drawableSize = CGSizeMake(frame_info.width, frame_info.height);
48 bool PresentDrawable(GrMTLHandle drawable)
const override {
return true; }
50 GPUMTLTextureInfo GetMTLTexture(
const DlISize& frame_info)
const override {
return {}; }
52 bool PresentTexture(GPUMTLTextureInfo
texture)
const override {
return true; }
54 bool AllowsDrawingWhenGpuDisabled()
const override {
return true; }
57 CAMetalLayer* layer_ = nil;
60std::vector<std::shared_ptr<fml::Mapping>> ShaderLibraryMappings() {
62 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
63 impeller_entity_shaders_length),
64 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_data,
65 impeller_modern_shaders_length),
66 std::make_shared<fml::NonOwnedMapping>(impeller_framebuffer_blend_shaders_data,
67 impeller_framebuffer_blend_shaders_length),
84 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = ShaderLibraryMappings();
85 auto sync_switch = std::make_shared<fml::SyncSwitch>(
false);
89 if (!context_ || !context_->IsValid()) {
94 auto device = context_->GetMTLDevice();
100 delegate_ = std::make_unique<TesterGPUSurfaceMetalDelegate>(
device);
101 aiks_context_ = std::make_shared<impeller::AiksContext>(
112 auto surface = std::make_unique<GPUSurfaceMetalImpeller>(delegate_.get(), aiks_context_);
120 std::shared_ptr<impeller::ContextMTL> context_;
121 std::unique_ptr<TesterGPUSurfaceMetalDelegate> delegate_;
122 std::shared_ptr<impeller::AiksContext> aiks_context_;
126 auto context = std::make_unique<TesterContextMTL>();
127 if (!context->Initialize()) {
static std::unique_ptr< TesterContext > Create()
std::shared_ptr< impeller::Context > GetImpellerContext() const override
~TesterContextMTL() override
TesterContextMTL()=default
std::unique_ptr< Surface > CreateRenderingSurface() override
static std::shared_ptr< ContextMTL > Create(const Flags &flags, const std::vector< std::string > &shader_library_paths, std::shared_ptr< const fml::SyncSwitch > is_gpu_disabled_sync_switch)
static std::shared_ptr< TypographerContext > Make()
impeller::ISize32 DlISize
void * GPUCAMetalLayerHandle