Android Graphic System details 5: Android rendering Mode

Source: Internet
Author: User

When Hard acceleration is enabled, the android framework uses a new draw mode to display your application to the screen. This mode uses a display list. to fully understand the display list and how it affects your application, you must first understand how Android draws a view with non-Hard acceleration. the following sections describe the soft acceleration and Hard acceleration models.

Software drawing mode

 

In the software drawing mode, view is drawn in the following two steps:

  • 1. Make the entire view level invalid

  • 2. Draw all view levels

When an application needs to update part of the UI at any time, it should call invalidate () (or any of its variants) on any view that changes the content ), messages that make the interface invalid are propagated throughout the view level to calculate the screen area (Dirty Area) to be drawn ). the Android system then draws all views at the view level that have an intersection with the dirty area. unfortunately, this rendering mode has two disadvantages:

  • First, this mode needs to execute a lot of code in each painting path. for example, if your app calls invalidate () on a button and the button is located on another view, the android system will draw the view even if the view does not change.

  • The second problem is that this rendering mode may hide bugs in your application. because the Android system will draw views that have an intersection with dirty areas, a view that you changed the content may be re-painted when invalidate () is not called. when this happens, you can only rely on the view that needs to be re-painted to obtain the correct behavior. however, this behavior may change every time you modify your application. therefore, you should always call invalidate () on your custom view when you modify the data or status that affects code rendering ().

Note: androidview automatically calls invalidate () when their attributes are changed, for example, when the background and text of A textview are changed.

Hard acceleration Mode

 

The Android system still uses invalidate () and draw () to request screen updates and draw views, but the actual rendering process is different. now, the draw command is not executed immediately after receiving the draw command, but recorded in the display list by the Android system, which contains the output of the view-level draw code. another optimization is that the Android system only needs to display view records and update lists marked as dirty by invalidate. views without invalidated can be simply re-painted using records in the previous display list. the new draw mode has three phases:

  • 1. Make the entire view level invalid

  • 2. record and update the display list

  • 3. Draw a list

In this mode, you can no longer call the draw () method by making the view interface with the dirty area. to ensure that the Android system records the view display list, you must call invalidate (). if you forget to do this, a view will always look like it, even if it is changed. however, this is a bug that can be easily identified.

Using the display list also improves the animation performance because an attribute, such as Alpha or rotation, is set and the invalidating target view is no longer required (automatically implemented ). this optimization will also be applied to the view with a display list (any view when your application is hard-accelerated ). for example, if a linearlayout contains a listview and a button, the listview is located on top of the button, and the display list of linearlayout looks as follows:

  • Drawdisplaylist (listview)

  • Drawdisplaylist (button)

Assume that you want to change the opacity of listview. After calling setalpha (0.5f) of listview, the displayed list contains the following items:

  • Savelayeralpha (0.5)

  • Drawdisplaylist (listview)

  • Restore

  • Drawdisplaylist (button)

The complex rendering process of listview is not executed, but only the display list of simple linearlayout is updated. in an unaccelerated application, the list and its dirty code will be re-executed.

Unsupported painting operations

 

When Hard acceleration is enabled, the 2D rendering pipeline supports common canvas painting operations and uncommon operations. all painting operations are used to present widgets, layouts, and general high-level visual effects, such as reflection and Paster textures. the following list describes known plotting operations that cannot be supported by Hard acceleration:

  • Canvas

    • Clippath ()

    • Clipregion ()

    • Drawpicture ()

    • Drawpostext ()

    • Drawtextonpath ()

    • Drawvertices ()

  • Paint

    • Setlineartext ()

    • Setmaskfilter ()

    • Setrasterizer ()

In addition, some operations may become different after hard acceleration is Enabled:

  • Canvas

    • Cliprect (): exclusive or, difference and reverse differential shear are ignored. 3D transformation should not be used in the cut box.

    • Drawbitmapmesh (): The color array is ignored.

    • Drawlines (): anti-sawtooth is not supported

    • Setdrawfilter (): can be set, but ignored

  • Paint

    • Setdither (): ignored

    • Setfilterbitmap (): Filter enabled all the time

    • Setshadowlayer (): only applies to text

  • Composeshader

    • Composeshader can only contain different types of pasters (for example, one bitmapshader and one lineargradient, but not two bitmapshader)

    • Composeshader cannot contain composeshader

If your application is affected by these missing features or restrictions, you can call setlayertype (view. layer_type_software, null) disables Hard acceleration for the affected part. with this method, you can still enjoy hard acceleration elsewhere.

Related Article

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.