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

Commit 17586a31 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: Iecebf4c926a83f0212dabaa769d8832054866024
parent 44ca658c
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -17,15 +17,13 @@ package com.android.internal.widget.remotecompose.core;

import java.util.List;

/**
 * Interface for the companion operations
 */
/** Interface for the companion operations */
public interface CompanionOperation {
    /**
     * Read, create and add instance to operations
     *
     * @param buffer data to read to create operation
     * @param operations command is to be added
     */
    void read(WireBuffer buffer, List<Operation> operations);
}
+156 −122
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.internal.widget.remotecompose.core;

import com.android.internal.widget.remotecompose.core.operations.ComponentValue;
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.Theme;
@@ -25,6 +26,8 @@ import com.android.internal.widget.remotecompose.core.operations.layout.Componen
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.LoopEnd;
import com.android.internal.widget.remotecompose.core.operations.layout.LoopOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.RootLayoutComponent;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ComponentModifiers;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.ModifierOperation;
@@ -33,11 +36,12 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Represents a platform independent RemoteCompose document,
 * containing RemoteCompose operations + state
 * Represents a platform independent RemoteCompose document, containing RemoteCompose operations +
 * state
 */
public class CoreDocument {

@@ -66,6 +70,8 @@ public class CoreDocument {

    RemoteComposeBuffer mBuffer = new RemoteComposeBuffer(mRemoteComposeState);

    private final HashMap<Long, IntegerExpression> mIntegerExpressions = new HashMap<>();

    private int mLastId = 1; // last component id when inflating the file

    public String getContentDescription() {
@@ -136,18 +142,11 @@ public class CoreDocument {
     * @param scroll set the horizontal behavior (NONE|SCROLL_HORIZONTAL|SCROLL_VERTICAL)
     * @param alignment set the alignment of the content (TOP|CENTER|BOTTOM|START|END)
     * @param sizing set the type of sizing for the content (NONE|SIZING_LAYOUT|SIZING_SCALE)
     * @param mode      set the mode of sizing, either LAYOUT modes or SCALE modes
     *                  the LAYOUT modes are:
     *                  - LAYOUT_MATCH_PARENT
     *                  - LAYOUT_WRAP_CONTENT
     *                  or adding an horizontal mode and a vertical mode:
     *                  - LAYOUT_HORIZONTAL_MATCH_PARENT
     *                  - LAYOUT_HORIZONTAL_WRAP_CONTENT
     *                  - LAYOUT_HORIZONTAL_FIXED
     *                  - LAYOUT_VERTICAL_MATCH_PARENT
     *                  - LAYOUT_VERTICAL_WRAP_CONTENT
     *                  - LAYOUT_VERTICAL_FIXED
     *                  The LAYOUT_*_FIXED modes will use the intrinsic document size
     * @param mode set the mode of sizing, either LAYOUT modes or SCALE modes the LAYOUT modes are:
     *     - LAYOUT_MATCH_PARENT - LAYOUT_WRAP_CONTENT or adding an horizontal mode and a vertical
     *     mode: - LAYOUT_HORIZONTAL_MATCH_PARENT - LAYOUT_HORIZONTAL_WRAP_CONTENT -
     *     LAYOUT_HORIZONTAL_FIXED - LAYOUT_VERTICAL_MATCH_PARENT - LAYOUT_VERTICAL_WRAP_CONTENT -
     *     LAYOUT_VERTICAL_FIXED The LAYOUT_*_FIXED modes will use the intrinsic document size
     */
    public void setRootContentBehavior(int scroll, int alignment, int sizing, int mode) {
        this.mContentScroll = scroll;
@@ -169,49 +168,46 @@ public class CoreDocument {
        float contentScaleY = 1f;
        if (mContentSizing == RootContentBehavior.SIZING_SCALE) {
            // we need to add canvas transforms ops here
            float scaleX = 1f;
            float scaleY = 1f;
            float scale = 1f;
            switch (mContentMode) {
                case RootContentBehavior.SCALE_INSIDE: {
                    float scaleX = w / mWidth;
                    float scaleY = h / mHeight;
                    float scale = Math.min(1f, Math.min(scaleX, scaleY));
                case RootContentBehavior.SCALE_INSIDE:
                    scaleX = w / mWidth;
                    scaleY = h / mHeight;
                    scale = Math.min(1f, Math.min(scaleX, scaleY));
                    contentScaleX = scale;
                    contentScaleY = scale;
                }
                    break;
                case RootContentBehavior.SCALE_FIT: {
                    float scaleX = w / mWidth;
                    float scaleY = h / mHeight;
                    float scale = Math.min(scaleX, scaleY);
                case RootContentBehavior.SCALE_FIT:
                    scaleX = w / mWidth;
                    scaleY = h / mHeight;
                    scale = Math.min(scaleX, scaleY);
                    contentScaleX = scale;
                    contentScaleY = scale;
                }
                    break;
                case RootContentBehavior.SCALE_FILL_WIDTH: {
                    float scale = w / mWidth;
                case RootContentBehavior.SCALE_FILL_WIDTH:
                    scale = w / mWidth;
                    contentScaleX = scale;
                    contentScaleY = scale;
                }
                    break;
                case RootContentBehavior.SCALE_FILL_HEIGHT: {
                    float scale = h / mHeight;
                case RootContentBehavior.SCALE_FILL_HEIGHT:
                    scale = h / mHeight;
                    contentScaleX = scale;
                    contentScaleY = scale;
                }
                    break;
                case RootContentBehavior.SCALE_CROP: {
                    float scaleX = w / mWidth;
                    float scaleY = h / mHeight;
                    float scale = Math.max(scaleX, scaleY);
                case RootContentBehavior.SCALE_CROP:
                    scaleX = w / mWidth;
                    scaleY = h / mHeight;
                    scale = Math.max(scaleX, scaleY);
                    contentScaleX = scale;
                    contentScaleY = scale;
                }
                    break;
                case RootContentBehavior.SCALE_FILL_BOUNDS: {
                    float scaleX = w / mWidth;
                    float scaleY = h / mHeight;
                case RootContentBehavior.SCALE_FILL_BOUNDS:
                    scaleX = w / mWidth;
                    scaleY = h / mHeight;
                    contentScaleX = scaleX;
                    contentScaleY = scaleY;
                }
                    break;
                default:
                    // nothing
@@ -231,8 +227,8 @@ public class CoreDocument {
     * @param contentScaleY the vertical scale we are going to use for the content
     * @param translateOutput will contain the computed translation
     */
    private void computeTranslate(float w, float h, float contentScaleX, float contentScaleY,
                                  float[] translateOutput) {
    private void computeTranslate(
            float w, float h, float contentScaleX, float contentScaleY, float[] translateOutput) {
        int horizontalContentAlignment = mContentAlignment & 0xF0;
        int verticalContentAlignment = mContentAlignment & 0xF;
        float translateX = 0f;
@@ -241,33 +237,27 @@ public class CoreDocument {
        float contentHeight = mHeight * contentScaleY;

        switch (horizontalContentAlignment) {
            case RootContentBehavior.ALIGNMENT_START: {
            case RootContentBehavior.ALIGNMENT_START:
                // nothing
            }
                break;
            case RootContentBehavior.ALIGNMENT_HORIZONTAL_CENTER: {
            case RootContentBehavior.ALIGNMENT_HORIZONTAL_CENTER:
                translateX = (w - contentWidth) / 2f;
            }
                break;
            case RootContentBehavior.ALIGNMENT_END: {
            case RootContentBehavior.ALIGNMENT_END:
                translateX = w - contentWidth;
            }
                break;
            default:
                // nothing (same as alignment_start)
        }
        switch (verticalContentAlignment) {
            case RootContentBehavior.ALIGNMENT_TOP: {
            case RootContentBehavior.ALIGNMENT_TOP:
                // nothing
            }
                break;
            case RootContentBehavior.ALIGNMENT_VERTICAL_CENTER: {
            case RootContentBehavior.ALIGNMENT_VERTICAL_CENTER:
                translateY = (h - contentHeight) / 2f;
            }
                break;
            case RootContentBehavior.ALIGNMENT_BOTTOM: {
            case RootContentBehavior.ALIGNMENT_BOTTOM:
                translateY = h - contentHeight;
            }
                break;
            default:
                // nothing (same as alignment_top)
@@ -279,6 +269,7 @@ public class CoreDocument {

    /**
     * Returns the list of click areas
     *
     * @return list of click areas in document coordinates
     */
    public Set<ClickAreaRepresentation> getClickAreas() {
@@ -287,15 +278,14 @@ public class CoreDocument {

    /**
     * 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.
     */
    /** Invalidate the document for layout measures. This will trigger a layout remeasure pass. */
    public void invalidateMeasure() {
        if (mRootLayoutComponent != null) {
            mRootLayoutComponent.invalidateMeasure();
@@ -304,6 +294,7 @@ public class CoreDocument {

    /**
     * Returns the component with the given id
     *
     * @param id component id
     * @return the component if it exists, null otherwise
     */
@@ -332,8 +323,21 @@ public class CoreDocument {
    }

    /**
     * Callback interface for host actions
     * Execute an integer expression with the given id and put its value on the targetId
     *
     * @param expressionId the id of the integer expression
     * @param targetId the id of the value to update with the expression
     * @param context the current context
     */
    public void evaluateIntExpression(long expressionId, int targetId, RemoteContext context) {
        IntegerExpression expression = mIntegerExpressions.get(expressionId);
        if (expression != null) {
            int v = expression.evaluate(context);
            context.overrideInteger(targetId, v);
        }
    }

    /** Callback interface for host actions */
    public interface ActionCallback {
        // TODO: add payload support
        void onAction(String name);
@@ -343,6 +347,7 @@ public class CoreDocument {

    /**
     * Warn action listeners for the given named action
     *
     * @param name the action name
     */
    public void runNamedAction(String name) {
@@ -360,9 +365,7 @@ public class CoreDocument {
        mActionListeners.add(callback);
    }

    /**
     * Clear existing callbacks for named host actions
     */
    /** Clear existing callbacks for named host actions */
    public void clearActionCallbacks() {
        mActionListeners.clear();
    }
@@ -395,7 +398,8 @@ public class CoreDocument {
        float mBottom;
        String mMetadata;

        public ClickAreaRepresentation(int id,
        public ClickAreaRepresentation(
                int id,
                String contentDescription,
                float left,
                float top,
@@ -419,8 +423,7 @@ public class CoreDocument {
         * @return x, y coordinate is within bounds
         */
        public boolean contains(float x, float y) {
            return x >= mLeft && x < mRight
                    && y >= mTop && y < mBottom;
            return x >= mLeft && x < mRight && y >= mTop && y < mBottom;
        }

        public float getLeft() {
@@ -452,12 +455,16 @@ public class CoreDocument {
        }
    }

    /**
     * Load operations from the given buffer
     */
    /** Load operations from the given buffer */
    public void initFromBuffer(RemoteComposeBuffer buffer) {
        mOperations = new ArrayList<Operation>();
        buffer.inflateFromBuffer(mOperations);
        for (Operation op : mOperations) {
            if (op instanceof IntegerExpression) {
                IntegerExpression expression = (IntegerExpression) op;
                mIntegerExpressions.put((long) expression.mId, expression);
            }
        }
        mOperations = inflateComponents(mOperations);
        mBuffer = buffer;
        for (Operation op : mOperations) {
@@ -473,6 +480,7 @@ public class CoreDocument {

    /**
     * Inflate a component tree
     *
     * @param operations flat list of operations
     * @return nested list of operations / components
     */
@@ -482,6 +490,7 @@ public class CoreDocument {
        ArrayList<Operation> finalOperationsList = new ArrayList<>();
        ArrayList<Operation> ops = finalOperationsList;
        ClickModifierOperation currentClickModifier = null;
        LoopOperation currentLoop = null;

        mLastId = -1;
        for (Operation o : operations) {
@@ -509,11 +518,22 @@ public class CoreDocument {
            } else if (o instanceof ClickModifierOperation) {
                // TODO: refactor to add container <- component...
                currentClickModifier = (ClickModifierOperation) o;
                ops = ((ClickModifierOperation) o).getList();
                ops = currentClickModifier.getList();
            } else if (o instanceof ClickModifierEnd) {
                ops = currentComponent.getList();
                ops.add(currentClickModifier);
                currentClickModifier = 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);
                } else {
                    ops = finalOperationsList;
                }
                currentLoop = null;
            } else {
                ops.add(o);
            }
@@ -555,8 +575,8 @@ public class CoreDocument {
    }

    /**
     * Called when an initialization is needed, allowing the document to eg load
     * resources / cache them.
     * Called when an initialization is needed, allowing the document to eg load resources / cache
     * them.
     */
    public void initializeContext(RemoteContext context) {
        mRemoteComposeState.reset();
@@ -605,9 +625,9 @@ public class CoreDocument {

    /**
     * Add a click area to the document, in root coordinates. We are not doing any specific sorting
     * through the declared areas on click detections, which means that the first one containing
     * the click coordinates will be the one reported; the order of addition of those click areas
     * is therefore meaningful.
     * through the declared areas on click detections, which means that the first one containing the
     * click coordinates will be the one reported; the order of addition of those click areas is
     * therefore meaningful.
     *
     * @param id the id of the area, which will be reported on click
     * @param contentDescription the content description (used for accessibility)
@@ -617,10 +637,17 @@ public class CoreDocument {
     * @param bottom the bottom coordinate of the click area (in pixels)
     * @param metadata arbitrary metadata associated with the are, also reported on click
     */
    public void addClickArea(int id, String contentDescription,
                             float left, float top, float right, float bottom, String metadata) {
        mClickAreas.add(new ClickAreaRepresentation(id,
                contentDescription, left, top, right, bottom, metadata));
    public void addClickArea(
            int id,
            String contentDescription,
            float left,
            float top,
            float right,
            float bottom,
            String metadata) {
        mClickAreas.add(
                new ClickAreaRepresentation(
                        id, contentDescription, left, top, right, bottom, metadata));
    }

    /**
@@ -672,9 +699,7 @@ public class CoreDocument {
        }
    }

    /**
     * Warn click listeners when a click area is activated
     */
    /** Warn click listeners when a click area is activated */
    private void warnClickListeners(ClickAreaRepresentation clickArea) {
        for (ClickCallbacks listener : mClickListeners) {
            listener.click(clickArea.mId, clickArea.mMetadata);
@@ -746,7 +771,6 @@ public class CoreDocument {
     * @param theme the theme we want to use for this document.
     */
    public void paint(RemoteContext context, int theme) {
        long time = System.nanoTime();
        context.getPaintContext().clearNeedsRepaint();
        context.mMode = RemoteContext.ContextMode.UNSET;

@@ -760,8 +784,12 @@ public class CoreDocument {
        if (mContentSizing == RootContentBehavior.SIZING_SCALE) {
            // we need to add canvas transforms ops here
            computeScale(context.mWidth, context.mHeight, mScaleOutput);
            computeTranslate(context.mWidth, context.mHeight,
                    mScaleOutput[0], mScaleOutput[1], mTranslateOutput);
            computeTranslate(
                    context.mWidth,
                    context.mHeight,
                    mScaleOutput[0],
                    mScaleOutput[1],
                    mTranslateOutput);
            context.mPaintContext.translate(mTranslateOutput[0], mTranslateOutput[1]);
            context.mPaintContext.scale(mScaleOutput[0], mScaleOutput[1]);
        }
@@ -795,7 +823,8 @@ public class CoreDocument {
            // or the theme is equal as the one passed in argument to paint.
            boolean apply = true;
            if (theme != Theme.UNSPECIFIED) {
                apply = op instanceof Theme // always apply a theme setter
                apply =
                        op instanceof Theme // always apply a theme setter
                                || context.getTheme() == theme
                                || context.getTheme() == Theme.UNSPECIFIED;
            }
@@ -809,6 +838,9 @@ public class CoreDocument {
        }
        context.mMode = RemoteContext.ContextMode.UNSET;
        // System.out.println(">>   " + (  System.nanoTime() - time)*1E-6f+" ms");
        if (DEBUG && mRootLayoutComponent != null) {
            System.out.println(mRootLayoutComponent.displayHierarchy());
        }
    }

    public String[] getStats() {
@@ -831,7 +863,6 @@ public class CoreDocument {
            if (mOperation instanceof Component) {
                Component com = (Component) mOperation;
                count += addChildren(com, map, buffer);

            }
        }

@@ -893,5 +924,8 @@ public class CoreDocument {
            }
        }
    }
}

    public List<Operation> getOperations() {
        return mOperations;
    }
}
+1 −3
Original line number Diff line number Diff line
@@ -17,6 +17,4 @@ package com.android.internal.widget.remotecompose.core;

import com.android.internal.widget.remotecompose.core.documentation.DocumentedCompanionOperation;

public interface DocumentedCompanion extends CompanionOperation , DocumentedCompanionOperation {

}
public interface DocumentedCompanion extends CompanionOperation, DocumentedCompanionOperation {}
+3 −9
Original line number Diff line number Diff line
@@ -15,14 +15,10 @@
 */
package com.android.internal.widget.remotecompose.core;

/**
 * Base interface for RemoteCompose operations
 */
/** Base interface for RemoteCompose operations */
public interface Operation {

    /**
     * add the operation to the buffer
     */
    /** add the operation to the buffer */
    void write(WireBuffer buffer);

    /**
@@ -32,8 +28,6 @@ public interface Operation {
     */
    void apply(RemoteContext context);

    /**
     * Debug utility to display an operation + indentation
     */
    /** Debug utility to display an operation + indentation */
    String deepToString(String indent);
}
+45 −9

File changed.

Preview size limit exceeded, changes collapsed.

Loading