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