nxmu_redraw.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /****************************************************************************
  2. * graphics/nxmu/nxmu_redraw.c
  3. *
  4. * Copyright (C) 2008-2009, 2011-2012, 2019 Gregory Nutt. All rights
  5. * reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * Included Files
  38. ****************************************************************************/
  39. #include <nuttx/config.h>
  40. #include <stdbool.h>
  41. #include <errno.h>
  42. #include <debug.h>
  43. #include <nuttx/nx/nx.h>
  44. #include "nxmu.h"
  45. /****************************************************************************
  46. * Private Functions
  47. ****************************************************************************/
  48. /****************************************************************************
  49. * Name: nxmu_redraw_pwfb
  50. *
  51. * Description:
  52. * Redraw into the per-window framebuffer
  53. *
  54. ****************************************************************************/
  55. #ifdef CONFIG_NX_RAMBACKED
  56. static inline void nxmu_redraw_pwfb(FAR struct nxbe_window_s *wnd,
  57. FAR const struct nxgl_rect_s *rect)
  58. {
  59. FAR const void *src[CONFIG_NX_NPLANES];
  60. struct nxgl_rect_s wndrect;
  61. struct nxgl_point_s origin;
  62. unsigned int bpp;
  63. /* Put the rectangle back relative to the window */
  64. nxgl_rectoffset(&wndrect, rect,
  65. -wnd->bounds.pt1.x, -wnd->bounds.pt1.y);
  66. /* Get the source of address of the rectangle in the framebuffer. */
  67. bpp = wnd->be->plane[0].pinfo.bpp;
  68. src[0] = (FAR const void *)((FAR uint8_t *)wnd->fbmem +
  69. wndrect.pt1.y * wnd->stride +
  70. ((bpp * wndrect.pt1.x) >> 3));
  71. /* For resolutions less than 8-bits, the starting pixel will be contained
  72. * in the byte pointed to by src[0]but may not be properly aligned for the
  73. * transfer. We fix this by modifying the origin.
  74. */
  75. origin.x = wndrect.pt1.x;
  76. origin.y = wndrect.pt1.y;
  77. switch (bpp)
  78. {
  79. #ifndef CONFIG_NX_DISABLE_1BPP
  80. case 1: /* 1 bit per pixel */
  81. {
  82. origin.x &= ~7;
  83. }
  84. break;
  85. #endif
  86. #ifndef CONFIG_NX_DISABLE_2BPP
  87. case 2: /* 2 bits per pixel */
  88. {
  89. origin.x &= ~3;
  90. }
  91. break;
  92. #endif
  93. #ifndef CONFIG_NX_DISABLE_4BPP
  94. case 4: /* 4 bits per pixel */
  95. {
  96. origin.x &= ~1;
  97. }
  98. break;
  99. #endif
  100. default:
  101. break;
  102. }
  103. /* And render the bitmap into device graphics memory */
  104. nxbe_flush(wnd, &wndrect, src, &origin, wnd->stride);
  105. }
  106. #endif
  107. /****************************************************************************
  108. * Public Functions
  109. ****************************************************************************/
  110. /****************************************************************************
  111. * Name: nxmu_redrawreq
  112. *
  113. * Description:
  114. * Send a message to the client requesting that it to redraw the rectangular
  115. * region in the window.
  116. *
  117. ****************************************************************************/
  118. void nxmu_redrawreq(FAR struct nxbe_window_s *wnd,
  119. FAR const struct nxgl_rect_s *rect)
  120. {
  121. struct nxclimsg_redraw_s outmsg;
  122. /* Send the client redraw message */
  123. outmsg.msgid = NX_CLIMSG_REDRAW;
  124. outmsg.wnd = wnd;
  125. outmsg.more = false;
  126. nxgl_rectoffset(&outmsg.rect, rect,
  127. -wnd->bounds.pt1.x, -wnd->bounds.pt1.y);
  128. nxmu_sendclientwindow(wnd, &outmsg,
  129. sizeof(struct nxclimsg_redraw_s));
  130. }
  131. /****************************************************************************
  132. * Name: nxmu_redraw
  133. *
  134. * Description:
  135. * Redraw client window data. This may involve either sending a message
  136. * to the client requesting that it redraw a region of the window. Or, in
  137. * the base that the window supports a per-window framebuffer, this might
  138. * amount to an immediate redraw from the framebuffer.
  139. *
  140. ****************************************************************************/
  141. void nxmu_redraw(FAR struct nxbe_window_s *wnd,
  142. FAR const struct nxgl_rect_s *rect)
  143. {
  144. /* Don't update hidden windows */
  145. if (!NXBE_ISHIDDEN(wnd))
  146. {
  147. #ifdef CONFIG_NX_RAMBACKED
  148. /* If this window supports a pre-window frame buffer, then we can just
  149. * update the device content from that framebuffer.
  150. */
  151. if (NXBE_ISRAMBACKED(wnd))
  152. {
  153. nxmu_redraw_pwfb(wnd, rect);
  154. }
  155. /* Otherwise, send a message to the client requesting an update of the
  156. * affected region in the window.
  157. */
  158. else
  159. #endif
  160. {
  161. nxmu_redrawreq(wnd, rect);
  162. }
  163. }
  164. }