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

Commit c37984f1 authored by Jesse Hall's avatar Jesse Hall
Browse files

Init EGL only for HW-accelerated Activities

Most processes might end up using  EGL, but most don't except for
Activities with HW-accelerated UI. And for other cases, the startup
latency of initializing EGL on-demand isn't as important. So this
change only tries to early-initialize EGL for HWUI Activities.

It also fixes a logic problem that may or not have been an actual bug:
previously, we only chose a graphics driver if we successfully set up
shader cache directories, even though these are mostly unrelated. Now
we always choose a graphics driver, except in isolated processes that
can't use graphics.

Bug: 38215658
Test: systrace framework start and Clock launch, check eglGetDisplay
      is called by RenderThread in non-HWUI-Activity cases, and is
      called on a separate thread before RenderThread needs it for
      HWUI-Activity cases.
Change-Id: I101e5578a9d7c508d232d0edeed7ceff9d8a74d6
parent 317fa5a9
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -2890,6 +2890,9 @@ public final class ActivityThread {
            TAG, "Handling launch of " + r);

        // Initialize before creating the activity
        if (!ThreadedRenderer.sRendererDisabled) {
            GraphicsEnvironment.earlyInitEGL();
        }
        WindowManagerGlobal.initialize();

        Activity a = performLaunchActivity(r, customIntent);
@@ -5401,7 +5404,6 @@ public final class ActivityThread {
                    if (packages != null) {
                        ThreadedRenderer.setupDiskCache(cacheDir);
                        RenderScriptCacheDir.setupDiskCache(cacheDir);
                        GraphicsEnvironment.setupGraphicsEnvironment(context);
                    }
                } catch (RemoteException e) {
                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
@@ -5412,6 +5414,7 @@ public final class ActivityThread {
            }
        }

        GraphicsEnvironment.chooseDriver(context);
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    }

+19 −11
Original line number Diff line number Diff line
@@ -35,12 +35,12 @@ public final class GraphicsEnvironment {
    private static final String TAG = "GraphicsEnvironment";
    private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0";

    public static void setupGraphicsEnvironment(Context context) {
        chooseDriver(context);
        earlyInitEGL();
    }

    private static void chooseDriver(Context context) {
    /**
     * Choose whether the current process should use the builtin or an updated driver.
     *
     * @hide
     */
    public static void chooseDriver(Context context) {
        String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER);
        if (driverPackageName == null || driverPackageName.isEmpty()) {
            return;
@@ -90,11 +90,19 @@ public final class GraphicsEnvironment {
        setDriverPath(paths);
    }

    private static void earlyInitEGL() {
        // Once we've figured out which driver to use for this process, load and initialize it.
        // This can take multiple frame periods, and it would otherwise happen as part of the first
        // frame, increasing first-frame latency. Starting it here means that it's usually done
        // long before we start drawing the first frame.
    /**
     * Start a background thread to initialize EGL.
     *
     * Initializing EGL involves loading and initializing the graphics driver. Some drivers take
     * several 10s of milliseconds to do this, so doing it on-demand when an app tries to render
     * its first frame adds directly to user-visible app launch latency. By starting it earlier
     * on a separate thread, it can usually be finished well before the UI is ready to be drawn.
     *
     * Should only be called after chooseDriver().
     *
     * @hide
     */
    public static void earlyInitEGL() {
        Thread eglInitThread = new Thread(
                () -> {
                    EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);