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

Commit 403d0cb7 authored by Nicolas Roard's avatar Nicolas Roard
Browse files

Update to ToT RemoteCompose (component support)

Bug: 339721781
Flag: EXEMPT External libraries
Test: in GOB

Change-Id: Ibd2fa38e819c4d3940af1649d8aae108eb940736
parent b4ddeb0e
Loading
Loading
Loading
Loading
+100 −1
Original line number Diff line number Diff line
@@ -18,6 +18,11 @@ package com.android.internal.widget.remotecompose.core;
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.Theme;
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.LayoutComponent;
import com.android.internal.widget.remotecompose.core.operations.layout.RootLayoutComponent;

import java.util.ArrayList;
import java.util.HashSet;
@@ -30,6 +35,9 @@ import java.util.Set;
public class CoreDocument {

    ArrayList<Operation> mOperations;

    RootLayoutComponent mRootLayoutComponent = null;

    RemoteComposeState mRemoteComposeState = new RemoteComposeState();
    TimeVariables mTimeVariables = new TimeVariables();
    // Semantic version of the document
@@ -81,7 +89,6 @@ public class CoreDocument {
    public void setHeight(int height) {
        this.mHeight = height;
        mRemoteComposeState.setWindowHeight(height);

    }

    public RemoteComposeBuffer getBuffer() {
@@ -259,10 +266,43 @@ public class CoreDocument {
        translateOutput[1] = translateY;
    }

    /**
     * Returns the list of click areas
     * @return list of click areas in document coordinates
     */
    public Set<ClickAreaRepresentation> getClickAreas() {
        return mClickAreas;
    }

    /**
     * Returns the root layout component
     * @return returns the root component if it exists, null otherwise
     */
    public RootLayoutComponent getRootLayoutComponent() {
        return mRootLayoutComponent;
    }

    /**
     * Invalidate the document for layout measures. This will trigger a layout remeasure pass.
     */
    public void invalidateMeasure() {
        if (mRootLayoutComponent != null) {
            mRootLayoutComponent.invalidateMeasure();
        }
    }

    /**
     * Returns the component with the given id
     * @param id component id
     * @return the component if it exists, null otherwise
     */
    public Component getComponent(int id) {
        if (mRootLayoutComponent != null) {
            return mRootLayoutComponent.getComponent(id);
        }
        return null;
    }

    public interface ClickCallbacks {
        void click(int id, String metadata);
    }
@@ -354,7 +394,54 @@ public class CoreDocument {
    public void initFromBuffer(RemoteComposeBuffer buffer) {
        mOperations = new ArrayList<Operation>();
        buffer.inflateFromBuffer(mOperations);
        mOperations = inflateComponents(mOperations);
        mBuffer = buffer;
        for (Operation op : mOperations) {
            if (op instanceof RootLayoutComponent) {
                mRootLayoutComponent = (RootLayoutComponent) op;
                break;
            }
        }
        if (mRootLayoutComponent != null) {
            mRootLayoutComponent.assignIds();
        }
    }

    /**
     * Inflate a component tree
     * @param operations flat list of operations
     * @return nested list of operations / components
     */
    private ArrayList<Operation> inflateComponents(ArrayList<Operation> operations) {
        Component currentComponent = null;
        ArrayList<Component> components = new ArrayList<>();
        ArrayList<Operation> finalOperationsList = new ArrayList<>();
        ArrayList<Operation> ops = finalOperationsList;

        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();
            } else if (o instanceof ComponentEnd) {
                if (currentComponent instanceof LayoutComponent) {
                    ((LayoutComponent) currentComponent).inflate();
                }
                components.remove(components.size() - 1);
                if (!components.isEmpty()) {
                    currentComponent = components.get(components.size() - 1);
                    ops = currentComponent.getList();
                } else {
                    ops = finalOperationsList;
                }
            } else {
                ops.add(o);
            }
        }
        return ops;
    }

    /**
@@ -559,6 +646,18 @@ public class CoreDocument {
        context.loadFloat(RemoteContext.ID_WINDOW_WIDTH, getWidth());
        context.loadFloat(RemoteContext.ID_WINDOW_HEIGHT, getHeight());
        mRepaintNext = context.updateOps();
        if (mRootLayoutComponent != null) {
            if (context.mWidth != mRootLayoutComponent.getWidth()
                    || context.mHeight != mRootLayoutComponent.getHeight()) {
                mRootLayoutComponent.invalidateMeasure();
            }
            if (mRootLayoutComponent.needsMeasure()) {
                mRootLayoutComponent.layout(context);
            }
            if (mRootLayoutComponent.doesNeedsRepaint()) {
                mRepaintNext = 1;
            }
        }
        for (Operation op : mOperations) {
            // 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.
+0 −1
Original line number Diff line number Diff line
@@ -37,4 +37,3 @@ public interface Operation {
     */
    String deepToString(String indent);
}
+56 −0
Original line number Diff line number Diff line
@@ -54,6 +54,21 @@ import com.android.internal.widget.remotecompose.core.operations.TextData;
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.layout.ComponentEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.ComponentStart;
import com.android.internal.widget.remotecompose.core.operations.layout.LayoutComponentContent;
import com.android.internal.widget.remotecompose.core.operations.layout.RootLayoutComponent;
import com.android.internal.widget.remotecompose.core.operations.layout.animation.AnimationSpec;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.BoxLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.ColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.RowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.BackgroundModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.BorderModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ClipRectModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.HeightModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.PaddingModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.RoundedClipRectModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.WidthModifierOperation;
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;
@@ -117,6 +132,27 @@ public class Operations {
    public static final int INTEGER_EXPRESSION = 144;

    /////////////////////////////////////////======================

    ////////////////////////////////////////
    // Layout commands
    ////////////////////////////////////////

    public static final int LAYOUT_ROOT = 200;
    public static final int LAYOUT_CONTENT = 201;
    public static final int LAYOUT_BOX = 202;
    public static final int LAYOUT_ROW = 203;
    public static final int LAYOUT_COLUMN = 204;
    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;
    public static final int MODIFIER_BACKGROUND = 55;
    public static final int MODIFIER_BORDER = 107;
    public static final int MODIFIER_PADDING = 58;
    public static final int MODIFIER_CLIP_RECT = 108;
    public static final int MODIFIER_ROUNDED_CLIP_RECT = 54;
    public static final int ANIMATION_SPEC = 14;

    public static IntMap<CompanionOperation> map = new IntMap<>();

    static {
@@ -162,6 +198,26 @@ public class Operations {
        map.put(DATA_INT, IntegerConstant.COMPANION);
        map.put(INTEGER_EXPRESSION, IntegerExpression.COMPANION);
        map.put(DATA_BOOLEAN, BooleanConstant.COMPANION);

        // Layout

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

        map.put(MODIFIER_WIDTH, WidthModifierOperation.COMPANION);
        map.put(MODIFIER_HEIGHT, HeightModifierOperation.COMPANION);
        map.put(MODIFIER_PADDING, PaddingModifierOperation.COMPANION);
        map.put(MODIFIER_BACKGROUND, BackgroundModifierOperation.COMPANION);
        map.put(MODIFIER_BORDER, BorderModifierOperation.COMPANION);
        map.put(MODIFIER_ROUNDED_CLIP_RECT, RoundedClipRectModifierOperation.COMPANION);
        map.put(MODIFIER_CLIP_RECT, ClipRectModifierOperation.COMPANION);

        map.put(LAYOUT_ROOT, RootLayoutComponent.COMPANION);
        map.put(LAYOUT_CONTENT, LayoutComponentContent.COMPANION);
        map.put(LAYOUT_BOX, BoxLayout.COMPANION);
        map.put(LAYOUT_COLUMN, ColumnLayout.COMPANION);
        map.put(LAYOUT_ROW, RowLayout.COMPANION);
    }

}
+67 −0
Original line number Diff line number Diff line
@@ -23,6 +23,10 @@ import com.android.internal.widget.remotecompose.core.operations.paint.PaintBund
public abstract class PaintContext {
    protected RemoteContext mContext;

    public RemoteContext getContext() {
        return mContext;
    }

    public PaintContext(RemoteContext context) {
        this.mContext = context;
    }
@@ -31,6 +35,28 @@ public abstract class PaintContext {
        this.mContext = context;
    }

    /**
     * convenience function to call matrixSave()
     */
    public void save() {
        matrixSave();
    }

    /**
     * convenience function to call matrixRestore()
     */
    public void restore() {
        matrixRestore();
    }

    /**
     * convenience function to call matrixSave()
     */
    public void saveLayer(float x, float y, float width, float height) {
        // TODO
        matrixSave();
    }

    public abstract void drawBitmap(int imageId,
                                    int srcLeft, int srcTop, int srcRight, int srcBottom,
                                    int dstLeft, int dstTop, int dstRight, int dstBottom,
@@ -196,9 +222,50 @@ public abstract class PaintContext {
     */
    public abstract void clipPath(int pathId, int regionOp);

    /**
     * Clip based ona  round rect
     * @param width
     * @param height
     * @param topStart
     * @param topEnd
     * @param bottomStart
     * @param bottomEnd
     */
    public abstract void roundedClipRect(float width, float height,
                                         float topStart, float topEnd,
                                         float bottomStart, float bottomEnd);

    /**
     * Reset the paint
     */
    public abstract void reset();

    /**
     * Returns true if the context is in debug mode
     *
     * @return true if in debug mode, false otherwise
     */
    public boolean isDebug() {
        return mContext.isDebug();
    }

    /**
     * Returns true if layout animations are enabled
     *
     * @return true if animations are enabled, false otherwise
     */
    public boolean isAnimationEnabled() {
        return mContext.isAnimationEnabled();
    }

    /**
     * Utility function to log comments
     *
     * @param content the content to log
     */
    public void log(String content) {
        System.out.println("[LOG] " + content);
    }

}
+5 −3
Original line number Diff line number Diff line
@@ -23,9 +23,11 @@ public abstract class PaintOperation implements Operation {

    @Override
    public void apply(RemoteContext context) {
        if (context.getMode() == RemoteContext.ContextMode.PAINT
                && context.getPaintContext() != null) {
            paint((PaintContext) context.getPaintContext());
        if (context.getMode() == RemoteContext.ContextMode.PAINT) {
            PaintContext paintContext = context.getPaintContext();
            if (paintContext != null) {
                paint(paintContext);
            }
        }
    }

Loading