-
Couldn't load subscription status.
- Fork 6k
Enabled metal on ios simulator #17881
Changes from all commits
a4fff2f
839185c
5c92d7d
ea495b7
eed65a5
63d1a38
13bd8e5
5b8e616
5bce7ab
40fb32b
db5db70
a2b792b
eaf87d0
f323636
c0a9f73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
| #import "flutter/shell/platform/darwin/ios/ios_surface_gl.h" | ||
| #import "flutter/shell/platform/darwin/ios/ios_surface_software.h" | ||
|
|
||
| #include "flutter/shell/platform/darwin/ios/rendering_api_selection.h" | ||
|
|
||
| #if FLUTTER_SHELL_ENABLE_METAL | ||
| #import "flutter/shell/platform/darwin/ios/ios_surface_metal.h" | ||
| #endif // FLUTTER_SHELL_ENABLE_METAL | ||
|
|
@@ -30,13 +32,15 @@ | |
| } | ||
|
|
||
| #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 METAL_IOS_VERSION_BASELINE, *)) { | ||
| 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 | ||
| ); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,23 @@ enum class IOSRenderingAPI { | |
| kMetal, | ||
| }; | ||
|
|
||
| IOSRenderingAPI GetRenderingAPIForProcess(); | ||
| // Pass force_software to force software rendering. This is only respected on | ||
| // simulators. | ||
| IOSRenderingAPI GetRenderingAPIForProcess(bool force_software); | ||
|
|
||
| Class GetCoreAnimationLayerClassForRenderingAPI( | ||
| IOSRenderingAPI rendering_api = GetRenderingAPIForProcess()); | ||
| Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api); | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| // Flutter supports Metal on all devices with Apple A7 SoC or above that have | ||
| // been updated to or 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. | ||
| // Support for Metal on simulators was added by Apple in the SDK for iOS 13. | ||
| #if TARGET_OS_SIMULATOR | ||
| #define METAL_IOS_VERSION_BASELINE 13.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please document how these baselines were selected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was added by @Kavantix - Adding what I assume is correct as // Metal support was added for simulators in iOS 13.
// Otherwise, the lowest supported version in Skia is iOS 10.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh I see, I'm moving the old comment from the impl file to here, and adding another line about when sim support was added. |
||
| #else | ||
| #define METAL_IOS_VERSION_BASELINE 10.0 | ||
| #endif // TARGET_OS_SIMULATOR | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_RENDERING_API_SELECTION_H_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,37 +10,49 @@ | |
| #if FLUTTER_SHELL_ENABLE_METAL | ||
| #include <Metal/Metal.h> | ||
| #endif // FLUTTER_SHELL_ENABLE_METAL | ||
| #import <TargetConditionals.h> | ||
|
|
||
| #include "flutter/fml/logging.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| #if FLUTTER_SHELL_ENABLE_METAL | ||
| bool ShouldUseMetalRenderer() { | ||
| // Flutter supports Metal on all devices with Apple A7 SoC or above that have been updated to or | ||
| // 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 METAL_IOS_VERSION_BASELINE, *)) { | ||
| auto device = MTLCreateSystemDefaultDevice(); | ||
| 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 | ||
| IOSRenderingAPI GetRenderingAPIForProcess(bool force_software) { | ||
| #if TARGET_OS_SIMULATOR | ||
| if (force_software) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows software rendering on devices. This check should only be performed on simulators. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an #elif block if we're not in release to print a warning that you can't use this on physical devices. |
||
| return IOSRenderingAPI::kSoftware; | ||
| } | ||
| #else | ||
| if (force_software) { | ||
| FML_LOG(WARNING) << "The --enable-software-rendering is only supported on Simulator targets " | ||
| "and will be ignored."; | ||
| } | ||
| #endif // TARGET_OS_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_OS_SIMULATOR | ||
| return IOSRenderingAPI::kSoftware; | ||
| #else | ||
| return IOSRenderingAPI::kOpenGLES; | ||
| #endif // TARGET_OS_SIMULATOR | ||
| } | ||
|
|
||
| Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api) { | ||
|
|
@@ -49,10 +61,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 METAL_IOS_VERSION_BASELINE, *)) { | ||
| return [CAMetalLayer class]; | ||
| } | ||
Kavantix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| FML_CHECK(false) << "Metal availability should already have been checked"; | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright 2020 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #import <Flutter/Flutter.h> | ||
| #import <XCTest/XCTest.h> | ||
|
|
||
| @interface RenderingSelectionTest : XCTestCase | ||
| @property(nonatomic, strong) XCUIApplication* application; | ||
| @end | ||
|
|
||
| @implementation RenderingSelectionTest | ||
|
|
||
| - (void)setUp { | ||
| [super setUp]; | ||
| self.continueAfterFailure = NO; | ||
| self.application = [[XCUIApplication alloc] init]; | ||
| } | ||
|
|
||
| - (void)testSoftwareRendering { | ||
| self.application.launchArguments = | ||
| @[ @"--animated-color-square", @"--assert-ca-layer-type", @"--enable-software-rendering" ]; | ||
| [self.application launch]; | ||
|
|
||
| // App asserts that the rendering API is CALayer | ||
| } | ||
|
|
||
| - (void)testMetalRendering { | ||
| self.application.launchArguments = @[ @"--animated-color-square", @"--assert-ca-layer-type" ]; | ||
| [self.application launch]; | ||
|
|
||
| // App asserts that the rendering API is CAMetalLayer | ||
| } | ||
| @end |
Uh oh!
There was an error while loading. Please reload this page.