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