7 #include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
8 #include "flutter/shell/gpu/gpu_surface_metal_skia.h"
12 - (void)flutterPrepareForPresent:(nonnull
id<MTLCommandBuffer>)commandBuffer;
22 std::shared_ptr<IOSContext> context)
24 GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
28 auto darwin_context = metal_context->GetDarwinContext().get();
29 command_queue_ = darwin_context.commandQueue;
30 device_ = darwin_context.device;
37 bool IOSSurfaceMetalSkia::IsValid()
const {
42 void IOSSurfaceMetalSkia::UpdateStorageSizeIfNecessary() {
47 std::unique_ptr<Surface> IOSSurfaceMetalSkia::CreateGPUSurface(GrDirectContext* context) {
49 return std::make_unique<GPUSurfaceMetalSkia>(
this,
56 GPUCAMetalLayerHandle IOSSurfaceMetalSkia::GetCAMetalLayer(
const SkISize& frame_info)
const {
57 CAMetalLayer* layer = layer_.get();
58 layer.device = device_;
60 layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
63 layer.framebufferOnly = NO;
65 const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
66 if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
67 layer.drawableSize = drawable_size;
73 layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
79 bool IOSSurfaceMetalSkia::PresentDrawable(GrMTLHandle drawable)
const {
80 if (drawable ==
nullptr) {
81 FML_DLOG(ERROR) <<
"Could not acquire next Metal drawable from the SkSurface.";
86 fml::scoped_nsprotocol<id<MTLCommandBuffer>>([[command_queue_ commandBuffer] retain]);
88 id<CAMetalDrawable> metal_drawable =
reinterpret_cast<id<CAMetalDrawable>
>(drawable);
93 [command_buffer.get() commit];
94 [command_buffer.get() waitUntilScheduled];
96 [metal_drawable present];
101 GPUMTLTextureInfo IOSSurfaceMetalSkia::GetMTLTexture(
const SkISize& frame_info)
const {
102 FML_CHECK(
false) <<
"render to texture not supported on ios";
103 return {.texture_id = -1, .texture = nullptr};
107 bool IOSSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo texture)
const {
108 FML_CHECK(
false) <<
"render to texture not supported on ios";
113 bool IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled()
const {