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