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

Commit ed20fa4a authored by rnlee's avatar rnlee
Browse files

Enable -Wconversion in BufferStateLayer.

Bug: 129481165
Test: make, atest libsurfaceflinger_unittest
Change-Id: I589add0afb21332a0bc2a4b20f5e8ee8fc85208c
parent 8650d5f4
Loading
Loading
Loading
Loading
+9 −17
Original line number Diff line number Diff line
@@ -14,11 +14,6 @@
 * limitations under the License.
 */

// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
#pragma clang diagnostic ignored "-Wextra"

//#define LOG_NDEBUG 0
#undef LOG_TAG
#define LOG_TAG "BufferStateLayer"
@@ -597,7 +592,7 @@ bool BufferStateLayer::setTransparentRegionHint(const Region& transparent) {
    return true;
}

Rect BufferStateLayer::getBufferSize(const State& s) const {
Rect BufferStateLayer::getBufferSize(const State& /*s*/) const {
    // for buffer state layers we use the display frame size as the buffer size.

    if (mBufferInfo.mBuffer == nullptr) {
@@ -619,7 +614,7 @@ Rect BufferStateLayer::getBufferSize(const State& s) const {
        }
    }

    return Rect(0, 0, bufWidth, bufHeight);
    return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight));
}

FloatRect BufferStateLayer::computeSourceBounds(const FloatRect& parentBounds) const {
@@ -818,7 +813,7 @@ void BufferStateLayer::HwcSlotGenerator::bufferErased(const client_cache_t& clie
    eraseBufferLocked(clientCacheId);
}

uint32_t BufferStateLayer::HwcSlotGenerator::getHwcCacheSlot(const client_cache_t& clientCacheId) {
int BufferStateLayer::HwcSlotGenerator::getHwcCacheSlot(const client_cache_t& clientCacheId) {
    std::lock_guard<std::mutex> lock(mMutex);
    auto itr = mCachedBuffers.find(clientCacheId);
    if (itr == mCachedBuffers.end()) {
@@ -829,7 +824,7 @@ uint32_t BufferStateLayer::HwcSlotGenerator::getHwcCacheSlot(const client_cache_
    return hwcCacheSlot;
}

uint32_t BufferStateLayer::HwcSlotGenerator::addCachedBuffer(const client_cache_t& clientCacheId)
int BufferStateLayer::HwcSlotGenerator::addCachedBuffer(const client_cache_t& clientCacheId)
        REQUIRES(mMutex) {
    if (!clientCacheId.isValid()) {
        ALOGE("invalid process, returning invalid slot");
@@ -838,17 +833,17 @@ uint32_t BufferStateLayer::HwcSlotGenerator::addCachedBuffer(const client_cache_

    ClientCache::getInstance().registerErasedRecipient(clientCacheId, wp<ErasedRecipient>(this));

    uint32_t hwcCacheSlot = getFreeHwcCacheSlot();
    int hwcCacheSlot = getFreeHwcCacheSlot();
    mCachedBuffers[clientCacheId] = {hwcCacheSlot, mCounter++};
    return hwcCacheSlot;
}

uint32_t BufferStateLayer::HwcSlotGenerator::getFreeHwcCacheSlot() REQUIRES(mMutex) {
int BufferStateLayer::HwcSlotGenerator::getFreeHwcCacheSlot() REQUIRES(mMutex) {
    if (mFreeHwcCacheSlots.empty()) {
        evictLeastRecentlyUsed();
    }

    uint32_t hwcCacheSlot = mFreeHwcCacheSlots.top();
    int hwcCacheSlot = mFreeHwcCacheSlots.top();
    mFreeHwcCacheSlots.pop();
    return hwcCacheSlot;
}
@@ -935,8 +930,8 @@ bool BufferStateLayer::bufferNeedsFiltering() const {
        return false;
    }

    uint32_t bufferWidth = s.buffer->getBuffer()->width;
    uint32_t bufferHeight = s.buffer->getBuffer()->height;
    int32_t bufferWidth = s.buffer->getBuffer()->width;
    int32_t bufferHeight = s.buffer->getBuffer()->height;

    // Undo any transformations on the buffer and return the result.
    if (s.bufferTransform & ui::Transform::ROT_90) {
@@ -1011,6 +1006,3 @@ Rect BufferStateLayer::getInputBounds() const {
}

} // namespace android

// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
+6 −7
Original line number Diff line number Diff line
@@ -178,19 +178,19 @@ private:
    class HwcSlotGenerator : public ClientCache::ErasedRecipient {
    public:
        HwcSlotGenerator() {
            for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
            for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
                mFreeHwcCacheSlots.push(i);
            }
        }

        void bufferErased(const client_cache_t& clientCacheId);

        uint32_t getHwcCacheSlot(const client_cache_t& clientCacheId);
        int getHwcCacheSlot(const client_cache_t& clientCacheId);

    private:
        friend class SlotGenerationTest;
        uint32_t addCachedBuffer(const client_cache_t& clientCacheId) REQUIRES(mMutex);
        uint32_t getFreeHwcCacheSlot() REQUIRES(mMutex);
        int addCachedBuffer(const client_cache_t& clientCacheId) REQUIRES(mMutex);
        int getFreeHwcCacheSlot() REQUIRES(mMutex);
        void evictLeastRecentlyUsed() REQUIRES(mMutex);
        void eraseBufferLocked(const client_cache_t& clientCacheId) REQUIRES(mMutex);

@@ -202,11 +202,10 @@ private:

        std::mutex mMutex;

        std::unordered_map<client_cache_t,
                           std::pair<uint32_t /*HwcCacheSlot*/, uint32_t /*counter*/>,
        std::unordered_map<client_cache_t, std::pair<int /*HwcCacheSlot*/, uint64_t /*counter*/>,
                           CachedBufferHash>
                mCachedBuffers GUARDED_BY(mMutex);
        std::stack<uint32_t /*HwcCacheSlot*/> mFreeHwcCacheSlots GUARDED_BY(mMutex);
        std::stack<int /*HwcCacheSlot*/> mFreeHwcCacheSlots GUARDED_BY(mMutex);

        // The cache increments this counter value when a slot is updated or used.
        // Used to track the least recently-used buffer
+1 −1
Original line number Diff line number Diff line
@@ -6791,7 +6791,7 @@ status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const {
    return NO_ERROR;
}

int SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const {
uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const {
    Fps refreshRate(60.f);

    if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) {
+1 −1
Original line number Diff line number Diff line
@@ -942,7 +942,7 @@ private:
        return width > mMaxRenderTargetSize || height > mMaxRenderTargetSize;
    }

    int getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const;
    uint32_t getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const;

    /*
     * Display and layer stack management
+8 −16
Original line number Diff line number Diff line
@@ -14,11 +14,6 @@
 * limitations under the License.
 */

// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
#pragma clang diagnostic ignored "-Wextra"

#undef LOG_TAG
#define LOG_TAG "CachingTest"

@@ -42,7 +37,7 @@ TEST_F(SlotGenerationTest, getHwcCacheSlot_Invalid) {
    sp<IBinder> binder = new BBinder();
    // test getting invalid client_cache_id
    client_cache_t id;
    uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(id);
    int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
    EXPECT_EQ(BufferQueue::INVALID_BUFFER_SLOT, slot);
}

@@ -51,7 +46,7 @@ TEST_F(SlotGenerationTest, getHwcCacheSlot_Basic) {
    client_cache_t id;
    id.token = binder;
    id.id = 0;
    uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(id);
    int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
    EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - 1, slot);

    client_cache_t idB;
@@ -72,31 +67,28 @@ TEST_F(SlotGenerationTest, getHwcCacheSlot_Reuse) {
    std::vector<client_cache_t> ids;
    uint32_t cacheId = 0;
    // fill up cache
    for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
    for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
        client_cache_t id;
        id.token = binder;
        id.id = cacheId;
        ids.push_back(id);

        uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(id);
        int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
        EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
        cacheId++;
    }
    for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
        uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(ids[i]);
    for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
        int slot = mHwcSlotGenerator->getHwcCacheSlot(ids[static_cast<uint32_t>(i)]);
        EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
    }

    for (uint32_t i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
    for (int i = 0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
        client_cache_t id;
        id.token = binder;
        id.id = cacheId;
        uint32_t slot = mHwcSlotGenerator->getHwcCacheSlot(id);
        int slot = mHwcSlotGenerator->getHwcCacheSlot(id);
        EXPECT_EQ(BufferQueue::NUM_BUFFER_SLOTS - (i + 1), slot);
        cacheId++;
    }
}
} // namespace android

// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"