Android Control Hard Acceleration hardwareaccelerated

Source: Internet
Author: User

Starting with Android3.0 (API Level11), Android's 2D display pipeline has been designed to support hard acceleration. Hard acceleration uses the GPU to take on all the drawing operations performed on the view's canvas.

The simplest way to enable hard acceleration is to enable hardware speed for the entire application. If your app uses only standard view and drawable, global enable hard acceleration will have no negative impact. However, because hard acceleration is not supported by all 2D drawing, enabling it can have an impact on your custom drawing. The problems that arise are often not visible, may be anomalies, or incorrectly display pixels. To avoid these problems, Android provides the ability to enable or disable hard acceleration at the following levels:

Applicationactivitywindowview

If your app uses custom drawing, you'll need to enable hard acceleration on your real device to test for problems. The "Unsupported Drawing Operations" section describes the known drawing operations that cannot be hard-accelerated and how to circumvent them.

Control hard Acceleration

You can control the hard acceleration separately at the following levels:

Applicationactivitywindowview

Application class

In your manifest file, add the following attributes to the <application> tab to enable hard acceleration for your entire app:

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

Activity level
If your app behaves incorrectly when you enable hard acceleration globally, you can enable hard acceleration individually for individual activities. To enable or disable hard acceleration at the actvity level, you can use the Android:hardwareaccelerated property on the <activity> element. The following example enables hard acceleration throughout the application but disables hard acceleration for an activity:

<applicationandroid:hardwareaccelerated="true"><activity .../>< activityandroid:hardwareaccelerated="false" /></application>

Window level
If you need higher granularity control, you can use the following code to enable hard acceleration for a window:

GetWindow (). SetFlags (Windowmanager.layoutparams.flag_hardware_accelerated,windowmanager.layoutparams.flag_ hardware_accelerated);

Note: You cannot disable hard acceleration at the window level at this time.

Viewlevel

You can suppress the hard acceleration of individual view at run time using the following code:

Myview.setlayertype (View.layer_type_software,null);

Note: You cannot enable hard acceleration at the view level at this moment. The view layer has features other than prohibit hard acceleration.

Determine if a view can be hard-accelerated

Sometimes an app is useful to know if hardware speed is enabled, especially for things like custom view. This is even more important when your application does some custom drawing that is not supported by the latest pipeline.

There are two ways to check whether an app is hard-accelerated:

View.ishardwareaccelerated (): Returns True if view is attached to a hard-accelerated window.

Canvas.ishardwareaccelerated (): Returns True if the canvas is hard-accelerated.

If you have to do this in your drawing code, you should use canvas.ishardwareaccelerated () instead of view.ishardwareaccelerated (). When a view is attached to a hard acceleration window, it can still draw using a non-hardware-speed canvas. For example, when a view is drawn to a bitmap in order to cache it.

Android Control Hard Acceleration hardwareaccelerated

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.