Switch RenderThread to a Java daemon thread
Bug: 69962494 Test: device boots, hwui unit tests pass Change-Id: I9d5f2fccebf845328914c82aa97285cf605a4354
This commit is contained in:
@@ -1043,7 +1043,22 @@ static const JNINativeMethod gMethods[] = {
|
||||
{ "nSetHighContrastText", "(Z)V", (void*)android_view_ThreadedRenderer_setHighContrastText },
|
||||
};
|
||||
|
||||
static JavaVM* mJvm = nullptr;
|
||||
|
||||
static void attachRenderThreadToJvm() {
|
||||
LOG_ALWAYS_FATAL_IF(!mJvm, "No jvm but we set the hook??");
|
||||
|
||||
JavaVMAttachArgs args;
|
||||
args.version = JNI_VERSION_1_4;
|
||||
args.name = (char*) "RenderThread";
|
||||
args.group = NULL;
|
||||
JNIEnv* env;
|
||||
mJvm->AttachCurrentThreadAsDaemon(&env, (void*) &args);
|
||||
}
|
||||
|
||||
int register_android_view_ThreadedRenderer(JNIEnv* env) {
|
||||
env->GetJavaVM(&mJvm);
|
||||
RenderThread::setOnStartHook(&attachRenderThreadToJvm);
|
||||
jclass observerClass = FindClassOrDie(env, "android/view/FrameMetricsObserver");
|
||||
gFrameMetricsObserverClassInfo.frameMetrics = GetFieldIDOrDie(
|
||||
env, observerClass, "mFrameMetrics", "Landroid/view/FrameMetrics;");
|
||||
|
||||
@@ -51,10 +51,17 @@ static const nsecs_t DISPATCH_FRAME_CALLBACKS_DELAY = milliseconds_to_nanosecond
|
||||
|
||||
static bool gHasRenderThreadInstance = false;
|
||||
|
||||
static void (*gOnStartHook)() = nullptr;
|
||||
|
||||
bool RenderThread::hasInstance() {
|
||||
return gHasRenderThreadInstance;
|
||||
}
|
||||
|
||||
void RenderThread::setOnStartHook(void (*onStartHook)()) {
|
||||
LOG_ALWAYS_FATAL_IF(hasInstance(), "can't set an onStartHook after we've started...");
|
||||
gOnStartHook = onStartHook;
|
||||
}
|
||||
|
||||
RenderThread& RenderThread::getInstance() {
|
||||
// This is a pointer because otherwise __cxa_finalize
|
||||
// will try to delete it like a Good Citizen but that causes us to crash
|
||||
@@ -256,6 +263,9 @@ void RenderThread::requestVsync() {
|
||||
|
||||
bool RenderThread::threadLoop() {
|
||||
setpriority(PRIO_PROCESS, 0, PRIORITY_DISPLAY);
|
||||
if (gOnStartHook) {
|
||||
gOnStartHook();
|
||||
}
|
||||
initThreadLocals();
|
||||
|
||||
while (true) {
|
||||
|
||||
@@ -67,6 +67,9 @@ class RenderThread : private ThreadBase {
|
||||
PREVENT_COPY_AND_ASSIGN(RenderThread);
|
||||
|
||||
public:
|
||||
// Sets a callback that fires before any RenderThread setup has occured.
|
||||
ANDROID_API static void setOnStartHook(void (*onStartHook)());
|
||||
|
||||
WorkQueue& queue() { return ThreadBase::queue(); }
|
||||
|
||||
// Mimics android.view.Choreographer
|
||||
|
||||
@@ -31,7 +31,10 @@ class ThreadBase : protected Thread {
|
||||
PREVENT_COPY_AND_ASSIGN(ThreadBase);
|
||||
|
||||
public:
|
||||
ThreadBase() : mLooper(new Looper(false)), mQueue([this]() { mLooper->wake(); }, mLock) {}
|
||||
ThreadBase()
|
||||
: Thread(false)
|
||||
, mLooper(new Looper(false))
|
||||
, mQueue([this]() { mLooper->wake(); }, mLock) {}
|
||||
|
||||
WorkQueue& queue() { return mQueue; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user