7 #include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
8 #include "flutter/shell/gpu/gpu_surface_metal_skia.h"
18 std::shared_ptr<IOSContext> context)
20 GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
24 auto darwin_context = metal_context->GetDarwinContext().get();
25 command_queue_ = darwin_context.commandQueue;
26 device_ = darwin_context.device;
33 bool IOSSurfaceMetalSkia::IsValid()
const {
38 void IOSSurfaceMetalSkia::UpdateStorageSizeIfNecessary() {
43 std::unique_ptr<Surface> IOSSurfaceMetalSkia::CreateGPUSurface(GrDirectContext* context) {
45 return std::make_unique<GPUSurfaceMetalSkia>(
this,
52 GPUCAMetalLayerHandle IOSSurfaceMetalSkia::GetCAMetalLayer(
const SkISize& frame_info)
const {
53 CAMetalLayer* layer = layer_.get();
54 layer.device = device_;
56 layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
59 layer.framebufferOnly = NO;
61 const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
62 if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
63 layer.drawableSize = drawable_size;
69 layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
75 bool IOSSurfaceMetalSkia::PresentDrawable(GrMTLHandle drawable)
const {
76 if (drawable ==
nullptr) {
77 FML_DLOG(ERROR) <<
"Could not acquire next Metal drawable from the SkSurface.";
82 fml::scoped_nsprotocol<id<MTLCommandBuffer>>([[command_queue_ commandBuffer] retain]);
83 [command_buffer.get() commit];
84 [command_buffer.get() waitUntilScheduled];
86 [
reinterpret_cast<id<CAMetalDrawable>
>(drawable) present];
91 GPUMTLTextureInfo IOSSurfaceMetalSkia::GetMTLTexture(
const SkISize& frame_info)
const {
92 FML_CHECK(
false) <<
"render to texture not supported on ios";
93 return {.texture_id = -1, .texture =
nullptr};
97 bool IOSSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo texture)
const {
98 FML_CHECK(
false) <<
"render to texture not supported on ios";
103 bool IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled()
const {