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

Commit 861616df authored by Marissa Wall's avatar Marissa Wall
Browse files

blast: use frame instead of size and position

BufferStateLayers will have a source crop rect and destination
frame rect. The crop is the portion of the buffer that should be
displayed. The frame is where that portion of the buffer should
be displayed. The portion of the cropped buffer is scaled to fit
the frame.

Shader provided by romainguy@google.com.

Test: Transaction_test
Bug: 80477568

Change-Id: Ied3f3af2211132f79098aeb986292ee705a62219
parent 8a3083ee
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ status_t layer_state_t::write(Parcel& output) const
    output.writeUint32(transform);
    output.writeBool(transformToDisplayInverse);
    output.write(crop);
    output.write(frame);
    if (buffer) {
        output.writeBool(true);
        output.write(*buffer);
@@ -135,6 +136,7 @@ status_t layer_state_t::read(const Parcel& input)
    transform = input.readUint32();
    transformToDisplayInverse = input.readBool();
    input.read(crop);
    input.read(frame);
    buffer = new GraphicBuffer();
    if (input.readBool()) {
        input.read(*buffer);
@@ -322,6 +324,10 @@ void layer_state_t::merge(const layer_state_t& other) {
        what |= eCropChanged;
        crop = other.crop;
    }
    if (other.what & eFrameChanged) {
        what |= eFrameChanged;
        frame = other.frame;
    }
    if (other.what & eBufferChanged) {
        what |= eBufferChanged;
        buffer = other.buffer;
+14 −0
Original line number Diff line number Diff line
@@ -609,6 +609,20 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCrop(
    return *this;
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFrame(
        const sp<SurfaceControl>& sc, const Rect& frame) {
    layer_state_t* s = getLayerState(sc);
    if (!s) {
        mStatus = BAD_INDEX;
        return *this;
    }
    s->what |= layer_state_t::eFrameChanged;
    s->frame = frame;

    registerSurfaceControlForCallback(sc);
    return *this;
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffer(
        const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer) {
    layer_state_t* s = getLayerState(sc);
+3 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ struct layer_state_t {
        eListenerCallbacksChanged = 0x20000000,
        eInputInfoChanged = 0x40000000,
        eCornerRadiusChanged = 0x80000000,
        eFrameChanged = 0x1'00000000,
    };

    layer_state_t()
@@ -104,6 +105,7 @@ struct layer_state_t {
            transform(0),
            transformToDisplayInverse(false),
            crop(Rect::INVALID_RECT),
            frame(Rect::INVALID_RECT),
            dataspace(ui::Dataspace::UNKNOWN),
            surfaceDamageRegion(),
            api(-1),
@@ -157,6 +159,7 @@ struct layer_state_t {
    uint32_t transform;
    bool transformToDisplayInverse;
    Rect crop;
    Rect frame;
    sp<GraphicBuffer> buffer;
    sp<Fence> acquireFence;
    ui::Dataspace dataspace;
+1 −0
Original line number Diff line number Diff line
@@ -295,6 +295,7 @@ public:
        Transaction& setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
                                                  bool transformToDisplayInverse);
        Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop);
        Transaction& setFrame(const sp<SurfaceControl>& sc, const Rect& frame);
        Transaction& setBuffer(const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer);
        Transaction& setAcquireFence(const sp<SurfaceControl>& sc, const sp<Fence>& fence);
        Transaction& setDataspace(const sp<SurfaceControl>& sc, ui::Dataspace dataspace);
+51 −38
Original line number Diff line number Diff line
@@ -95,10 +95,9 @@ bool BufferStateLayer::applyPendingStates(Layer::State* stateToCommit) {
    return stateUpdateAvailable;
}

Rect BufferStateLayer::getCrop(const Layer::State& s) const {
    return (getEffectiveScalingMode() == NATIVE_WINDOW_SCALING_MODE_SCALE_CROP)
            ? GLConsumer::scaleDownCrop(s.crop, s.active.w, s.active.h)
            : s.crop;
// Crop that applies to the window
Rect BufferStateLayer::getCrop(const Layer::State& /*s*/) const {
    return Rect::INVALID_RECT;
}

bool BufferStateLayer::setTransform(uint32_t transform) {
@@ -128,6 +127,30 @@ bool BufferStateLayer::setCrop(const Rect& crop) {
    return true;
}

bool BufferStateLayer::setFrame(const Rect& frame) {
    int x = frame.left;
    int y = frame.top;
    int w = frame.getWidth();
    int h = frame.getHeight();

    if (mCurrentState.active.transform.tx() == x && mCurrentState.active.transform.ty() == y &&
        mCurrentState.active.w == w && mCurrentState.active.h == h) {
        return false;
    }

    if (!frame.isValid()) {
        x = y = w = h = 0;
    }
    mCurrentState.active.transform.set(x, y);
    mCurrentState.active.w = w;
    mCurrentState.active.h = h;

    mCurrentState.sequence++;
    mCurrentState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}

bool BufferStateLayer::setBuffer(const sp<GraphicBuffer>& buffer) {
    if (mCurrentState.buffer) {
        mReleasePreviousBuffer = true;
@@ -237,27 +260,6 @@ bool BufferStateLayer::setTransactionCompletedListeners(
    return willPresent;
}

bool BufferStateLayer::setSize(uint32_t w, uint32_t h) {
    if (mCurrentState.active.w == w && mCurrentState.active.h == h) return false;
    mCurrentState.active.w = w;
    mCurrentState.active.h = h;
    mCurrentState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}

bool BufferStateLayer::setPosition(float x, float y, bool /*immediate*/) {
    if (mCurrentState.active.transform.tx() == x && mCurrentState.active.transform.ty() == y)
        return false;

    mCurrentState.active.transform.set(x, y);

    mCurrentState.sequence++;
    mCurrentState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}

bool BufferStateLayer::setTransparentRegionHint(const Region& transparent) {
    mCurrentState.transparentRegionHint = transparent;
    mCurrentState.modified = true;
@@ -265,21 +267,26 @@ bool BufferStateLayer::setTransparentRegionHint(const Region& transparent) {
    return true;
}

bool BufferStateLayer::setMatrix(const layer_state_t::matrix22_t& matrix,
                                 bool allowNonRectPreservingTransforms) {
    ui::Transform t;
    t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
Rect BufferStateLayer::getBufferSize(const State& s) const {
    // for buffer state layers we use the display frame size as the buffer size.
    if (getActiveWidth(s) < UINT32_MAX && getActiveHeight(s) < UINT32_MAX) {
        return Rect(getActiveWidth(s), getActiveHeight(s));
    }

    if (!allowNonRectPreservingTransforms && !t.preserveRects()) {
        ALOGW("Attempt to set rotation matrix without permission ACCESS_SURFACE_FLINGER ignored");
        return false;
    // if the display frame is not defined, use the parent bounds as the buffer size.
    const auto& p = mDrawingParent.promote();
    if (p != nullptr) {
        Rect parentBounds = Rect(p->computeBounds(Region()));
        if (!parentBounds.isEmpty()) {
            return parentBounds;
        }
    }

    mCurrentState.sequence++;
    mCurrentState.active.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
    mCurrentState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
    // if there is no parent layer, use the buffer's bounds as the buffer size
    if (s.buffer) {
        return s.buffer->getBounds();
    }
    return Rect::INVALID_RECT;
}
// -----------------------------------------------------------------------

@@ -315,8 +322,14 @@ ui::Dataspace BufferStateLayer::getDrawingDataSpace() const {
    return getDrawingState().dataspace;
}

// Crop that applies to the buffer
Rect BufferStateLayer::getDrawingCrop() const {
    return Rect::INVALID_RECT;
    const State& s(getDrawingState());

    if (s.crop.isEmpty() && s.buffer) {
        return s.buffer->getBounds();
    }
    return s.crop;
}

uint32_t BufferStateLayer::getDrawingScalingMode() const {
Loading