Analysis of Android HWUI hardware acceleration Module

Source: Internet
Author: User

Analysis of Android HWUI hardware acceleration Module

 

What is hardware acceleration)

The UI rendering of traditional software relies on the CPU, and hardware acceleration is to hand over the rendering task to the GPU for execution. Compared with CPU, GPU is more suitable for time-consuming tasks such as raster and animation transformation. Compared with CPU, GPU can save more power and provide better user experience.

Why hardware acceleration (Why)

The underlying implementation of Android hardware acceleration is based on the OpenGL ES interface to submit commands to the GPU to complete the painting. Compared with the soft drawing implemented by the CPU, the frame rate of hardware acceleration is higher than that of the CPU, and the performance is higher. The larger the screen resolution (especially for HDTV), the more obvious the advantage of hardware acceleration.

Is the HWUI rendering execution process of Android 5.0:

The source code is in the android/platform/framework/base/libs/hwui directory. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: java;"> public class View implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource { ...... public void buildLayer() { ...... final AttachInfo attachInfo = mAttachInfo; ...... switch (mLayerType) { case LAYER_TYPE_HARDWARE: updateDisplayListIfDirty(); if (attachInfo.mHardwareRenderer != null && mRenderNode.isValid()) { attachInfo.mHardwareRenderer.buildLayer(mRenderNode); } break; case LAYER_TYPE_SOFTWARE: buildDrawingCache(true); break; } } ......}

When the LayerType of a View is set to HARDWARE, the View is bound to a FrameBufferObject of OpenGL ES. If you want to perform Animation (Alpha, Rotation, etc.) On this View .), this FrameBufferObject will be rendered to Texture (2D) and then animated rendering. This has a disadvantage that the memory consumption has increased.

How independent rendering threads

On Android 5, the appearance of ThreadedRenderer reduces the burden on the main thread and can respond to user operations more quickly.

Deferred Display List

DisplayList records the painting operations and States. The main thread submits them to the OpenGL Renderer and the Renderer executes the final DrawCall.

After Android 4.4, the HWUI module introduced the Deferred Display List, which was optimized based on the Display List, such as removing drawn areas and performing batch or merge operations on DrawCall, this improves the rendering performance to a certain extent.

Create a texture set

Expires + DQo8L2Jsb2NrcXVvdGU + expires/LzTuN/Qp7XEyc + 0q87GwO3K/b7d1sFHUFWho8/Cw + expires/expires "brush: java;">// Bind the Texture unit and PBOglBindTexture (GL_TEXTURE_2D, textureId); then (pixel, pboIds [index]); // copy the pixels of PBO to the texture to remove glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, 0); // prepare to upload the next texture glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, pboIds [nextIndex]); // If glMapBuffer is directly called here, it will cause a synchronization check of the OpenGL state machine (with high overhead), but it will not be used if BufferData is used. It can directly allocate data and return glBufferDataARB (GL_PIXEL_UNPACK_BUFFER_ARB, DATA_SIZE, 0, GL_STREAM_DRAW_ARB); // map GPU data to memory GLubyte * ptr = (GLubyte *) glMapBufferARB (latency, latency); if (ptr) {updatePixels (ptr, DATA_SIZE); // directly update the texture data glUnmapBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB); // release the ing buffer} glBindBufferARB (GL_PIXEL_UNPACK_BUFFER_ARB, 0 );

The use of ATLAS reduces the consumption of GPU video memory and the overhead of Resource Binding for Texture units.

Merge DrawCall

DepthTest is not enabled during Android hardware acceleration. All UI painting is displayed on the screen in the order of drawing. Due to the complexity of OpenGL ES driver implementation, each GL binding call and GL status switching are expensive. Therefore, Deferred Display List is introduced to merge DrawCall and batch related classes, such.

Font drawing

Text rendering is also a headache. The text rendering of the APP is not as simple as in the game. Generally, when the game is released, fixed text can be converted into a single texture in advance, you can map texture coordinates directly when rendering text. The Android underlying layer caches the font and texture data. Android uses Skia and a third-party open-source Library (FreeType) to raster fonts.

Hardware acceleration Improvement

Multiple GL Context is used for iOS UI rendering, and Metal Framework is introduced after iOS 8. Native supports multi-thread UI rendering, because of the differences between GL drivers and GPU manufacturers, Android cannot squeeze GPU functions well. However, after the popularity of the next generation of graphics APIs (Vulkan, thin drivers and multi-thread support, there is still much room for optimization, and UI fluency can be further improved.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.