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

Commit c822a7c8 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: I5f7443df9a0fac694ba6b444011fa926a76e7130
parent efeea629
Loading
Loading
Loading
Loading
+2 −1
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.1f;
    static final float BUILD = 0.2f;

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

@@ -742,6 +742,7 @@ public class CoreDocument implements Serializable {
            if (op instanceof Component) {
                mComponentMap.put(((Component) op).getComponentId(), (Component) op);
                registerVariables(context, ((Component) op).getList());
                ((Component) op).registerVariables(context);
            }
            if (op instanceof ComponentValue) {
                ComponentValue v = (ComponentValue) op;
+9 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.internal.widget.remotecompose.core.operations.DrawBitmapFontT
import com.android.internal.widget.remotecompose.core.operations.DrawBitmapInt;
import com.android.internal.widget.remotecompose.core.operations.DrawBitmapScaled;
import com.android.internal.widget.remotecompose.core.operations.DrawCircle;
import com.android.internal.widget.remotecompose.core.operations.DrawContent;
import com.android.internal.widget.remotecompose.core.operations.DrawLine;
import com.android.internal.widget.remotecompose.core.operations.DrawOval;
import com.android.internal.widget.remotecompose.core.operations.DrawPath;
@@ -81,6 +82,7 @@ import com.android.internal.widget.remotecompose.core.operations.Theme;
import com.android.internal.widget.remotecompose.core.operations.TimeAttribute;
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.CanvasOperations;
import com.android.internal.widget.remotecompose.core.operations.layout.ClickModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.ComponentStart;
import com.android.internal.widget.remotecompose.core.operations.layout.ContainerEnd;
@@ -105,6 +107,7 @@ import com.android.internal.widget.remotecompose.core.operations.layout.modifier
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.ComponentVisibilityOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.DrawContentOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.GraphicsLayerModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.HeightInModifierOperation;
import com.android.internal.widget.remotecompose.core.operations.layout.modifiers.HeightModifierOperation;
@@ -172,6 +175,7 @@ public class Operations {
    public static final int DATA_PATH = 123;
    public static final int DRAW_PATH = 124;
    public static final int DRAW_TWEEN_PATH = 125;
    public static final int DRAW_CONTENT = 139;
    public static final int MATRIX_SCALE = 126;
    public static final int MATRIX_TRANSLATE = 127;
    public static final int MATRIX_SKEW = 128;
@@ -215,6 +219,8 @@ public class Operations {
    public static final int ATTRIBUTE_TEXT = 170;
    public static final int ATTRIBUTE_IMAGE = 171;
    public static final int ATTRIBUTE_TIME = 172;
    public static final int CANVAS_OPERATIONS = 173;
    public static final int MODIFIER_DRAW_CONTENT = 174;

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

@@ -366,6 +372,7 @@ public class Operations {
        map.put(MODIFIER_SCROLL, ScrollModifierOperation::read);
        map.put(MODIFIER_MARQUEE, MarqueeModifierOperation::read);
        map.put(MODIFIER_RIPPLE, RippleModifierOperation::read);
        map.put(MODIFIER_DRAW_CONTENT, DrawContentOperation::read);

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

@@ -393,6 +400,7 @@ public class Operations {
        map.put(LAYOUT_TEXT, TextLayout::read);

        map.put(LAYOUT_STATE, StateLayout::read);
        map.put(DRAW_CONTENT, DrawContent::read);

        map.put(COMPONENT_VALUE, ComponentValue::read);
        map.put(DRAW_ARC, DrawArc::read);
@@ -409,6 +417,7 @@ public class Operations {
        map.put(PARTICLE_LOOP, ParticlesLoop::read);
        map.put(FUNCTION_CALL, FloatFunctionCall::read);
        map.put(FUNCTION_DEFINE, FloatFunctionDefine::read);
        map.put(CANVAS_OPERATIONS, CanvasOperations::read);

        map.put(ACCESSIBILITY_SEMANTICS, CoreSemantics::read);
        map.put(ATTRIBUTE_IMAGE, ImageAttribute::read);
+13 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.internal.widget.remotecompose.core.operations.DrawBitmapFontT
import com.android.internal.widget.remotecompose.core.operations.DrawBitmapInt;
import com.android.internal.widget.remotecompose.core.operations.DrawBitmapScaled;
import com.android.internal.widget.remotecompose.core.operations.DrawCircle;
import com.android.internal.widget.remotecompose.core.operations.DrawContent;
import com.android.internal.widget.remotecompose.core.operations.DrawLine;
import com.android.internal.widget.remotecompose.core.operations.DrawOval;
import com.android.internal.widget.remotecompose.core.operations.DrawPath;
@@ -84,6 +85,7 @@ import com.android.internal.widget.remotecompose.core.operations.TimeAttribute;
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.CanvasOperations;
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.ImpulseOperation;
@@ -1887,7 +1889,7 @@ public class RemoteComposeBuffer {
    }

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

@@ -2231,6 +2233,11 @@ public class RemoteComposeBuffer {
        LayoutComponentContent.apply(mBuffer, mLastComponentId);
    }

    /** Add a canvas operations start tag */
    public void addCanvasOperationsStart() {
        CanvasOperations.apply(mBuffer);
    }

    /**
     * Add a component width value
     *
@@ -2427,4 +2434,9 @@ public class RemoteComposeBuffer {
        TimeAttribute.apply(mBuffer, id, timeId, attribute, args);
        return Utils.asNan(id);
    }

    /** In the context of a component draw modifier, draw the content of the component */
    public void drawComponentContent() {
        DrawContent.apply(mBuffer);
    }
}
+119 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.core.operations;

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

import com.android.internal.widget.remotecompose.core.Operation;
import com.android.internal.widget.remotecompose.core.Operations;
import com.android.internal.widget.remotecompose.core.PaintContext;
import com.android.internal.widget.remotecompose.core.PaintOperation;
import com.android.internal.widget.remotecompose.core.WireBuffer;
import com.android.internal.widget.remotecompose.core.documentation.DocumentationBuilder;
import com.android.internal.widget.remotecompose.core.operations.layout.LayoutComponent;
import com.android.internal.widget.remotecompose.core.serialize.MapSerializer;
import com.android.internal.widget.remotecompose.core.serialize.Serializable;

import java.util.List;

/** The DrawContent command */
public class DrawContent extends PaintOperation implements Serializable {
    private static final int OP_CODE = Operations.DRAW_CONTENT;
    private static final String CLASS_NAME = "DrawContent";
    private @Nullable LayoutComponent mComponent;

    @Override
    public void write(@NonNull WireBuffer buffer) {
        apply(buffer);
    }

    /**
     * Set the component to be painted
     *
     * @param component
     */
    public void setComponent(LayoutComponent component) {
        mComponent = component;
    }

    @NonNull
    @Override
    public String toString() {
        return "DrawContent;";
    }

    /**
     * Read this operation and add it to the list of operations
     *
     * @param buffer the buffer to read
     * @param operations the list of operations that will be added to
     */
    public static void read(@NonNull WireBuffer buffer, @NonNull List<Operation> operations) {
        DrawContent op = new DrawContent();
        operations.add(op);
    }

    /**
     * The name of the class
     *
     * @return the name
     */
    @NonNull
    public static String name() {
        return CLASS_NAME;
    }

    /**
     * The OP_CODE for this command
     *
     * @return the opcode
     */
    public static int id() {
        return OP_CODE;
    }

    /**
     * add a draw content operation to the buffer
     *
     * @param buffer the buffer to add to
     */
    public static void apply(@NonNull WireBuffer buffer) {
        buffer.start(Operations.DRAW_CONTENT);
    }

    /**
     * Populate the documentation with a description of this operation
     *
     * @param doc to append the description to.
     */
    public static void documentation(@NonNull DocumentationBuilder doc) {
        doc.operation("Layout Operations", OP_CODE, CLASS_NAME)
                .description("Draw the component content");
    }

    @Override
    public void paint(@NonNull PaintContext context) {
        if (mComponent != null) {
            mComponent.drawContent(context);
        }
    }

    @Override
    public void serialize(MapSerializer serializer) {
        serializer.add("type", CLASS_NAME);
    }
}
+175 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.widget.remotecompose.core.operations.layout;

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

import com.android.internal.widget.remotecompose.core.Operation;
import com.android.internal.widget.remotecompose.core.Operations;
import com.android.internal.widget.remotecompose.core.PaintContext;
import com.android.internal.widget.remotecompose.core.PaintOperation;
import com.android.internal.widget.remotecompose.core.RemoteContext;
import com.android.internal.widget.remotecompose.core.VariableSupport;
import com.android.internal.widget.remotecompose.core.WireBuffer;
import com.android.internal.widget.remotecompose.core.documentation.DocumentationBuilder;
import com.android.internal.widget.remotecompose.core.operations.ComponentValue;
import com.android.internal.widget.remotecompose.core.operations.DrawContent;
import com.android.internal.widget.remotecompose.core.serialize.MapSerializer;
import com.android.internal.widget.remotecompose.core.serialize.Serializable;

import java.util.ArrayList;
import java.util.List;

/** Represents a list of canvas operations. */
public class CanvasOperations extends PaintOperation
        implements VariableSupport, Container, Serializable {
    private static final int OP_CODE = Operations.CANVAS_OPERATIONS;
    private static final String CLASS_NAME = "CanvasOperations";

    @NonNull public ArrayList<Operation> mList = new ArrayList<>();
    @Nullable LayoutComponent mComponent;

    /** The constructor */
    public CanvasOperations() {}

    @Override
    public void registerListening(RemoteContext context) {
        for (Operation operation : mList) {
            if (operation instanceof VariableSupport) {
                VariableSupport variableSupport = (VariableSupport) operation;
                variableSupport.registerListening(context);
            }
            if (operation instanceof ComponentValue) {
                ComponentValue v = (ComponentValue) operation;
                mComponent.addComponentValue(v);
            }
        }
    }

    @Override
    public void updateVariables(RemoteContext context) {
        for (Operation operation : mList) {
            if (operation instanceof VariableSupport) {
                VariableSupport variableSupport = (VariableSupport) operation;
                variableSupport.updateVariables(context);
            }
        }
    }

    /**
     * The returns a list to be filled
     *
     * @return list to be filled
     */
    @NonNull
    public ArrayList<Operation> getList() {
        return mList;
    }

    @Override
    public void write(@NonNull WireBuffer buffer) {
        apply(buffer);
    }

    @NonNull
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder(CLASS_NAME + "\n");
        for (Operation operation : mList) {
            builder.append("  ");
            builder.append(operation);
            builder.append("\n");
        }
        return builder.toString();
    }

    @NonNull
    @Override
    public String deepToString(@NonNull String indent) {
        return (indent != null ? indent : "") + toString();
    }

    @Override
    public void paint(@NonNull PaintContext context) {
        RemoteContext remoteContext = context.getContext();
        for (Operation op : mList) {
            if (op instanceof VariableSupport && op.isDirty()) {
                ((VariableSupport) op).updateVariables(context.getContext());
            }
            remoteContext.incrementOpCount();
            op.apply(context.getContext());
        }
    }

    /**
     * The name of the class
     *
     * @return the name
     */
    @NonNull
    public static String name() {
        return "Loop";
    }

    /**
     * Apply this operation to the buffer
     *
     * @param buffer
     */
    public static void apply(@NonNull WireBuffer buffer) {
        buffer.start(OP_CODE);
    }

    /**
     * Read this operation and add it to the list of operations
     *
     * @param buffer the buffer to read
     * @param operations the list of operations that will be added to
     */
    public static void read(@NonNull WireBuffer buffer, @NonNull List<Operation> operations) {
        operations.add(new CanvasOperations());
    }

    /**
     * Populate the documentation with a description of this operation
     *
     * @param doc to append the description to.
     */
    public static void documentation(@NonNull DocumentationBuilder doc) {
        doc.operation("Operations", OP_CODE, name())
                .description("Impulse Process that runs a list of operations");
    }

    @Override
    public void serialize(MapSerializer serializer) {
        serializer.add("type", CLASS_NAME).add("list", mList);
    }

    /**
     * Set layout component
     *
     * @param layoutComponent
     */
    public void setComponent(LayoutComponent layoutComponent) {
        mComponent = layoutComponent;
        for (Operation op : mList) {
            if (op instanceof DrawContent) {
                ((DrawContent) op).setComponent(layoutComponent);
            }
        }
    }
}
Loading