diff options
3 files changed, 15 insertions, 10 deletions
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h index afa02cd0c2..c5d03a7218 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h @@ -108,7 +108,7 @@ public: private: CachedSet() = default; - NonBufferHash mFingerprint = 0; + const NonBufferHash mFingerprint; std::chrono::steady_clock::time_point mLastUpdate = std::chrono::steady_clock::now(); std::vector<Layer> mLayers; Rect mBounds = Rect::EMPTY_RECT; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/Flattener.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/Flattener.h index 313a180f4f..2f2ad4c9b5 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/Flattener.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/Flattener.h @@ -54,7 +54,7 @@ private: void resetActivities(NonBufferHash, std::chrono::steady_clock::time_point now); - void updateLayersHash(); + NonBufferHash computeLayersHash() const; bool mergeWithCachedSets(const std::vector<const LayerState*>& layers, std::chrono::steady_clock::time_point now); @@ -69,7 +69,6 @@ private: std::chrono::steady_clock::time_point mLastGeometryUpdate; std::vector<CachedSet> mLayers; - NonBufferHash mLayersHash = 0; std::optional<CachedSet> mNewCachedSet; // Statistics diff --git a/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp b/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp index ffca5baab7..9c9649ccbe 100644 --- a/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp +++ b/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp @@ -40,13 +40,17 @@ NonBufferHash Flattener::flattenLayers(const std::vector<const LayerState*>& lay ++mInitialLayerCounts[layers.size()]; - if (mergeWithCachedSets(layers, now)) { - hash = mLayersHash; - } + // Only buildCachedSets if these layers are already stored in mLayers. + // Otherwise (i.e. mergeWithCachedSets returns false), the time has not + // changed, so buildCachedSets will never find any runs. + const bool alreadyHadCachedSets = mergeWithCachedSets(layers, now); ++mFinalLayerCounts[mLayers.size()]; - buildCachedSets(now); + if (alreadyHadCachedSets) { + buildCachedSets(now); + hash = computeLayersHash(); + } return hash; } @@ -157,14 +161,17 @@ void Flattener::resetActivities(NonBufferHash hash, time_point now) { } } -void Flattener::updateLayersHash() { +NonBufferHash Flattener::computeLayersHash() const{ size_t hash = 0; for (const auto& layer : mLayers) { android::hashCombineSingleHashed(hash, layer.getNonBufferHash()); } - mLayersHash = hash; + return hash; } +// Only called if the geometry matches the last frame. Return true if mLayers +// was already populated with these layers, i.e. on the second and following +// calls with the same geometry. bool Flattener::mergeWithCachedSets(const std::vector<const LayerState*>& layers, time_point now) { std::vector<CachedSet> merged; @@ -272,7 +279,6 @@ bool Flattener::mergeWithCachedSets(const std::vector<const LayerState*>& layers } mLayers = std::move(merged); - updateLayersHash(); return true; } |