Flutter Engine
The Flutter Engine
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|
31bool IOSSurfaceMetalImpeller::IsValid() const {
32 return is_valid_;
33}
34
35// |IOSSurface|
36void IOSSurfaceMetalImpeller::UpdateStorageSizeIfNecessary() {
37 // Nothing to do.
38}
39
40// |IOSSurface|
41std::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|
50GPUCAMetalLayerHandle 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|
73bool IOSSurfaceMetalImpeller::PresentDrawable(GrMTLHandle drawable) const {
74 FML_DCHECK(false);
75 return false;
76}
77
78// |GPUSurfaceMetalDelegate|
79GPUMTLTextureInfo 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|
88bool IOSSurfaceMetalImpeller::PresentTexture(GPUMTLTextureInfo texture) const {
89 FML_CHECK(false);
90 return false;
91}
92
93// |GPUSurfaceMetalDelegate|
94bool IOSSurfaceMetalImpeller::AllowsDrawingWhenGpuDisabled() const {
95 return false;
96}
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"...
IOSSurfaceMetalImpeller(const fml::scoped_nsobject< CAMetalLayer > &layer, const std::shared_ptr< IOSContext > &context)
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:22
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37