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

Commit 0727926d authored by Evan Rosky's avatar Evan Rosky Committed by Android (Google) Code Review
Browse files

Merge "Always SeqId client draws prefactors [1/n]" into main

parents ba983ba6 3b0c818d
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -48,12 +48,13 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
    private final boolean mReportDraw;
    private final boolean mForceLayout;
    private final int mDisplayId;
    private final boolean mSyncWithBuffers;
    private final boolean mDragResizing;

    public WindowStateResizeItem(@NonNull IWindow window,
            @NonNull ClientWindowFrames frames, boolean reportDraw,
            @NonNull MergedConfiguration configuration, @NonNull InsetsState insetsState,
            boolean forceLayout, int displayId, int syncSeqId, boolean dragResizing,
    public WindowStateResizeItem(@NonNull IWindow window, @NonNull ClientWindowFrames frames,
            boolean reportDraw, @NonNull MergedConfiguration configuration,
            @NonNull InsetsState insetsState, boolean forceLayout, int displayId, int syncSeqId,
            boolean syncWithBuffers, boolean dragResizing,
            @Nullable ActivityWindowInfo activityWindowInfo) {
        super(window);
        mLayout.frames.setTo(frames);
@@ -68,6 +69,7 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
        mForceLayout = forceLayout;
        mDisplayId = displayId;
        mLayout.syncSeqId = syncSeqId;
        mSyncWithBuffers = syncWithBuffers;
        mDragResizing = dragResizing;
    }

@@ -77,7 +79,8 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER,
                mReportDraw ? "windowResizedReport" : "windowResized");
        try {
            window.resized(mLayout, mReportDraw, mForceLayout, mDisplayId, mDragResizing);
            window.resized(mLayout, mReportDraw, mForceLayout, mDisplayId, mSyncWithBuffers,
                    mDragResizing);
        } catch (RemoteException e) {
            // Should be a local call.
            // An exception could happen if the process is restarted. It is safe to ignore since
@@ -97,6 +100,7 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
        dest.writeBoolean(mReportDraw);
        dest.writeBoolean(mForceLayout);
        dest.writeInt(mDisplayId);
        dest.writeBoolean(mSyncWithBuffers);
        dest.writeBoolean(mDragResizing);
    }

@@ -107,6 +111,7 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
        mReportDraw = in.readBoolean();
        mForceLayout = in.readBoolean();
        mDisplayId = in.readInt();
        mSyncWithBuffers = in.readBoolean();
        mDragResizing = in.readBoolean();
    }

@@ -136,6 +141,7 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
                && mForceLayout == other.mForceLayout
                && mDisplayId == other.mDisplayId
                && mLayout.syncSeqId == other.mLayout.syncSeqId
                && mSyncWithBuffers == other.mSyncWithBuffers
                && mDragResizing == other.mDragResizing
                && Objects.equals(mLayout.activityWindowInfo, other.mLayout.activityWindowInfo);
    }
@@ -151,6 +157,7 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
        result = 31 * result + (mForceLayout ? 1 : 0);
        result = 31 * result + mDisplayId;
        result = 31 * result + mLayout.syncSeqId;
        result = 31 * result + (mSyncWithBuffers ? 1 : 0);
        result = 31 * result + (mDragResizing ? 1 : 0);
        result = 31 * result + Objects.hashCode(mLayout.activityWindowInfo);
        return result;
@@ -160,6 +167,7 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
    public String toString() {
        return "WindowStateResizeItem{" + super.toString()
                + ", reportDrawn=" + mReportDraw
                + ", syncSeqId=" + mLayout.syncSeqId + (mSyncWithBuffers ? "+buf" : "")
                + ", configuration=" + mLayout.mergedConfiguration
                + ", activityWindowInfo=" + mLayout.activityWindowInfo
                + "}";
+37 −25
Original line number Diff line number Diff line
@@ -321,6 +321,14 @@ public abstract class WallpaperService extends Service {
        final WindowManager.LayoutParams mLayout
                = new WindowManager.LayoutParams();
        IWindowSession mSession;
        int mSeqId = -1;

        /**
         * Sequence id for the most-recent visibility change. Track this separately since there are
         * many inputs that effect visibility and they all need to use the same seqId.
         */
        @GuardedBy("mLock")
        private int mVisSeqId = -1;

        final Object mLock = new Object();
        private final Object mSurfaceReleaseLock = new Object();
@@ -484,9 +492,9 @@ public abstract class WallpaperService extends Service {
        final BaseIWindow mWindow = new BaseIWindow() {
            @Override
            public void resized(WindowRelayoutResult layout, boolean reportDraw,
                    boolean forceLayout, int displayId, boolean dragResizing) {
                Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED,
                        reportDraw ? 1 : 0,
                    boolean forceLayout, int displayId, boolean syncWithBuffers,
                    boolean dragResizing) {
                Message msg = mCaller.obtainMessageIO(MSG_WINDOW_RESIZED, reportDraw ? 1 : 0,
                        layout.mergedConfiguration);
                mIWallpaperEngine.mPendingResizeCount.incrementAndGet();
                mCaller.sendMessage(msg);
@@ -499,12 +507,12 @@ public abstract class WallpaperService extends Service {
            }

            @Override
            public void dispatchAppVisibility(boolean visible) {
            public void dispatchAppVisibility(boolean visible, int seqId) {
                // We don't do this in preview mode; we'll let the preview
                // activity tell us when to run.
                if (!mIWallpaperEngine.mIsPreview) {
                    Message msg = mCaller.obtainMessageI(MSG_VISIBILITY_CHANGED,
                            visible ? 1 : 0);
                    Message msg = mCaller.obtainMessageII(MSG_VISIBILITY_CHANGED,
                            visible ? 1 : 0, seqId);
                    mCaller.sendMessage(msg);
                }
            }
@@ -706,7 +714,7 @@ public abstract class WallpaperService extends Service {
                    ? (mWindowFlags&~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
                    : (mWindowFlags|WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
            if (mCreated) {
                updateSurface(false, false, false);
                updateSurface(false, -1, false);
            }
        }

@@ -725,7 +733,7 @@ public abstract class WallpaperService extends Service {
                    : (mWindowPrivateFlags &
                        ~WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS);
            if (mCreated) {
                updateSurface(false, false, false);
                updateSurface(false, -1, false);
            }
        }

@@ -737,7 +745,7 @@ public abstract class WallpaperService extends Service {
                    : (mWindowPrivateFlags
                        & ~WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS);
            if (mCreated) {
                updateSurface(false, false, false);
                updateSurface(false, -1, false);
            }
        }

@@ -1087,14 +1095,14 @@ public abstract class WallpaperService extends Service {
                animator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        updateSurface(false, false, true);
                        updateSurface(false, -1, true);
                    }
                });
                animator.start();
            } else {
                Log.v(TAG, "Setting wallpaper dimming: " + 0);
                surfaceControlTransaction.setAlpha(mBbqSurfaceControl, 1.0f).apply();
                updateSurface(false, false, true);
                updateSurface(false, -1, true);
            }

            mPreviousWallpaperDimAmount = mWallpaperDimAmount;
@@ -1208,7 +1216,7 @@ public abstract class WallpaperService extends Service {
            }
        }

        void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNeeded) {
        void updateSurface(boolean forceRelayout, int seqId, boolean redrawNeeded) {
            if (mDestroyed) {
                Log.w(TAG, "Ignoring updateSurface due to destroyed");
                return;
@@ -1230,6 +1238,8 @@ public abstract class WallpaperService extends Service {
            final boolean typeChanged = mType != mSurfaceHolder.getRequestedType();
            final boolean flagsChanged = mCurWindowFlags != mWindowFlags ||
                    mCurWindowPrivateFlags != mWindowPrivateFlags;
            final boolean reportDraw = false;
            redrawNeeded = redrawNeeded || reportDraw;
            if (forceRelayout || creating || surfaceCreating || formatChanged || sizeChanged
                    || typeChanged || flagsChanged || redrawNeeded
                    || !mIWallpaperEngine.mShownReported) {
@@ -1459,12 +1469,12 @@ public abstract class WallpaperService extends Service {
                        redrawNeeded |= creating || (relayoutResult
                                & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0;

                        if (forceReport || creating || surfaceCreating
                        if (reportDraw || creating || surfaceCreating
                                || formatChanged || sizeChanged) {
                            if (DEBUG) {
                                RuntimeException e = new RuntimeException();
                                e.fillInStackTrace();
                                Log.w(TAG, "forceReport=" + forceReport + " creating=" + creating
                                Log.w(TAG, "reportDraw=" + reportDraw + " creating=" + creating
                                        + " formatChanged=" + formatChanged
                                        + " sizeChanged=" + sizeChanged, e);
                            }
@@ -1627,7 +1637,7 @@ public abstract class WallpaperService extends Service {

            mReportedVisible = false;
            Trace.beginSection("WPMS.Engine.updateSurface");
            updateSurface(false, false, false);
            updateSurface(false, -1, false);
            Trace.endSection();
        }

@@ -1685,7 +1695,7 @@ public abstract class WallpaperService extends Service {
                if (DEBUG) Log.v(TAG, "onDisplayPaddingChanged(" + padding + "): " + this);
                if (!mIWallpaperEngine.mDisplayPadding.equals(padding)) {
                    mIWallpaperEngine.mDisplayPadding.set(padding);
                    updateSurface(true, false, false);
                    updateSurface(true, -1, false);
                }
            }
        }
@@ -1742,7 +1752,7 @@ public abstract class WallpaperService extends Service {
                        // sure it is re-created.
                        doOffsetsChanged(false);
                        // It will check mSurfaceCreated so no need to force relayout.
                        updateSurface(false /* forceRelayout */, false /* forceReport */,
                        updateSurface(false /* forceRelayout */, mVisSeqId,
                                false /* redrawNeeded */);
                    }
                    onVisibilityChanged(visible);
@@ -2532,8 +2542,8 @@ public abstract class WallpaperService extends Service {
        }

        public void setVisibility(boolean visible) {
            Message msg = mCaller.obtainMessageI(MSG_VISIBILITY_CHANGED,
                    visible ? 1 : 0);
            Message msg = mCaller.obtainMessageII(MSG_VISIBILITY_CHANGED,
                    visible ? 1 : 0, -1);
            mCaller.sendMessage(msg);
        }

@@ -2732,7 +2742,7 @@ public abstract class WallpaperService extends Service {
                    return;
                }
                case MSG_UPDATE_SURFACE:
                    mEngine.updateSurface(true, false, false);
                    mEngine.updateSurface(true, -1, false);
                    break;
                case MSG_ZOOM:
                    mEngine.setZoom(Float.intBitsToFloat(message.arg1));
@@ -2763,7 +2773,7 @@ public abstract class WallpaperService extends Service {
                    mEngine.doCommand(cmd);
                } break;
                case MSG_WINDOW_RESIZED: {
                    handleResized((MergedConfiguration) message.obj, message.arg1 != 0);
                    handleResized((MergedConfiguration) message.obj, message.arg1);
                } break;
                case MSG_WINDOW_MOVED: {
                    // Do nothing. What does it mean for a Wallpaper to move?
@@ -2818,10 +2828,12 @@ public abstract class WallpaperService extends Service {
         * handled (ignore intermediate states). Note that this procedure cannot be skipped if the
         * configuration is not changed because this is also used to dispatch insets changes.
         */
        private void handleResized(MergedConfiguration config, boolean reportDraw) {
        private void handleResized(MergedConfiguration config, int seqId) {
            // The config can be null when retrying for a changed config from relayout, otherwise
            // it is from IWindow#resized which always sends non-null config.
            final int pendingCount = config != null ? mPendingResizeCount.decrementAndGet() : -1;
            final boolean fromResized = config != null;
            final boolean reportDraw = seqId != 0;
            final int pendingCount = fromResized ? mPendingResizeCount.decrementAndGet() : -1;
            if (reportDraw) {
                mReportDraw = true;
            }
@@ -2833,14 +2845,14 @@ public abstract class WallpaperService extends Service {
                }
                return;
            }
            if (config != null) {
            if (fromResized) {
                if (DEBUG) {
                    Log.d(TAG, "Update config from resized, bounds="
                            + config.getMergedConfiguration().windowConfiguration.getMaxBounds());
                }
                mEngine.mMergedConfiguration.setTo(config);
            }
            mEngine.updateSurface(true /* forceRelayout */, false /* forceReport */, mReportDraw);
            mEngine.updateSurface(true /* forceRelayout */, -1 /* seqId */, mReportDraw);
            mReportDraw = false;
            mEngine.doOffsetsChanged(true);
            mEngine.scaleAndCropScreenshot();
+2 −2
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ oneway interface IWindow {
     * the system server.
     */
    void resized(in WindowRelayoutResult layout, boolean reportDraw, boolean forceLayout,
            int displayId, boolean dragResizing);
            int displayId, boolean syncWithBuffers, boolean dragResizing);

    /**
     * Called when this window retrieved control over a specified set of insets sources.
@@ -83,7 +83,7 @@ oneway interface IWindow {
    void hideInsets(int types, in @nullable ImeTracker.Token statsToken);

    void moved(int newX, int newY);
    void dispatchAppVisibility(boolean visible);
    void dispatchAppVisibility(boolean visible, int seqId);
    void dispatchGetNewSurface();

    void closeSystemDialogs(String reason);
+2 −2
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ interface IWindowSession {
     * @param viewVisibility Window root view's visibility.
     * @param flags Request flags: {@link WindowManagerGlobal#RELAYOUT_INSETS_PENDING}.
     * @param seq The calling sequence of {@link #relayout} and {@link #relayoutAsync}.
     * @param lastSyncSeqId The last SyncSeqId that the client applied.
     * @param syncSeqId The latest SyncSeqId that the client is using.
     * @param outRelayoutResult Data object contains the info to be returned from server side.
     * @param outSurface Object in which is placed the new display surface.
     * @return int Result flags, defined in {@link WindowManagerGlobal}.
@@ -359,7 +359,7 @@ interface IWindowSession {
    /**
     * Returns whether this window needs to cancel draw and retry later.
     */
    boolean cancelDraw(IWindow window);
    boolean cancelDraw(IWindow window, int seqId);

    /**
     * Moves the focus to the adjacent window if there is one in the given direction. This can only
+27 −19
Original line number Diff line number Diff line
@@ -2263,7 +2263,7 @@ public final class ViewRootImpl implements ViewParent,
        return originalMode;
    }
    void handleAppVisibility(boolean visible) {
    void handleAppVisibility(boolean visible, int seqId) {
        if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) {
            Trace.instant(Trace.TRACE_TAG_VIEW, TextUtils.formatSimple(
                    "%s visibilityChanged oldVisibility=%b newVisibility=%b", mTag,
@@ -2298,7 +2298,7 @@ public final class ViewRootImpl implements ViewParent,
    /** Handles messages {@link #MSG_RESIZED} and {@link #MSG_RESIZED_REPORT}. */
    private void handleResized(ClientWindowFrames frames, boolean reportDraw,
            MergedConfiguration mergedConfiguration, InsetsState insetsState, boolean forceLayout,
            int displayId, int syncSeqId, boolean dragResizing,
            int displayId, int seqId, boolean syncWithBuffers, boolean dragResizing,
            @Nullable ActivityWindowInfo activityWindowInfo) {
        if (!mAdded) {
            return;
@@ -2367,7 +2367,7 @@ public final class ViewRootImpl implements ViewParent,
        mForceNextWindowRelayout |= forceLayout;
        mPendingAlwaysConsumeSystemBars = false;
        mSyncSeqId = syncSeqId > mSyncSeqId ? syncSeqId : mSyncSeqId;
        mSyncSeqId = seqId > mSyncSeqId ? seqId : mSyncSeqId;
        if (reportDraw) {
            reportNextDraw("resized");
@@ -4206,7 +4206,7 @@ public final class ViewRootImpl implements ViewParent,
            // traversal. So we don't know if the sync is complete that we can continue to draw.
            // Here invokes cancelDraw to obtain the information.
            try {
                cancelDraw = mWindowSession.cancelDraw(mWindow);
                cancelDraw = mWindowSession.cancelDraw(mWindow, 0);
                cancelReason = "wm_sync";
                if (DEBUG_BLAST) {
                    Log.d(mTag, "cancelDraw returned " + cancelDraw);
@@ -6982,7 +6982,7 @@ public final class ViewRootImpl implements ViewParent,
                    doProcessInputEvents();
                    break;
                case MSG_DISPATCH_APP_VISIBILITY:
                    handleAppVisibility(msg.arg1 != 0);
                    handleAppVisibility(msg.arg1 != 0, msg.arg2);
                    break;
                case MSG_DISPATCH_GET_NEW_SURFACE:
                    handleGetNewSurface();
@@ -6994,10 +6994,11 @@ public final class ViewRootImpl implements ViewParent,
                    final boolean reportDraw = msg.what == MSG_RESIZED_REPORT;
                    final boolean forceLayout = args.argi1 != 0;
                    final int displayId = args.argi2;
                    final boolean dragResizing = args.argi3 != 0;
                    final boolean syncWithBuffers = args.argi3 != 0;
                    final boolean dragResizing = args.argi4 != 0;
                    handleResized(layout.frames, reportDraw, layout.mergedConfiguration,
                            layout.insetsState, forceLayout, displayId, layout.syncSeqId,
                            dragResizing, layout.activityWindowInfo);
                            syncWithBuffers, dragResizing, layout.activityWindowInfo);
                    args.recycle();
                    break;
                }
@@ -9599,16 +9600,17 @@ public final class ViewRootImpl implements ViewParent,
        final int requestedHeight = (int) (measuredHeight * appScale + 0.5f);
        int relayoutResult = 0;
        mRelayoutSeq++;
        final int seqId = mLastSyncSeqId;
        if (relayoutAsync) {
            mWindowSession.relayoutAsync(mWindow, params,
                    requestedWidth, requestedHeight, viewVisibility,
                    insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, mRelayoutSeq,
                    mLastSyncSeqId);
                    seqId);
        } else {
            relayoutResult = mWindowSession.relayout(mWindow, params,
                    requestedWidth, requestedHeight, viewVisibility,
                    insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0,
                    mRelayoutSeq, mLastSyncSeqId, mRelayoutResult, mSurfaceControl);
                    mRelayoutSeq, seqId, mRelayoutResult, mSurfaceControl);
            mRelayoutRequested = true;
            onClientWindowFramesChanged(mTmpFrames);
@@ -10272,13 +10274,14 @@ public final class ViewRootImpl implements ViewParent,
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private void dispatchResized(WindowRelayoutResult layout, boolean reportDraw,
            boolean forceLayout, int displayId, boolean dragResizing) {
            boolean forceLayout, int displayId, boolean syncWithBuffers, boolean dragResizing) {
        Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED);
        SomeArgs args = SomeArgs.obtain();
        args.arg1 = layout;
        args.argi1 = forceLayout ? 1 : 0;
        args.argi2 = displayId;
        args.argi3 = dragResizing ? 1 : 0;
        args.argi3 = syncWithBuffers ? 1 : 0;
        args.argi4 = dragResizing ? 1 : 0;
        msg.obj = args;
        mHandler.sendMessage(msg);
@@ -11017,9 +11020,13 @@ public final class ViewRootImpl implements ViewParent,
        synthesizeInputEvent(event);
    }
    public void dispatchAppVisibility(boolean visible) {
    /**
     * Notify that the visibility has changed
     */
    public void dispatchAppVisibility(boolean visible, int seqId) {
        Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY);
        msg.arg1 = visible ? 1 : 0;
        msg.arg2 = seqId;
        mHandler.sendMessage(msg);
    }
@@ -11777,8 +11784,8 @@ public final class ViewRootImpl implements ViewParent,
        }
        @Override
        public void resized(WindowRelayoutResult layout, boolean reportDraw,
                boolean forceLayout, int displayId, boolean dragResizing) {
        public void resized(WindowRelayoutResult layout, boolean reportDraw, boolean forceLayout,
                int displayId, boolean syncWithBuffers, boolean dragResizing) {
            final boolean isFromResizeItem = mIsFromTransactionItem;
            mIsFromTransactionItem = false;
            // Although this is a AIDL method, it will only be triggered in local process through
@@ -11797,8 +11804,8 @@ public final class ViewRootImpl implements ViewParent,
            if (isFromResizeItem && viewAncestor.mHandler.getLooper()
                    == ActivityThread.currentActivityThread().getLooper()) {
                viewAncestor.handleResized(layout.frames, reportDraw, layout.mergedConfiguration,
                        layout.insetsState, forceLayout, displayId, layout.syncSeqId, dragResizing,
                        layout.activityWindowInfo);
                        layout.insetsState, forceLayout, displayId, layout.syncSeqId,
                        syncWithBuffers, dragResizing, layout.activityWindowInfo);
                return;
            }
            // The the parameters from WindowStateResizeItem are already copied.
@@ -11807,7 +11814,8 @@ public final class ViewRootImpl implements ViewParent,
            if (needsCopy) {
                layout = new WindowRelayoutResult(layout);
            }
            viewAncestor.dispatchResized(layout, reportDraw, forceLayout, displayId, dragResizing);
            viewAncestor.dispatchResized(layout, reportDraw, forceLayout, displayId,
                    syncWithBuffers, dragResizing);
        }
        @Override
@@ -11879,10 +11887,10 @@ public final class ViewRootImpl implements ViewParent,
        }
        @Override
        public void dispatchAppVisibility(boolean visible) {
        public void dispatchAppVisibility(boolean visible, int seqId) {
            final ViewRootImpl viewAncestor = mViewAncestor.get();
            if (viewAncestor != null) {
                viewAncestor.dispatchAppVisibility(visible);
                viewAncestor.dispatchAppVisibility(visible, seqId);
            }
        }
Loading