diff options
| author | 2024-11-19 23:41:59 +0000 | |
|---|---|---|
| committer | 2024-11-24 19:47:37 +0000 | |
| commit | 04be9989ee124b74ce7774677264492db8d5f8ee (patch) | |
| tree | 279351b57c30993ea679244265a354a2999ba499 | |
| parent | d97dc754b6c7d6129e0552b2524a83afc50e0cc0 (diff) | |
Update to ToT RemoteCompose
Bug: 339721781
Flag: EXEMPT External Libraries
Test: in GoB
Change-Id: I1f5da903e89b4c53863e34423bb66e882ebb8eab
120 files changed, 2814 insertions, 685 deletions
diff --git a/core/java/com/android/internal/widget/remotecompose/core/Operation.java b/core/java/com/android/internal/widget/remotecompose/core/Operation.java index 102003e2e371..6f6a0a892964 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/Operation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/Operation.java @@ -18,19 +18,19 @@ package com.android.internal.widget.remotecompose.core; import android.annotation.NonNull; /** Base interface for RemoteCompose operations */ -public interface Operation { +public abstract class Operation { /** add the operation to the buffer */ - void write(@NonNull WireBuffer buffer); + public abstract void write(@NonNull WireBuffer buffer); /** * paint an operation * * @param context the paint context used to paint the operation */ - void apply(@NonNull RemoteContext context); + public abstract void apply(@NonNull RemoteContext context); /** Debug utility to display an operation + indentation */ @NonNull - String deepToString(@NonNull String indent); + public abstract String deepToString(@NonNull String indent); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/OperationInterface.java b/core/java/com/android/internal/widget/remotecompose/core/OperationInterface.java new file mode 100644 index 000000000000..741303a40bc9 --- /dev/null +++ b/core/java/com/android/internal/widget/remotecompose/core/OperationInterface.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2023 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; + +import android.annotation.NonNull; + +/** Base interface for RemoteCompose operations */ +public interface OperationInterface { + + /** add the operation to the buffer */ + void write(@NonNull WireBuffer buffer); + + /** + * paint an operation + * + * @param context the paint context used to paint the operation + */ + void apply(@NonNull RemoteContext context); + + /** Debug utility to display an operation + indentation */ + @NonNull + String deepToString(@NonNull String indent); +} diff --git a/core/java/com/android/internal/widget/remotecompose/core/Operations.java b/core/java/com/android/internal/widget/remotecompose/core/Operations.java index 687a99baff83..006fe3afb4d8 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/Operations.java +++ b/core/java/com/android/internal/widget/remotecompose/core/Operations.java @@ -55,7 +55,10 @@ import com.android.internal.widget.remotecompose.core.operations.MatrixSkew; import com.android.internal.widget.remotecompose.core.operations.MatrixTranslate; import com.android.internal.widget.remotecompose.core.operations.NamedVariable; import com.android.internal.widget.remotecompose.core.operations.PaintData; +import com.android.internal.widget.remotecompose.core.operations.PathAppend; +import com.android.internal.widget.remotecompose.core.operations.PathCreate; import com.android.internal.widget.remotecompose.core.operations.PathData; +import com.android.internal.widget.remotecompose.core.operations.PathTween; import com.android.internal.widget.remotecompose.core.operations.RootContentBehavior; import com.android.internal.widget.remotecompose.core.operations.RootContentDescription; import com.android.internal.widget.remotecompose.core.operations.ShaderData; @@ -178,6 +181,9 @@ public class Operations { public static final int TEXT_MEASURE = 155; public static final int TEXT_LENGTH = 156; public static final int TOUCH_EXPRESSION = 157; + public static final int PATH_TWEEN = 158; + public static final int PATH_CREATE = 159; + public static final int PATH_ADD = 160; ///////////////////////////////////////// ====================== @@ -353,5 +359,8 @@ public class Operations { map.put(TEXT_MEASURE, TextMeasure::read); map.put(TEXT_LENGTH, TextLength::read); map.put(TOUCH_EXPRESSION, TouchExpression::read); + map.put(PATH_TWEEN, PathTween::read); + map.put(PATH_CREATE, PathCreate::read); + map.put(PATH_ADD, PathAppend::read); } } diff --git a/core/java/com/android/internal/widget/remotecompose/core/PaintContext.java b/core/java/com/android/internal/widget/remotecompose/core/PaintContext.java index 38b08e9b0ab3..7ecd11826303 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/PaintContext.java +++ b/core/java/com/android/internal/widget/remotecompose/core/PaintContext.java @@ -157,6 +157,8 @@ public abstract class PaintContext { public abstract void drawTweenPath( int path1Id, int path2Id, float tween, float start, float stop); + public abstract void tweenPath(int out, int path1, int path2, float tween); + /** * This applies changes to the current paint * diff --git a/core/java/com/android/internal/widget/remotecompose/core/PaintOperation.java b/core/java/com/android/internal/widget/remotecompose/core/PaintOperation.java index 9999182b53fc..cfdd52212b03 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/PaintOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/PaintOperation.java @@ -21,7 +21,7 @@ import android.annotation.NonNull; * PaintOperation interface, used for operations aimed at painting (while any operation _can_ paint, * this make it a little more explicit) */ -public abstract class PaintOperation implements Operation { +public abstract class PaintOperation extends Operation { @Override public void apply(@NonNull RemoteContext context) { diff --git a/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeBuffer.java b/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeBuffer.java index c05079e34505..3a5d68db8a37 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeBuffer.java +++ b/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeBuffer.java @@ -59,7 +59,10 @@ import com.android.internal.widget.remotecompose.core.operations.MatrixSkew; import com.android.internal.widget.remotecompose.core.operations.MatrixTranslate; import com.android.internal.widget.remotecompose.core.operations.NamedVariable; import com.android.internal.widget.remotecompose.core.operations.PaintData; +import com.android.internal.widget.remotecompose.core.operations.PathAppend; +import com.android.internal.widget.remotecompose.core.operations.PathCreate; import com.android.internal.widget.remotecompose.core.operations.PathData; +import com.android.internal.widget.remotecompose.core.operations.PathTween; import com.android.internal.widget.remotecompose.core.operations.RootContentBehavior; import com.android.internal.widget.remotecompose.core.operations.RootContentDescription; import com.android.internal.widget.remotecompose.core.operations.TextData; @@ -644,6 +647,37 @@ public class RemoteComposeBuffer { } /** + * interpolate the two paths to produce a 3rd + * + * @param pid1 the first path + * @param pid2 the second path + * @param tween path is the path1+(pat2-path1)*tween + * @return id of the tweened path + */ + public int pathTween(int pid1, int pid2, float tween) { + int out = mRemoteComposeState.nextId(); + PathTween.apply(mBuffer, out, pid1, pid2, tween); + return out; + } + + /** + * Create a path with an initial moveTo + * + * @param x x coordinate of the moveto + * @param y y coordinate of the moveto + * @return id of the created path + */ + public int pathCreate(float x, float y) { + int out = mRemoteComposeState.nextId(); + PathCreate.apply(mBuffer, out, x, y); + return out; + } + + public void pathAppend(int id, float... path) { + PathAppend.apply(mBuffer, id, path); + } + + /** * Draw the specified path * * @param pathId @@ -1154,6 +1188,16 @@ public class RemoteComposeBuffer { } /** + * Reserve a float and returns a NaN number pointing to that float + * + * @return the nan id of float + */ + public float reserveFloatVariable() { + int id = mRemoteComposeState.cacheFloat(0f); + return Utils.asNan(id); + } + + /** * Add a Integer return an id number pointing to that float. * * @param value adds an integer and assigns it an id @@ -1651,8 +1695,8 @@ public class RemoteComposeBuffer { */ public void addModifierScroll(int direction, float positionId, int notches) { // TODO: add support for non-notch behaviors etc. - float max = this.addFloat(0f); - float notchMax = this.addFloat(0f); + float max = this.reserveFloatVariable(); + float notchMax = this.reserveFloatVariable(); float touchExpressionDirection = direction != 0 ? RemoteContext.FLOAT_TOUCH_POS_X : RemoteContext.FLOAT_TOUCH_POS_Y; this.addTouchExpression( @@ -1807,8 +1851,8 @@ public class RemoteComposeBuffer { ClipRectModifierOperation.apply(mBuffer); } - public void addLoopStart(float count, float from, float step, int indexId) { - LoopOperation.apply(mBuffer, count, from, step, indexId); + public void addLoopStart(int indexId, float from, float step, float until) { + LoopOperation.apply(mBuffer, indexId, from, step, until); } public void addLoopEnd() { diff --git a/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeOperation.java b/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeOperation.java index e60695fc4a06..97487e6d2714 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeOperation.java @@ -15,4 +15,4 @@ */ package com.android.internal.widget.remotecompose.core; -public interface RemoteComposeOperation extends Operation {} +public interface RemoteComposeOperation {} diff --git a/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeState.java b/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeState.java index a903e6ee1f27..f5f9e214723b 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeState.java +++ b/core/java/com/android/internal/widget/remotecompose/core/RemoteComposeState.java @@ -131,6 +131,16 @@ public class RemoteComposeState implements CollectionsAccess { } } + private final IntMap<float[]> mPathData = new IntMap<>(); + + public void putPathData(int id, float[] data) { + mPathData.put(id, data); + } + + public float[] getPathData(int id) { + return mPathData.get(id); + } + /** * Adds a data Override. * diff --git a/core/java/com/android/internal/widget/remotecompose/core/RemoteContext.java b/core/java/com/android/internal/widget/remotecompose/core/RemoteContext.java index 26305bf124f7..6eb8463ab308 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/RemoteContext.java +++ b/core/java/com/android/internal/widget/remotecompose/core/RemoteContext.java @@ -93,12 +93,20 @@ public abstract class RemoteContext { /** * Load a path under an id. Paths can be use in clip drawPath and drawTweenPath * - * @param instanceId - * @param floatPath + * @param instanceId the id to save this path under + * @param floatPath the path as a float array */ public abstract void loadPathData(int instanceId, @NonNull float[] floatPath); /** + * Load a path under an id. Paths can be use in clip drawPath and drawTweenPath + * + * @param instanceId + * @return the a + */ + public abstract @Nullable float[] getPathData(int instanceId); + + /** * Associate a name with a give id. * * @param varName the name diff --git a/core/java/com/android/internal/widget/remotecompose/core/WireBuffer.java b/core/java/com/android/internal/widget/remotecompose/core/WireBuffer.java index a64b706fea3b..2f1502cd59c7 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/WireBuffer.java +++ b/core/java/com/android/internal/widget/remotecompose/core/WireBuffer.java @@ -28,11 +28,17 @@ public class WireBuffer { int mStartingIndex = 0; int mSize = 0; + /** + * Create a wire buffer + * + * @param size the initial size of the buffer + */ public WireBuffer(int size) { mMaxSize = size; mBuffer = new byte[mMaxSize]; } + /** Create a wire buffer of default size */ public WireBuffer() { this(BUFFER_SIZE); } @@ -44,37 +50,74 @@ public class WireBuffer { } } + /** + * get the wire buffer's underlying byte array. Note the array will be bigger that the used + * portion + * + * @return byte array of the wire buffer + */ public @NonNull byte[] getBuffer() { return mBuffer; } + /** + * The current mix size of the buffer + * + * @return max size + */ public int getMax_size() { return mMaxSize; } + /** + * The current point in the buffer which will be written to + * + * @return index pointing into the buffer + */ public int getIndex() { return mIndex; } + /** + * The size of the buffer + * + * @return the size of the buffer + */ public int getSize() { return mSize; } + /** + * Reposition the pointer + * + * @param index the new position of the index + */ public void setIndex(int index) { this.mIndex = index; } + /** + * Write a byte representing the command into the buffer + * + * @param type the command id + */ public void start(int type) { mStartingIndex = mIndex; writeByte(type); } + /** + * Unused Todo remove? + * + * @param type the type of object to write + */ public void startWithSize(int type) { mStartingIndex = mIndex; writeByte(type); mIndex += 4; // skip ahead for the future size } + /** Unused Todo remove? */ public void endWithSize() { int size = mIndex - mStartingIndex; int currentIndex = mIndex; @@ -97,10 +140,20 @@ public class WireBuffer { } } + /** + * return the size of the buffer todo rename to getSize + * + * @return the size of the buffer + */ public int size() { return mSize; } + /** + * Bytes available + * + * @return the size - index + */ public boolean available() { return mSize - mIndex > 0; } @@ -109,28 +162,53 @@ public class WireBuffer { // Read values /////////////////////////////////////////////////////////////////////////// + /** + * read the operation type (reads a single byte) + * + * @return the byte cast to an integer + */ public int readOperationType() { return readByte(); } + /** + * Read a boolean (stored as a byte 1 = true) + * + * @return boolean of the byte + */ public boolean readBoolean() { byte value = mBuffer[mIndex]; mIndex++; return (value == 1); } + /** + * read a single byte byte + * + * @return byte from 0..255 as an Integer + */ public int readByte() { int value = 0xFF & mBuffer[mIndex]; mIndex++; return value; } + /** + * read a short [byte n] << 8 | [byte n+1]; index increast by 2 + * + * @return return a short cast as an integer + */ public int readShort() { int v1 = (mBuffer[mIndex++] & 0xFF) << 8; int v2 = (mBuffer[mIndex++] & 0xFF) << 0; return v1 + v2; } + /** + * Read an integer without incrementing the index + * + * @return the integer + */ public int peekInt() { int tmp = mIndex; int v1 = (mBuffer[tmp++] & 0xFF) << 24; @@ -140,6 +218,11 @@ public class WireBuffer { return v1 + v2 + v3 + v4; } + /** + * Read an integer. index increased by 4 + * + * @return integer + */ public int readInt() { int v1 = (mBuffer[mIndex++] & 0xFF) << 24; int v2 = (mBuffer[mIndex++] & 0xFF) << 16; @@ -148,6 +231,11 @@ public class WireBuffer { return v1 + v2 + v3 + v4; } + /** + * Read a long index is increased by 8 + * + * @return long + */ public long readLong() { long v1 = (mBuffer[mIndex++] & 0xFFL) << 56; long v2 = (mBuffer[mIndex++] & 0xFFL) << 48; @@ -160,14 +248,30 @@ public class WireBuffer { return v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8; } + /** + * Read a 32 bit float IEEE standard index is increased by 4 + * + * @return the float + */ public float readFloat() { return java.lang.Float.intBitsToFloat(readInt()); } + /** + * Read a 64 bit double index is increased by 8 + * + * @return double + */ public double readDouble() { return java.lang.Double.longBitsToDouble(readLong()); } + /** + * Read a byte buffer bytes are encoded as 4 byte length followed by length bytes index is + * increased by 4 + number of bytes + * + * @return byte array + */ public @NonNull byte[] readBuffer() { int count = readInt(); byte[] b = Arrays.copyOfRange(mBuffer, mIndex, mIndex + count); @@ -175,6 +279,13 @@ public class WireBuffer { return b; } + /** + * Read a byte buffer limited to max size. bytes are encoded as 4 byte length followed by length + * bytes index is increased by 4 + number of bytes Throw an exception if the read excedes the + * max size. This is the preferred form of read buffer. + * + * @return byte array + */ public @NonNull byte[] readBuffer(int maxSize) { int count = readInt(); if (count < 0 || count > maxSize) { @@ -186,12 +297,23 @@ public class WireBuffer { return b; } + /** + * Read a string encoded in UTF8 The buffer is red with readBuffer and converted to a String + * + * @return unicode string + */ @NonNull public String readUTF8() { byte[] stringBuffer = readBuffer(); return new String(stringBuffer); } + /** + * Read a string encoded in UTF8 The buffer is red with readBuffer and converted to a String + * This is the preferred readUTF8 because it catches errors + * + * @return unicode string + */ @NonNull public String readUTF8(int maxSize) { byte[] stringBuffer = readBuffer(maxSize); @@ -202,18 +324,33 @@ public class WireBuffer { // Write values /////////////////////////////////////////////////////////////////////////// + /** + * Write a boolean value. (written as a byte 1=true) + * + * @param value value to write + */ public void writeBoolean(boolean value) { resize(1); mBuffer[mIndex++] = (byte) (value ? 1 : 0); mSize++; } + /** + * Write a byte value + * + * @param value value to write + */ public void writeByte(int value) { resize(1); mBuffer[mIndex++] = (byte) value; mSize++; } + /** + * Write a short value + * + * @param value value to write + */ public void writeShort(int value) { int need = 2; resize(need); @@ -222,6 +359,11 @@ public class WireBuffer { mSize += need; } + /** + * Write a int (4 byte) value + * + * @param value value to write + */ public void writeInt(int value) { int need = 4; resize(need); @@ -232,6 +374,11 @@ public class WireBuffer { mSize += need; } + /** + * Write a long (8 byte) value + * + * @param value value to write + */ public void writeLong(long value) { int need = 8; resize(need); @@ -246,14 +393,29 @@ public class WireBuffer { mSize += need; } + /** + * Write a 32 bit IEEE float value + * + * @param value value to write + */ public void writeFloat(float value) { writeInt(Float.floatToRawIntBits(value)); } + /** + * Write a 64 bit IEEE double value + * + * @param value value to write + */ public void writeDouble(double value) { writeLong(Double.doubleToRawLongBits(value)); } + /** + * Write a buffer The buffer length is first written followed by the bytes + * + * @param b array of bytes write + */ public void writeBuffer(@NonNull byte[] b) { resize(b.length + 4); writeInt(b.length); @@ -263,6 +425,11 @@ public class WireBuffer { mSize += b.length; } + /** + * Write a string is encoded as UTF8 + * + * @param content the string to write + */ public void writeUTF8(@NonNull String content) { byte[] buffer = content.getBytes(); writeBuffer(buffer); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/BitmapData.java b/core/java/com/android/internal/widget/remotecompose/core/operations/BitmapData.java index 948007699b80..27ba6528a703 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/BitmapData.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/BitmapData.java @@ -36,7 +36,7 @@ import java.util.List; * Operation to deal with bitmap data On getting an Image during a draw call the bitmap is * compressed and saved in playback the image is decompressed */ -public class BitmapData implements Operation, SerializableToString { +public class BitmapData extends Operation implements SerializableToString { private static final int OP_CODE = Operations.DATA_BITMAP; private static final String CLASS_NAME = "BitmapData"; int mImageId; @@ -85,6 +85,11 @@ public class BitmapData implements Operation, SerializableToString { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -119,6 +124,12 @@ public class BitmapData implements Operation, SerializableToString { buffer.writeBuffer(bitmap); } + /** + * 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 imageId = buffer.readInt(); int width = buffer.readInt(); @@ -133,6 +144,11 @@ public class BitmapData implements Operation, SerializableToString { operations.add(new BitmapData(imageId, width, height, bitmap)); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("Bitmap data") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/ClickArea.java b/core/java/com/android/internal/widget/remotecompose/core/operations/ClickArea.java index 310b194ec486..5e5e5653053f 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/ClickArea.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/ClickArea.java @@ -28,7 +28,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Add a click area to the document */ -public class ClickArea implements RemoteComposeOperation { +public class ClickArea extends Operation implements RemoteComposeOperation { private static final int OP_CODE = Operations.CLICK_AREA; private static final String CLASS_NAME = "ClickArea"; int mId; @@ -118,6 +118,11 @@ public class ClickArea implements RemoteComposeOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -141,6 +146,12 @@ public class ClickArea implements RemoteComposeOperation { buffer.writeInt(metadata); } + /** + * 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 id = buffer.readInt(); int contentDescription = buffer.readInt(); @@ -154,6 +165,11 @@ public class ClickArea implements RemoteComposeOperation { operations.add(clickArea); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Define a region you can click on") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/ClipPath.java b/core/java/com/android/internal/widget/remotecompose/core/operations/ClipPath.java index db93829586bb..2fe56d3ec935 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/ClipPath.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/ClipPath.java @@ -69,6 +69,12 @@ public class ClipPath extends PaintOperation { return "ClipPath " + mId + ";"; } + /** + * 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 pack = buffer.readInt(); int id = pack & 0xFFFFF; @@ -82,6 +88,11 @@ public class ClipPath extends PaintOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -91,6 +102,11 @@ public class ClipPath extends PaintOperation { buffer.writeInt(id); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Intersect the current clip with the path") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/ClipRect.java b/core/java/com/android/internal/widget/remotecompose/core/operations/ClipRect.java index df54fb1ed834..defa656b44e6 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/ClipRect.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/ClipRect.java @@ -31,11 +31,22 @@ public class ClipRect extends DrawBase4 { public static final int OP_CODE = Operations.CLIP_RECT; public static final String CLASS_NAME = "ClipRect"; + /** + * 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) { Maker m = ClipRect::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -50,6 +61,11 @@ public class ClipRect extends DrawBase4 { apply(buffer, v1, v2, v3, v4); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("Intersect the current clip with rectangle") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/ColorConstant.java b/core/java/com/android/internal/widget/remotecompose/core/operations/ColorConstant.java index 34e93f590dbe..d86576dd99f2 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/ColorConstant.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/ColorConstant.java @@ -29,12 +29,22 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Operation that defines a simple Color based on ID Mainly for colors in theming. */ -public class ColorConstant implements Operation { +public class ColorConstant extends Operation { private static final int OP_CODE = Operations.COLOR_CONSTANT; private static final String CLASS_NAME = "ColorConstant"; + + /** the id of the color */ public int mColorId; + + /** the color value (AARRGGBB) */ public int mColor; + /** + * Creat a color constant + * + * @param colorId id of color + * @param color AARRGGBB value + */ public ColorConstant(int colorId, int color) { this.mColorId = colorId; this.mColor = color; @@ -56,6 +66,11 @@ public class ColorConstant implements Operation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -73,12 +88,23 @@ public class ColorConstant implements Operation { buffer.writeInt(color); } + /** + * 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 colorId = buffer.readInt(); int color = buffer.readInt(); operations.add(new ColorConstant(colorId, color)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("Define a Color") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/ColorExpression.java b/core/java/com/android/internal/widget/remotecompose/core/operations/ColorExpression.java index c947d1139a2e..66f128f8f478 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/ColorExpression.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/ColorExpression.java @@ -34,7 +34,7 @@ import java.util.List; * Operation to Colors Color modes mMode = 0 two colors and a tween mMode = 1 color1 is a colorID. * mMode = 2 color2 is a colorID. mMode = 3 color1 & color2 are ids mMode = 4 H S V mode */ -public class ColorExpression implements Operation, VariableSupport { +public class ColorExpression extends Operation implements VariableSupport { private static final int OP_CODE = Operations.COLOR_EXPRESSIONS; private static final String CLASS_NAME = "ColorExpression"; public int mId; @@ -204,6 +204,11 @@ public class ColorExpression implements Operation, VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -228,6 +233,12 @@ public class ColorExpression implements Operation, VariableSupport { buffer.writeFloat(tween); } + /** + * 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 id = buffer.readInt(); int mode = buffer.readInt(); @@ -238,6 +249,11 @@ public class ColorExpression implements Operation, VariableSupport { operations.add(new ColorExpression(id, mode, color1, color2, tween)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("A Color defined by an expression") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/ComponentValue.java b/core/java/com/android/internal/widget/remotecompose/core/operations/ComponentValue.java index b0ccd1871fd2..19c219bc0121 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/ComponentValue.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/ComponentValue.java @@ -30,7 +30,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; -public class ComponentValue implements Operation, SerializableToString { +public class ComponentValue extends Operation implements SerializableToString { public static final int OP_CODE = Operations.COMPONENT_VALUE; public static final String CLASS_NAME = "ComponentValue"; @@ -41,6 +41,11 @@ public class ComponentValue implements Operation, SerializableToString { private int mComponentID = -1; private int mValueId = -1; + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -78,6 +83,12 @@ public class ComponentValue implements Operation, SerializableToString { // Nothing } + /** + * 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 type = buffer.readInt(); int componentId = buffer.readInt(); @@ -86,6 +97,11 @@ public class ComponentValue implements Operation, SerializableToString { operations.add(op); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("Encode a component-related value (eg its width, height etc.)") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DataListFloat.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DataListFloat.java index bfaf139da21b..ac6271c6328e 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DataListFloat.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DataListFloat.java @@ -32,7 +32,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Array import java.util.Arrays; import java.util.List; -public class DataListFloat implements VariableSupport, ArrayAccess, Operation { +public class DataListFloat extends Operation implements VariableSupport, ArrayAccess { private static final int OP_CODE = Operations.FLOAT_LIST; private static final String CLASS_NAME = "IdListData"; private final int mId; @@ -79,6 +79,12 @@ public class DataListFloat implements VariableSupport, ArrayAccess, Operation { } } + /** + * 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 id = buffer.readInt(); int len = buffer.readInt(); @@ -93,6 +99,11 @@ public class DataListFloat implements VariableSupport, ArrayAccess, Operation { operations.add(data); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("a list of Floats") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DataListIds.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DataListIds.java index 9b286b94d553..47cbff36d492 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DataListIds.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DataListIds.java @@ -33,7 +33,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Array import java.util.Arrays; import java.util.List; -public class DataListIds implements VariableSupport, ArrayAccess, Operation { +public class DataListIds extends Operation implements VariableSupport, ArrayAccess { private static final int OP_CODE = Operations.ID_LIST; private static final String CLASS_NAME = "IdListData"; private final int mId; @@ -71,6 +71,12 @@ public class DataListIds implements VariableSupport, ArrayAccess, Operation { } } + /** + * 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 id = buffer.readInt(); int len = buffer.readInt(); @@ -85,6 +91,11 @@ public class DataListIds implements VariableSupport, ArrayAccess, Operation { operations.add(data); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("a list of id's") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DataMapIds.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DataMapIds.java index 643afc85e69f..e888074cda74 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DataMapIds.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DataMapIds.java @@ -31,7 +31,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.DataM import java.util.List; /** This is a map of strings to type & Id */ -public class DataMapIds implements Operation { +public class DataMapIds extends Operation { private static final int OP_CODE = Operations.ID_MAP; private static final String CLASS_NAME = "DataMapIds"; int mId; @@ -105,6 +105,12 @@ public class DataMapIds implements Operation { } } + /** + * 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 id = buffer.readInt(); int len = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DataMapLookup.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DataMapLookup.java index eae532c14344..9af2343a5fa4 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DataMapLookup.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DataMapLookup.java @@ -31,7 +31,7 @@ import com.android.internal.widget.remotecompose.core.types.LongConstant; import java.util.List; /** This can lookup in a map given a string writing the results to an id. */ -public class DataMapLookup implements Operation { +public class DataMapLookup extends Operation { private static final int OP_CODE = Operations.DATA_MAP_LOOKUP; private static final String CLASS_NAME = "DataMapLookup"; public int mId; @@ -109,12 +109,17 @@ public class DataMapLookup implements Operation { operations.add(new DataMapLookup(id, mapId, stringId)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) - .description("A float and its associated id") + .description("Look up a value in a data map") .field(INT, "id", "id of float") .field(INT, "dataMapId", "32-bit float value") - .field(INT, "value", "32-bit float value"); + .field(INT, "stringId", "32-bit float value"); } @Override diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawArc.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawArc.java index 629f78647079..3f95f02747f9 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawArc.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawArc.java @@ -30,11 +30,22 @@ public class DrawArc extends DrawBase6 { public static final int OP_CODE = Operations.DRAW_ARC; private static final String CLASS_NAME = "DrawArc"; + /** + * 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) { Maker m = DrawArc::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -79,6 +90,11 @@ public class DrawArc extends DrawBase6 { apply(buffer, v1, v2, v3, v4, v5, v6); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description( diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmap.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmap.java index 9c23c9559953..69f5cc52a78a 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmap.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmap.java @@ -100,15 +100,21 @@ public class DrawBitmap extends PaintOperation implements VariableSupport { + ";"; } + /** + * 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 id = buffer.readInt(); float sLeft = buffer.readFloat(); float srcTop = buffer.readFloat(); float srcRight = buffer.readFloat(); float srcBottom = buffer.readFloat(); - int discriptionId = buffer.readInt(); + int descriptionId = buffer.readInt(); - DrawBitmap op = new DrawBitmap(id, sLeft, srcTop, srcRight, srcBottom, discriptionId); + DrawBitmap op = new DrawBitmap(id, sLeft, srcTop, srcRight, srcBottom, descriptionId); operations.add(op); } @@ -117,6 +123,11 @@ public class DrawBitmap extends PaintOperation implements VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -138,6 +149,11 @@ public class DrawBitmap extends PaintOperation implements VariableSupport { buffer.writeInt(descriptionId); } + /** + * 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("Draw Operations", OP_CODE, CLASS_NAME) .description("Draw a bitmap") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmapInt.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmapInt.java index da9fe247bced..66646d7c2faa 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmapInt.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmapInt.java @@ -111,6 +111,11 @@ public class DrawBitmapInt extends PaintOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -140,6 +145,12 @@ public class DrawBitmapInt extends PaintOperation { buffer.writeInt(cdId); } + /** + * 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 imageId = buffer.readInt(); int sLeft = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmapScaled.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmapScaled.java index e9f81d52d67f..170148608ab3 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmapScaled.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawBitmapScaled.java @@ -196,6 +196,11 @@ public class DrawBitmapScaled extends PaintOperation implements VariableSupport return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -232,6 +237,12 @@ public class DrawBitmapScaled extends PaintOperation implements VariableSupport buffer.writeInt(cdId); } + /** + * 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 imageId = buffer.readInt(); @@ -265,6 +276,11 @@ public class DrawBitmapScaled extends PaintOperation implements VariableSupport operations.add(op); } + /** + * 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("Draw Operations", OP_CODE, CLASS_NAME) .description("Draw a bitmap using integer coordinates") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawCircle.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawCircle.java index 11bd49a4a651..e6aecdbf8bbe 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawCircle.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawCircle.java @@ -30,11 +30,22 @@ public class DrawCircle extends DrawBase3 { private static final int OP_CODE = Operations.DRAW_CIRCLE; private static final String CLASS_NAME = "DrawCircle"; + /** + * 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) { Maker m = DrawCircle::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -44,6 +55,11 @@ public class DrawCircle extends DrawBase3 { return CLASS_NAME; } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Draw a Circle") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawLine.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawLine.java index 7310a9defba6..04f32642d5fa 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawLine.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawLine.java @@ -32,11 +32,22 @@ public class DrawLine extends DrawBase4 implements SerializableToString { private static final int OP_CODE = Operations.DRAW_LINE; private static final String CLASS_NAME = "DrawLine"; + /** + * 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) { Maker m = DrawLine::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -46,6 +57,11 @@ public class DrawLine extends DrawBase4 implements SerializableToString { return CLASS_NAME; } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Draw a line segment") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawOval.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawOval.java index aa5116e950c5..0a50042b11c7 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawOval.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawOval.java @@ -30,11 +30,22 @@ public class DrawOval extends DrawBase4 { private static final int OP_CODE = Operations.DRAW_OVAL; private static final String CLASS_NAME = "DrawOval"; + /** + * 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) { Maker m = DrawOval::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -44,6 +55,11 @@ public class DrawOval extends DrawBase4 { return CLASS_NAME; } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Draw the specified oval") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawPath.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawPath.java index d35094b0b351..41b8243f070f 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawPath.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawPath.java @@ -50,6 +50,12 @@ public class DrawPath extends PaintOperation { return "DrawPath " + "[" + mId + "]" + ", " + mStart + ", " + mEnd; } + /** + * 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 id = buffer.readInt(); DrawPath op = new DrawPath(id); @@ -61,6 +67,11 @@ public class DrawPath extends PaintOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.DRAW_PATH; } @@ -70,6 +81,11 @@ public class DrawPath extends PaintOperation { buffer.writeInt(id); } + /** + * 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("Draw Operations", OP_CODE, CLASS_NAME) .description("Draw a bitmap using integer coordinates") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawRect.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawRect.java index db7633cbe335..7e22550d6544 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawRect.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawRect.java @@ -31,11 +31,22 @@ public class DrawRect extends DrawBase4 { private static final int OP_CODE = Operations.DRAW_RECT; private static final String CLASS_NAME = "DrawRect"; + /** + * 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) { Maker m = DrawRect::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -45,6 +56,11 @@ public class DrawRect extends DrawBase4 { return CLASS_NAME; } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Draw the specified rectangle") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawRoundRect.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawRoundRect.java index c306e2b5f041..a41e46e03506 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawRoundRect.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawRoundRect.java @@ -31,11 +31,22 @@ public class DrawRoundRect extends DrawBase6 { private static final int OP_CODE = Operations.DRAW_ROUND_RECT; private static final String CLASS_NAME = "DrawRoundRect"; + /** + * 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) { Maker m = DrawRoundRect::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -80,6 +91,11 @@ public class DrawRoundRect extends DrawBase6 { apply(buffer, v1, v2, v3, v4, v5, v6); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Draw the specified round-rect") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawSector.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawSector.java index 3b60df7d529e..7616df09b6cc 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawSector.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawSector.java @@ -30,11 +30,22 @@ public class DrawSector extends DrawBase6 { public static final int OP_CODE = Operations.DRAW_SECTOR; private static final String CLASS_NAME = "DrawSector"; + /** + * 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) { Maker m = DrawSector::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -79,6 +90,11 @@ public class DrawSector extends DrawBase6 { apply(buffer, v1, v2, v3, v4, v5, v6); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description( diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawText.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawText.java index 9c587aba3f7b..2c5d790b2f2a 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawText.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawText.java @@ -101,6 +101,12 @@ public class DrawText extends PaintOperation implements VariableSupport { + floatToString(mY, mOutY); } + /** + * 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(); int start = buffer.readInt(); @@ -120,6 +126,11 @@ public class DrawText extends PaintOperation implements VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -158,6 +169,11 @@ public class DrawText extends PaintOperation implements VariableSupport { buffer.writeBoolean(rtl); } + /** + * 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("Draw Operations", id(), CLASS_NAME) .description("Draw a run of text, all in a single direction") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTextAnchored.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTextAnchored.java index 8b7018191f4d..7de52b8e5f3e 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTextAnchored.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTextAnchored.java @@ -111,6 +111,12 @@ public class DrawTextAnchored extends PaintOperation implements VariableSupport return Float.toString(v); } + /** + * 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 textID = buffer.readInt(); float x = buffer.readFloat(); @@ -129,6 +135,11 @@ public class DrawTextAnchored extends PaintOperation implements VariableSupport return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -161,6 +172,11 @@ public class DrawTextAnchored extends PaintOperation implements VariableSupport 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("Draw Operations", OP_CODE, CLASS_NAME) .description("Draw text centered about an anchor point") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTextOnPath.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTextOnPath.java index e90122bb95ac..18d9fdf1b671 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTextOnPath.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTextOnPath.java @@ -83,6 +83,12 @@ public class DrawTextOnPath extends PaintOperation implements VariableSupport { + Utils.floatToString(mVOffset, mOutVOffset); } + /** + * 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 textId = buffer.readInt(); int pathId = buffer.readInt(); @@ -97,6 +103,11 @@ public class DrawTextOnPath extends PaintOperation implements VariableSupport { return "DrawTextOnPath"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.DRAW_TEXT_ON_PATH; } @@ -110,6 +121,11 @@ public class DrawTextOnPath extends PaintOperation implements VariableSupport { buffer.writeFloat(hOffset); } + /** + * 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("Draw Operations", OP_CODE, CLASS_NAME) .description("Draw text along path object") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTweenPath.java b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTweenPath.java index 0aaaf42ba838..b83e4c2191b2 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTweenPath.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/DrawTweenPath.java @@ -92,6 +92,12 @@ public class DrawTweenPath extends PaintOperation implements VariableSupport { + floatToString(mStop, mOutStop); } + /** + * 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 path1Id = buffer.readInt(); int path2Id = buffer.readInt(); @@ -107,6 +113,11 @@ public class DrawTweenPath extends PaintOperation implements VariableSupport { return "DrawTweenPath"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.DRAW_TWEEN_PATH; } @@ -126,6 +137,11 @@ public class DrawTweenPath extends PaintOperation implements VariableSupport { buffer.writeFloat(stop); } + /** + * 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("Draw Operations", OP_CODE, CLASS_NAME) .description("Draw text along path object") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/FloatConstant.java b/core/java/com/android/internal/widget/remotecompose/core/operations/FloatConstant.java index 17aaf3bb9cd8..7dd435a5c5b1 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/FloatConstant.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/FloatConstant.java @@ -29,7 +29,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Operation to deal with Text data */ -public class FloatConstant implements com.android.internal.widget.remotecompose.core.Operation { +public class FloatConstant extends Operation { private static final int OP_CODE = Operations.DATA_FLOAT; private static final String CLASS_NAME = "FloatConstant"; public int mTextId; @@ -56,6 +56,11 @@ public class FloatConstant implements com.android.internal.widget.remotecompose. return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -73,6 +78,12 @@ public class FloatConstant implements com.android.internal.widget.remotecompose. buffer.writeFloat(value); } + /** + * 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 textId = buffer.readInt(); @@ -80,6 +91,11 @@ public class FloatConstant implements com.android.internal.widget.remotecompose. operations.add(new FloatConstant(textId, value)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("A float and its associated id") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/FloatExpression.java b/core/java/com/android/internal/widget/remotecompose/core/operations/FloatExpression.java index eef9746ffaf6..3d92e129a236 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/FloatExpression.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/FloatExpression.java @@ -42,7 +42,7 @@ import java.util.List; * like injecting the width of the component int draw rect As well as supporting generalized * animation floats. The floats represent a RPN style calculator */ -public class FloatExpression implements Operation, VariableSupport { +public class FloatExpression extends Operation implements VariableSupport { private static final int OP_CODE = Operations.ANIMATED_FLOAT; private static final String CLASS_NAME = "FloatExpression"; public int mId; @@ -146,16 +146,19 @@ public class FloatExpression implements Operation, VariableSupport { if (Float.isNaN(mLastChange)) { mLastChange = t; } - if (mFloatAnimation != null) { + if (mFloatAnimation != null && !Float.isNaN(mLastCalculatedValue)) { float f = mFloatAnimation.get(t - mLastChange); context.loadFloat(mId, f); } else if (mSpring != null) { float f = mSpring.get(t - mLastChange); context.loadFloat(mId, f); } else { - context.loadFloat( - mId, - mExp.eval(context.getCollectionsAccess(), mPreCalcValue, mPreCalcValue.length)); + float v = + mExp.eval(context.getCollectionsAccess(), mPreCalcValue, mPreCalcValue.length); + if (mFloatAnimation != null) { + mFloatAnimation.setTargetValue(v); + } + context.loadFloat(mId, v); } } @@ -207,6 +210,11 @@ public class FloatExpression implements Operation, VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -243,12 +251,18 @@ public class FloatExpression implements Operation, VariableSupport { } } + /** + * 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 id = buffer.readInt(); int len = buffer.readInt(); int valueLen = len & 0xFFFF; if (valueLen > MAX_EXPRESSION_SIZE) { - throw new RuntimeException("Float expression to long"); + throw new RuntimeException("Float expression too long"); } int animLen = (len >> 16) & 0xFFFF; float[] values = new float[valueLen]; @@ -268,6 +282,11 @@ public class FloatExpression implements Operation, VariableSupport { operations.add(new FloatExpression(id, values, animation)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("A Float expression") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/Header.java b/core/java/com/android/internal/widget/remotecompose/core/operations/Header.java index 009aa0339625..04e4346cf05d 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/Header.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/Header.java @@ -35,7 +35,7 @@ import java.util.List; * <p>It encodes the version of the document (following semantic versioning) as well as the * dimensions of the document in pixels. */ -public class Header implements RemoteComposeOperation { +public class Header extends Operation implements RemoteComposeOperation { private static final int OP_CODE = Operations.HEADER; private static final String CLASS_NAME = "Header"; public static final int MAJOR_VERSION = 0; @@ -120,6 +120,11 @@ public class Header implements RemoteComposeOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -136,6 +141,12 @@ public class Header implements RemoteComposeOperation { buffer.writeLong(capabilities); } + /** + * 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 majorVersion = buffer.readInt(); int minorVersion = buffer.readInt(); @@ -157,6 +168,11 @@ public class Header implements RemoteComposeOperation { operations.add(header); } + /** + * 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("Protocol Operations", OP_CODE, CLASS_NAME) .description( diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/IntegerExpression.java b/core/java/com/android/internal/widget/remotecompose/core/operations/IntegerExpression.java index c49f74de7893..67274af7c283 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/IntegerExpression.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/IntegerExpression.java @@ -38,7 +38,7 @@ import java.util.List; * like injecting the width of the component int draw rect As well as supporting generalized * animation floats. The floats represent a RPN style calculator */ -public class IntegerExpression implements Operation, VariableSupport { +public class IntegerExpression extends Operation implements VariableSupport { private static final int OP_CODE = Operations.INTEGER_EXPRESSION; private static final String CLASS_NAME = "IntegerExpression"; public int mId; @@ -141,6 +141,11 @@ public class IntegerExpression implements Operation, VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -163,6 +168,12 @@ public class IntegerExpression implements Operation, VariableSupport { } } + /** + * 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 id = buffer.readInt(); int mask = buffer.readInt(); @@ -178,6 +189,11 @@ public class IntegerExpression implements Operation, VariableSupport { operations.add(new IntegerExpression(id, mask, values)); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("Expression that computes an integer") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixRestore.java b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixRestore.java index 4e7ee4d135ee..aed597ae7494 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixRestore.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixRestore.java @@ -37,6 +37,12 @@ public class MatrixRestore extends PaintOperation { apply(buffer); } + /** + * 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) { MatrixRestore op = new MatrixRestore(); operations.add(op); @@ -53,6 +59,11 @@ public class MatrixRestore extends PaintOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -61,6 +72,11 @@ public class MatrixRestore extends PaintOperation { buffer.start(OP_CODE); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Restore the matrix and clip"); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixRotate.java b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixRotate.java index 438a2aad648a..fece143ebfa1 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixRotate.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixRotate.java @@ -30,6 +30,12 @@ public class MatrixRotate extends DrawBase3 { public static final int OP_CODE = Operations.MATRIX_ROTATE; private static final String CLASS_NAME = "MatrixRotate"; + /** + * 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) { Maker m = new Maker() { @@ -42,6 +48,11 @@ public class MatrixRotate extends DrawBase3 { read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -51,6 +62,11 @@ public class MatrixRotate extends DrawBase3 { return CLASS_NAME; } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("apply rotation to matrix") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixSave.java b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixSave.java index 09f54a52e6a3..7eb7b3ffaf34 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixSave.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixSave.java @@ -41,6 +41,12 @@ public class MatrixSave extends PaintOperation { return "MatrixSave;"; } + /** + * 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) { MatrixSave op = new MatrixSave(); operations.add(op); @@ -51,6 +57,11 @@ public class MatrixSave extends PaintOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -59,6 +70,11 @@ public class MatrixSave extends PaintOperation { buffer.start(Operations.MATRIX_SAVE); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Save the matrix and clip to a stack"); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixScale.java b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixScale.java index 630458499977..49bdd1b06eed 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixScale.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixScale.java @@ -30,11 +30,22 @@ public class MatrixScale extends DrawBase4 { public static final int OP_CODE = Operations.MATRIX_SCALE; public static final String CLASS_NAME = "MatrixScale"; + /** + * 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) { Maker m = MatrixScale::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -49,9 +60,14 @@ public class MatrixScale extends DrawBase4 { apply(buffer, v1, v2, v3, v4); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) - .description("Draw the specified Oval") + .description("Scale the following draw commands") .field(DocumentedOperation.FLOAT, "scaleX", "The amount to scale in X") .field(DocumentedOperation.FLOAT, "scaleY", "The amount to scale in Y") .field(DocumentedOperation.FLOAT, "pivotX", "The x-coordinate for the pivot point") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixSkew.java b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixSkew.java index 675cf0de4743..54b6fd1fa9ae 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixSkew.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixSkew.java @@ -31,11 +31,22 @@ public class MatrixSkew extends DrawBase2 { public static final int OP_CODE = Operations.MATRIX_SKEW; public static final String CLASS_NAME = "MatrixSkew"; + /** + * 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) { Maker m = MatrixSkew::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -50,6 +61,11 @@ public class MatrixSkew extends DrawBase2 { apply(buffer, v1, v2); } + /** + * 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("Canvas Operations", OP_CODE, CLASS_NAME) .description("Current matrix with the specified skew.") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixTranslate.java b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixTranslate.java index b0a7d352dfe3..b57d83b770b2 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixTranslate.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/MatrixTranslate.java @@ -30,11 +30,22 @@ public class MatrixTranslate extends DrawBase2 { public static final int OP_CODE = Operations.MATRIX_TRANSLATE; public static final String CLASS_NAME = "MatrixTranslate"; + /** + * 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) { Maker m = MatrixTranslate::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -49,6 +60,11 @@ public class MatrixTranslate extends DrawBase2 { apply(buffer, v1, v2); } + /** + * 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("Canvas Operations", OP_CODE, "MatrixTranslate") .description("Preconcat the current matrix with the specified translation") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/NamedVariable.java b/core/java/com/android/internal/widget/remotecompose/core/operations/NamedVariable.java index 5ca91af91f86..3c82f2b27ca6 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/NamedVariable.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/NamedVariable.java @@ -30,7 +30,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Operation to deal with Text data */ -public class NamedVariable implements Operation { +public class NamedVariable extends Operation { private static final int OP_CODE = Operations.NAMED_VARIABLE; private static final String CLASS_NAME = "NamedVariable"; public final int mVarId; @@ -69,6 +69,11 @@ public class NamedVariable implements Operation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -89,6 +94,12 @@ public class NamedVariable implements Operation { buffer.writeUTF8(text); } + /** + * 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 varId = buffer.readInt(); int varType = buffer.readInt(); @@ -96,6 +107,11 @@ public class NamedVariable implements Operation { operations.add(new NamedVariable(varId, varType, text)); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("Add a string name for an ID") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/PaintData.java b/core/java/com/android/internal/widget/remotecompose/core/operations/PaintData.java index b24df8a6a91e..3c0a842371c7 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/PaintData.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/PaintData.java @@ -66,6 +66,11 @@ public class PaintData extends PaintOperation implements VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -75,6 +80,12 @@ public class PaintData extends PaintOperation implements VariableSupport { paintBundle.writeBundle(buffer); } + /** + * 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) { PaintData data = new PaintData(); data.mPaintData.readBundle(buffer); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/PathAppend.java b/core/java/com/android/internal/widget/remotecompose/core/operations/PathAppend.java new file mode 100644 index 000000000000..2b00001a521e --- /dev/null +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/PathAppend.java @@ -0,0 +1,230 @@ +/* + * 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 static com.android.internal.widget.remotecompose.core.documentation.DocumentedOperation.FLOAT_ARRAY; +import static com.android.internal.widget.remotecompose.core.documentation.DocumentedOperation.INT; + +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.documentation.DocumentedOperation; + +import java.util.Arrays; +import java.util.List; + +public class PathAppend extends PaintOperation implements VariableSupport { + private static final int OP_CODE = Operations.PATH_ADD; + private static final String CLASS_NAME = "PathAppend"; + int mInstanceId; + float[] mFloatPath; + float[] mOutputPath; + + PathAppend(int instanceId, float[] floatPath) { + mInstanceId = instanceId; + mFloatPath = floatPath; + mOutputPath = Arrays.copyOf(mFloatPath, mFloatPath.length); + } + + @Override + public void updateVariables(@NonNull RemoteContext context) { + for (int i = 0; i < mFloatPath.length; i++) { + float v = mFloatPath[i]; + if (Utils.isVariable(v)) { + mOutputPath[i] = Float.isNaN(v) ? context.getFloat(Utils.idFromNan(v)) : v; + } else { + mOutputPath[i] = v; + } + } + } + + @Override + public void registerListening(@NonNull RemoteContext context) { + for (float v : mFloatPath) { + if (Float.isNaN(v)) { + context.listensTo(Utils.idFromNan(v), this); + } + } + } + + @Override + public void write(@NonNull WireBuffer buffer) { + apply(buffer, mInstanceId, mOutputPath); + } + + @NonNull + @Override + public String deepToString(String indent) { + return PathData.pathString(mFloatPath); + } + + @NonNull + @Override + public String toString() { + return "PathAppend[" + mInstanceId + "] += " + "\"" + pathString(mOutputPath) + "\""; + } + + /** + * public float[] getFloatPath(PaintContext context) { float[] ret = mRetFloats; // Assume + * retFloats is declared elsewhere if (ret == null) { return mFloatPath; // Assume floatPath is + * declared elsewhere } float[] localRef = mRef; // Assume ref is of type Float[] if (localRef + * == null) { for (int i = 0; i < mFloatPath.length; i++) { ret[i] = mFloatPath[i]; } } else { + * for (int i = 0; i < mFloatPath.length; i++) { float lr = localRef[i]; if (Float.isNaN(lr)) { + * ret[i] = Utils.getActualValue(lr); } else { ret[i] = mFloatPath[i]; } } } return ret; } + */ + public static final int MOVE = 10; + + public static final int LINE = 11; + public static final int QUADRATIC = 12; + public static final int CONIC = 13; + public static final int CUBIC = 14; + public static final int CLOSE = 15; + public static final int DONE = 16; + public static final float MOVE_NAN = Utils.asNan(MOVE); + public static final float LINE_NAN = Utils.asNan(LINE); + public static final float QUADRATIC_NAN = Utils.asNan(QUADRATIC); + public static final float CONIC_NAN = Utils.asNan(CONIC); + public static final float CUBIC_NAN = Utils.asNan(CUBIC); + public static final float CLOSE_NAN = Utils.asNan(CLOSE); + public static final float DONE_NAN = Utils.asNan(DONE); + + @NonNull + public static String name() { + return CLASS_NAME; + } + + /** + * The OP_CODE for this command + * + * @return the opcode + */ + public static int id() { + return OP_CODE; + } + + public static void apply(@NonNull WireBuffer buffer, int id, @NonNull float[] data) { + buffer.start(OP_CODE); + buffer.writeInt(id); + buffer.writeInt(data.length); + for (float datum : data) { + buffer.writeFloat(datum); + } + } + + /** + * 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 id = buffer.readInt(); + int len = buffer.readInt(); + float[] data = new float[len]; + for (int i = 0; i < data.length; i++) { + data[i] = buffer.readFloat(); + } + operations.add(new PathAppend(id, data)); + } + + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) + .description("Append to a Path") + .field(DocumentedOperation.INT, "id", "id string") + .field(INT, "length", "id string") + .field(FLOAT_ARRAY, "pathData", "length", "path encoded as floats"); + } + + @Override + public void paint(PaintContext context) {} + + @Override + public void apply(@NonNull RemoteContext context) { + updateVariables(context); + float[] data = context.getPathData(mInstanceId); + float[] out = mOutputPath; + if (data != null) { + out = new float[data.length + mOutputPath.length]; + + for (int i = 0; i < data.length; i++) { + out[i] = data[i]; + } + for (int i = 0; i < mOutputPath.length; i++) { + out[i + data.length] = mOutputPath[i]; + } + } else { + System.out.println(">>>>>>>>>>> DATA IS NULL"); + } + context.loadPathData(mInstanceId, out); + } + + @NonNull + public static String pathString(@Nullable float[] path) { + if (path == null) { + return "null"; + } + StringBuilder str = new StringBuilder(); + for (int i = 0; i < path.length; i++) { + if (Float.isNaN(path[i])) { + int id = Utils.idFromNan(path[i]); // Assume idFromNan is defined elsewhere + if (id <= DONE) { // Assume DONE is a constant + switch (id) { + case MOVE: + str.append("M"); + break; + case LINE: + str.append("L"); + break; + case QUADRATIC: + str.append("Q"); + break; + case CONIC: + str.append("R"); + break; + case CUBIC: + str.append("C"); + break; + case CLOSE: + str.append("Z"); + break; + case DONE: + str.append("."); + break; + default: + str.append("[" + id + "]"); + break; + } + } else { + str.append("(" + id + ")"); + } + } + } + return str.toString(); + } +} diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/PathCreate.java b/core/java/com/android/internal/widget/remotecompose/core/operations/PathCreate.java new file mode 100644 index 000000000000..b62f36b8db5f --- /dev/null +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/PathCreate.java @@ -0,0 +1,206 @@ +/* + * 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 static com.android.internal.widget.remotecompose.core.documentation.DocumentedOperation.FLOAT; + +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.documentation.DocumentedOperation; + +import java.util.Arrays; +import java.util.List; + +public class PathCreate extends PaintOperation implements VariableSupport { + private static final int OP_CODE = Operations.PATH_CREATE; + private static final String CLASS_NAME = "PathCreate"; + int mInstanceId; + float[] mFloatPath; + float[] mOutputPath; + + PathCreate(int instanceId, float startX, float startY) { + mInstanceId = instanceId; + mFloatPath = new float[] {PathData.MOVE_NAN, startX, startY}; + mOutputPath = Arrays.copyOf(mFloatPath, mFloatPath.length); + } + + @Override + public void updateVariables(@NonNull RemoteContext context) { + for (int i = 0; i < mFloatPath.length; i++) { + float v = mFloatPath[i]; + if (Utils.isVariable(v)) { + mOutputPath[i] = Float.isNaN(v) ? context.getFloat(Utils.idFromNan(v)) : v; + } else { + mOutputPath[i] = v; + } + } + } + + @Override + public void registerListening(@NonNull RemoteContext context) { + for (float v : mFloatPath) { + if (Float.isNaN(v)) { + context.listensTo(Utils.idFromNan(v), this); + } + } + } + + @Override + public void write(@NonNull WireBuffer buffer) { + apply(buffer, mInstanceId, mFloatPath[1], mFloatPath[2]); + } + + @NonNull + @Override + public String deepToString(String indent) { + return pathString(mFloatPath); + } + + @NonNull + @Override + public String toString() { + return "PathCreate[" + mInstanceId + "] = " + "\"" + deepToString(" ") + "\""; + } + + public static final int MOVE = 10; + public static final int LINE = 11; + public static final int QUADRATIC = 12; + public static final int CONIC = 13; + public static final int CUBIC = 14; + public static final int CLOSE = 15; + public static final int DONE = 16; + public static final float MOVE_NAN = Utils.asNan(MOVE); + public static final float LINE_NAN = Utils.asNan(LINE); + public static final float QUADRATIC_NAN = Utils.asNan(QUADRATIC); + public static final float CONIC_NAN = Utils.asNan(CONIC); + public static final float CUBIC_NAN = Utils.asNan(CUBIC); + public static final float CLOSE_NAN = Utils.asNan(CLOSE); + public static final float DONE_NAN = Utils.asNan(DONE); + + @NonNull + public static String name() { + return CLASS_NAME; + } + + /** + * The OP_CODE for this command + * + * @return the opcode + */ + public static int id() { + return OP_CODE; + } + + public static void apply(@NonNull WireBuffer buffer, int id, float startX, float startY) { + buffer.start(OP_CODE); + buffer.writeInt(id); + buffer.writeFloat(startX); + buffer.writeFloat(startY); + } + + /** + * 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 id = buffer.readInt(); + float startX = buffer.readFloat(); + float startY = buffer.readFloat(); + operations.add(new PathCreate(id, startX, startY)); + } + + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) + .description("Encode a Path ") + .field(DocumentedOperation.INT, "id", "id of path") + .field(FLOAT, "startX", "initial start x") + .field(FLOAT, "startX", "initial start y"); + } + + @NonNull + public static String pathString(@Nullable float[] path) { + if (path == null) { + return "null"; + } + StringBuilder str = new StringBuilder(); + for (int i = 0; i < path.length; i++) { + if (i != 0) { + str.append(" "); + } + if (Float.isNaN(path[i])) { + int id = Utils.idFromNan(path[i]); // Assume idFromNan is defined elsewhere + if (id <= DONE) { // Assume DONE is a constant + switch (id) { + case MOVE: + str.append("M"); + break; + case LINE: + str.append("L"); + break; + case QUADRATIC: + str.append("Q"); + break; + case CONIC: + str.append("R"); + break; + case CUBIC: + str.append("C"); + break; + case CLOSE: + str.append("Z"); + break; + case DONE: + str.append("."); + break; + default: + str.append("[" + id + "]"); + break; + } + } else { + str.append("(" + id + ")"); + } + } else { + str.append(path[i]); + } + } + return str.toString(); + } + + @Override + public void paint(PaintContext context) {} + + @Override + public void apply(@NonNull RemoteContext context) { + context.loadPathData(mInstanceId, mOutputPath); + } +} diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/PathData.java b/core/java/com/android/internal/widget/remotecompose/core/operations/PathData.java index 509f362c02ed..4ec5436c8689 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/PathData.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/PathData.java @@ -32,7 +32,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.Arrays; import java.util.List; -public class PathData implements Operation, VariableSupport { +public class PathData extends Operation implements VariableSupport { private static final int OP_CODE = Operations.DATA_PATH; private static final String CLASS_NAME = "PathData"; int mInstanceId; @@ -112,6 +112,11 @@ public class PathData implements Operation, VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -125,6 +130,12 @@ public class PathData implements Operation, VariableSupport { } } + /** + * 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 imageId = buffer.readInt(); int len = buffer.readInt(); @@ -135,6 +146,11 @@ public class PathData implements Operation, VariableSupport { operations.add(new PathData(imageId, data)); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("Encode a Path ") @@ -143,6 +159,12 @@ public class PathData implements Operation, VariableSupport { .field(FLOAT_ARRAY, "pathData", "length", "path encoded as floats"); } + /** + * Render a path as a string + * + * @param path path as a array of floats + * @return string describing the path + */ @NonNull public static String pathString(@Nullable float[] path) { if (path == null) { diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/PathTween.java b/core/java/com/android/internal/widget/remotecompose/core/operations/PathTween.java new file mode 100644 index 000000000000..a6fa680f647a --- /dev/null +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/PathTween.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2023 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 static com.android.internal.widget.remotecompose.core.documentation.DocumentedOperation.INT; +import static com.android.internal.widget.remotecompose.core.operations.Utils.floatToString; + +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.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.documentation.DocumentedOperation; + +import java.util.List; + +/** Operation to deal with Path data */ +public class PathTween extends PaintOperation implements VariableSupport { + private static final int OP_CODE = Operations.PATH_TWEEN; + private static final String CLASS_NAME = "PathTween"; + public int mOutId; + public int mPathId1; + public int mPathId2; + public float mTween; + public float mTweenOut; + + public PathTween(int outId, int pathId1, int pathId2, float tween) { + this.mOutId = outId; + this.mPathId1 = pathId1; + this.mPathId2 = pathId2; + this.mTween = tween; + this.mTweenOut = mTween; + } + + @Override + public void updateVariables(@NonNull RemoteContext context) { + mTweenOut = Float.isNaN(mTween) ? context.getFloat(Utils.idFromNan(mTween)) : mTween; + } + + @Override + public void registerListening(@NonNull RemoteContext context) { + if (Float.isNaN(mTween)) { + context.listensTo(Utils.idFromNan(mTween), this); + } + } + + @Override + public void write(@NonNull WireBuffer buffer) { + apply(buffer, mOutId, mPathId1, mPathId2, mTween); + } + + @NonNull + @Override + public String toString() { + return "PathTween[" + + mOutId + + "] = [" + + mPathId1 + + " ] + [ " + + mPathId2 + + "], " + + floatToString(mTween, mTweenOut); + } + + @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 buffer to write to + * @param outId id of the path + * @param pathId1 source path 1 + * @param pathId2 source path 2 + * @param tween interpolate between two paths + */ + public static void apply( + @NonNull WireBuffer buffer, int outId, int pathId1, int pathId2, float tween) { + buffer.start(OP_CODE); + buffer.writeInt(outId); + buffer.writeInt(pathId1); + buffer.writeInt(pathId2); + buffer.writeFloat(tween); + } + + /** + * 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 outId1 = buffer.readInt(); + int pathId1 = buffer.readInt(); + int pathId2 = buffer.readInt(); + float tween = buffer.readFloat(); + + operations.add(new PathTween(outId1, pathId1, pathId2, tween)); + } + + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) + .description("Merge two string into one") + .field(DocumentedOperation.INT, "pathId", "id of the path") + .field(INT, "srcPathId1", "id of the path") + .field(INT, "srcPathId1", "x Shift of the path"); + } + + @NonNull + @Override + public String deepToString(String indent) { + return indent + toString(); + } + + @Override + public void paint(PaintContext context) { + context.tweenPath(mOutId, mPathId1, mPathId2, mTweenOut); + } +} diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/RootContentBehavior.java b/core/java/com/android/internal/widget/remotecompose/core/operations/RootContentBehavior.java index 849412618c2c..aaa717629c2e 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/RootContentBehavior.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/RootContentBehavior.java @@ -33,7 +33,7 @@ import java.util.List; * <p>It encodes the version of the document (following semantic versioning) as well as the * dimensions of the document in pixels. */ -public class RootContentBehavior implements RemoteComposeOperation { +public class RootContentBehavior extends Operation implements RemoteComposeOperation { private static final int OP_CODE = Operations.ROOT_CONTENT_BEHAVIOR; private static final String CLASS_NAME = "RootContentBehavior"; int mScroll = NONE; @@ -205,6 +205,11 @@ public class RootContentBehavior implements RemoteComposeOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -218,6 +223,12 @@ public class RootContentBehavior implements RemoteComposeOperation { buffer.writeInt(mode); } + /** + * 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 scroll = buffer.readInt(); int alignment = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/RootContentDescription.java b/core/java/com/android/internal/widget/remotecompose/core/operations/RootContentDescription.java index 109945f21ec5..e92daa384dc3 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/RootContentDescription.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/RootContentDescription.java @@ -28,7 +28,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Describe a content description for the document */ -public class RootContentDescription implements RemoteComposeOperation { +public class RootContentDescription extends Operation implements RemoteComposeOperation { private static final int OP_CODE = Operations.ROOT_CONTENT_DESCRIPTION; private static final String CLASS_NAME = "RootContentDescription"; int mContentDescription; @@ -69,6 +69,11 @@ public class RootContentDescription implements RemoteComposeOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -78,12 +83,23 @@ public class RootContentDescription implements RemoteComposeOperation { buffer.writeInt(contentDescription); } + /** + * 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 contentDescription = buffer.readInt(); RootContentDescription header = new RootContentDescription(contentDescription); operations.add(header); } + /** + * 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("Protocol Operations", OP_CODE, CLASS_NAME) .description("Content description of root") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/ShaderData.java b/core/java/com/android/internal/widget/remotecompose/core/operations/ShaderData.java index e967ff4f4ff4..e2502feb2bb1 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/ShaderData.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/ShaderData.java @@ -41,7 +41,7 @@ import java.util.List; * Operation to deal with bitmap data On getting an Image during a draw call the bitmap is * compressed and saved in playback the image is decompressed */ -public class ShaderData implements Operation, VariableSupport { +public class ShaderData extends Operation implements VariableSupport { private static final int OP_CODE = Operations.DATA_SHADER; private static final String CLASS_NAME = "ShaderData"; int mShaderTextId; // the actual text of a shader @@ -203,6 +203,11 @@ public class ShaderData implements Operation, VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -266,6 +271,12 @@ public class ShaderData implements Operation, VariableSupport { } } + /** + * 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 shaderID = buffer.readInt(); int shaderTextId = buffer.readInt(); @@ -318,6 +329,11 @@ public class ShaderData implements Operation, VariableSupport { operations.add(new ShaderData(shaderID, shaderTextId, floatMap, intMap, bitmapMap)); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("Shader") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/TextData.java b/core/java/com/android/internal/widget/remotecompose/core/operations/TextData.java index ade008e3bdb4..3f679bf47582 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/TextData.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/TextData.java @@ -31,7 +31,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Operation to deal with Text data */ -public class TextData implements Operation, SerializableToString { +public class TextData extends Operation implements SerializableToString { private static final int OP_CODE = Operations.DATA_TEXT; private static final String CLASS_NAME = "TextData"; public final int mTextId; @@ -59,6 +59,11 @@ public class TextData implements Operation, SerializableToString { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -69,6 +74,12 @@ public class TextData implements Operation, SerializableToString { buffer.writeUTF8(text); } + /** + * 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 textId = buffer.readInt(); @@ -76,6 +87,11 @@ public class TextData implements Operation, SerializableToString { operations.add(new TextData(textId, text)); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("Encode a string ") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/TextFromFloat.java b/core/java/com/android/internal/widget/remotecompose/core/operations/TextFromFloat.java index 865ee81f2725..4d01e0c3cbe4 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/TextFromFloat.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/TextFromFloat.java @@ -36,7 +36,7 @@ import java.util.List; * [command][textID][before,after][flags] before and after define number of digits before and after * the decimal point */ -public class TextFromFloat implements Operation, VariableSupport { +public class TextFromFloat extends Operation implements VariableSupport { private static final int OP_CODE = Operations.TEXT_FROM_FLOAT; private static final String CLASS_NAME = "TextFromFloat"; public int mTextId; @@ -127,6 +127,11 @@ public class TextFromFloat implements Operation, VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -155,6 +160,12 @@ public class TextFromFloat implements Operation, VariableSupport { buffer.writeInt(flags); } + /** + * 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 textId = buffer.readInt(); float value = buffer.readFloat(); @@ -166,6 +177,11 @@ public class TextFromFloat implements Operation, VariableSupport { operations.add(new TextFromFloat(textId, value, pre, post, 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("Draw text along path object") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/TextLength.java b/core/java/com/android/internal/widget/remotecompose/core/operations/TextLength.java index 6ff687b7494e..37ea567f5913 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/TextLength.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/TextLength.java @@ -28,7 +28,7 @@ import com.android.internal.widget.remotecompose.core.documentation.Documentatio import java.util.List; /** Operation to measure the length of the text */ -public class TextLength implements Operation { +public class TextLength extends Operation { private static final int OP_CODE = Operations.TEXT_LENGTH; private static final String CLASS_NAME = "TextLength"; public int mLengthId; @@ -54,6 +54,11 @@ public class TextLength implements Operation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -71,12 +76,23 @@ public class TextLength implements Operation { buffer.writeInt(textId); } + /** + * 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 lengthId = buffer.readInt(); int textId = buffer.readInt(); operations.add(new TextLength(lengthId, textId)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("get the length of the text and store in float table") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/TextLookup.java b/core/java/com/android/internal/widget/remotecompose/core/operations/TextLookup.java index cc812a8e160e..3ec6f019c358 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/TextLookup.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/TextLookup.java @@ -34,7 +34,7 @@ import java.util.List; * [command][textID][before,after][flags] before and after define number of digits before and after * the decimal point */ -public class TextLookup implements Operation, VariableSupport { +public class TextLookup extends Operation implements VariableSupport { private static final int OP_CODE = Operations.TEXT_LOOKUP; private static final String CLASS_NAME = "TextFromFloat"; public int mTextId; @@ -84,6 +84,11 @@ public class TextLookup implements Operation, VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -103,6 +108,12 @@ public class TextLookup implements Operation, VariableSupport { buffer.writeFloat(index); } + /** + * 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 textId = buffer.readInt(); int dataSetId = buffer.readInt(); @@ -110,6 +121,11 @@ public class TextLookup implements Operation, VariableSupport { operations.add(new TextLookup(textId, dataSetId, index)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("Look an array and turn into a text object") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/TextLookupInt.java b/core/java/com/android/internal/widget/remotecompose/core/operations/TextLookupInt.java index 74be698872fa..9c0ee535f62a 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/TextLookupInt.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/TextLookupInt.java @@ -30,7 +30,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Operation convert int index of a list to text */ -public class TextLookupInt implements Operation, VariableSupport { +public class TextLookupInt extends Operation implements VariableSupport { private static final int OP_CODE = Operations.TEXT_LOOKUP_INT; private static final String CLASS_NAME = "TextFromINT"; public int mTextId; @@ -77,6 +77,11 @@ public class TextLookupInt implements Operation, VariableSupport { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -96,6 +101,12 @@ public class TextLookupInt implements Operation, VariableSupport { buffer.writeInt(indexId); } + /** + * 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 textId = buffer.readInt(); int dataSetId = buffer.readInt(); @@ -103,6 +114,11 @@ public class TextLookupInt implements Operation, VariableSupport { operations.add(new TextLookupInt(textId, dataSetId, indexId)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) .description("Look up an array and turn into a text object") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/TextMeasure.java b/core/java/com/android/internal/widget/remotecompose/core/operations/TextMeasure.java index 6d48f67ed8c8..d51b38924126 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/TextMeasure.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/TextMeasure.java @@ -70,6 +70,11 @@ public class TextMeasure extends PaintOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -89,6 +94,12 @@ public class TextMeasure extends PaintOperation { buffer.writeInt(type); } + /** + * 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 id = buffer.readInt(); int textId = buffer.readInt(); @@ -96,9 +107,14 @@ public class TextMeasure extends PaintOperation { operations.add(new TextMeasure(id, textId, type)); } + /** + * 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("Expressions Operations", OP_CODE, CLASS_NAME) - .description("A float and its associated id") + .description("Measure text") .field(INT, "id", "id of float result of the measure") .field(INT, "textId", "id of text") .field(INT, "type", "type: measure 0=width,1=height"); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/TextMerge.java b/core/java/com/android/internal/widget/remotecompose/core/operations/TextMerge.java index ecd5baaf0dd2..5b0c38fe996b 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/TextMerge.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/TextMerge.java @@ -29,7 +29,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Operation to deal with Text data */ -public class TextMerge implements Operation { +public class TextMerge extends Operation { private static final int OP_CODE = Operations.TEXT_MERGE; private static final String CLASS_NAME = "TextMerge"; public int mTextId; @@ -58,6 +58,11 @@ public class TextMerge implements Operation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -77,6 +82,12 @@ public class TextMerge implements Operation { buffer.writeInt(srcId2); } + /** + * 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 textId = buffer.readInt(); int srcId1 = buffer.readInt(); @@ -85,6 +96,11 @@ public class TextMerge implements Operation { operations.add(new TextMerge(textId, srcId1, srcId2)); } + /** + * 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("Data Operations", OP_CODE, CLASS_NAME) .description("Merge two string into one") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/Theme.java b/core/java/com/android/internal/widget/remotecompose/core/operations/Theme.java index d265070a50bf..e329c38daf20 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/Theme.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/Theme.java @@ -33,7 +33,7 @@ import java.util.List; * "tag" the subsequent operations to a given theme. On playback, we can then filter operations * depending on the chosen theme. */ -public class Theme implements RemoteComposeOperation { +public class Theme extends Operation implements RemoteComposeOperation { private static final int OP_CODE = Operations.THEME; private static final String CLASS_NAME = "Theme"; int mTheme; @@ -77,6 +77,11 @@ public class Theme implements RemoteComposeOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -86,11 +91,22 @@ public class Theme implements RemoteComposeOperation { buffer.writeInt(theme); } + /** + * 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 theme = buffer.readInt(); operations.add(new Theme(theme)); } + /** + * 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("Protocol Operations", OP_CODE, CLASS_NAME) .description("Set a theme") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/TouchExpression.java b/core/java/com/android/internal/widget/remotecompose/core/operations/TouchExpression.java index 1bb7b2a183a2..e2e20bc5e57f 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/TouchExpression.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/TouchExpression.java @@ -42,12 +42,12 @@ import java.util.List; * touch behaviours. Including animating to Notched, positions. and tweaking the dynamics of the * animation. */ -public class TouchExpression implements Operation, VariableSupport, TouchListener { +public class TouchExpression extends Operation implements VariableSupport, TouchListener { private static final int OP_CODE = Operations.TOUCH_EXPRESSION; private static final String CLASS_NAME = "TouchExpression"; private float mDefValue; private float mOutDefValue; - public int mId; + private int mId; public float[] mSrcExp; int mMode = 1; // 0 = delta, 1 = absolute float mMax = 1; @@ -56,11 +56,14 @@ public class TouchExpression implements Operation, VariableSupport, TouchListene float mOutMin = 1; float mValue = 0; boolean mUnmodified = true; - public float[] mPreCalcValue; + private float[] mPreCalcValue; private float mLastChange = Float.NaN; private float mLastCalculatedValue = Float.NaN; AnimatedFloatExpression mExp = new AnimatedFloatExpression(); + + /** The maximum number of floats in the expression */ public static final int MAX_EXPRESSION_SIZE = 32; + private VelocityEasing mEasyTouch = new VelocityEasing(); private boolean mEasingToStop = false; private float mTouchUpTime = 0; @@ -495,6 +498,11 @@ public class TouchExpression implements Operation, VariableSupport, TouchListene return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -505,6 +513,14 @@ public class TouchExpression implements Operation, VariableSupport, TouchListene * @param buffer The buffer to write to * @param id the id of the resulting float * @param value the float expression array + * @param min the minimum allowed value + * @param max the maximum allowed value + * @param velocityId the velocity id + * @param touchEffects the type touch effect + * @param exp the expression the maps touch drags to movement + * @param touchMode the touch mode e.g. notch modes + * @param touchSpec the spec of the touch modes + * @param easingSpec the spec of when the object comes to an easing */ public static void apply( WireBuffer buffer, @@ -549,7 +565,13 @@ public class TouchExpression implements Operation, VariableSupport, TouchListene } } - public static void read(WireBuffer buffer, List<Operation> operations) { + /** + * 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 id = buffer.readInt(); float startValue = buffer.readFloat(); float min = buffer.readFloat(); @@ -594,6 +616,11 @@ public class TouchExpression implements Operation, VariableSupport, TouchListene easingData)); } + /** + * Populate the documentation with a description of this operation + * + * @param doc to append the description to. + */ public static void documentation(DocumentationBuilder doc) { doc.operation("Expressions Operations", OP_CODE, CLASS_NAME) .description("A Float expression") diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/Utils.java b/core/java/com/android/internal/widget/remotecompose/core/operations/Utils.java index baca3e0dc99a..de43b90840cc 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/Utils.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/Utils.java @@ -19,34 +19,60 @@ import android.annotation.NonNull; /** Utilities to be used across all core operations */ public class Utils { + /** + * Convert an integer id into a float + * + * @param v the integer id to convert + * @return the id as an float + */ public static float asNan(int v) { return Float.intBitsToFloat(v | -0x800000); } + /** + * convert a float into an integer id + * + * @param value the float id to convert + * @return the id as an integer + */ public static int idFromNan(float value) { int b = Float.floatToRawIntBits(value); return b & 0x3FFFFF; } + /** + * convert a long into an ID + * + * @param v the long to convert + * @return the id still as a long + */ public static long idFromLong(long v) { return v - 0x100000000L; } + /** + * convert a float id and turn it into a string + * + * @param value float to convert + * @return string form of an id + */ @NonNull public static String idStringFromNan(float value) { int b = Float.floatToRawIntBits(value) & 0x3FFFFF; return idString(b); } + /** + * print an id as a string + * + * @param b the id + * @return the id as a string + */ @NonNull public static String idString(int b) { return (b > 0xFFFFF) ? "A_" + (b & 0xFFFFF) : "" + b; } - public static float getActualValue(float lr) { - return 0; - } - /** * trim a string to n characters if needing to trim end in "..." * diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ActionOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ActionOperation.java index 7f1d101cff16..0f840597e3c6 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ActionOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ActionOperation.java @@ -18,12 +18,11 @@ package com.android.internal.widget.remotecompose.core.operations.layout; import android.annotation.NonNull; import com.android.internal.widget.remotecompose.core.CoreDocument; -import com.android.internal.widget.remotecompose.core.Operation; import com.android.internal.widget.remotecompose.core.RemoteContext; import com.android.internal.widget.remotecompose.core.operations.utilities.StringSerializer; /** Operations representing actions on the document */ -public interface ActionOperation extends Operation { +public interface ActionOperation { void serializeToString(int indent, @NonNull StringSerializer serializer); void runAction( diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/CanvasContent.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/CanvasContent.java index aa8f75807141..121b18014a21 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/CanvasContent.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/CanvasContent.java @@ -46,6 +46,11 @@ public class CanvasContent extends Component implements ComponentStartOperation return "CanvasContent"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LAYOUT_CANVAS_CONTENT; } @@ -61,6 +66,12 @@ public class CanvasContent extends Component implements ComponentStartOperation buffer.writeInt(componentId); } + /** + * 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 componentId = buffer.readInt(); operations.add(new CanvasContent(componentId, 0, 0, 0, 0, null, -1)); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ClickModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ClickModifierOperation.java index f44e20ddcdac..34c42494d964 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ClickModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ClickModifierOperation.java @@ -182,6 +182,12 @@ public class ClickModifierOperation extends PaintOperation 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 ClickModifierOperation()); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/Component.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/Component.java index fbfc796e092a..faa259f6b835 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/Component.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/Component.java @@ -26,7 +26,6 @@ import com.android.internal.widget.remotecompose.core.RemoteContext; import com.android.internal.widget.remotecompose.core.SerializableToString; import com.android.internal.widget.remotecompose.core.VariableSupport; import com.android.internal.widget.remotecompose.core.WireBuffer; -import com.android.internal.widget.remotecompose.core.operations.BitmapData; import com.android.internal.widget.remotecompose.core.operations.ComponentValue; import com.android.internal.widget.remotecompose.core.operations.TextData; import com.android.internal.widget.remotecompose.core.operations.layout.animation.AnimateMeasure; @@ -468,11 +467,6 @@ public class Component extends PaintOperation implements Measurable, Serializabl value[0] += mX; value[1] += mY; if (mParent != null) { - if (mParent instanceof LayoutComponent) { - LayoutComponent parent = (LayoutComponent) mParent; - value[0] += parent.getMarginLeft() + parent.getPaddingLeft(); - value[1] += parent.getMarginTop() + parent.getPaddingTop(); - } mParent.getLocationInWindow(value); } } @@ -658,12 +652,7 @@ public class Component extends PaintOperation implements Measurable, Serializabl debugBox(this, context); } for (Operation op : mList) { - if (op instanceof BitmapData) { - ((BitmapData) op).apply(context.getContext()); - } - if (op instanceof PaintOperation) { - ((PaintOperation) op).paint(context); - } + op.apply(context.getContext()); } context.restore(); context.getContext().mLastComponent = prev; @@ -701,7 +690,7 @@ public class Component extends PaintOperation implements Measurable, Serializabl if (applyAnimationAsNeeded(context)) { return; } - if (mVisibility == Visibility.GONE) { + if (mVisibility == Visibility.GONE || mVisibility == Visibility.INVISIBLE) { return; } paintingComponent(context); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentEnd.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentEnd.java index 476b73c8fe7d..396644c45fa4 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentEnd.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentEnd.java @@ -25,7 +25,7 @@ import com.android.internal.widget.remotecompose.core.documentation.Documentatio import java.util.List; -public class ComponentEnd implements Operation { +public class ComponentEnd extends Operation { @Override public void write(@NonNull WireBuffer buffer) { @@ -54,6 +54,11 @@ public class ComponentEnd implements Operation { return "ComponentEnd"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.COMPONENT_END; } @@ -66,6 +71,12 @@ public class ComponentEnd implements Operation { return 1 + 4 + 4 + 4; } + /** + * 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 ComponentEnd()); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentStart.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentStart.java index def9f780ba7f..a85ae270ffb1 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentStart.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentStart.java @@ -28,7 +28,7 @@ import com.android.internal.widget.remotecompose.core.documentation.Documentatio import java.util.List; -public class ComponentStart implements ComponentStartOperation { +public class ComponentStart extends Operation implements ComponentStartOperation { int mType = DEFAULT; float mX; @@ -162,6 +162,11 @@ public class ComponentStart implements ComponentStartOperation { return "ComponentStart"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.COMPONENT_START; } @@ -179,6 +184,12 @@ public class ComponentStart implements ComponentStartOperation { return 1 + 4 + 4 + 4; } + /** + * 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 type = buffer.readInt(); int componentId = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentStartOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentStartOperation.java index abf2356a3e49..a257d466839c 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentStartOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/ComponentStartOperation.java @@ -15,6 +15,4 @@ */ package com.android.internal.widget.remotecompose.core.operations.layout; -import com.android.internal.widget.remotecompose.core.Operation; - -public interface ComponentStartOperation extends Operation {} +public interface ComponentStartOperation {} diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LayoutComponent.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LayoutComponent.java index 0041582f7189..7b0e4a2e2627 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LayoutComponent.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LayoutComponent.java @@ -19,8 +19,10 @@ import android.annotation.NonNull; import android.annotation.Nullable; import com.android.internal.widget.remotecompose.core.Operation; +import com.android.internal.widget.remotecompose.core.OperationInterface; import com.android.internal.widget.remotecompose.core.PaintContext; import com.android.internal.widget.remotecompose.core.operations.BitmapData; +import com.android.internal.widget.remotecompose.core.operations.FloatExpression; import com.android.internal.widget.remotecompose.core.operations.MatrixRestore; import com.android.internal.widget.remotecompose.core.operations.MatrixSave; import com.android.internal.widget.remotecompose.core.operations.MatrixTranslate; @@ -47,12 +49,6 @@ public class LayoutComponent extends Component { @Nullable protected ZIndexModifierOperation mZIndexModifier = null; @Nullable protected GraphicsLayerModifierOperation mGraphicsLayerModifier = null; - // Margins - protected float mMarginLeft = 0f; - protected float mMarginRight = 0f; - protected float mMarginTop = 0f; - protected float mMarginBottom = 0f; - protected float mPaddingLeft = 0f; protected float mPaddingRight = 0f; protected float mPaddingTop = 0f; @@ -76,22 +72,6 @@ public class LayoutComponent extends Component { super(parent, componentId, animationId, x, y, width, height); } - public float getMarginLeft() { - return mMarginLeft; - } - - public float getMarginRight() { - return mMarginRight; - } - - public float getMarginTop() { - return mMarginTop; - } - - public float getMarginBottom() { - return mMarginBottom; - } - public float getPaddingLeft() { return mPaddingLeft; } @@ -133,8 +113,7 @@ public class LayoutComponent extends Component { public void inflate() { ArrayList<TextData> data = new ArrayList<>(); - ArrayList<TouchExpression> touchExpressions = new ArrayList<>(); - ArrayList<PaintData> paintData = new ArrayList<>(); + ArrayList<Operation> supportedOperations = new ArrayList<>(); for (Operation op : mList) { if (op instanceof LayoutComponentContent) { @@ -179,10 +158,10 @@ public class LayoutComponent extends Component { mComponentModifiers.add((ModifierOperation) op); } else if (op instanceof TextData) { data.add((TextData) op); - } else if (op instanceof TouchExpression) { - touchExpressions.add((TouchExpression) op); - } else if (op instanceof PaintData) { - paintData.add((PaintData) op); + } else if (op instanceof TouchExpression + || (op instanceof PaintData) + || (op instanceof FloatExpression)) { + supportedOperations.add(op); } else { // nothing } @@ -190,8 +169,7 @@ public class LayoutComponent extends Component { mList.clear(); mList.addAll(data); - mList.addAll(touchExpressions); - mList.addAll(paintData); + mList.addAll(supportedOperations); mList.add(mComponentModifiers); for (Component c : mChildrenComponents) { c.mParent = this; @@ -203,10 +181,6 @@ public class LayoutComponent extends Component { mX = 0f; mY = 0f; - mMarginLeft = 0f; - mMarginTop = 0f; - mMarginRight = 0f; - mMarginBottom = 0f; mPaddingLeft = 0f; mPaddingTop = 0f; mPaddingRight = 0f; @@ -214,7 +188,7 @@ public class LayoutComponent extends Component { boolean applyHorizontalMargin = true; boolean applyVerticalMargin = true; - for (Operation op : mComponentModifiers.getList()) { + for (OperationInterface op : mComponentModifiers.getList()) { if (op instanceof PaddingModifierOperation) { // We are accumulating padding modifiers to compute the margin // until we hit a dimension; the computed padding for the @@ -223,31 +197,17 @@ public class LayoutComponent extends Component { float right = ((PaddingModifierOperation) op).getRight(); float top = ((PaddingModifierOperation) op).getTop(); float bottom = ((PaddingModifierOperation) op).getBottom(); - if (applyHorizontalMargin) { - mMarginLeft += left; - mMarginRight += right; - } - if (applyVerticalMargin) { - mMarginTop += top; - mMarginBottom += bottom; - } mPaddingLeft += left; mPaddingTop += top; mPaddingRight += right; mPaddingBottom += bottom; - } - if (op instanceof WidthModifierOperation && mWidthModifier == null) { + } else if (op instanceof WidthModifierOperation && mWidthModifier == null) { mWidthModifier = (WidthModifierOperation) op; - applyHorizontalMargin = false; - } - if (op instanceof HeightModifierOperation && mHeightModifier == null) { + } else if (op instanceof HeightModifierOperation && mHeightModifier == null) { mHeightModifier = (HeightModifierOperation) op; - applyVerticalMargin = false; - } - if (op instanceof ZIndexModifierOperation) { + } else if (op instanceof ZIndexModifierOperation) { mZIndexModifier = (ZIndexModifierOperation) op; - } - if (op instanceof GraphicsLayerModifierOperation) { + } else if (op instanceof GraphicsLayerModifierOperation) { mGraphicsLayerModifier = (GraphicsLayerModifierOperation) op; } } @@ -339,7 +299,7 @@ public class LayoutComponent extends Component { float s = 0f; float e = 0f; float w = 0f; - for (Operation c : mComponentModifiers.getList()) { + for (OperationInterface c : mComponentModifiers.getList()) { if (c instanceof WidthModifierOperation) { WidthModifierOperation o = (WidthModifierOperation) c; if (o.getType() == DimensionModifierOperation.Type.EXACT @@ -366,7 +326,7 @@ public class LayoutComponent extends Component { public float computeModifierDefinedPaddingWidth(@NonNull float[] padding) { float s = 0f; float e = 0f; - for (Operation c : mComponentModifiers.getList()) { + for (OperationInterface c : mComponentModifiers.getList()) { if (c instanceof PaddingModifierOperation) { PaddingModifierOperation pop = (PaddingModifierOperation) c; s += pop.getLeft(); @@ -383,7 +343,7 @@ public class LayoutComponent extends Component { float t = 0f; float b = 0f; float h = 0f; - for (Operation c : mComponentModifiers.getList()) { + for (OperationInterface c : mComponentModifiers.getList()) { if (c instanceof HeightModifierOperation) { HeightModifierOperation o = (HeightModifierOperation) c; if (o.getType() == DimensionModifierOperation.Type.EXACT @@ -410,7 +370,7 @@ public class LayoutComponent extends Component { public float computeModifierDefinedPaddingHeight(@NonNull float[] padding) { float t = 0f; float b = 0f; - for (Operation c : mComponentModifiers.getList()) { + for (OperationInterface c : mComponentModifiers.getList()) { if (c instanceof PaddingModifierOperation) { PaddingModifierOperation pop = (PaddingModifierOperation) c; t += pop.getTop(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LayoutComponentContent.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LayoutComponentContent.java index 7eea885f6b6d..20e4688aaa32 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LayoutComponentContent.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LayoutComponentContent.java @@ -46,6 +46,11 @@ public class LayoutComponentContent extends Component implements ComponentStartO return "LayoutContent"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LAYOUT_CONTENT; } @@ -61,6 +66,12 @@ public class LayoutComponentContent extends Component implements ComponentStartO buffer.writeInt(componentId); } + /** + * 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 componentId = buffer.readInt(); operations.add(new LayoutComponentContent(componentId, 0, 0, 0, 0, null, -1)); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LoopEnd.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LoopEnd.java index 71de2857258b..d88f711c62c6 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LoopEnd.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LoopEnd.java @@ -25,7 +25,7 @@ import com.android.internal.widget.remotecompose.core.documentation.Documentatio import java.util.List; -public class LoopEnd implements Operation { +public class LoopEnd extends Operation { @Override public void write(@NonNull WireBuffer buffer) { @@ -54,6 +54,11 @@ public class LoopEnd implements Operation { return "LoopEnd"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LOOP_END; } @@ -62,6 +67,12 @@ public class LoopEnd implements Operation { buffer.start(id()); } + /** + * 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 LoopEnd()); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LoopOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LoopOperation.java index d88382dde7e0..83a2f0e1ffa3 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LoopOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/LoopOperation.java @@ -21,31 +21,57 @@ 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.documentation.DocumentedOperation; +import com.android.internal.widget.remotecompose.core.operations.Utils; import java.util.ArrayList; import java.util.List; /** Represents a loop of operations */ -public class LoopOperation extends PaintOperation { +public class LoopOperation extends PaintOperation implements VariableSupport { private static final int OP_CODE = Operations.LOOP_START; @NonNull public ArrayList<Operation> mList = new ArrayList<>(); int mIndexVariableId; - float mUntil = 12; - float mFrom = 0; - float mStep = 1; + float mUntil; + float mFrom; + float mStep; + float mUntilOut; + float mFromOut; + float mStepOut; public LoopOperation(int count, int indexId) { mUntil = count; mIndexVariableId = indexId; } - public LoopOperation(float count, float from, float step, int indexId) { - mUntil = count; + @Override + public void registerListening(RemoteContext context) { + if (Float.isNaN(mUntil)) { + context.listensTo(Utils.idFromNan(mUntil), this); + } + if (Float.isNaN(mFrom)) { + context.listensTo(Utils.idFromNan(mFrom), this); + } + if (Float.isNaN(mStep)) { + context.listensTo(Utils.idFromNan(mStep), this); + } + } + + @Override + public void updateVariables(RemoteContext context) { + mUntilOut = Float.isNaN(mUntil) ? context.getFloat(Utils.idFromNan(mUntil)) : mUntil; + mFromOut = Float.isNaN(mFrom) ? context.getFloat(Utils.idFromNan(mFrom)) : mFrom; + mStepOut = Float.isNaN(mStep) ? context.getFloat(Utils.idFromNan(mStep)) : mStep; + } + + public LoopOperation(int indexId, float from, float step, float until) { + mUntil = until; mFrom = from; mStep = step; mIndexVariableId = indexId; @@ -58,13 +84,19 @@ public class LoopOperation extends PaintOperation { @Override public void write(@NonNull WireBuffer buffer) { - apply(buffer, mUntil, mFrom, mStep, mIndexVariableId); + apply(buffer, mIndexVariableId, mFrom, mStep, mUntil); } @NonNull @Override public String toString() { - return "LoopOperation"; + StringBuilder builder = new StringBuilder("LoopOperation\n"); + for (Operation operation : mList) { + builder.append(" "); + builder.append(operation); + builder.append("\n"); + } + return builder.toString(); } @NonNull @@ -76,13 +108,13 @@ public class LoopOperation extends PaintOperation { @Override public void paint(@NonNull PaintContext context) { if (mIndexVariableId == 0) { - for (float i = mFrom; i < mUntil; i += mStep) { + for (float i = mFromOut; i < mUntilOut; i += mStepOut) { for (Operation op : mList) { op.apply(context.getContext()); } } } else { - for (float i = mFrom; i < mUntil; i += mStep) { + for (float i = mFromOut; i < mUntilOut; i += mStepOut) { context.getContext().loadFloat(mIndexVariableId, i); for (Operation op : mList) { if (op instanceof VariableSupport) { @@ -100,24 +132,34 @@ public class LoopOperation extends PaintOperation { } public static void apply( - @NonNull WireBuffer buffer, float count, float from, float step, int indexId) { + @NonNull WireBuffer buffer, int indexId, float from, float step, float until) { buffer.start(OP_CODE); - buffer.writeFloat(count); + buffer.writeInt(indexId); buffer.writeFloat(from); buffer.writeFloat(step); - buffer.writeInt(indexId); + buffer.writeFloat(until); } + /** + * 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) { - float count = buffer.readFloat(); + int indexId = buffer.readInt(); float from = buffer.readFloat(); float step = buffer.readFloat(); - int indexId = buffer.readInt(); - operations.add(new LoopOperation(count, from, step, indexId)); + float until = buffer.readFloat(); + operations.add(new LoopOperation(indexId, from, step, until)); } public static void documentation(@NonNull DocumentationBuilder doc) { doc.operation("Operations", OP_CODE, name()) - .description("Loop. This operation execute" + " a list of action in a loop"); + .description("Loop. This operation execute" + " a list of action in a loop") + .field(DocumentedOperation.INT, "id", "if not 0 write value") + .field(DocumentedOperation.FLOAT, "from", "values starts at") + .field(DocumentedOperation.FLOAT, "step", "value step") + .field(DocumentedOperation.FLOAT, "until", "stops less than or equal"); } } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/OperationsListEnd.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/OperationsListEnd.java index ca79003448e7..99b7e68786fb 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/OperationsListEnd.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/OperationsListEnd.java @@ -25,7 +25,7 @@ import com.android.internal.widget.remotecompose.core.documentation.Documentatio import java.util.List; -public class OperationsListEnd implements Operation { +public class OperationsListEnd extends Operation { @Override public void write(@NonNull WireBuffer buffer) { @@ -54,6 +54,11 @@ public class OperationsListEnd implements Operation { return "ListEnd"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.OPERATIONS_LIST_END; } @@ -62,6 +67,12 @@ public class OperationsListEnd implements Operation { buffer.start(id()); } + /** + * 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 OperationsListEnd()); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/RootLayoutComponent.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/RootLayoutComponent.java index 85c71537540c..fd1628729dd4 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/RootLayoutComponent.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/RootLayoutComponent.java @@ -197,6 +197,11 @@ public class RootLayoutComponent extends Component implements ComponentStartOper return "RootLayout"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LAYOUT_ROOT; } @@ -206,6 +211,12 @@ public class RootLayoutComponent extends Component implements ComponentStartOper buffer.writeInt(componentId); } + /** + * 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 componentId = buffer.readInt(); operations.add(new RootLayoutComponent(componentId, 0, 0, 0, 0, null, -1)); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/TouchCancelModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/TouchCancelModifierOperation.java index 0316f96bfc3e..3185bb5f0f72 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/TouchCancelModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/TouchCancelModifierOperation.java @@ -84,6 +84,12 @@ public class TouchCancelModifierOperation extends ListActionsOperation implement 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(WireBuffer buffer, List<Operation> operations) { operations.add(new TouchCancelModifierOperation()); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/animation/AnimationSpec.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/animation/AnimationSpec.java index 6fb705985711..b230b09112b2 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/animation/AnimationSpec.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/animation/AnimationSpec.java @@ -29,7 +29,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.easin import java.util.List; /** Basic component animation spec */ -public class AnimationSpec implements Operation { +public class AnimationSpec extends Operation { int mAnimationId = -1; int mMotionDuration = 300; int mMotionEasingType = GeneralEasing.CUBIC_STANDARD; @@ -142,6 +142,11 @@ public class AnimationSpec implements Operation { return "AnimationSpec"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.ANIMATION_SPEC; } @@ -193,6 +198,12 @@ public class AnimationSpec implements Operation { buffer.writeInt(animationToInt(exitAnimation)); } + /** + * 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 animationId = buffer.readInt(); int motionDuration = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/BoxLayout.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/BoxLayout.java index 47a942187900..01cd7ccd0b94 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/BoxLayout.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/BoxLayout.java @@ -108,6 +108,8 @@ public class BoxLayout extends LayoutManager implements ComponentStartOperation @NonNull PaintContext context, float maxWidth, float maxHeight, + boolean horizontalWrap, + boolean verticalWrap, @NonNull MeasurePass measure, @NonNull Size size) { for (Component c : mChildrenComponents) { @@ -175,6 +177,11 @@ public class BoxLayout extends LayoutManager implements ComponentStartOperation return "BoxLayout"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LAYOUT_BOX; } @@ -192,6 +199,12 @@ public class BoxLayout extends LayoutManager implements ComponentStartOperation buffer.writeInt(verticalPositioning); } + /** + * 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 componentId = buffer.readInt(); int animationId = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/CanvasLayout.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/CanvasLayout.java index 476b1a666fe9..665db2637674 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/CanvasLayout.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/CanvasLayout.java @@ -77,6 +77,11 @@ public class CanvasLayout extends BoxLayout { return "CanvasLayout"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LAYOUT_CANVAS; } @@ -87,6 +92,12 @@ public class CanvasLayout extends BoxLayout { buffer.writeInt(animationId); } + /** + * 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 componentId = buffer.readInt(); int animationId = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/ColumnLayout.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/ColumnLayout.java index 68e18c699539..5b9ee0ff511f 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/ColumnLayout.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/ColumnLayout.java @@ -125,17 +125,21 @@ public class ColumnLayout extends LayoutManager implements ComponentStartOperati @NonNull PaintContext context, float maxWidth, float maxHeight, + boolean horizontalWrap, + boolean verticalWrap, @NonNull MeasurePass measure, @NonNull Size size) { DebugLog.s(() -> "COMPUTE WRAP SIZE in " + this + " (" + mComponentId + ")"); int visibleChildrens = 0; + float currentMaxHeight = maxHeight; for (Component c : mChildrenComponents) { - c.measure(context, 0f, maxWidth, 0f, maxHeight, measure); + c.measure(context, 0f, maxWidth, 0f, currentMaxHeight, measure); ComponentMeasure m = measure.get(c); if (m.getVisibility() != Visibility.GONE) { size.setWidth(Math.max(size.getWidth(), m.getW())); size.setHeight(size.getHeight() + m.getH()); visibleChildrens++; + currentMaxHeight -= m.getH(); } } if (!mChildrenComponents.isEmpty()) { @@ -342,6 +346,11 @@ public class ColumnLayout extends LayoutManager implements ComponentStartOperati return "ColumnLayout"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LAYOUT_COLUMN; } @@ -361,6 +370,12 @@ public class ColumnLayout extends LayoutManager implements ComponentStartOperati buffer.writeFloat(spacedBy); } + /** + * 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 componentId = buffer.readInt(); int animationId = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/LayoutManager.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/LayoutManager.java index 3b5aaf38fb5b..6a15b7f1b178 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/LayoutManager.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/LayoutManager.java @@ -53,6 +53,8 @@ public abstract class LayoutManager extends LayoutComponent implements Measurabl @NonNull PaintContext context, float maxWidth, float maxHeight, + boolean horizontalWrap, + boolean verticalWrap, @NonNull MeasurePass measure, @NonNull Size size) { // nothing here @@ -129,42 +131,67 @@ public abstract class LayoutManager extends LayoutComponent implements Measurabl float maxHeight, @NonNull MeasurePass measure) { boolean hasWrap = true; - float measuredWidth = - Math.min(maxWidth, computeModifierDefinedWidth() - mMarginLeft - mMarginRight); - float measuredHeight = - Math.min(maxHeight, computeModifierDefinedHeight() - mMarginTop - mMarginBottom); - float insetMaxWidth = maxWidth - mMarginLeft - mMarginRight; - float insetMaxHeight = maxHeight - mMarginTop - mMarginBottom; + + float measuredWidth = Math.min(maxWidth, computeModifierDefinedWidth()); + float measuredHeight = Math.min(maxHeight, computeModifierDefinedHeight()); + float insetMaxWidth = maxWidth - mPaddingLeft - mPaddingRight; + float insetMaxHeight = maxHeight - mPaddingTop - mPaddingBottom; + if (mWidthModifier.isIntrinsicMin()) { maxWidth = intrinsicWidth(); } if (mHeightModifier.isIntrinsicMin()) { maxHeight = intrinsicHeight(); } - if (mWidthModifier.isWrap() || mHeightModifier.isWrap()) { // TODO: potential npe -- bbade@ + + boolean hasHorizontalWrap = mWidthModifier.isWrap(); + boolean hasVerticalWrap = mHeightModifier.isWrap(); + if (hasHorizontalWrap || hasVerticalWrap) { // TODO: potential npe -- bbade@ mCachedWrapSize.setWidth(0f); mCachedWrapSize.setHeight(0f); - computeWrapSize(context, maxWidth, maxHeight, measure, mCachedWrapSize); + float wrapMaxWidth = insetMaxWidth; + float wrapMaxHeight = insetMaxHeight; + if (hasHorizontalWrap) { + wrapMaxWidth = insetMaxWidth - mPaddingLeft - mPaddingRight; + } + if (hasVerticalWrap) { + wrapMaxHeight = insetMaxHeight - mPaddingTop - mPaddingBottom; + } + computeWrapSize( + context, + wrapMaxWidth, + wrapMaxHeight, + mWidthModifier.isWrap(), + mHeightModifier.isWrap(), + measure, + mCachedWrapSize); measuredWidth = mCachedWrapSize.getWidth(); + if (hasHorizontalWrap) { + measuredWidth += mPaddingLeft + mPaddingRight; + } measuredHeight = mCachedWrapSize.getHeight(); + if (hasVerticalWrap) { + measuredHeight += mPaddingTop + mPaddingBottom; + } } else { hasWrap = false; } + if (isInHorizontalFill()) { - measuredWidth = insetMaxWidth; + measuredWidth = maxWidth; } else if (mWidthModifier.hasWeight()) { measuredWidth = Math.max(measuredWidth, computeModifierDefinedWidth()); } else { measuredWidth = Math.max(measuredWidth, minWidth); - measuredWidth = Math.min(measuredWidth, insetMaxWidth); + measuredWidth = Math.min(measuredWidth, maxWidth); } if (isInVerticalFill()) { // todo: potential npe -- bbade@ - measuredHeight = insetMaxHeight; + measuredHeight = maxHeight; } else if (mHeightModifier.hasWeight()) { measuredHeight = Math.max(measuredHeight, computeModifierDefinedHeight()); } else { measuredHeight = Math.max(measuredHeight, minHeight); - measuredHeight = Math.min(measuredHeight, insetMaxHeight); + measuredHeight = Math.min(measuredHeight, maxHeight); } if (minWidth == maxWidth) { measuredWidth = maxWidth; @@ -172,20 +199,27 @@ public abstract class LayoutManager extends LayoutComponent implements Measurabl if (minHeight == maxHeight) { measuredHeight = maxHeight; } - measuredWidth = Math.min(measuredWidth, insetMaxWidth); - measuredHeight = Math.min(measuredHeight, insetMaxHeight); + if (!hasWrap) { if (hasHorizontalScroll()) { mCachedWrapSize.setWidth(0f); mCachedWrapSize.setHeight(0f); - computeWrapSize(context, Float.MAX_VALUE, maxHeight, measure, mCachedWrapSize); + computeWrapSize( + context, + Float.MAX_VALUE, + maxHeight, + false, + false, + measure, + mCachedWrapSize); float w = mCachedWrapSize.getWidth(); computeSize(context, 0f, w, 0, measuredHeight, measure); mComponentModifiers.setHorizontalScrollDimension(measuredWidth, w); } else if (hasVerticalScroll()) { mCachedWrapSize.setWidth(0f); mCachedWrapSize.setHeight(0f); - computeWrapSize(context, maxWidth, Float.MAX_VALUE, measure, mCachedWrapSize); + computeWrapSize( + context, maxWidth, Float.MAX_VALUE, false, false, measure, mCachedWrapSize); float h = mCachedWrapSize.getHeight(); computeSize(context, 0f, measuredWidth, 0, h, measure); mComponentModifiers.setVerticalScrollDimension(measuredHeight, h); @@ -202,9 +236,6 @@ public abstract class LayoutManager extends LayoutComponent implements Measurabl cm.setH(measuredHeight); } - measuredWidth += mMarginLeft + mMarginRight; - measuredHeight += mMarginTop + mMarginBottom; - ComponentMeasure m = measure.get(this); m.setW(measuredWidth); m.setH(measuredHeight); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/RowLayout.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/RowLayout.java index 0ce634f9c1ab..0ec820b85964 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/RowLayout.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/RowLayout.java @@ -123,21 +123,25 @@ public class RowLayout extends LayoutManager implements ComponentStartOperation @NonNull PaintContext context, float maxWidth, float maxHeight, + boolean horizontalWrap, + boolean verticalWrap, @NonNull MeasurePass measure, @NonNull Size size) { DebugLog.s(() -> "COMPUTE WRAP SIZE in " + this + " (" + mComponentId + ")"); - // int visibleChildrens = 0; + int visibleChildrens = 0; + float currentMaxWidth = maxWidth; for (Component c : mChildrenComponents) { - c.measure(context, 0f, maxWidth, 0f, maxHeight, measure); + c.measure(context, 0f, currentMaxWidth, 0f, maxHeight, measure); ComponentMeasure m = measure.get(c); if (m.getVisibility() != Visibility.GONE) { size.setWidth(size.getWidth() + m.getW()); size.setHeight(Math.max(size.getHeight(), m.getH())); - // visibleChildrens++; + visibleChildrens++; + currentMaxWidth -= m.getW(); } } if (!mChildrenComponents.isEmpty()) { - size.setWidth(size.getWidth() + (mSpacedBy * (mChildrenComponents.size() - 1))); + size.setWidth(size.getWidth() + (mSpacedBy * (visibleChildrens - 1))); } DebugLog.e(); } @@ -345,6 +349,11 @@ public class RowLayout extends LayoutManager implements ComponentStartOperation return "RowLayout"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LAYOUT_ROW; } @@ -364,6 +373,12 @@ public class RowLayout extends LayoutManager implements ComponentStartOperation buffer.writeFloat(spacedBy); } + /** + * 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 componentId = buffer.readInt(); int animationId = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/StateLayout.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/StateLayout.java index 73a104bcafa6..61a3ec964142 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/StateLayout.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/StateLayout.java @@ -159,10 +159,13 @@ public class StateLayout extends LayoutManager implements ComponentStartOperatio @NonNull PaintContext context, float maxWidth, float maxHeight, + boolean horizontalWrap, + boolean verticalWrap, @NonNull MeasurePass measure, @NonNull Size size) { LayoutManager layout = getLayout(currentLayoutIndex); - layout.computeWrapSize(context, maxWidth, maxHeight, measure, size); + layout.computeWrapSize( + context, maxWidth, maxHeight, horizontalWrap, verticalWrap, measure, size); } @Override @@ -442,11 +445,7 @@ public class StateLayout extends LayoutManager implements ComponentStartOperatio int id = c.getPaintId(); for (int i = 0; i < idIndex; i++) { if (cacheListElementsId[i] == id) { - context.translate( - previousLayout.getMarginLeft(), previousLayout.getMarginTop()); c.paint(context); - context.translate( - -currentLayout.getMarginLeft(), -currentLayout.getMarginTop()); break; } } @@ -472,16 +471,10 @@ public class StateLayout extends LayoutManager implements ComponentStartOperatio // and fade in the new one Component previousComponent = stateComponents[previousLayoutIndex]; if (previousComponent != null && component != previousComponent) { - context.translate( - currentLayout.getMarginLeft(), currentLayout.getMarginTop()); previousComponent.paint(context); - context.translate( - -currentLayout.getMarginLeft(), -currentLayout.getMarginTop()); } } - context.translate(currentLayout.getMarginLeft(), currentLayout.getMarginTop()); component.paint(context); - context.translate(-currentLayout.getMarginLeft(), -currentLayout.getMarginTop()); } else if (op instanceof PaintOperation) { ((PaintOperation) op).paint(context); } @@ -563,6 +556,12 @@ public class StateLayout extends LayoutManager implements ComponentStartOperatio buffer.writeInt(indexId); } + /** + * 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 componentId = buffer.readInt(); int animationId = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/TextLayout.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/TextLayout.java index a527e5ad4077..8e7f538d0004 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/TextLayout.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/managers/TextLayout.java @@ -52,8 +52,8 @@ public class TextLayout extends LayoutManager implements ComponentStartOperation private int mType = -1; private float mTextX; private float mTextY; - private float mTextW; - private float mTextH; + private float mTextW = -1; + private float mTextH = -1; @Nullable private String mCachedString = ""; @@ -66,7 +66,11 @@ public class TextLayout extends LayoutManager implements ComponentStartOperation @Override public void updateVariables(@NonNull RemoteContext context) { - mCachedString = context.getText(mTextId); + String cachedString = context.getText(mTextId); + if (cachedString != null && cachedString.equalsIgnoreCase(mCachedString)) { + return; + } + mCachedString = cachedString; if (mType == -1) { if (mFontFamilyId != -1) { String fontFamily = context.getText(mFontFamilyId); @@ -86,8 +90,9 @@ public class TextLayout extends LayoutManager implements ComponentStartOperation mType = 0; } } - mNeedsMeasure = true; - needsRepaint(); + mTextW = -1; + mTextH = -1; + invalidateMeasure(); } public TextLayout( @@ -168,7 +173,14 @@ public class TextLayout extends LayoutManager implements ComponentStartOperation return; } int length = mCachedString.length(); - context.drawTextRun(mTextId, 0, length, 0, 0, mTextX, mTextY, false); + if (mTextW > mWidth) { + context.save(); + context.translate(getScrollX(), getScrollY()); + context.drawTextRun(mTextId, 0, length, 0, 0, mTextX, mTextY, false); + context.restore(); + } else { + context.drawTextRun(mTextId, 0, length, 0, 0, mTextX, mTextY, false); + } if (DEBUG) { mPaint.setStyle(PaintBundle.STYLE_FILL_AND_STROKE); mPaint.setColor(1f, 1F, 1F, 1F); @@ -246,6 +258,8 @@ public class TextLayout extends LayoutManager implements ComponentStartOperation @NonNull PaintContext context, float maxWidth, float maxHeight, + boolean horizontalWrap, + boolean verticalWrap, @NonNull MeasurePass measure, @NonNull Size size) { context.savePaint(); @@ -262,9 +276,9 @@ public class TextLayout extends LayoutManager implements ComponentStartOperation context.restorePaint(); float w = bounds[2] - bounds[0]; float h = bounds[3] - bounds[1]; - size.setWidth(w); + size.setWidth(Math.min(maxWidth, w)); mTextX = -bounds[0]; - size.setHeight(h); + size.setHeight(Math.min(maxHeight, h)); mTextY = -bounds[1]; mTextW = w; mTextH = h; @@ -285,6 +299,11 @@ public class TextLayout extends LayoutManager implements ComponentStartOperation return "TextLayout"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.LAYOUT_TEXT; } @@ -312,6 +331,12 @@ public class TextLayout extends LayoutManager implements ComponentStartOperation buffer.writeInt(textAlign); } + /** + * 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 componentId = buffer.readInt(); int animationId = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/BackgroundModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/BackgroundModifierOperation.java index 71d2ba6edf21..5df16c5bc03a 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/BackgroundModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/BackgroundModifierOperation.java @@ -114,6 +114,11 @@ public class BackgroundModifierOperation extends DecoratorModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -142,6 +147,12 @@ public class BackgroundModifierOperation extends DecoratorModifierOperation { buffer.writeInt(shapeType); } + /** + * 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) { float x = buffer.readFloat(); float y = buffer.readFloat(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/BorderModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/BorderModifierOperation.java index 0707cd627678..bfadd2f1ef9c 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/BorderModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/BorderModifierOperation.java @@ -160,6 +160,11 @@ public class BorderModifierOperation extends DecoratorModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -192,6 +197,12 @@ public class BorderModifierOperation extends DecoratorModifierOperation { buffer.writeInt(shapeType); } + /** + * 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) { float x = buffer.readFloat(); float y = buffer.readFloat(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ClipRectModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ClipRectModifierOperation.java index e05b02781e10..d0af872acc53 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ClipRectModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ClipRectModifierOperation.java @@ -60,6 +60,11 @@ public class ClipRectModifierOperation extends DecoratorModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -68,6 +73,12 @@ public class ClipRectModifierOperation extends DecoratorModifierOperation { 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 ClipRectModifierOperation()); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ComponentVisibilityOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ComponentVisibilityOperation.java index 471db0bedb11..1e6ccfcb5d34 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ComponentVisibilityOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ComponentVisibilityOperation.java @@ -34,7 +34,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Allows setting visibility on a component */ -public class ComponentVisibilityOperation +public class ComponentVisibilityOperation extends Operation implements ModifierOperation, VariableSupport, DecoratorComponent { private static final int OP_CODE = Operations.MODIFIER_VISIBILITY; @@ -79,6 +79,12 @@ public class ComponentVisibilityOperation buffer.writeInt(valueId); } + /** + * 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 valueId = buffer.readInt(); operations.add(new ComponentVisibilityOperation(valueId)); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/DimensionModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/DimensionModifierOperation.java index b9324f0320d3..b11deae3d196 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/DimensionModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/DimensionModifierOperation.java @@ -17,13 +17,15 @@ package com.android.internal.widget.remotecompose.core.operations.layout.modifie import android.annotation.NonNull; +import com.android.internal.widget.remotecompose.core.Operation; import com.android.internal.widget.remotecompose.core.RemoteContext; import com.android.internal.widget.remotecompose.core.VariableSupport; import com.android.internal.widget.remotecompose.core.operations.Utils; import com.android.internal.widget.remotecompose.core.operations.utilities.StringSerializer; /** Base class for dimension modifiers */ -public abstract class DimensionModifierOperation implements ModifierOperation, VariableSupport { +public abstract class DimensionModifierOperation extends Operation + implements ModifierOperation, VariableSupport { public enum Type { EXACT, diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/GraphicsLayerModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/GraphicsLayerModifierOperation.java index 571e554b9c71..4252309b7e4c 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/GraphicsLayerModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/GraphicsLayerModifierOperation.java @@ -206,6 +206,11 @@ public class GraphicsLayerModifierOperation extends DecoratorModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HeightModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HeightModifierOperation.java index 7bb4a756afa5..692b5269954a 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HeightModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HeightModifierOperation.java @@ -37,6 +37,11 @@ public class HeightModifierOperation extends DimensionModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -47,6 +52,12 @@ public class HeightModifierOperation extends DimensionModifierOperation { buffer.writeFloat(value); } + /** + * 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) { Type type = Type.fromInt(buffer.readInt()); float value = buffer.readFloat(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HostActionOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HostActionOperation.java index d239bc857446..333e281d4abb 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HostActionOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HostActionOperation.java @@ -32,7 +32,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Capture a host action information. This can be triggered on eg. a click. */ -public class HostActionOperation implements ActionOperation { +public class HostActionOperation extends Operation implements ActionOperation { private static final int OP_CODE = Operations.HOST_ACTION; int mActionId = -1; @@ -88,6 +88,12 @@ public class HostActionOperation implements ActionOperation { buffer.writeInt(actionId); } + /** + * 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 actionId = buffer.readInt(); operations.add(new HostActionOperation(actionId)); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HostNamedActionOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HostNamedActionOperation.java index 3268e5efd449..f9a4270905a1 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HostNamedActionOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/HostNamedActionOperation.java @@ -32,7 +32,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Capture a host action information. This can be triggered on eg. a click. */ -public class HostNamedActionOperation implements ActionOperation { +public class HostNamedActionOperation extends Operation implements ActionOperation { private static final int OP_CODE = Operations.HOST_NAMED_ACTION; public static final int FLOAT_TYPE = 0; @@ -112,6 +112,12 @@ public class HostNamedActionOperation implements ActionOperation { buffer.writeInt(valueId); } + /** + * 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 textId = buffer.readInt(); int type = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ModifierOperation.java index 8f08f1417add..f8926fef56fa 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ModifierOperation.java @@ -17,10 +17,10 @@ package com.android.internal.widget.remotecompose.core.operations.layout.modifie import android.annotation.NonNull; -import com.android.internal.widget.remotecompose.core.Operation; +import com.android.internal.widget.remotecompose.core.OperationInterface; import com.android.internal.widget.remotecompose.core.operations.utilities.StringSerializer; /** Represents a modifier */ -public interface ModifierOperation extends Operation { +public interface ModifierOperation extends OperationInterface { void serializeToString(int indent, @NonNull StringSerializer serializer); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/OffsetModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/OffsetModifierOperation.java index 8c07059369ab..69c4e9a8e423 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/OffsetModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/OffsetModifierOperation.java @@ -94,6 +94,11 @@ public class OffsetModifierOperation extends DecoratorModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/PaddingModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/PaddingModifierOperation.java index 2b6621e4fd58..545df64ab154 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/PaddingModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/PaddingModifierOperation.java @@ -32,7 +32,7 @@ import java.util.List; * Represents a padding modifier. Padding modifiers can be chained and will impact following * modifiers. */ -public class PaddingModifierOperation implements ModifierOperation { +public class PaddingModifierOperation extends Operation implements ModifierOperation { private static final int OP_CODE = Operations.MODIFIER_PADDING; public static final String CLASS_NAME = "PaddingModifierOperation"; float mLeft; @@ -118,6 +118,11 @@ public class PaddingModifierOperation implements ModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.MODIFIER_PADDING; } @@ -131,6 +136,12 @@ public class PaddingModifierOperation implements ModifierOperation { buffer.writeFloat(bottom); } + /** + * 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) { float left = buffer.readFloat(); float top = buffer.readFloat(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/RoundedClipRectModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/RoundedClipRectModifierOperation.java index 3fefc5817270..681501d9cdf9 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/RoundedClipRectModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/RoundedClipRectModifierOperation.java @@ -37,11 +37,22 @@ public class RoundedClipRectModifierOperation extends DrawBase4 public static final int OP_CODE = Operations.MODIFIER_ROUNDED_CLIP_RECT; public static final String CLASS_NAME = "RoundedClipRectModifierOperation"; + /** + * 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) { Maker m = RoundedClipRectModifierOperation::new; read(m, buffer, operations); } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ScrollModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ScrollModifierOperation.java index 8dcfed999c5c..0b6632057bd2 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ScrollModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ScrollModifierOperation.java @@ -134,6 +134,11 @@ public class ScrollModifierOperation extends DecoratorModifierOperation implemen return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueFloatChangeActionOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueFloatChangeActionOperation.java index a97fcffdf75c..b96d3cc4bbc0 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueFloatChangeActionOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueFloatChangeActionOperation.java @@ -33,7 +33,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Apply a value change on an float variable. */ -public class ValueFloatChangeActionOperation implements ActionOperation { +public class ValueFloatChangeActionOperation extends Operation implements ActionOperation { private static final int OP_CODE = Operations.VALUE_FLOAT_CHANGE_ACTION; int mTargetValueId = -1; diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueFloatExpressionChangeActionOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueFloatExpressionChangeActionOperation.java index 41586b4939a6..d81b7ffd1ef9 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueFloatExpressionChangeActionOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueFloatExpressionChangeActionOperation.java @@ -32,7 +32,8 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Apply a value change on an integer variable. */ -public class ValueFloatExpressionChangeActionOperation implements ActionOperation { +public class ValueFloatExpressionChangeActionOperation extends Operation + implements ActionOperation { private static final int OP_CODE = Operations.VALUE_FLOAT_EXPRESSION_CHANGE_ACTION; int mTargetValueId = -1; @@ -88,6 +89,12 @@ public class ValueFloatExpressionChangeActionOperation implements ActionOperatio buffer.writeInt(value); } + /** + * 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 valueId = buffer.readInt(); int value = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueIntegerChangeActionOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueIntegerChangeActionOperation.java index c2cd2ab32bb7..fb13b42dbd21 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueIntegerChangeActionOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueIntegerChangeActionOperation.java @@ -32,7 +32,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Apply a value change on an integer variable. */ -public class ValueIntegerChangeActionOperation implements ActionOperation { +public class ValueIntegerChangeActionOperation extends Operation implements ActionOperation { private static final int OP_CODE = Operations.VALUE_INTEGER_CHANGE_ACTION; int mTargetValueId = -1; @@ -87,6 +87,12 @@ public class ValueIntegerChangeActionOperation implements ActionOperation { buffer.writeInt(value); } + /** + * 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 valueId = buffer.readInt(); int value = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueIntegerExpressionChangeActionOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueIntegerExpressionChangeActionOperation.java index 43fbb8546b9d..0fe88ad165a9 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueIntegerExpressionChangeActionOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueIntegerExpressionChangeActionOperation.java @@ -32,7 +32,8 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Apply a value change on an integer variable. */ -public class ValueIntegerExpressionChangeActionOperation implements ActionOperation { +public class ValueIntegerExpressionChangeActionOperation extends Operation + implements ActionOperation { private static final int OP_CODE = Operations.VALUE_INTEGER_EXPRESSION_CHANGE_ACTION; long mTargetValueId = -1; @@ -88,6 +89,12 @@ public class ValueIntegerExpressionChangeActionOperation implements ActionOperat buffer.writeLong(value); } + /** + * 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) { long valueId = buffer.readLong(); long value = buffer.readLong(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueStringChangeActionOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueStringChangeActionOperation.java index 1107889faaab..a8d3b87f04b4 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueStringChangeActionOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ValueStringChangeActionOperation.java @@ -32,7 +32,7 @@ import com.android.internal.widget.remotecompose.core.operations.utilities.Strin import java.util.List; /** Apply a value change on a string variable. */ -public class ValueStringChangeActionOperation implements ActionOperation { +public class ValueStringChangeActionOperation extends Operation implements ActionOperation { private static final int OP_CODE = Operations.VALUE_STRING_CHANGE_ACTION; int mTargetValueId = -1; @@ -91,6 +91,12 @@ public class ValueStringChangeActionOperation implements ActionOperation { buffer.writeInt(value); } + /** + * 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 valueId = buffer.readInt(); int value = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/WidthModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/WidthModifierOperation.java index 3c757a893a57..f6d743f599d3 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/WidthModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/WidthModifierOperation.java @@ -37,6 +37,11 @@ public class WidthModifierOperation extends DimensionModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } @@ -47,6 +52,12 @@ public class WidthModifierOperation extends DimensionModifierOperation { buffer.writeFloat(value); } + /** + * 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) { Type type = Type.fromInt(buffer.readInt()); float value = buffer.readFloat(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ZIndexModifierOperation.java b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ZIndexModifierOperation.java index 82c8f343565e..96ed2cda3e10 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ZIndexModifierOperation.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/layout/modifiers/ZIndexModifierOperation.java @@ -83,6 +83,11 @@ public class ZIndexModifierOperation extends DecoratorModifierOperation { return CLASS_NAME; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return OP_CODE; } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/paint/PaintBundle.java b/core/java/com/android/internal/widget/remotecompose/core/operations/paint/PaintBundle.java index 07cf7627e24d..95434696abdc 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/paint/PaintBundle.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/paint/PaintBundle.java @@ -498,6 +498,11 @@ public class PaintBundle { return ret; } + /** + * Write a bundle of paint changes to the buffer + * + * @param buffer bundle to write + */ public void writeBundle(@NonNull WireBuffer buffer) { buffer.writeInt(mPos); for (int index = 0; index < mPos; index++) { @@ -505,6 +510,11 @@ public class PaintBundle { } } + /** + * This will read the paint bundle off the wire buffer + * + * @param buffer the buffer to read + */ public void readBundle(@NonNull WireBuffer buffer) { int len = buffer.readInt(); if (len <= 0 || len > 1024) { @@ -587,6 +597,9 @@ public class PaintBundle { public static final int RADIAL_GRADIENT = 1; public static final int SWEEP_GRADIENT = 2; + private int mLastShaderSet = -1; + private boolean mColorFilterSet = false; + /** * sets a shader that draws a linear gradient along a line. * @@ -722,12 +735,14 @@ public class PaintBundle { mArray[mPos] = COLOR_FILTER_ID | (mode << 16); mPos++; mArray[mPos++] = color; + mColorFilterSet = true; } /** This sets the color filter to null */ public void clearColorFilter() { mArray[mPos] = CLEAR_COLOR_FILTER; mPos++; + mColorFilterSet = false; } /** @@ -843,6 +858,7 @@ public class PaintBundle { * @param shaderId */ public void setShader(int shaderId) { + mLastShaderSet = shaderId; mArray[mPos] = SHADER; mPos++; mArray[mPos] = shaderId; @@ -909,11 +925,23 @@ public class PaintBundle { mPos++; } + /** + * clear a series of paint parameters. Currently not used + * + * @param mask bit pattern of the attributes to clear + */ public void clear(long mask) { // unused for now } + /** Reset the content of the paint bundle so that it can be reused */ public void reset() { mPos = 0; + if (mColorFilterSet) { + clearColorFilter(); + } + if (mLastShaderSet != -1 && mLastShaderSet != 0) { + setShader(0); + } } public static @NonNull String blendModeString(int mode) { diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/AnimatedFloatExpression.java b/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/AnimatedFloatExpression.java index e5633c70faee..a56874781e4a 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/AnimatedFloatExpression.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/AnimatedFloatExpression.java @@ -18,7 +18,6 @@ package com.android.internal.widget.remotecompose.core.operations.utilities; import android.annotation.NonNull; import android.annotation.Nullable; -import com.android.internal.widget.remotecompose.core.operations.Utils; import com.android.internal.widget.remotecompose.core.operations.utilities.easing.MonotonicSpline; /** high performance floating point expression evaluator used in animation */ @@ -141,7 +140,7 @@ public class AnimatedFloatExpression { for (int i = 0; i < mStack.length; i++) { float v = mStack[i]; if (Float.isNaN(v)) { - sp = mOps[fromNaN(v) - OFFSET].eval(sp); + sp = opEval(sp, fromNaN(v)); } else { mStack[++sp] = v; } @@ -170,7 +169,7 @@ public class AnimatedFloatExpression { if (Float.isNaN(v)) { int id = fromNaN(v); if ((id & NanMap.ID_REGION_MASK) != NanMap.ID_REGION_ARRAY) { - sp = mOps[id - OFFSET].eval(sp); + sp = opEval(sp, id); } else { mStack[++sp] = v; } @@ -199,7 +198,7 @@ public class AnimatedFloatExpression { if (Float.isNaN(v)) { int id = fromNaN(v); if ((id & NanMap.ID_REGION_MASK) != NanMap.ID_REGION_ARRAY) { - sp = mOps[id - OFFSET].eval(sp); + sp = opEval(sp, id); } else { mStack[++sp] = v; } @@ -228,10 +227,11 @@ public class AnimatedFloatExpression { mStack = mLocalStack; mVar = var; int sp = -1; + for (int i = 0; i < len; i++) { float v = mStack[i]; if (Float.isNaN(v)) { - sp = mOps[fromNaN(v) - OFFSET].eval(sp); + sp = opEval(sp, fromNaN(v)); } else { mStack[++sp] = v; } @@ -250,9 +250,10 @@ public class AnimatedFloatExpression { mStack = exp; mVar = var; int sp = -1; + for (float v : exp) { if (Float.isNaN(v)) { - sp = mOps[fromNaN(v) - OFFSET].eval(sp); + sp = opEval(sp, fromNaN(v)); } else { System.out.print(" " + v); mStack[++sp] = v; @@ -261,294 +262,6 @@ public class AnimatedFloatExpression { return mStack[sp]; } - @NonNull Op[] mOps; - - { - Op mADD = - (sp) -> { // ADD - mStack[sp - 1] = mStack[sp - 1] + mStack[sp]; - return sp - 1; - }; - Op mSUB = - (sp) -> { // SUB - mStack[sp - 1] = mStack[sp - 1] - mStack[sp]; - return sp - 1; - }; - Op mMUL = - (sp) -> { // MUL - mStack[sp - 1] = mStack[sp - 1] * mStack[sp]; - return sp - 1; - }; - Op mDIV = - (sp) -> { // DIV - mStack[sp - 1] = mStack[sp - 1] / mStack[sp]; - return sp - 1; - }; - Op mMOD = - (sp) -> { // MOD - mStack[sp - 1] = mStack[sp - 1] % mStack[sp]; - return sp - 1; - }; - Op mMIN = - (sp) -> { // MIN - mStack[sp - 1] = (float) Math.min(mStack[sp - 1], mStack[sp]); - return sp - 1; - }; - Op mMAX = - (sp) -> { // MAX - mStack[sp - 1] = (float) Math.max(mStack[sp - 1], mStack[sp]); - return sp - 1; - }; - Op mPOW = - (sp) -> { // POW - mStack[sp - 1] = (float) Math.pow(mStack[sp - 1], mStack[sp]); - return sp - 1; - }; - Op mSQRT = - (sp) -> { // SQRT - mStack[sp] = (float) Math.sqrt(mStack[sp]); - return sp; - }; - Op mABS = - (sp) -> { // ABS - mStack[sp] = (float) Math.abs(mStack[sp]); - return sp; - }; - Op mSIGN = - (sp) -> { // SIGN - mStack[sp] = (float) Math.signum(mStack[sp]); - return sp; - }; - Op mCOPY_SIGN = - (sp) -> { // copySign - mStack[sp - 1] = (float) Math.copySign(mStack[sp - 1], mStack[sp]); - return sp - 1; - }; - Op mEXP = - (sp) -> { // EXP - mStack[sp] = (float) Math.exp(mStack[sp]); - return sp; - }; - Op mFLOOR = - (sp) -> { // FLOOR - mStack[sp] = (float) Math.floor(mStack[sp]); - return sp; - }; - Op mLOG = - (sp) -> { // LOG - mStack[sp] = (float) Math.log10(mStack[sp]); - return sp; - }; - Op mLN = - (sp) -> { // LN - mStack[sp] = (float) Math.log(mStack[sp]); - return sp; - }; - Op mROUND = - (sp) -> { // ROUND - mStack[sp] = (float) Math.round(mStack[sp]); - return sp; - }; - Op mSIN = - (sp) -> { // SIN - mStack[sp] = (float) Math.sin(mStack[sp]); - return sp; - }; - Op mCOS = - (sp) -> { // COS - mStack[sp] = (float) Math.cos(mStack[sp]); - return sp; - }; - Op mTAN = - (sp) -> { // TAN - mStack[sp] = (float) Math.tan(mStack[sp]); - return sp; - }; - Op mASIN = - (sp) -> { // ASIN - mStack[sp] = (float) Math.asin(mStack[sp]); - return sp; - }; - Op mACOS = - (sp) -> { // ACOS - mStack[sp] = (float) Math.acos(mStack[sp]); - return sp; - }; - Op mATAN = - (sp) -> { // ATAN - mStack[sp] = (float) Math.atan(mStack[sp]); - return sp; - }; - Op mATAN2 = - (sp) -> { // ATAN2 - mStack[sp - 1] = (float) Math.atan2(mStack[sp - 1], mStack[sp]); - return sp - 1; - }; - Op mMAD = - (sp) -> { // MAD - mStack[sp - 2] = mStack[sp] + mStack[sp - 1] * mStack[sp - 2]; - return sp - 2; - }; - Op mTERNARY_CONDITIONAL = - (sp) -> { // TERNARY_CONDITIONAL - mStack[sp - 2] = (mStack[sp] > 0) ? mStack[sp - 1] : mStack[sp - 2]; - return sp - 2; - }; - Op mCLAMP = - (sp) -> { // CLAMP (min, max, value) - mStack[sp - 2] = Math.min(Math.max(mStack[sp - 2], mStack[sp]), mStack[sp - 1]); - return sp - 2; - }; - Op mCBRT = - (sp) -> { // CBRT is cube root - mStack[sp] = (float) Math.pow(mStack[sp], 1 / 3.); - return sp; - }; - Op mDEG = - (sp) -> { // DEG - mStack[sp] = mStack[sp] * FP_TO_RAD; - return sp; - }; - Op mRAD = - (sp) -> { // RAD - mStack[sp] = mStack[sp] * FP_TO_DEG; - return sp; - }; - Op mCEIL = - (sp) -> { // CEIL - mStack[sp] = (float) Math.ceil(mStack[sp]); - return sp; - }; - Op mA_DEREF = - (sp) -> { // A_DEREF - Utils.log(" \n >>> DREF " + Integer.toHexString(fromNaN(mStack[sp - 1]))); - Utils.log(" >>> DREF " + mStack[sp] + " " + mStack[sp - 1]); - int id = fromNaN(mStack[sp - 1]); - mStack[sp - 1] = mCollectionsAccess.getFloatValue(id, (int) mStack[sp]); - return sp - 1; - }; - Op mA_MAX = - (sp) -> { // A_MAX - int id = fromNaN(mStack[sp]); - float[] array = mCollectionsAccess.getFloats(id); - float max = array[0]; - for (int i = 1; i < array.length; i++) { - max = Math.max(max, array[i]); - } - mStack[sp] = max; - return sp; - }; - Op mA_MIN = - (sp) -> { // A_MIN - int id = fromNaN(mStack[sp]); - float[] array = mCollectionsAccess.getFloats(id); - if (array.length == 0) { - return sp; - } - float min = array[0]; - for (int i = 1; i < array.length; i++) { - min = Math.min(min, array[i]); - } - mStack[sp] = min; - return sp; - }; - Op mA_SUM = - (sp) -> { // A_SUM - int id = fromNaN(mStack[sp]); - float[] array = mCollectionsAccess.getFloats(id); - float sum = 0; - for (int i = 0; i < array.length; i++) { - sum += array[i]; - } - mStack[sp] = sum; - return sp; - }; - Op mA_AVG = - (sp) -> { // A_AVG - int id = fromNaN(mStack[sp]); - float[] array = mCollectionsAccess.getFloats(id); - float sum = 0; - for (int i = 0; i < array.length; i++) { - sum += array[i]; - } - mStack[sp] = sum / array.length; - return sp; - }; - Op mA_LEN = - (sp) -> { // A_LEN - int id = fromNaN(mStack[sp]); - mStack[sp] = mCollectionsAccess.getListLength(id); - return sp; - }; - Op mA_SPLINE = - (sp) -> { // A_SPLINE - int id = fromNaN(mStack[sp - 1]); - mStack[sp - 1] = getSplineValue(id, mStack[sp]); - return sp - 1; - }; - Op mFIRST_VAR = - (sp) -> { // FIRST_VAR - mStack[sp] = mVar[0]; - return sp; - }; - Op mSECOND_VAR = - (sp) -> { // SECOND_VAR - mStack[sp] = mVar[1]; - return sp; - }; - Op mTHIRD_VAR = - (sp) -> { // THIRD_VAR - mStack[sp] = mVar[2]; - return sp; - }; - - Op[] ops = { - null, - mADD, - mSUB, - mMUL, - mDIV, - mMOD, - mMIN, - mMAX, - mPOW, - mSQRT, - mABS, - mSIGN, - mCOPY_SIGN, - mEXP, - mFLOOR, - mLOG, - mLN, - mROUND, - mSIN, - mCOS, - mTAN, - mASIN, - mACOS, - mATAN, - mATAN2, - mMAD, - mTERNARY_CONDITIONAL, - mCLAMP, - mCBRT, - mDEG, - mRAD, - mCEIL, - mA_DEREF, - mA_MAX, - mA_MIN, - mA_SUM, - mA_AVG, - mA_LEN, - mA_SPLINE, - mFIRST_VAR, - mSECOND_VAR, - mTHIRD_VAR, - }; - mOps = ops; - } - static { int k = 0; sNames.put(k++, "NOP"); @@ -765,4 +478,248 @@ public class AnimatedFloatExpression { int b = Float.floatToRawIntBits(v); return b & 0x7FFFFF; } + + // ================= New approach ======== + private static final int OP_ADD = OFFSET + 1; + private static final int OP_SUB = OFFSET + 2; + private static final int OP_MUL = OFFSET + 3; + private static final int OP_DIV = OFFSET + 4; + private static final int OP_MOD = OFFSET + 5; + private static final int OP_MIN = OFFSET + 6; + private static final int OP_MAX = OFFSET + 7; + private static final int OP_POW = OFFSET + 8; + private static final int OP_SQRT = OFFSET + 9; + private static final int OP_ABS = OFFSET + 10; + private static final int OP_SIGN = OFFSET + 11; + private static final int OP_COPY_SIGN = OFFSET + 12; + private static final int OP_EXP = OFFSET + 13; + private static final int OP_FLOOR = OFFSET + 14; + private static final int OP_LOG = OFFSET + 15; + private static final int OP_LN = OFFSET + 16; + private static final int OP_ROUND = OFFSET + 17; + private static final int OP_SIN = OFFSET + 18; + private static final int OP_COS = OFFSET + 19; + private static final int OP_TAN = OFFSET + 20; + private static final int OP_ASIN = OFFSET + 21; + private static final int OP_ACOS = OFFSET + 22; + private static final int OP_ATAN = OFFSET + 23; + private static final int OP_ATAN2 = OFFSET + 24; + private static final int OP_MAD = OFFSET + 25; + private static final int OP_TERNARY_CONDITIONAL = OFFSET + 26; + private static final int OP_CLAMP = OFFSET + 27; + private static final int OP_CBRT = OFFSET + 28; + private static final int OP_DEG = OFFSET + 29; + private static final int OP_RAD = OFFSET + 30; + private static final int OP_CEIL = OFFSET + 31; + private static final int OP_A_DEREF = OFFSET + 32; + private static final int OP_A_MAX = OFFSET + 33; + private static final int OP_A_MIN = OFFSET + 34; + private static final int OP_A_SUM = OFFSET + 35; + private static final int OP_A_AVG = OFFSET + 36; + private static final int OP_A_LEN = OFFSET + 37; + private static final int OP_A_SPLINE = OFFSET + 38; + private static final int OP_FIRST_VAR = OFFSET + 39; + private static final int OP_SECOND_VAR = OFFSET + 40; + private static final int OP_THIRD_VAR = OFFSET + 41; + + int opEval(int sp, int id) { + float[] array; + + switch (id) { + case OP_ADD: + mStack[sp - 1] = mStack[sp - 1] + mStack[sp]; + return sp - 1; + + case OP_SUB: + mStack[sp - 1] = mStack[sp - 1] - mStack[sp]; + return sp - 1; + + case OP_MUL: + mStack[sp - 1] = mStack[sp - 1] * mStack[sp]; + return sp - 1; + + case OP_DIV: + mStack[sp - 1] = mStack[sp - 1] / mStack[sp]; + return sp - 1; + + case OP_MOD: + mStack[sp - 1] = mStack[sp - 1] % mStack[sp]; + return sp - 1; + + case OP_MIN: + mStack[sp - 1] = (float) Math.min(mStack[sp - 1], mStack[sp]); + return sp - 1; + + case OP_MAX: + mStack[sp - 1] = (float) Math.max(mStack[sp - 1], mStack[sp]); + return sp - 1; + + case OP_POW: + mStack[sp - 1] = (float) Math.pow(mStack[sp - 1], mStack[sp]); + return sp - 1; + + case OP_SQRT: + mStack[sp] = (float) Math.sqrt(mStack[sp]); + return sp; + + case OP_ABS: + mStack[sp] = (float) Math.abs(mStack[sp]); + return sp; + + case OP_SIGN: + mStack[sp] = (float) Math.signum(mStack[sp]); + return sp; + + case OP_COPY_SIGN: + mStack[sp - 1] = (float) Math.copySign(mStack[sp - 1], mStack[sp]); + return sp - 1; + + case OP_EXP: + mStack[sp] = (float) Math.exp(mStack[sp]); + return sp; + + case OP_FLOOR: + mStack[sp] = (float) Math.floor(mStack[sp]); + return sp; + + case OP_LOG: + mStack[sp] = (float) Math.log10(mStack[sp]); + return sp; + + case OP_LN: + mStack[sp] = (float) Math.log(mStack[sp]); + return sp; + + case OP_ROUND: + mStack[sp] = (float) Math.round(mStack[sp]); + return sp; + + case OP_SIN: + mStack[sp] = (float) Math.sin(mStack[sp]); + return sp; + + case OP_COS: + mStack[sp] = (float) Math.cos(mStack[sp]); + return sp; + + case OP_TAN: + mStack[sp] = (float) Math.tan(mStack[sp]); + return sp; + + case OP_ASIN: + mStack[sp] = (float) Math.asin(mStack[sp]); + return sp; + + case OP_ACOS: + mStack[sp] = (float) Math.acos(mStack[sp]); + return sp; + + case OP_ATAN: + mStack[sp] = (float) Math.atan(mStack[sp]); + return sp; + + case OP_ATAN2: + mStack[sp - 1] = (float) Math.atan2(mStack[sp - 1], mStack[sp]); + return sp - 1; + + case OP_MAD: + mStack[sp - 2] = mStack[sp] + mStack[sp - 1] * mStack[sp - 2]; + return sp - 2; + + case OP_TERNARY_CONDITIONAL: + mStack[sp - 2] = (mStack[sp] > 0) ? mStack[sp - 1] : mStack[sp - 2]; + return sp - 2; + + case OP_CLAMP: + mStack[sp - 2] = Math.min(Math.max(mStack[sp - 2], mStack[sp]), mStack[sp - 1]); + return sp - 2; + + case OP_CBRT: + mStack[sp] = (float) Math.pow(mStack[sp], 1 / 3.); + return sp; + + case OP_DEG: + mStack[sp] = mStack[sp] * FP_TO_RAD; + return sp; + + case OP_RAD: + mStack[sp] = mStack[sp] * FP_TO_DEG; + return sp; + + case OP_CEIL: + mStack[sp] = (float) Math.ceil(mStack[sp]); + return sp; + + case OP_A_DEREF: + id = fromNaN(mStack[sp - 1]); + mStack[sp - 1] = mCollectionsAccess.getFloatValue(id, (int) mStack[sp]); + return sp - 1; + + case OP_A_MAX: + id = fromNaN(mStack[sp]); + array = mCollectionsAccess.getFloats(id); + float max = array[0]; + for (int i = 1; i < array.length; i++) { + max = Math.max(max, array[i]); + } + mStack[sp] = max; + return sp; + + case OP_A_MIN: + id = fromNaN(mStack[sp]); + array = mCollectionsAccess.getFloats(id); + if (array.length == 0) { + return sp; + } + float min = array[0]; + for (int i = 1; i < array.length; i++) { + min = Math.min(min, array[i]); + } + mStack[sp] = min; + return sp; + + case OP_A_SUM: + id = fromNaN(mStack[sp]); + array = mCollectionsAccess.getFloats(id); + float sum = 0; + for (int i = 0; i < array.length; i++) { + sum += array[i]; + } + mStack[sp] = sum; + return sp; + + case OP_A_AVG: + id = fromNaN(mStack[sp]); + array = mCollectionsAccess.getFloats(id); + sum = 0; + for (int i = 0; i < array.length; i++) { + sum += array[i]; + } + mStack[sp] = sum / array.length; + return sp; + + case OP_A_LEN: + id = fromNaN(mStack[sp]); + mStack[sp] = mCollectionsAccess.getListLength(id); + return sp; + + case OP_A_SPLINE: + id = fromNaN(mStack[sp - 1]); + mStack[sp - 1] = getSplineValue(id, mStack[sp]); + return sp - 1; + + case OP_FIRST_VAR: + mStack[sp] = mVar[0]; + return sp; + + case OP_SECOND_VAR: + mStack[sp] = mVar[1]; + return sp; + + case OP_THIRD_VAR: + mStack[sp] = mVar[2]; + return sp; + } + return sp; + } } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/CollectionsAccess.java b/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/CollectionsAccess.java index 4f1287265d75..b92f96f63eb9 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/CollectionsAccess.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/CollectionsAccess.java @@ -24,13 +24,39 @@ import android.annotation.Nullable; public interface CollectionsAccess { float getFloatValue(int id, int index); + /** + * Get the array of float if it is a float array + * + * @param id the id of the float array + * @return + */ @Nullable float[] getFloats(int id); + /** + * Get the number of entries in the list + * + * @param id the id of the list + * @return + */ int getListLength(int id); + /** + * get the id of an entry if the list is a list of id's + * + * @param listId the list id + * @param index the index into the list + * @return + */ int getId(int listId, int index); + /** + * Get the value as an integer + * + * @param listId the list id to access + * @param index the index into the list + * @return + */ default int getIntValue(int listId, int index) { return (int) getFloatValue(listId, index); } diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/IntegerExpressionEvaluator.java b/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/IntegerExpressionEvaluator.java index f73ab39e496e..0a3351188d9e 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/IntegerExpressionEvaluator.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/IntegerExpressionEvaluator.java @@ -82,7 +82,7 @@ public class IntegerExpressionEvaluator { for (int i = 0; i < mStack.length; i++) { int v = mStack[i]; if (((1 << i) & mask) != 0) { - sp = mOps[v - OFFSET].eval(sp); + sp = opEval(sp, v); } else { mStack[++sp] = v; } @@ -107,7 +107,7 @@ public class IntegerExpressionEvaluator { for (int i = 0; i < len; i++) { int v = mStack[i]; if (((1 << i) & mask) != 0) { - sp = mOps[v - OFFSET].eval(sp); + sp = opEval(sp, v); } else { mStack[++sp] = v; } @@ -130,7 +130,7 @@ public class IntegerExpressionEvaluator { for (int i = 0; i < exp.length; i++) { int v = mStack[i]; if (((1 << i) & opMask) != 0) { - sp = mOps[v - OFFSET].eval(sp); + sp = opEval(sp, v); } else { mStack[++sp] = v; } @@ -138,171 +138,140 @@ public class IntegerExpressionEvaluator { return mStack[sp]; } - @NonNull Op[] mOps; - - { - Op mADD = - (sp) -> { // ADD - mStack[sp - 1] = mStack[sp - 1] + mStack[sp]; - return sp - 1; - }; - Op mSUB = - (sp) -> { // SUB - mStack[sp - 1] = mStack[sp - 1] - mStack[sp]; - return sp - 1; - }; - Op mMUL = - (sp) -> { // MUL - mStack[sp - 1] = mStack[sp - 1] * mStack[sp]; - return sp - 1; - }; - Op mDIV = - (sp) -> { // DIV - mStack[sp - 1] = mStack[sp - 1] / mStack[sp]; - return sp - 1; - }; - Op mMOD = - (sp) -> { // MOD - mStack[sp - 1] = mStack[sp - 1] % mStack[sp]; - return sp - 1; - }; - Op mSHL = - (sp) -> { // SHL - mStack[sp - 1] = mStack[sp - 1] << mStack[sp]; - return sp - 1; - }; - Op mSHR = - (sp) -> { // SHR - mStack[sp - 1] = mStack[sp - 1] >> mStack[sp]; - return sp - 1; - }; - Op mUSHR = - (sp) -> { // USHR - mStack[sp - 1] = mStack[sp - 1] >>> mStack[sp]; - return sp - 1; - }; - Op mOR = - (sp) -> { // OR - mStack[sp - 1] = mStack[sp - 1] | mStack[sp]; - return sp - 1; - }; - Op mAND = - (sp) -> { // AND - mStack[sp - 1] = mStack[sp - 1] & mStack[sp]; - return sp - 1; - }; - Op mXOR = - (sp) -> { // XOR - mStack[sp - 1] = mStack[sp - 1] ^ mStack[sp]; - return sp - 1; - }; - Op mCOPY_SIGN = - (sp) -> { // COPY_SIGN copy the sign via bit manipulation - mStack[sp - 1] = (mStack[sp - 1] ^ (mStack[sp] >> 31)) - (mStack[sp] >> 31); - return sp - 1; - }; - Op mMIN = - (sp) -> { // MIN - mStack[sp - 1] = Math.min(mStack[sp - 1], mStack[sp]); - return sp - 1; - }; - Op mMAX = - (sp) -> { // MAX - mStack[sp - 1] = Math.max(mStack[sp - 1], mStack[sp]); - return sp - 1; - }; - Op mNEG = - (sp) -> { // NEG - mStack[sp] = -mStack[sp]; - return sp; - }; - Op mABS = - (sp) -> { // ABS - mStack[sp] = Math.abs(mStack[sp]); - return sp; - }; - Op mINCR = - (sp) -> { // INCR - mStack[sp] = mStack[sp] + 1; - return sp; - }; - Op mDECR = - (sp) -> { // DECR - mStack[sp] = mStack[sp] - 1; - return sp; - }; - Op mNOT = - (sp) -> { // NOT - mStack[sp] = ~mStack[sp]; - return sp; - }; - Op mSIGN = - (sp) -> { // SIGN x<0 = -1,x==0 = 0 , x>0 = 1 - mStack[sp] = (mStack[sp] >> 31) | (-mStack[sp] >>> 31); - return sp; - }; - Op mCLAMP = - (sp) -> { // CLAMP(min,max, val) - mStack[sp - 2] = Math.min(Math.max(mStack[sp - 2], mStack[sp]), mStack[sp - 1]); - return sp - 2; - }; - Op mTERNARY_CONDITIONAL = - (sp) -> { // TERNARY_CONDITIONAL - mStack[sp - 2] = (mStack[sp] > 0) ? mStack[sp - 1] : mStack[sp - 2]; - return sp - 2; - }; - Op mMAD = - (sp) -> { // MAD - mStack[sp - 2] = mStack[sp] + mStack[sp - 1] * mStack[sp - 2]; - return sp - 2; - }; - Op mFIRST_VAR = - (sp) -> { // FIRST_VAR - mStack[sp] = mVar[0]; - return sp; - }; - Op mSECOND_VAR = - (sp) -> { // SECOND_VAR - mStack[sp] = mVar[1]; - return sp; - }; - Op mTHIRD_VAR = - (sp) -> { // THIRD_VAR - mStack[sp] = mVar[2]; - return sp; - }; - - Op[] ops = { - null, - mADD, - mSUB, - mMUL, - mDIV, - mMOD, - mSHL, - mSHR, - mUSHR, - mOR, - mAND, - mXOR, - mCOPY_SIGN, - mMIN, - mMAX, - mNEG, - mABS, - mINCR, - mDECR, - mNOT, - mSIGN, - mCLAMP, - mTERNARY_CONDITIONAL, - mMAD, - mFIRST_VAR, - mSECOND_VAR, - mTHIRD_VAR, - }; - - mOps = ops; + private static final int OP_ADD = OFFSET + 1; + private static final int OP_SUB = OFFSET + 2; + private static final int OP_MUL = OFFSET + 3; + private static final int OP_DIV = OFFSET + 4; + private static final int OP_MOD = OFFSET + 5; + private static final int OP_SHL = OFFSET + 6; + private static final int OP_SHR = OFFSET + 7; + private static final int OP_USHR = OFFSET + 8; + private static final int OP_OR = OFFSET + 9; + private static final int OP_AND = OFFSET + 10; + private static final int OP_XOR = OFFSET + 11; + private static final int OP_COPY_SIGN = OFFSET + 12; + private static final int OP_MIN = OFFSET + 13; + private static final int OP_MAX = OFFSET + 14; + private static final int OP_NEG = OFFSET + 15; + private static final int OP_ABS = OFFSET + 16; + private static final int OP_INCR = OFFSET + 17; + private static final int OP_DECR = OFFSET + 18; + private static final int OP_NOT = OFFSET + 19; + private static final int OP_SIGN = OFFSET + 20; + private static final int OP_CLAMP = OFFSET + 21; + private static final int OP_TERNARY_CONDITIONAL = OFFSET + 22; + private static final int OP_MAD = OFFSET + 23; + private static final int OP_FIRST_VAR = OFFSET + 24; + private static final int OP_SECOND_VAR = OFFSET + 25; + private static final int OP_THIRD_VAR = OFFSET + 26; + + int opEval(int sp, int id) { + switch (id) { + case OP_ADD: // ADD + mStack[sp - 1] = mStack[sp - 1] + mStack[sp]; + return sp - 1; + + case OP_SUB: // SUB + mStack[sp - 1] = mStack[sp - 1] - mStack[sp]; + return sp - 1; + + case OP_MUL: // MUL + mStack[sp - 1] = mStack[sp - 1] * mStack[sp]; + return sp - 1; + + case OP_DIV: // DIV + mStack[sp - 1] = mStack[sp - 1] / mStack[sp]; + return sp - 1; + + case OP_MOD: // MOD + mStack[sp - 1] = mStack[sp - 1] % mStack[sp]; + return sp - 1; + + case OP_SHL: // SHL + mStack[sp - 1] = mStack[sp - 1] << mStack[sp]; + return sp - 1; + + case OP_SHR: // SHR + mStack[sp - 1] = mStack[sp - 1] >> mStack[sp]; + return sp - 1; + + case OP_USHR: // USHR + mStack[sp - 1] = mStack[sp - 1] >>> mStack[sp]; + return sp - 1; + + case OP_OR: // OR + mStack[sp - 1] = mStack[sp - 1] | mStack[sp]; + return sp - 1; + + case OP_AND: // AND + mStack[sp - 1] = mStack[sp - 1] & mStack[sp]; + return sp - 1; + + case OP_XOR: // XOR + mStack[sp - 1] = mStack[sp - 1] ^ mStack[sp]; + return sp - 1; + + case OP_COPY_SIGN: // COPY_SIGN copy the sign via bit manipulation + mStack[sp - 1] = (mStack[sp - 1] ^ (mStack[sp] >> 31)) - (mStack[sp] >> 31); + return sp - 1; + + case OP_MIN: // MIN + mStack[sp - 1] = Math.min(mStack[sp - 1], mStack[sp]); + return sp - 1; + + case OP_MAX: // MAX + mStack[sp - 1] = Math.max(mStack[sp - 1], mStack[sp]); + return sp - 1; + + case OP_NEG: // NEG + mStack[sp] = -mStack[sp]; + return sp; + + case OP_ABS: // ABS + mStack[sp] = Math.abs(mStack[sp]); + return sp; + + case OP_INCR: // INCR + mStack[sp] = mStack[sp] + 1; + return sp; + + case OP_DECR: // DECR + mStack[sp] = mStack[sp] - 1; + return sp; + + case OP_NOT: // NOT + mStack[sp] = ~mStack[sp]; + return sp; + + case OP_SIGN: // SIGN x<0 = -1,x==0 = 0 , x>0 = 1 + mStack[sp] = (mStack[sp] >> 31) | (-mStack[sp] >>> 31); + return sp; + + case OP_CLAMP: // CLAMP(min,max, val) + mStack[sp - 2] = Math.min(Math.max(mStack[sp - 2], mStack[sp]), mStack[sp - 1]); + return sp - 2; + + case OP_TERNARY_CONDITIONAL: // TERNARY_CONDITIONAL + mStack[sp - 2] = (mStack[sp] > 0) ? mStack[sp - 1] : mStack[sp - 2]; + return sp - 2; + + case OP_MAD: // MAD + mStack[sp - 2] = mStack[sp] + mStack[sp - 1] * mStack[sp - 2]; + return sp - 2; + + case OP_FIRST_VAR: // FIRST_VAR + mStack[sp] = mVar[0]; + return sp; + + case OP_SECOND_VAR: // SECOND_VAR + mStack[sp] = mVar[1]; + return sp; + + case OP_THIRD_VAR: // THIRD_VAR + mStack[sp] = mVar[2]; + return sp; + } + return 0; } static { diff --git a/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/touch/VelocityEasing.java b/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/touch/VelocityEasing.java index 7e02bc9416a9..c7e2442221cd 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/touch/VelocityEasing.java +++ b/core/java/com/android/internal/widget/remotecompose/core/operations/utilities/touch/VelocityEasing.java @@ -31,6 +31,11 @@ package com.android.internal.widget.remotecompose.core.operations.utilities.touc * limitations under the License. */ +/** + * This computes an form of easing such that the values constrained to be consistent in velocity The + * easing function is also constrained by the configure To have: a maximum time to stop, a maximum + * velocity, a maximum acceleration + */ public class VelocityEasing { private float mStartPos = 0; private float mStartV = 0; @@ -46,6 +51,11 @@ public class VelocityEasing { private boolean mOneDimension = true; private float mTotalEasingDuration = 0; + /** + * get the duration the easing will take + * + * @return the duration for the easing + */ public float getDuration() { if (mEasing != null) { return mTotalEasingDuration; @@ -53,6 +63,12 @@ public class VelocityEasing { return mDuration; } + /** + * Get the velocity at time t + * + * @param t time in seconds + * @return the velocity units/second + */ public float getV(float t) { if (mEasing == null) { for (int i = 0; i < mNumberOfStages; i++) { @@ -71,6 +87,12 @@ public class VelocityEasing { return (float) getEasingDiff((t - mStage[lastStages].mStartTime)); } + /** + * Get the position t seconds after the configure + * + * @param t time in seconds + * @return the position at time t + */ public float getPos(float t) { if (mEasing == null) { for (int i = 0; i < mNumberOfStages; i++) { @@ -91,6 +113,7 @@ public class VelocityEasing { return ret; } + @Override public String toString() { var s = " "; for (int i = 0; i < mNumberOfStages; i++) { @@ -100,6 +123,17 @@ public class VelocityEasing { return s; } + /** + * Configure the Velocity easing curve The system is in arbitrary units + * + * @param currentPos the current position + * @param destination the destination + * @param currentVelocity the current velocity units/seconds + * @param maxTime the max time to achieve position + * @param maxAcceleration the max acceleration units/s^2 + * @param maxVelocity the maximum velocity + * @param easing End in using this easing curve + */ public void config( float currentPos, float destination, diff --git a/core/java/com/android/internal/widget/remotecompose/core/types/BooleanConstant.java b/core/java/com/android/internal/widget/remotecompose/core/types/BooleanConstant.java index 4af79f3ce4f4..975213f76bd2 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/types/BooleanConstant.java +++ b/core/java/com/android/internal/widget/remotecompose/core/types/BooleanConstant.java @@ -29,7 +29,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Used to represent a boolean */ -public class BooleanConstant implements Operation { +public class BooleanConstant extends Operation { private static final int OP_CODE = Operations.DATA_BOOLEAN; private boolean mValue = false; private int mId; @@ -73,6 +73,11 @@ public class BooleanConstant implements Operation { return "OrigamiBoolean"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.DATA_BOOLEAN; } @@ -90,6 +95,12 @@ public class BooleanConstant implements Operation { buffer.writeBoolean(value); } + /** + * 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 id = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/types/IntegerConstant.java b/core/java/com/android/internal/widget/remotecompose/core/types/IntegerConstant.java index 613e7328e24a..210a15ac7ca4 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/types/IntegerConstant.java +++ b/core/java/com/android/internal/widget/remotecompose/core/types/IntegerConstant.java @@ -29,7 +29,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Represents a single integer typically used for states or named for input into the system */ -public class IntegerConstant implements Operation { +public class IntegerConstant extends Operation { private int mValue = 0; private int mId; @@ -65,6 +65,11 @@ public class IntegerConstant implements Operation { return "IntegerConstant"; } + /** + * The OP_CODE for this command + * + * @return the opcode + */ public static int id() { return Operations.DATA_INT; } @@ -82,6 +87,12 @@ public class IntegerConstant implements Operation { buffer.writeInt(value); } + /** + * 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 id = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/core/types/LongConstant.java b/core/java/com/android/internal/widget/remotecompose/core/types/LongConstant.java index 745caa384e4c..9875c935c112 100644 --- a/core/java/com/android/internal/widget/remotecompose/core/types/LongConstant.java +++ b/core/java/com/android/internal/widget/remotecompose/core/types/LongConstant.java @@ -29,7 +29,7 @@ import com.android.internal.widget.remotecompose.core.documentation.DocumentedOp import java.util.List; /** Used to represent a long */ -public class LongConstant implements Operation { +public class LongConstant extends Operation { private static final int OP_CODE = Operations.DATA_LONG; private long mValue; private int mId; @@ -83,6 +83,12 @@ public class LongConstant implements Operation { buffer.writeLong(value); } + /** + * 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 id = buffer.readInt(); diff --git a/core/java/com/android/internal/widget/remotecompose/player/RemoteComposePlayer.java b/core/java/com/android/internal/widget/remotecompose/player/RemoteComposePlayer.java index 648f7bf06dd4..19b4b36b504c 100644 --- a/core/java/com/android/internal/widget/remotecompose/player/RemoteComposePlayer.java +++ b/core/java/com/android/internal/widget/remotecompose/player/RemoteComposePlayer.java @@ -659,4 +659,14 @@ public class RemoteComposePlayer extends FrameLayout { } mListener = null; } + + /** + * This returns the amount of time in ms the player used to evalueate a pass it is averaged over + * a number of evaluations. + * + * @return time in ms + */ + public float getEvalTime() { + return mInner.getEvalTime(); + } } diff --git a/core/java/com/android/internal/widget/remotecompose/player/platform/AndroidPaintContext.java b/core/java/com/android/internal/widget/remotecompose/player/platform/AndroidPaintContext.java index 3c91cffcec3f..bc7d5e108e1d 100644 --- a/core/java/com/android/internal/widget/remotecompose/player/platform/AndroidPaintContext.java +++ b/core/java/com/android/internal/widget/remotecompose/player/platform/AndroidPaintContext.java @@ -529,6 +529,7 @@ public class AndroidPaintContext extends PaintContext { @Override public void setImageFilterQuality(int quality) { Utils.log(" quality =" + quality); + mPaint.setFilterBitmap(quality == 1); } @Override @@ -711,20 +712,32 @@ public class AndroidPaintContext extends PaintContext { } @Override + public void tweenPath(int out, int path1, int path2, float tween) { + float[] p = getPathArray(path1, path2, tween); + AndroidRemoteContext androidContext = (AndroidRemoteContext) mContext; + androidContext.mRemoteComposeState.putPathData(out, p); + } + + @Override public void reset() { mPaint.reset(); } private Path getPath(int path1Id, int path2Id, float tween, float start, float end) { + return getPath(getPathArray(path1Id, path2Id, tween), start, end); + } + + private float[] getPathArray(int path1Id, int path2Id, float tween) { + AndroidRemoteContext androidContext = (AndroidRemoteContext) mContext; if (tween == 0.0f) { - return getPath(path1Id, start, end); + return androidContext.mRemoteComposeState.getPathData(path1Id); } if (tween == 1.0f) { - return getPath(path2Id, start, end); + return androidContext.mRemoteComposeState.getPathData(path2Id); } - AndroidRemoteContext androidContext = (AndroidRemoteContext) mContext; - float[] data1 = (float[]) androidContext.mRemoteComposeState.getFromId(path1Id); - float[] data2 = (float[]) androidContext.mRemoteComposeState.getFromId(path2Id); + + float[] data1 = androidContext.mRemoteComposeState.getPathData(path1Id); + float[] data2 = androidContext.mRemoteComposeState.getPathData(path2Id); float[] tmp = new float[data2.length]; for (int i = 0; i < tmp.length; i++) { if (Float.isNaN(data1[i]) || Float.isNaN(data2[i])) { @@ -733,6 +746,10 @@ public class AndroidPaintContext extends PaintContext { tmp[i] = (data2[i] - data1[i]) * tween + data1[i]; } } + return tmp; + } + + private Path getPath(float[] tmp, float start, float end) { Path path = new Path(); FloatsToPath.genPath(path, tmp, start, end); return path; @@ -741,9 +758,9 @@ public class AndroidPaintContext extends PaintContext { private Path getPath(int id, float start, float end) { AndroidRemoteContext androidContext = (AndroidRemoteContext) mContext; Path path = new Path(); - if (androidContext.mRemoteComposeState.containsId(id)) { - float[] data = (float[]) androidContext.mRemoteComposeState.getFromId(id); - FloatsToPath.genPath(path, data, start, end); + float[] pathData = androidContext.mRemoteComposeState.getPathData(id); + if (pathData != null) { + FloatsToPath.genPath(path, pathData, start, end); } return path; } diff --git a/core/java/com/android/internal/widget/remotecompose/player/platform/AndroidRemoteContext.java b/core/java/com/android/internal/widget/remotecompose/player/platform/AndroidRemoteContext.java index 77c25147b1fd..0fb0a28da1db 100644 --- a/core/java/com/android/internal/widget/remotecompose/player/platform/AndroidRemoteContext.java +++ b/core/java/com/android/internal/widget/remotecompose/player/platform/AndroidRemoteContext.java @@ -60,9 +60,12 @@ class AndroidRemoteContext extends RemoteContext { @Override public void loadPathData(int instanceId, @NonNull float[] floatPath) { - if (!mRemoteComposeState.containsId(instanceId)) { - mRemoteComposeState.cacheData(instanceId, floatPath); - } + mRemoteComposeState.putPathData(instanceId, floatPath); + } + + @Override + public float[] getPathData(int instanceId) { + return mRemoteComposeState.getPathData(instanceId); } static class VarName { @@ -162,7 +165,7 @@ class AndroidRemoteContext extends RemoteContext { * @param type the type of the data 0 = RGBA 8888, 1 = 888, 2 = 8 gray * @param width with of image to be loaded largest dimension is 32767 * @param height height of image to be loaded - * @param bitmap a byte array containing the image information + * @param data a byte array containing the image information * @oaram imageId the id of the image */ @Override diff --git a/core/java/com/android/internal/widget/remotecompose/player/platform/RemoteComposeCanvas.java b/core/java/com/android/internal/widget/remotecompose/player/platform/RemoteComposeCanvas.java index 8f55f8abf713..ecfd13aa66b6 100644 --- a/core/java/com/android/internal/widget/remotecompose/player/platform/RemoteComposeCanvas.java +++ b/core/java/com/android/internal/widget/remotecompose/player/platform/RemoteComposeCanvas.java @@ -349,6 +349,27 @@ public class RemoteComposeCanvas extends FrameLayout implements View.OnAttachSta private int mCount; private long mTime = System.nanoTime(); + private long mDuration; + private boolean mEvalTime = false; + + /** + * This returns the amount of time in ms the player used to evalueate a pass it is averaged over + * a number of evaluations. + * + * @return time in ms + */ + public float getEvalTime() { + if (!mEvalTime) { + mEvalTime = true; + return 0.0f; + } + double avg = mDuration / (double) mCount; + if (mCount > 100) { + mDuration /= 2; + mCount /= 2; + } + return (float) (avg * 1E-6); // ms + } @Override protected void onDraw(Canvas canvas) { @@ -356,6 +377,7 @@ public class RemoteComposeCanvas extends FrameLayout implements View.OnAttachSta if (mDocument == null) { return; } + long start = mEvalTime ? System.nanoTime() : 0; mARContext.setAnimationEnabled(true); mARContext.currentTime = System.currentTimeMillis(); mARContext.setDebug(mDebug); @@ -376,5 +398,9 @@ public class RemoteComposeCanvas extends FrameLayout implements View.OnAttachSta if (mDocument.needsRepaint() > 0) { invalidate(); } + if (mEvalTime) { + mDuration += System.nanoTime() - start; + mCount++; + } } } |