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

Commit 074e8122 authored by Lloyd Pique's avatar Lloyd Pique
Browse files

Revert "Revert "surfacefligner: revert recent BE/FE split changes""

This reverts commit 0756cdd4.

Reason for revert: b/111793219 Power regression, with urgent fix needed.

Test: run cts -m CtsDeqpTestCases, run cts -m CtsViewTestCases

Change-Id: I4f089100af6a788b5973961a214132c97597fa7e
parent b7d1230e
Loading
Loading
Loading
Loading
+49 −9
Original line number Diff line number Diff line
@@ -633,14 +633,37 @@ 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);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(),
              to_string(error).c_str(), static_cast<int32_t>(error));
        visible.dump(LOG_TAG);
    }

    getBE().compositionInfo.hwc.visibleRegion = visible;
    getBE().compositionInfo.hwc.surfaceDamage = surfaceDamageRegion;
    error = hwcLayer->setSurfaceDamage(surfaceDamageRegion);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(),
              to_string(error).c_str(), static_cast<int32_t>(error));
        surfaceDamageRegion.dump(LOG_TAG);
    }

    // Sideband layers
    if (getBE().compositionInfo.hwc.sidebandStream.get()) {
        setCompositionType(displayId, HWC2::Composition::Sideband);
        getBE().compositionInfo.compositionType = HWC2::Composition::Sideband;
        ALOGV("[%s] Requesting Sideband composition", mName.string());
        error = hwcLayer->setSidebandStream(getBE().compositionInfo.hwc.sidebandStream->handle());
        if (error != HWC2::Error::None) {
            ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", mName.string(),
                  getBE().compositionInfo.hwc.sidebandStream->handle(), to_string(error).c_str(),
                  static_cast<int32_t>(error));
        }
        return;
    }

@@ -653,14 +676,31 @@ void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& display) {
        setCompositionType(displayId, HWC2::Composition::Device);
    }

    getBE().compositionInfo.hwc.dataspace = mCurrentDataSpace;
    getBE().compositionInfo.hwc.hdrMetadata = mConsumer->getCurrentHdrMetadata();
    getBE().compositionInfo.hwc.supportedPerFrameMetadata = display->getSupportedPerFrameMetadata();
    ALOGV("setPerFrameData: dataspace = %d", mCurrentDataSpace);
    error = hwcLayer->setDataspace(mCurrentDataSpace);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set dataspace %d: %s (%d)", mName.string(), mCurrentDataSpace,
              to_string(error).c_str(), static_cast<int32_t>(error));
    }

    const HdrMetadata& metadata = mConsumer->getCurrentHdrMetadata();
    error = hwcLayer->setPerFrameMetadata(display->getSupportedPerFrameMetadata(), metadata);
    if (error != HWC2::Error::None && error != HWC2::Error::Unsupported) {
        ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", mName.string(),
              to_string(error).c_str(), static_cast<int32_t>(error));
    }

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

    auto acquireFence = mConsumer->getCurrentFence();
    getBE().compositionInfo.mBufferSlot = mActiveBufferSlot;
    getBE().compositionInfo.mBuffer = mActiveBuffer;
    getBE().compositionInfo.hwc.fence = acquireFence;
    error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(),
              getBE().compositionInfo.mBuffer->handle, to_string(error).c_str(),
              static_cast<int32_t>(error));
    }
}

bool BufferLayer::isOpaque(const Layer::State& s) const {
+31 −6
Original line number Diff line number Diff line
@@ -76,18 +76,43 @@ 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();
    getBE().compositionInfo.hwc.visibleRegion = visible;
    getBE().compositionInfo.hwc.dataspace = mCurrentDataSpace;
    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);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(),
              to_string(error).c_str(), static_cast<int32_t>(error));
        visible.dump(LOG_TAG);
    }

    setCompositionType(displayId, HWC2::Composition::SolidColor);

    error = hwcLayer->setDataspace(mCurrentDataSpace);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set dataspace %d: %s (%d)", mName.string(), mCurrentDataSpace,
              to_string(error).c_str(), static_cast<int32_t>(error));
    }

    half4 color = getColor();
    getBE().compositionInfo.hwc.color = { static_cast<uint8_t>(std::round(255.0f * color.r)),
    error = hwcLayer->setColor({static_cast<uint8_t>(std::round(255.0f * color.r)),
                                static_cast<uint8_t>(std::round(255.0f * color.g)),
                                      static_cast<uint8_t>(std::round(255.0f * color.b)), 255 };
                                static_cast<uint8_t>(std::round(255.0f * color.b)), 255});
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set color: %s (%d)", mName.string(), to_string(error).c_str(),
              static_cast<int32_t>(error));
    }

    // Clear out the transform, because it doesn't make sense absent a source buffer
    getBE().compositionInfo.hwc.transform = HWC2::Transform::None;
    error = hwcLayer->setTransform(HWC2::Transform::None);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to clear transform: %s (%d)", mName.string(), to_string(error).c_str(),
              static_cast<int32_t>(error));
    }
}

// ---------------------------------------------------------------------------
+47 −15
Original line number Diff line number Diff line
@@ -503,9 +503,6 @@ void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
    }
    auto& hwcInfo = getBE().mHwcLayers[displayId];

    // Need to program geometry parts
    getBE().compositionInfo.hwc.skipGeometry = false;

    // enable this layer
    hwcInfo.forceClientComposition = false;

@@ -513,6 +510,8 @@ void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
        hwcInfo.forceClientComposition = true;
    }

    auto& hwcLayer = hwcInfo.layer;

    // this gives us only the "orientation" component of the transform
    const State& s(getDrawingState());
    auto blendMode = HWC2::BlendMode::None;
@@ -520,7 +519,12 @@ void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
        blendMode =
                mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
    }
    getBE().compositionInfo.hwc.blendMode = blendMode;
    auto error = hwcLayer->setBlendMode(blendMode);
    ALOGE_IF(error != HWC2::Error::None,
             "[%s] Failed to set blend mode %s:"
             " %s (%d)",
             mName.string(), to_string(blendMode).c_str(), to_string(error).c_str(),
             static_cast<int32_t>(error));

    // apply the layer's transform, followed by the display's global transform
    // here we're guaranteed that the layer's transform preserves rects
@@ -563,15 +567,36 @@ void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
    }
    const Transform& tr = display->getTransform();
    Rect transformedFrame = tr.transform(frame);
    getBE().compositionInfo.hwc.displayFrame = transformedFrame;
    error = hwcLayer->setDisplayFrame(transformedFrame);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(),
              transformedFrame.left, transformedFrame.top, transformedFrame.right,
              transformedFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
    } else {
        hwcInfo.displayFrame = transformedFrame;
    }

    FloatRect sourceCrop = computeCrop(display);
    getBE().compositionInfo.hwc.sourceCrop = sourceCrop;
    error = hwcLayer->setSourceCrop(sourceCrop);
    if (error != HWC2::Error::None) {
        ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
              "%s (%d)",
              mName.string(), sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom,
              to_string(error).c_str(), static_cast<int32_t>(error));
    } else {
        hwcInfo.sourceCrop = sourceCrop;
    }

    float alpha = static_cast<float>(getAlpha());
    getBE().compositionInfo.hwc.alpha = alpha;
    error = hwcLayer->setPlaneAlpha(alpha);
    ALOGE_IF(error != HWC2::Error::None,
             "[%s] Failed to set plane alpha %.3f: "
             "%s (%d)",
             mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error));

    getBE().compositionInfo.hwc.z = z;
    error = hwcLayer->setZOrder(z);
    ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z,
             to_string(error).c_str(), static_cast<int32_t>(error));

    int type = s.type;
    int appId = s.appId;
@@ -584,8 +609,9 @@ void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
        }
    }

    getBE().compositionInfo.hwc.type = type;
    getBE().compositionInfo.hwc.appId = appId;
    error = hwcLayer->setInfo(type, appId);
    ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(),
             static_cast<int32_t>(error));

    /*
     * Transformations are applied in this order:
@@ -622,11 +648,16 @@ void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
    const uint32_t orientation = transform.getOrientation();
    if (orientation & Transform::ROT_INVALID) {
        // we can only handle simple transformation
        getBE().mHwcLayers[displayId].compositionType = HWC2::Composition::Client;
        hwcInfo.forceClientComposition = true;
    } else {
        auto transform = static_cast<HWC2::Transform>(orientation);
        hwcInfo.transform = transform;
        getBE().compositionInfo.hwc.transform = transform;
        auto error = hwcLayer->setTransform(transform);
        ALOGE_IF(error != HWC2::Error::None,
                 "[%s] Failed to set transform %s: "
                 "%s (%d)",
                 mName.string(), to_string(transform).c_str(), to_string(error).c_str(),
                 static_cast<int32_t>(error));
    }
}

@@ -1467,16 +1498,17 @@ void Layer::miniDump(String8& result, int32_t displayId) const {
    result.appendFormat(" %s\n", name.string());

    const Layer::State& layerState(getDrawingState());
    const LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers.at(displayId);
    if (layerState.zOrderRelativeOf != nullptr || mDrawingParent != nullptr) {
        result.appendFormat("  rel %6d | ", layerState.z);
    } else {
        result.appendFormat("  %10d | ", layerState.z);
    }
    result.appendFormat("%10s | ", to_string(getCompositionType(displayId)).c_str());
    result.appendFormat("%10s | ", to_string(getBE().mHwcLayers[displayId].transform).c_str());
    const Rect& frame = getBE().compositionInfo.hwc.displayFrame;
    result.appendFormat("%10s | ", to_string(hwcInfo.transform).c_str());
    const Rect& frame = hwcInfo.displayFrame;
    result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
    const FloatRect& crop = getBE().compositionInfo.hwc.sourceCrop;
    const FloatRect& crop = hwcInfo.sourceCrop;
    result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right, crop.bottom);

    result.append("- - - - - - - - - - - - - - - -");
+0 −8
Original line number Diff line number Diff line
@@ -472,14 +472,6 @@ public:
        return getBE().mHwcLayers[displayId].layer;
    }

    bool setHwcLayer(int32_t hwcId) {
        if (getBE().mHwcLayers.count(hwcId) == 0) {
            return false;
        }
        getBE().compositionInfo.hwc.hwcLayer = getBE().mHwcLayers[hwcId].layer;
        return true;
    }

    // -----------------------------------------------------------------------

    void clearWithOpenGL(const RenderArea& renderArea) const;
+2 −4
Original line number Diff line number Diff line
@@ -19,9 +19,10 @@
#include <stdint.h>
#include <sys/types.h>

#include <gui/HdrMetadata.h>
#include <ui/Region.h>

#include "SurfaceFlinger.h"

#include "DisplayHardware/HWComposer.h"
#include "DisplayHardware/HWComposerBufferCache.h"
#include "RenderEngine/Mesh.h"
@@ -39,7 +40,6 @@ struct CompositionInfo {
    LayerBE* layer = nullptr;
    struct {
        HWC2::Layer* hwcLayer;
        bool skipGeometry = true;
        sp<Fence> fence;
        HWC2::BlendMode blendMode = HWC2::BlendMode::Invalid;
        Rect displayFrame;
@@ -54,8 +54,6 @@ struct CompositionInfo {
        sp<NativeHandle> sidebandStream;
        ui::Dataspace dataspace;
        hwc_color_t color;
        bool supportedPerFrameMetadata = false;
        HdrMetadata hdrMetadata;
    } hwc;
    struct {
        Mesh* mesh;
Loading