2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_OVERLAY_INTERFACE_H
18 #define ANDROID_OVERLAY_INTERFACE_H
20 #include <cutils/native_handle.h>
22 #include <hardware/hardware.h>
25 #include <sys/cdefs.h>
26 #include <sys/types.h>
31 * The id of this module
33 #define OVERLAY_HARDWARE_MODULE_ID "overlay"
36 * Name of the overlay device to open
38 #define OVERLAY_HARDWARE_CONTROL "control"
39 #define OVERLAY_HARDWARE_DATA "data"
41 /*****************************************************************************/
43 /* possible overlay formats */
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_YCbYCr_422_I = 0x14,
49 OVERLAY_FORMAT_CbYCrY_422_I = 0x16,
50 OVERLAY_FORMAT_DEFAULT = 99 // The actual color format is determined
54 /* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
56 /* flip source image horizontally */
57 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
58 /* flip source image vertically */
59 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
60 /* rotate source image 90 degrees */
61 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
62 /* rotate source image 180 degrees */
63 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
64 /* rotate source image 270 degrees */
65 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270
68 /* names for setParameter() */
70 /* rotation of the source image in degrees (0 to 359) */
71 OVERLAY_ROTATION_DEG = 1,
72 /* enable or disable dithering */
74 /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
75 OVERLAY_TRANSFORM = 4,
78 /* enable/disable value setParameter() */
86 /* Maximum amount of minification supported by the hardware*/
87 OVERLAY_MINIFICATION_LIMIT = 1,
88 /* Maximum amount of magnification supported by the hardware */
89 OVERLAY_MAGNIFICATION_LIMIT = 2,
90 /* Number of fractional bits support by the overlay scaling engine */
91 OVERLAY_SCALING_FRAC_BITS = 3,
92 /* Supported rotation step in degrees. */
93 OVERLAY_ROTATION_STEP_DEG = 4,
94 /* horizontal alignment in pixels */
95 OVERLAY_HORIZONTAL_ALIGNMENT = 5,
96 /* vertical alignment in pixels */
97 OVERLAY_VERTICAL_ALIGNMENT = 6,
98 /* width alignment restrictions. negative number for max. power-of-two */
99 OVERLAY_WIDTH_ALIGNMENT = 7,
100 /* height alignment restrictions. negative number for max. power-of-two */
101 OVERLAY_HEIGHT_ALIGNMENT = 8,
104 /*****************************************************************************/
106 /* opaque reference to an Overlay kernel object */
107 typedef const native_handle* overlay_handle_t;
109 typedef struct overlay_t {
115 uint32_t reserved[3];
116 /* returns a reference to this overlay's handle (the caller doesn't
118 overlay_handle_t (*getHandleRef)(struct overlay_t* overlay);
119 uint32_t reserved_procs[7];
122 typedef void* overlay_buffer_t;
124 /*****************************************************************************/
127 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
128 * and the fields of this data structure must begin with hw_module_t
129 * followed by module specific information.
131 struct overlay_module_t {
132 struct hw_module_t common;
135 /*****************************************************************************/
138 * Every device data structure must begin with hw_device_t
139 * followed by module specific public methods and attributes.
142 struct overlay_control_device_t {
143 struct hw_device_t common;
145 /* get static informations about the capabilities of the overlay engine */
146 int (*get)(struct overlay_control_device_t *dev, int name);
148 /* creates an overlay matching the given parameters as closely as possible.
149 * returns an error if no more overlays are available. The actual
150 * size and format is returned in overlay_t. */
151 overlay_t* (*createOverlay)(struct overlay_control_device_t *dev,
152 uint32_t w, uint32_t h, int32_t format);
154 /* destroys an overlay. This call releases all
155 * resources associated with overlay_t and make it invalid */
156 void (*destroyOverlay)(struct overlay_control_device_t *dev,
159 /* set position and scaling of the given overlay as closely as possible.
160 * if scaling cannot be performed, overlay must be centered. */
161 int (*setPosition)(struct overlay_control_device_t *dev,
163 int x, int y, uint32_t w, uint32_t h);
165 /* returns the actual position and size of the overlay */
166 int (*getPosition)(struct overlay_control_device_t *dev,
168 int* x, int* y, uint32_t* w, uint32_t* h);
170 /* sets configurable parameters for this overlay. returns an error if not
172 int (*setParameter)(struct overlay_control_device_t *dev,
173 overlay_t* overlay, int param, int value);
175 int (*stage)(struct overlay_control_device_t *dev, overlay_t* overlay);
176 int (*commit)(struct overlay_control_device_t *dev, overlay_t* overlay);
180 struct overlay_data_device_t {
181 struct hw_device_t common;
183 /* initialize the overlay from the given handle. this associates this
184 * overlay data module to its control module */
185 int (*initialize)(struct overlay_data_device_t *dev,
186 overlay_handle_t handle);
188 /* can be called to change the width and height of the overlay. */
189 int (*resizeInput)(struct overlay_data_device_t *dev,
190 uint32_t w, uint32_t h);
192 int (*setCrop)(struct overlay_data_device_t *dev,
193 uint32_t x, uint32_t y, uint32_t w, uint32_t h) ;
195 int (*getCrop)(struct overlay_data_device_t *dev,
196 uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h) ;
198 int (*setParameter)(struct overlay_data_device_t *dev,
199 int param, int value);
201 /* blocks until an overlay buffer is available and return that buffer. */
202 int (*dequeueBuffer)(struct overlay_data_device_t *dev,
203 overlay_buffer_t *buf);
205 /* release the overlay buffer and post it */
206 int (*queueBuffer)(struct overlay_data_device_t *dev,
207 overlay_buffer_t buffer);
209 /* returns the address of a given buffer if supported, NULL otherwise. */
210 void* (*getBufferAddress)(struct overlay_data_device_t *dev,
211 overlay_buffer_t buffer);
213 int (*getBufferCount)(struct overlay_data_device_t *dev);
217 /*****************************************************************************/
219 /** convenience API for opening and closing a device */
221 static inline int overlay_control_open(const struct hw_module_t* module,
222 struct overlay_control_device_t** device) {
223 return module->methods->open(module,
224 OVERLAY_HARDWARE_CONTROL, (struct hw_device_t**)device);
227 static inline int overlay_control_close(struct overlay_control_device_t* device) {
228 return device->common.close(&device->common);
231 static inline int overlay_data_open(const struct hw_module_t* module,
232 struct overlay_data_device_t** device) {
233 return module->methods->open(module,
234 OVERLAY_HARDWARE_DATA, (struct hw_device_t**)device);
237 static inline int overlay_data_close(struct overlay_data_device_t* device) {
238 return device->common.close(&device->common);
243 #endif // ANDROID_OVERLAY_INTERFACE_H