Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions shell/gpu/gpu_surface_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

namespace flutter {

#if TARGET_IPHONE_SIMULATOR
class API_AVAILABLE(ios(13.0)) GPUSurfaceMetal : public Surface {
#else
class GPUSurfaceMetal : public Surface {
#endif // TARGET_IPHONE_SIMULATOR
public:
GPUSurfaceMetal(GPUSurfaceDelegate* delegate,
fml::scoped_nsobject<CAMetalLayer> layer,
Expand Down
20 changes: 13 additions & 7 deletions shell/platform/darwin/ios/ios_surface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ bool IsIosEmbeddedViewsPreviewEnabled() {
}

#if FLUTTER_SHELL_ENABLE_METAL
if ([layer.get() isKindOfClass:[CAMetalLayer class]]) {
return std::make_unique<IOSSurfaceMetal>(
fml::scoped_nsobject<CAMetalLayer>(
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
std::move(context), // context
platform_views_controller // platform views controller
);
#if TARGET_IPHONE_SIMULATOR
if (@available(iOS 13.0, *)) {
#endif // TARGET_IPHONE_SIMULATOR
if ([layer.get() isKindOfClass:[CAMetalLayer class]]) {
return std::make_unique<IOSSurfaceMetal>(
fml::scoped_nsobject<CAMetalLayer>(
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
std::move(context), // context
platform_views_controller // platform views controller
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: FML_CHECK(false) in an else clause saying this should already have been checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesnt make sense to me, it not being available is valid since it will use the software renderer in that case

#if TARGET_IPHONE_SIMULATOR
}
#endif // TARGET_IPHONE_SIMULATOR
#endif // FLUTTER_SHELL_ENABLE_METAL

return std::make_unique<IOSSurfaceSoftware>(
Expand Down
5 changes: 5 additions & 0 deletions shell/platform/darwin/ios/ios_surface_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

namespace flutter {

#if TARGET_IPHONE_SIMULATOR
class API_AVAILABLE(ios(13.0)) IOSSurfaceMetal final : public IOSSurface,
public GPUSurfaceDelegate {
#else
class IOSSurfaceMetal final : public IOSSurface, public GPUSurfaceDelegate {
#endif // TARGET_IPHONE_SIMULATOR
public:
IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer,
std::shared_ptr<IOSContext> context,
Expand Down
27 changes: 21 additions & 6 deletions shell/platform/darwin/ios/rendering_api_selection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,34 @@ bool ShouldUseMetalRenderer() {
// past iOS 10.0. The processor was selected as it is the first version at which Metal was
// supported. The iOS version floor was selected due to the availability of features used by Skia.
bool ios_version_supports_metal = false;
#if TARGET_IPHONE_SIMULATOR
if (@available(iOS 13.0, *)) {
#else
if (@available(iOS 10.0, *)) {
#endif // TARGET_IPHONE_SIMULATOR
auto device = MTLCreateSystemDefaultDevice();
ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3];
// We need to check if the device is here since an ios 13 simulator running on an older version
// of macos (below 10.15) will not actually allow metal to be used.
if (device != nil) {
ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3];
}
}
return ios_version_supports_metal;
}
#endif // FLUTTER_SHELL_ENABLE_METAL

IOSRenderingAPI GetRenderingAPIForProcess() {
#if TARGET_IPHONE_SIMULATOR
return IOSRenderingAPI::kSoftware;
#endif // TARGET_IPHONE_SIMULATOR

#if FLUTTER_SHELL_ENABLE_METAL
static bool should_use_metal = ShouldUseMetalRenderer();
if (should_use_metal) {
return IOSRenderingAPI::kMetal;
}
#endif // FLUTTER_SHELL_ENABLE_METAL
#if TARGET_IPHONE_SIMULATOR
return IOSRenderingAPI::kSoftware;
#else
return IOSRenderingAPI::kOpenGLES;
#endif // TARGET_IPHONE_SIMULATOR
}

Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api) {
Expand All @@ -49,8 +57,15 @@ Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api) {
return [CALayer class];
case IOSRenderingAPI::kOpenGLES:
return [CAEAGLLayer class];
#if !TARGET_IPHONE_SIMULATOR
case IOSRenderingAPI::kMetal:
#if TARGET_IPHONE_SIMULATOR
// This will always be true since we filter out this case when checking if the device
// supports metal.
if (@available(iOS 13.0, *)) {
return [CAMetalLayer class];
}
break;
#else
return [CAMetalLayer class];
#endif // !TARGET_IPHONE_SIMULATOR
default:
Expand Down
2 changes: 1 addition & 1 deletion tools/gn
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def to_gn_args(args):
gn_args['goma_dir'] = None

# Enable Metal on non-simulator iOS builds.
if args.target_os == 'ios' and not args.simulator:
if args.target_os == 'ios':
gn_args['skia_use_metal'] = True
gn_args['shell_enable_metal'] = True
# Bitcode enabled builds using the current version of the toolchain leak
Expand Down