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

Commit 9ec1c551 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: If821c6c14022f824645a6c6bc5f42e0b611f316b
parent 56c3534e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ 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.2f;
    static final float BUILD = 0.3f;

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

@@ -411,7 +411,7 @@ public class CoreDocument implements Serializable {
    @Override
    public void serialize(MapSerializer serializer) {
        serializer
                .add("type", "CoreDocument")
                .addType("CoreDocument")
                .add("width", mWidth)
                .add("height", mHeight)
                .add("operations", mOperations);
+3 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ import com.android.internal.widget.remotecompose.core.operations.layout.managers
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CollapsibleColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CollapsibleRowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.ColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.FitBoxLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.RowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.StateLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.TextLayout;
@@ -231,6 +232,7 @@ public class Operations {
    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_FIT_BOX = 176;
    public static final int LAYOUT_ROW = 203;
    public static final int LAYOUT_COLLAPSIBLE_ROW = 230;
    public static final int LAYOUT_COLUMN = 204;
@@ -391,6 +393,7 @@ public class Operations {
        map.put(LAYOUT_ROOT, RootLayoutComponent::read);
        map.put(LAYOUT_CONTENT, LayoutComponentContent::read);
        map.put(LAYOUT_BOX, BoxLayout::read);
        map.put(LAYOUT_FIT_BOX, FitBoxLayout::read);
        map.put(LAYOUT_COLUMN, ColumnLayout::read);
        map.put(LAYOUT_COLLAPSIBLE_COLUMN, CollapsibleColumnLayout::read);
        map.put(LAYOUT_ROW, RowLayout::read);
+3 −1
Original line number Diff line number Diff line
@@ -17,11 +17,13 @@ package com.android.internal.widget.remotecompose.core;

import android.annotation.NonNull;

import com.android.internal.widget.remotecompose.core.serialize.Serializable;

/**
 * PaintOperation interface, used for operations aimed at painting (while any operation _can_ paint,
 * this make it a little more explicit)
 */
public abstract class PaintOperation extends Operation {
public abstract class PaintOperation extends Operation implements Serializable {

    @Override
    public void apply(@NonNull RemoteContext context) {
+13 −0
Original line number Diff line number Diff line
@@ -46,6 +46,14 @@ public interface Platform {
     */
    int getImageHeight(@NonNull Object image);

    /**
     * Returns true if the platform-specific image object has format ALPHA_8
     *
     * @param image platform-specific image object
     * @return whether or not the platform-specific image object has format ALPHA_8
     */
    boolean isAlpha8Image(@NonNull Object image);

    /**
     * Converts a platform-specific path object into a platform-independent float buffer
     *
@@ -109,6 +117,11 @@ public interface Platform {
                    throw new UnsupportedOperationException();
                }

                @Override
                public boolean isAlpha8Image(@NonNull Object image) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public float[] pathToFloatArray(@NonNull Object path) {
                    throw new UnsupportedOperationException();
+56 −73
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ import com.android.internal.widget.remotecompose.core.operations.layout.managers
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CollapsibleColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.CollapsibleRowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.ColumnLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.FitBoxLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.RowLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.StateLayout;
import com.android.internal.widget.remotecompose.core.operations.layout.managers.TextLayout;
@@ -281,13 +282,7 @@ public class RemoteComposeBuffer {
            int dstRight,
            int dstBottom,
            @Nullable String contentDescription) {
        int imageId = mRemoteComposeState.dataGetId(image);
        if (imageId == -1) {
            imageId = mRemoteComposeState.cacheData(image);
            byte[] data = mPlatform.imageToByteArray(image); // todo: potential npe
            BitmapData.apply(
                    mBuffer, imageId, imageWidth, imageHeight, data); // todo: potential npe
        }
        int imageId = storeBitmap(image);
        int contentDescriptionId = 0;
        if (contentDescription != null) {
            contentDescriptionId = addText(contentDescription);
@@ -443,16 +438,7 @@ public class RemoteComposeBuffer {
            float right,
            float bottom,
            @Nullable String contentDescription) {
        int imageId = mRemoteComposeState.dataGetId(image);
        if (imageId == -1) {
            imageId = mRemoteComposeState.cacheData(image);
            byte[] data = mPlatform.imageToByteArray(image); // todo: potential npe
            int imageWidth = mPlatform.getImageWidth(image);
            int imageHeight = mPlatform.getImageHeight(image);

            BitmapData.apply(
                    mBuffer, imageId, imageWidth, imageHeight, data); // todo: potential npe
        }
        int imageId = storeBitmap(image);
        addDrawBitmap(imageId, left, top, right, bottom, contentDescription);
    }

@@ -523,15 +509,7 @@ public class RemoteComposeBuffer {
            int scaleType,
            float scaleFactor,
            @Nullable String contentDescription) {
        int imageId = mRemoteComposeState.dataGetId(image);
        if (imageId == -1) {
            imageId = mRemoteComposeState.cacheData(image);
            byte[] data = mPlatform.imageToByteArray(image); // todo: potential npe
            int imageWidth = mPlatform.getImageWidth(image);
            int imageHeight = mPlatform.getImageHeight(image);

            BitmapData.apply(mBuffer, imageId, imageWidth, imageHeight, data); // todo: potential pe
        }
        int imageId = storeBitmap(image);
        int contentDescriptionId = 0;
        if (contentDescription != null) {
            contentDescriptionId = addText(contentDescription);
@@ -559,16 +537,7 @@ public class RemoteComposeBuffer {
     * @return id of the image useful with
     */
    public int addBitmap(@NonNull Object image) {
        int imageId = mRemoteComposeState.dataGetId(image);
        if (imageId == -1) {
            imageId = mRemoteComposeState.cacheData(image);
            byte[] data = mPlatform.imageToByteArray(image); // tODO: potential npe
            int imageWidth = mPlatform.getImageWidth(image);
            int imageHeight = mPlatform.getImageHeight(image);

            BitmapData.apply(mBuffer, imageId, imageWidth, imageHeight, data);
        }
        return imageId;
        return storeBitmap(image);
    }

    /**
@@ -578,18 +547,7 @@ public class RemoteComposeBuffer {
     * @return id of the image useful with
     */
    public int addBitmap(@NonNull Object image, @NonNull String name) {
        int imageId = mRemoteComposeState.dataGetId(image);
        if (imageId == -1) {
            imageId = mRemoteComposeState.cacheData(image);
            byte[] data = mPlatform.imageToByteArray(image); // todo: potential npe
            int imageWidth = mPlatform.getImageWidth(image);
            int imageHeight = mPlatform.getImageHeight(image);

            BitmapData.apply(mBuffer, imageId, imageWidth, imageHeight, data);
            setBitmapName(imageId, name);
        }

        return imageId;
        return storeBitmap(image);
    }

    /**
@@ -1393,7 +1351,7 @@ public class RemoteComposeBuffer {
     * @return the id of the command representing long
     */
    public int addLong(long value) {
        int id = mRemoteComposeState.cacheData(value);
        int id = mRemoteComposeState.nextId();
        LongConstant.apply(mBuffer, id, value);
        return id;
    }
@@ -1405,7 +1363,7 @@ public class RemoteComposeBuffer {
     * @return the id
     */
    public int addBoolean(boolean value) {
        int id = mRemoteComposeState.cacheData(value);
        int id = mRemoteComposeState.nextId();
        BooleanConstant.apply(mBuffer, id, value);
        return id;
    }
@@ -1821,33 +1779,14 @@ public class RemoteComposeBuffer {
    }

    /**
     * This defines the name of the color given the id.
     *
     * @param id of the color
     * @param name Name of the color
     */
    public void setColorName(int id, @NonNull String name) {
        NamedVariable.apply(mBuffer, id, NamedVariable.COLOR_TYPE, name);
    }

    /**
     * This defines the name of the string given the id
     *
     * @param id of the string
     * @param name name of the string
     */
    public void setStringName(int id, @NonNull String name) {
        NamedVariable.apply(mBuffer, id, NamedVariable.STRING_TYPE, name);
    }

    /**
     * This defines the name of the float given the id
     * This defines the name of a type of given object
     *
     * @param id of the float
     * @param name name of the float
     * @param type the type of variable NamedVariable.COLOR_TYPE, STRING_TYPE, etc
     */
    public void setFloatName(int id, String name) {
        NamedVariable.apply(mBuffer, id, NamedVariable.FLOAT_TYPE, name);
    public void setNamedVariable(int id, @NonNull String name, int type) {
        NamedVariable.apply(mBuffer, id, type, name);
    }

    /**
@@ -2138,6 +2077,19 @@ public class RemoteComposeBuffer {
        BoxLayout.apply(mBuffer, mLastComponentId, animationId, horizontal, vertical);
    }

    /**
     * Add a fitbox start tag
     *
     * @param componentId component id
     * @param animationId animation id
     * @param horizontal horizontal alignment
     * @param vertical vertical alignment
     */
    public void addFitBoxStart(int componentId, int animationId, int horizontal, int vertical) {
        mLastComponentId = getComponentId(componentId);
        FitBoxLayout.apply(mBuffer, mLastComponentId, animationId, horizontal, vertical);
    }

    /**
     * Add a row start tag
     *
@@ -2439,4 +2391,35 @@ public class RemoteComposeBuffer {
    public void drawComponentContent() {
        DrawContent.apply(mBuffer);
    }

    /**
     * Ensures the bitmap is stored.
     *
     * @param image the bitbap to store
     * @return the id of the bitmap
     */
    private int storeBitmap(Object image) {
        int imageId = mRemoteComposeState.dataGetId(image);
        if (imageId == -1) {
            imageId = mRemoteComposeState.cacheData(image);
            byte[] data = mPlatform.imageToByteArray(image); // todo: potential npe
            short imageWidth = (short) mPlatform.getImageWidth(image);
            short imageHeight = (short) mPlatform.getImageHeight(image);
            if (mPlatform.isAlpha8Image(image)) {
                BitmapData.apply(
                        mBuffer,
                        imageId,
                        BitmapData.TYPE_PNG_ALPHA_8,
                        imageWidth,
                        BitmapData.ENCODING_INLINE,
                        imageHeight,
                        data); // todo: potential npe
            } else {
                BitmapData.apply(
                        mBuffer, imageId, imageWidth, imageHeight, data); // todo: potential npe
            }
        }

        return imageId;
    }
}
Loading