• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
4  *
5  * Not a Contribution, Apache license notifications and license are retained
6  * for attribution purposes only.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef ANDROID_COPYBIT_INTERFACE_H
22 #define ANDROID_COPYBIT_INTERFACE_H
23 
24 #include <hardware/hardware.h>
25 
26 #include <stdint.h>
27 #include <sys/cdefs.h>
28 #include <sys/types.h>
29 
30 __BEGIN_DECLS
31 
32 /**
33  * The id of this module
34  */
35 #define COPYBIT_HARDWARE_MODULE_ID "copybit"
36 
37 /**
38  * Name of the graphics device to open
39  */
40 #define COPYBIT_HARDWARE_COPYBIT0 "copybit0"
41 
42 /* supported pixel-formats. these must be compatible with
43  * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h
44  */
45 enum {
46     COPYBIT_FORMAT_RGBA_8888    = HAL_PIXEL_FORMAT_RGBA_8888,
47     COPYBIT_FORMAT_RGBX_8888    = HAL_PIXEL_FORMAT_RGBX_8888,
48     COPYBIT_FORMAT_RGB_888      = HAL_PIXEL_FORMAT_RGB_888,
49     COPYBIT_FORMAT_RGB_565      = HAL_PIXEL_FORMAT_RGB_565,
50     COPYBIT_FORMAT_BGRA_8888    = HAL_PIXEL_FORMAT_BGRA_8888,
51     COPYBIT_FORMAT_YCbCr_422_SP = 0x10,
52     COPYBIT_FORMAT_YCrCb_420_SP = 0x11,
53 };
54 
55 /* name for copybit_set_parameter */
56 enum {
57     /* Default blit destination is offline buffer */
58     /* clients to set this to '1', if blitting to framebuffer */
59     /* and reset to '0', after calling blit/stretch */
60     COPYBIT_BLIT_TO_FRAMEBUFFER = 0,
61     /* rotation of the source image in degrees (0 to 359) */
62     COPYBIT_ROTATION_DEG    = 1,
63     /* plane alpha value */
64     COPYBIT_PLANE_ALPHA     = 2,
65     /* enable or disable dithering */
66     COPYBIT_DITHER          = 3,
67     /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
68     COPYBIT_TRANSFORM       = 4,
69     /* blurs the copied bitmap. The amount of blurring cannot be changed
70      * at this time. */
71     COPYBIT_BLUR            = 5,
72     /* Blend mode */
73     COPYBIT_BLEND_MODE  = 6,
74     /* FB width */
75     COPYBIT_FRAMEBUFFER_WIDTH = 7,
76     /* FB height */
77     COPYBIT_FRAMEBUFFER_HEIGHT = 8,
78     COPYBIT_FG_LAYER = 9,
79 };
80 
81 /* values for copybit_set_parameter(COPYBIT_TRANSFORM) */
82 enum {
83     /* flip source image horizontally */
84     COPYBIT_TRANSFORM_FLIP_H    = HAL_TRANSFORM_FLIP_H,
85     /* flip source image vertically */
86     COPYBIT_TRANSFORM_FLIP_V    = HAL_TRANSFORM_FLIP_V,
87     /* rotate source image 90 degres */
88     COPYBIT_TRANSFORM_ROT_90    = HAL_TRANSFORM_ROT_90,
89     /* rotate source image 180 degres */
90     COPYBIT_TRANSFORM_ROT_180   = HAL_TRANSFORM_ROT_180,
91     /* rotate source image 270 degres */
92     COPYBIT_TRANSFORM_ROT_270   = HAL_TRANSFORM_ROT_270,
93 };
94 
95 /* enable/disable value copybit_set_parameter */
96 enum {
97     COPYBIT_DISABLE = 0,
98     COPYBIT_ENABLE  = 1
99 };
100 
101 /*
102  * copybit blending values. same as HWC blending values
103  */
104 enum {
105     /* no blending */
106     COPYBIT_BLENDING_NONE     = 0x0100,
107 
108     /* ONE / ONE_MINUS_SRC_ALPHA */
109     COPYBIT_BLENDING_PREMULT  = 0x0105,
110 
111     /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
112     COPYBIT_BLENDING_COVERAGE = 0x0405
113 };
114 
115 /* use get_static_info() to query static informations about the hardware */
116 enum {
117     /* Maximum amount of minification supported by the hardware*/
118     COPYBIT_MINIFICATION_LIMIT  = 1,
119     /* Maximum amount of magnification supported by the hardware */
120     COPYBIT_MAGNIFICATION_LIMIT = 2,
121     /* Number of fractional bits support by the scaling engine */
122     COPYBIT_SCALING_FRAC_BITS   = 3,
123     /* Supported rotation step in degres. */
124     COPYBIT_ROTATION_STEP_DEG   = 4,
125 };
126 
127 /* Image structure */
128 struct copybit_image_t {
129     /* width */
130     uint32_t    w;
131     /* height */
132     uint32_t    h;
133     /* format COPYBIT_FORMAT_xxx */
134     int32_t     format;
135     /* base of buffer with image */
136     void        *base;
137     /* handle to the image */
138     native_handle_t* handle;
139     /* number of pixels added for the stride */
140     uint32_t    horiz_padding;
141     /* number of pixels added for the vertical stride */
142     uint32_t    vert_padding;
143 };
144 
145 /* Rectangle */
146 struct copybit_rect_t {
147     /* left */
148     int l;
149     /* top */
150     int t;
151     /* right */
152     int r;
153     /* bottom */
154     int b;
155 };
156 
157 /* Region */
158 struct copybit_region_t {
159     int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect);
160 };
161 
162 /**
163  * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
164  * and the fields of this data structure must begin with hw_module_t
165  * followed by module specific information.
166  */
167 struct copybit_module_t {
168     struct hw_module_t common;
169 };
170 
171 /**
172  * Every device data structure must begin with hw_device_t
173  * followed by module specific public methods and attributes.
174  */
175 struct copybit_device_t {
176     struct hw_device_t common;
177 
178     /**
179      * Set a copybit parameter.
180      *
181      * @param dev from open
182      * @param name one for the COPYBIT_NAME_xxx
183      * @param value one of the COPYBIT_VALUE_xxx
184      *
185      * @return 0 if successful
186      */
187     int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
188 
189     /**
190      * Get a static copybit information.
191      *
192      * @param dev from open
193      * @param name one of the COPYBIT_STATIC_xxx
194      *
195      * @return value or -EINVAL if error
196      */
197     int (*get)(struct copybit_device_t *dev, int name);
198 
199     /**
200      * Execute the bit blit copy operation
201      *
202      * @param dev from open
203      * @param dst is the destination image
204      * @param src is the source image
205      * @param region the clip region
206      *
207      * @return 0 if successful
208      */
209     int (*blit)(struct copybit_device_t *dev,
210                 struct copybit_image_t const *dst,
211                 struct copybit_image_t const *src,
212                 struct copybit_region_t const *region);
213 
214     /**
215      * Give acquire fence to copybit to be used in upcoming stretch
216      * call
217      *
218      * @param dev from open
219      * @param acquireFenceFd is the acquire fence
220      *
221      * @return 0 if successful
222      */
223     int (*set_sync)(struct copybit_device_t *dev,
224                    int acquireFenceFd);
225 
226     /**
227      * Execute the stretch bit blit copy operation
228      *
229      * @param dev from open
230      * @param dst is the destination image
231      * @param src is the source image
232      * @param dst_rect is the destination rectangle
233      * @param src_rect is the source rectangle
234      * @param region the clip region
235      *
236      * @return 0 if successful
237      */
238     int (*stretch)(struct copybit_device_t *dev,
239                    struct copybit_image_t const *dst,
240                    struct copybit_image_t const *src,
241                    struct copybit_rect_t const *dst_rect,
242                    struct copybit_rect_t const *src_rect,
243                    struct copybit_region_t const *region);
244 
245     /**
246      * Fill the rect on dst with RGBA color
247      *
248      * @param dev from open
249      * @param dst is destination image
250      * @param rect is destination rectangle
251      * @param color is RGBA color to fill
252      *
253      * @return 0 if successful
254      */
255     int (*fill_color)(struct copybit_device_t *dev,
256                       struct copybit_image_t const *dst,
257                       struct copybit_rect_t const *rect,
258                       uint32_t color);
259 
260   /**
261     * Execute the completion of the copybit draw operation.
262     *
263     * @param dev from open
264     *
265     * @return 0 if successful
266     */
267   int (*finish)(struct copybit_device_t *dev);
268 
269   /**
270     * Trigger the copybit draw operation(async).
271     *
272     * @param dev from open
273     *
274     * @param fd - gets the fencefd
275     *
276     * @return 0 if successful
277     */
278   int (*flush_get_fence)(struct copybit_device_t *dev, int* fd);
279 
280   /* Clears the buffer
281    */
282   int (*clear)(struct copybit_device_t *dev, struct copybit_image_t const *buf,
283                struct copybit_rect_t *rect);
284 };
285 
286 
287 /** convenience API for opening and closing a device */
288 
copybit_open(const struct hw_module_t * module,struct copybit_device_t ** device)289 static inline int copybit_open(const struct hw_module_t* module,
290                                struct copybit_device_t** device) {
291     return module->methods->open(module,
292                                  COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device);
293 }
294 
copybit_close(struct copybit_device_t * device)295 static inline int copybit_close(struct copybit_device_t* device) {
296     return device->common.close(&device->common);
297 }
298 
299 
300 __END_DECLS
301 
302 #endif  // ANDROID_COPYBIT_INTERFACE_H
303