im2d_buffer.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (C) 2022 Rockchip Electronics Co., Ltd.
  3. * Authors:
  4. * Cerf Yu <cerf.yu@rock-chips.com>
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef _im2d_buffer_h_
  19. #define _im2d_buffer_h_
  20. #include "im2d_type.h"
  21. /**
  22. * Import external buffers into RGA driver.
  23. *
  24. * @param fd/va/pa
  25. * Select dma_fd/virtual_address/physical_address by buffer type
  26. * @param size
  27. * Describes the size of the image buffer
  28. *
  29. * @return rga_buffer_handle_t
  30. */
  31. #ifdef __cplusplus
  32. IM_API rga_buffer_handle_t importbuffer_fd(int fd, int size);
  33. IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, int size);
  34. IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, int size);
  35. #endif
  36. /**
  37. * Import external buffers into RGA driver.
  38. *
  39. * @param fd/va/pa
  40. * Select dma_fd/virtual_address/physical_address by buffer type
  41. * @param width
  42. * Describes the pixel width stride of the image buffer
  43. * @param height
  44. * Describes the pixel height stride of the image buffer
  45. * @param format
  46. * Describes the pixel format of the image buffer
  47. *
  48. * @return rga_buffer_handle_t
  49. */
  50. #ifdef __cplusplus
  51. IM_API rga_buffer_handle_t importbuffer_fd(int fd, int width, int height, int format);
  52. IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, int width, int height, int format);
  53. IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, int width, int height, int format);
  54. #endif
  55. /**
  56. * Import external buffers into RGA driver.
  57. *
  58. * @param fd/va/pa
  59. * Select dma_fd/virtual_address/physical_address by buffer type
  60. * @param param
  61. * Configure buffer parameters
  62. *
  63. * @return rga_buffer_handle_t
  64. */
  65. IM_EXPORT_API rga_buffer_handle_t importbuffer_fd(int fd, im_handle_param_t *param);
  66. IM_EXPORT_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, im_handle_param_t *param);
  67. IM_EXPORT_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, im_handle_param_t *param);
  68. /**
  69. * Import external buffers into RGA driver.
  70. *
  71. * @param handle
  72. * rga buffer handle
  73. *
  74. * @return success or else negative error code.
  75. */
  76. IM_EXPORT_API IM_STATUS releasebuffer_handle(rga_buffer_handle_t handle);
  77. /**
  78. * Wrap image Parameters.
  79. *
  80. * @param handle/virtualaddr/physicaladdr/fd
  81. * RGA buffer handle/virtualaddr/physicaladdr/fd.
  82. * @param width
  83. * Width of image manipulation area.
  84. * @param height
  85. * Height of image manipulation area.
  86. * @param wstride
  87. * Width pixel stride, default (width = wstride).
  88. * @param hstride
  89. * Height pixel stride, default (height = hstride).
  90. * @param format
  91. * Image format.
  92. *
  93. * @return rga_buffer_t
  94. */
  95. #define wrapbuffer_handle(handle, width, height, format, ...) \
  96. ({ \
  97. rga_buffer_t im2d_api_buffer; \
  98. int __args[] = {__VA_ARGS__}; \
  99. int __argc = sizeof(__args)/sizeof(int); \
  100. if (__argc == 0) { \
  101. im2d_api_buffer = wrapbuffer_handle_t(handle, width, height, width, height, format); \
  102. } else if (__argc == 2){ \
  103. im2d_api_buffer = wrapbuffer_handle_t(handle, width, height, __args[0], __args[1], format); \
  104. } else { \
  105. memset(&im2d_api_buffer, 0x0, sizeof(im2d_api_buffer)); \
  106. printf("invalid parameter\n"); \
  107. } \
  108. im2d_api_buffer; \
  109. })
  110. #define wrapbuffer_virtualaddr(vir_addr, width, height, format, ...) \
  111. ({ \
  112. rga_buffer_t im2d_api_buffer; \
  113. int __args[] = {__VA_ARGS__}; \
  114. int __argc = sizeof(__args)/sizeof(int); \
  115. if (__argc == 0) { \
  116. im2d_api_buffer = wrapbuffer_virtualaddr_t(vir_addr, width, height, width, height, format); \
  117. } else if (__argc == 2){ \
  118. im2d_api_buffer = wrapbuffer_virtualaddr_t(vir_addr, width, height, __args[0], __args[1], format); \
  119. } else { \
  120. memset(&im2d_api_buffer, 0x0, sizeof(im2d_api_buffer)); \
  121. printf("invalid parameter\n"); \
  122. } \
  123. im2d_api_buffer; \
  124. })
  125. #define wrapbuffer_physicaladdr(phy_addr, width, height, format, ...) \
  126. ({ \
  127. rga_buffer_t im2d_api_buffer; \
  128. int __args[] = {__VA_ARGS__}; \
  129. int __argc = sizeof(__args)/sizeof(int); \
  130. if (__argc == 0) { \
  131. im2d_api_buffer = wrapbuffer_physicaladdr_t(phy_addr, width, height, width, height, format); \
  132. } else if (__argc == 2){ \
  133. im2d_api_buffer = wrapbuffer_physicaladdr_t(phy_addr, width, height, __args[0], __args[1], format); \
  134. } else { \
  135. memset(&im2d_api_buffer, 0x0, sizeof(im2d_api_buffer)); \
  136. printf("invalid parameter\n"); \
  137. } \
  138. im2d_api_buffer; \
  139. })
  140. #define wrapbuffer_fd(fd, width, height, format, ...) \
  141. ({ \
  142. rga_buffer_t im2d_api_buffer; \
  143. int __args[] = {__VA_ARGS__}; \
  144. int __argc = sizeof(__args)/sizeof(int); \
  145. if (__argc == 0) { \
  146. im2d_api_buffer = wrapbuffer_fd_t(fd, width, height, width, height, format); \
  147. } else if (__argc == 2){ \
  148. im2d_api_buffer = wrapbuffer_fd_t(fd, width, height, __args[0], __args[1], format); \
  149. } else { \
  150. memset(&im2d_api_buffer, 0x0, sizeof(im2d_api_buffer)); \
  151. printf("invalid parameter\n"); \
  152. } \
  153. im2d_api_buffer; \
  154. })
  155. /* Symbols for define *_t functions */
  156. IM_C_API rga_buffer_t wrapbuffer_handle_t(rga_buffer_handle_t handle, int width, int height, int wstride, int hstride, int format);
  157. IM_C_API rga_buffer_t wrapbuffer_virtualaddr_t(void* vir_addr, int width, int height, int wstride, int hstride, int format);
  158. IM_C_API rga_buffer_t wrapbuffer_physicaladdr_t(void* phy_addr, int width, int height, int wstride, int hstride, int format);
  159. IM_C_API rga_buffer_t wrapbuffer_fd_t(int fd, int width, int height, int wstride, int hstride, int format);
  160. #ifdef __cplusplus
  161. #undef wrapbuffer_handle
  162. IM_API rga_buffer_t wrapbuffer_handle(rga_buffer_handle_t handle,
  163. int width, int height, int format);
  164. IM_API rga_buffer_t wrapbuffer_handle(rga_buffer_handle_t handle,
  165. int width, int height, int format,
  166. int wstride, int hstride);
  167. #endif
  168. IM_EXPORT_API void imsetAlphaBit(rga_buffer_t *buf, uint8_t alpha0, uint8_t alpha1);
  169. IM_EXPORT_API void imsetOpacity(rga_buffer_t *buf, uint8_t alpha);
  170. IM_EXPORT_API void imsetColorSpace(rga_buffer_t *buf, IM_COLOR_SPACE_MODE mode);
  171. #endif /* #ifndef _im2d_buffer_h_ */