Flutter iOS Embedder
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 
6 
7 #include <memory>
8 
9 #include "flutter/fml/logging.h"
10 #import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
13 
15 
16 namespace flutter {
17 
18 std::unique_ptr<IOSSurface> IOSSurface::Create(const std::shared_ptr<IOSContext>& context,
19  CALayer* layer) {
20  FML_DCHECK(layer);
21  FML_DCHECK(context);
22 
23  if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
24  if ([layer isKindOfClass:[CAMetalLayer class]]) {
25  return std::make_unique<IOSSurfaceMetalImpeller>(
26  static_cast<CAMetalLayer*>(layer), // Metal layer
27  context // context
28  );
29  }
30  }
31  // The layer MUST be a CAMetalLayer or FlutterMetalLayer, which overrides
32  // isKindOfClass to return true for the above check. Anything else means the
33  // rendering surface was misconfigured.
34  FML_CHECK(false) << "Expected a Metal-backed layer for iOS rendering.";
35  FML_UNREACHABLE();
36 }
37 
38 IOSSurface::IOSSurface(std::shared_ptr<IOSContext> ios_context)
39  : ios_context_(std::move(ios_context)) {
40  FML_DCHECK(ios_context_);
41 }
42 
43 IOSSurface::~IOSSurface() = default;
44 
45 std::shared_ptr<IOSContext> IOSSurface::GetContext() const {
46  return ios_context_;
47 }
48 
49 } // namespace flutter
IOSSurface(std::shared_ptr< IOSContext > ios_context)
Definition: ios_surface.mm:38
std::shared_ptr< IOSContext > GetContext() const
Definition: ios_surface.mm:45
static std::unique_ptr< IOSSurface > Create(const std::shared_ptr< IOSContext > &context, CALayer *layer)
Definition: ios_surface.mm:18
#define METAL_IOS_VERSION_BASELINE