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 
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 
13 namespace flutter {
14 
15 IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller(const fml::scoped_nsobject<CAMetalLayer>& layer,
16  const std::shared_ptr<IOSContext>& context)
17  : IOSSurface(context),
18  GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
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|
31 bool IOSSurfaceMetalImpeller::IsValid() const {
32  return is_valid_;
33 }
34 
35 // |IOSSurface|
36 void IOSSurfaceMetalImpeller::UpdateStorageSizeIfNecessary() {
37  // Nothing to do.
38 }
39 
40 // |IOSSurface|
41 std::unique_ptr<Surface> IOSSurfaceMetalImpeller::CreateGPUSurface(GrDirectContext*) {
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|
50 GPUCAMetalLayerHandle IOSSurfaceMetalImpeller::GetCAMetalLayer(const SkISize& frame_info) const {
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|
73 bool IOSSurfaceMetalImpeller::PresentDrawable(GrMTLHandle drawable) const {
74  FML_DCHECK(false);
75  return false;
76 }
77 
78 // |GPUSurfaceMetalDelegate|
79 GPUMTLTextureInfo IOSSurfaceMetalImpeller::GetMTLTexture(const SkISize& frame_info) const {
80  FML_CHECK(false);
81  return GPUMTLTextureInfo{
82  .texture_id = -1, //
83  .texture = nullptr //
84  };
85 }
86 
87 // |GPUSurfaceMetalDelegate|
88 bool IOSSurfaceMetalImpeller::PresentTexture(GPUMTLTextureInfo texture) const {
89  FML_CHECK(false);
90  return false;
91 }
92 
93 // |GPUSurfaceMetalDelegate|
94 bool IOSSurfaceMetalImpeller::AllowsDrawingWhenGpuDisabled() const {
95  return false;
96 }
97 
98 } // namespace flutter
flutter::IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller
IOSSurfaceMetalImpeller(const fml::scoped_nsobject< CAMetalLayer > &layer, const std::shared_ptr< IOSContext > &context)
Definition: ios_surface_metal_impeller.mm:15
flutter::IOSSurface
Definition: ios_surface.h:25
flutter
Definition: accessibility_bridge.h:28
ios_surface_metal_impeller.h
flutter::IOSSurfaceMetalImpeller::~IOSSurfaceMetalImpeller
~IOSSurfaceMetalImpeller()
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13