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

Commit 61cb4abb authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update to ToT RemoteCompose" into main

parents 8218dda7 ee9732a5
Loading
Loading
Loading
Loading
+50 −3
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import com.android.internal.widget.remotecompose.core.operations.FloatExpression
import com.android.internal.widget.remotecompose.core.operations.IntegerExpression;
import com.android.internal.widget.remotecompose.core.operations.NamedVariable;
import com.android.internal.widget.remotecompose.core.operations.RootContentBehavior;
import com.android.internal.widget.remotecompose.core.operations.ShaderData;
import com.android.internal.widget.remotecompose.core.operations.TextData;
import com.android.internal.widget.remotecompose.core.operations.Theme;
import com.android.internal.widget.remotecompose.core.operations.layout.ClickModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.Component;
@@ -45,6 +47,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
@@ -470,6 +473,21 @@ public class CoreDocument {
        float mBottom;
        @Nullable final String mMetadata;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof ClickAreaRepresentation)) return false;
            ClickAreaRepresentation that = (ClickAreaRepresentation) o;
            return mId == that.mId
                    && Objects.equals(mContentDescription, that.mContentDescription)
                    && Objects.equals(mMetadata, that.mMetadata);
        }

        @Override
        public int hashCode() {
            return Objects.hash(mId, mContentDescription, mMetadata);
        }

        public ClickAreaRepresentation(
                int id,
                @Nullable String contentDescription,
@@ -754,9 +772,13 @@ public class CoreDocument {
            float right,
            float bottom,
            @Nullable String metadata) {
        mClickAreas.add(

        ClickAreaRepresentation car =
                new ClickAreaRepresentation(
                        id, contentDescription, left, top, right, bottom, metadata));
                        id, contentDescription, left, top, right, bottom, metadata);

        boolean old = mClickAreas.remove(car);
        mClickAreas.add(car);
    }

    /**
@@ -1067,7 +1089,6 @@ public class CoreDocument {
            mRepaintNext = 1;
        }
        context.mMode = RemoteContext.ContextMode.UNSET;
        // System.out.println(">>   " + (  System.nanoTime() - time)*1E-6f+" ms");
        if (DEBUG && mRootLayoutComponent != null) {
            System.out.println(mRootLayoutComponent.displayHierarchy());
        }
@@ -1163,4 +1184,30 @@ public class CoreDocument {
    public List<Operation> getOperations() {
        return mOperations;
    }

    /** defines if a shader can be run */
    public interface ShaderControl {
        boolean isShaderValid(String shader);
    }

    /**
     * validate the shaders
     *
     * @param context the remote context
     * @param ctl the call back to allow evaluation of shaders
     */
    public void checkShaders(RemoteContext context, ShaderControl ctl) {
        int count = 0;
        for (Operation op : mOperations) {
            if (op instanceof TextData) {
                op.apply(context);
            }
            if (op instanceof ShaderData) {
                ShaderData sd = (ShaderData) op;
                int id = sd.getShaderTextId();
                String str = context.getText(id);
                sd.enable(ctl.isShaderValid(str));
            }
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -493,6 +493,9 @@ public abstract class RemoteContext {

    public static final int ID_DENSITY = 27;

    /** Defines when the last build was made */
    public static final int ID_API_LEVEL = 28;

    public static final float FLOAT_DENSITY = Utils.asNan(ID_DENSITY);

    /** CONTINUOUS_SEC is seconds from midnight looping every hour 0-3600 */
@@ -566,6 +569,9 @@ public abstract class RemoteContext {
    /** Ambient light level in SI lux */
    public static final float FLOAT_LIGHT = Utils.asNan(ID_LIGHT);

    /** When was this player built */
    public static final float FLOAT_API_LEVEL = Utils.asNan(ID_API_LEVEL);

    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Click handling
    ///////////////////////////////////////////////////////////////////////////////////////////////
+3 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import java.time.ZoneOffset;

/** This generates the standard system variables for time. */
public class TimeVariables {
    private static final float BUILD = 0.01f;

    /**
     * This class populates all time variables in the system
     *
@@ -57,6 +59,7 @@ public class TimeVariables {
        context.loadFloat(RemoteContext.ID_CALENDAR_MONTH, month);
        context.loadFloat(RemoteContext.ID_DAY_OF_MONTH, month);
        context.loadFloat(RemoteContext.ID_WEEK_DAY, day_week);
        context.loadFloat(RemoteContext.ID_API_LEVEL, CoreDocument.getDocumentApiLevel() + BUILD);
    }

    /**
+38 −7
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import com.android.internal.widget.remotecompose.core.Operation;
import com.android.internal.widget.remotecompose.core.Operations;
import com.android.internal.widget.remotecompose.core.RemoteComposeOperation;
import com.android.internal.widget.remotecompose.core.RemoteContext;
import com.android.internal.widget.remotecompose.core.VariableSupport;
import com.android.internal.widget.remotecompose.core.WireBuffer;
import com.android.internal.widget.remotecompose.core.documentation.DocumentationBuilder;
import com.android.internal.widget.remotecompose.core.documentation.DocumentedOperation;
@@ -29,7 +30,8 @@ import com.android.internal.widget.remotecompose.core.semantics.AccessibleCompon
import java.util.List;

/** Add a click area to the document */
public class ClickArea extends Operation implements RemoteComposeOperation, AccessibleComponent {
public class ClickArea extends Operation
        implements RemoteComposeOperation, AccessibleComponent, VariableSupport {
    private static final int OP_CODE = Operations.CLICK_AREA;
    private static final String CLASS_NAME = "ClickArea";
    int mId;
@@ -38,6 +40,10 @@ public class ClickArea extends Operation implements RemoteComposeOperation, Acce
    float mTop;
    float mRight;
    float mBottom;
    float mOutLeft;
    float mOutTop;
    float mOutRight;
    float mOutBottom;
    int mMetadata;

    /**
@@ -62,11 +68,35 @@ public class ClickArea extends Operation implements RemoteComposeOperation, Acce
            int metadata) {
        this.mId = id;
        this.mContentDescription = contentDescription;
        this.mLeft = left;
        this.mTop = top;
        this.mRight = right;
        this.mBottom = bottom;
        this.mMetadata = metadata;
        mOutLeft = mLeft = left;
        mOutTop = mTop = top;
        mOutRight = mRight = right;
        mOutBottom = mBottom = bottom;
        mMetadata = metadata;
    }

    @Override
    public void registerListening(@NonNull RemoteContext context) {
        if (Float.isNaN(mLeft)) {
            context.listensTo(Utils.idFromNan(mLeft), this);
        }
        if (Float.isNaN(mTop)) {
            context.listensTo(Utils.idFromNan(mTop), this);
        }
        if (Float.isNaN(mRight)) {
            context.listensTo(Utils.idFromNan(mRight), this);
        }
        if (Float.isNaN(mBottom)) {
            context.listensTo(Utils.idFromNan(mBottom), this);
        }
    }

    @Override
    public void updateVariables(@NonNull RemoteContext context) {
        mOutLeft = Float.isNaN(mLeft) ? context.getFloat(Utils.idFromNan(mLeft)) : mLeft;
        mOutTop = Float.isNaN(mTop) ? context.getFloat(Utils.idFromNan(mTop)) : mTop;
        mRight = Float.isNaN(mRight) ? context.getFloat(Utils.idFromNan(mRight)) : mRight;
        mOutBottom = Float.isNaN(mBottom) ? context.getFloat(Utils.idFromNan(mBottom)) : mBottom;
    }

    @Override
@@ -105,7 +135,8 @@ public class ClickArea extends Operation implements RemoteComposeOperation, Acce
        if (context.getMode() != RemoteContext.ContextMode.DATA) {
            return;
        }
        context.addClickArea(mId, mContentDescription, mLeft, mTop, mRight, mBottom, mMetadata);
        context.addClickArea(
                mId, mContentDescription, mOutLeft, mOutTop, mOutRight, mOutBottom, mMetadata);
    }

    @NonNull
+13 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ public class ShaderData extends Operation implements VariableSupport {
    @Nullable HashMap<String, float[]> mUniformFloatMap = null;
    @Nullable HashMap<String, int[]> mUniformIntMap;
    @Nullable HashMap<String, Integer> mUniformBitmapMap = null;
    private boolean mShaderValid = false;

    public ShaderData(
            int shaderID,
@@ -358,12 +359,23 @@ public class ShaderData extends Operation implements VariableSupport {

    @Override
    public void apply(@NonNull RemoteContext context) {
        if (mShaderValid) {
            context.loadShader(mShaderID, this);
        }
    }

    @NonNull
    @Override
    public String deepToString(@NonNull String indent) {
        return indent + toString();
    }

    /**
     * Enable or disable the shader
     *
     * @param shaderValid if true shader can be used
     */
    public void enable(boolean shaderValid) {
        mShaderValid = shaderValid;
    }
}
Loading