Android hardware Accelerator and its issues summary GIF does not show

Source: Internet
Author: User


Find a screen on your phone, some control backgrounds are stretched too much to cover the other controls, it is difficult to see. The phenomenon of high probability, analysis of the next discovery: Once this phenomenon occurs, will inevitably print the following log,google, this log should be hardware acceleration caused. The problem does not appear again after the hardware acceleration switch is turned off from the view level.
[Plain] View plaincopyprint?

D/openglrenderer (10887): GL error from openglrenderer:0x501
E/openglrenderer (10887): Gl_invalid_value

The Hardware acceleration switch was introduced by android3.0, with a general impression, but the hardware acceleration switch was not turned on in our code. I wrote a demo,log to show that the hardware acceleration switch has indeed been turned on. It seems that Google has done something to look at the official documents, the following sentence:
Beginning with Android 4.0, hardware acceleration for all windows are enabled by default if your application have set either Targetsdkversion or Minsdkversion to "+" or higher.
Here, the reason why the hardware acceleration switch is turned on has been found, why this interface in this application will introduce the problem.
Learn some of the concepts of Android hardware acceleration first. Android has introduced hardware acceleration from 3.0, that is, drawing with the GPU, designed to get smoother animations smoother scrolling, and better overall performance and responsiveness to user interaction. However, hardware acceleration does not provide complete support for all drawings, usually in the form of invisible content, exceptions, or rendering errors. In general, you need to turn off the hardware acceleration switch. To facilitate the control of hardware acceleration switches, Android provides support at four levels:
1.Application level: Add the following configuration statement to the application tag in the Androidmanifes file to open the hardware acceleration switch, which works for the entire application.
[HTML] View Plaincopyprint?

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

2.Activity level: Also in the Androidmanifes file, add the following configuration statement to the activity tag, you can turn off the hardware acceleration switch, this switch is active in the current activity, you can override the application switch in 1:
[HTML] View Plaincopyprint?

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

3.Window: Add the following code to the code to open the hardware acceleration switch at the window level. Note at the window level, only the hardware acceleration switch cannot be turned off, unlike the above 1, 2.
[HTML] View Plaincopyprint?

GetWindow (). SetFlags (
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

4.View level: Turn off the hardware acceleration switch from the view hierarchy by setting the following properties in the code for view. Only the hardware acceleration switch can be turned off here and cannot be turned on. This level of discretion is the highest and can cover the above three levels.
[HTML] View Plaincopyprint?

Myview.setlayertype (view.layer_type_software, NULL);

It's still unclear why only the view of this interface has a problem. This view is not a rewrite of application overrides and is not complex. Take a look at some of the techniques behind Google's efficient use of hardware acceleration switches:
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 turned on the Android developer option to check whether the feature was over-drawn, it was found that the interface was obviously over-drawn. Here basically can be drawn, this interface due to open hardware accelerator high probability of the appearance of flower screen, should be violated the second: Avoid overdraw.
To see Google's Android Drawing models instructions, or not fundamentally understand how hardware acceleration is a matter. It's not always a good idea to see these from the code, but it's sufficient to understand that hardware acceleration is enough to solve the problems that are encountered during the development process.
Finally, in the analysis of the above-mentioned flower screen problem, it is found that the. 9 image is removed to a common resource, the problem will also be corrected.

Android hardware Accelerator and its issues summary GIF does not show

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.