From 978a2cc477a5461b238985a66cd32a47307e733b Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Tue, 12 May 2020 22:51:15 -0700 Subject: [PATCH] Initialize DeviceInfo earlier. DMS should be queried before RenderProxy is first created. Otherwise JankTracker will be initialized with bad offset information, which breaks the dequeue time forgiveness checks and causes apps to report longer rendering times than they should. Also, fix the default for the presentation deadline - the default should align with SF's offset to be 0 Bug: 155490805 Test: builds, boots, verified that offsets are plumbed at the right time. Test: quickstep benchmark shows improved jank numbers Change-Id: I51538a02969eb312df40cad5df48619433056de9 --- graphics/java/android/graphics/HardwareRenderer.java | 8 ++++++-- libs/hwui/DeviceInfo.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/graphics/java/android/graphics/HardwareRenderer.java b/graphics/java/android/graphics/HardwareRenderer.java index bfe7443915d54..87060ca57e977 100644 --- a/graphics/java/android/graphics/HardwareRenderer.java +++ b/graphics/java/android/graphics/HardwareRenderer.java @@ -165,6 +165,7 @@ public class HardwareRenderer { * to opaque with no light source configured. */ public HardwareRenderer() { + ProcessInitializer.sInstance.initDisplayInfo(); mRootNode = RenderNode.adopt(nCreateRootRenderNode()); mRootNode.setClipToBounds(false); mNativeProxy = nCreateProxy(!mOpaque, mIsWideGamut, mRootNode.mNativeRenderNode); @@ -1051,6 +1052,7 @@ public class HardwareRenderer { } private boolean mInitialized = false; + private boolean mDisplayInitialized = false; private boolean mIsolated = false; private Context mContext; @@ -1087,7 +1089,6 @@ public class HardwareRenderer { initSched(renderProxy); initGraphicsStats(); - initDisplayInfo(); } private void initSched(long renderProxy) { @@ -1112,7 +1113,8 @@ public class HardwareRenderer { } } - private void initDisplayInfo() { + synchronized void initDisplayInfo() { + if (mDisplayInitialized) return; if (mContext == null) return; // If we're in an isolated sandbox mode then we shouldn't try to communicate with DMS @@ -1120,6 +1122,7 @@ public class HardwareRenderer { // Defensively clear out the context in case we were passed a context that can leak // if we live longer than it, e.g. an activity context. mContext = null; + mDisplayInitialized = true; return; } @@ -1162,6 +1165,7 @@ public class HardwareRenderer { // Defensively clear out the context mContext = null; + mDisplayInitialized = true; } private void rotateBuffer() { diff --git a/libs/hwui/DeviceInfo.h b/libs/hwui/DeviceInfo.h index 191dcd89a0263..27be622699598 100644 --- a/libs/hwui/DeviceInfo.h +++ b/libs/hwui/DeviceInfo.h @@ -95,7 +95,8 @@ private: int32_t mWidth = 1080; int32_t mHeight = 1920; int64_t mVsyncPeriod = 16666666; - int64_t mPresentationDeadlineNanos = 0; + // Magically corresponds with an sf offset of 0 for a sane default. + int64_t mPresentationDeadlineNanos = 17666666; int64_t mAppVsyncOffsetNanos = 0; // Density is not retrieved from the ADisplay apis, so this may potentially