问题
I've been experimenting with using a canvas inside of WebView to capture a small drawing. Testing on Chrome or on a very simple test page, the canvas performs OK. By this I mean that if I drag my finger across a 500-pixel-wide canvas, I see 60-100 touchMove events.
This canvas-based utility is implemented as a jQuery plugin. When I utilize the plugin within my larger web application, there are only about 20 or so events captured by the canvas when I perform the same finger drag across a 500-pixel-wide canvas.
I had a number of ideas about what might be causing degradation in my application vs. a simple test page, but nothing has panned out so far. Memory and CPU usage on the Xoom test device seem fine.
Here are some symptoms, but they have not yet led to a conclusive solution:
04-12 10:47:58.037: WARN/webview(13316): Miss a drag as we are waiting for WebCore's response for touch down.
I see messages like this on the simple test page scenario and when using the plugin inside the larger web app. These messages require more vigorous drawing to reproduce in the simple test page. Just do a rapid sketching motion across the canvas inside of WebView and you will probably see it, at least on similar hardware to the Xoom 1. There are also occasionally messages about a stale touchMove event, though they are much less common
Some additional details that may or may not contribute to the problem or solution:
settings.setRenderPriority(WebSettings.RenderPriority.HIGH); //applying high render priority is in place
The application is an offline app, so we must have caching enabled. There is 10-20K of JavaScript, excluding libraries, in the app, though I have no reason to suspect this would slow down the delivery of touchMove events to the canvas inside of a WebView.
I've seen posts by others that have given up on the canvas inside of a WebView, though they were working on more intensive applications than this simple drawing app. Clearly, I need more events more quickly or all my curved lines look like straight lines.
Does anyone know about the exact causes of touchMove event degradation or it is time to simply abandon the canvas inside of an Android WebView for now?
来源:https://stackoverflow.com/questions/10127900/how-can-i-prevent-performance-degradation-for-canvas-inside-of-webview-on-an-and