Flutter Engine
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 
5 #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
6 
7 #include <Foundation/Foundation.h>
8 #include <QuartzCore/CAEAGLLayer.h>
9 #include <QuartzCore/CAMetalLayer.h>
10 #if FLUTTER_SHELL_ENABLE_METAL
11 #include <Metal/Metal.h>
12 #endif // FLUTTER_SHELL_ENABLE_METAL
13 #import <TargetConditionals.h>
14 
15 #include "flutter/fml/logging.h"
16 
17 namespace flutter {
18 
19 #if FLUTTER_SHELL_ENABLE_METAL
20 bool ShouldUseMetalRenderer() {
21  bool ios_version_supports_metal = false;
22  if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
23  auto device = MTLCreateSystemDefaultDevice();
24  ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3];
25  }
26  return ios_version_supports_metal;
27 }
28 #endif // FLUTTER_SHELL_ENABLE_METAL
29 
31 #if TARGET_OS_SIMULATOR
32  if (force_software) {
34  }
35 #else
36  if (force_software) {
37  FML_LOG(WARNING) << "The --enable-software-rendering is only supported on Simulator targets "
38  "and will be ignored.";
39  }
40 #endif // TARGET_OS_SIMULATOR
41 
42 #if FLUTTER_SHELL_ENABLE_METAL
43  static bool should_use_metal = ShouldUseMetalRenderer();
44  if (should_use_metal) {
46  }
47 #endif // FLUTTER_SHELL_ENABLE_METAL
48 
49  // OpenGL will be emulated using software rendering by Apple on the simulator, so we use the
50  // Skia software rendering since it performs a little better than the emulated OpenGL.
51 #if TARGET_OS_SIMULATOR
53 #else
55 #endif // TARGET_OS_SIMULATOR
56 }
57 
59  switch (rendering_api) {
61  return [CALayer class];
63  return [CAEAGLLayer class];
65  if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
66  return [CAMetalLayer class];
67  }
68  FML_CHECK(false) << "Metal availability should already have been checked";
69  break;
70  default:
71  break;
72  }
73  FML_CHECK(false) << "Unknown client rendering API";
74  return [CALayer class];
75 }
76 
77 } // namespace flutter
#define FML_LOG(severity)
Definition: logging.h:65
Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api)
#define METAL_IOS_VERSION_BASELINE
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software)
#define FML_CHECK(condition)
Definition: logging.h:68