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_gl.h"
8 #import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
9 
10 #include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
11 
12 #if FLUTTER_SHELL_ENABLE_METAL
13 #import "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
14 #endif // FLUTTER_SHELL_ENABLE_METAL
15 
16 namespace flutter {
17 
18 std::unique_ptr<IOSSurface> IOSSurface::Create(
19  std::shared_ptr<IOSContext> context,
21  FlutterPlatformViewsController* platform_views_controller) {
22  FML_DCHECK(layer);
23  FML_DCHECK(context);
24 
25  if ([layer.get() isKindOfClass:[CAEAGLLayer class]]) {
26  return std::make_unique<IOSSurfaceGL>(
28  reinterpret_cast<CAEAGLLayer*>([layer.get() retain])), // EAGL layer
29  std::move(context), // context
30  platform_views_controller // platform views controller
31  );
32  }
33 
34 #if FLUTTER_SHELL_ENABLE_METAL
35  if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
36  if ([layer.get() isKindOfClass:[CAMetalLayer class]]) {
37  return std::make_unique<IOSSurfaceMetal>(
39  reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
40  std::move(context), // context
41  platform_views_controller // platform views controller
42  );
43  }
44  }
45 #endif // FLUTTER_SHELL_ENABLE_METAL
46 
47  return std::make_unique<IOSSurfaceSoftware>(
48  std::move(layer), // layer
49  std::move(context), // context
50  platform_views_controller // platform views controller
51  );
52 }
53 
54 IOSSurface::IOSSurface(std::shared_ptr<IOSContext> ios_context,
55  FlutterPlatformViewsController* platform_views_controller)
56  : ios_context_(std::move(ios_context)) {
57  FML_DCHECK(ios_context_);
58  external_view_embedder_ =
59  std::make_shared<IOSExternalViewEmbedder>(platform_views_controller, ios_context_);
60 }
61 
62 IOSSurface::~IOSSurface() = default;
63 
64 std::shared_ptr<IOSContext> IOSSurface::GetContext() const {
65  return ios_context_;
66 }
67 
68 std::shared_ptr<IOSExternalViewEmbedder> IOSSurface::GetSurfaceExternalViewEmbedder() const {
69  return external_view_embedder_;
70 }
71 
72 } // namespace flutter
std::shared_ptr< IOSContext > GetContext() const
Definition: ios_surface.mm:64
IOSSurface(std::shared_ptr< IOSContext > ios_context, FlutterPlatformViewsController *platform_views_controller)
Definition: ios_surface.mm:54
#define FML_DCHECK(condition)
Definition: logging.h:86
Definition: ref_ptr.h:252
std::shared_ptr< IOSExternalViewEmbedder > GetSurfaceExternalViewEmbedder() const
Definition: ios_surface.mm:68
#define METAL_IOS_VERSION_BASELINE
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, fml::scoped_nsobject< CALayer > layer, FlutterPlatformViewsController *platform_views_controller)
Definition: ios_surface.mm:18