"Android Official document Reading notes" hardware acceleration

Source: Internet
Author: User

to make the app run more smoothly on Android, starting with 3.0 ,theandroid 2D drawing process is designed to better support hardware acceleration. The so-called hardware acceleration is the use of the GPU to draw on the View, but the rendering speed is faster, the application experience smoother.

1. How to start hardware acceleration

    The easiest way to enable hardware acceleration is to turn on hardware-accelerated global settings for the entire system, but hardware acceleration does not support all 2d So turning on hardware acceleration can have an impact on applications that use custom components, Problems often manifest in invisible element anomalies and incorrect pixel rendering. In order to solve this problem android You can choose to start or disable hardware acceleration at the following levels:   APPLICATION  ACTIVITY  WINDOW  VIEW 

application level: in android manifest < span> <APPLICATION/>&NBSP; Adding attributes in the method android:hardwareaccelerated=" true "&NBSP;

Activity Level: In the Android Manifest file, find the specific Activity <activity/> the android:hardwareaccelerated= method adds a property of "true" .

Window Level: Implemented by code, as follows. At the Window level, you can only turn on hardware acceleration cannot be disabled.

GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

View Level: Implemented by code, as follows. At the View level, only disable hardware acceleration cannot be turned on.

Myview.setlayertype (View.layer_type_software, null).

2,android Drawing Model

After Android 4.0 , two kinds of drawing models are provided, one is software-based drawing model and the other is a hardware-based drawing model. After hardware acceleration is turned on, a hardware-based drawing model is used.

Software-based drawing model: When a view 's invalidate is called, the system will immediately redraw the view hierarchy The View in which the update area intersects .

Hardware-based drawing model: When a View 's invalidate is called, the system does not draw it immediately, but instead records it in the display list and only updates the call when it is drawn. Invalidate of the View , and the others appear just like the previous display list.

layers of 3,android View and their classification

All Android versions are capable of rendering off-screen buffers, or using the View 's draw buffer, or using canvas.savelayer () function. starting with Android 3.0 , you have more control over when and how layers can be used through the view.setlayertype () method. One View can use one of the following three layer types:

Layer_type_none: This View will be rendered in a normal manner, but will not return an off-screen buffer, which is the default behavior.

Layer_type_hardware: If the application is hardware-accelerated, the View will be rendered as a hardware texture in the hardware, and if the application is not accelerated by hardware, its effect and LAYER _type_software are the same.

Layer_type_software: This View is rendered as a bitmap by software .

4, the advantages of hardware acceleration and problems

For Android -enabled applications, turning on hardware acceleration offers the following benefits:

(1) Faster rendering speed, a hardware-based drawing model allows applications to do less redrawing when updating the View.

(2) Smoother operation experience, sliding screen action, animation will be smoother. When animating a complex View , it is not always possible to reach frames per second because there is a lot of painting to do . In this case, the hardware layer can be rendered as a hardware texture to improve performance. A hardware texture operation can be used to animate a view , which reduces the frequent redrawing of the view itself when animating.

(3) Better support for video.

But turning on hardware acceleration also poses some problems:

(1) use more memory.

(2) firmware support is not unified,3.0 above the firmware is supported, and subsequent versions support the same standards.

(3) Some specific rendering is not supported.

"Android Official document Reading notes" hardware acceleration

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.