Replace CLOCK_MONOTONIC with SYSTEM_TIME_MONOTONIC
Using SYSTEM_TIME_MONOTONIC works for Android (where it translates to CLOCK_MONOTONIC) and host targets, while CLOCK_MONOTONIC is not defined on macOS. Bug: 117921091 Test: existing tests should pass Change-Id: I1fad472881830fb0701a320cf37319e083932ad4
This commit is contained in:
@@ -485,7 +485,7 @@ static void setSurface(JNIEnv* env, jclass clazz, jlong rendererPtr, jlong surfa
|
||||
|
||||
static void draw(JNIEnv* env, jclass clazz, jlong rendererPtr) {
|
||||
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(rendererPtr);
|
||||
nsecs_t vsync = systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t vsync = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
UiFrameInfoBuilder(proxy->frameInfo())
|
||||
.setVsync(vsync, vsync)
|
||||
.addFlag(FrameInfoFlags::SurfaceCanvas);
|
||||
|
||||
@@ -957,7 +957,7 @@ static jobject android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode(
|
||||
// to all 0s.
|
||||
proxy.setLightAlpha(0, 0);
|
||||
proxy.setLightGeometry((Vector3){0, 0, 0}, 0);
|
||||
nsecs_t vsync = systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t vsync = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
UiFrameInfoBuilder(proxy.frameInfo())
|
||||
.setVsync(vsync, vsync)
|
||||
.addFlag(FrameInfoFlags::SurfaceCanvas);
|
||||
|
||||
@@ -100,15 +100,15 @@ class FrameInfo {
|
||||
public:
|
||||
void importUiThreadInfo(int64_t* info);
|
||||
|
||||
void markSyncStart() { set(FrameInfoIndex::SyncStart) = systemTime(CLOCK_MONOTONIC); }
|
||||
void markSyncStart() { set(FrameInfoIndex::SyncStart) = systemTime(SYSTEM_TIME_MONOTONIC); }
|
||||
|
||||
void markIssueDrawCommandsStart() {
|
||||
set(FrameInfoIndex::IssueDrawCommandsStart) = systemTime(CLOCK_MONOTONIC);
|
||||
set(FrameInfoIndex::IssueDrawCommandsStart) = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
}
|
||||
|
||||
void markSwapBuffers() { set(FrameInfoIndex::SwapBuffers) = systemTime(CLOCK_MONOTONIC); }
|
||||
void markSwapBuffers() { set(FrameInfoIndex::SwapBuffers) = systemTime(SYSTEM_TIME_MONOTONIC); }
|
||||
|
||||
void markFrameCompleted() { set(FrameInfoIndex::FrameCompleted) = systemTime(CLOCK_MONOTONIC); }
|
||||
void markFrameCompleted() { set(FrameInfoIndex::FrameCompleted) = systemTime(SYSTEM_TIME_MONOTONIC); }
|
||||
|
||||
void addFlag(int frameInfoFlag) {
|
||||
set(FrameInfoIndex::Flags) |= static_cast<uint64_t>(frameInfoFlag);
|
||||
|
||||
@@ -143,7 +143,7 @@ void ProfileData::reset() {
|
||||
mSlowFrameCounts.fill(0);
|
||||
mTotalFrameCount = 0;
|
||||
mJankFrameCount = 0;
|
||||
mStatStartTime = systemTime(CLOCK_MONOTONIC);
|
||||
mStatStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
}
|
||||
|
||||
void ProfileData::reportFrame(int64_t duration) {
|
||||
|
||||
@@ -24,12 +24,6 @@
|
||||
|
||||
#include <optional>
|
||||
|
||||
#ifdef __APPLE__
|
||||
// macOS SDK 10.10 does not support CLOCK_MONOTONIC, which is not an issue since
|
||||
// the value of the argument is not used in the host definition of systemTime
|
||||
#define CLOCK_MONOTONIC
|
||||
#endif
|
||||
|
||||
namespace android {
|
||||
|
||||
AnimatedImageDrawable::AnimatedImageDrawable(sk_sp<SkAnimatedImage> animatedImage, size_t bytesUsed)
|
||||
@@ -70,7 +64,7 @@ bool AnimatedImageDrawable::nextSnapshotReady() const {
|
||||
// Only called on the RenderThread while UI thread is locked.
|
||||
bool AnimatedImageDrawable::isDirty(nsecs_t* outDelay) {
|
||||
*outDelay = 0;
|
||||
const nsecs_t currentTime = systemTime(CLOCK_MONOTONIC);
|
||||
const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
const nsecs_t lastWallTime = mLastWallTime;
|
||||
|
||||
mLastWallTime = currentTime;
|
||||
@@ -250,7 +244,7 @@ int AnimatedImageDrawable::drawStaging(SkCanvas* canvas) {
|
||||
|
||||
bool update = false;
|
||||
{
|
||||
const nsecs_t currentTime = systemTime(CLOCK_MONOTONIC);
|
||||
const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
std::unique_lock lock{mSwapLock};
|
||||
// mLastWallTime starts off at 0. If it is still 0, just update it to
|
||||
// the current time and avoid updating
|
||||
|
||||
@@ -463,7 +463,7 @@ void CanvasContext::draw() {
|
||||
}
|
||||
SwapHistory& swap = mSwapHistory.next();
|
||||
swap.damage = windowDirty;
|
||||
swap.swapCompletedTime = systemTime(CLOCK_MONOTONIC);
|
||||
swap.swapCompletedTime = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
swap.vsyncTime = mRenderThread.timeLord().latestVsync();
|
||||
if (mNativeSurface.get()) {
|
||||
int durationUs;
|
||||
@@ -549,7 +549,7 @@ void CanvasContext::prepareAndDraw(RenderNode* node) {
|
||||
UiFrameInfoBuilder(frameInfo).addFlag(FrameInfoFlags::RTAnimation).setVsync(vsync, vsync);
|
||||
|
||||
TreeInfo info(TreeInfo::MODE_RT_ONLY, *this);
|
||||
prepareTree(info, frameInfo, systemTime(CLOCK_MONOTONIC), node);
|
||||
prepareTree(info, frameInfo, systemTime(SYSTEM_TIME_MONOTONIC), node);
|
||||
if (info.out.canDrawThisFrame) {
|
||||
draw();
|
||||
} else {
|
||||
|
||||
@@ -69,7 +69,7 @@ int DrawFrameTask::drawFrame() {
|
||||
LOG_ALWAYS_FATAL_IF(!mContext, "Cannot drawFrame with no CanvasContext!");
|
||||
|
||||
mSyncResult = SyncResult::OK;
|
||||
mSyncQueued = systemTime(CLOCK_MONOTONIC);
|
||||
mSyncQueued = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
postAndWait();
|
||||
|
||||
return mSyncResult;
|
||||
|
||||
@@ -339,7 +339,7 @@ void RenderProxy::prepareToDraw(Bitmap& bitmap) {
|
||||
};
|
||||
nsecs_t lastVsync = renderThread->timeLord().latestVsync();
|
||||
nsecs_t estimatedNextVsync = lastVsync + renderThread->timeLord().frameIntervalNanos();
|
||||
nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t timeToNextVsync = estimatedNextVsync - systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
// We expect the UI thread to take 4ms and for RT to be active from VSYNC+4ms to
|
||||
// VSYNC+12ms or so, so aim for the gap during which RT is expected to
|
||||
// be idle
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
[this]() { mRenderThread->drainDisplayEventQueue(); });
|
||||
}
|
||||
|
||||
virtual nsecs_t latestVsyncEvent() override { return systemTime(CLOCK_MONOTONIC); }
|
||||
virtual nsecs_t latestVsyncEvent() override { return systemTime(SYSTEM_TIME_MONOTONIC); }
|
||||
|
||||
private:
|
||||
RenderThread* mRenderThread;
|
||||
|
||||
@@ -31,7 +31,7 @@ bool TimeLord::vsyncReceived(nsecs_t vsync) {
|
||||
|
||||
nsecs_t TimeLord::computeFrameTimeNanos() {
|
||||
// Logic copied from Choreographer.java
|
||||
nsecs_t now = systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
nsecs_t jitterNanos = now - mFrameTimeNanos;
|
||||
if (jitterNanos >= mFrameIntervalNanos) {
|
||||
nsecs_t lastFrameOffset = jitterNanos % mFrameIntervalNanos;
|
||||
|
||||
@@ -146,7 +146,7 @@ void run(const TestScene::Info& info, const TestScene::Options& opts,
|
||||
}
|
||||
for (int i = 0; i < warmupFrameCount; i++) {
|
||||
testContext.waitForVsync();
|
||||
nsecs_t vsync = systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t vsync = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
UiFrameInfoBuilder(proxy->frameInfo()).setVsync(vsync, vsync);
|
||||
proxy->syncAndDrawFrame();
|
||||
}
|
||||
@@ -161,10 +161,10 @@ void run(const TestScene::Info& info, const TestScene::Options& opts,
|
||||
|
||||
ModifiedMovingAverage<double> avgMs(opts.reportFrametimeWeight);
|
||||
|
||||
nsecs_t start = systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t start = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
for (int i = 0; i < opts.count; i++) {
|
||||
testContext.waitForVsync();
|
||||
nsecs_t vsync = systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t vsync = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
{
|
||||
ATRACE_NAME("UI-Draw Frame");
|
||||
UiFrameInfoBuilder(proxy->frameInfo()).setVsync(vsync, vsync);
|
||||
@@ -173,7 +173,7 @@ void run(const TestScene::Info& info, const TestScene::Options& opts,
|
||||
}
|
||||
if (opts.reportFrametimeWeight) {
|
||||
proxy->fence();
|
||||
nsecs_t done = systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t done = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
avgMs.add((done - vsync) / 1000000.0);
|
||||
if (i % 10 == 9) {
|
||||
printf("Average frametime %.3fms\n", avgMs.average());
|
||||
@@ -181,7 +181,7 @@ void run(const TestScene::Info& info, const TestScene::Options& opts,
|
||||
}
|
||||
}
|
||||
proxy->fence();
|
||||
nsecs_t end = systemTime(CLOCK_MONOTONIC);
|
||||
nsecs_t end = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
|
||||
if (reporter) {
|
||||
outputBenchmarkReport(info, opts, reporter, proxy.get(), (end - start) / (double)s2ns(1));
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
namespace android::uirenderer {
|
||||
|
||||
struct MonotonicClock {
|
||||
static nsecs_t now() { return systemTime(CLOCK_MONOTONIC); }
|
||||
static nsecs_t now() { return systemTime(SYSTEM_TIME_MONOTONIC); }
|
||||
};
|
||||
|
||||
class WorkQueue {
|
||||
|
||||
Reference in New Issue
Block a user