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

Commit 197743ff authored by Nader Jawad's avatar Nader Jawad
Browse files

Update hole punch logic in HWUI

--Updated HWUI holepunch logic for SurfaceView to
also apply the stretch to the hole punch
--Updated RenderNode callbacks to also include
an offset from the ancestor RenderNode that also
has a stretch configured on it
--Added new test activity to verify hole punch
logic

Bug: 179047472
Test: manual
Change-Id: Ibbaf8248a31839ba9dc352ecb9fef54e1276918e
parent 9443a3e8
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -146,8 +146,9 @@ public final class SurfaceControl implements Parcelable {
    private static native void nativeSetBlurRegions(long transactionObj, long nativeObj,
    private static native void nativeSetBlurRegions(long transactionObj, long nativeObj,
            float[][] regions, int length);
            float[][] regions, int length);
    private static native void nativeSetStretchEffect(long transactionObj, long nativeObj,
    private static native void nativeSetStretchEffect(long transactionObj, long nativeObj,
            float left, float top, float right, float bottom, float vecX, float vecY,
            float width, float height, float vecX, float vecY,
            float maxStretchAmount);
            float maxStretchAmountX, float maxStretchAmountY, float childRelativeLeft,
            float childRelativeTop, float childRelativeRight, float childRelativeBottom);


    private static native boolean nativeClearContentFrameStats(long nativeObject);
    private static native boolean nativeClearContentFrameStats(long nativeObject);
    private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats);
    private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats);
@@ -3038,11 +3039,14 @@ public final class SurfaceControl implements Parcelable {
        /**
        /**
         * @hide
         * @hide
         */
         */
        public Transaction setStretchEffect(SurfaceControl sc, float left, float top, float right,
        public Transaction setStretchEffect(SurfaceControl sc, float width, float height,
                float bottom, float vecX, float vecY, float maxStretchAmount) {
                float vecX, float vecY, float maxStretchAmountX,
                float maxStretchAmountY, float childRelativeLeft, float childRelativeTop, float childRelativeRight,
                float childRelativeBottom) {
            checkPreconditions(sc);
            checkPreconditions(sc);
            nativeSetStretchEffect(mNativeObject, sc.mNativeObject, left, top, right, bottom,
            nativeSetStretchEffect(mNativeObject, sc.mNativeObject, width, height,
                    vecX, vecY, maxStretchAmount);
                    vecX, vecY, maxStretchAmountX, maxStretchAmountY, childRelativeLeft, childRelativeTop,
                    childRelativeRight, childRelativeBottom);
            return this;
            return this;
        }
        }


+7 −4
Original line number Original line Diff line number Diff line
@@ -1471,10 +1471,13 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        }
        }


        @Override
        @Override
        public void applyStretch(long frameNumber, float left, float top, float right,
        public void applyStretch(long frameNumber, float width, float height,
                float bottom, float vecX, float vecY, float maxStretch) {
                float vecX, float vecY, float maxStretchX, float maxStretchY,
            mRtTransaction.setStretchEffect(mSurfaceControl, left, top, right, bottom, vecX, vecY,
                float childRelativeLeft, float childRelativeTop, float childRelativeRight,
                    maxStretch);
                float childRelativeBottom) {
            mRtTransaction.setStretchEffect(mSurfaceControl, width, height, vecX, vecY,
                    maxStretchX, maxStretchY, childRelativeLeft, childRelativeTop,
                    childRelativeRight, childRelativeBottom);
            applyOrMergeTransaction(mRtTransaction, frameNumber);
            applyOrMergeTransaction(mRtTransaction, frameNumber);
        }
        }


+4 −8
Original line number Original line Diff line number Diff line
@@ -641,14 +641,10 @@ public class EdgeEffect {
            boolean hasValidVectors = Float.isFinite(vecX) && Float.isFinite(vecY);
            boolean hasValidVectors = Float.isFinite(vecX) && Float.isFinite(vecY);
            if (right > left && bottom > top && mWidth > 0 && mHeight > 0 && hasValidVectors) {
            if (right > left && bottom > top && mWidth > 0 && mHeight > 0 && hasValidVectors) {
                renderNode.stretch(
                renderNode.stretch(
                        left,
                        vecX, // horizontal stretch intensity
                        top,
                        vecY, // vertical stretch intensity
                        right,
                        mWidth, // max horizontal stretch in pixels
                        bottom,
                        mHeight // max vertical stretch in pixels
                        vecX,
                        vecY,
                        mWidth,
                        mHeight
                );
                );
            }
            }
        } else {
        } else {
+18 −6
Original line number Original line Diff line number Diff line
@@ -626,12 +626,24 @@ static void nativeSetBlurRegions(JNIEnv* env, jclass clazz, jlong transactionObj
}
}


static void nativeSetStretchEffect(JNIEnv* env, jclass clazz, jlong transactionObj,
static void nativeSetStretchEffect(JNIEnv* env, jclass clazz, jlong transactionObj,
                                   jlong nativeObject, jfloat left, jfloat top, jfloat right,
                                   jlong nativeObject, jfloat width, jfloat height,
                                   jfloat bottom, jfloat vecX, jfloat vecY,
                                   jfloat vecX, jfloat vecY,
                                   jfloat maxStretchAmount) {
                                   jfloat maxStretchAmountX, jfloat maxStretchAmountY,
                                   jfloat childRelativeLeft, jfloat childRelativeTop,
                                   jfloat childRelativeRight, jfloat childRelativeBottom) {
    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
    SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
    auto* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
    transaction->setStretchEffect(ctrl, left, top, right, bottom, vecX, vecY, maxStretchAmount);
    auto stretch = StretchEffect{
      .width = width,
      .height = height,
      .vectorX = vecX,
      .vectorY = vecY,
      .maxAmountX = maxStretchAmountX,
      .maxAmountY = maxStretchAmountY,
      .mappedChildBounds = FloatRect(
          childRelativeLeft, childRelativeTop, childRelativeRight, childRelativeBottom)
    };
    transaction->setStretchEffect(ctrl, stretch);
}
}


static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
@@ -1829,7 +1841,7 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeSetLayerStack },
            (void*)nativeSetLayerStack },
    {"nativeSetBlurRegions", "(JJ[[FI)V",
    {"nativeSetBlurRegions", "(JJ[[FI)V",
            (void*)nativeSetBlurRegions },
            (void*)nativeSetBlurRegions },
    {"nativeSetStretchEffect", "(JJFFFFFFF)V",
    {"nativeSetStretchEffect", "(JJFFFFFFFFFF)V",
            (void*) nativeSetStretchEffect },
            (void*) nativeSetStretchEffect },
    {"nativeSetShadowRadius", "(JJF)V",
    {"nativeSetShadowRadius", "(JJF)V",
            (void*)nativeSetShadowRadius },
            (void*)nativeSetShadowRadius },
+15 −18
Original line number Original line Diff line number Diff line
@@ -280,8 +280,10 @@ public final class RenderNode {
         *
         *
         * @hide
         * @hide
         */
         */
        default void applyStretch(long frameNumber, float left, float top, float right,
        default void applyStretch(long frameNumber, float width, float height,
                float bottom, float vecX, float vecY, float maxStretch) { }
                float vecX, float vecY,
                float maxStretchX, float maxStretchY, float childRelativeLeft,
                float childRelativeTop, float childRelativeRight, float childRelativeBottom) { }


        /**
        /**
         * Called by native on RenderThread to notify that the view is no longer in the
         * Called by native on RenderThread to notify that the view is no longer in the
@@ -326,10 +328,13 @@ public final class RenderNode {
        }
        }


        @Override
        @Override
        public void applyStretch(long frameNumber, float left, float top, float right, float bottom,
        public void applyStretch(long frameNumber, float width, float height,
                float vecX, float vecY, float maxStretch) {
                float vecX, float vecY, float maxStretchX, float maxStretchY, float childRelativeLeft,
                float childRelativeTop, float childRelativeRight, float childRelativeBottom) {
            for (PositionUpdateListener pul : mListeners) {
            for (PositionUpdateListener pul : mListeners) {
                pul.applyStretch(frameNumber, left, top, right, bottom, vecX, vecY, maxStretch);
                pul.applyStretch(frameNumber, width, height, vecX, vecY, maxStretchX,
                        maxStretchY, childRelativeLeft, childRelativeTop, childRelativeRight,
                        childRelativeBottom);
            }
            }
        }
        }
    }
    }
@@ -719,19 +724,15 @@ public final class RenderNode {
    }
    }


    /** @hide */
    /** @hide */
    public boolean stretch(float left, float top, float right, float bottom,
    public boolean stretch(float vecX, float vecY,
            float vecX, float vecY, float maxStretchAmountX, float maxStretchAmountY) {
        float maxStretchAmountX, float maxStretchAmountY) {
        if (Float.isInfinite(vecX) || Float.isNaN(vecX)) {
        if (Float.isInfinite(vecX) || Float.isNaN(vecX)) {
            throw new IllegalArgumentException("vecX must be a finite, non-NaN value " + vecX);
            throw new IllegalArgumentException("vecX must be a finite, non-NaN value " + vecX);
        }
        }
        if (Float.isInfinite(vecY) || Float.isNaN(vecY)) {
        if (Float.isInfinite(vecY) || Float.isNaN(vecY)) {
            throw new IllegalArgumentException("vecY must be a finite, non-NaN value " + vecY);
            throw new IllegalArgumentException("vecY must be a finite, non-NaN value " + vecY);
        }
        }
        if (top >= bottom || left >= right) {

            throw new IllegalArgumentException(
                    "Stretch region must not be empty, got "
                            + new RectF(left, top, right, bottom).toString());
        }
        if (maxStretchAmountX <= 0.0f) {
        if (maxStretchAmountX <= 0.0f) {
            throw new IllegalArgumentException(
            throw new IllegalArgumentException(
                    "The max horizontal stretch amount must be >0, got " + maxStretchAmountX);
                    "The max horizontal stretch amount must be >0, got " + maxStretchAmountX);
@@ -742,10 +743,6 @@ public final class RenderNode {
        }
        }
        return nStretch(
        return nStretch(
                mNativeRenderNode,
                mNativeRenderNode,
                left,
                top,
                right,
                bottom,
                vecX,
                vecX,
                vecY,
                vecY,
                maxStretchAmountX,
                maxStretchAmountX,
@@ -1701,8 +1698,8 @@ public final class RenderNode {
    private static native boolean nClearStretch(long renderNode);
    private static native boolean nClearStretch(long renderNode);


    @CriticalNative
    @CriticalNative
    private static native boolean nStretch(long renderNode, float left, float top, float right,
    private static native boolean nStretch(long renderNode, float vecX, float vecY,
            float bottom, float vecX, float vecY, float maxStretchX, float maxStretchY);
            float maxStretchX, float maxStretchY);


    @CriticalNative
    @CriticalNative
    private static native boolean nHasShadow(long renderNode);
    private static native boolean nHasShadow(long renderNode);
Loading