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

Commit 3b1ded17 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Wire up SurfaceView stretch effect" into sc-dev

parents e02aef66 5d53a754
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -142,6 +142,9 @@ public final class SurfaceControl implements Parcelable {
            int layerStack);
    private static native void nativeSetBlurRegions(long transactionObj, long nativeObj,
            float[][] regions, int length);
    private static native void nativeSetStretchEffect(long transactionObj, long nativeObj,
            float left, float top, float right, float bottom, float vecX, float vecY,
            float maxStretchAmount);

    private static native boolean nativeClearContentFrameStats(long nativeObject);
    private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats);
@@ -2970,6 +2973,17 @@ public final class SurfaceControl implements Parcelable {
            return this;
        }

        /**
         * @hide
         */
        public Transaction setStretchEffect(SurfaceControl sc, float left, float top, float right,
                float bottom, float vecX, float vecY, float maxStretchAmount) {
            checkPreconditions(sc);
            nativeSetStretchEffect(mNativeObject, sc.mNativeObject, left, top, right, bottom,
                    vecX, vecY, maxStretchAmount);
            return this;
        }

        /**
         * @hide
         */
+8 −0
Original line number Diff line number Diff line
@@ -1443,6 +1443,14 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
            }
        }

        @Override
        public void applyStretch(long frameNumber, float left, float top, float right,
                float bottom, float vecX, float vecY, float maxStretch) {
            mRtTransaction.setStretchEffect(mSurfaceControl, left, top, right, bottom, vecX, vecY,
                    maxStretch);
            applyRtTransaction(frameNumber);
        }

        @Override
        public void positionLost(long frameNumber) {
            if (DEBUG) {
+11 −0
Original line number Diff line number Diff line
@@ -593,6 +593,15 @@ static void nativeSetBlurRegions(JNIEnv* env, jclass clazz, jlong transactionObj
    transaction->setBlurRegions(ctrl, blurRegionVector);
}

static void nativeSetStretchEffect(JNIEnv* env, jclass clazz, jlong transactionObj,
                                   jlong nativeObject, jfloat left, jfloat top, jfloat right,
                                   jfloat bottom, jfloat vecX, jfloat vecY,
                                   jfloat maxStretchAmount) {
    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
    SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
    transaction->setStretchEffect(ctrl, left, top, right, bottom, vecX, vecY, maxStretchAmount);
}

static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
        jlong nativeObject, jint w, jint h) {
    auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
@@ -1769,6 +1778,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeSetLayerStack },
    {"nativeSetBlurRegions", "(JJ[[FI)V",
            (void*)nativeSetBlurRegions },
    {"nativeSetStretchEffect", "(JJFFFFFFF)V",
            (void*) nativeSetStretchEffect },
    {"nativeSetShadowRadius", "(JJF)V",
            (void*)nativeSetShadowRadius },
    {"nativeSetFrameRate", "(JJFIZ)V",
+19 −1
Original line number Diff line number Diff line
@@ -271,6 +271,16 @@ public final class RenderNode {
         */
        void positionChanged(long frameNumber, int left, int top, int right, int bottom);

        /**
         * Call to apply a stretch effect to any child SurfaceControl layers
         *
         * TODO: Fold this into positionChanged & have HWUI do the ASurfaceControl calls?
         *
         * @hide
         */
        default void applyStretch(long frameNumber, float left, float top, float right,
                float bottom, float vecX, float vecY, float maxStretch) { }

        /**
         * Called by native on RenderThread to notify that the view is no longer in the
         * draw tree. UI thread is blocked at this point.
@@ -312,6 +322,14 @@ public final class RenderNode {
                pul.positionLost(frameNumber);
            }
        }

        @Override
        public void applyStretch(long frameNumber, float left, float top, float right, float bottom,
                float vecX, float vecY, float maxStretch) {
            for (PositionUpdateListener pul : mListeners) {
                pul.applyStretch(frameNumber, left, top, right, bottom, vecX, vecY, maxStretch);
            }
        }
    }

    /**
@@ -707,7 +725,7 @@ public final class RenderNode {
        if (1.0 < vecY || vecY < -1.0) {
            throw new IllegalArgumentException("vecY must be in the range [-1, 1], was " + vecY);
        }
        if (top <= bottom || right <= left) {
        if (top >= bottom || left >= right) {
            throw new IllegalArgumentException(
                    "Stretch region must not be empty, got "
                            + new RectF(left, top, right, bottom).toString());
+15 −0
Original line number Diff line number Diff line
@@ -249,5 +249,20 @@ void DamageAccumulator::finish(SkRect* totalDirty) {
    mHead->pendingDirty.setEmpty();
}

const StretchEffect* DamageAccumulator::findNearestStretchEffect() const {
    DirtyStack* frame = mHead;
    while (frame->prev != frame) {
        frame = frame->prev;
        if (frame->type == TransformRenderNode) {
            const auto& effect =
                    frame->renderNode->properties().layerProperties().getStretchEffect();
            if (!effect.isEmpty()) {
                return &effect;
            }
        }
    }
    return nullptr;
}

} /* namespace uirenderer */
} /* namespace android */
Loading