nxbe_cursor_backupdraw.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /****************************************************************************
  2. * graphics/nxbe/nxbe_cursor_backupdraw.c
  3. *
  4. * Copyright (C) 2019 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include <assert.h>
  40. #include "nxglib.h"
  41. #include "nxbe.h"
  42. #ifdef CONFIG_NX_SWCURSOR
  43. /****************************************************************************
  44. * Private Functions
  45. ****************************************************************************/
  46. /****************************************************************************
  47. * Name: _nxbe_cursor_backupdraw_dev
  48. *
  49. * Description:
  50. * Called after any modification to the display to backup and redraw one
  51. * color plane
  52. *
  53. * Input Parameters:
  54. * be - The back-end state structure instance
  55. * rect - The modified region of the display, in device coordinates
  56. * plane - The plane number to use.
  57. *
  58. * Returned Value:
  59. * None
  60. *
  61. ****************************************************************************/
  62. static inline void _nxbe_cursor_backupdraw_dev(FAR struct nxbe_state_s *be,
  63. FAR const struct nxgl_rect_s *rect,
  64. int plane)
  65. {
  66. /* Save the modified cursor background region. */
  67. be->plane[plane].cursor.backup(be, rect, plane);
  68. /* Restore the software cursor in the region that was modified. */
  69. be->plane[plane].cursor.draw(be, rect, plane);
  70. }
  71. /****************************************************************************
  72. * Public Functions
  73. ****************************************************************************/
  74. /****************************************************************************
  75. * Name: nxbe_cursor_backupdraw
  76. *
  77. * Description:
  78. * Called after any modification to the display (in window coordinate
  79. * frame) to perform the backup-draw operation on one color plane.
  80. *
  81. * Input Parameters:
  82. * be - The back-end state structure instance, or
  83. * wnd - Window state structure
  84. * rect - The modified region of the window, in windows coordinates
  85. * plane - The plane number to use.
  86. *
  87. * Returned Value:
  88. * None
  89. *
  90. ****************************************************************************/
  91. void nxbe_cursor_backupdraw_dev(FAR struct nxbe_state_s *be,
  92. FAR const struct nxgl_rect_s *rect,
  93. int plane)
  94. {
  95. struct nxgl_rect_s bounds;
  96. /* Update the software cursor if it is visible */
  97. if (be->cursor.visible)
  98. {
  99. /* Clip to the limits of the display */
  100. nxgl_rectintersect(&bounds, rect, &be->bkgd.bounds);
  101. if (!nxgl_nullrect(&bounds))
  102. {
  103. _nxbe_cursor_backupdraw_dev(be, &bounds, plane);
  104. }
  105. }
  106. }
  107. void nxbe_cursor_backupdraw(FAR struct nxbe_window_s *wnd,
  108. FAR const struct nxgl_rect_s *rect,
  109. int plane)
  110. {
  111. struct nxgl_rect_s bounds;
  112. /* Update the software cursor if it is visible */
  113. if (wnd->be->cursor.visible)
  114. {
  115. /* Offset the rectangle to convert to device coordinates */
  116. nxgl_rectoffset(&bounds, rect, wnd->bounds.pt1.x, wnd->bounds.pt1.y);
  117. /* Clip to the limits of the window */
  118. nxgl_rectintersect(&bounds, &bounds, &wnd->bounds);
  119. /* Let nxbe_cursor_backupdraw_dev() do the rest */
  120. nxbe_cursor_backupdraw_dev(wnd->be, &bounds, plane);
  121. }
  122. }
  123. /****************************************************************************
  124. * Name: nxbe_cursor_backupdraw_all and nxbe_cursor_backupdraw_devall
  125. *
  126. * Description:
  127. * Called after any modification to the display to perform the backup-draw
  128. * operation on all color planes.
  129. *
  130. * Input Parameters:
  131. * be - The back-end state structure instance, or
  132. * wnd - Window state structure
  133. * rect - The modified region of the window. In windows coordinates for
  134. * nxbe_cursor_backupdraw(); in graphics device corrdinates for
  135. * nxbe_cursor_backupdraw_dev().
  136. *
  137. * Returned Value:
  138. * None
  139. *
  140. ****************************************************************************/
  141. void nxbe_cursor_backupdraw_devall(FAR struct nxbe_state_s *be,
  142. FAR const struct nxgl_rect_s *rect)
  143. {
  144. #if CONFIG_NX_NPLANES > 1
  145. struct nxgl_rect_s bounds;
  146. int plane;
  147. /* Update the software cursor if it is visible */
  148. if (be->cursor.visible)
  149. {
  150. /* Clip to the limits of the display */
  151. nxgl_rectintersect(&bounds, &bounds, &be->bkgd.bounds);
  152. if (!nxgl_nullrect(&bounds))
  153. {
  154. /* Perform the backup-draw operation on all color planes */
  155. for (plane = 0; plane < CONFIG_NX_NPLANES; plane++)
  156. {
  157. _nxbe_cursor_backupdraw_dev(be, &bounds, plane);
  158. }
  159. }
  160. }
  161. #else
  162. nxbe_cursor_backupdraw_dev(be, rect, 0);
  163. #endif
  164. }
  165. void nxbe_cursor_backupdraw_all(FAR struct nxbe_window_s *wnd,
  166. FAR const struct nxgl_rect_s *rect)
  167. {
  168. #if CONFIG_NX_NPLANES > 1
  169. struct nxgl_rect_s bounds;
  170. /* Update the software cursor if it is visible */
  171. if (wnd->be->cursor.visible)
  172. {
  173. /* Offset the rectangle to convert it to device coordinates */
  174. nxgl_rectoffset(&bounds, rect, wnd->bounds.pt1.x, wnd->bounds.pt1.y);
  175. /* Clip to the limits of the window */
  176. nxgl_rectintersect(&bounds, &bounds, &wnd->bounds);
  177. /* And then let nxbe_cursor_backupdraw_devall() do the rest */
  178. nxbe_cursor_backupdraw_all(wnd, &bounds);
  179. }
  180. #else
  181. nxbe_cursor_backupdraw(wnd, rect, 0);
  182. #endif
  183. }
  184. #endif /* CONFIG_NX_SWCURSOR */