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