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

Commit 6f38ecb7 authored by John Hoford's avatar John Hoford Committed by Android (Google) Code Review
Browse files

Merge "Update to ToT RemoteCompose" into main

parents 6778496a 5c3c43a6
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -64,16 +64,16 @@ public class CoreDocument implements Serializable {
    private static final boolean DEBUG = false;

    // Semantic version
    public static final int MAJOR_VERSION = 0;
    public static final int MINOR_VERSION = 4;
    public static final int MAJOR_VERSION = 1;
    public static final int MINOR_VERSION = 0;
    public static final int PATCH_VERSION = 0;

    // Internal version level
    public static final int DOCUMENT_API_LEVEL = 4;
    public static final int DOCUMENT_API_LEVEL = 5;

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

    private static final boolean UPDATE_VARIABLES_BEFORE_LAYOUT = false;

+3 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.internal.widget.remotecompose.core.operations.DataListFloat;
import com.android.internal.widget.remotecompose.core.operations.DataListIds;
import com.android.internal.widget.remotecompose.core.operations.DataMapIds;
import com.android.internal.widget.remotecompose.core.operations.DataMapLookup;
import com.android.internal.widget.remotecompose.core.operations.DebugMessage;
import com.android.internal.widget.remotecompose.core.operations.DrawArc;
import com.android.internal.widget.remotecompose.core.operations.DrawBitmap;
import com.android.internal.widget.remotecompose.core.operations.DrawBitmapFontText;
@@ -231,6 +232,7 @@ public class Operations {
    public static final int PATH_COMBINE = 175;
    public static final int HAPTIC_FEEDBACK = 177;
    public static final int CONDITIONAL_OPERATIONS = 178;
    public static final int DEBUG_MESSAGE = 179;

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

@@ -443,6 +445,7 @@ public class Operations {
        map.put(PATH_COMBINE, PathCombine::read);
        map.put(HAPTIC_FEEDBACK, HapticFeedback::read);
        map.put(CONDITIONAL_OPERATIONS, ConditionalOperations::read);
        map.put(DEBUG_MESSAGE, DebugMessage::read);

        //        map.put(ACCESSIBILITY_CUSTOM_ACTION, CoreSemantics::read);
    }
+53 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.internal.widget.remotecompose.core.operations.DataListFloat;
import com.android.internal.widget.remotecompose.core.operations.DataListIds;
import com.android.internal.widget.remotecompose.core.operations.DataMapIds;
import com.android.internal.widget.remotecompose.core.operations.DataMapLookup;
import com.android.internal.widget.remotecompose.core.operations.DebugMessage;
import com.android.internal.widget.remotecompose.core.operations.DrawArc;
import com.android.internal.widget.remotecompose.core.operations.DrawBitmap;
import com.android.internal.widget.remotecompose.core.operations.DrawBitmapFontText;
@@ -1332,7 +1333,7 @@ public class RemoteComposeBuffer {
     * @return the nan id of float
     */
    public float reserveFloatVariable() {
        int id = mRemoteComposeState.cacheFloat(0f);
        int id = mRemoteComposeState.nextId();
        return Utils.asNan(id);
    }

@@ -1869,6 +1870,46 @@ public class RemoteComposeBuffer {
        ContainerEnd.apply(mBuffer);
    }

    /**
     * Add a scroll modifier
     *
     * @param direction HORIZONTAL(0) or VERTICAL(1)
     * @param positionId the position id as a NaN
     */
    public void addModifierScroll(int direction, float positionId) {
        float max = this.reserveFloatVariable();
        float notchMax = this.reserveFloatVariable();
        float touchExpressionDirection =
                direction != 0 ? RemoteContext.FLOAT_TOUCH_POS_X : RemoteContext.FLOAT_TOUCH_POS_Y;

        ScrollModifierOperation.apply(mBuffer, direction, positionId, max, notchMax);
        this.addTouchExpression(
                positionId,
                0f,
                0f,
                max,
                0f,
                3,
                new float[] {
                    touchExpressionDirection, -1, MUL,
                },
                TouchExpression.STOP_GENTLY,
                null,
                null);
        ContainerEnd.apply(mBuffer);
    }

    /**
     * Add a scroll modifier
     *
     * @param direction HORIZONTAL(0) or VERTICAL(1)
     */
    public void addModifierScroll(int direction) {
        float max = this.reserveFloatVariable();
        ScrollModifierOperation.apply(mBuffer, direction, 0f, max, 0f);
        ContainerEnd.apply(mBuffer);
    }

    /**
     * Add a background modifier of provided color
     *
@@ -2464,4 +2505,15 @@ public class RemoteComposeBuffer {
    public void addConditionalOperations(byte type, float a, float b) {
        ConditionalOperations.apply(mBuffer, type, a, b);
    }

    /**
     * Add a debug message
     *
     * @param textId text id
     * @param value
     * @param flags
     */
    public void addDebugMessage(int textId, float value, int flags) {
        DebugMessage.apply(mBuffer, textId, value, flags);
    }
}
+157 −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 com.android.internal.widget.remotecompose.core.Operation;
import com.android.internal.widget.remotecompose.core.Operations;
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.documentation.DocumentedOperation;

import java.util.List;

/**
 * This prints debugging message useful for debugging. It should not be use in production documents
 */
public class DebugMessage extends Operation implements VariableSupport {
    private static final int OP_CODE = Operations.DEBUG_MESSAGE;
    private static final String CLASS_NAME = "DebugMessage";
    int mTextID;
    float mFloatValue;
    float mOutFloatValue;
    int mFlags = 0;

    public DebugMessage(int textID, float value, int flags) {
        mTextID = textID;
        mFloatValue = value;
        mFlags = flags;
    }

    @Override
    public void updateVariables(@NonNull RemoteContext context) {
        System.out.println("Debug message : updateVariables ");
        mOutFloatValue =
                Float.isNaN(mFloatValue)
                        ? context.getFloat(Utils.idFromNan(mFloatValue))
                        : mFloatValue;
        System.out.println(
                "Debug message : updateVariables "
                        + Utils.floatToString(mFloatValue, mOutFloatValue));
    }

    @Override
    public void registerListening(@NonNull RemoteContext context) {
        System.out.println("Debug message : registerListening ");

        if (Float.isNaN(mFloatValue)) {
            System.out.println("Debug message : registerListening " + mFloatValue);
            context.listensTo(Utils.idFromNan(mFloatValue), this);
        }
    }

    @Override
    public void write(@NonNull WireBuffer buffer) {
        apply(buffer, mTextID, mFloatValue, mFlags);
    }

    @NonNull
    @Override
    public String toString() {
        return "DebugMessage "
                + mTextID
                + ", "
                + Utils.floatToString(mFloatValue, mOutFloatValue)
                + ", "
                + mFlags;
    }

    /**
     * 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) {
        int text = buffer.readInt();
        float floatValue = buffer.readFloat();
        int flags = buffer.readInt();
        DebugMessage op = new DebugMessage(text, floatValue, flags);
        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;
    }

    /**
     * Writes out the operation to the buffer
     *
     * @param buffer write the command to the buffer
     * @param textID id of the text
     * @param value value to print
     * @param flags flags to print
     */
    public static void apply(@NonNull WireBuffer buffer, int textID, float value, int flags) {
        buffer.start(OP_CODE);
        buffer.writeInt(textID);
        buffer.writeFloat(value);
        buffer.writeInt(flags);
    }

    /**
     * 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("DebugMessage Operations", id(), CLASS_NAME)
                .description("Print debugging messages")
                .field(DocumentedOperation.INT, "textId", "test to print")
                .field(DocumentedOperation.FLOAT, "value", "value of a float to print")
                .field(DocumentedOperation.INT, "flags", "print additional information");
    }

    @Override
    public void apply(@NonNull RemoteContext context) {
        String str = context.getText(mTextID);
        System.out.println("Debug message : " + str + " " + mOutFloatValue + " " + mFlags);
    }

    @NonNull
    @Override
    public String deepToString(@NonNull String indent) {
        return indent + toString();
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -266,10 +266,12 @@ public class TimeAttribute extends PaintOperation {
            case TIME_FROM_NOW_SEC:
            case TIME_FROM_ARG_SEC:
                ctx.loadFloat(mId, (delta) * 1E-3f);
                ctx.needsRepaint();
                break;
            case TIME_FROM_ARG_MIN:
            case TIME_FROM_NOW_MIN:
                ctx.loadFloat(mId, (float) (delta * 1E-3 / 60));
                ctx.needsRepaint();
                break;
            case TIME_FROM_ARG_HR:
            case TIME_FROM_NOW_HR:
@@ -298,6 +300,7 @@ public class TimeAttribute extends PaintOperation {
                break;
            case TIME_FROM_LOAD_SEC:
                ctx.loadFloat(mId, (value - load_time) * 1E-3f);
                ctx.needsRepaint();
                break;
        }
    }
Loading