Flutter iOS Embedder
rendering_api_selection.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 <Foundation/Foundation.h>
8 #include <Metal/Metal.h>
9 #include <QuartzCore/CAEAGLLayer.h>
10 #import <QuartzCore/CAMetalLayer.h>
11 #import <TargetConditionals.h>
12 
13 #include "flutter/fml/logging.h"
14 #import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
17 
19 
20 namespace flutter {
21 namespace {
22 
23 bool IsMetalAvailable() {
24  bool ios_version_supports_metal = false;
25  if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
26  id<MTLDevice> device = MTLCreateSystemDefaultDevice();
27  ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3];
28  }
29  return ios_version_supports_metal;
30 }
31 
32 } // namespace
33 
35  static bool metal_available = IsMetalAvailable();
36  FML_CHECK(metal_available)
37  << "Metal is unavailable. On a simulator this means the host environment "
38  "does not expose a Metal device; enabling GPU passthrough may fix this.";
39 
40  if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
41  // FlutterMetalLayer reports itself as a CAMetalLayer via -isKindOfClass:.
42  if ([FlutterMetalLayer enabled]) {
43  return [FlutterMetalLayer class];
44  }
45  return [CAMetalLayer class];
46  }
47  FML_CHECK(false) << "Metal availability should already have been checked";
48  return [CALayer class];
49 }
50 
51 } // namespace flutter
Class GetCoreAnimationLayerClass()
#define METAL_IOS_VERSION_BASELINE