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

Commit d340261e authored by Rob Carr's avatar Rob Carr Committed by Android (Google) Code Review
Browse files

Merge changes Ic8309518,If3199d7c,Ie4d32162

* changes:
  SurfaceFlinger: Inherit Alpha for child surfaces.
  Add SurfaceFlinger test filter for presubmit.
  Include finalCrop in setGeometryAppliesWithResize.
parents f37eca0f 6452f12c
Loading
Loading
Loading
Loading
+33 −11
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ void Layer::setGeometry(
    const State& s(getDrawingState());
#ifdef USE_HWC2
    auto blendMode = HWC2::BlendMode::None;
    if (!isOpaque(s) || s.alpha != 1.0f) {
    if (!isOpaque(s) || getAlpha() != 1.0f) {
        blendMode = mPremultipliedAlpha ?
                HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
    }
@@ -604,7 +604,7 @@ void Layer::setGeometry(
             " %s (%d)", mName.string(), to_string(blendMode).c_str(),
             to_string(error).c_str(), static_cast<int32_t>(error));
#else
    if (!isOpaque(s) || s.alpha != 0xFF) {
    if (!isOpaque(s) || getAlpha() != 0xFF) {
        layer.setBlending(mPremultipliedAlpha ?
                HWC_BLENDING_PREMULT :
                HWC_BLENDING_COVERAGE);
@@ -678,9 +678,10 @@ void Layer::setGeometry(
        hwcInfo.sourceCrop = sourceCrop;
    }

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

    error = hwcLayer->setZOrder(z);
@@ -698,7 +699,7 @@ void Layer::setGeometry(
    const Transform& tr(hw->getTransform());
    layer.setFrame(tr.transform(frame));
    layer.setCrop(computeCrop(hw));
    layer.setPlaneAlpha(s.alpha);
    layer.setPlaneAlpha(getAlpha());
#endif

    /*
@@ -1147,7 +1148,7 @@ void Layer::drawWithOpenGL(const sp<const DisplayDevice>& hw,
    texCoords[3] = vec2(right, 1.0f - top);

    RenderEngine& engine(mFlinger->getRenderEngine());
    engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), s.alpha);
    engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), getAlpha());
    engine.drawMesh(mMesh);
    engine.disableBlending();
}
@@ -1753,11 +1754,15 @@ bool Layer::setCrop(const Rect& crop, bool immediate) {
    setTransactionFlags(eTransactionNeeded);
    return true;
}
bool Layer::setFinalCrop(const Rect& crop) {

bool Layer::setFinalCrop(const Rect& crop, bool immediate) {
    if (mCurrentState.finalCrop == crop)
        return false;
    mCurrentState.sequence++;
    mCurrentState.requestedFinalCrop = crop;
    if (immediate) {
        mCurrentState.finalCrop = crop;
    }
    mCurrentState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
@@ -1957,12 +1962,11 @@ bool Layer::isHiddenByPolicy() const {
}

bool Layer::isVisible() const {
    const Layer::State& s(mDrawingState);
#ifdef USE_HWC2
    return !(isHiddenByPolicy()) && s.alpha > 0.0f
    return !(isHiddenByPolicy()) && getAlpha() > 0.0f
            && (mActiveBuffer != NULL || mSidebandStream != NULL);
#else
    return !(isHiddenByPolicy()) && s.alpha
    return !(isHiddenByPolicy()) && getAlpha()
            && (mActiveBuffer != NULL || mSidebandStream != NULL);
#endif
}
@@ -2519,6 +2523,24 @@ Transform Layer::getTransform() const {
    return t * getDrawingState().active.transform;
}

#ifdef USE_HWC2
float Layer::getAlpha() const {
    const auto& p = getParent();

    float parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0;
    return parentAlpha * getDrawingState().alpha;
}
#else
uint8_t Layer::getAlpha() const {
    const auto& p = getParent();

    float parentAlpha = (p != nullptr) ? (p->getAlpha() / 255.0f) : 1.0;
    float drawingAlpha = getDrawingState().alpha / 255.0f;
    drawingAlpha = drawingAlpha * parentAlpha;
    return static_cast<uint8_t>(std::round(drawingAlpha * 255));
}
#endif

void Layer::commitChildList() {
    for (size_t i = 0; i < mCurrentChildren.size(); i++) {
        const auto& child = mCurrentChildren[i];
+17 −2
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ public:

        // finalCrop is expressed in display space coordinate.
        Rect finalCrop;
        Rect requestedFinalCrop;

        // If set, defers this state update until the identified Layer
        // receives a frame with the given frameNumber
@@ -163,7 +164,14 @@ public:
    status_t setBuffers(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags);

    // modify current state

    // These members of state (position, crop, and finalCrop)
    // may be updated immediately or have the update delayed
    // until a pending surface resize completes (if applicable).
    bool setPosition(float x, float y, bool immediate);
    bool setCrop(const Rect& crop, bool immediate);
    bool setFinalCrop(const Rect& crop, bool immediate);

    bool setLayer(int32_t z);
    bool setSize(uint32_t w, uint32_t h);
#ifdef USE_HWC2
@@ -174,8 +182,6 @@ public:
    bool setMatrix(const layer_state_t::matrix22_t& matrix);
    bool setTransparentRegionHint(const Region& transparent);
    bool setFlags(uint8_t flags, uint8_t mask);
    bool setCrop(const Rect& crop, bool immediate);
    bool setFinalCrop(const Rect& crop);
    bool setLayerStack(uint32_t layerStack);
    bool setDataSpace(android_dataspace dataSpace);
    uint32_t getLayerStack() const;
@@ -453,6 +459,15 @@ public:

    Transform getTransform() const;

    // Returns the Alpha of the Surface, accounting for the Alpha
    // of parent Surfaces in the hierarchy (alpha's will be multiplied
    // down the hierarchy).
#ifdef USE_HWC2
    float getAlpha() const;
#else
    uint8_t getAlpha() const;
#endif

    void traverseInReverseZOrder(const std::function<void(Layer*)>& exec);
    void traverseInZOrder(const std::function<void(Layer*)>& exec);

+5 −0
Original line number Diff line number Diff line
@@ -120,6 +120,11 @@ bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item)
        mCurrent.crop = mFront.requestedCrop;
        mRecomputeVisibleRegions = true;
    }
    if (mFront.finalCrop != mFront.requestedFinalCrop) {
        mFront.finalCrop = mFront.requestedFinalCrop;
        mCurrent.finalCrop = mFront.requestedFinalCrop;
        mRecomputeVisibleRegions = true;
    }
    mFreezePositionUpdates = false;

    return false;
+1 −1
Original line number Diff line number Diff line
@@ -2766,7 +2766,7 @@ uint32_t SurfaceFlinger::setClientStateLocked(
                flags |= eTraversalNeeded;
        }
        if (what & layer_state_t::eFinalCropChanged) {
            if (layer->setFinalCrop(s.finalCrop))
            if (layer->setFinalCrop(s.finalCrop, !geometryAppliesWithResize))
                flags |= eTraversalNeeded;
        }
        if (what & layer_state_t::eLayerStackChanged) {
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ LOCAL_STATIC_LIBRARIES := libtrace_proto

LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code

LOCAL_TEST_DATA = SurfaceFlinger_test.filter

# Build the binary to $(TARGET_OUT_DATA_NATIVE_TESTS)/$(LOCAL_MODULE)
# to integrate with auto-test framework.
include $(BUILD_NATIVE_TEST)
Loading