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

Commit 4459bf40 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

HWC2: refactor code to convert a Region to hwcRects

This code already appears twice, and
I991c8e1beca22075ec831f96dff218e6af3d9a08 will add a third use. Move it
into a common function so that it can be called by all three.

Bug: 212736475
Test: existing tests (no change in behavior)
Change-Id: Ibe7684b415c08b7bec01188dbab4655c91086372
parent e5cff63e
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -584,6 +584,21 @@ std::shared_ptr<HWC2::Layer> Display::getLayerById(HWLayerId id) const {

// Layer methods

namespace {
std::vector<Hwc2::IComposerClient::Rect> convertRegionToHwcRects(const Region& region) {
    size_t rectCount = 0;
    Rect const* rectArray = region.getArray(&rectCount);

    std::vector<Hwc2::IComposerClient::Rect> hwcRects;
    hwcRects.reserve(rectCount);
    for (size_t rect = 0; rect < rectCount; ++rect) {
        hwcRects.push_back({rectArray[rect].left, rectArray[rect].top, rectArray[rect].right,
                            rectArray[rect].bottom});
    }
    return hwcRects;
}
} // namespace

Layer::~Layer() = default;

namespace impl {
@@ -674,15 +689,7 @@ Error Layer::setSurfaceDamage(const Region& damage)
        intError = mComposer.setLayerSurfaceDamage(mDisplay->getId(), mId,
                                                   std::vector<Hwc2::IComposerClient::Rect>());
    } else {
        size_t rectCount = 0;
        auto rectArray = damage.getArray(&rectCount);

        std::vector<Hwc2::IComposerClient::Rect> hwcRects;
        for (size_t rect = 0; rect < rectCount; ++rect) {
            hwcRects.push_back({rectArray[rect].left, rectArray[rect].top,
                    rectArray[rect].right, rectArray[rect].bottom});
        }

        const auto hwcRects = convertRegionToHwcRects(damage);
        intError = mComposer.setLayerSurfaceDamage(mDisplay->getId(), mId, hwcRects);
    }

@@ -870,16 +877,7 @@ Error Layer::setVisibleRegion(const Region& region)
        return Error::NONE;
    }
    mVisibleRegion = region;

    size_t rectCount = 0;
    auto rectArray = region.getArray(&rectCount);

    std::vector<Hwc2::IComposerClient::Rect> hwcRects;
    for (size_t rect = 0; rect < rectCount; ++rect) {
        hwcRects.push_back({rectArray[rect].left, rectArray[rect].top,
                rectArray[rect].right, rectArray[rect].bottom});
    }

    const auto hwcRects = convertRegionToHwcRects(region);
    auto intError = mComposer.setLayerVisibleRegion(mDisplay->getId(), mId, hwcRects);
    return static_cast<Error>(intError);
}