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

Commit 389b0584 authored by Alex Careja's avatar Alex Careja
Browse files

Raise priority of RenderThread early during startup

Instead of raising the RenderThread priority after earlyPreloadGLContext is finished, retrieve the tid of the render thread while preloading and apply the priority boost to the RenderThread as soon as possible.

Flag: android.app.early_render_thread_priority_boost
Bug: 417909658
Change-Id: I82d7f131b16472a93622f31c8b906ae3695a18be
parent 7e1c1cad
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import static android.app.ActivityManager.PROCESS_STATE_UNKNOWN;
import static android.app.ConfigurationController.createNewConfigAndUpdateIfNotNull;
import static android.app.Flags.skipBgMemTrimOnFgApp;
import static android.app.Flags.earlyRenderThreadPriorityBoost;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.servertransaction.ActivityLifecycleItem.ON_CREATE;
@@ -4494,8 +4495,20 @@ public final class ActivityThread extends ClientTransactionHandler
        // Initialize before creating the activity
        if (ThreadedRenderer.sRendererEnabled
                && (r.activityInfo.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
            if (earlyRenderThreadPriorityBoost()) {
                final int tid = HardwareRenderer.preload();
                // Adjust the RenderThread priority as soon as it's created.
                if (tid > 0) {
                    try {
                        ActivityManager.getService().setRenderThread(tid);
                    } catch (Throwable t) {
                        Log.w(TAG, "Failed to set scheduler for RenderThread", t);
                    }
                }
            } else {
                HardwareRenderer.preload();
            }
        }
        WindowManagerGlobal.initialize();

        // Hint the GraphicsEnvironment that an activity is launching on the process.
+10 −0
Original line number Diff line number Diff line
@@ -151,3 +151,13 @@ flag {
         purpose: PURPOSE_BUGFIX
     }
}

flag {
     namespace: "system_performance"
     name: "early_render_thread_priority_boost"
     description: "Boost the render thread priority during preload."
     bug: "417909658"
     metadata {
         purpose: PURPOSE_BUGFIX
     }
}
+6 −2
Original line number Diff line number Diff line
@@ -1421,7 +1421,9 @@ public class HardwareRenderer {
            if (mInitialized) return;
            mInitialized = true;

            if (!android.app.Flags.earlyRenderThreadPriorityBoost()) {
                initSched(renderProxy);
            }
            initGraphicsStats();
        }

@@ -1565,9 +1567,11 @@ public class HardwareRenderer {
     * its first frame adds directly to user-visible app launch latency.
     *
     * Should only be called after GraphicsEnvironment.chooseDriver().
     *
     * @return the tid of the RenderThread.
     * @hide
     */
    public static native void preload();
    public static native int preload();

    /**
     * Initialize the Buffer Allocator singleton
+3 −3
Original line number Diff line number Diff line
@@ -854,8 +854,8 @@ static void android_view_ThreadedRenderer_setForceDark(JNIEnv* env, jobject claz
    proxy->setForceDark(static_cast<ForceDarkType>(type));
}

static void android_view_ThreadedRenderer_preload(JNIEnv*, jclass) {
    RenderProxy::preload();
static int android_view_ThreadedRenderer_preload(JNIEnv*, jclass) {
    return RenderProxy::preload();
}

static void android_view_ThreadedRenderer_preInitBufferAllocator(JNIEnv*, jclass) {
@@ -1066,7 +1066,7 @@ static const JNINativeMethod gMethods[] = {
        {"nSetDisplayDensityDpi", "(I)V",
         (void*)android_view_ThreadedRenderer_setDisplayDensityDpi},
        {"nInitDisplayInfo", "(IIFIJJZZZ)V", (void*)android_view_ThreadedRenderer_initDisplayInfo},
        {"preload", "()V", (void*)android_view_ThreadedRenderer_preload},
        {"preload", "()I", (void*)android_view_ThreadedRenderer_preload},
        {"preInitBufferAllocator", "()V",
         (void*)android_view_ThreadedRenderer_preInitBufferAllocator},
        {"isWebViewOverlaysEnabled", "()Z",
+7 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <SkPicture.h>
#include <gui/TraceUtils.h>
#include <pthread.h>
#include "utils/Thread.h"

#ifdef __ANDROID__
#include <gui/SurfaceControl.h>
@@ -504,10 +505,15 @@ void RenderProxy::disableVsync() {
    Properties::disableVsync = true;
}

void RenderProxy::preload() {
int RenderProxy::preload() {
    // Create RenderThread object and start the thread. Then preload Vulkan/EGL driver.
    auto& thread = RenderThread::getInstance();
    thread.queue().post([&thread]() { thread.preload(); });
#ifdef __ANDROID__
    return thread.getTid();
#else
    return 0;
#endif
}

void RenderProxy::setRtAnimationsEnabled(bool enabled) {
Loading