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 #include "impeller/display_list/aiks_context.h"
11 #include "impeller/typographer/backends/skia/typographer_context_skia.h"
12 #include "impeller/typographer/typographer_context.h"
13 
15 
16 namespace flutter {
17 
18 IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller(const fml::scoped_nsobject<CAMetalLayer>& layer,
19  const std::shared_ptr<IOSContext>& context)
20  : IOSSurface(context),
21  GPUSurfaceMetalDelegate(MTLRenderTargetType::kCAMetalLayer),
22  layer_(layer),
23  impeller_context_(context ? context->GetImpellerContext() : nullptr),
24  aiks_context_(context ? context->GetAiksContext() : nullptr) {
25  if (!impeller_context_ || !aiks_context_) {
26  return;
27  }
28  is_valid_ = true;
29 }
30 
31 // |IOSSurface|
33 
34 // |IOSSurface|
35 bool IOSSurfaceMetalImpeller::IsValid() const {
36  return is_valid_;
37 }
38 
39 // |IOSSurface|
40 void IOSSurfaceMetalImpeller::UpdateStorageSizeIfNecessary() {
41  // Nothing to do.
42 }
43 
44 // |IOSSurface|
45 std::unique_ptr<Surface> IOSSurfaceMetalImpeller::CreateGPUSurface(GrDirectContext*) {
46  impeller_context_->UpdateOffscreenLayerPixelFormat(
47  impeller::FromMTLPixelFormat(layer_.get().pixelFormat));
48  return std::make_unique<GPUSurfaceMetalImpeller>(this, //
49  aiks_context_ //
50  );
51 }
52 
53 // |GPUSurfaceMetalDelegate|
54 GPUCAMetalLayerHandle IOSSurfaceMetalImpeller::GetCAMetalLayer(const SkISize& frame_info) const {
55  CAMetalLayer* layer = layer_.get();
56  const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
57  if (!CGSizeEqualToSize(drawable_size, layer.drawableSize)) {
58  layer.drawableSize = drawable_size;
59  }
60 
61  // Flutter needs to read from the color attachment in cases where there are effects such as
62  // backdrop filters. Flutter plugins that create platform views may also read from the layer.
63  layer.framebufferOnly = NO;
64 
65  return (__bridge GPUCAMetalLayerHandle)layer;
66 }
67 
68 // |GPUSurfaceMetalDelegate|
69 bool IOSSurfaceMetalImpeller::PresentDrawable(GrMTLHandle drawable) const {
70  FML_DCHECK(false);
71  return false;
72 }
73 
74 // |GPUSurfaceMetalDelegate|
75 GPUMTLTextureInfo IOSSurfaceMetalImpeller::GetMTLTexture(const SkISize& frame_info) const {
76  FML_CHECK(false);
77  return GPUMTLTextureInfo{
78  .texture_id = -1, //
79  .texture = nullptr //
80  };
81 }
82 
83 // |GPUSurfaceMetalDelegate|
84 bool IOSSurfaceMetalImpeller::PresentTexture(GPUMTLTextureInfo texture) const {
85  FML_CHECK(false);
86  return false;
87 }
88 
89 // |GPUSurfaceMetalDelegate|
90 bool IOSSurfaceMetalImpeller::AllowsDrawingWhenGpuDisabled() const {
91  return false;
92 }
93 
94 } // namespace flutter
flutter::IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller
IOSSurfaceMetalImpeller(const fml::scoped_nsobject< CAMetalLayer > &layer, const std::shared_ptr< IOSContext > &context)
Definition: ios_surface_metal_impeller.mm:18
flutter::IOSSurface
Definition: ios_surface.h:21
flutter
Definition: accessibility_bridge.h:28
ios_surface_metal_impeller.h
flutter::IOSSurfaceMetalImpeller::~IOSSurfaceMetalImpeller
~IOSSurfaceMetalImpeller()
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13