blob: 3e4c02bcf204e5ae2afd5452cf265a46252e6402 [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#define LOG_TAG "Overlay"
18
19#include <hardware/hardware.h>
20#include <hardware/overlay.h>
21
22#include <fcntl.h>
23#include <errno.h>
24
25#include <cutils/log.h>
26#include <cutils/atomic.h>
27
28/*****************************************************************************/
29
30struct overlay_context_t {
31 struct overlay_device_t device;
32 /* our private state goes below here */
33};
34
35
36static int overlay_device_open(const struct hw_module_t* module, const char* name,
37 struct hw_device_t** device);
38
39static struct hw_module_methods_t overlay_module_methods = {
40 open: overlay_device_open
41};
42
43const struct overlay_module_t HAL_MODULE_INFO_SYM = {
44 common: {
45 tag: HARDWARE_MODULE_TAG,
46 version_major: 1,
47 version_minor: 0,
48 id: OVERLAY_HARDWARE_MODULE_ID,
49 name: "Sample Overlay module",
50 author: "The Android Open Source Project",
51 methods: &overlay_module_methods,
52 }
53};
54
55/*****************************************************************************/
56
57/*
58 * This is the overlay_t object, it is returned to the user and represents
59 * an overlay. here we use a subclass, where we can store our own state.
60 * Notice the use of "overlay_handle_t", which is an "opaque" marshallable
61 * handle, it can contains any number of ints and up to 4 filedescriptors.
62 * In this example we store no fd and 2 ints.
63 * This handles will be passed across processes and possibly given to other
64 * HAL modules (for instance video decode modules).
65 */
66
67class overlay_object : public overlay_t {
68
69 struct handle_t : public overlay_handle_t {
70 /* add the data fields we need here, for instance: */
71 int width;
72 int height;
73 };
74
75 handle_t mHandle;
76
77 static overlay_handle_t const* getHandleRef(struct overlay_t* overlay) {
78 /* returns a reference to the handle, caller doesn't take ownership */
79 return &(static_cast<overlay_object *>(overlay)->mHandle);
80 }
81
82public:
83 overlay_object() {
84 this->overlay_t::getHandleRef = getHandleRef;
85 mHandle.numFds = 0;
86 mHandle.numInts = 2; // extra ints we have in our handle
87 }
88};
89
90/*****************************************************************************/
91
92static int overlay_get(struct overlay_device_t *dev, int name) {
93 int result = -1;
94 switch (name) {
95 case OVERLAY_MINIFICATION_LIMIT:
96 result = 0; // 0 = no limit
97 break;
98 case OVERLAY_MAGNIFICATION_LIMIT:
99 result = 0; // 0 = no limit
100 break;
101 case OVERLAY_SCALING_FRAC_BITS:
102 result = 0; // 0 = infinite
103 break;
104 case OVERLAY_ROTATION_STEP_DEG:
105 result = 90; // 90 rotation steps (for instance)
106 break;
107 case OVERLAY_HORIZONTAL_ALIGNMENT:
108 result = 1; // 1-pixel alignment
109 break;
110 case OVERLAY_VERTICAL_ALIGNMENT:
111 result = 1; // 1-pixel alignment
112 break;
113 case OVERLAY_WIDTH_ALIGNMENT:
114 result = 1; // 1-pixel alignment
115 break;
116 case OVERLAY_HEIGHT_ALIGNMENT:
117 result = 1; // 1-pixel alignment
118 break;
119 }
120 return result;
121}
122
123static overlay_t* overlay_createOverlay(struct overlay_device_t *dev,
124 uint32_t w, uint32_t h, int32_t format)
125{
126 /* check the input params, reject if not supported or invalid */
127 switch (format) {
128 case OVERLAY_FORMAT_RGBA_8888:
129 case OVERLAY_FORMAT_RGB_565:
130 case OVERLAY_FORMAT_BGRA_8888:
131 case OVERLAY_FORMAT_YCbCr_422_SP:
132 case OVERLAY_FORMAT_YCbCr_420_SP:
133 case OVERLAY_FORMAT_YCbCr_422_P:
134 case OVERLAY_FORMAT_YCbCr_420_P:
135 break;
136 default:
137 return NULL;
138 }
139
140 /* Create overlay object. Talk to the h/w here and adjust to what it can
141 * do. the overlay_t returned can be a C++ object, subclassing overlay_t
142 * if needed.
143 *
144 * we probably want to keep a list of the overlay_t created so they can
145 * all be cleaned up in overlay_close().
146 */
147 return new overlay_object( /* pass needed params here*/ );
148}
149
150static void overlay_destroyOverlay(struct overlay_device_t *dev,
151 overlay_t* overlay)
152{
153 /* free resources associated with this overlay_t */
154 delete overlay;
155}
156
157static int overlay_setPosition(struct overlay_device_t *dev,
158 overlay_t* overlay,
159 int x, int y, uint32_t w, uint32_t h) {
160 /* set this overlay's position (talk to the h/w) */
161 return -EINVAL;
162}
163
164static int overlay_getPosition(struct overlay_device_t *dev,
165 overlay_t* overlay,
166 int* x, int* y, uint32_t* w, uint32_t* h) {
167 /* get this overlay's position */
168 return -EINVAL;
169}
170
171static int overlay_setParameter(struct overlay_device_t *dev,
172 overlay_t* overlay, int param, int value) {
173
174 int result = 0;
175 /* set this overlay's parameter (talk to the h/w) */
176 switch (param) {
177 case OVERLAY_ROTATION_DEG:
178 break;
179 case OVERLAY_DITHER:
180 break;
181 default:
182 result = -EINVAL;
183 break;
184 }
185 return result;
186}
187
188static int overlay_swapBuffers(struct overlay_device_t *dev,
189 overlay_t* overlay) {
190 /* swap this overlay's buffers (talk to the h/w), this call probably
191 * wants to block until a new buffer is available */
192 return -EINVAL;
193}
194
195static int overlay_getOffset(struct overlay_device_t *dev,
196 overlay_t* overlay) {
197 /* return the current's buffer offset */
198 return 0;
199}
200
201static int overlay_getMemory(struct overlay_device_t *dev) {
202 /* maps this overlay if possible. don't forget to unmap in destroyOverlay */
203 return -EINVAL;
204}
205
206/*****************************************************************************/
207
208
209static int overlay_device_close(struct hw_device_t *dev)
210{
211 struct overlay_context_t* ctx = (struct overlay_context_t*)dev;
212 if (ctx) {
213 /* free all resources associated with this device here */
214 free(ctx);
215 }
216 return 0;
217}
218
219
220static int overlay_device_open(const struct hw_module_t* module, const char* name,
221 struct hw_device_t** device)
222{
223 int status = -EINVAL;
224 if (!strcmp(name, OVERLAY_HARDWARE_OVERLAY0)) {
225 struct overlay_context_t *dev;
226 dev = (overlay_context_t*)malloc(sizeof(*dev));
227
228 /* initialize our state here */
229 memset(dev, 0, sizeof(*dev));
230
231 /* initialize the procs */
232 dev->device.common.tag = HARDWARE_DEVICE_TAG;
233 dev->device.common.version = 0;
234 dev->device.common.module = const_cast<hw_module_t*>(module);
235 dev->device.common.close = overlay_device_close;
236
237 dev->device.get = overlay_get;
238 dev->device.createOverlay = overlay_createOverlay;
239 dev->device.destroyOverlay = overlay_destroyOverlay;
240 dev->device.setPosition = overlay_setPosition;
241 dev->device.getPosition = overlay_getPosition;
242 dev->device.setParameter = overlay_setParameter;
243 dev->device.swapBuffers = overlay_swapBuffers;
244 dev->device.getOffset = overlay_getOffset;
245 dev->device.getMemory = overlay_getMemory;
246
247 *device = &dev->device.common;
248 status = 0;
249 }
250 return status;
251}