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