Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
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
#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
() {
32
static
bool
should_use_metal =
ShouldUseMetalRenderer
();
33
if
(should_use_metal) {
34
return
IOSRenderingAPI::kMetal
;
35
}
36
37
// When Metal isn't available we use Skia software rendering since it performs
38
// a little better than emulated OpenGL. Also, omitting an OpenGL backend
39
// reduces binary footprint.
40
#if TARGET_OS_SIMULATOR
41
return
IOSRenderingAPI::kSoftware
;
42
#else
43
FML_CHECK
(
false
) <<
"Metal may only be unavailable on simulators"
;
44
return
IOSRenderingAPI::kSoftware
;
45
#endif
// TARGET_OS_SIMULATOR
46
}
47
48
Class
GetCoreAnimationLayerClassForRenderingAPI
(
IOSRenderingAPI
rendering_api) {
49
switch
(rendering_api) {
50
case
IOSRenderingAPI::kSoftware
:
51
return
[CALayer
class
];
52
case
IOSRenderingAPI::kMetal
:
53
if
(@available(iOS
METAL_IOS_VERSION_BASELINE
, *)) {
54
if
([
FlutterMetalLayer
enabled]) {
55
return
[
FlutterMetalLayer
class
];
56
}
else
{
57
return
[CAMetalLayer
class
];
58
}
59
}
60
FML_CHECK
(
false
) <<
"Metal availability should already have been checked"
;
61
break
;
62
default
:
63
break
;
64
}
65
FML_CHECK
(
false
) <<
"Unknown client rendering API"
;
66
return
[CALayer
class
];
67
}
68
69
}
// namespace flutter
FlutterMacros.h
FlutterMetalLayer.h
device
VkDevice device
Definition
main.cc:69
logging.h
FML_CHECK
#define FML_CHECK(condition)
Definition
logging.h:104
FlutterMetalLayer
Definition
FlutterMetalLayer.h:16
FLUTTER_ASSERT_ARC
Definition
FlutterChannelKeyResponder.mm:13
flutter
Definition
asset_manager.cc:10
flutter::ShouldUseMetalRenderer
bool ShouldUseMetalRenderer()
Definition
rendering_api_selection.mm:22
flutter::IOSRenderingAPI
IOSRenderingAPI
Definition
rendering_api_selection.h:14
flutter::IOSRenderingAPI::kMetal
@ kMetal
flutter::IOSRenderingAPI::kSoftware
@ kSoftware
flutter::GetRenderingAPIForProcess
IOSRenderingAPI GetRenderingAPIForProcess()
Definition
rendering_api_selection.mm:31
flutter::GetCoreAnimationLayerClassForRenderingAPI
Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api)
Definition
rendering_api_selection.mm:48
rendering_api_selection.h
METAL_IOS_VERSION_BASELINE
#define METAL_IOS_VERSION_BASELINE
Definition
rendering_api_selection.h:38
shell
platform
darwin
ios
rendering_api_selection.mm
Generated on Fri Jul 24 2026 07:12:38 for Flutter Engine Uber Docs by
1.9.8