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 to a window with hardware acceleration enabled,//That is to say, it does not necessarily use hardware acceleration when drawing, getdrawingcacheMyview. ishardwareaccelerated ();//Method 2//Returns true. If the canvas enables hardware acceleration during painting//Try to use this method to determine whether hardware acceleration is enabledCanvas. 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.

This article is basically written according to the android developer documentation, specific details can refer to the http://developer.android.com/guide/topics/graphics/hardware-accel.html here

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.