Flutter Engine
The Flutter Engine
ios_surface.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.h"
6
7#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
8#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
9#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
10#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
11
13
14namespace flutter {
15
16std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> context,
17 const fml::scoped_nsobject<CALayer>& layer) {
18 FML_DCHECK(layer);
19 FML_DCHECK(context);
20
21 if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
22 if ([layer.get() isKindOfClass:[CAMetalLayer class]]) {
23 switch (context->GetBackend()) {
25#if !SLIMPELLER
26 return std::make_unique<IOSSurfaceMetalSkia>(
27 fml::scoped_nsobject<CAMetalLayer>((CAMetalLayer*)layer.get()), // Metal layer
28 std::move(context) // context
29 );
30#else // !SLIMPELLER
31 FML_LOG(FATAL) << "Impeller opt-out unavailable.";
32 return nullptr;
33#endif // !SLIMPELLER
34 break;
36 return std::make_unique<IOSSurfaceMetalImpeller>(
37 fml::scoped_nsobject<CAMetalLayer>((CAMetalLayer*)layer.get()), // Metal layer
38 std::move(context) // context
39 );
40 }
41 }
42 }
43
44 return std::make_unique<IOSSurfaceSoftware>(layer, // layer
45 std::move(context) // context
46 );
47}
48
49IOSSurface::IOSSurface(std::shared_ptr<IOSContext> ios_context)
50 : ios_context_(std::move(ios_context)) {
51 FML_DCHECK(ios_context_);
52}
53
54IOSSurface::~IOSSurface() = default;
55
56std::shared_ptr<IOSContext> IOSSurface::GetContext() const {
57 return ios_context_;
58}
59
60} // namespace flutter
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, const fml::scoped_nsobject< CALayer > &layer)
Definition: ios_surface.mm:16
IOSSurface(std::shared_ptr< IOSContext > ios_context)
Definition: ios_surface.mm:49
std::shared_ptr< IOSContext > GetContext() const
Definition: ios_surface.mm:56
T get() const __attribute((ns_returns_not_retained))
#define FATAL(error)
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_DCHECK(condition)
Definition: logging.h:103
Definition: ref_ptr.h:256
#define METAL_IOS_VERSION_BASELINE