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

Commit 604556c6 authored by Nicolas Roard's avatar Nicolas Roard Committed by Android (Google) Code Review
Browse files

Merge "add suport for integer operations" into main

parents e87aed2e 0e808480
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.internal.widget.remotecompose.core.operations.DrawTweenPath;
import com.android.internal.widget.remotecompose.core.operations.FloatConstant;
import com.android.internal.widget.remotecompose.core.operations.FloatExpression;
import com.android.internal.widget.remotecompose.core.operations.Header;
import com.android.internal.widget.remotecompose.core.operations.IntegerExpression;
import com.android.internal.widget.remotecompose.core.operations.MatrixRestore;
import com.android.internal.widget.remotecompose.core.operations.MatrixRotate;
import com.android.internal.widget.remotecompose.core.operations.MatrixSave;
@@ -54,6 +55,8 @@ import com.android.internal.widget.remotecompose.core.operations.TextFromFloat;
import com.android.internal.widget.remotecompose.core.operations.TextMerge;
import com.android.internal.widget.remotecompose.core.operations.Theme;
import com.android.internal.widget.remotecompose.core.operations.utilities.IntMap;
import com.android.internal.widget.remotecompose.core.types.BooleanConstant;
import com.android.internal.widget.remotecompose.core.types.IntegerConstant;

/**
 * List of operations supported in a RemoteCompose document
@@ -109,6 +112,9 @@ public class Operations {
    public static final int TEXT_MERGE = 136;
    public static final int NAMED_VARIABLE = 137;
    public static final int COLOR_CONSTANT = 138;
    public static final int DATA_INT = 140;
    public static final int DATA_BOOLEAN = 143;
    public static final int INTEGER_EXPRESSION = 144;

    /////////////////////////////////////////======================
    public static IntMap<CompanionOperation> map = new IntMap<>();
@@ -153,6 +159,9 @@ public class Operations {
        map.put(TEXT_MERGE, TextMerge.COMPANION);
        map.put(NAMED_VARIABLE, NamedVariable.COMPANION);
        map.put(COLOR_CONSTANT, ColorConstant.COMPANION);
        map.put(DATA_INT, IntegerConstant.COMPANION);
        map.put(INTEGER_EXPRESSION, IntegerExpression.COMPANION);
        map.put(DATA_BOOLEAN, BooleanConstant.COMPANION);
    }

}
+14 −0
Original line number Diff line number Diff line
@@ -59,6 +59,16 @@ public abstract class PaintContext {

    public abstract void drawRect(float left, float top, float right, float bottom);

    /**
     * this caches the paint to a paint stack
     */
    public abstract void  savePaint();

    /**
     * This restores the paint form the paint stack
     */
    public abstract void  restorePaint();

    public abstract void drawRoundRect(float left,
                                       float top,
                                       float right,
@@ -119,6 +129,10 @@ public abstract class PaintContext {
                                       float start,
                                       float stop);

    /**
     * This applies changes to the current paint
     * @param mPaintData the list of changes
     */
    public abstract void applyPaint(PaintBundle mPaintData);

    /**
+36 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.internal.widget.remotecompose.core.operations.DrawTweenPath;
import com.android.internal.widget.remotecompose.core.operations.FloatConstant;
import com.android.internal.widget.remotecompose.core.operations.FloatExpression;
import com.android.internal.widget.remotecompose.core.operations.Header;
import com.android.internal.widget.remotecompose.core.operations.IntegerExpression;
import com.android.internal.widget.remotecompose.core.operations.MatrixRestore;
import com.android.internal.widget.remotecompose.core.operations.MatrixRotate;
import com.android.internal.widget.remotecompose.core.operations.MatrixSave;
@@ -55,6 +56,7 @@ import com.android.internal.widget.remotecompose.core.operations.Theme;
import com.android.internal.widget.remotecompose.core.operations.Utils;
import com.android.internal.widget.remotecompose.core.operations.paint.PaintBundle;
import com.android.internal.widget.remotecompose.core.operations.utilities.easing.FloatAnimation;
import com.android.internal.widget.remotecompose.core.types.IntegerConstant;

import java.io.File;
import java.io.FileInputStream;
@@ -876,6 +878,27 @@ public class RemoteComposeBuffer {
        return Utils.asNan(id);
    }


    /**
     * Add a Integer return an id number pointing to that float.
     * @param value
     * @return
     */
    public int addInteger(int value) {
        int id = mRemoteComposeState.cacheInteger(value);
        IntegerConstant.COMPANION.apply(mBuffer, id, value);
        return id;
    }

    /**
     * Add a IntegerId as float ID.
     * @param id id to be converted
     * @return
     */
    public float asFloatId(int id) {
        return Utils.asNan(id);
    }

    /**
     * Add a float that is a computation based on variables
     * @param value A RPN style float operation i.e. "4, 3, ADD" outputs 7
@@ -900,6 +923,18 @@ public class RemoteComposeBuffer {
        return Utils.asNan(id);
    }

    /**
     * Add and integer expression
     * @param mask defines which elements are operators or variables
     * @param value array of values to calculate maximum 32
     * @return
     */
    public int addIntegerExpression(int mask, int[] value) {
        int id = mRemoteComposeState.cache(value);
        IntegerExpression.COMPANION.apply(mBuffer, id, mask, value);
        return  id;
    }

    /**
     * Add a simple color
     * @param color
@@ -1038,5 +1073,6 @@ public class RemoteComposeBuffer {
        NamedVariable.COMPANION.apply(mBuffer, id,
                NamedVariable.COLOR_TYPE, name);
    }

}
+54 −16
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static com.android.internal.widget.remotecompose.core.RemoteContext.ID_TI
import static com.android.internal.widget.remotecompose.core.RemoteContext.ID_WINDOW_HEIGHT;
import static com.android.internal.widget.remotecompose.core.RemoteContext.ID_WINDOW_WIDTH;

import com.android.internal.widget.remotecompose.core.operations.utilities.IntFloatMap;
import com.android.internal.widget.remotecompose.core.operations.utilities.IntIntMap;
import com.android.internal.widget.remotecompose.core.operations.utilities.IntMap;

import java.util.ArrayList;
@@ -37,16 +39,12 @@ public class RemoteComposeState {
    private final IntMap<Object> mIntDataMap = new IntMap<>();
    private final IntMap<Boolean> mIntWrittenMap = new IntMap<>();
    private final HashMap<Object, Integer> mDataIntMap = new HashMap();
    private final float[] mFloatMap = new float[MAX_FLOATS]; // efficient cache
    private final int[] mColorMap = new int[MAX_COLORS]; // efficient cache
    private final IntFloatMap mFloatMap = new IntFloatMap(); // efficient cache
    private final IntIntMap mIntegerMap = new IntIntMap(); // efficient cache
    private final IntIntMap mColorMap = new IntIntMap(); // efficient cache
    private final boolean[] mColorOverride = new boolean[MAX_COLORS];
    private int mNextId = START_ID;

    {
        for (int i = 0; i < mFloatMap.length; i++) {
            mFloatMap[i] = Float.NaN;
        }
    }

    /**
     * Get Object based on id. The system will cache things like bitmaps
@@ -113,29 +111,62 @@ public class RemoteComposeState {
     */
    public int cacheFloat(float item) {
        int id = nextId();
        mFloatMap[id] = item;
        mFloatMap.put(id, item);
        mIntegerMap.put(id, (int) item);
        return id;
    }

    /**
     * Insert an item in the cache
     */
    public void cacheFloat(int id, float item) {
        mFloatMap[id] = item;
    public int cacheInteger(int item) {
        int id = nextId();
        mIntegerMap.put(id, item);
        mFloatMap.put(id, item);
        return id;
    }

    /**
     * Insert an item in the cache
     */
    public void cacheFloat(int id, float item) {
        mFloatMap.put(id, item);
    }

    /**
     * Insert an float item in the cache
     */
    public void updateFloat(int id, float item) {
        mFloatMap[id] = item;
        mFloatMap.put(id, item);
        mIntegerMap.put(id, (int) item);
    }

    /**
     * get float
     * Insert an integer item in the cache
     */
    public void updateInteger(int id, int item) {
        mFloatMap.put(id, item);
        mIntegerMap.put(id, item);
    }

    /**
     * get a float from the float cache
     *
     * @param id of the float value
     * @return the float value
     */
    public float getFloat(int id) {
        return mFloatMap[id];
        return mFloatMap.get(id);
    }

    /**
     * get an integer from the cache
     *
     * @param id of the integer value
     * @return the integer
     */
    public int getInteger(int id) {
        return mIntegerMap.get(id);
    }

    /**
@@ -145,11 +176,12 @@ public class RemoteComposeState {
     * @return
     */
    public int getColor(int id) {
        return mColorMap[id];
        return mColorMap.get(id);
    }

    /**
     * Modify the color at id.
     *
     * @param id
     * @param color
     */
@@ -157,7 +189,7 @@ public class RemoteComposeState {
        if (mColorOverride[id]) {
            return;
        }
        mColorMap[id] = color;
        mColorMap.put(id, color);
    }

    /**
@@ -169,7 +201,7 @@ public class RemoteComposeState {
     */
    public void overrideColor(int id, int color) {
        mColorOverride[id] = true;
        mColorMap[id] = color;
        mColorMap.put(id, color);
    }

    /**
@@ -205,6 +237,7 @@ public class RemoteComposeState {

    /**
     * Get the next available id
     *
     * @return
     */
    public int nextId() {
@@ -213,6 +246,7 @@ public class RemoteComposeState {

    /**
     * Set the next id
     *
     * @param id
     */
    public void setNextId(int id) {
@@ -234,6 +268,7 @@ public class RemoteComposeState {

    /**
     * Commands that listen to variables add themselves.
     *
     * @param id
     * @param variableSupport
     */
@@ -243,6 +278,7 @@ public class RemoteComposeState {

    /**
     * List of Commands that need to be updated
     *
     * @param context
     * @return
     */
@@ -264,6 +300,7 @@ public class RemoteComposeState {

    /**
     * Set the width of the overall document on screen.
     *
     * @param width
     */
    public void setWindowWidth(float width) {
@@ -272,6 +309,7 @@ public class RemoteComposeState {

    /**
     * Set the width of the overall document on screen.
     *
     * @param height
     */
    public void setWindowHeight(float height) {
+25 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ public abstract class RemoteContext {

    public float mWidth = 0f;
    public float mHeight = 0f;
    private float mAnimationTime;

    /**
     * Load a path under an id.
@@ -64,12 +65,21 @@ public abstract class RemoteContext {
     */
    public abstract void loadColor(int id, int color);

    /**
     * Set the animation time allowing the creator to control animation rates
     * @param time
     */
    public void setAnimationTime(float time) {
        mAnimationTime = time;
    }

    /**
     * gets the time animation clock as float in seconds
     * @return a monotonic time in seconds (arbitrary zero point)
     */
    public float getAnimationTime() {
        return (System.nanoTime() - mStart) * 1E-9f;
        mAnimationTime = (System.nanoTime() - mStart) * 1E-9f; // Eliminate
        return mAnimationTime;
    }

    /**
@@ -212,6 +222,13 @@ public abstract class RemoteContext {
     */
    public abstract void loadFloat(int id, float value);

    /**
     * Load a float
     * @param id
     * @param value
     */
    public abstract void loadInteger(int id, int value);

    /**
     * Load an animated float associated with an id
     * Todo: Remove?
@@ -234,6 +251,13 @@ public abstract class RemoteContext {
     */
    public abstract float getFloat(int id);

    /**
     * Get a float given an id
     * @param id
     * @return
     */
    public abstract int getInteger(int id);

    /**
     * Get the color given and ID
     * @param id
Loading