5#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
7#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
8#include "flutter/shell/gpu/gpu_surface_metal_skia.h"
9#include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
13@protocol FlutterMetalDrawable <MTLDrawable>
14- (void)flutterPrepareForPresent:(nonnull
id<MTLCommandBuffer>)commandBuffer;
25 std::shared_ptr<IOSContext> context)
31 auto darwin_context = metal_context->GetDarwinContext().get();
32 command_queue_ = darwin_context.commandQueue;
33 device_ = darwin_context.device;
52 return std::make_unique<GPUSurfaceMetalSkia>(
this,
60 CAMetalLayer* layer = layer_.
get();
61 layer.device = device_;
63 layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
66 layer.framebufferOnly = NO;
68 const auto drawable_size = CGSizeMake(frame_info.
width(), frame_info.
height());
69 if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
70 layer.drawableSize = drawable_size;
76 layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
83 if (drawable ==
nullptr) {
84 FML_DLOG(
ERROR) <<
"Could not acquire next Metal drawable from the SkSurface.";
88 id<MTLCommandBuffer> command_buffer = [command_queue_ commandBuffer];
90 id<CAMetalDrawable> metal_drawable = (__bridge id<CAMetalDrawable>)drawable;
91 if ([metal_drawable conformsToProtocol:
@protocol(FlutterMetalDrawable)]) {
92 [(id<FlutterMetalDrawable>)metal_drawable flutterPrepareForPresent:command_buffer];
95 [command_buffer commit];
96 [command_buffer waitUntilScheduled];
98 [metal_drawable present];
104 FML_CHECK(
false) <<
"render to texture not supported on ios";
105 return {.
texture_id = -1, .texture =
nullptr};
110 FML_CHECK(
false) <<
"render to texture not supported on ios";
sk_sp< T > sk_ref_sp(T *obj)
std::shared_ptr< IOSContext > GetContext() const
T get() const __attribute((ns_returns_not_retained))
#define FML_DLOG(severity)
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
struct flutter::ImageMetaData __attribute__((packed))
void * GPUCAMetalLayerHandle
static IOSContextMetalSkia * CastToMetalContext(const std::shared_ptr< IOSContext > &context) __attribute__((cf_audited_transfer))
constexpr int32_t width() const
constexpr int32_t height() const