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

Commit 3ada4be7 authored by Tracy Zhou's avatar Tracy Zhou Committed by Android (Google) Code Review
Browse files

Merge changes If764dcff,I30063c7a into main

* changes:
  Send GPU_LOAD_UP hint when blurring
  Support sending GPU_LOAD_UP hint from ViewRootImpl
parents af81f5ac 3f375e0f
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ import static android.view.accessibility.Flags.forceInvertColor;
import static android.view.accessibility.Flags.reduceWindowContentChangedEventThrottle;
import static android.view.flags.Flags.addSchandleToVriSurface;
import static android.view.flags.Flags.disableDrawWakeLock;
import static android.view.flags.Flags.notifyGpuLoadUp;
import static android.view.flags.Flags.sensitiveContentAppProtection;
import static android.view.flags.Flags.sensitiveContentPrematureProtectionRemovedFix;
import static android.view.flags.Flags.toolkitFrameRateDebug;
@@ -3012,6 +3013,21 @@ public final class ViewRootImpl implements ViewParent,
        }
    }
    /**
     * Notifies the HardwareRenderer that upcoming frames need to increase the
     * GPU work load for speedup the rendering.
     *
     * @hide
     */
    public void notifyRendererForGpuLoadUp(String reason) {
        if (!notifyGpuLoadUp()) {
            return;
        }
        if (mAttachInfo.mThreadedRenderer != null) {
            mAttachInfo.mThreadedRenderer.notifyRendererForGpuLoadUp(reason);
        }
    }
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    void scheduleTraversals() {
        if (!mTraversalScheduled) {
+44 −23
Original line number Diff line number Diff line
@@ -192,8 +192,11 @@ public class HardwareRenderer {
    private @ActivityInfo.ColorMode int mColorMode = ActivityInfo.COLOR_MODE_DEFAULT;
    private float mDesiredSdrHdrRatio = 1f;

    private final NotifyRendererRateLimiter mNotifyRendererWorkLoadRateLimiter =
            createNotifyRendererRateLimiter();
    private final NotifyRendererRateLimiter mNotifyExpensiveFrameRateLimiter =
            createNotifyRendererRateLimiter("notifyExpensiveFrame", this::notifyExpensiveFrame);

    private final NotifyRendererRateLimiter mNotifyGpuLoadUpRateLimiter =
            createNotifyRendererRateLimiter("notifyGpuLoadUp", this::notifyGpuLoadUp);

    /**
     * A class for rate limiting of notifying renderer IPC invocation (e.g. notifyExpensiveFrame)
@@ -201,16 +204,32 @@ public class HardwareRenderer {
     */
    private static class NotifyRendererRateLimiter extends RateLimitingCache<Void> {
        private static final long DEFAULT_NOTIFY_PERIOD_MILLIS = 100;

        private final @NonNull RateLimitingCache.ValueFetcher<Void> mNotifyRendererRunnable;
        private final @NonNull Runnable mRunnable;

        /** Counts when the rate limiter permits to notify the renderer */
        private int mNotifyCount;
        private @Nullable String mNotifyReason;

        NotifyRendererRateLimiter(@NonNull RateLimitingCache.ValueFetcher<Void> runnable,
        NotifyRendererRateLimiter(String reason, @NonNull Runnable runnable,
                long periodMillis) {
            super(periodMillis);
            mNotifyRendererRunnable = runnable;

            mRunnable = runnable;
            mNotifyRendererRunnable = () -> {
                final String notifyReason = getNotifyReason();
                final boolean logForReason = notifyReason != null && !notifyReason.isEmpty();
                try {
                    final String traceReason = logForReason ? reason + ":" + notifyReason : reason;
                    Trace.traceBegin(Trace.TRACE_TAG_VIEW, traceReason);
                    mRunnable.run();
                } finally {
                    Trace.traceEnd(Trace.TRACE_TAG_VIEW);
                }
                incrementNotifyCount();
                return null;
            };
        }

        private int notifyIfAllow(String reason) {
@@ -228,24 +247,10 @@ public class HardwareRenderer {
        }
    }

    private NotifyRendererRateLimiter getNotifyRendererRateLimiter() {
        return mNotifyRendererWorkLoadRateLimiter;
    }

    private NotifyRendererRateLimiter createNotifyRendererRateLimiter() {
        return new NotifyRendererRateLimiter(() -> {
            final String notifyReason = getNotifyRendererRateLimiter().getNotifyReason();
            final boolean logForReason = notifyReason != null && !notifyReason.isEmpty();
            try {
                final String traceReason = logForReason ? notifyReason : "notifyExpensiveFrame";
                Trace.traceBegin(Trace.TRACE_TAG_VIEW, traceReason);
                notifyExpensiveFrame();
            } finally {
                Trace.traceEnd(Trace.TRACE_TAG_VIEW);
            }
            getNotifyRendererRateLimiter().incrementNotifyCount();
            return null;
        }, NotifyRendererRateLimiter.DEFAULT_NOTIFY_PERIOD_MILLIS);
    private NotifyRendererRateLimiter createNotifyRendererRateLimiter(String reason,
            Runnable runnable) {
        return new NotifyRendererRateLimiter(reason, runnable,
                NotifyRendererRateLimiter.DEFAULT_NOTIFY_PERIOD_MILLIS);
    }

    /**
@@ -1118,7 +1123,21 @@ public class HardwareRenderer {
     * @hide
     */
    public int notifyExpensiveFrameWithRateLimit(String reason) {
        return mNotifyRendererWorkLoadRateLimiter.notifyIfAllow(reason);
        return mNotifyExpensiveFrameRateLimiter.notifyIfAllow(reason);
    }

    /**
     * Notifies the HardwareRenderer that upcoming frames need to increase the
     * GPU work load for speedup the rendering.
     *
     * @hide
     */
    public int notifyRendererForGpuLoadUp(String reason) {
        return mNotifyGpuLoadUpRateLimiter.notifyIfAllow(reason);
    }

    private void notifyGpuLoadUp() {
        nNotifyGpuLoadUp(mNativeProxy);
    }

    /**
@@ -1720,4 +1739,6 @@ public class HardwareRenderer {
    private static native void nNotifyCallbackPending(long nativeProxy);

    private static native void nNotifyExpensiveFrame(long nativeProxy);

    private static native void nNotifyGpuLoadUp(long nativeProxy);
}
+7 −0
Original line number Diff line number Diff line
@@ -882,6 +882,11 @@ static void android_view_ThreadedRenderer_notifyExpensiveFrame(JNIEnv*, jclass,
    proxy->notifyExpensiveFrame();
}

static void android_view_ThreadedRenderer_notifyGpuLoadUp(JNIEnv*, jclass, jlong proxyPtr) {
    RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
    proxy->notifyGpuLoadUp();
}

// Plumbs the display density down to DeviceInfo.
static void android_view_ThreadedRenderer_setDisplayDensityDpi(JNIEnv*, jclass, jint densityDpi) {
    // Convert from dpi to density-independent pixels.
@@ -1072,6 +1077,8 @@ static const JNINativeMethod gMethods[] = {
         (void*)android_view_ThreadedRenderer_notifyCallbackPending},
        {"nNotifyExpensiveFrame", "(J)V",
         (void*)android_view_ThreadedRenderer_notifyExpensiveFrame},
        {"nNotifyGpuLoadUp", "(J)V",
         (void*)android_view_ThreadedRenderer_notifyGpuLoadUp},
        {"nTrimCaches", "(I)V", (void*)android_view_ThreadedRenderer_trimCaches},
};

+4 −2
Original line number Diff line number Diff line
@@ -39,9 +39,11 @@ void HintSessionWrapper::updateTargetWorkDuration(long targetWorkDurationNanos)

void HintSessionWrapper::reportActualWorkDuration(long actualDurationNanos) {}

void HintSessionWrapper::sendLoadResetHint() {}
void HintSessionWrapper::sendCpuLoadResetHint() {}

void HintSessionWrapper::sendLoadIncreaseHint() {}
void HintSessionWrapper::sendCpuLoadIncreaseHint() {}

void HintSessionWrapper::sendGpuLoadIncreaseHint() {}

bool HintSessionWrapper::alive() {
    return false;
+9 −5
Original line number Diff line number Diff line
@@ -582,7 +582,7 @@ void CanvasContext::stopDrawing() {
void CanvasContext::notifyFramePending() {
    ATRACE_CALL();
    mRenderThread.pushBackFrameCallback(this);
    sendLoadResetHint();
    sendCpuLoadResetHint();
}

Frame CanvasContext::getFrame() {
@@ -1182,12 +1182,16 @@ void CanvasContext::prepareSurfaceControlForWebview() {
    }
}

void CanvasContext::sendLoadResetHint() {
    mHintSessionWrapper->sendLoadResetHint();
void CanvasContext::sendCpuLoadResetHint() {
    mHintSessionWrapper->sendCpuLoadResetHint();
}

void CanvasContext::sendLoadIncreaseHint() {
    mHintSessionWrapper->sendLoadIncreaseHint();
void CanvasContext::sendCpuLoadIncreaseHint() {
    mHintSessionWrapper->sendCpuLoadIncreaseHint();
}

void CanvasContext::sendGpuLoadIncreaseHint() {
    mHintSessionWrapper->sendGpuLoadIncreaseHint();
}

void CanvasContext::setSyncDelayDuration(nsecs_t duration) {
Loading