display_composer.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /*********************
  19. * INCLUDES
  20. *********************/
  21. #include <stdint.h>
  22. #include <drivers/display.h>
  23. #include <drivers/display/display_graphics.h>
  24. #include <display/graphic_buffer.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /*********************
  29. * DEFINES
  30. *********************/
  31. #ifdef CONFIG_DISPLAY_ENGINE_LARK
  32. # define NUM_POST_LAYERS (2)
  33. #else
  34. # define NUM_POST_LAYERS (3)
  35. #endif
  36. /**********************
  37. * TYPEDEFS
  38. **********************/
  39. /*
  40. * @brief Display composer flags
  41. *
  42. */
  43. enum display_composer_flags {
  44. /* first post in one frame */
  45. FIRST_POST_IN_FRAME = BIT(0),
  46. /* last post in one frame */
  47. LAST_POST_IN_FRAME = BIT(1),
  48. /* post using DE path.
  49. * posting by DE has much higher efficiency than DMA, but may be affected
  50. * by drawing, since DMA2D HAL is accelerated by DE.
  51. */
  52. POST_PATH_BY_DE = BIT(7),
  53. POST_FULL_FRAME = FIRST_POST_IN_FRAME | LAST_POST_IN_FRAME,
  54. };
  55. /**
  56. * @typedef display_composer_post_cleanup_t
  57. * @brief Callback API executed when post cleanup
  58. *
  59. */
  60. typedef void (*display_composer_post_cleanup_t)(void *user_data);
  61. /**
  62. * @struct ui_layer
  63. * @brief Structure holding ui layer for composition
  64. *
  65. */
  66. typedef struct ui_layer {
  67. /* pointer to graphic buffer */
  68. graphic_buffer_t *buffer;
  69. /* area of the source to consider, the origin is the top-left corner of the buffer. */
  70. ui_region_t crop;
  71. /* where to composite the crop onto the display, the origin is the top-left corner
  72. * of the screen. So far, the size of frame must equal to the crop's, since scaling
  73. * not supported by hardware.
  74. */
  75. ui_region_t frame;
  76. /* blending to apply during composition */
  77. uint8_t blending;
  78. /* panel alpha */
  79. uint8_t plane_alpha;
  80. /* user post cleanup cb */
  81. display_composer_post_cleanup_t cleanup_cb;
  82. void *cleanup_data;
  83. } ui_layer_t;
  84. /**********************
  85. * GLOBAL PROTOTYPES
  86. **********************/
  87. /**
  88. * @brief Initialize the display composer
  89. *
  90. * @return 0 on success else negative errno code.
  91. */
  92. int display_composer_init(void);
  93. /**
  94. * @brief Destroy the display composer
  95. *
  96. * @return N/A.
  97. */
  98. void display_composer_destroy(void);
  99. /**
  100. * @brief Register the display composer callback
  101. *
  102. * The callback will be called when one frame complete.
  103. *
  104. * @param callback callback function
  105. *
  106. * @return N/A.
  107. */
  108. void display_composer_register_callback(const struct display_callback *callback);
  109. /**
  110. * @brief Set post period
  111. *
  112. * @multiple how many vsync periods to post one frame
  113. *
  114. * @return N/A
  115. */
  116. void display_composer_set_post_period(uint8_t multiple);
  117. /**
  118. * @brief Get actual display refresh rate
  119. *
  120. * @return refresh rate in Hz
  121. */
  122. uint8_t display_composer_get_refresh_rate(void);
  123. /**
  124. * @brief Get geometry of the display
  125. *
  126. * @param width address to store the x resolution
  127. * @param height address to store the y resolution
  128. * @param pixel_format address to store the pixel format
  129. * @param round_screen address to store screen shape
  130. *
  131. * @return 0 on success else negative code.
  132. */
  133. int display_composer_get_geometry(uint16_t *width, uint16_t *height,
  134. uint32_t *pixel_format, uint8_t *round_screen);
  135. /**
  136. * @brief Get display orientation
  137. *
  138. * @return rotation (CW) in degrees
  139. */
  140. uint16_t display_composer_get_orientation(void);
  141. /**
  142. * @brief Get number of layers supported
  143. *
  144. * @return number of layers supported.
  145. */
  146. uint8_t display_composer_get_num_layers(void);
  147. /**
  148. * @brief Set the brightness of the display
  149. *
  150. * Set the brightness of the display in steps of 1/256, where 255 is full
  151. * brightness and 0 is minimal.
  152. *
  153. * @param brightness Brightness in steps of 1/256
  154. *
  155. * @retval 0 on success else negative errno code.
  156. */
  157. int display_composer_set_brightness(uint8_t brightness);
  158. /**
  159. * @brief Extend the invalidated region to match with the display requirements
  160. *
  161. * @param region the invalidated/dirty region of the display
  162. *
  163. * @retval N/A
  164. */
  165. void display_composer_round(ui_region_t *region);
  166. /**
  167. * @brief Post the layers to display
  168. *
  169. * This routine may be blocked in thread context.
  170. *
  171. * @param layers layer array to post
  172. * @param num_layers number of layers to post
  173. * @param post_flags post flags, see enum display_composer_flags
  174. *
  175. * @return 0 on success else negative errno code.
  176. */
  177. int display_composer_post(const ui_layer_t *layers, int num_layers, uint32_t post_flags);
  178. /**
  179. * @brief Flush to display
  180. *
  181. * This routine can be used in AOD mode without vsync/TE enabled.
  182. *
  183. * @param timeout timeout in milliseconds
  184. *
  185. * @retval number of frames flushed on success else negative errno code.
  186. */
  187. int display_composer_flush(unsigned int timeout);
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. /**
  192. * @}
  193. */
  194. #endif /* ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_DISPLAY_COMPOSER_H_ */