display_composer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief Public API for display composer
  9. */
  10. #ifndef ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_DISPLAY_COMPOSER_H_
  11. #define ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_DISPLAY_COMPOSER_H_
  12. /**
  13. * @brief Display Composer Interface
  14. * @defgroup display_composer_interface Display Composer Interface
  15. * @ingroup display_libraries
  16. * @{
  17. */
  18. #include <stdint.h>
  19. #include <drivers/display.h>
  20. #include <drivers/display/display_graphics.h>
  21. #include <graphic_buffer.h>
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /*
  26. * @brief Display composer flags
  27. *
  28. */
  29. enum display_composer_flags {
  30. /* first post in one frame */
  31. FIRST_POST_IN_FRAME = BIT(0),
  32. /* last post in one frame */
  33. LAST_POST_IN_FRAME = BIT(1),
  34. /* current post is full screen, and can optimize the square corners */
  35. POST_FULL_SCREEN_OPT = BIT(2),
  36. /* post using DE path.
  37. * posting by DE has much higher efficiency than DMA, but may be affected
  38. * by drawing, since DMA2D HAL is accelerated by DE.
  39. */
  40. POST_PATH_BY_DE = BIT(7),
  41. };
  42. /**
  43. * @typedef display_composer_post_cleanup_t
  44. * @brief Callback API executed when post cleanup
  45. *
  46. */
  47. typedef void (*display_composer_post_cleanup_t)(void *user_data);
  48. /**
  49. * @struct ui_layer
  50. * @brief Structure holding ui layer for composition
  51. *
  52. */
  53. typedef struct ui_layer {
  54. /* pointer to graphic buffer */
  55. graphic_buffer_t *buffer;
  56. /*
  57. * plane color applied to the whole layer:
  58. * 1) For buffer == NULL, use color.argb as the default pixel color value
  59. * 1) For buffer with format A1/4/8, use color.rgb as the pixel rgb value
  60. * 2) For buffer with other formats, use color.a as the global alpha value
  61. */
  62. display_color_t color;
  63. /* area of the source to consider, the origin is the top-left corner of the buffer. */
  64. ui_region_t crop;
  65. /* where to composite the crop onto the display, the origin is the top-left corner
  66. * of the screen. So far, the size of frame must equal to the crop's, since scaling
  67. * not supported by hardware.
  68. */
  69. ui_region_t frame;
  70. /* blending to apply during composition */
  71. uint8_t blending;
  72. /* reserved for future */
  73. uint8_t _pad[2];
  74. /* buffer is resident, no need to do ref/unref */
  75. uint8_t buf_resident;
  76. /* user post cleanup cb */
  77. display_composer_post_cleanup_t cleanup_cb;
  78. void *cleanup_data;
  79. } ui_layer_t;
  80. /**
  81. * @brief Initialize the display composer
  82. *
  83. * @return 0 on success else negative errno code.
  84. */
  85. int display_composer_init(void);
  86. /**
  87. * @brief Destroy the display composer
  88. *
  89. * @return N/A.
  90. */
  91. void display_composer_destroy(void);
  92. /**
  93. * @brief Register the display composer callback
  94. *
  95. * The callback will be called when one frame complete.
  96. *
  97. * @param callback callback function
  98. *
  99. * @return N/A.
  100. */
  101. void display_composer_register_callback(const struct display_callback *callback);
  102. /**
  103. * @brief Get vsync period of the display
  104. *
  105. * @return vsync period in us
  106. */
  107. uint32_t display_composer_get_vsync_period(void);
  108. /**
  109. * @brief Get geometry of the display
  110. *
  111. * @param width address to store the x resolution
  112. * @param height address to store the y resolution
  113. * @param pixel_format address to store the pixel format
  114. *
  115. * @return N/A.
  116. */
  117. int display_composer_get_geometry(
  118. uint16_t *width, uint16_t *height, uint32_t *pixel_format);
  119. /**
  120. * @brief Set the blanking of the display
  121. *
  122. * @param blanking_on blanking on or not
  123. *
  124. * @retval 0 on success else negative errno code.
  125. */
  126. int display_composer_set_blanking(bool blanking_on);
  127. /**
  128. * @brief Set the brightness of the display
  129. *
  130. * Set the brightness of the display in steps of 1/256, where 255 is full
  131. * brightness and 0 is minimal.
  132. *
  133. * @param brightness Brightness in steps of 1/256
  134. *
  135. * @retval 0 on success else negative errno code.
  136. */
  137. int display_composer_set_brightness(uint8_t brightness);
  138. /**
  139. * @brief Set the contrast of the display
  140. *
  141. * Set the contrast of the display in steps of 1/256, where 255 is maximum
  142. * difference and 0 is minimal.
  143. *
  144. * @param contrast Contrast in steps of 1/256
  145. *
  146. * @retval 0 on success else negative errno code.
  147. */
  148. int display_composer_set_contrast(uint8_t contrast);
  149. /**
  150. * @brief Extend the invalidated region to match with the display requirements
  151. *
  152. * @param region the invalidated/dirty region of the display
  153. *
  154. * @retval N/A
  155. */
  156. void display_composer_round(ui_region_t *region);
  157. /**
  158. * @brief Post one buffer to display
  159. *
  160. * @param buffer buffer to post
  161. * @param crop crop area of the buffer, if NULL, means the whole buffer
  162. * @param x x Coordinate of the upper left corner where to write the buffer
  163. * @param y y Coordinate of the upper left corner where to write the buffer
  164. *
  165. * @return 0 on success else negative errno code.
  166. */
  167. int display_composer_simple_post(graphic_buffer_t *buffer,
  168. ui_region_t *crop, uint16_t x, uint16_t y);
  169. /**
  170. * @brief Post the layers to display
  171. *
  172. * This routine may be blocked in thread context.
  173. *
  174. * @param layers layer array to post
  175. * @param num_layers number of layers to post
  176. * @param post_flags post flags, see enum display_composer_flags
  177. *
  178. * @return 0 on success else negative errno code.
  179. */
  180. int display_composer_post(const ui_layer_t *layers, int num_layers, uint32_t post_flags);
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. /**
  185. * @}
  186. */
  187. #endif /* ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_DISPLAY_COMPOSER_H_ */