1 /* 2 * Copyright (C) 2020 Rockchip Electronics Co., Ltd. 3 * Authors: 4 * PutinLee <putin.lee@rock-chips.com> 5 * Cerf Yu <cerf.yu@rock-chips.com> 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 #ifndef _im2d_hpp_ 20 #define _im2d_hpp_ 21 22 #include "im2d.h" 23 #include "RgaUtils.h" 24 25 #ifdef ANDROID 26 27 #include <ui/GraphicBuffer.h> 28 29 using namespace android; 30 #endif 31 32 /* 33 * Import external buffers into RGA driver. 34 * 35 * @param fd/va/pa 36 * Select dma_fd/virtual_address/physical_address by buffer type 37 * @param size 38 * Describes the size of the image buffer 39 * 40 * @return rga_buffer_handle_t 41 */ 42 IM_API rga_buffer_handle_t importbuffer_fd(int fd, int size); 43 IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, int size); 44 IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, int size); 45 46 /* 47 * Import external buffers into RGA driver. 48 * 49 * @param fd/va/pa 50 * Select dma_fd/virtual_address/physical_address by buffer type 51 * @param width 52 * Describes the pixel width stride of the image buffer 53 * @param height 54 * Describes the pixel height stride of the image buffer 55 * @param format 56 * Describes the pixel format of the image buffer 57 * 58 * @return rga_buffer_handle_t 59 */ 60 IM_API rga_buffer_handle_t importbuffer_fd(int fd, int width, int height, int format); 61 IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, int width, int height, int format); 62 IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, int width, int height, int format); 63 64 #undef wrapbuffer_handle 65 IM_API rga_buffer_t wrapbuffer_handle(rga_buffer_handle_t handle, 66 int width, int height, 67 int wstride, int hstride, 68 int format); 69 IM_API rga_buffer_t wrapbuffer_handle(rga_buffer_handle_t handle, 70 int width, int height, 71 int format); 72 73 #if ANDROID 74 IM_API rga_buffer_handle_t importbuffer_GraphicBuffer_handle(buffer_handle_t hnd); 75 IM_API rga_buffer_handle_t importbuffer_GraphicBuffer(sp<GraphicBuffer> buf); 76 77 IM_API rga_buffer_t wrapbuffer_handle(buffer_handle_t hnd); 78 IM_API rga_buffer_t wrapbuffer_GraphicBuffer(sp<GraphicBuffer> buf); 79 80 #if USE_AHARDWAREBUFFER 81 #include <android/hardware_buffer.h> 82 IM_API rga_buffer_handle_t importbuffer_AHardwareBuffer(AHardwareBuffer *buf); 83 IM_API rga_buffer_t wrapbuffer_AHardwareBuffer(AHardwareBuffer *buf); 84 85 #endif /* USE_AHARDWAREBUFFER */ 86 #endif /* ANDROID */ 87 88 /* 89 * Resize 90 * 91 * @param src 92 * @param dst 93 * @param fx 94 * @param fy 95 * @param interpolation 96 * @param sync 97 * wait until operation complete 98 * 99 * @returns success or else negative error code. 100 */ 101 #undef imresize 102 IM_API IM_STATUS imresize(const rga_buffer_t src, rga_buffer_t dst, double fx = 0, double fy = 0, int interpolation = 0, int sync = 1, int *release_fence_fd = NULL); 103 104 /* 105 * Crop 106 * 107 * @param src 108 * @param dst 109 * @param rect 110 * @param sync 111 * wait until operation complete 112 * 113 * @returns success or else negative error code. 114 */ 115 #undef imcrop 116 IM_API IM_STATUS imcrop(const rga_buffer_t src, rga_buffer_t dst, im_rect rect, int sync = 1, int *release_fence_fd = NULL); 117 118 /* 119 * rotation 120 * 121 * @param src 122 * @param dst 123 * @param rotation 124 * IM_HAL_TRANSFORM_ROT_90 125 * IM_HAL_TRANSFORM_ROT_180 126 * IM_HAL_TRANSFORM_ROT_270 127 * @param sync 128 * wait until operation complete 129 * 130 * @returns success or else negative error code. 131 */ 132 #undef imrotate 133 IM_API IM_STATUS imrotate(const rga_buffer_t src, rga_buffer_t dst, int rotation, int sync = 1, int *release_fence_fd = NULL); 134 135 /* 136 * flip 137 * 138 * @param src 139 * @param dst 140 * @param mode 141 * IM_HAL_TRANSFORM_FLIP_H 142 * IM_HAL_TRANSFORM_FLIP_V 143 * @param sync 144 * wait until operation complete 145 * 146 * @returns success or else negative error code. 147 */ 148 #undef imflip 149 IM_API IM_STATUS imflip(const rga_buffer_t src, rga_buffer_t dst, int mode, int sync = 1, int *release_fence_fd = NULL); 150 151 /* 152 * fill/reset/draw 153 * 154 * @param src 155 * @param dst 156 * @param rect 157 * @param color 158 * @param sync 159 * wait until operation complete 160 * 161 * @returns success or else negative error code. 162 */ 163 #undef imfill 164 IM_API IM_STATUS imfill(rga_buffer_t dst, im_rect rect, int color, int sync = 1, int *release_fence_fd = NULL); 165 166 /* 167 * palette 168 * 169 * @param src 170 * @param dst 171 * @param lut 172 * @param sync 173 * wait until operation complete 174 * 175 * @returns success or else negative error code. 176 */ 177 #undef impalette 178 IM_API IM_STATUS impalette(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t lut, int sync = 1, int *release_fence_fd = NULL); 179 180 /* 181 * translate 182 * 183 * @param src 184 * @param dst 185 * @param x 186 * @param y 187 * @param sync 188 * wait until operation complete 189 * 190 * @returns success or else negative error code. 191 */ 192 #undef imtranslate 193 IM_API IM_STATUS imtranslate(const rga_buffer_t src, rga_buffer_t dst, int x, int y, int sync = 1, int *release_fence_fd = NULL); 194 195 /* 196 * copy 197 * 198 * @param src 199 * @param dst 200 * @param sync 201 * wait until operation complete 202 * 203 * @returns success or else negative error code. 204 */ 205 #undef imcopy 206 IM_API IM_STATUS imcopy(const rga_buffer_t src, rga_buffer_t dst, int sync = 1, int *release_fence_fd = NULL); 207 208 /* 209 * blend (SRC + DST -> DST or SRCA + SRCB -> DST) 210 * 211 * @param srcA 212 * @param srcB can be NULL. 213 * @param dst 214 * @param mode 215 * IM_ALPHA_BLEND_MODE 216 * @param sync 217 * wait until operation complete 218 * 219 * @returns success or else negative error code. 220 */ 221 #undef imblend 222 IM_API IM_STATUS imblend(const rga_buffer_t src, rga_buffer_t dst, int mode = IM_ALPHA_BLEND_SRC_OVER, int sync = 1, int *release_fence_fd = NULL); 223 #undef imcomposite 224 IM_API IM_STATUS imcomposite(const rga_buffer_t srcA, const rga_buffer_t srcB, rga_buffer_t dst, int mode = IM_ALPHA_BLEND_SRC_OVER, int sync = 1, int *release_fence_fd = NULL); 225 226 /* 227 * color key 228 * 229 * @param src 230 * @param dst 231 * @param colorkey_range 232 * max color 233 * min color 234 * @param sync 235 * wait until operation complete 236 * 237 * @returns success or else negative error code. 238 */ 239 #undef imcolorkey 240 IM_API IM_STATUS imcolorkey(const rga_buffer_t src, rga_buffer_t dst, im_colorkey_range range, int mode = IM_ALPHA_COLORKEY_NORMAL, int sync = 1, int *release_fence_fd = NULL); 241 242 /* 243 * format convert 244 * 245 * @param src 246 * @param dst 247 * @param sfmt 248 * @param dfmt 249 * @param mode 250 * color space mode: IM_COLOR_SPACE_MODE 251 * @param sync 252 * wait until operation complete 253 * 254 * @returns success or else negative error code. 255 */ 256 #undef imcvtcolor 257 IM_API IM_STATUS imcvtcolor(rga_buffer_t src, rga_buffer_t dst, int sfmt, int dfmt, int mode = IM_COLOR_SPACE_DEFAULT, int sync = 1, int *release_fence_fd = NULL); 258 259 /* 260 * nn quantize 261 * 262 * @param src 263 * @param dst 264 * @param nninfo 265 * @param sync 266 * wait until operation complete 267 * 268 * @returns success or else negative error code. 269 */ 270 #undef imquantize 271 IM_API IM_STATUS imquantize(const rga_buffer_t src, rga_buffer_t dst, im_nn_t nn_info, int sync = 1, int *release_fence_fd = NULL); 272 273 /* 274 * ROP 275 * 276 * @param src 277 * @param dst 278 * @param rop_code 279 * @param sync 280 * wait until operation complete 281 * 282 * @returns success or else negative error code. 283 */ 284 #undef imrop 285 IM_API IM_STATUS imrop(const rga_buffer_t src, rga_buffer_t dst, int rop_code, int sync = 1, int *release_fence_fd = NULL); 286 287 /* 288 * MOSAIC 289 * 290 * @param src 291 * @param dst 292 * @param mosaic_mode 293 * @param sync 294 * wait until operation complete 295 * 296 * @returns success or else negative error code. 297 */ 298 IM_API IM_STATUS immosaic(const rga_buffer_t image, im_rect rect, int mosaic_mode, int sync = 1, int *release_fence_fd = NULL); 299 300 /* 301 * OSD 302 * 303 * @param osd 304 * osd block 305 * @param dst 306 * background image 307 * @param osd_rect 308 * @param osd_config 309 * osd mode config 310 * @param sync 311 * wait until operation complete 312 * 313 * @returns success or else negative error code. 314 */ 315 IM_API IM_STATUS imosd(const rga_buffer_t osd,const rga_buffer_t dst, 316 const im_rect osd_rect, im_osd_t *osd_config, 317 int sync = 1, int *release_fence_fd = NULL); 318 319 /* 320 * process 321 * 322 * @param src 323 * @param dst 324 * @param pat 325 * @param srect 326 * @param drect 327 * @param prect 328 * @param acquire_fence_fd 329 * @param release_fence_fd 330 * @param opt 331 * @param usage 332 * 333 * @returns success or else negative error code. 334 */ 335 IM_API IM_STATUS improcess(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t pat, 336 im_rect srect, im_rect drect, im_rect prect, 337 int acquire_fence_fd, int *release_fence_fd, im_opt_t *opt_ptr, int usage); 338 IM_API IM_STATUS improcess(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t pat, 339 im_rect srect, im_rect drect, im_rect prect, 340 int acquire_fence_fd, int *release_fence_fd, im_opt_t *opt, int usage, im_ctx_id_t ctx_id); 341 342 #endif /* _im2d_hpp_ */ 343 344