nx_register.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /****************************************************************************
  2. * graphics/nxterm/nx_register.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <nuttx/nx/nx.h>
  25. #include <nuttx/nx/nxterm.h>
  26. #include "nxterm.h"
  27. /****************************************************************************
  28. * Private Function Prototypes
  29. ****************************************************************************/
  30. static int nxterm_fill(FAR struct nxterm_state_s *priv,
  31. FAR const struct nxgl_rect_s *rect,
  32. nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES]);
  33. #ifndef CONFIG_NX_WRITEONLY
  34. static int nxterm_move(FAR struct nxterm_state_s *priv,
  35. FAR const struct nxgl_rect_s *rect,
  36. FAR const struct nxgl_point_s *offset);
  37. #endif
  38. static int nxterm_bitmap(FAR struct nxterm_state_s *priv,
  39. FAR const struct nxgl_rect_s *dest,
  40. FAR const void *src[CONFIG_NX_NPLANES],
  41. FAR const struct nxgl_point_s *origin,
  42. unsigned int stride);
  43. /****************************************************************************
  44. * Private Data
  45. ****************************************************************************/
  46. static const struct nxterm_operations_s g_nxops =
  47. {
  48. nxterm_fill,
  49. #ifndef CONFIG_NX_WRITEONLY
  50. nxterm_move,
  51. #endif
  52. nxterm_bitmap
  53. };
  54. /****************************************************************************
  55. * Private Functions
  56. ****************************************************************************/
  57. /****************************************************************************
  58. * Name: nxterm_fill
  59. *
  60. * Description:
  61. * Fill the specified rectangle in the window with the specified color
  62. *
  63. * Input Parameters:
  64. * priv - The driver state structure.
  65. * rect - The location to be filled
  66. * color - The color to use in the fill
  67. *
  68. * Returned Value:
  69. * OK on success; ERROR on failure with errno set appropriately
  70. *
  71. ****************************************************************************/
  72. static int nxterm_fill(FAR struct nxterm_state_s *priv,
  73. FAR const struct nxgl_rect_s *rect,
  74. nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES])
  75. {
  76. return nx_fill((NXWINDOW)priv->handle, rect, wcolor);
  77. }
  78. /****************************************************************************
  79. * Name: nxterm_move
  80. *
  81. * Description:
  82. * Move a rectangular region within the window
  83. *
  84. * Input Parameters:
  85. * priv - The driver state structure.
  86. * rect - Describes the rectangular region to move
  87. * offset - The offset to move the region. The rectangular region will be
  88. * moved so that the origin is translated by this amount.
  89. *
  90. * Returned Value:
  91. * OK on success; ERROR on failure with errno set appropriately
  92. *
  93. ****************************************************************************/
  94. #ifndef CONFIG_NX_WRITEONLY
  95. static int nxterm_move(FAR struct nxterm_state_s *priv,
  96. FAR const struct nxgl_rect_s *rect,
  97. FAR const struct nxgl_point_s *offset)
  98. {
  99. return nx_move((NXWINDOW)priv->handle, rect, offset);
  100. }
  101. #endif
  102. /****************************************************************************
  103. * Name: nxterm_bitmap
  104. *
  105. * Description:
  106. * Copy a rectangular region of a larger image into the rectangle in the
  107. * specified window.
  108. *
  109. * Input Parameters:
  110. * priv - The driver state structure.
  111. * dest - Describes the rectangular region on the display that will
  112. * receive the bit map.
  113. * src - The start of the source image. This is an array source
  114. * images of size CONFIG_NX_NPLANES.
  115. * origin - The origin of the upper, left-most corner of the full bitmap.
  116. * Both dest and origin are in window coordinates, however, origin
  117. * may lie outside of the display.
  118. * stride - The width of the full source image in bytes.
  119. *
  120. * Returned Value:
  121. * OK on success; ERROR on failure with errno set appropriately
  122. *
  123. ****************************************************************************/
  124. static int nxterm_bitmap(FAR struct nxterm_state_s *priv,
  125. FAR const struct nxgl_rect_s *dest,
  126. FAR const void *src[CONFIG_NX_NPLANES],
  127. FAR const struct nxgl_point_s *origin,
  128. unsigned int stride)
  129. {
  130. return nx_bitmap((NXWINDOW)priv->handle, dest, src, origin, stride);
  131. }
  132. /****************************************************************************
  133. * Public Functions
  134. ****************************************************************************/
  135. /****************************************************************************
  136. * Name: nx_register
  137. *
  138. * Description:
  139. * Register a console device on a raw NX window. The device will be
  140. * registered at /dev/nxtermN where N is the provided minor number.
  141. *
  142. * Input Parameters:
  143. * hwnd - A handle that will be used to access the window. The window must
  144. * persist and this handle must be valid for the life of the NX console.
  145. * wndo - Describes the window and font to be used
  146. * minor - The device minor number
  147. *
  148. * Returned Value:
  149. * A non-NULL handle is returned on success.
  150. *
  151. ****************************************************************************/
  152. NXTERM nx_register(NXWINDOW hwnd,
  153. FAR struct nxterm_window_s *wndo,
  154. int minor)
  155. {
  156. return nxterm_register((NXTERM)hwnd, wndo, &g_nxops, minor);
  157. }