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
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index c5ae043..aa39d55 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -219,7 +219,7 @@
}
- mFrameNumber = -1;
+ mFrameNumber = 0;
if (mNativeSurface != nullptr && hasSurface) {
mHaveNewSurface = true;
@@ -581,7 +581,7 @@
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 @@
}
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 852cbda6..ec91e66 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -281,7 +281,8 @@
// Need at least 4 because we do quad buffer. Add a 5th for good measure.
RingBuffer<SwapHistory, 5> 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