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

Commit d410124d authored by Nicolas Roard's avatar Nicolas Roard
Browse files

Update to ToT RemoteCompose

Bug: 339721781
Flag: EXEMPT External Libraries
Test: in GoB
Change-Id: I29219d6d481df738ff020983f88a0c7130e04252
parent 3b7bd0aa
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public class CoreDocument {

    // We also keep a more fine-grained BUILD number, exposed as
    // ID_API_LEVEL = DOCUMENT_API_LEVEL + BUILD
    static final float BUILD = 0.0f;
    static final float BUILD = 0.1f;

    @NonNull ArrayList<Operation> mOperations = new ArrayList<>();

+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import java.time.ZoneOffset;
 * <p>We also contain a PaintContext, so that any operation can draw as needed.
 */
public abstract class RemoteContext {
    private static final int MAX_OP_COUNT = 100_000; // Maximum cmds per frame
    private static final int MAX_OP_COUNT = 20_000; // Maximum cmds per frame
    protected @NonNull CoreDocument mDocument =
            new CoreDocument(); // todo: is this a valid way to initialize? bbade@
    public @NonNull RemoteComposeState mRemoteComposeState =
+9 −9
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ public class AnimatedFloatExpression {
    /** VAR2 operator */
    public static final float VAR3 = asNan(OFFSET + 43);

    // TODO CLAMP, CBRT, DEG, RAD, EXPM1, CEIL, FLOOR
    // TODO SQUARE, DUP, HYPOT, SWAP
    //    private static final float FP_PI = (float) Math.PI;
    private static final float FP_TO_RAD = 57.29578f; // 180/PI
    private static final float FP_TO_DEG = 0.017453292f; // 180/PI
@@ -172,7 +172,7 @@ public class AnimatedFloatExpression {
    @NonNull float[] mVar = new float[0];
    @Nullable CollectionsAccess mCollectionsAccess;
    IntMap<MonotonicSpline> mSplineMap = new IntMap<>();
    private Random mRandom;
    private static Random sRandom;

    private float getSplineValue(int arrayId, float pos) {
        MonotonicSpline fit = mSplineMap.get(arrayId);
@@ -806,21 +806,21 @@ public class AnimatedFloatExpression {
                return sp - 1;

            case OP_RAND:
                if (mRandom == null) {
                    mRandom = new Random();
                if (sRandom == null) {
                    sRandom = new Random();
                }
                mStack[sp + 1] = mRandom.nextFloat();
                mStack[sp + 1] = sRandom.nextFloat();
                return sp + 1;

            case OP_RAND_SEED:
                float seed = mStack[sp];
                if (seed == 0) {
                    mRandom = new Random();
                    sRandom = new Random();
                } else {
                    if (mRandom == null) {
                        mRandom = new Random(Float.floatToRawIntBits(seed));
                    if (sRandom == null) {
                        sRandom = new Random(Float.floatToRawIntBits(seed));
                    } else {
                        mRandom.setSeed(Float.floatToRawIntBits(seed));
                        sRandom.setSeed(Float.floatToRawIntBits(seed));
                    }
                }
                return sp - 1;
+70 −37
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Choreographer;
import android.view.MotionEvent;
@@ -104,6 +106,7 @@ public class RemoteComposeCanvas extends FrameLayout implements View.OnAttachSta
    public void setDocument(RemoteComposeDocument value) {
        mDocument = value;
        mDocument.initializeContext(mARContext);
        mDisable = false;
        mARContext.setAnimationEnabled(true);
        mARContext.setDensity(mDensity);
        mARContext.setUseChoreographer(true);
@@ -463,6 +466,7 @@ public class RemoteComposeCanvas extends FrameLayout implements View.OnAttachSta
    private long mDuration;
    private boolean mEvalTime = false; // turn on to measure eval time
    private float mLastAnimationTime = 0.1f; // set to random non 0 number
    private boolean mDisable = false;

    /**
     * This returns the amount of time in ms the player used to evalueate a pass it is averaged over
@@ -489,13 +493,19 @@ public class RemoteComposeCanvas extends FrameLayout implements View.OnAttachSta
        if (mDocument == null) {
            return;
        }
        if (mDisable) {
            drawDisable(canvas);
            return;
        }
        try {

            long start = mEvalTime ? System.nanoTime() : 0; // measure execut of commands

            float animationTime = (System.nanoTime() - mStart) * 1E-9f;
            mARContext.setAnimationTime(animationTime);
            mARContext.loadFloat(RemoteContext.ID_ANIMATION_TIME, animationTime);
        mARContext.loadFloat(
                RemoteContext.ID_ANIMATION_DELTA_TIME, animationTime - mLastAnimationTime);
            float loopTime = animationTime - mLastAnimationTime;
            mARContext.loadFloat(RemoteContext.ID_ANIMATION_DELTA_TIME, loopTime);
            mLastAnimationTime = animationTime;
            mARContext.setAnimationEnabled(true);
            mARContext.currentTime = System.currentTimeMillis();
@@ -531,5 +541,28 @@ public class RemoteComposeCanvas extends FrameLayout implements View.OnAttachSta
                mDuration += System.nanoTime() - start;
                mCount++;
            }
        } catch (Exception ex) {
            mARContext.getLastOpCount();
            mDisable = true;
            invalidate();
        }
    }

    private void drawDisable(Canvas canvas) {
        Rect rect = new Rect();
        canvas.drawColor(Color.BLACK);
        Paint paint = new Paint();
        paint.setTextSize(128f);
        paint.setColor(Color.RED);
        int w = getWidth();
        int h = getHeight();

        String str = "⚠";
        paint.getTextBounds(str, 0, 1, rect);

        float x = w / 2f - rect.width() / 2f - rect.left;
        float y = h / 2f + rect.height() / 2f - rect.bottom;

        canvas.drawText(str, x, y, paint);
    }
}