summaryrefslogtreecommitdiff
path: root/libs/hwui/renderthread/DrawFrameTask.cpp
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2021-04-11 23:06:44 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2021-04-11 23:06:44 +0000
commitbd33c1d7942f5aad3e313cbd447056b720d1149b (patch)
treec15000b5ed150231e7633f422a89a613d6584961 /libs/hwui/renderthread/DrawFrameTask.cpp
parent2946f76a85ed162fe5f401f5b2b47a79e8e79e5c (diff)
parent66915840539c1e0f82f440ef74cdf78cfeba00ec (diff)
Snap for 7274915 from 66915840539c1e0f82f440ef74cdf78cfeba00ec to sc-release
Change-Id: I20cdf6357254e01f42dc75a1cfb4fe74ad144cb4
Diffstat (limited to 'libs/hwui/renderthread/DrawFrameTask.cpp')
-rw-r--r--libs/hwui/renderthread/DrawFrameTask.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/libs/hwui/renderthread/DrawFrameTask.cpp b/libs/hwui/renderthread/DrawFrameTask.cpp
index 3408ffda3f9d..7a38a3bc9c05 100644
--- a/libs/hwui/renderthread/DrawFrameTask.cpp
+++ b/libs/hwui/renderthread/DrawFrameTask.cpp
@@ -21,6 +21,7 @@
#include "../DeferredLayerUpdater.h"
#include "../DisplayList.h"
+#include "../Properties.h"
#include "../RenderNode.h"
#include "CanvasContext.h"
#include "RenderThread.h"
@@ -44,6 +45,12 @@ void DrawFrameTask::setContext(RenderThread* thread, CanvasContext* context,
mTargetNode = targetNode;
}
+void DrawFrameTask::setHintSessionCallbacks(std::function<void(int64_t)> updateTargetWorkDuration,
+ std::function<void(int64_t)> reportActualWorkDuration) {
+ mUpdateTargetWorkDuration = std::move(updateTargetWorkDuration);
+ mReportActualWorkDuration = std::move(reportActualWorkDuration);
+}
+
void DrawFrameTask::pushLayerUpdate(DeferredLayerUpdater* layer) {
LOG_ALWAYS_FATAL_IF(!mContext,
"Lifecycle violation, there's no context to pushLayerUpdate with!");
@@ -102,6 +109,9 @@ void DrawFrameTask::run() {
CanvasContext* context = mContext;
std::function<void(int64_t)> callback = std::move(mFrameCallback);
mFrameCallback = nullptr;
+ int64_t intendedVsync = mFrameInfo[static_cast<int>(FrameInfoIndex::IntendedVsync)];
+ int64_t frameDeadline = mFrameInfo[static_cast<int>(FrameInfoIndex::FrameDeadline)];
+ int64_t frameStartTime = mFrameInfo[static_cast<int>(FrameInfoIndex::FrameStartTime)];
// From this point on anything in "this" is *UNSAFE TO ACCESS*
if (canUnblockUiThread) {
@@ -124,6 +134,25 @@ void DrawFrameTask::run() {
if (!canUnblockUiThread) {
unblockUiThread();
}
+
+ // These member callbacks are effectively const as they are set once during init, so it's safe
+ // to use these directly instead of making local copies.
+ if (mUpdateTargetWorkDuration && mReportActualWorkDuration) {
+ constexpr int64_t kSanityCheckLowerBound = 100000; // 0.1ms
+ constexpr int64_t kSanityCheckUpperBound = 10000000000; // 10s
+ int64_t targetWorkDuration = frameDeadline - intendedVsync;
+ targetWorkDuration = targetWorkDuration * Properties::targetCpuTimePercentage / 100;
+ if (targetWorkDuration > kSanityCheckLowerBound &&
+ targetWorkDuration < kSanityCheckUpperBound &&
+ targetWorkDuration != mLastTargetWorkDuration) {
+ mLastTargetWorkDuration = targetWorkDuration;
+ mUpdateTargetWorkDuration(targetWorkDuration);
+ }
+ int64_t frameDuration = systemTime(SYSTEM_TIME_MONOTONIC) - frameStartTime;
+ if (frameDuration > kSanityCheckLowerBound && frameDuration < kSanityCheckUpperBound) {
+ mReportActualWorkDuration(frameDuration);
+ }
+ }
}
bool DrawFrameTask::syncFrameState(TreeInfo& info) {