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

Commit af95a200 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Fix blur in ViewRootImpl"

parents 209f3ff1 6fbb788f
Loading
Loading
Loading
Loading
+69 −67
Original line number Original line Diff line number Diff line
@@ -3868,8 +3868,6 @@ public final class ViewRootImpl implements ViewParent,
    private HardwareRenderer.FrameCompleteCallback createFrameCompleteCallback(Handler handler,
    private HardwareRenderer.FrameCompleteCallback createFrameCompleteCallback(Handler handler,
            boolean reportNextDraw, ArrayList<Runnable> commitCallbacks) {
            boolean reportNextDraw, ArrayList<Runnable> commitCallbacks) {
        return frameNr -> {
        return frameNr -> {
            mBlurRegionAggregator.dispatchBlurTransactionIfNeeded(frameNr);

            if (DEBUG_BLAST) {
            if (DEBUG_BLAST) {
                Log.d(mTag, "Received frameCompleteCallback frameNum=" + frameNr);
                Log.d(mTag, "Received frameCompleteCallback frameNum=" + frameNr);
            }
            }
@@ -3903,8 +3901,7 @@ public final class ViewRootImpl implements ViewParent,
                .captureFrameCommitCallbacks();
                .captureFrameCommitCallbacks();
        final boolean needFrameCompleteCallback =
        final boolean needFrameCompleteCallback =
                mNextDrawUseBLASTSyncTransaction || mReportNextDraw
                mNextDrawUseBLASTSyncTransaction || mReportNextDraw
                        || (commitCallbacks != null && commitCallbacks.size() > 0)
                        || (commitCallbacks != null && commitCallbacks.size() > 0);
                        || mBlurRegionAggregator.hasRegions();
        if (needFrameCompleteCallback) {
        if (needFrameCompleteCallback) {
            if (DEBUG_BLAST) {
            if (DEBUG_BLAST) {
                Log.d(mTag, "Creating frameCompleteCallback"
                Log.d(mTag, "Creating frameCompleteCallback"
@@ -3921,28 +3918,61 @@ public final class ViewRootImpl implements ViewParent,
        return false;
        return false;
    }
    }


    /**
    private void addFrameCallbackIfNeeded() {
     * The callback will run on a worker thread pool from the render thread.
        boolean nextDrawUseBlastSync = mNextDrawUseBLASTSyncTransaction;
     */
        boolean hasBlur = mBlurRegionAggregator.hasRegions();
    private HardwareRenderer.FrameDrawingCallback createFrameDrawingCallback(
        boolean reportNextDraw = mReportNextDraw;
            boolean addTransactionComplete) {
        boolean addTransactionComplete = mSendNextFrameToWm;
        return frame -> {

        if (!nextDrawUseBlastSync && !reportNextDraw && !hasBlur) {
            return;
        }

        mNextDrawUseBLASTSyncTransaction = false;

        if (DEBUG_BLAST) {
            Log.d(mTag, "Creating frameDrawingCallback"
                    + " nextDrawUseBlastSync=" + nextDrawUseBlastSync
                    + " reportNextDraw=" + reportNextDraw
                    + " hasBlur=" + hasBlur);
        }

        // The callback will run on a worker thread pool from the render thread.
        HardwareRenderer.FrameDrawingCallback frameDrawingCallback = frame -> {
            if (DEBUG_BLAST) {
            if (DEBUG_BLAST) {
                Log.d(mTag, "Received frameDrawingCallback frameNum=" + frame + "."
                Log.d(mTag, "Received frameDrawingCallback frameNum=" + frame + "."
                        + " Creating transactionCompleteCallback=" + addTransactionComplete);
                        + " Creating transactionCompleteCallback=" + addTransactionComplete);
            }
            }
            mRtNextFrameReportedConsumeWithBlast = true;

            if (hasBlur) {
                mBlurRegionAggregator.dispatchBlurTransactionIfNeeded(frame);
            }

            if (mBlastBufferQueue == null) {
            if (mBlastBufferQueue == null) {
                return;
                return;
            }
            }


            if (nextDrawUseBlastSync) {
                // Frame callbacks will always occur after submitting draw requests and before
                // the draw actually occurs. This will ensure that we set the next transaction
                // for the frame that's about to get drawn and not on a previous frame that.
                //
                // This is thread safe since mRtNextFrameReportConsumeWithBlast will only be
                // modified in onFrameDraw and then again in onFrameComplete. This is to ensure the
                // next frame completed should be reported with the blast sync transaction.
                mRtNextFrameReportedConsumeWithBlast = true;

                // We don't need to synchronize mRtBLASTSyncTransaction here since it's not
                // We don't need to synchronize mRtBLASTSyncTransaction here since it's not
                // being modified and only sent to BlastBufferQueue.
                // being modified and only sent to BlastBufferQueue.
                mBlastBufferQueue.setNextTransaction(mRtBLASTSyncTransaction);
                mBlastBufferQueue.setNextTransaction(mRtBLASTSyncTransaction);
            if (!addTransactionComplete) {
            } else if (reportNextDraw) {
                return;
                // If we need to report next draw, wait for adapter to flush its shadow queue
                // by processing previously queued buffers so that we can submit the
                // transaction a timely manner.
                mBlastBufferQueue.flushShadowQueue();
            }
            }


            if (addTransactionComplete) {
                mBlastBufferQueue.setTransactionCompleteCallback(frame, frameNumber -> {
                mBlastBufferQueue.setTransactionCompleteCallback(frame, frameNumber -> {
                    if (DEBUG_BLAST) {
                    if (DEBUG_BLAST) {
                        Log.d(mTag, "Received transactionCompleteCallback frameNum=" + frame);
                        Log.d(mTag, "Received transactionCompleteCallback frameNum=" + frame);
@@ -3959,37 +3989,9 @@ public final class ViewRootImpl implements ViewParent,
                        }
                        }
                    });
                    });
                });
                });
        };
    }

    private void addFrameCallbackIfNeeded() {
        if (DEBUG_BLAST) {
            if (mNextDrawUseBLASTSyncTransaction || mReportNextDraw) {
                Log.d(mTag, "Creating frameDrawingCallback mNextDrawUseBLASTSyncTransaction="
                        + mNextDrawUseBLASTSyncTransaction + " mReportNextDraw=" + mReportNextDraw);
            }
        }

        if (mNextDrawUseBLASTSyncTransaction) {
            // Frame callbacks will always occur after submitting draw requests and before
            // the draw actually occurs. This will ensure that we set the next transaction
            // for the frame that's about to get drawn and not on a previous frame that.
            //
            // This is thread safe since mRtNextFrameReportConsumeWithBlast will only be
            // modified in onFrameDraw and then again in onFrameComplete. This is to ensure the
            // next frame completed should be reported with the blast sync transaction.
            registerRtFrameCallback(createFrameDrawingCallback(mSendNextFrameToWm));
            mNextDrawUseBLASTSyncTransaction = false;
        } else if (mReportNextDraw) {
            registerRtFrameCallback(frame -> {
                if (mBlastBufferQueue != null) {
                    // If we need to report next draw, wait for adapter to flush its shadow queue
                    // by processing previously queued buffers so that we can submit the
                    // transaction a timely manner.
                    mBlastBufferQueue.flushShadowQueue();
                }
            });
            }
            }
        };
        registerRtFrameCallback(frameDrawingCallback);
    }
    }


    private void performDraw() {
    private void performDraw() {
@@ -10070,14 +10072,14 @@ public final class ViewRootImpl implements ViewParent,
        if (!surfaceControl.isValid()) {
        if (!surfaceControl.isValid()) {
            return;
            return;
        }
        }
        if (useBLAST()) {

            synchronized (getBlastTransactionLock()) {
                getBLASTSyncTransaction().setBlurRegions(surfaceControl, regionCopy);
            }
        } else {
        SurfaceControl.Transaction transaction = new SurfaceControl.Transaction();
        SurfaceControl.Transaction transaction = new SurfaceControl.Transaction();
        transaction.setBlurRegions(surfaceControl, regionCopy);
        transaction.setBlurRegions(surfaceControl, regionCopy);
            transaction.deferTransactionUntil(surfaceControl, getSurfaceControl(), frameNumber);

        if (useBLAST() && mBlastBufferQueue != null) {
            mBlastBufferQueue.mergeWithNextTransaction(transaction, frameNumber);
        } else {
            transaction.deferTransactionUntil(surfaceControl, surfaceControl, frameNumber);
            transaction.apply();
            transaction.apply();
        }
        }
    }
    }