-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macos] Reland default metal and also check if the system supports me…
…tal before defaulting to it (#24601)
- Loading branch information
1 parent
755ca6d
commit aa00016
Showing
10 changed files
with
127 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2013 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 <Cocoa/Cocoa.h> | ||
|
||
/** | ||
* Flutter on macOS currently supports both OpenGL and Metal rendering backends. This class provides | ||
* utilities for determining the rendering backend and the corresponging layer properties. | ||
*/ | ||
@interface FlutterRenderingBackend : NSObject | ||
|
||
/** | ||
* Returns YES if the engine is supposed to use Metal as the rendering backend. On macOS versions | ||
* >= 10.4 this is YES. | ||
*/ | ||
+ (BOOL)renderUsingMetal; | ||
|
||
/** | ||
* CALayer class depending on the rendering backend. | ||
*/ | ||
+ (nonnull Class)layerClass; | ||
|
||
/** | ||
* On both Metal and OpenGL rendering backends, `wantsLayer` is set on the `FlutterView`. This | ||
* methos is used by `FlutterView` to provide the said `CALayer`. | ||
*/ | ||
+ (nonnull CALayer*)createBackingLayer; | ||
|
||
@end |
46 changes: 46 additions & 0 deletions
46
shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2013 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/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.h" | ||
|
||
#import <Metal/Metal.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
|
||
@implementation FlutterRenderingBackend | ||
|
||
+ (BOOL)renderUsingMetal { | ||
if (@available(macOS 10.14, *)) { | ||
BOOL systemSupportsMetal = MTLCreateSystemDefaultDevice() != nil; | ||
return systemSupportsMetal; | ||
} else { | ||
return NO; | ||
} | ||
} | ||
|
||
+ (Class)layerClass { | ||
BOOL enableMetal = [FlutterRenderingBackend renderUsingMetal]; | ||
if (enableMetal) { | ||
return [CAMetalLayer class]; | ||
} else { | ||
return [CAOpenGLLayer class]; | ||
} | ||
} | ||
|
||
+ (CALayer*)createBackingLayer { | ||
BOOL enableMetal = [FlutterRenderingBackend renderUsingMetal]; | ||
if (enableMetal) { | ||
CAMetalLayer* metalLayer = [CAMetalLayer layer]; | ||
// This is set to true to synchronize the presentation of the layer and its contents with Core | ||
// Animation. When presenting the texture see `[FlutterMetalResizableBackingStoreProvider | ||
// resizeSynchronizerCommit:]` we start a CATransaction and wait for the command buffer to be | ||
// scheduled. This ensures that the resizing process is smooth. | ||
metalLayer.presentsWithTransaction = YES; | ||
metalLayer.autoresizingMask = kCALayerHeightSizable | kCALayerWidthSizable; | ||
return metalLayer; | ||
} else { | ||
return [CAOpenGLLayer layer]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters