• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import android.annotation.Nullable;
20 
21 import com.android.internal.widget.remotecompose.core.Operation;
22 import com.android.internal.widget.remotecompose.core.Operations;
23 import com.android.internal.widget.remotecompose.core.PaintContext;
24 import com.android.internal.widget.remotecompose.core.PaintOperation;
25 import com.android.internal.widget.remotecompose.core.WireBuffer;
26 import com.android.internal.widget.remotecompose.core.documentation.DocumentationBuilder;
27 import com.android.internal.widget.remotecompose.core.operations.layout.LayoutComponent;
28 import com.android.internal.widget.remotecompose.core.serialize.MapSerializer;
29 import com.android.internal.widget.remotecompose.core.serialize.Serializable;
30 
31 import java.util.List;
32 
33 /** The DrawContent command */
34 public class DrawContent extends PaintOperation implements Serializable {
35     private static final int OP_CODE = Operations.DRAW_CONTENT;
36     private static final String CLASS_NAME = "DrawContent";
37     private @Nullable LayoutComponent mComponent;
38 
39     @Override
write(@onNull WireBuffer buffer)40     public void write(@NonNull WireBuffer buffer) {
41         apply(buffer);
42     }
43 
44     /**
45      * Set the component to be painted
46      *
47      * @param component
48      */
setComponent(@ullable LayoutComponent component)49     public void setComponent(@Nullable LayoutComponent component) {
50         mComponent = component;
51     }
52 
53     @NonNull
54     @Override
toString()55     public String toString() {
56         return "DrawContent;";
57     }
58 
59     /**
60      * Read this operation and add it to the list of operations
61      *
62      * @param buffer the buffer to read
63      * @param operations the list of operations that will be added to
64      */
read(@onNull WireBuffer buffer, @NonNull List<Operation> operations)65     public static void read(@NonNull WireBuffer buffer, @NonNull List<Operation> operations) {
66         DrawContent op = new DrawContent();
67         operations.add(op);
68     }
69 
70     /**
71      * The name of the class
72      *
73      * @return the name
74      */
75     @NonNull
name()76     public static String name() {
77         return CLASS_NAME;
78     }
79 
80     /**
81      * The OP_CODE for this command
82      *
83      * @return the opcode
84      */
id()85     public static int id() {
86         return OP_CODE;
87     }
88 
89     /**
90      * add a draw content operation to the buffer
91      *
92      * @param buffer the buffer to add to
93      */
apply(@onNull WireBuffer buffer)94     public static void apply(@NonNull WireBuffer buffer) {
95         buffer.start(Operations.DRAW_CONTENT);
96     }
97 
98     /**
99      * Populate the documentation with a description of this operation
100      *
101      * @param doc to append the description to.
102      */
documentation(@onNull DocumentationBuilder doc)103     public static void documentation(@NonNull DocumentationBuilder doc) {
104         doc.operation("Layout Operations", OP_CODE, CLASS_NAME)
105                 .description("Draw the component content");
106     }
107 
108     @Override
paint(@onNull PaintContext context)109     public void paint(@NonNull PaintContext context) {
110         if (mComponent != null) {
111             mComponent.drawContent(context);
112         }
113     }
114 
115     @Override
serialize(MapSerializer serializer)116     public void serialize(MapSerializer serializer) {
117         serializer.addType(CLASS_NAME);
118     }
119 }
120