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

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

Merge "Update to ToT RemoteCompose" into main

parents c0582178 2b891319
Loading
Loading
Loading
Loading
+69 −88
Original line number Diff line number Diff line
@@ -21,26 +21,20 @@ import android.annotation.Nullable;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.widget.remotecompose.core.operations.ComponentValue;
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.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;
import com.android.internal.widget.remotecompose.core.operations.layout.ComponentEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.ComponentStartOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.LoopEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.Container;
import com.android.internal.widget.remotecompose.core.operations.layout.ContainerEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.LoopOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.OperationsListEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.RootLayoutComponent;
import com.android.internal.widget.remotecompose.core.operations.layout.TouchCancelModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.TouchDownModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.TouchUpModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ComponentModifiers;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ScrollModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.utilities.StringSerializer;

import java.util.ArrayList;
@@ -57,7 +51,18 @@ import java.util.Set;
public class CoreDocument {

    private static final boolean DEBUG = false;
    private static final int DOCUMENT_API_LEVEL = 2;

    // Semantic version
    public static final int MAJOR_VERSION = 0;
    public static final int MINOR_VERSION = 3;
    public static final int PATCH_VERSION = 0;

    // Internal version level
    public static final int DOCUMENT_API_LEVEL = 3;

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

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

@@ -65,8 +70,9 @@ public class CoreDocument {

    @NonNull RemoteComposeState mRemoteComposeState = new RemoteComposeState();
    @VisibleForTesting @NonNull public TimeVariables mTimeVariables = new TimeVariables();

    // Semantic version of the document
    @NonNull Version mVersion = new Version(0, 1, 0);
    @NonNull Version mVersion = new Version(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);

    @Nullable
    String mContentDescription; // text description of the document (used for accessibility)
@@ -551,6 +557,11 @@ public class CoreDocument {
        mOperations = new ArrayList<Operation>();
        buffer.inflateFromBuffer(mOperations);
        for (Operation op : mOperations) {
            if (op instanceof Header) {
                // Make sure we parse the version at init time...
                Header header = (Header) op;
                header.setVersion(this);
            }
            if (op instanceof IntegerExpression) {
                IntegerExpression expression = (IntegerExpression) op;
                mIntegerExpressions.put((long) expression.mId, expression);
@@ -581,85 +592,49 @@ public class CoreDocument {
     */
    @NonNull
    private ArrayList<Operation> inflateComponents(@NonNull ArrayList<Operation> operations) {
        Component currentComponent = null;
        ArrayList<Component> components = new ArrayList<>();
        ArrayList<Operation> finalOperationsList = new ArrayList<>();
        ArrayList<Operation> ops = finalOperationsList;
        ClickModifierOperation currentClickModifier = null;
        TouchDownModifierOperation currentTouchDownModifier = null;
        TouchUpModifierOperation currentTouchUpModifier = null;
        TouchCancelModifierOperation currentTouchCancelModifier = null;
        LoopOperation currentLoop = null;
        ScrollModifierOperation currentScrollModifier = null;

        ArrayList<Container> containers = new ArrayList<>();

        mLastId = -1;
        for (Operation o : operations) {
            if (o instanceof ComponentStartOperation) {
                Component component = (Component) o;
                component.setParent(currentComponent);
                components.add(component);
                currentComponent = component;
                ops.add(currentComponent);
                ops = currentComponent.getList();
            if (o instanceof Container) {
                Container container = (Container) o;
                containers.add(container);
                ops = container.getList();
                if (container instanceof Component) {
                    Component component = (Component) container;
                    if (component.getComponentId() < mLastId) {
                        mLastId = component.getComponentId();
                    }
            } else if (o instanceof ComponentEnd) {
                if (currentComponent != null) {
                    currentComponent.inflate();
                }
                components.remove(components.size() - 1);
                if (!components.isEmpty()) {
                    currentComponent = components.get(components.size() - 1);
                    ops = currentComponent.getList();
                } else {
                    ops = finalOperationsList;
            } else if (o instanceof ContainerEnd) {
                // check if we have a parent container
                Container container = null;
                // pop the container
                if (!containers.isEmpty()) {
                    container = containers.remove(containers.size() - 1);
                }
            } else if (o instanceof ClickModifierOperation) {
                // TODO: refactor to add container <- component...
                currentClickModifier = (ClickModifierOperation) o;
                ops = currentClickModifier.getList();
            } else if (o instanceof TouchDownModifierOperation) {
                currentTouchDownModifier = (TouchDownModifierOperation) o;
                ops = currentTouchDownModifier.getList();
            } else if (o instanceof TouchUpModifierOperation) {
                currentTouchUpModifier = (TouchUpModifierOperation) o;
                ops = currentTouchUpModifier.getList();
            } else if (o instanceof TouchCancelModifierOperation) {
                currentTouchCancelModifier = (TouchCancelModifierOperation) o;
                ops = currentTouchCancelModifier.getList();
            } else if (o instanceof ScrollModifierOperation) {
                currentScrollModifier = (ScrollModifierOperation) o;
                ops = currentScrollModifier.getList();
            } else if (o instanceof OperationsListEnd) {
                ops = currentComponent.getList();
                if (currentClickModifier != null) {
                    ops.add(currentClickModifier);
                    currentClickModifier = null;
                } else if (currentTouchDownModifier != null) {
                    ops.add(currentTouchDownModifier);
                    currentTouchDownModifier = null;
                } else if (currentTouchUpModifier != null) {
                    ops.add(currentTouchUpModifier);
                    currentTouchUpModifier = null;
                } else if (currentTouchCancelModifier != null) {
                    ops.add(currentTouchCancelModifier);
                    currentTouchCancelModifier = null;
                } else if (currentScrollModifier != null) {
                    ops.add(currentScrollModifier);
                    currentScrollModifier = null;
                }
            } else if (o instanceof LoopOperation) {
                currentLoop = (LoopOperation) o;
                ops = currentLoop.getList();
            } else if (o instanceof LoopEnd) {
                if (currentComponent != null) {
                    ops = currentComponent.getList();
                    ops.add(currentLoop);
                Container parentContainer = null;
                if (!containers.isEmpty()) {
                    parentContainer = containers.get(containers.size() - 1);
                }
                if (parentContainer != null) {
                    ops = parentContainer.getList();
                } else {
                    ops = finalOperationsList;
                }
                currentLoop = null;
                if (container != null) {
                    if (container instanceof Component) {
                        Component component = (Component) container;
                        if (parentContainer instanceof Component) {
                            component.setParent((Component) parentContainer);
                        }
                        component.inflate();
                    }
                    ops.add((Operation) container);
                }
            } else {
                ops.add(o);
            }
@@ -744,7 +719,7 @@ public class CoreDocument {
     * @param minorVersion minor version number, increased when adding new features
     * @param patch patch level, increased upon bugfixes
     */
    void setVersion(int majorVersion, int minorVersion, int patch) {
    public void setVersion(int majorVersion, int minorVersion, int patch) {
        mVersion = new Version(majorVersion, minorVersion, patch);
    }

@@ -1080,19 +1055,22 @@ public class CoreDocument {
            }
        }
        context.mMode = RemoteContext.ContextMode.PAINT;
        for (Operation op : mOperations) {
        for (int i = 0; i < mOperations.size(); i++) {
            Operation op = mOperations.get(i);
            // operations will only be executed if no theme is set (ie UNSPECIFIED)
            // or the theme is equal as the one passed in argument to paint.
            boolean apply = true;
            if (theme != Theme.UNSPECIFIED) {
                int currentTheme = context.getTheme();
                apply =
                        op instanceof Theme // always apply a theme setter
                                || context.getTheme() == theme
                                || context.getTheme() == Theme.UNSPECIFIED;
                        currentTheme == theme
                                || currentTheme == Theme.UNSPECIFIED
                                || op instanceof Theme; // always apply a theme setter
            }
            if (apply) {
                if (op.isDirty() || op instanceof PaintOperation) {
                    if (op.isDirty() && op instanceof VariableSupport) {
                boolean opIsDirty = op.isDirty();
                if (opIsDirty || op instanceof PaintOperation) {
                    if (opIsDirty && op instanceof VariableSupport) {
                        op.markNotDirty();
                        ((VariableSupport) op).updateVariables(context);
                    }
@@ -1253,8 +1231,11 @@ public class CoreDocument {
    private void toNestedString(
            @NonNull Component base, @NonNull StringBuilder ret, String indent) {
        for (Operation mOperation : base.mList) {
            ret.append(mOperation.toString());
            for (String line : mOperation.toString().split("\n")) {
                ret.append(indent);
                ret.append(line);
                ret.append("\n");
            }
            if (mOperation instanceof Component) {
                toNestedString((Component) mOperation, ret, indent + "  ");
            }
+3 −9
Original line number Diff line number Diff line
@@ -73,12 +73,10 @@ import com.android.internal.widget.remotecompose.core.operations.Theme;
import com.android.internal.widget.remotecompose.core.operations.TouchExpression;
import com.android.internal.widget.remotecompose.core.operations.layout.CanvasContent;
import com.android.internal.widget.remotecompose.core.operations.layout.ClickModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.ComponentEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.ComponentStart;
import com.android.internal.widget.remotecompose.core.operations.layout.ContainerEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.LayoutComponentContent;
import com.android.internal.widget.remotecompose.core.operations.layout.LoopEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.LoopOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.OperationsListEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.RootLayoutComponent;
import com.android.internal.widget.remotecompose.core.operations.layout.TouchCancelModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.TouchDownModifierOperation;
@@ -208,7 +206,6 @@ public class Operations {
    public static final int LAYOUT_STATE = 217;

    public static final int COMPONENT_START = 2;
    public static final int COMPONENT_END = 3;

    public static final int MODIFIER_WIDTH = 16;
    public static final int MODIFIER_HEIGHT = 67;
@@ -223,7 +220,7 @@ public class Operations {
    public static final int MODIFIER_TOUCH_UP = 220;
    public static final int MODIFIER_TOUCH_CANCEL = 225;

    public static final int OPERATIONS_LIST_END = 214;
    public static final int CONTAINER_END = 214;

    public static final int MODIFIER_OFFSET = 221;
    public static final int MODIFIER_ZINDEX = 223;
@@ -233,7 +230,6 @@ public class Operations {
    public static final int MODIFIER_RIPPLE = 229;

    public static final int LOOP_START = 215;
    public static final int LOOP_END = 216;

    public static final int MODIFIER_VISIBILITY = 211;
    public static final int HOST_ACTION = 209;
@@ -311,12 +307,10 @@ public class Operations {
        map.put(TEXT_LOOKUP_INT, TextLookupInt::read);

        map.put(LOOP_START, LoopOperation::read);
        map.put(LOOP_END, LoopEnd::read);

        // Layout

        map.put(COMPONENT_START, ComponentStart::read);
        map.put(COMPONENT_END, ComponentEnd::read);
        map.put(ANIMATION_SPEC, AnimationSpec::read);

        map.put(MODIFIER_WIDTH, WidthModifierOperation::read);
@@ -338,7 +332,7 @@ public class Operations {
        map.put(MODIFIER_MARQUEE, MarqueeModifierOperation::read);
        map.put(MODIFIER_RIPPLE, RippleModifierOperation::read);

        map.put(OPERATIONS_LIST_END, OperationsListEnd::read);
        map.put(CONTAINER_END, ContainerEnd::read);

        map.put(HOST_ACTION, HostActionOperation::read);
        map.put(HOST_NAMED_ACTION, HostNamedActionOperation::read);
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.internal.widget.remotecompose.core;

import android.annotation.NonNull;
import android.annotation.Nullable;

import com.android.internal.widget.remotecompose.core.operations.paint.PaintBundle;

@@ -297,4 +298,12 @@ public abstract class PaintContext {
    public boolean isVisualDebug() {
        return mContext.isVisualDebug();
    }

    /**
     * Returns a String from an id
     *
     * @param textID
     * @return the string if found
     */
    public abstract @Nullable String getText(int textID);
}
+30 −6
Original line number Diff line number Diff line
@@ -75,12 +75,10 @@ import com.android.internal.widget.remotecompose.core.operations.Theme;
import com.android.internal.widget.remotecompose.core.operations.TouchExpression;
import com.android.internal.widget.remotecompose.core.operations.Utils;
import com.android.internal.widget.remotecompose.core.operations.layout.CanvasContent;
import com.android.internal.widget.remotecompose.core.operations.layout.ComponentEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.ComponentStart;
import com.android.internal.widget.remotecompose.core.operations.layout.ContainerEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.LayoutComponentContent;
import com.android.internal.widget.remotecompose.core.operations.layout.LoopEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.LoopOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.OperationsListEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.RootLayoutComponent;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.BoxLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CanvasLayout;
@@ -733,6 +731,22 @@ public class RemoteComposeBuffer {
        DrawTextOnPath.apply(mBuffer, textId, pathId, hOffset, vOffset);
    }

    /**
     * Draw the text, with origin at (x,y) along the specified path.
     *
     * @param textId The text to be drawn
     * @param path The path the text should follow for its baseline
     * @param hOffset The distance along the path to add to the text's starting position
     * @param vOffset The distance above(-) or below(+) the path to position the text
     */
    public void addDrawTextOnPath(int textId, Object path, float hOffset, float vOffset) {
        int pathId = mRemoteComposeState.dataGetId(path);
        if (pathId == -1) { // never been seen before
            pathId = addPathData(path);
        }
        DrawTextOnPath.apply(mBuffer, textId, pathId, hOffset, vOffset);
    }

    /**
     * Draw the text, with origin at (x,y). The origin is interpreted based on the Align setting in
     * the paint.
@@ -1645,6 +1659,16 @@ public class RemoteComposeBuffer {
        NamedVariable.apply(mBuffer, id, NamedVariable.STRING_TYPE, name);
    }

    /**
     * This defines the name of the float given the id
     *
     * @param id of the float
     * @param name name of the float
     */
    public void setFloatName(int id, String name) {
        NamedVariable.apply(mBuffer, id, NamedVariable.FLOAT_TYPE, name);
    }

    /**
     * Returns a usable component id -- either the one passed in parameter if not -1 or a generated
     * one.
@@ -1685,7 +1709,7 @@ public class RemoteComposeBuffer {

    /** Add a component end tag */
    public void addComponentEnd() {
        ComponentEnd.apply(mBuffer);
        ContainerEnd.apply(mBuffer);
    }

    /**
@@ -1718,7 +1742,7 @@ public class RemoteComposeBuffer {
                new float[] {notches, notchMax},
                null);

        OperationsListEnd.apply(mBuffer);
        ContainerEnd.apply(mBuffer);
    }

    /**
@@ -1886,7 +1910,7 @@ public class RemoteComposeBuffer {
    }

    public void addLoopEnd() {
        LoopEnd.apply(mBuffer);
        ContainerEnd.apply(mBuffer);
    }

    public void addStateLayout(
+2 −1
Original line number Diff line number Diff line
@@ -318,7 +318,8 @@ public class RemoteComposeState implements CollectionsAccess {
    private void updateListeners(int id) {
        ArrayList<VariableSupport> v = mVarListeners.get(id);
        if (v != null && mRemoteContext != null) {
            for (VariableSupport c : v) {
            for (int i = 0; i < v.size(); i++) {
                VariableSupport c = v.get(i);
                c.markDirty();
            }
        }
Loading