Android hardware acceleration

Source: Internet
Author: User

Android 3.0 (API level 11) and supports hardware acceleration when drawing a view. It makes full use of GPU features to make the painting smoother, but consumes more memory.

Enable or disable hardware acceleration:

Because hardware acceleration is not perfect, Android provides options to enable or disable hardware acceleration, which is disabled by default. You can enable or disable hardware acceleration at four levels:

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

Activity Level: <activity Android: hardwareaccelerated = "false"...>

Window Level:

    getWindow().setFlags( WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

Note: currently, Android does not support disabling hardware acceleration at the window level.

View level:

myView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

Note: currently, Android does not support enabling hardware acceleration at the view level.

Checks whether hardware acceleration is enabled.:

// Method 1 // This method returns true. If myview is mounted under a window with hardware acceleration enabled, // that is, it does not necessarily use hardware acceleration during painting, getdrawingcachemyview. ishardwareaccelerated (); // method 2 // return true. If the canvas enables hardware acceleration during painting, try to use this method to determine whether the hardware acceleration canvas is enabled. ishardwareaccelerated ();

Understand 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

Restrictions on hardware acceleration:

Currently, Android does not provide perfect support for hardware acceleration. Some rendering operations cannot work properly when hardware acceleration is enabled (for a specific list, refer to the android developer documentation ).

However, android can ensure that built-in components and Applications Support Hardware acceleration. Therefore, if only standard UI components are used in the application, you can enable hardware acceleration with confidence.

With the upgrade of Android, we believe that after a while, hardware acceleration will be perfectly supported.

Abnormal responses after hardware acceleration is Enabled:

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: The operation that does not support hardware acceleration may be used. Disable or bypass this operation.

4. Throw an exception: the operation that does not support hardware acceleration may be used. Disable or bypass this operation.

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.