Loading services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h +3 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,9 @@ public: const LayerState* getState() const { return mState; } const std::string& getName() const { return mState->getName(); } Rect getDisplayFrame() const { return mState->getDisplayFrame(); } const sp<GraphicBuffer>& getBuffer() const { return mState->getBuffer(); } const sp<GraphicBuffer>& getBuffer() const { return mState->getOutputLayer()->getLayerFE().getCompositionState()->buffer; } int64_t getFramesSinceBufferUpdate() const { return mState->getFramesSinceBufferUpdate(); } NonBufferHash getHash() const { return mHash; } std::chrono::steady_clock::time_point getLastUpdate() const { return mLastUpdate; } Loading services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h +26 −14 Original line number Diff line number Diff line Loading @@ -32,6 +32,14 @@ template <typename T> struct hash<android::sp<T>> { size_t operator()(const android::sp<T>& p) { return std::hash<void*>()(p.get()); } }; template <typename T> struct hash<android::wp<T>> { size_t operator()(const android::wp<T>& p) { android::sp<T> promoted = p.promote(); return std::hash<void*>()(promoted ? promoted.get() : nullptr); } }; } // namespace std namespace android::compositionengine::impl::planner { Loading Loading @@ -70,7 +78,7 @@ public: virtual Flags<LayerStateField> update(const compositionengine::OutputLayer* layer) = 0; virtual size_t getHash(Flags<LayerStateField> skipFields) const = 0; virtual size_t getHash() const = 0; virtual LayerStateField getField() const = 0; Loading Loading @@ -113,6 +121,10 @@ public: // Returns this member's field flag if it was changed Flags<LayerStateField> update(const compositionengine::OutputLayer* layer) override { T newValue = mReader(layer); return update(newValue); } Flags<LayerStateField> update(const T& newValue) { if (!mEquals(mValue, newValue)) { mValue = newValue; mHash = {}; Loading @@ -124,10 +136,7 @@ public: LayerStateField getField() const override { return FIELD; } const T& get() const { return mValue; } size_t getHash(Flags<LayerStateField> skipFields) const override { if (skipFields.test(FIELD)) { return 0; } size_t getHash() const override { if (!mHash) { mHash = std::hash<T>{}(mValue); } Loading Loading @@ -175,13 +184,13 @@ public: Flags<LayerStateField> update(compositionengine::OutputLayer*); // Computes a hash for this LayerState. // The hash is only computed from NonUniqueFields. size_t getHash(Flags<LayerStateField> skipFields) const; // The hash is only computed from NonUniqueFields, and excludes GraphicBuffers since they are // not guaranteed to live longer than the LayerState object. size_t getHash() const; // Returns the bit-set of differing fields between this LayerState and another LayerState. // This bit-set is based on NonUniqueFields only Flags<LayerStateField> getDifferingFields(const LayerState& other, Flags<LayerStateField> skipFields) const; // This bit-set is based on NonUniqueFields only, and excludes GraphicBuffers. Flags<LayerStateField> getDifferingFields(const LayerState& other) const; compositionengine::OutputLayer* getOutputLayer() const { return mOutputLayer; } int32_t getId() const { return mId.get(); } Loading @@ -190,7 +199,6 @@ public: hardware::graphics::composer::hal::Composition getCompositionType() const { return mCompositionType.get(); } const sp<GraphicBuffer>& getBuffer() const { return mBuffer.get(); } void incrementFramesSinceBufferUpdate() { ++mFramesSinceBufferUpdate; } void resetFramesSinceBufferUpdate() { mFramesSinceBufferUpdate = 0; } Loading Loading @@ -311,10 +319,14 @@ private: return std::vector<std::string>{base::StringPrintf("%p", p)}; }}; OutputLayerState<sp<GraphicBuffer>, LayerStateField::Buffer> OutputLayerState<wp<GraphicBuffer>, LayerStateField::Buffer> mBuffer{[](auto layer) { return layer->getLayerFE().getCompositionState()->buffer; }, [](const sp<GraphicBuffer>& buffer) { return std::vector<std::string>{base::StringPrintf("%p", buffer.get())}; [](const wp<GraphicBuffer>& buffer) { sp<GraphicBuffer> promotedBuffer = buffer.promote(); return std::vector<std::string>{ base::StringPrintf("%p", promotedBuffer ? promotedBuffer.get() : nullptr)}; }}; int64_t mFramesSinceBufferUpdate = 0; Loading services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -51,10 +51,10 @@ std::string durationString(std::chrono::milliseconds duration) { } CachedSet::Layer::Layer(const LayerState* state, std::chrono::steady_clock::time_point lastUpdate) : mState(state), mHash(state->getHash(LayerStateField::Buffer)), mLastUpdate(lastUpdate) {} : mState(state), mHash(state->getHash()), mLastUpdate(lastUpdate) {} CachedSet::CachedSet(const LayerState* layer, std::chrono::steady_clock::time_point lastUpdate) : mFingerprint(layer->getHash(LayerStateField::Buffer)), mLastUpdate(lastUpdate) { : mFingerprint(layer->getHash()), mLastUpdate(lastUpdate) { addLayer(layer, lastUpdate); } Loading services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -193,9 +193,7 @@ bool Flattener::mergeWithCachedSets(const std::vector<const LayerState*>& layers auto currentLayerIter = mLayers.begin(); auto incomingLayerIter = layers.begin(); while (incomingLayerIter != layers.end()) { if (mNewCachedSet && mNewCachedSet->getFingerprint() == (*incomingLayerIter)->getHash(LayerStateField::Buffer)) { if (mNewCachedSet && mNewCachedSet->getFingerprint() == (*incomingLayerIter)->getHash()) { if (mNewCachedSet->hasBufferUpdate()) { ALOGV("[%s] Dropping new cached set", __func__); ++mInvalidatedCachedSetAges[0]; Loading services/surfaceflinger/CompositionEngine/src/planner/LayerState.cpp +8 −8 Original line number Diff line number Diff line Loading @@ -58,24 +58,24 @@ Flags<LayerStateField> LayerState::update(compositionengine::OutputLayer* layer) return differences; } size_t LayerState::getHash( Flags<LayerStateField> skipFields = static_cast<LayerStateField>(0)) const { size_t LayerState::getHash() const { size_t hash = 0; for (const StateInterface* field : getNonUniqueFields()) { android::hashCombineSingleHashed(hash, field->getHash(skipFields)); if (field->getField() == LayerStateField::Buffer) { continue; } android::hashCombineSingleHashed(hash, field->getHash()); } return hash; } Flags<LayerStateField> LayerState::getDifferingFields( const LayerState& other, Flags<LayerStateField> skipFields = static_cast<LayerStateField>(0)) const { Flags<LayerStateField> LayerState::getDifferingFields(const LayerState& other) const { Flags<LayerStateField> differences; auto myFields = getNonUniqueFields(); auto otherFields = other.getNonUniqueFields(); for (size_t i = 0; i < myFields.size(); ++i) { if (skipFields.test(myFields[i]->getField())) { if (myFields[i]->getField() == LayerStateField::Buffer) { continue; } Loading Loading @@ -169,7 +169,7 @@ bool operator==(const LayerState& lhs, const LayerState& rhs) { NonBufferHash getNonBufferHash(const std::vector<const LayerState*>& layers) { size_t hash = 0; for (const auto layer : layers) { android::hashCombineSingleHashed(hash, layer->getHash(LayerStateField::Buffer)); android::hashCombineSingleHashed(hash, layer->getHash()); } return hash; Loading Loading
services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h +3 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,9 @@ public: const LayerState* getState() const { return mState; } const std::string& getName() const { return mState->getName(); } Rect getDisplayFrame() const { return mState->getDisplayFrame(); } const sp<GraphicBuffer>& getBuffer() const { return mState->getBuffer(); } const sp<GraphicBuffer>& getBuffer() const { return mState->getOutputLayer()->getLayerFE().getCompositionState()->buffer; } int64_t getFramesSinceBufferUpdate() const { return mState->getFramesSinceBufferUpdate(); } NonBufferHash getHash() const { return mHash; } std::chrono::steady_clock::time_point getLastUpdate() const { return mLastUpdate; } Loading
services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h +26 −14 Original line number Diff line number Diff line Loading @@ -32,6 +32,14 @@ template <typename T> struct hash<android::sp<T>> { size_t operator()(const android::sp<T>& p) { return std::hash<void*>()(p.get()); } }; template <typename T> struct hash<android::wp<T>> { size_t operator()(const android::wp<T>& p) { android::sp<T> promoted = p.promote(); return std::hash<void*>()(promoted ? promoted.get() : nullptr); } }; } // namespace std namespace android::compositionengine::impl::planner { Loading Loading @@ -70,7 +78,7 @@ public: virtual Flags<LayerStateField> update(const compositionengine::OutputLayer* layer) = 0; virtual size_t getHash(Flags<LayerStateField> skipFields) const = 0; virtual size_t getHash() const = 0; virtual LayerStateField getField() const = 0; Loading Loading @@ -113,6 +121,10 @@ public: // Returns this member's field flag if it was changed Flags<LayerStateField> update(const compositionengine::OutputLayer* layer) override { T newValue = mReader(layer); return update(newValue); } Flags<LayerStateField> update(const T& newValue) { if (!mEquals(mValue, newValue)) { mValue = newValue; mHash = {}; Loading @@ -124,10 +136,7 @@ public: LayerStateField getField() const override { return FIELD; } const T& get() const { return mValue; } size_t getHash(Flags<LayerStateField> skipFields) const override { if (skipFields.test(FIELD)) { return 0; } size_t getHash() const override { if (!mHash) { mHash = std::hash<T>{}(mValue); } Loading Loading @@ -175,13 +184,13 @@ public: Flags<LayerStateField> update(compositionengine::OutputLayer*); // Computes a hash for this LayerState. // The hash is only computed from NonUniqueFields. size_t getHash(Flags<LayerStateField> skipFields) const; // The hash is only computed from NonUniqueFields, and excludes GraphicBuffers since they are // not guaranteed to live longer than the LayerState object. size_t getHash() const; // Returns the bit-set of differing fields between this LayerState and another LayerState. // This bit-set is based on NonUniqueFields only Flags<LayerStateField> getDifferingFields(const LayerState& other, Flags<LayerStateField> skipFields) const; // This bit-set is based on NonUniqueFields only, and excludes GraphicBuffers. Flags<LayerStateField> getDifferingFields(const LayerState& other) const; compositionengine::OutputLayer* getOutputLayer() const { return mOutputLayer; } int32_t getId() const { return mId.get(); } Loading @@ -190,7 +199,6 @@ public: hardware::graphics::composer::hal::Composition getCompositionType() const { return mCompositionType.get(); } const sp<GraphicBuffer>& getBuffer() const { return mBuffer.get(); } void incrementFramesSinceBufferUpdate() { ++mFramesSinceBufferUpdate; } void resetFramesSinceBufferUpdate() { mFramesSinceBufferUpdate = 0; } Loading Loading @@ -311,10 +319,14 @@ private: return std::vector<std::string>{base::StringPrintf("%p", p)}; }}; OutputLayerState<sp<GraphicBuffer>, LayerStateField::Buffer> OutputLayerState<wp<GraphicBuffer>, LayerStateField::Buffer> mBuffer{[](auto layer) { return layer->getLayerFE().getCompositionState()->buffer; }, [](const sp<GraphicBuffer>& buffer) { return std::vector<std::string>{base::StringPrintf("%p", buffer.get())}; [](const wp<GraphicBuffer>& buffer) { sp<GraphicBuffer> promotedBuffer = buffer.promote(); return std::vector<std::string>{ base::StringPrintf("%p", promotedBuffer ? promotedBuffer.get() : nullptr)}; }}; int64_t mFramesSinceBufferUpdate = 0; Loading
services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -51,10 +51,10 @@ std::string durationString(std::chrono::milliseconds duration) { } CachedSet::Layer::Layer(const LayerState* state, std::chrono::steady_clock::time_point lastUpdate) : mState(state), mHash(state->getHash(LayerStateField::Buffer)), mLastUpdate(lastUpdate) {} : mState(state), mHash(state->getHash()), mLastUpdate(lastUpdate) {} CachedSet::CachedSet(const LayerState* layer, std::chrono::steady_clock::time_point lastUpdate) : mFingerprint(layer->getHash(LayerStateField::Buffer)), mLastUpdate(lastUpdate) { : mFingerprint(layer->getHash()), mLastUpdate(lastUpdate) { addLayer(layer, lastUpdate); } Loading
services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -193,9 +193,7 @@ bool Flattener::mergeWithCachedSets(const std::vector<const LayerState*>& layers auto currentLayerIter = mLayers.begin(); auto incomingLayerIter = layers.begin(); while (incomingLayerIter != layers.end()) { if (mNewCachedSet && mNewCachedSet->getFingerprint() == (*incomingLayerIter)->getHash(LayerStateField::Buffer)) { if (mNewCachedSet && mNewCachedSet->getFingerprint() == (*incomingLayerIter)->getHash()) { if (mNewCachedSet->hasBufferUpdate()) { ALOGV("[%s] Dropping new cached set", __func__); ++mInvalidatedCachedSetAges[0]; Loading
services/surfaceflinger/CompositionEngine/src/planner/LayerState.cpp +8 −8 Original line number Diff line number Diff line Loading @@ -58,24 +58,24 @@ Flags<LayerStateField> LayerState::update(compositionengine::OutputLayer* layer) return differences; } size_t LayerState::getHash( Flags<LayerStateField> skipFields = static_cast<LayerStateField>(0)) const { size_t LayerState::getHash() const { size_t hash = 0; for (const StateInterface* field : getNonUniqueFields()) { android::hashCombineSingleHashed(hash, field->getHash(skipFields)); if (field->getField() == LayerStateField::Buffer) { continue; } android::hashCombineSingleHashed(hash, field->getHash()); } return hash; } Flags<LayerStateField> LayerState::getDifferingFields( const LayerState& other, Flags<LayerStateField> skipFields = static_cast<LayerStateField>(0)) const { Flags<LayerStateField> LayerState::getDifferingFields(const LayerState& other) const { Flags<LayerStateField> differences; auto myFields = getNonUniqueFields(); auto otherFields = other.getNonUniqueFields(); for (size_t i = 0; i < myFields.size(); ++i) { if (skipFields.test(myFields[i]->getField())) { if (myFields[i]->getField() == LayerStateField::Buffer) { continue; } Loading Loading @@ -169,7 +169,7 @@ bool operator==(const LayerState& lhs, const LayerState& rhs) { NonBufferHash getNonBufferHash(const std::vector<const LayerState*>& layers) { size_t hash = 0; for (const auto layer : layers) { android::hashCombineSingleHashed(hash, layer->getHash(LayerStateField::Buffer)); android::hashCombineSingleHashed(hash, layer->getHash()); } return hash; Loading