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

Commit 91b1df2f authored by Peiyong Lin's avatar Peiyong Lin
Browse files

[SurfaceFlinger] Checking nullptr for HWC layer.

There were several places where we didn't check nullptr when accessing HWC
layer, which results in function call on nullptr when external display was
disconnected. This patch makes sure we check HWC layer before calling functions
on it.

BUG: 80325674
Test: Build, flash, boot, watch videos
Change-Id: I302ad4eeea5c196daadcdccb596dac60b02d3845
parent 5d51a061
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -613,6 +613,11 @@ void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& display) {
    const auto& viewport = display->getViewport();
    Region visible = tr.transform(visibleRegion.intersect(viewport));
    const auto displayId = display->getId();
    if (!hasHwcLayer(displayId)) {
        ALOGE("[%s] failed to setPerFrameData: no HWC layer found (%d)",
              mName.string(), displayId);
        return;
    }
    auto& hwcInfo = getBE().mHwcLayers[displayId];
    auto& hwcLayer = hwcInfo.layer;
    auto error = hwcLayer->setVisibleRegion(visible);
@@ -667,8 +672,7 @@ void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& display) {

    uint32_t hwcSlot = 0;
    sp<GraphicBuffer> hwcBuffer;
    getBE().mHwcLayers[displayId].bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer,
                                                           &hwcSlot, &hwcBuffer);
    hwcInfo.bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer, &hwcSlot, &hwcBuffer);

    auto acquireFence = mConsumer->getCurrentFence();
    error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence);
+5 −0
Original line number Diff line number Diff line
@@ -66,6 +66,11 @@ void ColorLayer::setPerFrameData(const sp<const DisplayDevice>& display) {
    const auto& viewport = display->getViewport();
    Region visible = tr.transform(visibleRegion.intersect(viewport));
    const auto displayId = display->getId();
    if (!hasHwcLayer(displayId)) {
        ALOGE("[%s] failed to setPerFrameData: no HWC layer found (%d)",
              mName.string(), displayId);
        return;
    }
    auto& hwcInfo = getBE().mHwcLayers[displayId];
    auto& hwcLayer = hwcInfo.layer;
    auto error = hwcLayer->setVisibleRegion(visible);
+9 −0
Original line number Diff line number Diff line
@@ -482,6 +482,11 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {

void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
    const auto displayId = display->getId();
    if (!hasHwcLayer(displayId)) {
        ALOGE("[%s] failed to setGeometry: no HWC layer found (%d)",
              mName.string(), displayId);
        return;
    }
    auto& hwcInfo = getBE().mHwcLayers[displayId];

    // enable this layer
@@ -1980,6 +1985,10 @@ void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet)
}

void Layer::writeToProto(LayerProto* layerInfo, int32_t displayId) {
    if (!hasHwcLayer(displayId)) {
        return;
    }

    writeToProto(layerInfo, LayerVector::StateSet::Drawing);

    const auto& hwcInfo = getBE().mHwcLayers.at(displayId);