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

Commit 4b7c4bc2 authored by David Sodman's avatar David Sodman
Browse files

SF: Use CompositionInfo to program HWComposer

Test: Build and run manually
Merged-Id: I3a4fd676781d0b7db1665430e0d84a6bc9b83f60
Change-Id: I3a4fd676781d0b7db1665430e0d84a6bc9b83f60
parent dc5e0627
Loading
Loading
Loading
Loading
+8 −45
Original line number Original line Diff line number Diff line
@@ -593,32 +593,14 @@ void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& displayDevice)
    const auto& viewport = displayDevice->getViewport();
    const auto& viewport = displayDevice->getViewport();
    Region visible = tr.transform(visibleRegion.intersect(viewport));
    Region visible = tr.transform(visibleRegion.intersect(viewport));
    auto hwcId = displayDevice->getHwcDisplayId();
    auto hwcId = displayDevice->getHwcDisplayId();
    auto& hwcInfo = getBE().mHwcLayers[hwcId];
    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);
    }


    error = (*hwcLayer)->setSurfaceDamage(surfaceDamageRegion);
    getBE().compositionInfo.hwc.visibleRegion = visible;
    if (error != HWC2::Error::None) {
    getBE().compositionInfo.hwc.surfaceDamage = surfaceDamageRegion;
        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
    // Sideband layers
    if (getBE().compositionInfo.hwc.sidebandStream.get()) {
    if (getBE().compositionInfo.hwc.sidebandStream.get()) {
        setCompositionType(hwcId, HWC2::Composition::Sideband);
        setCompositionType(hwcId, HWC2::Composition::Sideband);
        ALOGV("[%s] Requesting Sideband composition", mName.string());
        getBE().compositionInfo.compositionType = HWC2::Composition::Sideband;
        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;
        return;
    }
    }


@@ -631,32 +613,13 @@ void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& displayDevice)
        setCompositionType(hwcId, HWC2::Composition::Device);
        setCompositionType(hwcId, HWC2::Composition::Device);
    }
    }


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

    const HdrMetadata& metadata = mConsumer->getCurrentHdrMetadata();
    error = (*hwcLayer)->setHdrMetadata(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;
    getBE().mHwcLayers[hwcId].bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer, &hwcSlot,
                                                       &hwcBuffer);


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


bool BufferLayer::isOpaque(const Layer::State& s) const {
bool BufferLayer::isOpaque(const Layer::State& s) const {
+6 −26
Original line number Original line Diff line number Diff line
@@ -77,38 +77,18 @@ void ColorLayer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) {
    const auto& viewport = displayDevice->getViewport();
    const auto& viewport = displayDevice->getViewport();
    Region visible = tr.transform(visibleRegion.intersect(viewport));
    Region visible = tr.transform(visibleRegion.intersect(viewport));
    auto hwcId = displayDevice->getHwcDisplayId();
    auto hwcId = displayDevice->getHwcDisplayId();
    auto& hwcInfo = getBE().mHwcLayers[hwcId];
    getBE().compositionInfo.hwc.visibleRegion = visible;
    auto& hwcLayer = hwcInfo.layer;
    getBE().compositionInfo.hwc.dataspace = mDrawingState.dataSpace;
    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(hwcId, HWC2::Composition::SolidColor);
    setCompositionType(hwcId, HWC2::Composition::SolidColor);


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

    half4 color = getColor();
    half4 color = getColor();
    error = (*hwcLayer)->setColor({static_cast<uint8_t>(std::round(255.0f * color.r)),
    getBE().compositionInfo.hwc.color = { 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.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
    // Clear out the transform, because it doesn't make sense absent a source buffer
    error = (*hwcLayer)->setTransform(HWC2::Transform::None);
    getBE().compositionInfo.hwc.transform = 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));
    }
}
}


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
+111 −44
Original line number Original line Diff line number Diff line
@@ -490,8 +490,6 @@ void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z
        hwcInfo.forceClientComposition = true;
        hwcInfo.forceClientComposition = true;
    }
    }


    auto& hwcLayer = hwcInfo.layer;

    // this gives us only the "orientation" component of the transform
    // this gives us only the "orientation" component of the transform
    const State& s(getDrawingState());
    const State& s(getDrawingState());
    auto blendMode = HWC2::BlendMode::None;
    auto blendMode = HWC2::BlendMode::None;
@@ -499,12 +497,7 @@ void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z
        blendMode =
        blendMode =
                mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
                mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
    }
    }
    auto error = (*hwcLayer)->setBlendMode(blendMode);
    getBE().compositionInfo.hwc.blendMode = 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
    // apply the layer's transform, followed by the display's global transform
    // here we're guaranteed that the layer's transform preserves rects
    // here we're guaranteed that the layer's transform preserves rects
@@ -547,36 +540,15 @@ void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z
    }
    }
    const Transform& tr(displayDevice->getTransform());
    const Transform& tr(displayDevice->getTransform());
    Rect transformedFrame = tr.transform(frame);
    Rect transformedFrame = tr.transform(frame);
    error = (*hwcLayer)->setDisplayFrame(transformedFrame);
    getBE().compositionInfo.hwc.displayFrame = 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(displayDevice);
    FloatRect sourceCrop = computeCrop(displayDevice);
    error = (*hwcLayer)->setSourceCrop(sourceCrop);
    getBE().compositionInfo.hwc.sourceCrop = 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());
    float alpha = static_cast<float>(getAlpha());
    error = (*hwcLayer)->setPlaneAlpha(alpha);
    getBE().compositionInfo.hwc.alpha = 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));


    error = (*hwcLayer)->setZOrder(z);
    getBE().compositionInfo.hwc.z = 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 type = s.type;
    int appId = s.appId;
    int appId = s.appId;
@@ -587,9 +559,8 @@ void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z
        appId = parentState.appId;
        appId = parentState.appId;
    }
    }


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


    /*
    /*
     * Transformations are applied in this order:
     * Transformations are applied in this order:
@@ -636,12 +607,109 @@ void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z
    } else {
    } else {
        auto transform = static_cast<HWC2::Transform>(orientation);
        auto transform = static_cast<HWC2::Transform>(orientation);
        hwcInfo.transform = transform;
        hwcInfo.transform = transform;
        auto error = (*hwcLayer)->setTransform(transform);
        getBE().compositionInfo.hwc.transform = transform;
    }
}

void Layer::configureHwcLayer(const sp<const DisplayDevice>& displayDevice) {
    ATRACE_CALL();

    auto hwcId = displayDevice->getHwcDisplayId();
    auto& hwcInfo = getBE().mHwcLayers[hwcId];
    auto& hwcLayer = hwcInfo.layer;

    auto error = (*hwcLayer)->setBlendMode(getBE().compositionInfo.hwc.blendMode);
    ALOGE_IF(error != HWC2::Error::None,
             "[%s] Failed to set blend mode %s:"
             " %s (%d)",
             mName.string(),
             to_string(getBE().compositionInfo.hwc.blendMode).c_str(), to_string(error).c_str(),
             static_cast<int32_t>(error));

    error = (*hwcLayer)->setDisplayFrame(getBE().compositionInfo.hwc.displayFrame);
    ALOGE_IF(error != HWC2::Error::None,
            "[%s] Failed to set the display frame [%d, %d, %d, %d] %s (%d)",
            mName.string(),
            getBE().compositionInfo.hwc.displayFrame.left,
            getBE().compositionInfo.hwc.displayFrame.right,
            getBE().compositionInfo.hwc.displayFrame.top,
            getBE().compositionInfo.hwc.displayFrame.bottom,
            to_string(error).c_str(), static_cast<int32_t>(error));


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

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

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

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

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

    error = (*hwcLayer)->setVisibleRegion(getBE().compositionInfo.hwc.visibleRegion);
    ALOGE_IF(error != HWC2::Error::None,
            "[%s] Failed to set visible region: %s (%d)",
            mName.string(), to_string(error).c_str(), static_cast<int32_t>(error));

    error = (*hwcLayer)->setSurfaceDamage(getBE().compositionInfo.hwc.surfaceDamage);
    ALOGE_IF(error != HWC2::Error::None,
            "[%s] Failed to set surface damage: %s (%d)",
            mName.string(), to_string(error).c_str(), static_cast<int32_t>(error));

    error = (*hwcLayer)->setCompositionType(getBE().compositionInfo.compositionType);
    ALOGE_IF(error != HWC2::Error::None,
            "[%s] Failed to set composition type: %s (%d)",
            mName.string(), to_string(error).c_str(), static_cast<int32_t>(error));

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

    error = (*hwcLayer)->setHdrMetadata(getBE().compositionInfo.hwc.hdrMetadata);
    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));
    }

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

    if (getBE().compositionInfo.hwc.fence) {
        error = (*hwcLayer)->setBuffer(getBE().compositionInfo.mBufferSlot,
                getBE().compositionInfo.mBuffer, getBE().compositionInfo.hwc.fence);
        ALOGE_IF(error != HWC2::Error::None,
                "[%s] Failed to set buffer: %s (%d)",
                mName.string(), to_string(error).c_str(), static_cast<int32_t>(error));
    }
    }
}
}


@@ -1488,12 +1556,11 @@ void Layer::miniDump(String8& result, int32_t hwcId) const {
    result.appendFormat(" %s\n", name.string());
    result.appendFormat(" %s\n", name.string());


    const Layer::State& layerState(getDrawingState());
    const Layer::State& layerState(getDrawingState());
    const LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers.at(hwcId);
    result.appendFormat("  %10d | ", layerState.z);
    result.appendFormat("  %10d | ", layerState.z);
    result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
    result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
    const Rect& frame = hwcInfo.displayFrame;
    const Rect& frame = getBE().compositionInfo.hwc.displayFrame;
    result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
    result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
    const FloatRect& crop = hwcInfo.sourceCrop;
    const FloatRect& crop = getBE().compositionInfo.hwc.sourceCrop;
    result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right, crop.bottom);
    result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right, crop.bottom);


    result.append("- - - - - - - - - - - - - - - - - - - - ");
    result.append("- - - - - - - - - - - - - - - - - - - - ");
+1 −0
Original line number Original line Diff line number Diff line
@@ -309,6 +309,7 @@ public:
    virtual void setDefaultBufferSize(uint32_t /*w*/, uint32_t /*h*/) {}
    virtual void setDefaultBufferSize(uint32_t /*w*/, uint32_t /*h*/) {}


    void setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z);
    void setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z);
    void configureHwcLayer(const sp<const DisplayDevice>& displayDevice);
    void forceClientComposition(int32_t hwcId);
    void forceClientComposition(int32_t hwcId);
    bool getForceClientComposition(int32_t hwcId);
    bool getForceClientComposition(int32_t hwcId);
    virtual void setPerFrameData(const sp<const DisplayDevice>& displayDevice) = 0;
    virtual void setPerFrameData(const sp<const DisplayDevice>& displayDevice) = 0;
+2 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/types.h>


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


#include "SurfaceFlinger.h"
#include "SurfaceFlinger.h"
@@ -80,6 +81,7 @@ struct CompositionInfo {
        sp<NativeHandle> sidebandStream;
        sp<NativeHandle> sidebandStream;
        android_dataspace dataspace;
        android_dataspace dataspace;
        hwc_color_t color;
        hwc_color_t color;
        HdrMetadata hdrMetadata;
    } hwc;
    } hwc;
    struct {
    struct {
        Mesh* mesh;
        Mesh* mesh;
Loading