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;
23 GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
27 FlutterDarwinContextMetalSkia* darwin_context = metal_context->
GetDarwinContext();
28 command_queue_ = darwin_context.commandQueue;
29 device_ = darwin_context.device;
36 bool IOSSurfaceMetalSkia::IsValid()
const {
41 void IOSSurfaceMetalSkia::UpdateStorageSizeIfNecessary() {
46 std::unique_ptr<Surface> IOSSurfaceMetalSkia::CreateGPUSurface(GrDirectContext* context) {
48 return std::make_unique<GPUSurfaceMetalSkia>(
this,
54 GPUCAMetalLayerHandle IOSSurfaceMetalSkia::GetCAMetalLayer(
const SkISize& frame_info)
const {
55 layer_.device = device_;
57 layer_.pixelFormat = MTLPixelFormatBGRA8Unorm;
60 layer_.framebufferOnly = NO;
62 const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
63 if (!CGSizeEqualToSize(drawable_size, layer_.drawableSize)) {
64 layer_.drawableSize = drawable_size;
70 layer_.presentsWithTransaction = [[NSThread currentThread] isMainThread];
72 return (__bridge GPUCAMetalLayerHandle)layer_;
76 bool IOSSurfaceMetalSkia::PreparePresent(GrMTLHandle drawable)
const {
77 id<MTLCommandBuffer> command_buffer = [command_queue_ commandBuffer];
78 id<CAMetalDrawable> metal_drawable = (__bridge id<CAMetalDrawable>)drawable;
82 [command_buffer commit];
83 [command_buffer waitUntilScheduled];
88 bool IOSSurfaceMetalSkia::PresentDrawable(GrMTLHandle drawable)
const {
89 if (drawable ==
nullptr) {
90 FML_DLOG(ERROR) <<
"Could not acquire next Metal drawable from the SkSurface.";
94 id<CAMetalDrawable> metal_drawable = (__bridge id<CAMetalDrawable>)drawable;
95 [metal_drawable present];
100 GPUMTLTextureInfo IOSSurfaceMetalSkia::GetMTLTexture(
const SkISize& frame_info)
const {
101 FML_CHECK(
false) <<
"render to texture not supported on ios";
102 return {.texture_id = -1, .texture = nullptr};
106 bool IOSSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo texture)
const {
107 FML_CHECK(
false) <<
"render to texture not supported on ios";
112 bool IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled()
const {
118 #endif // !SLIMPELLER