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::PresentDrawable(GrMTLHandle drawable)
const {
84 if (drawable ==
nullptr) {
85 FML_DLOG(ERROR) <<
"Could not acquire next Metal drawable from the SkSurface.";
89 id<MTLCommandBuffer> command_buffer = [command_queue_ commandBuffer];
91 id<CAMetalDrawable> metal_drawable = (__bridge id<CAMetalDrawable>)drawable;
96 [command_buffer commit];
97 [command_buffer waitUntilScheduled];
99 [metal_drawable present];
104 GPUMTLTextureInfo IOSSurfaceMetalSkia::GetMTLTexture(
const SkISize& frame_info)
const {
105 FML_CHECK(
false) <<
"render to texture not supported on ios";
106 return {.texture_id = -1, .texture = nullptr};
110 bool IOSSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo texture)
const {
111 FML_CHECK(
false) <<
"render to texture not supported on ios";
116 bool IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled()
const {
122 #endif // !SLIMPELLER