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
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index 325bdd6..5d3bc89 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -39,6 +39,9 @@
constexpr bool hdr_10bit_plus() {
return false;
}
+constexpr bool initialize_gl_always() {
+ return false;
+}
} // namespace hwui_flags
#endif
@@ -257,5 +260,9 @@
return drawingEnabled == DrawingEnabled::On;
}
+bool Properties::initializeGlAlways() {
+ return base::GetBoolProperty(PROPERTY_INITIALIZE_GL_ALWAYS, hwui_flags::initialize_gl_always());
+}
+
} // namespace uirenderer
} // namespace android
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index c1510d9..d3176f6 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -229,6 +229,11 @@
#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 @@
static bool isDrawingEnabled();
static void setDrawingEnabled(bool enable);
+ static bool initializeGlAlways();
+
private:
static StretchEffectBehavior stretchEffectBehavior;
static ProfileType sProfileType;
diff --git a/libs/hwui/aconfig/hwui_flags.aconfig b/libs/hwui/aconfig/hwui_flags.aconfig
index 50f8b39..cd3ae53 100644
--- a/libs/hwui/aconfig/hwui_flags.aconfig
+++ b/libs/hwui/aconfig/hwui_flags.aconfig
@@ -90,3 +90,10 @@
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"
+}
diff --git a/libs/hwui/apex/jni_runtime.cpp b/libs/hwui/apex/jni_runtime.cpp
index 6ace396..15b2bac 100644
--- a/libs/hwui/apex/jni_runtime.cpp
+++ b/libs/hwui/apex/jni_runtime.cpp
@@ -192,5 +192,14 @@
// 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);
+ }
}
}