diff options
author | 2019-06-14 12:58:57 +0100 | |
---|---|---|
committer | 2019-06-14 12:07:36 +0000 | |
commit | e218c6928508ef72de2cc5c8b89de0f250a3e68c (patch) | |
tree | 22713615fad3dda93063795c97b41f281b6ff745 | |
parent | f06c22660f41e307cb4a1a70ac9f93f490e68870 (diff) |
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
-rw-r--r-- | core/jni/android_view_Surface.cpp | 2 | ||||
-rw-r--r-- | core/jni/android_view_ThreadedRenderer.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/FrameInfo.h | 8 | ||||
-rw-r--r-- | libs/hwui/ProfileData.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/hwui/AnimatedImageDrawable.cpp | 10 | ||||
-rw-r--r-- | libs/hwui/renderthread/CanvasContext.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/renderthread/DrawFrameTask.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderProxy.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderThread.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/renderthread/TimeLord.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/tests/macrobench/TestSceneRunner.cpp | 10 | ||||
-rw-r--r-- | libs/hwui/thread/WorkQueue.h | 2 |
12 files changed, 21 insertions, 27 deletions
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index ccadc7d7c22a..0a7bc3027065 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -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); diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index f7e9b24e32ec..84c3b3a8acb5 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -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); diff --git a/libs/hwui/FrameInfo.h b/libs/hwui/FrameInfo.h index 0aab58c38ba0..b75192ff8476 100644 --- a/libs/hwui/FrameInfo.h +++ b/libs/hwui/FrameInfo.h @@ -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); diff --git a/libs/hwui/ProfileData.cpp b/libs/hwui/ProfileData.cpp index 70ca4e3e8074..c7f92321b090 100644 --- a/libs/hwui/ProfileData.cpp +++ b/libs/hwui/ProfileData.cpp @@ -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) { diff --git a/libs/hwui/hwui/AnimatedImageDrawable.cpp b/libs/hwui/hwui/AnimatedImageDrawable.cpp index 7677f9c6628d..4544beae5df8 100644 --- a/libs/hwui/hwui/AnimatedImageDrawable.cpp +++ b/libs/hwui/hwui/AnimatedImageDrawable.cpp @@ -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 diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index f326ce8d23e9..c9203d9bb530 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -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 { diff --git a/libs/hwui/renderthread/DrawFrameTask.cpp b/libs/hwui/renderthread/DrawFrameTask.cpp index 91dc3bc6e603..1e593388d063 100644 --- a/libs/hwui/renderthread/DrawFrameTask.cpp +++ b/libs/hwui/renderthread/DrawFrameTask.cpp @@ -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; diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index 1a1b9dac37f6..20247dc7c861 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -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 diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 863814263610..ee1a7ce19e82 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -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; diff --git a/libs/hwui/renderthread/TimeLord.cpp b/libs/hwui/renderthread/TimeLord.cpp index b82c5d159756..784068f1d877 100644 --- a/libs/hwui/renderthread/TimeLord.cpp +++ b/libs/hwui/renderthread/TimeLord.cpp @@ -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; diff --git a/libs/hwui/tests/macrobench/TestSceneRunner.cpp b/libs/hwui/tests/macrobench/TestSceneRunner.cpp index 9c845f04e820..22d5abbd3dbc 100644 --- a/libs/hwui/tests/macrobench/TestSceneRunner.cpp +++ b/libs/hwui/tests/macrobench/TestSceneRunner.cpp @@ -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)); diff --git a/libs/hwui/thread/WorkQueue.h b/libs/hwui/thread/WorkQueue.h index 42f8503fd000..46b8bc07b432 100644 --- a/libs/hwui/thread/WorkQueue.h +++ b/libs/hwui/thread/WorkQueue.h @@ -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 { |