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