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