blob: 833aa328c21a0e109f511fa0fe954a3f1190b5ac [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;
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800106 /* base of buffer with image */
Mathias Agopian689fa732009-06-24 16:54:44 -0700107 void *base;
108 /* handle to the image */
109 native_handle_t* handle;
The Android Open Source Projectf53ebec2009-03-03 19:32:14 -0800110};
111
112/* Rectangle */
113struct copybit_rect_t {
114 /* left */
115 int l;
116 /* top */
117 int t;
118 /* right */
119 int r;
120 /* bottom */
121 int b;
122};
123
124/* Region */
125struct copybit_region_t {
126 int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect);
127};
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 copybit_module_t {
135 struct hw_module_t common;
136};
137
138/**
139 * Every device data structure must begin with hw_device_t
140 * followed by module specific public methods and attributes.
141 */
142struct copybit_device_t {
143 struct hw_device_t common;
144
145 /**
146 * Set a copybit parameter.
147 *
148 * @param dev from open
149 * @param name one for the COPYBIT_NAME_xxx
150 * @param value one of the COPYBIT_VALUE_xxx
151 *
152 * @return 0 if successful
153 */
154 int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
155
156 /**
157 * Get a static copybit information.
158 *
159 * @param dev from open
160 * @param name one of the COPYBIT_STATIC_xxx
161 *
162 * @return value or -EINVAL if error
163 */
164 int (*get)(struct copybit_device_t *dev, int name);
165
166 /**
167 * Execute the bit blit copy operation
168 *
169 * @param dev from open
170 * @param dst is the destination image
171 * @param src is the source image
172 * @param region the clip region
173 *
174 * @return 0 if successful
175 */
176 int (*blit)(struct copybit_device_t *dev,
177 struct copybit_image_t const *dst,
178 struct copybit_image_t const *src,
179 struct copybit_region_t const *region);
180
181 /**
182 * Execute the stretch bit blit copy operation
183 *
184 * @param dev from open
185 * @param dst is the destination image
186 * @param src is the source image
187 * @param dst_rect is the destination rectangle
188 * @param src_rect is the source rectangle
189 * @param region the clip region
190 *
191 * @return 0 if successful
192 */
193 int (*stretch)(struct copybit_device_t *dev,
194 struct copybit_image_t const *dst,
195 struct copybit_image_t const *src,
196 struct copybit_rect_t const *dst_rect,
197 struct copybit_rect_t const *src_rect,
198 struct copybit_region_t const *region);
199};
200
201
202/** convenience API for opening and closing a device */
203
204static inline int copybit_open(const struct hw_module_t* module,
205 struct copybit_device_t** device) {
206 return module->methods->open(module,
207 COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device);
208}
209
210static inline int copybit_close(struct copybit_device_t* device) {
211 return device->common.close(&device->common);
212}
213
214
215__END_DECLS
216
217#endif // ANDROID_COPYBIT_INTERFACE_H