blob: a5cd2633c60ce2cc2676166819c44ad0c7180b48 [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
The Android Open Source Projectf87393c2009-01-20 14:03:59 -080020#include <cutils/native_handle.h>
21
The Android Open Source Project51704be2008-12-17 18:05:50 -080022#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 */
The Android Open Source Project699d24a2009-01-09 17:51:24 -080038#define OVERLAY_HARDWARE_CONTROL "control"
39#define OVERLAY_HARDWARE_DATA "data"
The Android Open Source Project51704be2008-12-17 18:05:50 -080040
41/*****************************************************************************/
42
43/* possible overlay formats */
44enum {
45 OVERLAY_FORMAT_RGBA_8888 = 1,
46 OVERLAY_FORMAT_RGB_565 = 4,
47 OVERLAY_FORMAT_BGRA_8888 = 5,
48 OVERLAY_FORMAT_YCbCr_422_SP = 0x10,
49 OVERLAY_FORMAT_YCbCr_420_SP = 0x11,
The Android Open Source Project699d24a2009-01-09 17:51:24 -080050 OVERLAY_FORMAT_YCbCr_422_I = 0x14,
51 OVERLAY_FORMAT_YCbCr_420_I = 0x15
The Android Open Source Project51704be2008-12-17 18:05:50 -080052};
53
The Android Open Source Project699d24a2009-01-09 17:51:24 -080054/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
The Android Open Source Project51704be2008-12-17 18:05:50 -080055enum {
56 /* flip source image horizontally */
57 OVERLAY_TRANSFORM_FLIP_H = 0x01,
58 /* flip source image vertically */
59 OVERLAY_TRANSFORM_FLIP_V = 0x02,
60 /* rotate source image 90 degrees */
61 OVERLAY_TRANSFORM_ROT_90 = 0x04,
62 /* rotate source image 180 degrees */
63 OVERLAY_TRANSFORM_ROT_180 = 0x03,
64 /* rotate source image 270 degrees */
65 OVERLAY_TRANSFORM_ROT_270 = 0x07,
66};
67
68/* names for setParameter() */
69enum {
The Android Open Source Project699d24a2009-01-09 17:51:24 -080070 /* rotation of the source image in degrees (0 to 359) */
The Android Open Source Project51704be2008-12-17 18:05:50 -080071 OVERLAY_ROTATION_DEG = 1,
The Android Open Source Project699d24a2009-01-09 17:51:24 -080072 /* enable or disable dithering */
The Android Open Source Project51704be2008-12-17 18:05:50 -080073 OVERLAY_DITHER = 3,
The Android Open Source Project699d24a2009-01-09 17:51:24 -080074 /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
75 OVERLAY_TRANSFORM = 4,
The Android Open Source Project51704be2008-12-17 18:05:50 -080076};
77
78/* enable/disable value setParameter() */
79enum {
80 OVERLAY_DISABLE = 0,
81 OVERLAY_ENABLE = 1
82};
83
84/* names for get() */
85enum {
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,
102};
103
104/*****************************************************************************/
105
106/* opaque reference to an Overlay kernel object */
The Android Open Source Projectf87393c2009-01-20 14:03:59 -0800107typedef const native_handle* overlay_handle_t;
The Android Open Source Project51704be2008-12-17 18:05:50 -0800108
109typedef struct overlay_t {
110 uint32_t w;
111 uint32_t h;
112 int32_t format;
113 uint32_t w_stride;
114 uint32_t h_stride;
115 uint32_t reserved[3];
116 /* returns a reference to this overlay's handle (the caller doesn't
117 * take ownership) */
The Android Open Source Projectf87393c2009-01-20 14:03:59 -0800118 overlay_handle_t (*getHandleRef)(struct overlay_t* overlay);
The Android Open Source Project51704be2008-12-17 18:05:50 -0800119 uint32_t reserved_procs[7];
120} overlay_t;
121
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800122typedef void* overlay_buffer_t;
123
The Android Open Source Project51704be2008-12-17 18:05:50 -0800124/*****************************************************************************/
125
126/**
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.
130 */
131struct overlay_module_t {
132 struct hw_module_t common;
133};
134
135/*****************************************************************************/
136
137/**
138 * Every device data structure must begin with hw_device_t
139 * followed by module specific public methods and attributes.
140 */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800141
142struct overlay_control_device_t {
The Android Open Source Project51704be2008-12-17 18:05:50 -0800143 struct hw_device_t common;
144
145 /* get static informations about the capabilities of the overlay engine */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800146 int (*get)(struct overlay_control_device_t *dev, int name);
The Android Open Source Project51704be2008-12-17 18:05:50 -0800147
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. */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800151 overlay_t* (*createOverlay)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800152 uint32_t w, uint32_t h, int32_t format);
153
154 /* destroys an overlay. This call releases all
155 * resources associated with overlay_t and make it invalid */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800156 void (*destroyOverlay)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800157 overlay_t* overlay);
158
159 /* set position and scaling of the given overlay as closely as possible.
160 * if scaling cannot be performed, overlay must be centered. */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800161 int (*setPosition)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800162 overlay_t* overlay,
163 int x, int y, uint32_t w, uint32_t h);
164
165 /* returns the actual position and size of the overlay */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800166 int (*getPosition)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800167 overlay_t* overlay,
168 int* x, int* y, uint32_t* w, uint32_t* h);
169
170 /* sets configurable parameters for this overlay. returns an error if not
171 * supported. */
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800172 int (*setParameter)(struct overlay_control_device_t *dev,
The Android Open Source Project51704be2008-12-17 18:05:50 -0800173 overlay_t* overlay, int param, int value);
The Android Open Source Project51704be2008-12-17 18:05:50 -0800174};
175
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800176
177struct overlay_data_device_t {
178 struct hw_device_t common;
179
180 /* initialize the overlay from the given handle. this associates this
181 * overlay data module to its control module */
182 int (*initialize)(struct overlay_data_device_t *dev,
The Android Open Source Projectf87393c2009-01-20 14:03:59 -0800183 overlay_handle_t handle);
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800184
185 /* blocks until an overlay buffer is available and return that buffer. */
The Android Open Source Project0100d512009-01-15 16:12:12 -0800186 int (*dequeueBuffer)(struct overlay_data_device_t *dev,
187 overlay_buffer_t *buf);
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800188
189 /* release the overlay buffer and post it */
190 int (*queueBuffer)(struct overlay_data_device_t *dev,
191 overlay_buffer_t buffer);
192
193 /* returns the address of a given buffer if supported, NULL otherwise. */
194 void* (*getBufferAddress)(struct overlay_data_device_t *dev,
195 overlay_buffer_t buffer);
196};
197
198
The Android Open Source Project51704be2008-12-17 18:05:50 -0800199/*****************************************************************************/
200
201/** convenience API for opening and closing a device */
202
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800203static inline int overlay_control_open(const struct hw_module_t* module,
204 struct overlay_control_device_t** device) {
The Android Open Source Project51704be2008-12-17 18:05:50 -0800205 return module->methods->open(module,
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800206 OVERLAY_HARDWARE_CONTROL, (struct hw_device_t**)device);
The Android Open Source Project51704be2008-12-17 18:05:50 -0800207}
208
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800209static inline int overlay_control_close(struct overlay_control_device_t* device) {
The Android Open Source Project51704be2008-12-17 18:05:50 -0800210 return device->common.close(&device->common);
211}
212
The Android Open Source Project699d24a2009-01-09 17:51:24 -0800213static 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
219static inline int overlay_data_close(struct overlay_data_device_t* device) {
220 return device->common.close(&device->common);
221}
The Android Open Source Project51704be2008-12-17 18:05:50 -0800222
223__END_DECLS
224
225#endif // ANDROID_OVERLAY_INTERFACE_H