nxtk_register.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /****************************************************************************
  2. * nuttx/graphics/nxterm/nxtk_register.c
  3. *
  4. * Copyright (C) 2012 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 <nuttx/nx/nxtk.h>
  40. #include <nuttx/nx/nxterm.h>
  41. #include "nxterm.h"
  42. /****************************************************************************
  43. * Private Function Prototypes
  44. ****************************************************************************/
  45. static int nxtkcon_fill(FAR struct nxterm_state_s *priv,
  46. FAR const struct nxgl_rect_s *rect,
  47. nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES]);
  48. #ifndef CONFIG_NX_WRITEONLY
  49. static int nxtkcon_move(FAR struct nxterm_state_s *priv,
  50. FAR const struct nxgl_rect_s *rect,
  51. FAR const struct nxgl_point_s *offset);
  52. #endif
  53. static int nxtkcon_bitmap(FAR struct nxterm_state_s *priv,
  54. FAR const struct nxgl_rect_s *dest,
  55. FAR const void *src[CONFIG_NX_NPLANES],
  56. FAR const struct nxgl_point_s *origin,
  57. unsigned int stride);
  58. /****************************************************************************
  59. * Private Data
  60. ****************************************************************************/
  61. static const struct nxterm_operations_s g_nxtkops =
  62. {
  63. nxtkcon_fill,
  64. #ifndef CONFIG_NX_WRITEONLY
  65. nxtkcon_move,
  66. #endif
  67. nxtkcon_bitmap
  68. };
  69. /****************************************************************************
  70. * Private Functions
  71. ****************************************************************************/
  72. /****************************************************************************
  73. * Name: nxtkcon_fill
  74. *
  75. * Description:
  76. * Fill the specified rectangle in the window with the specified color
  77. *
  78. * Input Parameters:
  79. * priv - The driver state structure.
  80. * rect - The location to be filled
  81. * color - The color to use in the fill
  82. *
  83. * Returned Value:
  84. * OK on success; ERROR on failure with errno set appropriately
  85. *
  86. ****************************************************************************/
  87. static int nxtkcon_fill(FAR struct nxterm_state_s *priv,
  88. FAR const struct nxgl_rect_s *rect,
  89. nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES])
  90. {
  91. return nxtk_fillwindow((NXTKWINDOW)priv->handle, rect, wcolor);
  92. }
  93. /****************************************************************************
  94. * Name: nxtkcon_move
  95. *
  96. * Description:
  97. * Move a rectangular region within the window
  98. *
  99. * Input Parameters:
  100. * priv - The driver state structure.
  101. * rect - Describes the rectangular region to move
  102. * offset - The offset to move the region. The rectangular region will be
  103. * moved so that the origin is translated by this amount.
  104. *
  105. * Returned Value:
  106. * OK on success; ERROR on failure with errno set appropriately
  107. *
  108. ****************************************************************************/
  109. #ifndef CONFIG_NX_WRITEONLY
  110. static int nxtkcon_move(FAR struct nxterm_state_s *priv,
  111. FAR const struct nxgl_rect_s *rect,
  112. FAR const struct nxgl_point_s *offset)
  113. {
  114. return nxtk_movewindow((NXTKWINDOW)priv->handle, rect, offset);
  115. }
  116. #endif
  117. /****************************************************************************
  118. * Name: nxtkcon_bitmap
  119. *
  120. * Description:
  121. * Copy a rectangular region of a larger image into the rectangle in the
  122. * specified window.
  123. *
  124. * Input Parameters:
  125. * priv - The driver state structure.
  126. * dest - Describes the rectangular region on the display that will
  127. * receive the bit map.
  128. * src - The start of the source image. This is an array source
  129. * images of size CONFIG_NX_NPLANES.
  130. * origin - The origin of the upper, left-most corner of the full bitmap.
  131. * Both dest and origin are in window coordinates, however, origin
  132. * may lie outside of the display.
  133. * stride - The width of the full source image in bytes.
  134. *
  135. * Returned Value:
  136. * OK on success; ERROR on failure with errno set appropriately
  137. *
  138. ****************************************************************************/
  139. static int nxtkcon_bitmap(FAR struct nxterm_state_s *priv,
  140. FAR const struct nxgl_rect_s *dest,
  141. FAR const void *src[CONFIG_NX_NPLANES],
  142. FAR const struct nxgl_point_s *origin,
  143. unsigned int stride)
  144. {
  145. return nxtk_bitmapwindow((NXTKWINDOW)priv->handle, dest, src, origin, stride);
  146. }
  147. /****************************************************************************
  148. * Public Functions
  149. ****************************************************************************/
  150. /****************************************************************************
  151. * Name: nxtk_register
  152. *
  153. * Description:
  154. * Register a console device on a framed NX window. The device will be
  155. * registered at /dev/nxtkN where N is the provided minor number.
  156. *
  157. * Input Parameters:
  158. * hfwnd - A handle that will be used to access the window. The window must
  159. * persist and this handle must be valid for the life of the NX console.
  160. * wndo - Describes the window and font to be used
  161. * minor - The device minor number
  162. *
  163. * Returned Value:
  164. * A non-NULL handle is returned on success.
  165. *
  166. ****************************************************************************/
  167. NXTERM nxtk_register(NXTKWINDOW hfwnd, FAR struct nxterm_window_s *wndo,
  168. int minor)
  169. {
  170. return nxterm_register((NXTERM)hfwnd, wndo, &g_nxtkops, minor);
  171. }