blob: 63230e3d8264cbdf7c07df5b94d02d915589b161 [file] [log] [blame]
The Android Open Source Project51704be2008-12-17 18:05:50 -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 <hardware/hardware.h>
21
22#include <stdint.h>
23#include <sys/cdefs.h>
24#include <sys/types.h>
25
26__BEGIN_DECLS
27
28/**
29 * The id of this module
30 */
31#define OVERLAY_HARDWARE_MODULE_ID "overlay"
32
33/**
34 * Name of the overlay device to open
35 */
The Android Open Source Project699d24a2009-01-09 17:51:24 -080036#define OVERLAY_HARDWARE_CONTROL "control"
37#define OVERLAY_HARDWARE_DATA "data"
The Android Open Source Project51704be2008-12-17 18:05:50 -080038
39/*****************************************************************************/
40
41/* possible overlay formats */
42enum {
43 OVERLAY_FORMAT_RGBA_8888 = 1,
44 OVERLAY_FORMAT_RGB_565 = 4,
45 OVERLAY_FORMAT_BGRA_8888 = 5,
46 OVERLAY_FORMAT_YCbCr_422_SP = 0x10,
47 OVERLAY_FORMAT_YCbCr_420_SP = 0x11,
The Android Open Source Project699d24a2009-01-09 17:51:24 -080048 OVERLAY_FORMAT_YCbCr_422_I = 0x14,
49 OVERLAY_FORMAT_YCbCr_420_I = 0x15
The Android Open Source Project51704be2008-12-17 18:05:50 -080050};
51
The Android Open Source Project699d24a2009-01-09 17:51:24 -080052/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
The Android Open Source Project51704be2008-12-17 18:05:50 -080053enum {
54 /* flip source image horizontally */
55 OVERLAY_TRANSFORM_FLIP_H = 0x01,
56 /* flip source image vertically */
57 OVERLAY_TRANSFORM_FLIP_V = 0x02,
58 /* rotate source image 90 degrees */
59 OVERLAY_TRANSFORM_ROT_90 = 0x04,
60 /* rotate source image 180 degrees */
61 OVERLAY_TRANSFORM_ROT_180 = 0x03,
62 /* rotate source image 270 degrees */
63 OVERLAY_TRANSFORM_ROT_270 = 0x07,
64};
65
66/* names for setParameter() */
67enum {
The Android Open Source Project699d24a2009-01-09 17:51:24 -080068 /* rotation of the source image in degrees (0 to 359) */
The Android Open Source Project51704be2008-12-17 18:05:50 -080069 OVERLAY_ROTATION_DEG = 1,
The Android Open Source Project699d24a2009-01-09 17:51:24 -080070 /* enable or disable dithering */
The Android Open Source Project51704be2008-12-17 18:05:50 -080071 OVERLAY_DITHER = 3,
The Android Open Source Project699d24a2009-01-09 17:51:24 -080072 /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
73 OVERLAY_TRANSFORM = 4,
The Android Open Source Project51704be2008-12-17 18:05:50 -080074};
75
76/* enable/disable value setParameter() */
77enum {
78 OVERLAY_DISABLE = 0,
79 OVERLAY_ENABLE = 1
80};
81
82/* names for get() */
83enum {
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 */
105typedef struct {
106 int numFds;
107 int fds[4];
108 int numInts;
109 int data[0];
110} overlay_handle_t;
111
112typedef struct overlay_t {
113 uint32_t w;
114 uint32_t h;
115 int32_t format;
116 uint32_t w_stride;
117 uint32_t h_stride;
118 uint32_t reserved[3];
119 /* returns a reference to this overlay's handle (the caller doesn't
120 * take ownership) */
121 overlay_handle_t const* (*getHandleRef)(struct overlay_t* overlay);
122 uint32_t reserved_procs[7];
123} overlay_t;
124
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800125typedef void* overlay_buffer_t;
126
The Android Open Source Project51704be2008-12-17 18:05:50 -0800127/*****************************************************************************/
128
129/**
130 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
131 * and the fields of this data structure must begin with hw_module_t
132 * followed by module specific information.
133 */
134struct overlay_module_t {
135 struct hw_module_t common;
136};
137
138/*****************************************************************************/
139
140/**
141 * Every device data structure must begin with hw_device_t
142 * followed by module specific public methods and attributes.
143 */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800144
145struct overlay_control_device_t {
The Android Open Source Project51704be2008-12-17 18:05:50 -0800146 struct hw_device_t common;
147
148 /* get static informations about the capabilities of the overlay engine */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800149 int (*get)(struct overlay_control_device_t *dev, int name);
The Android Open Source Project51704be2008-12-17 18:05:50 -0800150
151 /* creates an overlay matching the given parameters as closely as possible.
152 * returns an error if no more overlays are available. The actual
153 * size and format is returned in overlay_t. */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800154 overlay_t* (*createOverlay)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800155 uint32_t w, uint32_t h, int32_t format);
156
157 /* destroys an overlay. This call releases all
158 * resources associated with overlay_t and make it invalid */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800159 void (*destroyOverlay)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800160 overlay_t* overlay);
161
162 /* set position and scaling of the given overlay as closely as possible.
163 * if scaling cannot be performed, overlay must be centered. */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800164 int (*setPosition)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800165 overlay_t* overlay,
166 int x, int y, uint32_t w, uint32_t h);
167
168 /* returns the actual position and size of the overlay */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800169 int (*getPosition)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800170 overlay_t* overlay,
171 int* x, int* y, uint32_t* w, uint32_t* h);
172
173 /* sets configurable parameters for this overlay. returns an error if not
174 * supported. */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800175 int (*setParameter)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800176 overlay_t* overlay, int param, int value);
The Android Open Source Project51704be2008-12-17 18:05:50 -0800177};
178
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800179
180struct overlay_data_device_t {
181 struct hw_device_t common;
182
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 const* handle);
187
188 /* blocks until an overlay buffer is available and return that buffer. */
The Android Open Source Project0100d512009-01-15 16:12:12 -0800189 int (*dequeueBuffer)(struct overlay_data_device_t *dev,
190 overlay_buffer_t *buf);
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800191
192 /* release the overlay buffer and post it */
193 int (*queueBuffer)(struct overlay_data_device_t *dev,
194 overlay_buffer_t buffer);
195
196 /* returns the address of a given buffer if supported, NULL otherwise. */
197 void* (*getBufferAddress)(struct overlay_data_device_t *dev,
198 overlay_buffer_t buffer);
199};
200
201
The Android Open Source Project51704be2008-12-17 18:05:50 -0800202/*****************************************************************************/
203
204/** convenience API for opening and closing a device */
205
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800206static inline int overlay_control_open(const struct hw_module_t* module,
207 struct overlay_control_device_t** device) {
The Android Open Source Project51704be2008-12-17 18:05:50 -0800208 return module->methods->open(module,
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800209 OVERLAY_HARDWARE_CONTROL, (struct hw_device_t**)device);
The Android Open Source Project51704be2008-12-17 18:05:50 -0800210}
211
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800212static inline int overlay_control_close(struct overlay_control_device_t* device) {
The Android Open Source Project51704be2008-12-17 18:05:50 -0800213 return device->common.close(&device->common);
214}
215
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800216static inline int overlay_data_open(const struct hw_module_t* module,
217 struct overlay_data_device_t** device) {
218 return module->methods->open(module,
219 OVERLAY_HARDWARE_DATA, (struct hw_device_t**)device);
220}
221
222static inline int overlay_data_close(struct overlay_data_device_t* device) {
223 return device->common.close(&device->common);
224}
The Android Open Source Project51704be2008-12-17 18:05:50 -0800225
226__END_DECLS
227
228#endif // ANDROID_OVERLAY_INTERFACE_H