| 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 <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"
15 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
16 #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.h"
17
18 FLUTTER_ASSERT_ARC
19
20 namespace flutter {
21
22 bool ShouldUseMetalRenderer() {
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
31 IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
32 #if TARGET_OS_SIMULATOR
33 if (force_software) {
34 return IOSRenderingAPI::kSoftware;
35 }
36 #else
37 if (force_software) {
38 [FlutterLogger logWarning:@"The --enable-software-rendering is only supported on simulator "
39 "targets and will be ignored."];
40 }
41 #endif // TARGET_OS_SIMULATOR
42
43 static bool should_use_metal = ShouldUseMetalRenderer();
44 if (should_use_metal) {
45 return IOSRenderingAPI::kMetal;
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
52 return IOSRenderingAPI::kSoftware;
53 #else
54 FML_CHECK(false) << "Metal may only be unavailable on simulators";
55 return IOSRenderingAPI::kSoftware;
56 #endif // TARGET_OS_SIMULATOR
57 }
58
59 Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api) {
60 switch (rendering_api) {
61 case IOSRenderingAPI::kSoftware:
62 return [CALayer class];
63 case IOSRenderingAPI::kMetal:
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
FlutterMacros.h
FlutterMetalLayer.h
FlutterMetalLayer
Definition: FlutterMetalLayer.h:16
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13
flutter
Definition: accessibility_bridge.h:26
flutter::ShouldUseMetalRenderer
bool ShouldUseMetalRenderer()
Definition: rendering_api_selection.mm:22
flutter::GetRenderingAPIForProcess
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software)
Definition: rendering_api_selection.mm:31
flutter::IOSRenderingAPI
IOSRenderingAPI
Definition: rendering_api_selection.h:14
flutter::IOSRenderingAPI::kMetal
@ kMetal
flutter::IOSRenderingAPI::kSoftware
@ kSoftware
flutter::GetCoreAnimationLayerClassForRenderingAPI
Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api)
Definition: rendering_api_selection.mm:59
rendering_api_selection.h
METAL_IOS_VERSION_BASELINE
#define METAL_IOS_VERSION_BASELINE
Definition: rendering_api_selection.h:40