Android 3.0 GPUI (hardware accelerated UI)

Android 並沒有 Windowing 的架構,Application 建立 Surface 後進行繪圖與顯示。Andorid 中繪圖有幾種方式:Canvas - 2D drawing context, Skia – 2D drawing API, OpenGL – 3D rendering API 以及 Android 2.2 之後開始支援的 OpenGL|ES 2.0 規格,開發者可使用 RenderScript (Language + API) 繪製3D圖型。

為確保 Application 能正常在各個 Android 平台上執行,Android 實作了軟體 OpenGL|ES API - libAGL.so。若裝置上並沒有 GPU 的話,則以軟體來處理 3D graphic;而若 Android 裝置有 GPU,則由 GPU 所提供的 libHGL_cyclone.so 把 3D 圖形轉交給 GPU 去運算,效能會好許多。

Application 可以使用 Canvas 透過 skia library 繪製、直接使用 OpenGL|ES 1.x fixed API 來繪製 3D graphic,或使用 OpenGL|ES 2.0 的 RenderScript,開發者得選用相對應的 Surface 去繪圖。

Android 3.0 重寫了常用的 2D UI compoment 繪製方式,特點是借用 GPU 對圖形處理能力來加快效能,稱為 UI on the GPU,簡稱 GPUI。GPUI 基本運作概念是將每個 2D UI component 轉換成兩個三角形的物件去貼圖,這部份的觀念跟先前 Android 處理 LayerBuffer 的作法一樣。而藉由GPU的處理,在shading、alpha blanding...等運算上,速度會比原本使用 Cavans + skia + pixelfligner 快許多。

對開發者而言,Android GPUI 提供多種不同層級 hardware acceleration 設定,可分別針對 Applicaion、Activity、Window、View 去設定是否使用 hardware acceleration。若程式中僅使用標準 drawable 元件例如list、button、path...等標準 2D UI component,程式開發員可以打開 Hardware acceleration 功能,以使用GPU 繪製。開發者也可以利用 View.isHardwareAccelerated() / Canvas.isHardwareAccelerated() 來得知所運行的平台是否支援 GPU 硬體加速,用以選擇所使用的 UI component,達最佳顯示效果。

在 Android 發展中,愈來愈多 application 使用 3D graphic 去做 UI 特效處理,而 Android 本身亦利用 GPU 的特性對於 2D UI component 做最佳化,GPU 在 Android 上扮演愈來愈重要的角色。

Android 3.0 Platform Highlights
http://developer.android.com/sdk/android-3.0-highlights.html
Android 3.0 Hardware Acceleration
http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html
Make android use the GPU (if available) for UI and browsing.
http://code.google.com/p/android/issues/detail?id=6914
The Care and Feeding of the Android GPU
http://www.satine.org/archives/2011/01/01/the-care-and-feeding-of-the-android-gpu/
Make Android use the GPU (if available) for UI and browsing
http://www.androidannoyances.com/post/10
Android 3.0 (Honeycomb): Introducing Hardware Accelerated 2D Graphics and Tips to Use it Properly
http://goo.gl/nWe40

Surface
Graphics in Android - an Introduction
Android Display System --- Surface Flinger
Android display架构分析

OpenGL ES | Hardware acceleration
Android OpenGL ES 分析与实践