blob: 6384dfe541253b9ae38958a2c02f5e7d2be798d4 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
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_COPYBIT_INTERFACE_H
18#define ANDROID_COPYBIT_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 COPYBIT_HARDWARE_MODULE_ID "copybit"
32
33/**
34 * Name of the graphics device to open
35 */
36#define COPYBIT_HARDWARE_COPYBIT0 "copybit0"
37
38/* supported pixel-formats. these must be compatible with
39 * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h
40 */
41enum {
42 COPYBIT_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888,
43 COPYBIT_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888,
44 COPYBIT_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888,
45 COPYBIT_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565,
46 COPYBIT_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888,
47 COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551,
48 COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444,
49 COPYBIT_FORMAT_YCbCr_422_SP = 0x10,
50 COPYBIT_FORMAT_YCrCb_420_SP = 0x11,
51};
52
53/* name for copybit_set_parameter */
54enum {
55 /* rotation of the source image in degrees (0 to 359) */
56 COPYBIT_ROTATION_DEG = 1,
57 /* plane alpha value */
58 COPYBIT_PLANE_ALPHA = 2,
59 /* enable or disable dithering */
60 COPYBIT_DITHER = 3,
61 /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
62 COPYBIT_TRANSFORM = 4,
63 /* blurs the copied bitmap. The amount of blurring cannot be changed
64 * at this time. */
65 COPYBIT_BLUR = 5,
66 /* Informs the copybit that the source and destination contains
67 premultiplied alpha */
68 COPYBIT_PREMULTIPLIED_ALPHA = 6,
69 /* FB width */
70 COPYBIT_FRAMEBUFFER_WIDTH = 7,
71 /* FB height */
72 COPYBIT_FRAMEBUFFER_HEIGHT = 8,
73};
74
75/* values for copybit_set_parameter(COPYBIT_TRANSFORM) */
76enum {
77 /* flip source image horizontally */
78 COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
79 /* flip source image vertically */
80 COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
81 /* rotate source image 90 degres */
82 COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
83 /* rotate source image 180 degres */
84 COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
85 /* rotate source image 270 degres */
86 COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
87};
88
89/* enable/disable value copybit_set_parameter */
90enum {
91 COPYBIT_DISABLE = 0,
92 COPYBIT_ENABLE = 1
93};
94
95/* use get_static_info() to query static informations about the hardware */
96enum {
97 /* Maximum amount of minification supported by the hardware*/
98 COPYBIT_MINIFICATION_LIMIT = 1,
99 /* Maximum amount of magnification supported by the hardware */
100 COPYBIT_MAGNIFICATION_LIMIT = 2,
101 /* Number of fractional bits support by the scaling engine */
102 COPYBIT_SCALING_FRAC_BITS = 3,
103 /* Supported rotation step in degres. */
104 COPYBIT_ROTATION_STEP_DEG = 4,
105};
106
107/* Image structure */
108struct copybit_image_t {
109 /* width */
110 uint32_t w;
111 /* height */
112 uint32_t h;
113 /* format COPYBIT_FORMAT_xxx */
114 int32_t format;
115 /* base of buffer with image */
116 void *base;
117 /* handle to the image */
118 native_handle_t* handle;
119 /* number of pixels added for the stride */
120 uint32_t horiz_padding;
121 /* number of pixels added for the vertical stride */
122 uint32_t vert_padding;
123};
124
125/* Rectangle */
126struct copybit_rect_t {
127 /* left */
128 int l;
129 /* top */
130 int t;
131 /* right */
132 int r;
133 /* bottom */
134 int b;
135};
136
137/* Region */
138struct copybit_region_t {
139 int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect);
140};
141
142/**
143 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
144 * and the fields of this data structure must begin with hw_module_t
145 * followed by module specific information.
146 */
147struct copybit_module_t {
148 struct hw_module_t common;
149};
150
151/**
152 * Every device data structure must begin with hw_device_t
153 * followed by module specific public methods and attributes.
154 */
155struct copybit_device_t {
156 struct hw_device_t common;
157
158 /**
159 * Set a copybit parameter.
160 *
161 * @param dev from open
162 * @param name one for the COPYBIT_NAME_xxx
163 * @param value one of the COPYBIT_VALUE_xxx
164 *
165 * @return 0 if successful
166 */
167 int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
168
169 /**
170 * Get a static copybit information.
171 *
172 * @param dev from open
173 * @param name one of the COPYBIT_STATIC_xxx
174 *
175 * @return value or -EINVAL if error
176 */
177 int (*get)(struct copybit_device_t *dev, int name);
178
179 /**
180 * Execute the bit blit copy operation
181 *
182 * @param dev from open
183 * @param dst is the destination image
184 * @param src is the source image
185 * @param region the clip region
186 *
187 * @return 0 if successful
188 */
189 int (*blit)(struct copybit_device_t *dev,
190 struct copybit_image_t const *dst,
191 struct copybit_image_t const *src,
192 struct copybit_region_t const *region);
193
194 /**
195 * Execute the stretch bit blit copy operation
196 *
197 * @param dev from open
198 * @param dst is the destination image
199 * @param src is the source image
200 * @param dst_rect is the destination rectangle
201 * @param src_rect is the source rectangle
202 * @param region the clip region
203 *
204 * @return 0 if successful
205 */
206 int (*stretch)(struct copybit_device_t *dev,
207 struct copybit_image_t const *dst,
208 struct copybit_image_t const *src,
209 struct copybit_rect_t const *dst_rect,
210 struct copybit_rect_t const *src_rect,
211 struct copybit_region_t const *region);
212};
213
214
215/** convenience API for opening and closing a device */
216
217static inline int copybit_open(const struct hw_module_t* module,
218 struct copybit_device_t** device) {
219 return module->methods->open(module,
220 COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device);
221}
222
223static inline int copybit_close(struct copybit_device_t* device) {
224 return device->common.close(&device->common);
225}
226
227
228__END_DECLS
229
230#endif // ANDROID_COPYBIT_INTERFACE_H