Android Hardware acceleration

Source: Internet
Author: User

Android starts with 3.0 (API level 11), supports hardware acceleration when drawing view, takes advantage of GPU features, makes drawing smoother, but consumes more memory.

To turn hardware acceleration on or off:

Because hardware acceleration itself is not perfect, Android offers the option to turn hardware acceleration on or off, which is turned off by default. Hardware acceleration can be turned on or off at 4 levels:

Application level: <applicationandroid:hardwareaccelerated= "true" ...>

Activity level: <activity android:hardwareaccelerated= "false" ...>

Window level:

[Java]View Plaincopy print?
    1. GetWindow (). SetFlags (Windowmanager.layoutparams.flag_hardware_accelerated,windowmanager.layoutparams.flag_ hardware_accelerated);

Note: Android is not yet supported to turn off hardware acceleration at the window level until now.

View level:

[Java]View Plaincopy print?
    1. Myview.setlayertype (View.layer_type_hardware, null);

Note: Android also does not support hardware acceleration at the view level so far.

To detect whether hardware acceleration is currently enabled :

[Java]View Plaincopy print?
    1. //  method one   
    2. //  this method returns True if MyView hangs under a window with hardware acceleration turned on,   
    3. //  that is, it does not necessarily use hardware acceleration when drawing, getdrawingcache  
    4. myview.ishardwareaccelerated ();   
    5.                            
    6. //  method two   
    7. //  returns true if Canvas is drawing with hardware acceleration enabled   
    8. //  try to use this method to determine whether hardware acceleration    is turned on;
    9. Canvas.ishardwareaccelerated ();   
Method One//This method returns True if MyView hangs under a window with hardware acceleration enabled,//That is, it does not necessarily use hardware acceleration when drawing. Getdrawingcachemyview.ishardwareaccelerated ();                        Method Two//returns TRUE if the canvas is drawing with hardware acceleration enabled//Try to use this method to determine if hardware acceleration canvas.ishardwareaccelerated () is turned on;

Understanding the drawing model of the View:

1. No hardware acceleration: Invalidate the View hierarchy------> Draw the View hierarchy

2. Hardware acceleration: Invalidate the View hierarchy------> record and update the display list------> draw the Display list

Limitations of hardware acceleration:

Currently, Android support for hardware acceleration is not perfect, and some drawing operations do not work properly when hardware acceleration is turned on (the list can refer to the Android Developer documentation).

However, Android can guarantee that the built-in components and applications support hardware acceleration. Therefore, if you use only standard UI components in your app, you can safely turn on hardware acceleration.

With the Android version upgraded, it is believed that after a while, hardware acceleration can be perfectly supported.

abnormal response after hardware acceleration is turned on:

1. Some UI elements are not displayed: Invalidate may not be called

2. Some UI elements are not updated: Invalidate may not be called

3. Incorrect drawing: You may be using an operation that does not support hardware acceleration, need to turn off hardware acceleration, or bypass the operation

4. Throw an exception: You may be using an operation that does not support hardware acceleration, need to turn off hardware acceleration, or bypass the operation

Android Hardware acceleration

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.