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 3 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
3 changes: 2 additions & 1 deletion shell/gpu/gpu_surface_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
#include "flutter/shell/common/surface.h"
#include "flutter/shell/gpu/gpu_surface_delegate.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"

@class CAMetalLayer;

namespace flutter {

class GPUSurfaceMetal : public Surface {
class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetal : public Surface {
public:
GPUSurfaceMetal(GPUSurfaceDelegate* delegate,
fml::scoped_nsobject<CAMetalLayer> layer,
Expand Down
18 changes: 11 additions & 7 deletions shell/platform/darwin/ios/ios_surface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "flutter/shell/platform/darwin/ios/ios_surface_gl.h"
#include "flutter/shell/platform/darwin/ios/ios_surface_software.h"

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

#if FLUTTER_SHELL_ENABLE_METAL
#include "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
#endif // FLUTTER_SHELL_ENABLE_METAL
Expand Down Expand Up @@ -39,13 +41,15 @@ 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 (@available(iOS kMetalOSVersionBaseline, *)) {
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

}
#endif // FLUTTER_SHELL_ENABLE_METAL

Expand Down
4 changes: 3 additions & 1 deletion shell/platform/darwin/ios/ios_surface_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include "flutter/fml/macros.h"
#include "flutter/shell/gpu/gpu_surface_delegate.h"
#include "flutter/shell/platform/darwin/ios/ios_surface.h"
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"

@class CAMetalLayer;

namespace flutter {

class IOSSurfaceMetal final : public IOSSurface, public GPUSurfaceDelegate {
class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface,
public GPUSurfaceDelegate {
public:
IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer,
std::shared_ptr<IOSContext> context,
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/darwin/ios/rendering_api_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ Class GetCoreAnimationLayerClassForRenderingAPI(

} // namespace flutter

#if TARGET_OS_SIMULATOR
#define kMetalOSVersionBaseline 13.0
#else
#define kMetalOSVersionBaseline 10.0
#endif // TARGET_OS_SIMULATOR

#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_RENDERING_API_SELECTION_H_
21 changes: 13 additions & 8 deletions shell/platform/darwin/ios/rendering_api_selection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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 (@available(iOS 10.0, *)) {
if (@available(iOS kMetalOSVersionBaseline, *)) {
auto device = MTLCreateSystemDefaultDevice();
ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3];
}
Expand All @@ -30,17 +30,20 @@ bool ShouldUseMetalRenderer() {
#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

// OpenGL will be emulated using software rendering by Apple on the simulator, so we use the
// Skia software rendering since it performs a little better than the emulated OpenGL.
#if TARGET_IPHONE_SIMULATOR
return IOSRenderingAPI::kSoftware;
Copy link
Contributor

Choose a reason for hiding this comment

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

We could have something above this if --enable-software-rendering has been specified to force the emulator to run using software rendering. I think we should do this for parity with Android, and then for now we could make the bots run using software rendering until we're ready to update goldens.

Copy link
Contributor

Choose a reason for hiding this comment

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

An easy way to do this would be to add a parameter to GetRenderingAPIForProcess about whether to force software rendering, and pass settings.enable_software_rendering as the parameter.

If that's set to true, we just return IOSRenderingAPI::kSoftware.

#else
return IOSRenderingAPI::kOpenGLES;
#endif // TARGET_IPHONE_SIMULATOR
}

Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api) {
Expand All @@ -49,10 +52,12 @@ Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api) {
return [CALayer class];
case IOSRenderingAPI::kOpenGLES:
return [CAEAGLLayer class];
#if !TARGET_IPHONE_SIMULATOR
case IOSRenderingAPI::kMetal:
return [CAMetalLayer class];
#endif // !TARGET_IPHONE_SIMULATOR
if (@available(iOS kMetalOSVersionBaseline, *)) {
return [CAMetalLayer class];
}
FML_CHECK(false) << "Metal availability should already have been checked";
break;
default:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/gn
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ def to_gn_args(args):
gn_args['use_goma'] = False
gn_args['goma_dir'] = None

# Enable Metal on non-simulator iOS builds.
if args.target_os == 'ios' and not args.simulator:
# Enable Metal on iOS builds.
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