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

Commit ed5c0388 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7952937 from 99ab01f4 to sc-v2-release

Change-Id: I67c26287454b5bd074d7bf6e1a8bccecec38bf2b
parents f7a05044 99ab01f4
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1266,6 +1266,11 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    public void notifyFinished(InsetsAnimationControlRunner runner, boolean shown) {
        cancelAnimation(runner, false /* invokeCallback */);
        if (DEBUG) Log.d(TAG, "notifyFinished. shown: " + shown);
        if (runner.getAnimationType() == ANIMATION_TYPE_RESIZE) {
            // The resize animation doesn't show or hide the insets. We shouldn't change the
            // requested visibility.
            return;
        }
        if (shown) {
            showDirectly(runner.getTypes(), true /* fromIme */);
        } else {
+3 −0
Original line number Diff line number Diff line
@@ -131,6 +131,9 @@ public class InsetsResizeAnimationRunner implements InsetsAnimationControlRunner

    @Override
    public boolean applyChangeInsets(InsetsState outState) {
        if (mCancelled) {
            return false;
        }
        final float fraction = mAnimation.getInterpolatedFraction();
        for (@InternalInsetsType int type = 0; type < InsetsState.SIZE; type++) {
            final InsetsSource fromSource = mFromState.peekSource(type);
+91 −54
Original line number Diff line number Diff line
@@ -767,6 +767,12 @@ public final class ViewRootImpl implements ViewParent,
     */
    private boolean mWaitForBlastSyncComplete = false;

    /**
     * Keeps track of the last frame number that was attempted to draw. Should only be accessed on
     * the RenderThread.
     */
    private long mRtLastAttemptedDrawFrameNum = 0;

    /**
     * Keeps track of whether a traverse was triggered while the UI thread was paused. This can
     * occur when the client is waiting on another process to submit the transaction that
@@ -4051,73 +4057,112 @@ public final class ViewRootImpl implements ViewParent,
    }

    /**
     * The callback will run on the render thread.
     * Only call this on the UI Thread.
     */
    private HardwareRenderer.FrameCompleteCallback createFrameCompleteCallback(Handler handler,
            boolean reportNextDraw, ArrayList<Runnable> commitCallbacks) {
        final Consumer<SurfaceControl.Transaction> blastSyncConsumer = mBLASTDrawConsumer;
        mBLASTDrawConsumer = null;
        return frameNr -> {
    void clearBlastSync() {
        mNextDrawUseBlastSync = false;
        mWaitForBlastSyncComplete = false;
        if (DEBUG_BLAST) {
            Log.d(mTag, "Scheduling a traversal=" + mRequestedTraverseWhilePaused
                    + " due to a previous skipped traversal.");
        }
        if (mRequestedTraverseWhilePaused) {
            mRequestedTraverseWhilePaused = false;
            scheduleTraversals();
        }
    }

    /**
     * @hide
     */
    public boolean isHardwareEnabled() {
        return mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.isEnabled();
    }

    private boolean addFrameCompleteCallbackIfNeeded(boolean reportNextDraw) {
        if (!isHardwareEnabled()) {
            return false;
        }

        if (!mNextDrawUseBlastSync && !reportNextDraw) {
            return false;
        }

        if (DEBUG_BLAST) {
                Log.d(mTag, "Received frameCompleteCallback frameNum=" + frameNr);
            Log.d(mTag, "Creating frameCompleteCallback");
        }

            handler.postAtFrontOfQueue(() -> {
        mAttachInfo.mThreadedRenderer.setFrameCompleteCallback(() -> {
            long frameNr = mBlastBufferQueue.getLastAcquiredFrameNum();
            if (DEBUG_BLAST) {
                Log.d(mTag, "Received frameCompleteCallback "
                        + " lastAcquiredFrameNum=" + frameNr
                        + " lastAttemptedDrawFrameNum=" + mRtLastAttemptedDrawFrameNum);
            }

            boolean frameWasNotDrawn = frameNr != mRtLastAttemptedDrawFrameNum;
            // If frame wasn't drawn, clear out the next transaction so it doesn't affect the next
            // draw attempt. The next transaction and transaction complete callback were only set
            // for the current draw attempt.
            if (frameWasNotDrawn) {
                mBlastBufferQueue.setNextTransaction(null);
                mBlastBufferQueue.setTransactionCompleteCallback(mRtLastAttemptedDrawFrameNum,
                        null);
            }

            mHandler.postAtFrontOfQueue(() -> {
                if (mNextDrawUseBlastSync) {
                    // We don't need to synchronize mRtBLASTSyncTransaction here since we're
                    // guaranteed that this is called after onFrameDraw and mNextDrawUseBlastSync
                    // is only true when the UI thread is paused. Therefore, no one should be
                    // modifying this object until the next vsync.
                    mSurfaceChangedTransaction.merge(mRtBLASTSyncTransaction);
                    if (blastSyncConsumer != null) {
                        blastSyncConsumer.accept(mSurfaceChangedTransaction);
                    if (mBLASTDrawConsumer != null) {
                        mBLASTDrawConsumer.accept(mSurfaceChangedTransaction);
                    }
                    mBLASTDrawConsumer = null;
                }

                if (reportNextDraw) {
                    // TODO: Use the frame number
                    pendingDrawFinished();
                }
                if (commitCallbacks != null) {
                    for (int i = 0; i < commitCallbacks.size(); i++) {
                        commitCallbacks.get(i).run();
                    }

                if (frameWasNotDrawn) {
                    clearBlastSync();
                }
            });
        };
    }

    /**
     * @hide
     */
    public boolean isHardwareEnabled() {
        return mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.isEnabled();
        });
        return true;
    }

    private boolean addFrameCompleteCallbackIfNeeded() {
    private void addFrameCommitCallbackIfNeeded() {
        if (!isHardwareEnabled()) {
            return false;
            return;
        }

        ArrayList<Runnable> commitCallbacks = mAttachInfo.mTreeObserver
                .captureFrameCommitCallbacks();
        final boolean needFrameCompleteCallback =
                mNextDrawUseBlastSync || mReportNextDraw
                        || (commitCallbacks != null && commitCallbacks.size() > 0);
        if (needFrameCompleteCallback) {
            if (DEBUG_BLAST) {
                Log.d(mTag, "Creating frameCompleteCallback"
                        + " mNextDrawUseBlastSync=" + mNextDrawUseBlastSync
                        + " mReportNextDraw=" + mReportNextDraw
                        + " commitCallbacks size="
                        + (commitCallbacks == null ? 0 : commitCallbacks.size()));
            }
            mAttachInfo.mThreadedRenderer.setFrameCompleteCallback(
                    createFrameCompleteCallback(mAttachInfo.mHandler, mReportNextDraw,
                            commitCallbacks));
            return true;
        final boolean needFrameCommitCallback =
                (commitCallbacks != null && commitCallbacks.size() > 0);
        if (!needFrameCommitCallback) {
            return;
        }
        return false;

        if (DEBUG_DRAW) {
            Log.d(mTag, "Creating frameCommitCallback"
                    + " commitCallbacks size=" + commitCallbacks.size());
        }
        mAttachInfo.mThreadedRenderer.setFrameCommitCallback(didProduceBuffer -> {
            if (DEBUG_DRAW) {
                Log.d(mTag, "Received frameCommitCallback didProduceBuffer=" + didProduceBuffer);
            }

            mHandler.postAtFrontOfQueue(() -> {
                for (int i = 0; i < commitCallbacks.size(); i++) {
                    commitCallbacks.get(i).run();
                }
            });
        });
    }

    private void addFrameCallbackIfNeeded() {
@@ -4147,6 +4192,8 @@ public final class ViewRootImpl implements ViewParent,
                        + " Creating transactionCompleteCallback=" + nextDrawUseBlastSync);
            }

            mRtLastAttemptedDrawFrameNum = frame;

            if (needsCallbackForBlur) {
                mBlurRegionAggregator
                    .dispatchBlurTransactionIfNeeded(frame, blurRegionsForFrame, hasBlurUpdates);
@@ -4169,18 +4216,7 @@ public final class ViewRootImpl implements ViewParent,
                    if (DEBUG_BLAST) {
                        Log.d(mTag, "Received transactionCompleteCallback frameNum=" + frame);
                    }
                    mHandler.postAtFrontOfQueue(() -> {
                        mNextDrawUseBlastSync = false;
                        mWaitForBlastSyncComplete = false;
                        if (DEBUG_BLAST) {
                            Log.d(mTag, "Scheduling a traversal=" + mRequestedTraverseWhilePaused
                                    + " due to a previous skipped traversal.");
                        }
                        if (mRequestedTraverseWhilePaused) {
                            mRequestedTraverseWhilePaused = false;
                            scheduleTraversals();
                        }
                    });
                    mHandler.postAtFrontOfQueue(this::clearBlastSync);
                });
            }
        };
@@ -4201,8 +4237,9 @@ public final class ViewRootImpl implements ViewParent,
        mIsDrawing = true;
        Trace.traceBegin(Trace.TRACE_TAG_VIEW, "draw");

        boolean usingAsyncReport = addFrameCompleteCallbackIfNeeded();
        addFrameCallbackIfNeeded();
        addFrameCommitCallbackIfNeeded();
        boolean usingAsyncReport = addFrameCompleteCallbackIfNeeded(mReportNextDraw);

        try {
            boolean canUseAsync = draw(fullRedrawNeeded);
+7 −1
Original line number Diff line number Diff line
@@ -134,6 +134,11 @@ static void nativeSetTransactionCompleteCallback(JNIEnv* env, jclass clazz, jlon
    }
}

static jlong nativeGetLastAcquiredFrameNum(JNIEnv* env, jclass clazz, jlong ptr) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    return queue->getLastAcquiredFrameNum();
}

static const JNINativeMethod gMethods[] = {
        /* name, signature, funcPtr */
        // clang-format off
@@ -145,7 +150,8 @@ static const JNINativeMethod gMethods[] = {
        {"nativeMergeWithNextTransaction", "(JJJ)V", (void*)nativeMergeWithNextTransaction},
        {"nativeSetTransactionCompleteCallback",
                "(JJLandroid/graphics/BLASTBufferQueue$TransactionCompleteCallback;)V",
                (void*)nativeSetTransactionCompleteCallback}
                (void*)nativeSetTransactionCompleteCallback},
        {"nativeGetLastAcquiredFrameNum", "(J)J", (void*)nativeGetLastAcquiredFrameNum},
        // clang-format on
};

+22 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <vector>

#include <android-base/logging.h>
#include <android-base/properties.h>
#include <bionic/malloc.h>
#include <debuggerd/client.h>
#include <log/log.h>
@@ -859,7 +860,22 @@ static jlong android_os_Debug_getDmabufHeapPoolsSizeKb(JNIEnv* env, jobject claz
    return poolsSizeKb;
}

static bool halSupportsGpuPrivateMemory() {
    int productApiLevel =
            android::base::GetIntProperty("ro.product.first_api_level",
                                          android::base::GetIntProperty("ro.build.version.sdk",
                                                                         __ANDROID_API_FUTURE__));
    int boardApiLevel =
            android::base::GetIntProperty("ro.board.api_level",
                                          android::base::GetIntProperty("ro.board.first_api_level",
                                                                         __ANDROID_API_FUTURE__));

    return std::min(productApiLevel, boardApiLevel) >= __ANDROID_API_S__;
}

static jlong android_os_Debug_getGpuPrivateMemoryKb(JNIEnv* env, jobject clazz) {
    static bool gpuPrivateMemorySupported = halSupportsGpuPrivateMemory();

    struct memtrack_proc* p = memtrack_proc_new();
    if (p == nullptr) {
        LOG(ERROR) << "getGpuPrivateMemoryKb: Failed to create memtrack_proc";
@@ -876,6 +892,12 @@ static jlong android_os_Debug_getGpuPrivateMemoryKb(JNIEnv* env, jobject clazz)
    ssize_t gpuPrivateMem = memtrack_proc_gl_pss(p);

    memtrack_proc_destroy(p);

    // Old HAL implementations may return 0 for GPU private memory if not supported
    if (gpuPrivateMem == 0 && !gpuPrivateMemorySupported) {
        return -1;
    }

    return gpuPrivateMem / 1024;
}

Loading