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

Commit bac8706b authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Initialize GL even when HWUI is running Vulkan

Even though more and more devices are running Vulkan, many apps still
use GL, instead of or in addition to using HWUI. Initialize GL as part
of the zygote step. This only happens once at boot - new app processes
won't do this again, so it speeds up app startup time. And since it
happens before forking the zygote, it starts off in shared memory. If an
app never uses GL, it won't have to use any memory for this GL state.

Use a new static method on Properties, rather than a static bool, as is
done for several other properties, because this happens before loading
other properties.

Bug: 335172671
Test: manual verification via log statements
Flag: initialize_gl_always
Change-Id: I80b366121db0034131afb656ea774e37171f223b
parent 309fdfc8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ constexpr bool clip_surfaceviews() {
constexpr bool hdr_10bit_plus() {
    return false;
}
constexpr bool initialize_gl_always() {
    return false;
}
}  // namespace hwui_flags
#endif

@@ -257,5 +260,9 @@ bool Properties::isDrawingEnabled() {
    return drawingEnabled == DrawingEnabled::On;
}

bool Properties::initializeGlAlways() {
    return base::GetBoolProperty(PROPERTY_INITIALIZE_GL_ALWAYS, hwui_flags::initialize_gl_always());
}

}  // namespace uirenderer
}  // namespace android
+7 −0
Original line number Diff line number Diff line
@@ -229,6 +229,11 @@ enum DebugLevel {

#define PROPERTY_8BIT_HDR_HEADROOM "debug.hwui.8bit_hdr_headroom"

/**
 * Whether to initialize GL even when HWUI is running Vulkan.
 */
#define PROPERTY_INITIALIZE_GL_ALWAYS "debug.hwui.initialize_gl_always"

///////////////////////////////////////////////////////////////////////////////
// Misc
///////////////////////////////////////////////////////////////////////////////
@@ -368,6 +373,8 @@ public:
    static bool isDrawingEnabled();
    static void setDrawingEnabled(bool enable);

    static bool initializeGlAlways();

private:
    static StretchEffectBehavior stretchEffectBehavior;
    static ProfileType sProfileType;
+7 −0
Original line number Diff line number Diff line
@@ -90,3 +90,10 @@ flag {
  description: "Add canvas#drawRegion API"
  bug: "318612129"
}

flag {
  name: "initialize_gl_always"
  namespace: "core_graphics"
  description: "Initialize GL even when HWUI is set to use Vulkan. This improves app startup time for apps using GL."
  bug: "335172671"
}
+9 −0
Original line number Diff line number Diff line
@@ -192,5 +192,14 @@ void zygote_preload_graphics() {
        // Preload Vulkan driver if HWUI renders with Vulkan backend.
        uint32_t apiVersion;
        vkEnumerateInstanceVersion(&apiVersion);

        if (Properties::initializeGlAlways()) {
            // Even though HWUI is rendering with Vulkan, some apps still use
            // GL. Preload GL driver just in case. Since this happens prior to
            // forking from the zygote, apps that do not use GL are unaffected.
            // Any memory that (E)GL uses for this call is in shared memory,
            // and this call only happens once.
            eglGetDisplay(EGL_DEFAULT_DISPLAY);
        }
    }
}