Flutter在iOS上採用Metal驅動GPU

具體內容稍後整理後更新...更新中inggit

前言

Flutter1.17正式發佈github

關於1.17正式版

移動性能和尺寸改進

此版本的主要重點是在性能和內存改進方面繼續進行整體工做。只需將您的應用程序升級到此版本,您的用戶就會看到更快的動畫,更小的應用程序和更低的內存利用率。在此版本中,默認導航狀況(不透明的不透明路線)的速度將提升20%-37%。對於簡單的iOS動畫,您還將看到最多減小40%的CPU / GPU使用率,具體取決於硬件(在PR 14104和PR 13976中進行了詳細介紹)。web

此版本還提供了一個至關大的應用程序大小的改善是因爲幾個 補丁 是 添加 了一個大的結果。例如,Android的FlutterGallery示例在2019年末爲9.6MB,如今爲8.1MB,減小了18.5%。express

對於內存使用,此版本將快速滾動瀏覽大圖像減小了70%的內存,這也可能致使性能提升,具體取決於設備的內存量。app

Metal支持可將iOS的性能提升50%

蘋果公司在iOS上對Metal的支持幾乎能夠直接訪問底層GPU,而且是蘋果公司推薦的圖形API。在徹底支持Metal的iOS設備上,Flutter如今默認狀況下使用它,這使您的Flutter應用程序大多數時候運行得更快,平均將渲染速度提升了約50%(取決於您的工做量)。less

對於不徹底支持Metal的設備(A7處理器以前的版本或運行10以前的iOS版本的設備),Flutter會像過去同樣使用OpenGL,從而爲較舊的設備提供本地渲染速度。ide

新增Widgets:NavigationRail,DatePicker等

在此版本中,咱們添加NavigationRail了一個新的小部件,該小部件提供了響應式應用程序導航模型。它是由Google Material Design團隊設計和實施的。該NavigationRail是偉大的,可由於它是很容易在一個交換的移動和臺式機外形之間切換應用程序BottomNavigator爲您的應用程序的屏幕尺寸的增大。工具

實質性文本比例:使Flutter文本主題現代化

在此版本中,Flutter團隊完成了2018 Material Design規範的Type Scale部分的實現,同時沒有破壞現有的Flutter應用程序。2018年10月的PR 22330中增長了對新配置的選擇加入支持,但不對新名稱提供支持。現有的文本樣式名稱未更改,由於這樣作是一個重大的API更改,可能會影響大多數應用程序。此版本更新了TextThemeAPI以匹配當前的Material規範,但保留了舊名稱,以使您的代碼不會中斷。可是,舊名稱已被棄用,所以您將收到警告,以鼓勵您採用新名稱.性能

Google字體用於Flutter

文字和字體齊頭並進,所以,若是您對新的Material Text Scale實現感到興奮,那麼您可能也會對新的Flutter v1.0版Google字體感到興奮。測試

Google字體容許開發人員在其應用中輕鬆地嘗試和使用fonts.google.com中的任何字體。當應用程序準備發佈時,開發人員將決定用戶是否經過從API下載字體來接收字體,或者它與應用程序包預先捆綁在一塊兒。

可訪問性和國際化

在此發行版中,咱們已完成了所有工做,包括滾動,文本 字段和其餘輸入小部件的可訪問性修復程序。您將在GitHub的該版本中看到有關可訪問性問題的完整列表。咱們鼓勵您測試本身的應用程序的可訪問性,而且還經過一些推薦的最佳實踐更新了此版本中的文檔。

工具:Dart DevTools移植到Flutter,Android快速入門等

此版本使咱們很是接近將Dart DevTools的當前版本換成新的Flutter版本。若是您想嘗試一下,請啓動DevTools並單擊DevTools右上角的「燒杯」圖標。

Devtools還有其它不少有趣的更新等待你的發掘。

1.17 Flutter Metal

The Flutter Engine will migrate to using the Metal Rendering API instead of OpenGL on iOS.

Why use Metal?

A Flutter user interface is displayed on screen by accessing the GPU on the platform using an accelerated graphics API. This API has been some version of OpenGL ES on iOS. OpenGL ES and associated APIs were formally deprecated by Apple in 2018 with the introduction of iOS 12. Metal is now the recommended API for low-level, low-overhead rendering on iOS and Mac. While the cross platform aspects of OpenGL were certainly useful, the Flutter team agrees with the case for Metal. The deprecation of OpenGL ES also appears to have resulted in a less well maintained OpenGL driver on iOS. There is an uptick in iOS specific OpenGL issues that are increasingly harder to debug and unlikely to be fixed. For these reasons, a migration to Metal on iOS is imperative.

Where will Flutter use Metal?

Metal will be used on Apple A7 devices or later running iOS 10 or above. When Metal cannot be used, OpenGL will be used instead.

Why can’t Flutter always use Metal on iOS?

Flutter currently supports running on iOS 8 and above. This includes devices on which Metal itself is not available. Specifically, Metal is only available on iOS devices with Apple A7 or later. This would exclude devices like the iPhone 5C that can be updated to iOS 10 but only have an Apple A6 SOC. A policy that mandates the use of Metal everywhere would mean we would have to leave some devices behind. That is not something we are prepared to consider now.

That still leaves a small number of devices that support iOS versions between 8 and 10 that have an Apple A7 SOC (or later) but have not updated to the latest iOS versions. Flutter could technically use Metal on these devices as well but currently doesn’t. This is because versions of the Metal API on earlier versions of iOS weren’t expressive enough for the features needed by Flutter (specifically the Skia rendering library used by Flutter). This requires authoring workarounds or fallbacks for cases like dual-source blending. To reduce the implementation and testing burden it was decided to pick iOS 10 as the baseline instead. This decision can be revised if necessary.

Does this change the minimum version of iOS supported by Flutter? No. Flutter will use Metal on newer devices and iOS versions but the OpenGL backend remains as-is and present. It will be used when Metal is unavailable.

As a Flutter Developer, is there anything I need to do to migrate to using Metal on iOS?

Except for the highly unlikely case that your application makes assumptions about Flutter using OpenGL under the hood, no. The updated Flutter Engine requires no changes to the Flutter application or how it is embedded.

Is there an impact to the binary size because of the addition of Metal support?

Yes. The size of the uncompressed Flutter Engine binary will increase by ~250KB. Incremental reductions to this size will continue to be made but a significant reduction requires the removal of the OpenGL backend. This is not something we have considered yet.

Will plugins for the camera preview, video playback, webview, maps, etc. keep working?

Yes. There are no updates necessary to these plugins and they will continue to work as expected. All plugins in the Flutter Plugins repo have also been tested to work with the Metal backend.

How can I tell if my application makes assumptions about Flutter using OpenGL under the hood?

The rendering API used by Flutter is an implementation detail of the Flutter Engine. However, Flutter does provide the ability for the underlying platform to provide textures for inline composition within a Flutter hierarchy. Developers (or plugins) do this by using a Texture widget in their applications and writing some platform specific code to provide and update these textures. If the platform specific code that operates on the textures provided to the Flutter Engine does not specify that the texture may interoperate with the Metal API, inline composition of these textures may fail. For guidance on ensuring your textures are interoperable with Metal, please follow the documentation on how to 「Create an Interoperable Texture」. Specifically, the kCVPixelBufferMetalCompatibilityKey must be specified in addition to the kCVPixelBufferOpenGLCompatibilityKey key when creating the pixel buffer describing the texture is given to Flutter.

If you application does not use the Texture widget, there is nothing to do. If it does, the texture provided to Flutter must be checked to see that they are interoperable with Metal.

This is a very unique use case and no plugins in the Flutter Plugins repo use this mechanism.

If my application uses OpenGL to provide textures for inline composition in a Flutter application, will this work with the Metal backend?

Yes. As mentioned earlier, as long as the textures provided to Flutter are interoperable with Metal, you may continue to use OpenGL to update the texture and Flutter will composite the same using Metal.

How can I tell at runtime if my Flutter application is using Metal to render instead of OpenGL?

The FlutterViewControllers view will have a class that is a CAMetalLayer. Flutter will always use either Metal or OpenGL. That is, in a process, there is no chance of some Flutter application instances using Metal and others OpenGL.

Will Flutter use Metal on iOS Simulators?

No. Not currently. Flutter will continue to use the software backend on iOS simulators as before. Flutter on simulators is something on the radar though.

相關文章
相關標籤/搜索