Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e3104af

Browse files
authored
Remove #if SHELL_ENABLE_METAL checks in iOS code (#51636)
All physical iOS devices Flutter supports (iOS 12+) can run Metal. The only time Flutter doesn't use Metal afaik is for iOS simulators running < iOS 13, which is covered by a few `if (@available(iOS METAL_IOS_VERSION_BASELINE, *))` checks. https://github.com/flutter/engine/blob/8a51e124fbf168295a1b05f8d66459bfb29ae8a9/shell/platform/darwin/ios/rendering_api_selection.h#L37-L41 Remove hardware checks for physical devices. Remove `shell_enable_metal` from the gn files and the `#if SHELL_ENABLE_METAL` checks in the iOS embedder. I limited this PR to just iOS, but I imagine it's safe to remove `shell_enable_metal` everywhere? https://github.com/flutter/engine/blob/41da00ac46bc38a97a63ed0635450271d71afd9f/shell/platform/darwin/macos/BUILD.gn#L18 https://github.com/flutter/engine/blob/41da00ac46bc38a97a63ed0635450271d71afd9f/tools/gn#L673-L679
1 parent c6fd95f commit e3104af

File tree

4 files changed

+17
-51
lines changed

4 files changed

+17
-51
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ shell_gpu_configuration("ios_gpu_configuration") {
1919
enable_software = true
2020
enable_gl = false
2121
enable_vulkan = false
22-
enable_metal = shell_enable_metal
22+
enable_metal = true
2323
}
2424

2525
# The headers that will be copied to the Flutter.framework and be accessed
@@ -147,12 +147,22 @@ source_set("flutter_framework_source") {
147147
"framework/Source/vsync_waiter_ios.mm",
148148
"ios_context.h",
149149
"ios_context.mm",
150+
"ios_context_metal_impeller.h",
151+
"ios_context_metal_impeller.mm",
152+
"ios_context_metal_skia.h",
153+
"ios_context_metal_skia.mm",
150154
"ios_context_software.h",
151155
"ios_context_software.mm",
156+
"ios_external_texture_metal.h",
157+
"ios_external_texture_metal.mm",
152158
"ios_external_view_embedder.h",
153159
"ios_external_view_embedder.mm",
154160
"ios_surface.h",
155161
"ios_surface.mm",
162+
"ios_surface_metal_impeller.h",
163+
"ios_surface_metal_impeller.mm",
164+
"ios_surface_metal_skia.h",
165+
"ios_surface_metal_skia.mm",
156166
"ios_surface_software.h",
157167
"ios_surface_software.mm",
158168
"platform_message_handler_ios.h",
@@ -170,23 +180,6 @@ source_set("flutter_framework_source") {
170180
defines += [ "APPLICATION_EXTENSION_API_ONLY=1" ]
171181
}
172182

173-
if (shell_enable_metal) {
174-
sources += [
175-
"ios_context_metal_impeller.h",
176-
"ios_context_metal_impeller.mm",
177-
"ios_context_metal_skia.h",
178-
"ios_context_metal_skia.mm",
179-
"ios_external_texture_metal.h",
180-
"ios_external_texture_metal.mm",
181-
"ios_surface_metal_impeller.h",
182-
"ios_surface_metal_impeller.mm",
183-
"ios_surface_metal_skia.h",
184-
"ios_surface_metal_skia.mm",
185-
]
186-
187-
deps += [ "//flutter/shell/platform/darwin/graphics" ]
188-
}
189-
190183
deps += [
191184
":ios_gpu_configuration",
192185
"//flutter/common",
@@ -200,6 +193,7 @@ source_set("flutter_framework_source") {
200193
"//flutter/shell/platform/common:common_cpp_input",
201194
"//flutter/shell/platform/darwin/common",
202195
"//flutter/shell/platform/darwin/common:framework_common",
196+
"//flutter/shell/platform/darwin/graphics",
203197
"//flutter/shell/platform/embedder:embedder_as_internal_library",
204198
"//flutter/shell/profiling:profiling",
205199
"//flutter/skia",

shell/platform/darwin/ios/ios_context.mm

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
77

88
#include "flutter/fml/logging.h"
9-
#include "flutter/shell/platform/darwin/ios/ios_context_software.h"
10-
11-
#if SHELL_ENABLE_METAL
129
#include "flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h"
1310
#include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
14-
#endif // SHELL_ENABLE_METAL
11+
#include "flutter/shell/platform/darwin/ios/ios_context_software.h"
1512

1613
namespace flutter {
1714

@@ -32,15 +29,13 @@
3229
"in an environment that does not support Metal. Enabling GPU pass through in your "
3330
"environment may fix this. If that is not possible, then disable Impeller.";
3431
return std::make_unique<IOSContextSoftware>();
35-
#if SHELL_ENABLE_METAL
3632
case IOSRenderingAPI::kMetal:
3733
switch (backend) {
3834
case IOSRenderingBackend::kSkia:
3935
return std::make_unique<IOSContextMetalSkia>(msaa_samples);
4036
case IOSRenderingBackend::kImpeller:
4137
return std::make_unique<IOSContextMetalImpeller>(is_gpu_disabled_sync_switch);
4238
}
43-
#endif // SHELL_ENABLE_METAL
4439
default:
4540
break;
4641
}

shell/platform/darwin/ios/ios_surface.mm

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44

55
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
66

7-
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
8-
9-
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
10-
11-
#if SHELL_ENABLE_METAL
127
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
138
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
14-
#endif // SHELL_ENABLE_METAL
9+
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
10+
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
1511

1612
namespace flutter {
1713

@@ -20,7 +16,6 @@
2016
FML_DCHECK(layer);
2117
FML_DCHECK(context);
2218

23-
#if SHELL_ENABLE_METAL
2419
if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
2520
if ([layer.get() isKindOfClass:[CAMetalLayer class]]) {
2621
switch (context->GetBackend()) {
@@ -40,7 +35,6 @@
4035
}
4136
}
4237
}
43-
#endif // SHELL_ENABLE_METAL
4438

4539
return std::make_unique<IOSSurfaceSoftware>(layer, // layer
4640
std::move(context) // context

shell/platform/darwin/ios/rendering_api_selection.mm

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
66

77
#include <Foundation/Foundation.h>
8+
#include <Metal/Metal.h>
89
#include <QuartzCore/CAEAGLLayer.h>
910
#import <QuartzCore/CAMetalLayer.h>
10-
#if SHELL_ENABLE_METAL
11-
#include <Metal/Metal.h>
12-
#endif // SHELL_ENABLE_METAL
1311
#import <TargetConditionals.h>
1412

1513
#include "flutter/fml/logging.h"
@@ -18,18 +16,6 @@
1816

1917
namespace flutter {
2018

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-
3319
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
3420
#if TARGET_OS_SIMULATOR
3521
if (force_software) {
@@ -42,12 +28,9 @@ IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
4228
}
4329
#endif // TARGET_OS_SIMULATOR
4430

45-
#if SHELL_ENABLE_METAL
46-
static bool should_use_metal = ShouldUseMetalRenderer();
47-
if (should_use_metal) {
31+
if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
4832
return IOSRenderingAPI::kMetal;
4933
}
50-
#endif // SHELL_ENABLE_METAL
5134

5235
// When Metal isn't available we use Skia software rendering since it performs
5336
// a little better than emulated OpenGL. Also, omitting an OpenGL backend

0 commit comments

Comments
 (0)