1 /*
2 * Copyright (C) 2008 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
17 #ifndef ANDROID_OVERLAY_INTERFACE_H
18 #define ANDROID_OVERLAY_INTERFACE_H
19
20 #include <cutils/native_handle.h>
21
22 #include <hardware/hardware.h>
23
24 #include <stdint.h>
25 #include <sys/cdefs.h>
26 #include <sys/types.h>
27
28 __BEGIN_DECLS
29
30 /**
31 * The id of this module
32 */
33 #define OVERLAY_HARDWARE_MODULE_ID "overlay"
34
35 /**
36 * Name of the overlay device to open
37 */
38 #define OVERLAY_HARDWARE_CONTROL "control"
39 #define OVERLAY_HARDWARE_DATA "data"
40
41 /*****************************************************************************/
42
43 /* possible overlay formats */
44 enum {
45 OVERLAY_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888,
46 OVERLAY_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565,
47 OVERLAY_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888,
48 OVERLAY_FORMAT_YCbCr_422_SP = HAL_PIXEL_FORMAT_YCbCr_422_SP,
49 OVERLAY_FORMAT_YCbCr_420_SP = HAL_PIXEL_FORMAT_YCbCr_420_SP,
50 OVERLAY_FORMAT_YCbYCr_422_I = HAL_PIXEL_FORMAT_YCbCr_422_I,
51 OVERLAY_FORMAT_YCbYCr_420_I = HAL_PIXEL_FORMAT_YCbCr_420_I,
52 OVERLAY_FORMAT_CbYCrY_422_I = HAL_PIXEL_FORMAT_CbYCrY_422_I,
53 OVERLAY_FORMAT_CbYCrY_420_I = HAL_PIXEL_FORMAT_CbYCrY_420_I,
54 OVERLAY_FORMAT_DEFAULT = 99 // The actual color format is determined
55 // by the overlay
56 };
57
58 /* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
59 enum {
60 /* flip source image horizontally */
61 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_V,
62 /* flip source image vertically */
63 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_H,
64 /* rotate source image 90 degrees */
65 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
66 /* rotate source image 180 degrees */
67 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
68 /* rotate source image 270 degrees */
69 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270
70 };
71
72 /* names for setParameter() */
73 enum {
74 /* rotation of the source image in degrees (0 to 359) */
75 OVERLAY_ROTATION_DEG = 1,
76 /* enable or disable dithering */
77 OVERLAY_DITHER = 3,
78 /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
79 OVERLAY_TRANSFORM = 4,
80 };
81
82 /* enable/disable value setParameter() */
83 enum {
84 OVERLAY_DISABLE = 0,
85 OVERLAY_ENABLE = 1
86 };
87
88 /* names for get() */
89 enum {
90 /* Maximum amount of minification supported by the hardware*/
91 OVERLAY_MINIFICATION_LIMIT = 1,
92 /* Maximum amount of magnification supported by the hardware */
93 OVERLAY_MAGNIFICATION_LIMIT = 2,
94 /* Number of fractional bits support by the overlay scaling engine */
95 OVERLAY_SCALING_FRAC_BITS = 3,
96 /* Supported rotation step in degrees. */
97 OVERLAY_ROTATION_STEP_DEG = 4,
98 /* horizontal alignment in pixels */
99 OVERLAY_HORIZONTAL_ALIGNMENT = 5,
100 /* vertical alignment in pixels */
101 OVERLAY_VERTICAL_ALIGNMENT = 6,
102 /* width alignment restrictions. negative number for max. power-of-two */
103 OVERLAY_WIDTH_ALIGNMENT = 7,
104 /* height alignment restrictions. negative number for max. power-of-two */
105 OVERLAY_HEIGHT_ALIGNMENT = 8,
106 };
107
108 /*****************************************************************************/
109
110 /* opaque reference to an Overlay kernel object */
111 typedef const native_handle* overlay_handle_t;
112
113 typedef struct overlay_t {
114 uint32_t w;
115 uint32_t h;
116 int32_t format;
117 uint32_t w_stride;
118 uint32_t h_stride;
119 uint32_t reserved[3];
120 /* returns a reference to this overlay's handle (the caller doesn't
121 * take ownership) */
122 overlay_handle_t (*getHandleRef)(struct overlay_t* overlay);
123 uint32_t reserved_procs[7];
124 } overlay_t;
125
126 typedef void* overlay_buffer_t;
127
128 /*****************************************************************************/
129
130 /**
131 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
132 * and the fields of this data structure must begin with hw_module_t
133 * followed by module specific information.
134 */
135 struct overlay_module_t {
136 struct hw_module_t common;
137 };
138
139 /*****************************************************************************/
140
141 /**
142 * Every device data structure must begin with hw_device_t
143 * followed by module specific public methods and attributes.
144 */
145
146 struct overlay_control_device_t {
147 struct hw_device_t common;
148
149 /* get static informations about the capabilities of the overlay engine */
150 int (*get)(struct overlay_control_device_t *dev, int name);
151
152 /* creates an overlay matching the given parameters as closely as possible.
153 * returns an error if no more overlays are available. The actual
154 * size and format is returned in overlay_t. */
155 overlay_t* (*createOverlay)(struct overlay_control_device_t *dev,
156 uint32_t w, uint32_t h, int32_t format);
157
158 /* destroys an overlay. This call releases all
159 * resources associated with overlay_t and make it invalid */
160 void (*destroyOverlay)(struct overlay_control_device_t *dev,
161 overlay_t* overlay);
162
163 /* set position and scaling of the given overlay as closely as possible.
164 * if scaling cannot be performed, overlay must be centered. */
165 int (*setPosition)(struct overlay_control_device_t *dev,
166 overlay_t* overlay,
167 int x, int y, uint32_t w, uint32_t h);
168
169 /* returns the actual position and size of the overlay */
170 int (*getPosition)(struct overlay_control_device_t *dev,
171 overlay_t* overlay,
172 int* x, int* y, uint32_t* w, uint32_t* h);
173
174 /* sets configurable parameters for this overlay. returns an error if not
175 * supported. */
176 int (*setParameter)(struct overlay_control_device_t *dev,
177 overlay_t* overlay, int param, int value);
178
179 int (*stage)(struct overlay_control_device_t *dev, overlay_t* overlay);
180 int (*commit)(struct overlay_control_device_t *dev, overlay_t* overlay);
181 };
182
183
184 struct overlay_data_device_t {
185 struct hw_device_t common;
186
187 /* initialize the overlay from the given handle. this associates this
188 * overlay data module to its control module */
189 int (*initialize)(struct overlay_data_device_t *dev,
190 overlay_handle_t handle);
191
192 /* can be called to change the width and height of the overlay. */
193 int (*resizeInput)(struct overlay_data_device_t *dev,
194 uint32_t w, uint32_t h);
195
196 int (*setCrop)(struct overlay_data_device_t *dev,
197 uint32_t x, uint32_t y, uint32_t w, uint32_t h) ;
198
199 int (*getCrop)(struct overlay_data_device_t *dev,
200 uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h) ;
201
202 int (*setParameter)(struct overlay_data_device_t *dev,
203 int param, int value);
204
205 /* blocks until an overlay buffer is available and return that buffer. */
206 int (*dequeueBuffer)(struct overlay_data_device_t *dev,
207 overlay_buffer_t *buf);
208
209 /* release the overlay buffer and post it */
210 int (*queueBuffer)(struct overlay_data_device_t *dev,
211 overlay_buffer_t buffer);
212
213 /* returns the address of a given buffer if supported, NULL otherwise. */
214 void* (*getBufferAddress)(struct overlay_data_device_t *dev,
215 overlay_buffer_t buffer);
216
217 int (*getBufferCount)(struct overlay_data_device_t *dev);
218 };
219
220
221 /*****************************************************************************/
222
223 /** convenience API for opening and closing a device */
224
overlay_control_open(const struct hw_module_t * module,struct overlay_control_device_t ** device)225 static inline int overlay_control_open(const struct hw_module_t* module,
226 struct overlay_control_device_t** device) {
227 return module->methods->open(module,
228 OVERLAY_HARDWARE_CONTROL, (struct hw_device_t**)device);
229 }
230
overlay_control_close(struct overlay_control_device_t * device)231 static inline int overlay_control_close(struct overlay_control_device_t* device) {
232 return device->common.close(&device->common);
233 }
234
overlay_data_open(const struct hw_module_t * module,struct overlay_data_device_t ** device)235 static inline int overlay_data_open(const struct hw_module_t* module,
236 struct overlay_data_device_t** device) {
237 return module->methods->open(module,
238 OVERLAY_HARDWARE_DATA, (struct hw_device_t**)device);
239 }
240
overlay_data_close(struct overlay_data_device_t * device)241 static inline int overlay_data_close(struct overlay_data_device_t* device) {
242 return device->common.close(&device->common);
243 }
244
245 __END_DECLS
246
247 #endif // ANDROID_OVERLAY_INTERFACE_H
248