| 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 #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
14 FLUTTER_ASSERT_ARC
15
16 namespace flutter {
17
18 IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller(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|
32 IOSSurfaceMetalImpeller::~IOSSurfaceMetalImpeller() = default;
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_.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 const auto drawable_size = CGSizeMake(frame_info.width(), frame_info.height());
56 if (!CGSizeEqualToSize(drawable_size, layer_.drawableSize)) {
57 layer_.drawableSize = drawable_size;
58 }
59
60 // Flutter needs to read from the color attachment in cases where there are effects such as
61 // backdrop filters. Flutter plugins that create platform views may also read from the layer.
62 layer_.framebufferOnly = NO;
63
64 return (__bridge GPUCAMetalLayerHandle)layer_;
65 }
66
67 // |GPUSurfaceMetalDelegate|
68 bool IOSSurfaceMetalImpeller::PresentDrawable(GrMTLHandle drawable) const {
69 FML_DCHECK(false);
70 return false;
71 }
72
73 // |GPUSurfaceMetalDelegate|
74 GPUMTLTextureInfo IOSSurfaceMetalImpeller::GetMTLTexture(const SkISize& frame_info) const {
75 FML_CHECK(false);
76 return GPUMTLTextureInfo{
77 .texture_id = -1, //
78 .texture = nullptr //
79 };
80 }
81
82 // |GPUSurfaceMetalDelegate|
83 bool IOSSurfaceMetalImpeller::PresentTexture(GPUMTLTextureInfo texture) const {
84 FML_CHECK(false);
85 return false;
86 }
87
88 // |GPUSurfaceMetalDelegate|
89 bool IOSSurfaceMetalImpeller::AllowsDrawingWhenGpuDisabled() const {
90 return false;
91 }
92
93 } // namespace flutter
flutter::IOSSurface
Definition: ios_surface.h:20
flutter
Definition: accessibility_bridge.h:27
ios_surface_metal_impeller.h
flutter::IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller
IOSSurfaceMetalImpeller(CAMetalLayer *layer, const std::shared_ptr< IOSContext > &context)
Definition: ios_surface_metal_impeller.mm:18
flutter::IOSSurfaceMetalImpeller::~IOSSurfaceMetalImpeller
~IOSSurfaceMetalImpeller()
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13