From 7e6a5f29f59e732f3172439ae8417970fe229d42 Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Tue, 31 Aug 2021 13:49:19 +0000 Subject: [PATCH] Set uninitialized frame number to 0 Now that the frame number is a uint instead of an int it's clearer if the uninitailized value is 0. Frame numbers start from 1 so 0 doesn't collide with any valid frame numbers. It also means comparing frame numbers to check if the frame is newer always works even when comparing to the uninitialized frame number. Test: N/A Change-Id: I0901ffeaefbdd6378e59d8858a06de92b0104cd9 --- libs/hwui/renderthread/CanvasContext.cpp | 8 ++++---- libs/hwui/renderthread/CanvasContext.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index c5ae0431e06bf..aa39d55adc36f 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -219,7 +219,7 @@ void CanvasContext::setupPipelineSurface() { } - mFrameNumber = -1; + mFrameNumber = 0; if (mNativeSurface != nullptr && hasSurface) { mHaveNewSurface = true; @@ -581,7 +581,7 @@ nsecs_t CanvasContext::draw() { mCurrentFrameInfo->set(FrameInfoIndex::DequeueBufferDuration) = swap.dequeueDuration; mCurrentFrameInfo->set(FrameInfoIndex::QueueBufferDuration) = swap.queueDuration; mHaveNewSurface = false; - mFrameNumber = -1; + mFrameNumber = 0; } else { mCurrentFrameInfo->set(FrameInfoIndex::DequeueBufferDuration) = 0; mCurrentFrameInfo->set(FrameInfoIndex::QueueBufferDuration) = 0; @@ -891,8 +891,8 @@ void CanvasContext::enqueueFrameWork(std::function&& func) { } uint64_t CanvasContext::getFrameNumber() { - // mFrameNumber is reset to -1 when the surface changes or we swap buffers - if (mFrameNumber == -1 && mNativeSurface.get()) { + // mFrameNumber is reset to 0 when the surface changes or we swap buffers + if (mFrameNumber == 0 && mNativeSurface.get()) { mFrameNumber = ANativeWindow_getNextFrameId(mNativeSurface->getNativeWindow()); } return mFrameNumber; diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h index 852cbda6c3135..ec91e662fcd3c 100644 --- a/libs/hwui/renderthread/CanvasContext.h +++ b/libs/hwui/renderthread/CanvasContext.h @@ -281,7 +281,8 @@ private: // Need at least 4 because we do quad buffer. Add a 5th for good measure. RingBuffer mSwapHistory; - uint64_t mFrameNumber = -1; + // Frame numbers start at 1, 0 means uninitialized + uint64_t mFrameNumber = 0; int64_t mDamageId = 0; // last vsync for a dropped frame due to stuffed queue