7#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
9#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
10#include "flutter/shell/gpu/gpu_surface_metal_skia.h"
11#include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
16- (void)flutterPrepareForPresent:(nonnull
id<MTLCommandBuffer>)commandBuffer;
27 std::shared_ptr<IOSContext> context)
33 auto darwin_context = metal_context->GetDarwinContext().get();
34 command_queue_ = darwin_context.commandQueue;
35 device_ = darwin_context.device;
42bool IOSSurfaceMetalSkia::IsValid()
const {
47void IOSSurfaceMetalSkia::UpdateStorageSizeIfNecessary() {
52std::unique_ptr<Surface> IOSSurfaceMetalSkia::CreateGPUSurface(
GrDirectContext* context) {
54 return std::make_unique<GPUSurfaceMetalSkia>(
this,
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];
83bool 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];
104GPUMTLTextureInfo 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};
110bool IOSSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo
texture)
const {
111 FML_CHECK(
false) <<
"render to texture not supported on ios";
116bool IOSSurfaceMetalSkia::AllowsDrawingWhenGpuDisabled()
const {
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