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

Commit 2110ae22 authored by Shadman Shadid's avatar Shadman Shadid Committed by Android (Google) Code Review
Browse files

Merge "preload Buffer Allocator instance on the ViewRootImpl init" into main

parents badf1452 d9583094
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -537,6 +537,11 @@ public final class ViewRootImpl implements ViewParent,
     */
    private static boolean sAlwaysAssignFocus;
    /**
     * whether we pre-initialized the Buffer Allocator
     */
    private static boolean sPreInitializedBufferAllocator = false;
    /**
     * This list must only be modified by the main thread.
     */
@@ -1342,6 +1347,11 @@ public final class ViewRootImpl implements ViewParent,
                com.android.server.display.feature.flags.Flags.subscribeGranularDisplayEvents();
        mSendPerfHintOnTouch = adpfViewrootimplActionDownBoost();
        if (!sPreInitializedBufferAllocator) {
            preInitBufferAllocator();
            sPreInitializedBufferAllocator = true;
        }
    }
    public static void addFirstDrawHandler(Runnable callback) {
@@ -13562,4 +13572,10 @@ public final class ViewRootImpl implements ViewParent,
            sProtoLogInitialized = true;
        }
    }
    private void preInitBufferAllocator() {
        if (com.android.graphics.hwui.flags.Flags.earlyPreinitBufferAllocator()) {
            ThreadedRenderer.preInitBufferAllocator();
        }
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -1466,6 +1466,18 @@ public class HardwareRenderer {
     */
    public static native void preload();

    /**
     * Initialize the Buffer Allocator singleton
     *
     * This takes 10-20ms on low-resourced devices, so doing it on-demand when an app
     * tries to render its first frame causes drawFrames to be blocked for buffer
     * allocation due to just initializing the allocator.
     *
     * Should only be called when a buffer is expected to be used.
     * @hide
     */
    public static native void preInitBufferAllocator();

    /**
     * @hide
     */
+9 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ flag {
flag {
  name: "early_preload_gl_context"
  namespace: "core_graphics"
  description: "Initialize GL context and GraphicBufferAllocater init on renderThread preload. This improves app startup time for apps using GL."
  description: "Preload GL context on renderThread preload. This improves app startup time for apps using GL."
  bug: "383612849"
}

@@ -188,3 +188,11 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "early_preinit_buffer_allocator"
  namespace: "core_graphics"
  description: "Initialize GraphicBufferAllocater on ViewRootImpl init, to avoid blocking on init during buffer allocation, improving app launch latency."
  bug: "389908734"
  is_fixed_read_only: true
}
 No newline at end of file
+16 −0
Original line number Diff line number Diff line
@@ -52,6 +52,9 @@
#include <renderthread/RenderThread.h>
#include <src/image/SkImage_Base.h>
#include <thread/CommonPool.h>
#ifdef __ANDROID__
#include <ui/GraphicBufferAllocator.h>
#endif
#include <utils/Color.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
@@ -849,6 +852,17 @@ static void android_view_ThreadedRenderer_preload(JNIEnv*, jclass) {
    RenderProxy::preload();
}

static void android_view_ThreadedRenderer_preInitBufferAllocator(JNIEnv*, jclass) {
#ifdef __ANDROID__
    CommonPool::async([] {
        ATRACE_NAME("preInitBufferAllocator:GraphicBufferAllocator");
        // This involves several binder calls which we do not want blocking
        // critical path of the activity that is launching.
        GraphicBufferAllocator::getInstance();
    });
#endif
}

static void android_view_ThreadedRenderer_setRtAnimationsEnabled(JNIEnv* env, jobject clazz,
                                                                 jboolean enabled) {
    RenderProxy::setRtAnimationsEnabled(enabled);
@@ -1040,6 +1054,8 @@ static const JNINativeMethod gMethods[] = {
         (void*)android_view_ThreadedRenderer_setDisplayDensityDpi},
        {"nInitDisplayInfo", "(IIFIJJZZZ)V", (void*)android_view_ThreadedRenderer_initDisplayInfo},
        {"preload", "()V", (void*)android_view_ThreadedRenderer_preload},
        {"preInitBufferAllocator", "()V",
         (void*)android_view_ThreadedRenderer_preInitBufferAllocator},
        {"isWebViewOverlaysEnabled", "()Z",
         (void*)android_view_ThreadedRenderer_isWebViewOverlaysEnabled},
        {"nSetDrawingEnabled", "(Z)V", (void*)android_view_ThreadedRenderer_setDrawingEnabled},