Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
15#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
16#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.h"
17
19
20namespace 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
VkDevice device
Definition main.cc:53
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
bool ShouldUseMetalRenderer()
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software)
Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api)
#define METAL_IOS_VERSION_BASELINE