| Flutter iOS Embedder |

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
11 namespace flutter {
12
13 IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller(const fml::scoped_nsobject<CAMetalLayer>& layer,
14 const std::shared_ptr<IOSContext>& context)
15 : IOSSurface(context),
16 GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
17 layer_(layer),
18 impeller_context_(context ? context->GetImpellerContext() : nullptr) {
19 if (!impeller_context_) {
20 return;
21 }
22 is_valid_ = true;
23 }
24
25 // |IOSSurface|
26 IOSSurfaceMetalImpeller::~IOSSurfaceMetalImpeller() = default;
27
28 // |IOSSurface|
29 bool IOSSurfaceMetalImpeller::IsValid() const {
30 return is_valid_;
31 }
32
33 // |IOSSurface|
34 void IOSSurfaceMetalImpeller::UpdateStorageSizeIfNecessary() {
35 // Nothing to do.
36 }
37
38 // |IOSSurface|
39 std::unique_ptr<Surface> IOSSurfaceMetalImpeller::CreateGPUSurface(GrDirectContext*) {
40 impeller_context_->UpdateOffscreenLayerPixelFormat(
41 impeller::FromMTLPixelFormat(layer_.get().pixelFormat));
42 return std::make_unique<GPUSurfaceMetalImpeller>(this, //
43 impeller_context_ //
44 );
45 }
46
47 // |GPUSurfaceMetalDelegate|
48 GPUCAMetalLayerHandle IOSSurfaceMetalImpeller::GetCAMetalLayer(const SkISize& frame_info) const {
49 CAMetalLayer* layer = layer_.get();
50 const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
51 if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
52 layer.drawableSize = drawable_size;
53 }
54
55 // Flutter needs to read from the color attachment in cases where there are effects such as
56 // backdrop filters. Flutter plugins that create platform views may also read from the layer.
57 layer.framebufferOnly = NO;
58
59 // When there are platform views in the scene, the drawable needs to be presented in the same
60 // transaction as the one created for platform views. When the drawable are being presented from
61 // the raster thread, we may not be able to use a transaction as it will dirty the UIViews being
62 // presented. If there is a non-Flutter UIView active, such as in add2app or a
63 // presentViewController page transition, then this will cause CoreAnimation assertion errors and
64 // exit the app.
65 layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
66
67 return layer;
68 }
69
70 // |GPUSurfaceMetalDelegate|
71 bool IOSSurfaceMetalImpeller::PresentDrawable(GrMTLHandle drawable) const {
72 FML_DCHECK(false);
73 return false;
74 }
75
76 // |GPUSurfaceMetalDelegate|
77 GPUMTLTextureInfo IOSSurfaceMetalImpeller::GetMTLTexture(const SkISize& frame_info) const {
78 FML_CHECK(false);
79 return GPUMTLTextureInfo{
80 .texture_id = -1, //
81 .texture = nullptr //
82 };
83 }
84
85 // |GPUSurfaceMetalDelegate|
86 bool IOSSurfaceMetalImpeller::PresentTexture(GPUMTLTextureInfo texture) const {
87 FML_CHECK(false);
88 return false;
89 }
90
91 // |GPUSurfaceMetalDelegate|
92 bool IOSSurfaceMetalImpeller::AllowsDrawingWhenGpuDisabled() const {
93 return false;
94 }
95
96 } // namespace flutter
flutter::IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller
IOSSurfaceMetalImpeller(const fml::scoped_nsobject< CAMetalLayer > &layer, const std::shared_ptr< IOSContext > &context)
Definition: ios_surface_metal_impeller.mm:13
flutter::IOSSurface
Definition: ios_surface.h:25
flutter
Definition: accessibility_bridge.h:28
ios_surface_metal_impeller.h
flutter::IOSSurfaceMetalImpeller::~IOSSurfaceMetalImpeller
~IOSSurfaceMetalImpeller()