9 #include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
10 #include "flutter/shell/gpu/gpu_surface_metal_skia.h"
16 - (void)flutterPrepareForPresent:(nonnull
id<MTLCommandBuffer>)commandBuffer;
22 __attribute__((cf_audited_transfer)) {
27 std::shared_ptr<IOSContext> context)
29 GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
33 auto darwin_context = metal_context->GetDarwinContext().get();
34 command_queue_ = darwin_context.commandQueue;
35 device_ = darwin_context.device;
42 bool IOSSurfaceMetalSkia::IsValid()
const {
47 void IOSSurfaceMetalSkia::UpdateStorageSizeIfNecessary() {
52 std::unique_ptr<Surface> IOSSurfaceMetalSkia::CreateGPUSurface(GrDirectContext* context) {
54 return std::make_unique<GPUSurfaceMetalSkia>(
this,
60 GPUCAMetalLayerHandle IOSSurfaceMetalSkia::GetCAMetalLayer(
const SkISize& frame_info)
const {
61 CAMetalLayer* layer = layer_.get();
62 layer.device = device_;
64 layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
67 layer.framebufferOnly = NO;
69 const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
70 if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
71 layer.drawableSize = drawable_size;
77 layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
79 return (__bridge GPUCAMetalLayerHandle)layer;
83 bool IOSSurfaceMetalSkia::PreparePresent(GrMTLHandle drawable)
const {
84 id<MTLCommandBuffer> command_buffer = [command_queue_ commandBuffer];
85 id<CAMetalDrawable> metal_drawable = (__bridge id<CAMetalDrawable>)drawable;
89 [command_buffer commit];
90 [command_buffer waitUntilScheduled];
95 bool IOSSurfaceMetalSkia::PresentDrawable(GrMTLHandle drawable)
const {
96 if (drawable ==
nullptr) {
97 FML_DLOG(ERROR) <<
"Could not acquire next Metal drawable from the SkSurface.";
101 id<CAMetalDrawable> metal_drawable = (__bridge id<CAMetalDrawable>)drawable;
102 [metal_drawable present];
107 GPUMTLTextureInfo IOSSurfaceMetalSkia::GetMTLTexture(
const SkISize& frame_info)
const {
108 FML_CHECK(
false) <<
"render to texture not supported on ios";
109 return {.texture_id = -1, .texture = nullptr};
113 bool IOSSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo texture)
const {
114 FML_CHECK(
false) <<
"render to texture not supported on ios";
119 bool IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled()
const {
125 #endif // !SLIMPELLER