How to detect if the system supports hardware acceleration?

5

I currently do this so that one of my activity which requires acceleration to work:

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

Otherwise the application hangs and crashes and in the log I get the following error:

  

04-23 05: 27: 36.570: E / chromium (902): [ERROR: gles2_cmd_decoder.cc (3389)] GLES2DecoderImpl :: ResizeOffscreenFrameBuffer failed to allocate storage for offscreen target depth buffer.

However, I would like to detect if there is support for hardware acceleration and activate it, this can be by manifest as by java. Is it possible?

    
asked by anonymous 08.11.2016 / 16:29

1 answer

5

Hardware acceleration is available with Android 3.0 (API level 11). As of Android 4.0 (API level 14) it is enabled by default.

Hardware acceleration can be controlled at the following levels:

  • Application
    In AndroidManifest.xml, indicating true or false to the android:hardwareAccelerated attribute, in the <application/> section:

    <application android:hardwareAccelerated="true" ...>
    
  • Activity
    In AndroidManifest.xml, indicating true or false to the android:hardwareAccelerated attribute, in the <activity/> section:

    <application android:hardwareAccelerated="true">
        <activity ... />
        <activity android:hardwareAccelerated="false" />
    </application>
    
  • Window
    Using% Window% method to enable hardware acceleration:

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

    At this level it is not possible to disable hardware acceleration.

  • View
    Using the% View method to disable hardware acceleration:

    myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    

    At this level it is not possible to enable hardware acceleration.

There are two ways to know if an application is hardware accelerated:

Note that before using the method you must be sure that View is associated with a Window , which is not the case for example onCreate ( ).

One place where you have this guarantee is onWindowFocusChanged () Activity.

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if(hasFocus){
        boolean isAccelerated = view.isHardwareAccelerated();
    }

}

For more detailed information see Hardware Acceleration in the documentation.

    
08.11.2016 / 17:10