Fix Transaction tracking for FrameTimeline
The current setup only supports one SurfaceFrame per DrawingState for
Transactions. This becomes problematic if more than one Transaction is
submitted for the same vsync, on the same layer. On top of this, the
Blast transactions can have a buffer that could result in a buffer drop.
This change adds the support to hold multiple SurfaceFrames in the
Layer's State. It also adds a bufferSurfaceFrame that's intended only
for Blast Transactions with a Buffer. All other Transactions are tracked
in the bufferlessSurfaceFrames.
Additionally, this change also adds a lastLatchTime. It is needed for
classifying BufferStuffing properly.
Bug: 176106798
Test: open any app from the launcher and at the same time check dumpsys
Change-Id: Id3b8369ca206f8b89be3041e5fc018f1f1be1d23
Merged-In: Id3b8369ca206f8b89be3041e5fc018f1f1be1d23
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index 3dc62e3..e470eb9 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -28,6 +28,7 @@
#include <limits>
+#include <FrameTimeline/FrameTimeline.h>
#include <compositionengine/LayerFECompositionState.h>
#include <gui/BufferQueue.h>
#include <private/gui/SyncFeatures.h>
@@ -38,6 +39,7 @@
namespace android {
+using PresentState = frametimeline::SurfaceFrame::PresentState;
// clang-format off
const std::array<float, 16> BufferStateLayer::IDENTITY_MATRIX{
1, 0, 0, 0,
@@ -335,7 +337,8 @@
bool BufferStateLayer::setBuffer(const sp<GraphicBuffer>& buffer, const sp<Fence>& acquireFence,
nsecs_t postTime, nsecs_t desiredPresentTime, bool isAutoTimestamp,
const client_cache_t& clientCacheId, uint64_t frameNumber,
- std::optional<nsecs_t> /* dequeueTime */) {
+ std::optional<nsecs_t> /* dequeueTime */,
+ const FrameTimelineInfo& info) {
ATRACE_CALL();
if (mCurrentState.buffer) {
@@ -345,6 +348,10 @@
// before swapping to drawing state, then the first buffer will be
// dropped and we should decrement the pending buffer count.
decrementPendingBufferCount();
+ if (mCurrentState.bufferSurfaceFrameTX != nullptr) {
+ addSurfaceFrameDroppedForBuffer(mCurrentState.bufferSurfaceFrameTX);
+ mCurrentState.bufferSurfaceFrameTX.reset();
+ }
}
}
@@ -365,6 +372,11 @@
LayerHistory::LayerUpdateType::Buffer);
addFrameEvent(acquireFence, postTime, isAutoTimestamp ? 0 : desiredPresentTime);
+
+ if (info.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) {
+ setFrameTimelineVsyncForBufferTransaction(info, postTime);
+ }
+
return true;
}
@@ -620,6 +632,17 @@
std::make_shared<FenceTime>(mDrawingState.acquireFence));
mFlinger->mTimeStats->setLatchTime(layerId, mDrawingState.frameNumber, latchTime);
+ auto& bufferSurfaceFrame = mDrawingState.bufferSurfaceFrameTX;
+ if (bufferSurfaceFrame != nullptr &&
+ bufferSurfaceFrame->getPresentState() != PresentState::Presented) {
+ // Update only if the bufferSurfaceFrame wasn't already presented. A Presented
+ // bufferSurfaceFrame could be seen here if a pending state was applied successfully and we
+ // are processing the next state.
+ addSurfaceFramePresentedForBuffer(bufferSurfaceFrame,
+ mDrawingState.acquireFence->getSignalTime(), latchTime);
+ bufferSurfaceFrame.reset();
+ }
+
mCurrentStateModified = false;
return NO_ERROR;