1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.internal.widget.remotecompose.core.operations; 17 18 import android.annotation.NonNull; 19 20 import com.android.internal.widget.remotecompose.core.Operation; 21 import com.android.internal.widget.remotecompose.core.Operations; 22 import com.android.internal.widget.remotecompose.core.PaintContext; 23 import com.android.internal.widget.remotecompose.core.PaintOperation; 24 import com.android.internal.widget.remotecompose.core.WireBuffer; 25 import com.android.internal.widget.remotecompose.core.documentation.DocumentationBuilder; 26 import com.android.internal.widget.remotecompose.core.serialize.MapSerializer; 27 import com.android.internal.widget.remotecompose.core.serialize.Serializable; 28 29 import java.util.List; 30 31 /** The save the matrix state command */ 32 public class MatrixSave extends PaintOperation implements Serializable { 33 private static final int OP_CODE = Operations.MATRIX_SAVE; 34 private static final String CLASS_NAME = "MatrixSave"; 35 36 @Override write(@onNull WireBuffer buffer)37 public void write(@NonNull WireBuffer buffer) { 38 apply(buffer); 39 } 40 41 @NonNull 42 @Override toString()43 public String toString() { 44 return "MatrixSave;"; 45 } 46 47 /** 48 * Read this operation and add it to the list of operations 49 * 50 * @param buffer the buffer to read 51 * @param operations the list of operations that will be added to 52 */ read(@onNull WireBuffer buffer, @NonNull List<Operation> operations)53 public static void read(@NonNull WireBuffer buffer, @NonNull List<Operation> operations) { 54 MatrixSave op = new MatrixSave(); 55 operations.add(op); 56 } 57 58 /** 59 * The name of the class 60 * 61 * @return the name 62 */ 63 @NonNull name()64 public static String name() { 65 return CLASS_NAME; 66 } 67 68 /** 69 * The OP_CODE for this command 70 * 71 * @return the opcode 72 */ id()73 public static int id() { 74 return OP_CODE; 75 } 76 77 /** 78 * add a matrix save operation to the buffer 79 * 80 * @param buffer the buffer to add to 81 */ apply(@onNull WireBuffer buffer)82 public static void apply(@NonNull WireBuffer buffer) { 83 buffer.start(Operations.MATRIX_SAVE); 84 } 85 86 /** 87 * Populate the documentation with a description of this operation 88 * 89 * @param doc to append the description to. 90 */ documentation(@onNull DocumentationBuilder doc)91 public static void documentation(@NonNull DocumentationBuilder doc) { 92 doc.operation("Canvas Operations", OP_CODE, CLASS_NAME) 93 .description("Save the matrix and clip to a stack"); 94 } 95 96 @Override paint(@onNull PaintContext context)97 public void paint(@NonNull PaintContext context) { 98 context.matrixSave(); 99 } 100 101 @Override serialize(MapSerializer serializer)102 public void serialize(MapSerializer serializer) { 103 serializer.addType(CLASS_NAME); 104 } 105 } 106