Android hardware accelerator and Its problem summary

Source: Internet
Author: User

I found that a screen appeared on a certain page on my mobile phone. Some widgets were stretched too much to cover other widgets, which was ugly. This phenomenon has a high probability. After analysis, it is found that, once this phenomenon occurs, the following log will be printed. After Google, this log should be introduced by hardware acceleration. After the hardware acceleration switch is disabled at the view level, the problem does not occur again.

D/OpenGLRenderer(10887): GL error from OpenGLRenderer: 0x501E/OpenGLRenderer(10887): GL_INVALID_VALUE

The hardware accelerator switch was introduced at the beginning of android3.0. It was roughly impressive, but we didn't turn on the hardware accelerator switch in our code. I wrote a demo, and the log shows that the hardware accelerator switch has been turned on. What does Google do? Go to the official document and read the following sentence:
Beginning with Android 4.0, hardware acceleration for all windows is enabled by default if your application has set either targetsdkversion or minsdkversion to "14" or higher.
Here, the reason why the hardware accelerator switch is turned on is found. Why is the problem introduced on this application interface.
First, let's take a look at the concepts of Android hardware acceleration. Android 3.0 introduces hardware acceleration, that is, drawing with GPU, to achieve smoother animation and smoother scrolling, and better overall performance and response to user interaction. However, hardware acceleration does not fully support all plotting operations, usually because the content is invisible, abnormal, or rendering error. If a problem occurs, you need to disable the hardware acceleration switch. To facilitate the control of the hardware acceleration switch, Android provides support at four levels:
1. application level: Add the following configuration statement to the application tag in the androidmanifes file to enable the hardware acceleration switch. This switch applies to the entire application.

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

2. activity level: In the androidmanifes file, add the following configuration statement to the activity tag to disable the hardware acceleration switch. This switch takes effect for the current activity and can overwrite the Application Switch in Step 1:

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

3. Window Level: Add the following code to the Code to enable the hardware acceleration switch at the window level. Note: At the window level, you can only enable the hardware acceleration switch, but cannot disable it.

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

4. view level: You can set the following attributes for the view in the code to disable the hardware acceleration switch at the view level. You can only disable the hardware acceleration switch. This level of decision is the highest and can cover the above three levels.

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

It is unclear why only the view on this interface has a problem. This view is not overwritten by the application, and is not complex. I have read some tips on using the hardware accelerator after Google:
Reduce the number of views in your application
Avoid overdraw
Don't create render objects in draw Methods
Don't modify shapes too often
Don't modify bitmaps too often
Later, I opened the android developer option to check whether there was excessive painting, and found that this interface was obviously over-drawn. Here, we can basically conclude that this interface is in violation of the second avoid overdraw because of the high probability of opening the hardware accelerator. After reading Google's Android drawing models instructions, I still haven't figured out what hardware acceleration is like. I don't always feel clear about this from the code, but I know that hardware acceleration is enough to solve the problems encountered in the development process. When analyzing the above problem, I found that I had removed the. 9 image and changed it to a normal resource. This problem was also corrected.

Related Article

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.