Skip to content

Commit 5f1c549

Browse files
committed
Pause drawing when not visible
Bug: 5594608 If onPause is called or if the view or view's window is no longer visible, pause webview drawing. Calls to onDraw will continue to work, but animations and other continual drawing will stop Change-Id: I11640f087852d1a9a33b945ff72297fab1d25b94
1 parent 36a7f2a commit 5f1c549

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

core/java/android/webkit/WebView.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3254,6 +3254,26 @@ public void onPause() {
32543254
if (mHTML5VideoViewProxy != null) {
32553255
mHTML5VideoViewProxy.pauseAndDispatch();
32563256
}
3257+
if (mNativeClass != 0) {
3258+
nativeSetPauseDrawing(mNativeClass, true);
3259+
}
3260+
}
3261+
}
3262+
3263+
@Override
3264+
protected void onWindowVisibilityChanged(int visibility) {
3265+
super.onWindowVisibilityChanged(visibility);
3266+
updateDrawingState();
3267+
}
3268+
3269+
void updateDrawingState() {
3270+
if (mNativeClass == 0 || mIsPaused) return;
3271+
if (getWindowVisibility() != VISIBLE) {
3272+
nativeSetPauseDrawing(mNativeClass, true);
3273+
} else if (getVisibility() != VISIBLE) {
3274+
nativeSetPauseDrawing(mNativeClass, true);
3275+
} else {
3276+
nativeSetPauseDrawing(mNativeClass, false);
32573277
}
32583278
}
32593279

@@ -3265,6 +3285,9 @@ public void onResume() {
32653285
if (mIsPaused) {
32663286
mIsPaused = false;
32673287
mWebViewCore.sendMessage(EventHub.ON_RESUME);
3288+
if (mNativeClass != 0) {
3289+
nativeSetPauseDrawing(mNativeClass, false);
3290+
}
32683291
}
32693292
}
32703293

@@ -5599,6 +5622,7 @@ protected void onVisibilityChanged(View changedView, int visibility) {
55995622
if (visibility != View.VISIBLE && mZoomManager != null) {
56005623
mZoomManager.dismissZoomPicker();
56015624
}
5625+
updateDrawingState();
56025626
}
56035627

56045628
/**
@@ -8403,6 +8427,9 @@ public void handleMessage(Message msg) {
84038427
setNewPicture(mDelaySetPicture, true);
84048428
mDelaySetPicture = null;
84058429
}
8430+
if (mIsPaused) {
8431+
nativeSetPauseDrawing(mNativeClass, true);
8432+
}
84068433
break;
84078434
case UPDATE_TEXTFIELD_TEXT_MSG_ID:
84088435
// Make sure that the textfield is currently focused
@@ -9584,4 +9611,5 @@ private native int nativeScrollableLayer(int x, int y, Rect scrollRect,
95849611
* See {@link ComponentCallbacks2} for the trim levels and descriptions
95859612
*/
95869613
private static native void nativeOnTrimMemory(int level);
9614+
private static native void nativeSetPauseDrawing(int instance, boolean pause);
95879615
}

0 commit comments

Comments
 (0)