nxbe_getrectangle.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /****************************************************************************
  2. * graphics/nxbe/nxbe_getrectangle.c
  3. *
  4. * Copyright (C) 2011, 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 <errno.h>
  41. #include <debug.h>
  42. #include <nuttx/nx/nxglib.h>
  43. #include "nxbe.h"
  44. /****************************************************************************
  45. * Private Types
  46. ****************************************************************************/
  47. struct nxbe_fill_s
  48. {
  49. struct nxbe_clipops_s cops;
  50. nxgl_mxpixel_t color;
  51. };
  52. /****************************************************************************
  53. * Private Functions
  54. ****************************************************************************/
  55. /****************************************************************************
  56. * Name: nxbe_getrectangle_dev
  57. *
  58. * Description:
  59. * Get the raw contents of graphic memory within a rectangular region. NOTE:
  60. * Since raw graphic memory is returned, the returned memory content may be
  61. * the memory of windows above this one and may not necessarily belong to
  62. * this window unless you assure that this is the top window.
  63. *
  64. * Input Parameters:
  65. * wnd - The window structure reference
  66. * rect - The location to be copied
  67. * plane - Specifies the color plane to get from.
  68. * dest - The location to copy the memory region
  69. * deststride - The width, in bytes, of the dest memory
  70. *
  71. * Returned Value:
  72. * None
  73. *
  74. ****************************************************************************/
  75. static inline void nxbe_getrectangle_dev(FAR struct nxbe_window_s *wnd,
  76. FAR const struct nxgl_rect_s *rect,
  77. unsigned int plane,
  78. FAR uint8_t *dest,
  79. unsigned int deststride)
  80. {
  81. FAR struct nxbe_plane_s *pplane = &wnd->be->plane[plane];
  82. DEBUGASSERT(pplane != NULL && pplane->dev.getrectangle != NULL);
  83. pplane->dev.getrectangle(&pplane->pinfo, rect, dest, deststride);
  84. }
  85. /****************************************************************************
  86. * Name: nxbe_getrectangle_pwfb
  87. *
  88. * Description:
  89. * Get the contents of pre-window framebuffer graphic memory within a
  90. * rectangular region.
  91. *
  92. * Input Parameters:
  93. * wnd - The window structure reference
  94. * rect - The location to be copied (in device coordinates, clipped)
  95. * plane - Specifies the color plane to get from.
  96. * dest - The location to copy the memory region
  97. * deststride - The width, in bytes, of the dest memory
  98. *
  99. * Returned Value:
  100. * None
  101. *
  102. ****************************************************************************/
  103. #ifdef CONFIG_NX_RAMBACKED
  104. static inline void nxbe_getrectangle_pwfb(FAR struct nxbe_window_s *wnd,
  105. FAR const struct nxgl_rect_s *rect,
  106. unsigned int plane,
  107. FAR uint8_t *dest,
  108. unsigned int deststride)
  109. {
  110. FAR struct nxbe_plane_s *pplane = &wnd->be->plane[plane];
  111. struct nxgl_rect_s relrect;
  112. DEBUGASSERT(pplane != NULL && pplane->pwfb.getrectangle != NULL);
  113. /* The rectangle that we receive here is in abolute device coordinates.
  114. * We need to restore this to windows relative coordinates.
  115. */
  116. nxgl_rectoffset(&relrect, rect, -wnd->bounds.pt1.x, -wnd->bounds.pt1.y);
  117. /* Then get the rectangle from the framebuffer */
  118. pplane->pwfb.getrectangle(wnd, &relrect, dest, deststride);
  119. }
  120. #endif
  121. /****************************************************************************
  122. * Public Functions
  123. ****************************************************************************/
  124. /****************************************************************************
  125. * Name: nxbe_getrectangle
  126. *
  127. * Description:
  128. * Get the raw contents of graphic memory within a rectangular region. NOTE:
  129. * Since raw graphic memory is returned, the returned memory content may be
  130. * the memory of windows above this one and may not necessarily belong to
  131. * this window unless you assure that this is the top window.
  132. *
  133. * Input Parameters:
  134. * wnd - The window structure reference
  135. * rect - The location to be copied (in window-relative coordinates)
  136. * plane - Specifies the color plane to get from.
  137. * dest - The location to copy the memory region
  138. * deststride - The width, in bytes, of the dest memory
  139. *
  140. * Returned Value:
  141. * None
  142. *
  143. ****************************************************************************/
  144. void nxbe_getrectangle(FAR struct nxbe_window_s *wnd,
  145. FAR const struct nxgl_rect_s *rect, unsigned int plane,
  146. FAR uint8_t *dest, unsigned int deststride)
  147. {
  148. struct nxgl_rect_s remaining;
  149. DEBUGASSERT(wnd != NULL && rect != NULL && dest != NULL);
  150. DEBUGASSERT(wnd->be != NULL && wnd->be->plane != NULL);
  151. DEBUGASSERT(plane < wnd->be->vinfo.nplanes);
  152. /* Offset the rectangle by the window origin to convert it into a
  153. * bounding box in device coordinates
  154. */
  155. nxgl_rectoffset(&remaining, rect, wnd->bounds.pt1.x, wnd->bounds.pt1.y);
  156. /* Clip to the bounding box to the limits of the window and of the
  157. * background screen
  158. */
  159. nxgl_rectintersect(&remaining, &remaining, &wnd->bounds);
  160. nxgl_rectintersect(&remaining, &remaining, &wnd->be->bkgd.bounds);
  161. /* The return the graphics memory at this location. */
  162. if (!nxgl_nullrect(&remaining))
  163. {
  164. #ifdef CONFIG_NX_RAMBACKED
  165. /* If this window supports a pre-window frame buffer then get the
  166. * rectangle from pre-window framebuffer.
  167. */
  168. if (NXBE_ISRAMBACKED(wnd))
  169. {
  170. nxbe_getrectangle_pwfb(wnd, &remaining, plane, dest, deststride);
  171. }
  172. else
  173. #endif
  174. /* If the window is hidden, then there is no available data source */
  175. if (!NXBE_ISHIDDEN(wnd))
  176. {
  177. #ifdef CONFIG_NX_SWCURSOR
  178. /* Is the software cursor visible? */
  179. if (wnd->be->cursor.visible)
  180. {
  181. /* Erase any portion of the cursor that may be above this
  182. * region.
  183. * REVISIT: Only a single color plane is supported
  184. */
  185. wnd->be->plane[0].cursor.erase(wnd->be, &remaining, 0);
  186. }
  187. #endif
  188. /* Get the rectangle from the graphics device memory.
  189. * NOTE: Since raw graphic memory is returned, the returned memory
  190. * content may be the memory of windows above this one and may
  191. * not necessarily belong to this window.
  192. */
  193. nxbe_getrectangle_dev(wnd, &remaining, plane, dest, deststride);
  194. #ifdef CONFIG_NX_SWCURSOR
  195. /* Was the software cursor visible? */
  196. if (wnd->be->cursor.visible)
  197. {
  198. /* Restore the software cursor if any part of the cursor was
  199. * erased above.
  200. */
  201. wnd->be->plane[0].cursor.draw(wnd->be, &remaining, 0);
  202. }
  203. #endif
  204. }
  205. }
  206. }