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

Commit 2c28f42b authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Automerger Merge Worker
Browse files

Merge "Restore old behavior in pulic API setGeometry" into sc-dev am: 81aec8eb

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14353217

Change-Id: I46eab741eda15c6190cfb961efb07ebd7acf6974
parents f3f9df61 81aec8eb
Loading
Loading
Loading
Loading
+28 −11
Original line number Original line Diff line number Diff line
@@ -438,27 +438,44 @@ void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction,
                                     const ARect& destination, int32_t transform) {
                                     const ARect& destination, int32_t transform) {
    CHECK_NOT_NULL(aSurfaceTransaction);
    CHECK_NOT_NULL(aSurfaceTransaction);
    CHECK_NOT_NULL(aSurfaceControl);
    CHECK_NOT_NULL(aSurfaceControl);
    CHECK_VALID_RECT(source);
    CHECK_VALID_RECT(destination);
    CHECK_VALID_RECT(destination);


    sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
    Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);

    Rect sourceRect = static_cast<const Rect&>(source);
    Rect sourceRect = static_cast<const Rect&>(source);
    Rect destRect = static_cast<const Rect&>(destination);
    // Adjust the source so its top and left are not negative
    // Adjust the source so its top and left are not negative
    sourceRect.left = std::max(sourceRect.left, 0);
    sourceRect.left = std::max(sourceRect.left, 0);
    sourceRect.top = std::max(sourceRect.top, 0);
    sourceRect.top = std::max(sourceRect.top, 0);
    LOG_ALWAYS_FATAL_IF(sourceRect.isEmpty(), "invalid arg passed as source argument");

    sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
    Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);


    if (!sourceRect.isValid()) {
        sourceRect.makeInvalid();
    }
    transaction->setBufferCrop(surfaceControl, sourceRect);
    transaction->setBufferCrop(surfaceControl, sourceRect);


    float dsdx = (destination.right - destination.left) /
    int destW = destRect.width();
            static_cast<float>(sourceRect.right - sourceRect.left);
    int destH = destRect.height();
    float dsdy = (destination.bottom - destination.top) /
    if (destRect.left < 0) {
            static_cast<float>(sourceRect.bottom - sourceRect.top);
        destRect.left = 0;
        destRect.right = destW;
    }
    if (destRect.top < 0) {
        destRect.top = 0;
        destRect.bottom = destH;
    }

    if (!sourceRect.isEmpty()) {
        float sx = destW / static_cast<float>(sourceRect.width());
        float sy = destH / static_cast<float>(sourceRect.height());
        transaction->setPosition(surfaceControl, destRect.left - (sourceRect.left * sx),
                                 destRect.top - (sourceRect.top * sy));
        transaction->setMatrix(surfaceControl, sx, 0, 0, sy);
    } else {
        transaction->setPosition(surfaceControl, destRect.left, destRect.top);
    }


    transaction->setPosition(surfaceControl, destination.left - (sourceRect.left * dsdx),
                             destination.top - (sourceRect.top * dsdy));
    transaction->setMatrix(surfaceControl, dsdx, 0, 0, dsdy);
    transaction->setTransform(surfaceControl, transform);
    transaction->setTransform(surfaceControl, transform);
    bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) ==
    bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) ==
            NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
            NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;