• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 
21 /** Services that are needed to be provided by the platform during encoding. */
22 public interface Platform {
23 
24     /**
25      * Converts a platform-specific image object into a platform-independent byte buffer
26      *
27      * @param image
28      * @return
29      */
30     @Nullable
imageToByteArray(@onNull Object image)31     byte[] imageToByteArray(@NonNull Object image);
32 
33     /**
34      * Returns the width of a platform-specific image object
35      *
36      * @param image platform-specific image object
37      * @return the width of the image in pixels
38      */
getImageWidth(@onNull Object image)39     int getImageWidth(@NonNull Object image);
40 
41     /**
42      * Returns the height of a platform-specific image object
43      *
44      * @param image platform-specific image object
45      * @return the height of the image in pixels
46      */
getImageHeight(@onNull Object image)47     int getImageHeight(@NonNull Object image);
48 
49     /**
50      * Returns true if the platform-specific image object has format ALPHA_8
51      *
52      * @param image platform-specific image object
53      * @return whether or not the platform-specific image object has format ALPHA_8
54      */
isAlpha8Image(@onNull Object image)55     boolean isAlpha8Image(@NonNull Object image);
56 
57     /**
58      * Converts a platform-specific path object into a platform-independent float buffer
59      *
60      * @param path
61      * @return
62      */
63     @Nullable
pathToFloatArray(@onNull Object path)64     float[] pathToFloatArray(@NonNull Object path);
65 
66     enum LogCategory {
67         DEBUG,
68         INFO,
69         WARN,
70         ERROR,
71         TODO,
72     }
73 
74     /**
75      * Log a message
76      *
77      * @param category
78      * @param message
79      */
log(LogCategory category, String message)80     void log(LogCategory category, String message);
81 
82     /**
83      * Represents a precomputed text layout, for complex text painting / measuring / layout. Allows
84      * the implementation to return a cached / engine after a text measure to be used int the paint
85      * pass.
86      */
87     interface ComputedTextLayout {
88         /**
89          * Horizontal dimension of this text layout
90          *
91          * @return
92          */
getWidth()93         float getWidth();
94 
95         /**
96          * Vertical dimension of this text layout
97          *
98          * @return
99          */
getHeight()100         float getHeight();
101     }
102 
103     Platform None =
104             new Platform() {
105                 @Override
106                 public byte[] imageToByteArray(@NonNull Object image) {
107                     throw new UnsupportedOperationException();
108                 }
109 
110                 @Override
111                 public int getImageWidth(@NonNull Object image) {
112                     throw new UnsupportedOperationException();
113                 }
114 
115                 @Override
116                 public int getImageHeight(@NonNull Object image) {
117                     throw new UnsupportedOperationException();
118                 }
119 
120                 @Override
121                 public boolean isAlpha8Image(@NonNull Object image) {
122                     throw new UnsupportedOperationException();
123                 }
124 
125                 @Override
126                 public float[] pathToFloatArray(@NonNull Object path) {
127                     throw new UnsupportedOperationException();
128                 }
129 
130                 @Override
131                 public void log(LogCategory category, String message) {}
132             };
133 }
134