diff options
| -rw-r--r-- | services/surfaceflinger/BufferStateLayer.cpp | 13 | ||||
| -rw-r--r-- | services/surfaceflinger/BufferStateLayer.h | 5 | ||||
| -rw-r--r-- | services/surfaceflinger/Layer.h | 3 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 24 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 14 |
5 files changed, 42 insertions, 17 deletions
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp index b2383ad8a7..37131219ae 100644 --- a/services/surfaceflinger/BufferStateLayer.cpp +++ b/services/surfaceflinger/BufferStateLayer.cpp @@ -345,6 +345,14 @@ FloatRect BufferStateLayer::computeSourceBounds(const FloatRect& parentBounds) c return parentBounds; } +void BufferStateLayer::setPostTime(nsecs_t postTime) { + mFlinger->mTimeStats->setPostTime(getSequence(), getFrameNumber(), getName().c_str(), postTime); +} + +void BufferStateLayer::setDesiredPresentTime(nsecs_t desiredPresentTime) { + mDesiredPresentTime = desiredPresentTime; +} + // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- @@ -359,8 +367,7 @@ bool BufferStateLayer::fenceHasSignaled() const { } nsecs_t BufferStateLayer::getDesiredPresentTime() { - // TODO(marissaw): support an equivalent to desiredPresentTime for timestats metrics - return 0; + return mDesiredPresentTime; } std::shared_ptr<FenceTime> BufferStateLayer::getCurrentFenceTime() const { @@ -532,8 +539,6 @@ status_t BufferStateLayer::updateTexImage(bool& /*recomputeVisibleRegions*/, nse } } - // TODO(marissaw): properly support mTimeStats - mFlinger->mTimeStats->setPostTime(layerID, getFrameNumber(), getName().c_str(), latchTime); mFlinger->mTimeStats->setAcquireFence(layerID, getFrameNumber(), getCurrentFenceTime()); mFlinger->mTimeStats->setLatchTime(layerID, getFrameNumber(), latchTime); diff --git a/services/surfaceflinger/BufferStateLayer.h b/services/surfaceflinger/BufferStateLayer.h index 97662e8ff7..668830a3fe 100644 --- a/services/surfaceflinger/BufferStateLayer.h +++ b/services/surfaceflinger/BufferStateLayer.h @@ -89,6 +89,9 @@ public: Rect getBufferSize(const State& s) const override; FloatRect computeSourceBounds(const FloatRect& parentBounds) const override; + + void setPostTime(nsecs_t postTime) override; + void setDesiredPresentTime(nsecs_t desiredPresentTime) override; // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- @@ -149,6 +152,8 @@ private: bool mReleasePreviousBuffer = false; nsecs_t mCallbackHandleAcquireTime = -1; + nsecs_t mDesiredPresentTime = -1; + // TODO(marissaw): support sticky transform for LEGACY camera mode }; diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index c7feb72d55..79d2238d87 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -434,6 +434,9 @@ public: } virtual Rect getCrop(const Layer::State& s) const { return s.crop_legacy; } + virtual void setPostTime(nsecs_t /*postTime*/) {} + virtual void setDesiredPresentTime(nsecs_t /*desiredPresentTime*/) {} + protected: virtual bool prepareClientLayer(const RenderArea& renderArea, const Region& clip, bool useIdentityTransform, Region& clearRegion, diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 96292a8b92..b605cb22ba 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -3437,12 +3437,13 @@ bool SurfaceFlinger::flushTransactionQueues() { auto& [applyToken, transactionQueue] = *it; while (!transactionQueue.empty()) { - const auto& [states, displays, flags, desiredPresentTime, privileged] = + const auto& [states, displays, flags, desiredPresentTime, postTime, privileged] = transactionQueue.front(); if (!transactionIsReadyToBeApplied(desiredPresentTime, states)) { break; } - applyTransactionState(states, displays, flags, mPendingInputWindowCommands, privileged); + applyTransactionState(states, displays, flags, mPendingInputWindowCommands, + desiredPresentTime, postTime, privileged); transactionQueue.pop(); } @@ -3502,6 +3503,8 @@ void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& states, int64_t desiredPresentTime) { ATRACE_CALL(); + const int64_t postTime = systemTime(); + bool privileged = callingThreadHasUnscopedSurfaceFlingerAccess(); Mutex::Autolock _l(mStateLock); @@ -3514,17 +3517,19 @@ void SurfaceFlinger::setTransactionState(const Vector<ComposerState>& states, if (mTransactionQueues.find(applyToken) != mTransactionQueues.end() || !transactionIsReadyToBeApplied(desiredPresentTime, states)) { mTransactionQueues[applyToken].emplace(states, displays, flags, desiredPresentTime, - privileged); + postTime, privileged); setTransactionFlags(eTransactionNeeded); return; } - applyTransactionState(states, displays, flags, inputWindowCommands, privileged); + applyTransactionState(states, displays, flags, inputWindowCommands, desiredPresentTime, + postTime, privileged); } void SurfaceFlinger::applyTransactionState(const Vector<ComposerState>& states, const Vector<DisplayState>& displays, uint32_t flags, const InputWindowCommands& inputWindowCommands, + const int64_t desiredPresentTime, const int64_t postTime, bool privileged) { uint32_t transactionFlags = 0; @@ -3550,7 +3555,7 @@ void SurfaceFlinger::applyTransactionState(const Vector<ComposerState>& states, uint32_t clientStateFlags = 0; for (const ComposerState& state : states) { - clientStateFlags |= setClientStateLocked(state, privileged); + clientStateFlags |= setClientStateLocked(state, desiredPresentTime, postTime, privileged); } // If the state doesn't require a traversal and there are callbacks, send them now if (!(clientStateFlags & eTraversalNeeded)) { @@ -3663,7 +3668,8 @@ bool SurfaceFlinger::callingThreadHasUnscopedSurfaceFlingerAccess() { } uint32_t SurfaceFlinger::setClientStateLocked(const ComposerState& composerState, - bool privileged) { + int64_t desiredPresentTime, int64_t postTime, + bool privileged) { const layer_state_t& s = composerState.state; sp<Client> client(static_cast<Client*>(composerState.client.get())); @@ -3905,7 +3911,11 @@ uint32_t SurfaceFlinger::setClientStateLocked(const ComposerState& composerState sp<GraphicBuffer> buffer = BufferStateLayerCache::getInstance().get(s.cachedBuffer.token, s.cachedBuffer.bufferId); - if (layer->setBuffer(buffer)) flags |= eTraversalNeeded; + if (layer->setBuffer(buffer)) { + flags |= eTraversalNeeded; + layer->setPostTime(postTime); + layer->setDesiredPresentTime(desiredPresentTime); + } } if (layer->setTransactionCompletedListeners(callbackHandles)) flags |= eTraversalNeeded; // Do not put anything that updates layer state or modifies flags after diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 96a21cca67..e79c4ee62b 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -572,6 +572,7 @@ private: void applyTransactionState(const Vector<ComposerState>& state, const Vector<DisplayState>& displays, uint32_t flags, const InputWindowCommands& inputWindowCommands, + const int64_t desiredPresentTime, const int64_t postTime, bool privileged) REQUIRES(mStateLock); bool flushTransactionQueues(); uint32_t getTransactionFlags(uint32_t flags); @@ -584,8 +585,8 @@ private: bool containsAnyInvalidClientState(const Vector<ComposerState>& states); bool transactionIsReadyToBeApplied(int64_t desiredPresentTime, const Vector<ComposerState>& states); - uint32_t setClientStateLocked(const ComposerState& composerState, bool privileged) - REQUIRES(mStateLock); + uint32_t setClientStateLocked(const ComposerState& composerState, int64_t desiredPresentTime, + int64_t postTime, bool privileged) REQUIRES(mStateLock); uint32_t setDisplayStateLocked(const DisplayState& s) REQUIRES(mStateLock); uint32_t addInputWindowCommands(const InputWindowCommands& inputWindowCommands) REQUIRES(mStateLock); @@ -1047,18 +1048,19 @@ private: struct TransactionState { TransactionState(const Vector<ComposerState>& composerStates, const Vector<DisplayState>& displayStates, uint32_t transactionFlags, - int64_t desiredPresentTime, - bool privileged) + int64_t desiredPresentTime, int64_t postTime, bool privileged) : states(composerStates), displays(displayStates), flags(transactionFlags), - time(desiredPresentTime), + desiredPresentTime(desiredPresentTime), + postTime(postTime), privileged(privileged) {} Vector<ComposerState> states; Vector<DisplayState> displays; uint32_t flags; - int64_t time; + const int64_t desiredPresentTime; + const int64_t postTime; bool privileged; }; std::unordered_map<sp<IBinder>, std::queue<TransactionState>, IBinderHash> mTransactionQueues; |