Android Force Gpu Rendering How to Enable and Disable

Find out if Force GPU-Rendering is enabled

Find a View that you know shouldn't be accelerated, which should be any View if you add

android:hardwareAccelerated="false"

to your <application> in Android Manifest, then in your code, call

view.isHardwareAccelerated();

If it returns true, the option is set as on. This has been confirmed to work on my Galaxy Nexus.

Turn on Force Gpu Rendering programmatically

Add android:hardwareAccelerated="true" to the application tag of your manifest. It will be ignored by pre Honeycomb devices. Make sure your target sdk is honeycomb or later.

You will need to check that you are not using apis that are for a higher level, but it is not a massive problem. You can get around it with reflection for more complicated tasks or simply by using an if statement, like:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
}

There is some more details about this here

Android: Application being forced to use hardware acceleration?

Disable it for the views using those operations with the 'View Level' option in the dev guide - I expect that other options will be foiled by how the setting is forced on your app.

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Failing that, the link describes how you can detect hardware acceleration, to complain about it.

View.isHardwareAccelerated() returns true if the View is attached to a hardware accelerated window.

Canvas.isHardwareAccelerated() returns true if the Canvas is hardware accelerated

Enable hardware acceleration in Android app, targeting Honeycomb AND prior versions

Try to set build target to the 3.0 version, but set minsdkversion to the oldest version you want to support. It should at least allow you to build, but will not enable HW-acceleration on the older versions.

From the documentation:

Starting from Android 3.0, a hardware-accelerated OpenGL renderer is available to applications, to improve performance for many common 2D graphics operations. When the hardware-accelerated renderer is enabled, most operations in Canvas, Paint, Xfermode, ColorFilter, Shader, and Camera are accelerated. This results in smoother animations, smoother scrolling, and improved responsiveness overall, even for applications that do not explicitly make use the framework's OpenGL libraries.

Have not tested the 3.0 API yet myself, but the documentation seems to say this should be supported...

<manifest ... >
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="11" />
<application ... >
...
<application>
</manifest>

(cut from Optimizing Apps for Android 3.0

Setting android:hardwareAccelerated=true in activity or in application

Hardware acceleration is enabled by default so you don't have to set it unless you need to disable it. As said in the documentation:

Hardware acceleration is enabled by default if your Target API level is >=14, but can also be explicitly enabled.

To answer your question. Setting it on Application tag affects your whole application and setting it on Activity tag affects that activity.

Application level

In your Android manifest file, add the following attribute to the tag to enable hardware acceleration for your entire application:

<application android:hardwareAccelerated="true" ...>

Activity level

If your application does not behave properly with hardware acceleration turned on globally, you can control it for individual activities as well. To enable or disable hardware acceleration at the activity level, you can use the android:hardwareAccelerated attribute for the element. The following example enables hardware acceleration for the entire application but disables it for one activity:

<application android:hardwareAccelerated="true">
<activity ... />
<activity android:hardwareAccelerated="false" />
</application>

How to show/hide Profile GPU rendering as bars using adb command?

The Profile GPU Rendering checkbox in the Developer Options controls value of the debug.hwui.profile system property:

/**
* System property used to enable or disable hardware rendering profiling.
* The default value of this property is assumed to be false.
*
* When profiling is enabled, the adb shell dumpsys gfxinfo command will
* output extra information about the time taken to execute by the last
* frames.
*
* Possible values:
* "true", to enable profiling
* "visual_bars", to enable profiling and visualize the results on screen
* "false", to disable profiling
*
* @see #PROFILE_PROPERTY_VISUALIZE_BARS
*
* @hide
*/
public static final String PROFILE_PROPERTY = "debug.hwui.profile";

So you can use setprop debug.hwui.profile visual_bars command to enable profiling and setprop debug.hwui.profile false to disable it.



Related Topics



Leave a reply



Submit