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

Commit 6d404bf

Browse files
author
auto-submit[bot]
committed
Revert "Remove #if SHELL_ENABLE_METAL checks in iOS code (#51636)"
This reverts commit e3104af.
1 parent c17cb89 commit 6d404bf

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 18 additions & 12 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 = true
22+
enable_metal = shell_enable_metal
2323
}
2424

2525
# The headers that will be copied to the Flutter.framework and be accessed
@@ -147,22 +147,12 @@ 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",
154150
"ios_context_software.h",
155151
"ios_context_software.mm",
156-
"ios_external_texture_metal.h",
157-
"ios_external_texture_metal.mm",
158152
"ios_external_view_embedder.h",
159153
"ios_external_view_embedder.mm",
160154
"ios_surface.h",
161155
"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",
166156
"ios_surface_software.h",
167157
"ios_surface_software.mm",
168158
"platform_message_handler_ios.h",
@@ -180,6 +170,23 @@ source_set("flutter_framework_source") {
180170
defines += [ "APPLICATION_EXTENSION_API_ONLY=1" ]
181171
}
182172

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+
183190
deps += [
184191
":ios_gpu_configuration",
185192
"//flutter/common",
@@ -193,7 +200,6 @@ source_set("flutter_framework_source") {
193200
"//flutter/shell/platform/common:common_cpp_input",
194201
"//flutter/shell/platform/darwin/common",
195202
"//flutter/shell/platform/darwin/common:framework_common",
196-
"//flutter/shell/platform/darwin/graphics",
197203
"//flutter/shell/platform/embedder:embedder_as_internal_library",
198204
"//flutter/shell/profiling:profiling",
199205
"//flutter/skia",

shell/platform/darwin/ios/ios_context.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
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
912
#include "flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h"
1013
#include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
11-
#include "flutter/shell/platform/darwin/ios/ios_context_software.h"
14+
#endif // SHELL_ENABLE_METAL
1215

1316
namespace flutter {
1417

@@ -29,13 +32,15 @@
2932
"in an environment that does not support Metal. Enabling GPU pass through in your "
3033
"environment may fix this. If that is not possible, then disable Impeller.";
3134
return std::make_unique<IOSContextSoftware>();
35+
#if SHELL_ENABLE_METAL
3236
case IOSRenderingAPI::kMetal:
3337
switch (backend) {
3438
case IOSRenderingBackend::kSkia:
3539
return std::make_unique<IOSContextMetalSkia>(msaa_samples);
3640
case IOSRenderingBackend::kImpeller:
3741
return std::make_unique<IOSContextMetalImpeller>(is_gpu_disabled_sync_switch);
3842
}
43+
#endif // SHELL_ENABLE_METAL
3944
default:
4045
break;
4146
}

shell/platform/darwin/ios/ios_surface.mm

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

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

7-
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
8-
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
97
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
8+
109
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
1110

11+
#if SHELL_ENABLE_METAL
12+
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
13+
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
14+
#endif // SHELL_ENABLE_METAL
15+
1216
namespace flutter {
1317

1418
std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> context,
1519
const fml::scoped_nsobject<CALayer>& layer) {
1620
FML_DCHECK(layer);
1721
FML_DCHECK(context);
1822

23+
#if SHELL_ENABLE_METAL
1924
if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
2025
if ([layer.get() isKindOfClass:[CAMetalLayer class]]) {
2126
switch (context->GetBackend()) {
@@ -35,6 +40,7 @@
3540
}
3641
}
3742
}
43+
#endif // SHELL_ENABLE_METAL
3844

3945
return std::make_unique<IOSSurfaceSoftware>(layer, // layer
4046
std::move(context) // context

shell/platform/darwin/ios/rendering_api_selection.mm

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

77
#include <Foundation/Foundation.h>
8-
#include <Metal/Metal.h>
98
#include <QuartzCore/CAEAGLLayer.h>
109
#import <QuartzCore/CAMetalLayer.h>
10+
#if SHELL_ENABLE_METAL
11+
#include <Metal/Metal.h>
12+
#endif // SHELL_ENABLE_METAL
1113
#import <TargetConditionals.h>
1214

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

1719
namespace flutter {
1820

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+
1933
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
2034
#if TARGET_OS_SIMULATOR
2135
if (force_software) {
@@ -28,9 +42,12 @@ IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
2842
}
2943
#endif // TARGET_OS_SIMULATOR
3044

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

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

0 commit comments

Comments
 (0)