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

Commit b8aaea16 authored by David Sodman's avatar David Sodman
Browse files

SF: use shared_ptr to track hwcLayer

Use std::shared_ptr to track hwcLayer pointers.
This is necessary because the calculation of
data for HWComposer is done in Layer and the processing of that
data is done in SurfaceFlinger, and we need to make sure that
the hwcLayer is not destroyed by Layer while or before being
used by SurfaceFlinger.

Bug: 112259502
Test: cts -m CtsViewTestCases
      SurfaceFlinger_test
      vrflinger_test

Change-Id: I683dd071efbeebd9a9941053183daf4efb88469e
parent f4c8f386
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -230,7 +230,10 @@ sp<IBinder> Layer::getHandle() {
bool Layer::createHwcLayer(HWComposer* hwc, int32_t displayId) {
    LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(displayId) != 0,
                        "Already have a layer for display %d", displayId);
    HWC2::Layer* layer = hwc->createLayer(displayId);
    auto layer = std::shared_ptr<HWC2::Layer>(
            hwc->createLayer(displayId),
            [hwc, displayId](HWC2::Layer* layer) {
               hwc->destroyLayer(displayId, layer); });
    if (!layer) {
        return false;
    }
@@ -249,11 +252,8 @@ bool Layer::destroyHwcLayer(int32_t displayId) {
    auto& hwcInfo = getBE().mHwcLayers[displayId];
    LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
    LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
    hwcInfo.hwc->destroyLayer(displayId, hwcInfo.layer);
    // The layer destroyed listener should have cleared the entry from
    // mHwcLayers. Verify that.
    LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(displayId) != 0,
                        "Stale layer entry in getBE().mHwcLayers");
    hwcInfo.layer = nullptr;

    return true;
}

@@ -716,7 +716,8 @@ void Layer::updateCursorPosition(const sp<const DisplayDevice>& display) {
    auto position = displayTransform.transform(frame);

    auto error =
            getBE().mHwcLayers[displayId].layer->setCursorPosition(position.left, position.top);
            (getBE().mHwcLayers[displayId].layer)->setCursorPosition(
                    position.left, position.top);
    ALOGE_IF(error != HWC2::Error::None,
             "[%s] Failed to set cursor position "
             "to (%d, %d): %s (%d)",
@@ -759,13 +760,13 @@ void Layer::setCompositionType(int32_t displayId, HWC2::Composition type, bool c
    }
    auto& hwcInfo = getBE().mHwcLayers[displayId];
    auto& hwcLayer = hwcInfo.layer;
    ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), to_string(type).c_str(),
    ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", (hwcLayer)->getId(), to_string(type).c_str(),
          static_cast<int>(callIntoHwc));
    if (hwcInfo.compositionType != type) {
        ALOGV("    actually setting");
        hwcInfo.compositionType = type;
        if (callIntoHwc) {
            auto error = hwcLayer->setCompositionType(type);
            auto error = (hwcLayer)->setCompositionType(type);
            ALOGE_IF(error != HWC2::Error::None,
                     "[%s] Failed to set "
                     "composition type %s: %s (%d)",
+1 −1
Original line number Diff line number Diff line
@@ -510,7 +510,7 @@ public:
        if (getBE().mHwcLayers.count(displayId) == 0) {
            return nullptr;
        }
        return getBE().mHwcLayers[displayId].layer;
        return getBE().mHwcLayers[displayId].layer.get();
    }

    // -----------------------------------------------------------------------
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ void LayerBE::onLayerDisplayed(const sp<Fence>& releaseFence) {
}

void CompositionInfo::dumpHwc(const char* tag) const {
    ALOGV("[%s]\thwcLayer=%p", tag, hwc.hwcLayer);
    ALOGV("[%s]\thwcLayer=%p", tag, hwc.hwcLayer.get());
    ALOGV("[%s]\tfence=%p", tag, hwc.fence.get());
    ALOGV("[%s]\ttransform=%d", tag, hwc.transform);
    ALOGV("[%s]\tz=%d", tag, hwc.z);
+2 −2
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ struct CompositionInfo {
    int mBufferSlot = BufferQueue::INVALID_BUFFER_SLOT;
    LayerBE* layer = nullptr;
    struct {
        HWC2::Layer* hwcLayer;
        std::shared_ptr<HWC2::Layer> hwcLayer;
        sp<Fence> fence;
        HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
        Rect displayFrame;
@@ -103,7 +103,7 @@ private:
                transform(HWC2::Transform::None) {}

        HWComposer* hwc;
        HWC2::Layer* layer;
        std::shared_ptr<HWC2::Layer> layer;
        bool forceClientComposition;
        HWC2::Composition compositionType;
        bool clearClientTarget;