| 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 namespace flutter {
18
19 #if 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 [device release];
26 }
27 return ios_version_supports_metal;
28 }
29 #endif // SHELL_ENABLE_METAL
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 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 #if SHELL_ENABLE_METAL
44 static bool should_use_metal = ShouldUseMetalRenderer();
45 if (should_use_metal) {
46 return IOSRenderingAPI::kMetal;
47 }
48 #endif // SHELL_ENABLE_METAL
49
50 // When Metal isn't available we use Skia software rendering since it performs
51 // a little better than emulated OpenGL. Also, omitting an OpenGL backend
52 // reduces binary footprint.
53 #if TARGET_OS_SIMULATOR
54 return IOSRenderingAPI::kSoftware;
55 #else
56 FML_CHECK(false) << "Metal may only be unavailable on simulators";
57 return IOSRenderingAPI::kSoftware;
58 #endif // TARGET_OS_SIMULATOR
59 }
60
61 Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api) {
62 switch (rendering_api) {
63 case IOSRenderingAPI::kSoftware:
64 return [CALayer class];
65 case IOSRenderingAPI::kMetal:
66 if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
67 return [CAMetalLayer class];
68 }
69 FML_CHECK(false) << "Metal availability should already have been checked";
70 break;
71 default:
72 break;
73 }
74 FML_CHECK(false) << "Unknown client rendering API";
75 return [CALayer class];
76 }
77
78 } // namespace flutter
flutter::GetCoreAnimationLayerClassForRenderingAPI
Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api)
Definition: rendering_api_selection.mm:61
flutter::GetRenderingAPIForProcess
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software)
Definition: rendering_api_selection.mm:31
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
flutter::IOSRenderingAPI::kSoftware
@ kSoftware