Android layer type, webview white screen, and webview are not animated.

Source: Internet
Author: User

Let's talk about these three layers first.

Layer_type_software
No matter whether the hardware acceleration is enabled or not, there will be a bitmap (software layer) and soft rendering will be performed on the webview.
Benefits:
When performing an animation, you can use software to draw a view tree only once, saving a lot of effort.
When not to use:
Do not use the view tree when it is updated frequently. Especially when hardware acceleration is enabled, each update consumes more time. Because after rendering this bitmap, you still need to render this bitmap to the hardware layer.

Layer_type_hardware
When hardware acceleration is disabled, the function is the same as that of software.
When the hardware is accelerated, it will be rendered on the FBO (framebuffer object). During the animation, the view tree only needs to be painted once.

Differences:
1. One is rendered to bitmap, and the other is rendered to FB.
2. Some operations may not be supported by hardware.
The two are the same:
A buffer is enabled to draw the view to the buffer.

Layer_type_none
This is relatively simple. Do not create a separate layer for this view tree.

PS: the default layertype of glsurfaceview and webview is none.

Glsurfaceview:
After glsurfaceview is set to software or hardware, nothing can be drawn. Conclusion: The layer type of glsurfaceview can only be none.

Webview:
I encountered a problem when using webview before. If you use animation on webview, the painting area of webview will not change. At that time, the solution was to take a screenshot (drawingcache) of the webview before the animation ). I tried it based on the above principles and set a hardware or software layer to OK.

Now we have another problem. After hardware acceleration is enabled, some machines (3.2 for me) webview sometimes have a white screen problem in a certain area. The default layer type is none, and cannot be changed to hardware. If it is set to software, the problem is solved. Of course, it is better to disable hardware acceleration, but the program will be slow as a whole. Therefore, the final solution is the overall hardware acceleration, and the problematic webview sets the software.

Supplemented by 2012.4.21:

This can make 3D rendering faster: getholder (). settype (surfaceholder. surface_type_hardware );

Supplement:

Let's talk about the problem first:
When hardware acceleration is enabled, once glsurfaceview is removed from the view tree, the background of the entire window turns black, even if the layer type is set to software.
After two days of troubleshooting, I found the cause. On the C layer, my program is driven by drawframe (which belongs to the glthread thread) for painting. When glsurfaceview is taken off, the destroy method of glsurfaceview is called. I directly call the end METHOD OF THE glthread thread in the destroy method (which belongs to the UI thread. While glsurfaceview. creat, sizechanged, destroyed are in the UI thread, render. Create, sizechanged, and drawframe are in the glthread thread. Therefore, there is a problem where the UI thread calls the glthread method directly. Finally, the glsurfaceview. queueevent is used to send runnable to the glthread thread. The problem is solved.
It seems that the fault tolerance capability of soft rendering is strong, and the underlying layer is weak when hardware acceleration is enabled.
Conclusion: You must know which is the UI thread and which is the glthread thread.

Add several knowledge points found during the search process:
Hardware acclerator accelerates the entire window. When hardware acceleration is enabled, view. ishardwareacclerator returns true. However, each view may be rendered to a different canvas. For example, the view may be set to a layer through setlayer. In this case, canvas. ishardwareaccelerator returns false.
Android provides three control levels for whether hardware acceleration is Enabled: application, activity, window, and view. For more information, see Dev guide.

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.