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