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 
17 
19 
20 namespace flutter {
21 
23  bool ios_version_supports_metal = false;
24  if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
25  id<MTLDevice> device = MTLCreateSystemDefaultDevice();
26  ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3];
27  }
28  return ios_version_supports_metal;
29 }
30 
32 #if TARGET_OS_SIMULATOR
33  if (force_software) {
35  }
36 #else
37  if (force_software) {
38  FML_LOG(WARNING) << "The --enable-software-rendering is only supported on Simulator targets "
39  "and will be ignored.";
40  }
41 #endif // TARGET_OS_SIMULATOR
42 
43  static bool should_use_metal = ShouldUseMetalRenderer();
44  if (should_use_metal) {
46  }
47 
48  // When Metal isn't available we use Skia software rendering since it performs
49  // a little better than emulated OpenGL. Also, omitting an OpenGL backend
50  // reduces binary footprint.
51 #if TARGET_OS_SIMULATOR
53 #else
54  FML_CHECK(false) << "Metal may only be unavailable on simulators";
56 #endif // TARGET_OS_SIMULATOR
57 }
58 
60  switch (rendering_api) {
62  return [CALayer class];
64  if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
65  if ([FlutterMetalLayer enabled]) {
66  return [FlutterMetalLayer class];
67  } else {
68  return [CAMetalLayer class];
69  }
70  }
71  FML_CHECK(false) << "Metal availability should already have been checked";
72  break;
73  default:
74  break;
75  }
76  FML_CHECK(false) << "Unknown client rendering API";
77  return [CALayer class];
78 }
79 
80 } // namespace flutter
flutter::GetCoreAnimationLayerClassForRenderingAPI
Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api)
Definition: rendering_api_selection.mm:59
FlutterMacros.h
flutter::GetRenderingAPIForProcess
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software)
Definition: rendering_api_selection.mm:31
flutter::ShouldUseMetalRenderer
bool ShouldUseMetalRenderer()
Definition: rendering_api_selection.mm:22
flutter
Definition: accessibility_bridge.h:28
flutter::IOSRenderingAPI
IOSRenderingAPI
Definition: rendering_api_selection.h:14
METAL_IOS_VERSION_BASELINE
#define METAL_IOS_VERSION_BASELINE
Definition: rendering_api_selection.h:40
flutter::IOSRenderingAPI::kMetal
@ kMetal
rendering_api_selection.h
FlutterMetalLayer.h
flutter::IOSRenderingAPI::kSoftware
@ kSoftware
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13
FlutterMetalLayer
Definition: FlutterMetalLayer.h:12