Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e22b4e84 authored by Huihong Luo's avatar Huihong Luo Committed by Android (Google) Code Review
Browse files

Merge "Store a wp GraphicBuffer pointer instead of an sp on LayerState" into sc-dev

parents b5183f21 a19a8960
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -40,7 +40,9 @@ public:
        const LayerState* getState() const { return mState; }
        const LayerState* getState() const { return mState; }
        const std::string& getName() const { return mState->getName(); }
        const std::string& getName() const { return mState->getName(); }
        Rect getDisplayFrame() const { return mState->getDisplayFrame(); }
        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(); }
        int64_t getFramesSinceBufferUpdate() const { return mState->getFramesSinceBufferUpdate(); }
        NonBufferHash getHash() const { return mHash; }
        NonBufferHash getHash() const { return mHash; }
        std::chrono::steady_clock::time_point getLastUpdate() const { return mLastUpdate; }
        std::chrono::steady_clock::time_point getLastUpdate() const { return mLastUpdate; }
+26 −14
Original line number Original line Diff line number Diff line
@@ -32,6 +32,14 @@ template <typename T>
struct hash<android::sp<T>> {
struct hash<android::sp<T>> {
    size_t operator()(const android::sp<T>& p) { return std::hash<void*>()(p.get()); }
    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 std


namespace android::compositionengine::impl::planner {
namespace android::compositionengine::impl::planner {
@@ -70,7 +78,7 @@ public:


    virtual Flags<LayerStateField> update(const compositionengine::OutputLayer* layer) = 0;
    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;
    virtual LayerStateField getField() const = 0;


@@ -113,6 +121,10 @@ public:
    // Returns this member's field flag if it was changed
    // Returns this member's field flag if it was changed
    Flags<LayerStateField> update(const compositionengine::OutputLayer* layer) override {
    Flags<LayerStateField> update(const compositionengine::OutputLayer* layer) override {
        T newValue = mReader(layer);
        T newValue = mReader(layer);
        return update(newValue);
    }

    Flags<LayerStateField> update(const T& newValue) {
        if (!mEquals(mValue, newValue)) {
        if (!mEquals(mValue, newValue)) {
            mValue = newValue;
            mValue = newValue;
            mHash = {};
            mHash = {};
@@ -124,10 +136,7 @@ public:
    LayerStateField getField() const override { return FIELD; }
    LayerStateField getField() const override { return FIELD; }
    const T& get() const { return mValue; }
    const T& get() const { return mValue; }


    size_t getHash(Flags<LayerStateField> skipFields) const override {
    size_t getHash() const override {
        if (skipFields.test(FIELD)) {
            return 0;
        }
        if (!mHash) {
        if (!mHash) {
            mHash = std::hash<T>{}(mValue);
            mHash = std::hash<T>{}(mValue);
        }
        }
@@ -175,13 +184,13 @@ public:
    Flags<LayerStateField> update(compositionengine::OutputLayer*);
    Flags<LayerStateField> update(compositionengine::OutputLayer*);


    // Computes a hash for this LayerState.
    // Computes a hash for this LayerState.
    // The hash is only computed from NonUniqueFields.
    // The hash is only computed from NonUniqueFields, and excludes GraphicBuffers since they are
    size_t getHash(Flags<LayerStateField> skipFields) const;
    // 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.
    // Returns the bit-set of differing fields between this LayerState and another LayerState.
    // This bit-set is based on NonUniqueFields only
    // This bit-set is based on NonUniqueFields only, and excludes GraphicBuffers.
    Flags<LayerStateField> getDifferingFields(const LayerState& other,
    Flags<LayerStateField> getDifferingFields(const LayerState& other) const;
                                              Flags<LayerStateField> skipFields) const;


    compositionengine::OutputLayer* getOutputLayer() const { return mOutputLayer; }
    compositionengine::OutputLayer* getOutputLayer() const { return mOutputLayer; }
    int32_t getId() const { return mId.get(); }
    int32_t getId() const { return mId.get(); }
@@ -190,7 +199,6 @@ public:
    hardware::graphics::composer::hal::Composition getCompositionType() const {
    hardware::graphics::composer::hal::Composition getCompositionType() const {
        return mCompositionType.get();
        return mCompositionType.get();
    }
    }
    const sp<GraphicBuffer>& getBuffer() const { return mBuffer.get(); }


    void incrementFramesSinceBufferUpdate() { ++mFramesSinceBufferUpdate; }
    void incrementFramesSinceBufferUpdate() { ++mFramesSinceBufferUpdate; }
    void resetFramesSinceBufferUpdate() { mFramesSinceBufferUpdate = 0; }
    void resetFramesSinceBufferUpdate() { mFramesSinceBufferUpdate = 0; }
@@ -311,10 +319,14 @@ private:
                                return std::vector<std::string>{base::StringPrintf("%p", p)};
                                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; },
            mBuffer{[](auto layer) { return layer->getLayerFE().getCompositionState()->buffer; },
                    [](const sp<GraphicBuffer>& buffer) {
                    [](const wp<GraphicBuffer>& buffer) {
                        return std::vector<std::string>{base::StringPrintf("%p", buffer.get())};
                        sp<GraphicBuffer> promotedBuffer = buffer.promote();
                        return std::vector<std::string>{
                                base::StringPrintf("%p",
                                                   promotedBuffer ? promotedBuffer.get()
                                                                  : nullptr)};
                    }};
                    }};


    int64_t mFramesSinceBufferUpdate = 0;
    int64_t mFramesSinceBufferUpdate = 0;
+2 −2
Original line number Original line Diff line number Diff line
@@ -51,10 +51,10 @@ std::string durationString(std::chrono::milliseconds duration) {
}
}


CachedSet::Layer::Layer(const LayerState* state, std::chrono::steady_clock::time_point lastUpdate)
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)
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);
    addLayer(layer, lastUpdate);
}
}


+1 −3
Original line number Original line Diff line number Diff line
@@ -193,9 +193,7 @@ bool Flattener::mergeWithCachedSets(const std::vector<const LayerState*>& layers
    auto currentLayerIter = mLayers.begin();
    auto currentLayerIter = mLayers.begin();
    auto incomingLayerIter = layers.begin();
    auto incomingLayerIter = layers.begin();
    while (incomingLayerIter != layers.end()) {
    while (incomingLayerIter != layers.end()) {
        if (mNewCachedSet &&
        if (mNewCachedSet && mNewCachedSet->getFingerprint() == (*incomingLayerIter)->getHash()) {
            mNewCachedSet->getFingerprint() ==
                    (*incomingLayerIter)->getHash(LayerStateField::Buffer)) {
            if (mNewCachedSet->hasBufferUpdate()) {
            if (mNewCachedSet->hasBufferUpdate()) {
                ALOGV("[%s] Dropping new cached set", __func__);
                ALOGV("[%s] Dropping new cached set", __func__);
                ++mInvalidatedCachedSetAges[0];
                ++mInvalidatedCachedSetAges[0];
+8 −8
Original line number Original line Diff line number Diff line
@@ -58,24 +58,24 @@ Flags<LayerStateField> LayerState::update(compositionengine::OutputLayer* layer)
    return differences;
    return differences;
}
}


size_t LayerState::getHash(
size_t LayerState::getHash() const {
        Flags<LayerStateField> skipFields = static_cast<LayerStateField>(0)) const {
    size_t hash = 0;
    size_t hash = 0;
    for (const StateInterface* field : getNonUniqueFields()) {
    for (const StateInterface* field : getNonUniqueFields()) {
        android::hashCombineSingleHashed(hash, field->getHash(skipFields));
        if (field->getField() == LayerStateField::Buffer) {
            continue;
        }
        android::hashCombineSingleHashed(hash, field->getHash());
    }
    }


    return hash;
    return hash;
}
}


Flags<LayerStateField> LayerState::getDifferingFields(
Flags<LayerStateField> LayerState::getDifferingFields(const LayerState& other) const {
        const LayerState& other,
        Flags<LayerStateField> skipFields = static_cast<LayerStateField>(0)) const {
    Flags<LayerStateField> differences;
    Flags<LayerStateField> differences;
    auto myFields = getNonUniqueFields();
    auto myFields = getNonUniqueFields();
    auto otherFields = other.getNonUniqueFields();
    auto otherFields = other.getNonUniqueFields();
    for (size_t i = 0; i < myFields.size(); ++i) {
    for (size_t i = 0; i < myFields.size(); ++i) {
        if (skipFields.test(myFields[i]->getField())) {
        if (myFields[i]->getField() == LayerStateField::Buffer) {
            continue;
            continue;
        }
        }


@@ -169,7 +169,7 @@ bool operator==(const LayerState& lhs, const LayerState& rhs) {
NonBufferHash getNonBufferHash(const std::vector<const LayerState*>& layers) {
NonBufferHash getNonBufferHash(const std::vector<const LayerState*>& layers) {
    size_t hash = 0;
    size_t hash = 0;
    for (const auto layer : layers) {
    for (const auto layer : layers) {
        android::hashCombineSingleHashed(hash, layer->getHash(LayerStateField::Buffer));
        android::hashCombineSingleHashed(hash, layer->getHash());
    }
    }


    return hash;
    return hash;
Loading