Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ios_surface_metal_impeller.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
6
7#include "flutter/impeller/renderer/backend/metal/formats_mtl.h"
8#include "flutter/impeller/renderer/context.h"
9#include "flutter/shell/gpu/gpu_surface_metal_impeller.h"
10
12
13namespace flutter {
14
16 const std::shared_ptr<IOSContext>& context)
17 : IOSSurface(context),
19 layer_(layer),
20 impeller_context_(context ? context->GetImpellerContext() : nullptr) {
21 if (!impeller_context_) {
22 return;
23 }
24 is_valid_ = true;
25}
26
27// |IOSSurface|
29
30// |IOSSurface|
32 return is_valid_;
33}
34
35// |IOSSurface|
39
40// |IOSSurface|
42 impeller_context_->UpdateOffscreenLayerPixelFormat(
43 impeller::FromMTLPixelFormat(layer_.get().pixelFormat));
44 return std::make_unique<GPUSurfaceMetalImpeller>(this, //
45 impeller_context_ //
46 );
47}
48
49// |GPUSurfaceMetalDelegate|
51 CAMetalLayer* layer = layer_.get();
52 const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
53 if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
54 layer.drawableSize = drawable_size;
55 }
56
57 // Flutter needs to read from the color attachment in cases where there are effects such as
58 // backdrop filters. Flutter plugins that create platform views may also read from the layer.
59 layer.framebufferOnly = NO;
60
61 // When there are platform views in the scene, the drawable needs to be presented in the same
62 // transaction as the one created for platform views. When the drawable are being presented from
63 // the raster thread, we may not be able to use a transaction as it will dirty the UIViews being
64 // presented. If there is a non-Flutter UIView active, such as in add2app or a
65 // presentViewController page transition, then this will cause CoreAnimation assertion errors and
66 // exit the app.
67 layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
68
69 return (__bridge GPUCAMetalLayerHandle)layer;
70}
71
72// |GPUSurfaceMetalDelegate|
74 FML_DCHECK(false);
75 return false;
76}
77
78// |GPUSurfaceMetalDelegate|
80 FML_CHECK(false);
81 return GPUMTLTextureInfo{
82 .texture_id = -1, //
83 .texture = nullptr //
84 };
85}
86
87// |GPUSurfaceMetalDelegate|
89 FML_CHECK(false);
90 return false;
91}
92
93// |GPUSurfaceMetalDelegate|
97
98} // namespace flutter
const void * GrMTLHandle
Definition GrMtlTypes.h:20
Interface implemented by all platform surfaces that can present a metal backing store to the "screen"...
bool PresentTexture(GPUMTLTextureInfo texture) const override __attribute__((cf_audited_transfer))
Presents the texture with texture_id to the "screen". texture_id corresponds to a texture that has be...
IOSSurfaceMetalImpeller(const fml::scoped_nsobject< CAMetalLayer > &layer, const std::shared_ptr< IOSContext > &context)
bool AllowsDrawingWhenGpuDisabled() const override
Whether to allow drawing to the surface when the GPU is disabled.
GPUCAMetalLayerHandle GetCAMetalLayer(const SkISize &frame_info) const override __attribute__((cf_audited_transfer))
Returns the handle to the CAMetalLayer to render to. This is only called when the specified render ta...
GPUMTLTextureInfo GetMTLTexture(const SkISize &frame_info) const override __attribute__((cf_audited_transfer))
Returns the handle to the MTLTexture to render to. This is only called when the specified render targ...
bool PresentDrawable(GrMTLHandle drawable) const override __attribute__((cf_audited_transfer))
Presents the drawable to the "screen". The drawable is obtained from the CAMetalLayer that given by G...
std::unique_ptr< Surface > CreateGPUSurface(GrDirectContext *gr_context) override
T get() const __attribute((ns_returns_not_retained))
#define FML_CHECK(condition)
Definition logging.h:85
#define FML_DCHECK(condition)
Definition logging.h:103
FlTexture * texture
constexpr PixelFormat FromMTLPixelFormat(MTLPixelFormat format)
Definition formats_mtl.h:23
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37