Skip to content

Commit d5544ac

Browse files
ChrisCraikAndroid (Google) Code Review
authored andcommitted
Merge "Pause webkit painting when UI tile painting queue is full"
2 parents 37f6934 + 4390c6b commit d5544ac

File tree

3 files changed

+58
-26
lines changed

3 files changed

+58
-26
lines changed

core/java/android/webkit/WebView.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ public void clearView() {
26542654
checkThread();
26552655
mContentWidth = 0;
26562656
mContentHeight = 0;
2657-
setBaseLayer(0, null, false, false, false);
2657+
setBaseLayer(0, null, false, false);
26582658
mWebViewCore.sendMessage(EventHub.CLEAR_CONTENT);
26592659
}
26602660

@@ -4521,6 +4521,8 @@ protected void onDraw(Canvas canvas) {
45214521

45224522
if (canvas.isHardwareAccelerated()) {
45234523
mZoomManager.setHardwareAccelerated();
4524+
} else {
4525+
mWebViewCore.resumeWebKitDraw();
45244526
}
45254527

45264528
int saveCount = canvas.save();
@@ -4763,11 +4765,19 @@ private void offsetByLayerScrollPosition(Rect box) {
47634765
}
47644766

47654767
void setBaseLayer(int layer, Region invalRegion, boolean showVisualIndicator,
4766-
boolean isPictureAfterFirstLayout, boolean registerPageSwapCallback) {
4768+
boolean isPictureAfterFirstLayout) {
47674769
if (mNativeClass == 0)
47684770
return;
4769-
nativeSetBaseLayer(mNativeClass, layer, invalRegion, showVisualIndicator,
4770-
isPictureAfterFirstLayout, registerPageSwapCallback);
4771+
boolean queueFull;
4772+
queueFull = nativeSetBaseLayer(mNativeClass, layer, invalRegion,
4773+
showVisualIndicator, isPictureAfterFirstLayout);
4774+
4775+
if (layer == 0 || isPictureAfterFirstLayout) {
4776+
mWebViewCore.resumeWebKitDraw();
4777+
} else if (queueFull) {
4778+
mWebViewCore.pauseWebKitDraw();
4779+
}
4780+
47714781
if (mHTML5VideoViewProxy != null) {
47724782
mHTML5VideoViewProxy.setBaseLayer(layer);
47734783
}
@@ -9049,6 +9059,7 @@ private void setTouchHighlightRects(WebKitHitTest hit) {
90499059
/** @hide Called by JNI when pages are swapped (only occurs with hardware
90509060
* acceleration) */
90519061
protected void pageSwapCallback(boolean notifyAnimationStarted) {
9062+
mWebViewCore.resumeWebKitDraw();
90529063
if (inEditingMode()) {
90539064
didUpdateWebTextViewDimensions(ANYWHERE);
90549065
}
@@ -9071,13 +9082,9 @@ void setNewPicture(final WebViewCore.DrawData draw, boolean updateBaseLayer) {
90719082
boolean isPictureAfterFirstLayout = viewState != null;
90729083

90739084
if (updateBaseLayer) {
9074-
// Request a callback on pageSwap (to reposition the webtextview)
9075-
boolean registerPageSwapCallback =
9076-
!mZoomManager.isFixedLengthAnimationInProgress() && inEditingMode();
9077-
90789085
setBaseLayer(draw.mBaseLayer, draw.mInvalRegion,
90799086
getSettings().getShowVisualIndicator(),
9080-
isPictureAfterFirstLayout, registerPageSwapCallback);
9087+
isPictureAfterFirstLayout);
90819088
}
90829089
final Point viewSize = draw.mViewSize;
90839090
// We update the layout (i.e. request a layout from the
@@ -9755,11 +9762,6 @@ protected void contentInvalidateAll() {
97559762
}
97569763
}
97579764

9758-
/** @hide call pageSwapCallback upon next page swap */
9759-
protected void registerPageSwapCallback() {
9760-
nativeRegisterPageSwapCallback(mNativeClass);
9761-
}
9762-
97639765
/** @hide discard all textures from tiles */
97649766
protected void discardAllTextures() {
97659767
nativeDiscardAllTextures();
@@ -9922,10 +9924,9 @@ private native boolean nativeMoveCursor(int keyCode, int count,
99229924
private native void nativeSetFindIsEmpty();
99239925
private native void nativeSetFindIsUp(boolean isUp);
99249926
private native void nativeSetHeightCanMeasure(boolean measure);
9925-
private native void nativeSetBaseLayer(int nativeInstance,
9927+
private native boolean nativeSetBaseLayer(int nativeInstance,
99269928
int layer, Region invalRegion,
9927-
boolean showVisualIndicator, boolean isPictureAfterFirstLayout,
9928-
boolean registerPageSwapCallback);
9929+
boolean showVisualIndicator, boolean isPictureAfterFirstLayout);
99299930
private native int nativeGetBaseLayer();
99309931
private native void nativeShowCursorTimed();
99319932
private native void nativeReplaceBaseContent(int content);
@@ -9937,7 +9938,6 @@ private native void nativeSetSelectionPointer(int nativeInstance,
99379938
private native void nativeStopGL();
99389939
private native Rect nativeSubtractLayers(Rect content);
99399940
private native int nativeTextGeneration();
9940-
private native void nativeRegisterPageSwapCallback(int nativeInstance);
99419941
private native void nativeDiscardAllTextures();
99429942
private native void nativeTileProfilingStart();
99439943
private native float nativeTileProfilingStop();

core/java/android/webkit/WebViewCore.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,36 @@ private void webkitDrawLayers() {
21692169
.obtainMessage(WebView.INVAL_RECT_MSG_ID));
21702170
}
21712171

2172+
private Boolean m_skipDrawFlag = false;
2173+
private boolean m_drawWasSkipped = false;
2174+
2175+
void pauseWebKitDraw() {
2176+
synchronized (m_skipDrawFlag) {
2177+
if (!m_skipDrawFlag) {
2178+
m_skipDrawFlag = true;
2179+
}
2180+
}
2181+
}
2182+
2183+
void resumeWebKitDraw() {
2184+
synchronized (m_skipDrawFlag) {
2185+
if (m_skipDrawFlag && m_drawWasSkipped) {
2186+
// a draw was dropped, send a retry
2187+
m_drawWasSkipped = false;
2188+
mEventHub.sendMessage(Message.obtain(null, EventHub.WEBKIT_DRAW));
2189+
}
2190+
m_skipDrawFlag = false;
2191+
}
2192+
}
2193+
21722194
private void webkitDraw() {
2195+
synchronized (m_skipDrawFlag) {
2196+
if (m_skipDrawFlag) {
2197+
m_drawWasSkipped = true;
2198+
return;
2199+
}
2200+
}
2201+
21732202
mDrawIsScheduled = false;
21742203
DrawData draw = new DrawData();
21752204
if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw start");
@@ -2178,7 +2207,7 @@ private void webkitDraw() {
21782207
if (draw.mBaseLayer == 0) {
21792208
if (mWebView != null && !mWebView.isPaused()) {
21802209
if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw abort, resending draw message");
2181-
mEventHub.sendMessage(Message.obtain(null, EventHub.WEBKIT_DRAW));
2210+
mEventHub.sendMessageDelayed(Message.obtain(null, EventHub.WEBKIT_DRAW), 10);
21822211
} else {
21832212
if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw abort, webview paused");
21842213
}

tests/TileBenchmark/src/com/test/tilebenchmark/ProfiledWebView.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ public class ProfiledWebView extends WebView {
4040
private long mContentInvalMillis;
4141
private static final int LOAD_STALL_MILLIS = 2000; // nr of millis after load,
4242
// before test is forced
43-
private double mLoadTime;
44-
private double mAnimationTime;
43+
44+
// ignore anim end events until this many millis after load
45+
private static final long ANIM_SAFETY_THRESHOLD = 200;
46+
private long mLoadTime;
47+
private long mAnimationTime;
4548

4649
public ProfiledWebView(Context context) {
4750
super(context);
@@ -131,7 +134,6 @@ public void onFinish() {
131134
// invalidate all content, and kick off redraw
132135
Log.d("ProfiledWebView",
133136
"kicking off test with callback registration, and tile discard...");
134-
registerPageSwapCallback();
135137
discardAllTextures();
136138
invalidate();
137139
mIsScrolling = true;
@@ -150,10 +152,11 @@ public void onFinish() {
150152
*/
151153
@Override
152154
protected void pageSwapCallback(boolean startAnim) {
155+
super.pageSwapCallback(startAnim);
156+
153157
if (!mIsTesting && mIsScrolling) {
154158
// kick off testing
155159
mContentInvalMillis = System.currentTimeMillis() - mContentInvalMillis;
156-
super.pageSwapCallback(startAnim);
157160
Log.d("ProfiledWebView", "REDRAW TOOK " + mContentInvalMillis + "millis");
158161
mIsTesting = true;
159162
invalidate(); // ensure a redraw so that auto-scrolling can occur
@@ -166,14 +169,14 @@ private double animFramerate() {
166169
String updatesString = settings.getProperty("tree_updates");
167170
int updates = (updatesString == null) ? -1 : Integer.parseInt(updatesString);
168171

169-
double animationTime;
170-
if (mAnimationTime == 0) {
172+
long animationTime;
173+
if (mAnimationTime == 0 || mAnimationTime - mLoadTime < ANIM_SAFETY_THRESHOLD) {
171174
animationTime = System.currentTimeMillis() - mLoadTime;
172175
} else {
173176
animationTime = mAnimationTime - mLoadTime;
174177
}
175178

176-
return updates * 1000 / animationTime;
179+
return updates * 1000.0 / animationTime;
177180
}
178181

179182
public void setDoubleBuffering(boolean useDoubleBuffering) {

0 commit comments

Comments
 (0)