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

Commit a22d8b29 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "webkit: Reduce processing in WebCore thread while scrolling and zooming" into ics

parents 7e7b72d5 b963f3c0
Loading
Loading
Loading
Loading
+35 −8
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 The Android Open Source Project
 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -743,9 +744,10 @@ public class WebView extends AbsoluteLayout
    static final int ENTER_FULLSCREEN_VIDEO             = 137;
    static final int UPDATE_SELECTION                   = 138;
    static final int UPDATE_ZOOM_DENSITY                = 139;
    static final int RESUME_RENDER_PRIORITY             = 140;

    private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID;
    private static final int LAST_PACKAGE_MSG_ID = SET_TOUCH_HIGHLIGHT_RECTS;
    private static final int LAST_PACKAGE_MSG_ID = RESUME_RENDER_PRIORITY;

    static final String[] HandlerPrivateDebugString = {
        "REMEMBER_PASSWORD", //              = 1;
@@ -3647,7 +3649,9 @@ public class WebView extends AbsoluteLayout
                abortAnimation();
                nativeSetIsScrolling(false);
                if (!mBlockWebkitViewMessages) {
                    WebViewCore.resumePriority();
                    WebViewCore.resumePriority(2000);
                    WebSettings webSettings = getSettings();
                    webSettings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
                    if (!mSelectingText) {
                        WebViewCore.resumeUpdatePicture(mWebViewCore);
                    }
@@ -5593,7 +5597,9 @@ public class WebView extends AbsoluteLayout
            // called by mSelectCallback.onDestroyActionMode
            mSelectCallback.finish();
            mSelectCallback = null;
            WebViewCore.resumePriority();
            WebViewCore.resumePriority(0);
            WebSettings webSettings = getSettings();
            webSettings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
            WebViewCore.resumeUpdatePicture(mWebViewCore);
            invalidate(); // redraw without selection
            mAutoScrollX = 0;
@@ -6498,6 +6504,8 @@ public class WebView extends AbsoluteLayout
                                // we will not rewrite drag code here, but we
                                // will try fling if it applies.
                                WebViewCore.reducePriority();
                                WebSettings webSettings = getSettings();
                                webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
                                // to get better performance, pause updating the
                                // picture
                                WebViewCore.pauseUpdatePicture(mWebViewCore);
@@ -6568,7 +6576,9 @@ public class WebView extends AbsoluteLayout
                        // device as we almost certain will get a MOVE. But this
                        // is possible on emulator.
                        mLastVelocity = 0;
                        WebViewCore.resumePriority();
                        WebViewCore.resumePriority(0);
                        WebSettings webSettings = getSettings();
                        webSettings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
                        if (!mSelectingText) {
                            WebViewCore.resumeUpdatePicture(mWebViewCore);
                        }
@@ -6620,6 +6630,9 @@ public class WebView extends AbsoluteLayout
    }

    void handleMultiTouchInWebView(MotionEvent ev) {
        WebViewCore.reducePriority();
        WebSettings webSettings = getSettings();
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        if (DebugFlags.WEB_VIEW) {
            Log.v(LOGTAG, "multi-touch: " + ev + " at " + ev.getEventTime()
                + " mTouchMode=" + mTouchMode
@@ -6720,6 +6733,8 @@ public class WebView extends AbsoluteLayout

    private void startDrag() {
        WebViewCore.reducePriority();
        WebSettings webSettings = getSettings();
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        // to get better performance, pause updating the picture
        WebViewCore.pauseUpdatePicture(mWebViewCore);
        nativeSetIsScrolling(true);
@@ -6795,7 +6810,9 @@ public class WebView extends AbsoluteLayout
    private void stopTouch() {
        if (mScroller.isFinished() && !mSelectingText
                && (mTouchMode == TOUCH_DRAG_MODE || mTouchMode == TOUCH_DRAG_LAYER_MODE)) {
            WebViewCore.resumePriority();
            WebViewCore.resumePriority(0);
            WebSettings webSettings = getSettings();
            webSettings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
            WebViewCore.resumeUpdatePicture(mWebViewCore);
            nativeSetIsScrolling(false);
        }
@@ -6825,7 +6842,9 @@ public class WebView extends AbsoluteLayout

        if ((mTouchMode == TOUCH_DRAG_MODE
                || mTouchMode == TOUCH_DRAG_LAYER_MODE) && !mSelectingText) {
            WebViewCore.resumePriority();
            WebViewCore.resumePriority(0);
            WebSettings webSettings = getSettings();
            webSettings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
            WebViewCore.resumeUpdatePicture(mWebViewCore);
            nativeSetIsScrolling(false);
        }
@@ -7236,7 +7255,9 @@ public class WebView extends AbsoluteLayout
            }
        }
        if ((maxX == 0 && vy == 0) || (maxY == 0 && vx == 0)) {
            WebViewCore.resumePriority();
            WebViewCore.resumePriority(0);
            WebSettings webSettings = getSettings();
            webSettings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
            if (!mSelectingText) {
                WebViewCore.resumeUpdatePicture(mWebViewCore);
            }
@@ -8283,7 +8304,9 @@ public class WebView extends AbsoluteLayout
                                        computeMaxScrollX(), 0,
                                        computeMaxScrollY());
                                invalidate();
                                WebViewCore.resumePriority();
                                WebViewCore.resumePriority(0);
                                WebSettings webSettings = getSettings();
                                webSettings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
                                WebViewCore.resumeUpdatePicture(mWebViewCore);
                            }
                            mDeferTouchMode = TOUCH_DONE_MODE;
@@ -8776,6 +8799,10 @@ public class WebView extends AbsoluteLayout
                    nativeSelectAt(msg.arg1, msg.arg2);
                    break;

                case RESUME_RENDER_PRIORITY:
                    WebSettings webSettings = getSettings();
                    webSettings.setRenderPriority(WebSettings.RenderPriority.NORMAL);

                default:
                    super.handleMessage(msg);
                    break;
+55 −5
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ public final class WebViewCore {
     * WebViewCore always executes in the same thread as the native webkit.
     */

    private static int mResumeTimerDuration = 2000;

    // The WebView that corresponds to this WebViewCore.
    private WebView mWebView;
    // Proxy for handling callbacks from native code
@@ -210,6 +212,13 @@ public final class WebViewCore {
        sWebCoreHandler.sendMessage(init);
    }

    private void sendPriorityMessageToWebView()
    {
        if (mWebView != null)
            mWebView.mPrivateHandler.sendMessageAtFrontOfQueue(
                mWebView.mPrivateHandler.obtainMessage(WebView.RESUME_RENDER_PRIORITY));
    }

    /* Initialize private data within the WebCore thread.
     */
    private void initialize() {
@@ -564,6 +573,7 @@ public final class WebViewCore {
            int anchorY, boolean ignoreHeight);

    private native int nativeGetContentMinPrefWidth();
    private native static int nativeGetTextureGeneratorThreadID();

    // Start: functions that deal with text editing
    private native void nativeReplaceTextfieldText(
@@ -678,6 +688,8 @@ public final class WebViewCore {
        private static final int RESUME_PRIORITY = 2;
        private static Performance mPerf = new Performance();
        private static final int MIN_FREQ_DURING_SCROLLING = 10;
        private WebViewCore core = null;
        private int tid = 0;

        public void run() {
            Looper.prepare();
@@ -688,32 +700,62 @@ public final class WebViewCore {
                    public void handleMessage(Message msg) {
                        switch (msg.what) {
                            case INITIALIZE:
                                WebViewCore core = (WebViewCore) msg.obj;
                                core = (WebViewCore) msg.obj;
                                core.initialize();
                                break;

                            case REDUCE_PRIORITY:
                                // 3 is an adjustable number.
                                sWebCoreHandler.removeMessages(WebCoreThread.RESUME_PRIORITY);
                                tid = nativeGetTextureGeneratorThreadID();
                                if (tid > 0) {
                                    try {
                                        Process.setThreadPriority(tid,Process.THREAD_PRIORITY_FOREGROUND);
                                    } catch (IllegalArgumentException ex){
                                        Log.e(LOGTAG, "Thread does not exist");
                                    }
                                }
                                    // 10 is an adjustable number.
                                Process.setThreadPriority(
                                        Process.THREAD_PRIORITY_DEFAULT + 3 *
                                        Process.THREAD_PRIORITY_DEFAULT + 10 *
                                        Process.THREAD_PRIORITY_LESS_FAVORABLE);

                                sWebCoreHandler.sendMessageDelayed(Message.obtain(null,
                                    WebCoreThread.RESUME_PRIORITY), mResumeTimerDuration);

                                if (SystemProperties.QCOM_HARDWARE ) {
                                    /* Disable power collapse and setup the min frequency */
                                    /* 0 means disabling power collapse */
                                    mPerf.cpuSetOptions(Performance.CPUOPT_CPU0_PWRCLSP,0);
                                    mPerf.cpuSetOptions(Performance.CPUOPT_CPU0_FREQMIN,MIN_FREQ_DURING_SCROLLING);
                                }

                                break;

                            case RESUME_PRIORITY:

                                tid = nativeGetTextureGeneratorThreadID();
                                if (tid > 0) {
                                    try {
                                        Process.setThreadPriority(tid,Process.THREAD_PRIORITY_DEFAULT);
                                    } catch (IllegalArgumentException ex) {
                                        Log.e(LOGTAG, "Thread does not exist");
                                    }
                                }
                                Process.setThreadPriority(
                                        Process.THREAD_PRIORITY_DEFAULT);

                                if (core != null)
                                {
                                    core.sendPriorityMessageToWebView();
                                }

                                if (SystemProperties.QCOM_HARDWARE ) {
                                    /* Enable power collapse and reset the min frequency */
                                    /* 1 means enabling power collapse */
                                    mPerf.cpuSetOptions(Performance.CPUOPT_CPU0_PWRCLSP,1);
                                    mPerf.cpuSetOptions(Performance.CPUOPT_CPU0_FREQMIN,0);
                                }

                                break;

                            case EventHub.ADD_PACKAGE_NAME:
@@ -2105,13 +2147,21 @@ public final class WebViewCore {
                .obtainMessage(WebCoreThread.REDUCE_PRIORITY));
    }

    static void resumePriority() {
    static void resumePriority(int delay) {
        // remove the pending REDUCE_PRIORITY and RESUME_PRIORITY messages
        sWebCoreHandler.removeMessages(WebCoreThread.REDUCE_PRIORITY);
        sWebCoreHandler.removeMessages(WebCoreThread.RESUME_PRIORITY);
        if (delay > 0)
        {
            sWebCoreHandler.sendMessageDelayed(sWebCoreHandler
                .obtainMessage(WebCoreThread.RESUME_PRIORITY), delay);
        }
        else
        {
            sWebCoreHandler.sendMessageAtFrontOfQueue(sWebCoreHandler
                .obtainMessage(WebCoreThread.RESUME_PRIORITY));
        }
    }

    static void sendStaticMessage(int messageType, Object argument) {
        if (sWebCoreHandler == null)
+3 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -628,6 +629,8 @@ class ZoomManager {
        if (!isDoubleTapEnabled()) {
            return;
        }
        WebViewCore.reducePriority();
        settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

        setZoomCenter(lastTouchX, lastTouchY);
        mAnchorX = mWebView.viewToContentX((int) lastTouchX + mWebView.getScrollX());