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

Reverts "Remove #if SHELL_ENABLE_METAL checks in iOS code (#51636)" #51941

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions shell/platform/darwin/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ shell_gpu_configuration("ios_gpu_configuration") {
enable_software = true
enable_gl = false
enable_vulkan = false
enable_metal = true
enable_metal = shell_enable_metal
}

# The headers that will be copied to the Flutter.framework and be accessed
Expand Down Expand Up @@ -147,22 +147,12 @@ source_set("flutter_framework_source") {
"framework/Source/vsync_waiter_ios.mm",
"ios_context.h",
"ios_context.mm",
"ios_context_metal_impeller.h",
"ios_context_metal_impeller.mm",
"ios_context_metal_skia.h",
"ios_context_metal_skia.mm",
"ios_context_software.h",
"ios_context_software.mm",
"ios_external_texture_metal.h",
"ios_external_texture_metal.mm",
"ios_external_view_embedder.h",
"ios_external_view_embedder.mm",
"ios_surface.h",
"ios_surface.mm",
"ios_surface_metal_impeller.h",
"ios_surface_metal_impeller.mm",
"ios_surface_metal_skia.h",
"ios_surface_metal_skia.mm",
"ios_surface_software.h",
"ios_surface_software.mm",
"platform_message_handler_ios.h",
Expand All @@ -180,6 +170,23 @@ source_set("flutter_framework_source") {
defines += [ "APPLICATION_EXTENSION_API_ONLY=1" ]
}

if (shell_enable_metal) {
sources += [
"ios_context_metal_impeller.h",
"ios_context_metal_impeller.mm",
"ios_context_metal_skia.h",
"ios_context_metal_skia.mm",
"ios_external_texture_metal.h",
"ios_external_texture_metal.mm",
"ios_surface_metal_impeller.h",
"ios_surface_metal_impeller.mm",
"ios_surface_metal_skia.h",
"ios_surface_metal_skia.mm",
]

deps += [ "//flutter/shell/platform/darwin/graphics" ]
}

deps += [
":ios_gpu_configuration",
"//flutter/common",
Expand All @@ -193,7 +200,6 @@ source_set("flutter_framework_source") {
"//flutter/shell/platform/common:common_cpp_input",
"//flutter/shell/platform/darwin/common",
"//flutter/shell/platform/darwin/common:framework_common",
"//flutter/shell/platform/darwin/graphics",
"//flutter/shell/platform/embedder:embedder_as_internal_library",
"//flutter/shell/profiling:profiling",
"//flutter/skia",
Expand Down
7 changes: 6 additions & 1 deletion shell/platform/darwin/ios/ios_context.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"

#include "flutter/fml/logging.h"
#include "flutter/shell/platform/darwin/ios/ios_context_software.h"

#if SHELL_ENABLE_METAL
#include "flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h"
#include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
#include "flutter/shell/platform/darwin/ios/ios_context_software.h"
#endif // SHELL_ENABLE_METAL

namespace flutter {

Expand All @@ -29,13 +32,15 @@
"in an environment that does not support Metal. Enabling GPU pass through in your "
"environment may fix this. If that is not possible, then disable Impeller.";
return std::make_unique<IOSContextSoftware>();
#if SHELL_ENABLE_METAL
case IOSRenderingAPI::kMetal:
switch (backend) {
case IOSRenderingBackend::kSkia:
return std::make_unique<IOSContextMetalSkia>(msaa_samples);
case IOSRenderingBackend::kImpeller:
return std::make_unique<IOSContextMetalImpeller>(is_gpu_disabled_sync_switch);
}
#endif // SHELL_ENABLE_METAL
default:
break;
}
Expand Down
10 changes: 8 additions & 2 deletions shell/platform/darwin/ios/ios_surface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@

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

#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"

#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"

#if SHELL_ENABLE_METAL
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.h"
#import "flutter/shell/platform/darwin/ios/ios_surface_metal_skia.h"
#endif // SHELL_ENABLE_METAL

namespace flutter {

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

#if SHELL_ENABLE_METAL
if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
if ([layer.get() isKindOfClass:[CAMetalLayer class]]) {
switch (context->GetBackend()) {
Expand All @@ -35,6 +40,7 @@
}
}
}
#endif // SHELL_ENABLE_METAL

return std::make_unique<IOSSurfaceSoftware>(layer, // layer
std::move(context) // context
Expand Down
21 changes: 19 additions & 2 deletions shell/platform/darwin/ios/rendering_api_selection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"

#include <Foundation/Foundation.h>
#include <Metal/Metal.h>
#include <QuartzCore/CAEAGLLayer.h>
#import <QuartzCore/CAMetalLayer.h>
#if SHELL_ENABLE_METAL
#include <Metal/Metal.h>
#endif // SHELL_ENABLE_METAL
#import <TargetConditionals.h>

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

namespace flutter {

#if SHELL_ENABLE_METAL
bool ShouldUseMetalRenderer() {
bool ios_version_supports_metal = false;
if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
auto device = MTLCreateSystemDefaultDevice();
ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3];
[device release];
}
return ios_version_supports_metal;
}
#endif // SHELL_ENABLE_METAL

IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
#if TARGET_OS_SIMULATOR
if (force_software) {
Expand All @@ -28,9 +42,12 @@ IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) {
}
#endif // TARGET_OS_SIMULATOR

if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
#if SHELL_ENABLE_METAL
static bool should_use_metal = ShouldUseMetalRenderer();
if (should_use_metal) {
return IOSRenderingAPI::kMetal;
}
#endif // SHELL_ENABLE_METAL

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