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

Commit 57d5b5a4 authored by Nicolas Roard's avatar Nicolas Roard
Browse files

Update to ToT RemoteCompose

bug: 412684851
Flag: EXEMPT External Libraries
Test: in GoB
Change-Id: Id9a5d35e6c78fcb7a7781dec62fc8f091ac3721d
parent 58a717f2
Loading
Loading
Loading
Loading
+225 −77
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

@@ -74,22 +75,28 @@ public class CoreDocument implements Serializable {

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

    private static final boolean UPDATE_VARIABLES_BEFORE_LAYOUT = false;

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

    @Nullable RootLayoutComponent mRootLayoutComponent = null;
    @Nullable
    RootLayoutComponent mRootLayoutComponent = null;

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

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

    @Nullable String
            mContentDescription; // text description of the document (used for accessibility)
    @Nullable
    String mContentDescription; // text description of the document (used for accessibility)

    long mRequiredCapabilities = 0L; // bitmask indicating needed capabilities of the player(unused)
    int mWidth = 0; // horizontal dimension of the document in pixels
@@ -101,7 +108,8 @@ public class CoreDocument implements Serializable {

    int mContentAlignment = RootContentBehavior.ALIGNMENT_CENTER;

    @NonNull RemoteComposeBuffer mBuffer = new RemoteComposeBuffer();
    @NonNull
    RemoteComposeBuffer mBuffer = new RemoteComposeBuffer();

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

@@ -133,7 +141,9 @@ public class CoreDocument implements Serializable {
        return mClock;
    }

    /** Returns a version number that is monotonically increasing. */
    /**
     * Returns a version number that is monotonically increasing.
     */
    public static int getDocumentApiLevel() {
        return DOCUMENT_API_LEVEL;
    }
@@ -219,11 +229,18 @@ public class CoreDocument implements Serializable {
     * @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;
@@ -368,7 +385,9 @@ public class CoreDocument implements Serializable {
        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();
@@ -603,7 +622,8 @@ public class CoreDocument implements Serializable {
        void haptic(int type);
    }

    @Nullable HapticEngine mHapticEngine;
    @Nullable
    HapticEngine mHapticEngine;

    public void setHapticEngine(@NonNull HapticEngine engine) {
        mHapticEngine = engine;
@@ -631,7 +651,9 @@ public class CoreDocument implements Serializable {
        mAppliedTouchOperations.add(component);
    }

    /** Callback interface for host actions */
    /**
     * Callback interface for host actions
     */
    public interface ActionCallback {
        /**
         * Callback for actions
@@ -642,7 +664,8 @@ public class CoreDocument implements Serializable {
        void onAction(@NonNull String name, @Nullable Object value);
    }

    @NonNull HashSet<ActionCallback> mActionListeners = new HashSet<ActionCallback>();
    @NonNull
    HashSet<ActionCallback> mActionListeners = new HashSet<ActionCallback>();

    /**
     * Warn action listeners for the given named action
@@ -666,12 +689,16 @@ public class CoreDocument implements Serializable {
        mActionListeners.add(callback);
    }

    /** Clear existing callbacks for named host actions */
    /**
     * Clear existing callbacks for named host actions
     */
    public void clearActionCallbacks() {
        mActionListeners.clear();
    }

    /** Id Actions */
    /**
     * Id Actions
     */
    public interface IdActionCallback {
        /**
         * Callback on Id Actions
@@ -682,9 +709,12 @@ public class CoreDocument implements Serializable {
        void onAction(int id, @Nullable String metadata);
    }

    @NonNull HashSet<IdActionCallback> mIdActionListeners = new HashSet<>();
    @NonNull HashSet<TouchListener> mTouchListeners = new HashSet<>();
    @NonNull HashSet<ClickAreaRepresentation> mClickAreas = new HashSet<>();
    @NonNull
    HashSet<IdActionCallback> mIdActionListeners = new HashSet<>();
    @NonNull
    HashSet<TouchListener> mTouchListeners = new HashSet<>();
    @NonNull
    HashSet<ClickAreaRepresentation> mClickAreas = new HashSet<>();

    static class Version {
        public final int major;
@@ -726,12 +756,14 @@ public class CoreDocument implements Serializable {

    public static class ClickAreaRepresentation {
        int mId;
        @Nullable final String mContentDescription;
        @Nullable
        final String mContentDescription;
        float mLeft;
        float mTop;
        float mRight;
        float mBottom;
        @Nullable final String mMetadata;
        @Nullable
        final String mMetadata;

        @Override
        public boolean equals(Object o) {
@@ -816,7 +848,9 @@ public class CoreDocument implements Serializable {
        }
    }

    /** Load operations from the given buffer */
    /**
     * Load operations from the given buffer
     */
    public void initFromBuffer(@NonNull RemoteComposeBuffer buffer) {
        mOperations = new ArrayList<Operation>();
        buffer.inflateFromBuffer(mOperations);
@@ -994,14 +1028,36 @@ public class CoreDocument implements Serializable {
    }

    /**
     * Called when an initialization is needed, allowing the document to eg load resources / cache
     * Called when an initialization is needed,
     * allowing the document to eg load resources / cache
     * them.
     *
     * @param context the context
     */
    public void initializeContext(@NonNull RemoteContext context) {
        initializeContext(context, null);
    }

    /**
     * Called when an initialization is needed,
     * allowing the document to eg load resources / cache
     * them.
     *
     * @param context   the context
     * @param bitmapMap bitmap map
     */
    public void initializeContext(@NonNull RemoteContext context,
                                  @Nullable Map<Integer, Object> bitmapMap) {
        mRemoteComposeState.reset();
        mRemoteComposeState.setContext(context);
        mClickAreas.clear();
        mRemoteComposeState.setNextId(RemoteComposeState.START_ID);
        if (bitmapMap != null) {
            for (Integer i : bitmapMap.keySet()) {
                mRemoteComposeState.cacheData(i, bitmapMap.get(i));
            }
        }

        context.mDocument = this;
        context.mRemoteComposeState = mRemoteComposeState;
        // mark context to be in DATA mode, which will skip the painting ops.
@@ -1164,7 +1220,9 @@ public class CoreDocument implements Serializable {
        }
    }

    /** Warn click listeners when a click area is activated */
    /**
     * Warn click listeners when a click area is activated
     */
    private void warnClickListeners(@NonNull ClickAreaRepresentation clickArea) {
        notifyOfException(clickArea.mId, clickArea.mMetadata);
    }
@@ -1181,6 +1239,7 @@ public class CoreDocument implements Serializable {
    }

    // TODO support velocity estimate support, support regions

    /**
     * Support touch drag events on commands supporting touch
     *
@@ -1496,6 +1555,93 @@ public class CoreDocument implements Serializable {
        return count;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Stats

    /// ////////////////////////////////////////////////////////////////////////////////////////////
    public static class DocInfo {
        public int mNumberOfOps = 0;
        public int mNumberOfImages = 0;
        public int mSizeOfImages = 0;

        /**
         * Get the number of operations
         *
         * @return number of operations
         */
        public int getNumberOfOps() {
            return mNumberOfOps;
        }

        /**
         * Get the number of images
         *
         * @return number of images
         */
        public int getNumberOfImages() {
            return mNumberOfImages;
        }

        /**
         * Get the size of images
         *
         * @return size of images
         */
        public int getSizeOfImages() {
            return mSizeOfImages;
        }
    }

    /**
     * Returns the list of bitmap data operations
     *
     * @return array of bitmap data operations
     */
    public @NonNull BitmapData[] getBitmapDataSet() {
        ArrayList<BitmapData> ret = new ArrayList<>();
        getBitmapDataSet(mOperations, ret);
        return ret.toArray(new BitmapData[0]);
    }

    private void getBitmapDataSet(@NonNull ArrayList<Operation> operations,
                                  @NonNull ArrayList<BitmapData> ret) {
        for (Operation operation : operations) {
            if (operation instanceof BitmapData) {
                ret.add((BitmapData) operation);
            }
            if (operation instanceof Container) {
                getBitmapDataSet(((Container) operation).getList(), ret);
            }
        }
    }

    /**
     * Returns the size of the document
     *
     * @return size of the document
     */
    public @NonNull DocInfo getDocInfo() {
        DocInfo docInfo = new DocInfo();
        getDocInfo(mOperations, docInfo);
        return docInfo;
    }

    private void getDocInfo(@NonNull ArrayList<Operation> operations, @NonNull DocInfo docInfo) {
        int count = operations.size();
        docInfo.mNumberOfOps += count;
        for (Operation operation : operations) {
            if (operation instanceof Container) {
                getDocInfo(((Container) operation).getList(), docInfo);
            }
            if (operation instanceof BitmapData) {
                docInfo.mNumberOfImages++;
                BitmapData b = ((BitmapData) operation);
                docInfo.mSizeOfImages += b.getWidth() * b.getHeight();
            }

        }
    }

    /**
     * Returns a list of useful statistics for the runtime document
     *
@@ -1601,7 +1747,9 @@ public class CoreDocument implements Serializable {
        return mOperations;
    }

    /** defines if a shader can be run */
    /**
     * defines if a shader can be run
     */
    public interface ShaderControl {
        /**
         * validate if a shader can run in the document
@@ -1613,7 +1761,7 @@ public class CoreDocument implements Serializable {
    }

    /**
     * validate the shaders
     * validate the shaders.
     *
     * @param context the remote context
     * @param ctl     the call back to allow evaluation of shaders
+0 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.core;

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

+0 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.core;

import android.annotation.NonNull;

/** Base interface for RemoteCompose operations */
+0 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.core;

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

+0 −1
Original line number Diff line number Diff line
@@ -14,5 +14,4 @@
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.core;

public interface RemoteComposeOperation {}
Loading