Disable Hwui---hardware render

Source: Internet
Author: User
Tags skia

adb shell setprop debug.disable.hwacc 1



1 Overview

Android starting from 3.0 (API Level 11), supports hardware acceleration when drawing Views, making full use of the characteristics of the GPU to make drawing smoother.

In essence, before Android 3.0, almost all graphics drawing was done by Skia. Skia is a vector drawing library that uses the CPU to perform calculations. So starting from Android 3.0, Google replaced Skia with hwui. To be precise, It is recommended to replace it, because Opengl's support is not complete, and a small number of graphic APIs are still completed by Skia. The drawing of most views is implemented by the HGL UI module using openGL functions.


Because hardware acceleration itself is not perfect, Android provides options to turn hardware acceleration on or off, which is off by default. Generally we turn hardware acceleration on or off at two levels:


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

      Activity level: <activity android: hardwareAccelerated = "false" ...>

Below we understand how the system implements hardware acceleration from the code level. 2 Turn on hardware acceleration


Before starting the analysis, let's take a look at a basic flowchart in ViewRootImpl:

disable hwui --- hardware render

As shown in the figure above, in fact, process 2 is the process of turning on hardware acceleration. In the SetView function of ViewRootImpl, you enable hardware acceleration by calling the enableHardwareAcceleration function. Let us look at the code of enableHardwareAcceleration:


    

    

     

     

      

      

       

       [cpp]

       

       view plain

       

       copy

      

      

     

     

     

     

      

      private void enableHardwareAcceleration (WindowManager.LayoutParams attrs) {

      

              mAttachInfo.mHardwareAccelerated = false;

      

              mAttachInfo.mHardwareAccelerationRequested = false;

      

              final boolean hardwareAccelerated =

      

                      (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)! = 0;

      

              if (hardwareAccelerated) {

      

                  if (! HardwareRenderer.isAvailable ()) {

      

                      return;

      

                  }

      

                  // Persistent processes (including the system) should not do

      

                  // accelerated rendering on low-end devices. In that case,

      

                  // sRendererDisabled will be set. In addition, the system process

      

                  // itself should never do accelerated rendering. In that case, both

      

                  // sRendererDisabled and sSystemRendererDisabled are set. When

      

                  // sSystemRendererDisabled is set, PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED

      

                  // can be used by code on the system process to escape that and enable

      

                  // HW accelerated drawing. (This is basically for the lock screen.)

      

        

      

                  final boolean fakeHwAccelerated = (attrs.privateFlags &

      

                          WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED)! = 0;

      

                  final boolean forceHwAccelerated = (attrs.privateFlags &

      

                          WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED)! = 0;

      

        

      

                  if (! HardwareRenderer.sRendererDisabled || (HardwareRenderer.sSystemRendererDisabled

      

                          && forceHwAccelerated)) {

      

                      // Don't enable hardware acceleration when we're not on the main thread

      

                      if (! HardwareRenderer.sSystemRendererDisabled &&

      

                              Looper.getMainLooper ()! = Looper.myLooper ()) {

      

                          Log.w (HardwareRenderer.LOG_TAG, "Attempting to initialize hardware"

      

                                  + "acceleration outside of the main thread, aborting");

      

                          return;

      

                      }

      

        

      

                      if (mAttachInfo.mHardwareRenderer! = null) {

      

                          mAttachInfo.mHardwareRenderer.destroy (true);

      

                      }

      

        

      

                      final boolean translucent = attrs.format! = PixelFormat.OPAQUE;

      

                      mAttachInfo.mHardwareRenderer = HardwareRenderer.createGlRenderer (2, translucent);

      

                      if (mAttachInfo.mHardwareRenderer! = null) {

      

                          mAttachInfo.mHardwareRenderer.setName (attrs.getTitle (). toString ());

      

                          mAttachInfo.mHardwareAccelerated =

      

                                  mAttachInfo.mHardwareAccelerationRequested = true;

      

                      }

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.