Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4390c6b4 authored by Chris Craik's avatar Chris Craik
Browse files

Pause webkit painting when UI tile painting queue is full

Change-Id: I8836d7951f8f02d7f966dc22d807ea785ac9e637
parent 6baed6c1
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -2613,7 +2613,7 @@ public class WebView extends AbsoluteLayout
        checkThread();
        mContentWidth = 0;
        mContentHeight = 0;
        setBaseLayer(0, null, false, false, false);
        setBaseLayer(0, null, false, false);
        mWebViewCore.sendMessage(EventHub.CLEAR_CONTENT);
    }

@@ -4480,6 +4480,8 @@ public class WebView extends AbsoluteLayout

        if (canvas.isHardwareAccelerated()) {
            mZoomManager.setHardwareAccelerated();
        } else {
            mWebViewCore.resumeWebKitDraw();
        }

        int saveCount = canvas.save();
@@ -4722,11 +4724,19 @@ public class WebView extends AbsoluteLayout
    }

    void setBaseLayer(int layer, Region invalRegion, boolean showVisualIndicator,
            boolean isPictureAfterFirstLayout, boolean registerPageSwapCallback) {
            boolean isPictureAfterFirstLayout) {
        if (mNativeClass == 0)
            return;
        nativeSetBaseLayer(mNativeClass, layer, invalRegion, showVisualIndicator,
                isPictureAfterFirstLayout, registerPageSwapCallback);
        boolean queueFull;
        queueFull = nativeSetBaseLayer(mNativeClass, layer, invalRegion,
                                       showVisualIndicator, isPictureAfterFirstLayout);

        if (layer == 0 || isPictureAfterFirstLayout) {
            mWebViewCore.resumeWebKitDraw();
        } else if (queueFull) {
            mWebViewCore.pauseWebKitDraw();
        }

        if (mHTML5VideoViewProxy != null) {
            mHTML5VideoViewProxy.setBaseLayer(layer);
        }
@@ -9009,6 +9019,7 @@ public class WebView extends AbsoluteLayout
    /** @hide Called by JNI when pages are swapped (only occurs with hardware
     * acceleration) */
    protected void pageSwapCallback(boolean notifyAnimationStarted) {
        mWebViewCore.resumeWebKitDraw();
        if (inEditingMode()) {
            didUpdateWebTextViewDimensions(ANYWHERE);
        }
@@ -9031,13 +9042,9 @@ public class WebView extends AbsoluteLayout
        boolean isPictureAfterFirstLayout = viewState != null;

        if (updateBaseLayer) {
            // Request a callback on pageSwap (to reposition the webtextview)
            boolean registerPageSwapCallback =
                !mZoomManager.isFixedLengthAnimationInProgress() && inEditingMode();

            setBaseLayer(draw.mBaseLayer, draw.mInvalRegion,
                    getSettings().getShowVisualIndicator(),
                    isPictureAfterFirstLayout, registerPageSwapCallback);
                    isPictureAfterFirstLayout);
        }
        final Point viewSize = draw.mViewSize;
        // We update the layout (i.e. request a layout from the
@@ -9715,11 +9722,6 @@ public class WebView extends AbsoluteLayout
        }
    }

    /** @hide call pageSwapCallback upon next page swap */
    protected void registerPageSwapCallback() {
        nativeRegisterPageSwapCallback(mNativeClass);
    }

    /** @hide discard all textures from tiles */
    protected void discardAllTextures() {
        nativeDiscardAllTextures();
@@ -9882,10 +9884,9 @@ public class WebView extends AbsoluteLayout
    private native void     nativeSetFindIsEmpty();
    private native void     nativeSetFindIsUp(boolean isUp);
    private native void     nativeSetHeightCanMeasure(boolean measure);
    private native void     nativeSetBaseLayer(int nativeInstance,
    private native boolean  nativeSetBaseLayer(int nativeInstance,
            int layer, Region invalRegion,
            boolean showVisualIndicator, boolean isPictureAfterFirstLayout,
            boolean registerPageSwapCallback);
            boolean showVisualIndicator, boolean isPictureAfterFirstLayout);
    private native int      nativeGetBaseLayer();
    private native void     nativeShowCursorTimed();
    private native void     nativeReplaceBaseContent(int content);
@@ -9897,7 +9898,6 @@ public class WebView extends AbsoluteLayout
    private native void     nativeStopGL();
    private native Rect     nativeSubtractLayers(Rect content);
    private native int      nativeTextGeneration();
    private native void     nativeRegisterPageSwapCallback(int nativeInstance);
    private native void     nativeDiscardAllTextures();
    private native void     nativeTileProfilingStart();
    private native float    nativeTileProfilingStop();
+30 −1
Original line number Diff line number Diff line
@@ -2169,7 +2169,36 @@ public final class WebViewCore {
                .obtainMessage(WebView.INVAL_RECT_MSG_ID));
    }

    private Boolean m_skipDrawFlag = false;
    private boolean m_drawWasSkipped = false;

    void pauseWebKitDraw() {
        synchronized (m_skipDrawFlag) {
            if (!m_skipDrawFlag) {
                m_skipDrawFlag = true;
            }
        }
    }

    void resumeWebKitDraw() {
        synchronized (m_skipDrawFlag) {
            if (m_skipDrawFlag && m_drawWasSkipped) {
                // a draw was dropped, send a retry
                m_drawWasSkipped = false;
                mEventHub.sendMessage(Message.obtain(null, EventHub.WEBKIT_DRAW));
            }
            m_skipDrawFlag = false;
        }
    }

    private void webkitDraw() {
        synchronized (m_skipDrawFlag) {
            if (m_skipDrawFlag) {
                m_drawWasSkipped = true;
                return;
            }
        }

        mDrawIsScheduled = false;
        DrawData draw = new DrawData();
        if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw start");
@@ -2178,7 +2207,7 @@ public final class WebViewCore {
        if (draw.mBaseLayer == 0) {
            if (mWebView != null && !mWebView.isPaused()) {
                if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw abort, resending draw message");
                mEventHub.sendMessage(Message.obtain(null, EventHub.WEBKIT_DRAW));
                mEventHub.sendMessageDelayed(Message.obtain(null, EventHub.WEBKIT_DRAW), 10);
            } else {
                if (DebugFlags.WEB_VIEW_CORE) Log.v(LOGTAG, "webkitDraw abort, webview paused");
            }
+10 −7
Original line number Diff line number Diff line
@@ -40,8 +40,11 @@ public class ProfiledWebView extends WebView {
    private long mContentInvalMillis;
    private static final int LOAD_STALL_MILLIS = 2000; // nr of millis after load,
                                                       // before test is forced
    private double mLoadTime;
    private double mAnimationTime;

    // ignore anim end events until this many millis after load
    private static final long ANIM_SAFETY_THRESHOLD = 200;
    private long mLoadTime;
    private long mAnimationTime;

    public ProfiledWebView(Context context) {
        super(context);
@@ -131,7 +134,6 @@ public class ProfiledWebView extends WebView {
                    // invalidate all content, and kick off redraw
                    Log.d("ProfiledWebView",
                            "kicking off test with callback registration, and tile discard...");
                    registerPageSwapCallback();
                    discardAllTextures();
                    invalidate();
                    mIsScrolling = true;
@@ -150,10 +152,11 @@ public class ProfiledWebView extends WebView {
     */
    @Override
    protected void pageSwapCallback(boolean startAnim) {
        super.pageSwapCallback(startAnim);

        if (!mIsTesting && mIsScrolling) {
            // kick off testing
            mContentInvalMillis = System.currentTimeMillis() - mContentInvalMillis;
            super.pageSwapCallback(startAnim);
            Log.d("ProfiledWebView", "REDRAW TOOK " + mContentInvalMillis + "millis");
            mIsTesting = true;
            invalidate(); // ensure a redraw so that auto-scrolling can occur
@@ -166,14 +169,14 @@ public class ProfiledWebView extends WebView {
        String updatesString = settings.getProperty("tree_updates");
        int updates = (updatesString == null) ? -1 : Integer.parseInt(updatesString);

        double animationTime;
        if (mAnimationTime == 0) {
        long animationTime;
        if (mAnimationTime == 0 || mAnimationTime - mLoadTime < ANIM_SAFETY_THRESHOLD) {
            animationTime = System.currentTimeMillis() - mLoadTime;
        } else {
            animationTime = mAnimationTime - mLoadTime;
        }

        return updates * 1000 / animationTime;
        return updates * 1000.0 / animationTime;
    }

    public void setDoubleBuffering(boolean useDoubleBuffering) {