GUIDEMO_Speed.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH & Co. KG *
  3. * Solutions for real time microcontroller applications *
  4. **********************************************************************
  5. * *
  6. * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
  7. * *
  8. * Internet: www.segger.com Support: support@segger.com *
  9. * *
  10. **********************************************************************
  11. ** emWin V5.32 - Graphical user interface for embedded applications **
  12. All Intellectual Property rights in the Software belongs to SEGGER.
  13. emWin is protected by international copyright laws. Knowledge of the
  14. source code may not be used to write a similar product. This file may
  15. only be used in accordance with the following terms:
  16. The software has been licensed to STMicroelectronics International
  17. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  18. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  19. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  20. troller products commercialized by Licensee only, sublicensed and dis_
  21. tributed under the terms and conditions of the End User License Agree_
  22. ment supplied by STMicroelectronics International N.V.
  23. Full source code is available at: www.segger.com
  24. We appreciate your understanding and fairness.
  25. ----------------------------------------------------------------------
  26. Licensing information
  27. Licensor: SEGGER Software GmbH
  28. Licensed to: STMicroelectronics International NV
  29. Licensed SEGGER software: emWin
  30. License number: GUI-00429
  31. License model: Buyout SRC [Buyout Source Code License, signed November 29th 2012]
  32. Licensed product: -
  33. Licensed platform: STMs ARM Cortex-M based 32 BIT CPUs
  34. Licensed number of seats: -
  35. ----------------------------------------------------------------------
  36. File : GUIDEMO_Speed.c
  37. Purpose : Speed demo
  38. ----------------------------------------------------------------------
  39. */
  40. #include "GUIDEMO.h"
  41. #if (SHOW_GUIDEMO_SPEED)
  42. #include <stdlib.h> // rand()
  43. /*********************************************************************
  44. *
  45. * Static data
  46. *
  47. **********************************************************************
  48. */
  49. static const GUI_COLOR _aColor[8] = {
  50. 0x000000,
  51. 0x0000FF,
  52. 0x00FF00,
  53. 0x00FFFF,
  54. 0xFF0000,
  55. 0xFF00FF,
  56. 0xFFFF00,
  57. 0xFFFFFF
  58. };
  59. /*********************************************************************
  60. *
  61. * Static code
  62. *
  63. **********************************************************************
  64. */
  65. /*********************************************************************
  66. *
  67. * _GetPixelsPerSecond
  68. */
  69. static U32 _GetPixelsPerSecond(void) {
  70. GUI_COLOR BkColor;
  71. GUI_COLOR Color;
  72. I32 PixelsPerSecond;
  73. I32 PixelCnt;
  74. I32 t0;
  75. I32 t;
  76. U32 xSize;
  77. U32 ySize;
  78. U32 Cnt;
  79. U32 x0;
  80. U32 x1;
  81. U32 y0;
  82. U32 y1;
  83. //
  84. // Find an area which is not obstructed by any windows
  85. //
  86. xSize = LCD_GetXSize();
  87. ySize = LCD_GetYSize();
  88. Cnt = 0;
  89. x0 = 0;
  90. x1 = xSize - 1;
  91. y0 = 65;
  92. y1 = ySize - 60 - 1;
  93. Color = GUI_GetColor();
  94. BkColor = GUI_GetBkColor();
  95. GUI_SetColor(BkColor);
  96. //
  97. // Repeat fill as often as possible in 100 ms
  98. //
  99. t0 = GUIDEMO_GetTime();
  100. do {
  101. GUI_FillRect(x0, y0, x1, y1);
  102. Cnt++;
  103. t = GUIDEMO_GetTime();
  104. } while ((t - (t0 + 100)) <= 0);
  105. //
  106. // Compute result
  107. //
  108. t -= t0;
  109. PixelCnt = (x1 - x0 + 1) * (y1 - y0 + 1) * Cnt;
  110. PixelsPerSecond = PixelCnt / t * 1000;
  111. GUI_SetColor(Color);
  112. return PixelsPerSecond;
  113. }
  114. /*********************************************************************
  115. *
  116. * Public code
  117. *
  118. **********************************************************************
  119. */
  120. /*********************************************************************
  121. *
  122. * GUIDEMO_Speed
  123. */
  124. void GUIDEMO_Speed(void) {
  125. #if GUI_SUPPORT_TOUCH
  126. GUI_PID_STATE State;
  127. #endif
  128. GUI_RECT ClipRect;
  129. GUI_RECT Rect;
  130. char acText[40] = { 0 };
  131. U32 PixelsPerSecond;
  132. int aColorIndex[8];
  133. int TimeStart;
  134. int vySize;
  135. int xSize;
  136. int ySize;
  137. int i;
  138. GUIDEMO_ConfigureDemo("High speed", "Multi layer clipping\nHighly optimized drivers", 0);
  139. xSize = LCD_GetXSize();
  140. ySize = LCD_GetYSize();
  141. vySize = LCD_GetVYSize();
  142. if (vySize > ySize) {
  143. ClipRect.x0 = 0;
  144. ClipRect.y0 = 0;
  145. ClipRect.x1 = xSize;
  146. ClipRect.y1 = ySize;
  147. GUI_SetClipRect(&ClipRect);
  148. }
  149. for (i = 0; i< 8; i++) {
  150. aColorIndex[i] = GUI_Color2Index(_aColor[i]);
  151. }
  152. TimeStart = GUIDEMO_GetTime();
  153. for (i = 0; ((GUIDEMO_GetTime() - TimeStart) < 5000) && (GUIDEMO_CheckCancel() == 0); i++) {
  154. GUI_SetColorIndex(aColorIndex[i&7]);
  155. //
  156. // Calculate random positions
  157. //
  158. Rect.x0 = rand() % xSize - xSize / 2;
  159. Rect.y0 = rand() % ySize - ySize / 2;
  160. Rect.x1 = Rect.x0 + 20 + rand() % xSize;
  161. Rect.y1 = Rect.y0 + 20 + rand() % ySize;
  162. GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
  163. //
  164. // Clip rectangle to visible area and add the number of pixels (for speed computation)
  165. //
  166. if (Rect.x1 >= xSize) {
  167. Rect.x1 = xSize - 1;
  168. }
  169. if (Rect.y1 >= ySize) {
  170. Rect.y1 = ySize - 1;
  171. }
  172. if (Rect.x0 < 0 ) {
  173. Rect.x0 = 0;
  174. }
  175. if (Rect.y1 < 0) {
  176. Rect.y1 = 0;
  177. }
  178. //
  179. // There is no control window. A simple click on any position has to skip the demo.
  180. //
  181. #if GUI_SUPPORT_TOUCH
  182. GUI_PID_GetState(&State);
  183. if (State.Pressed) {
  184. break;
  185. }
  186. #endif
  187. }
  188. GUIDEMO_NotifyStartNext();
  189. PixelsPerSecond = _GetPixelsPerSecond();
  190. GUI_SetClipRect(NULL);
  191. GUIDEMO_AddStringToString(acText, "Pixels/sec: ");
  192. GUIDEMO_AddIntToString(acText, PixelsPerSecond);
  193. GUIDEMO_DrawBk();
  194. GUI_SetColor(GUI_WHITE);
  195. GUI_SetTextMode(GUI_TM_TRANS);
  196. GUI_SetFont(&GUI_FontRounded22);
  197. GUI_DispStringHCenterAt(acText, xSize / 2, (ySize - GUI_GetFontSizeY()) / 2);
  198. GUIDEMO_ConfigureDemo(NULL, NULL, GUIDEMO_SHOW_CURSOR | GUIDEMO_SHOW_CONTROL);
  199. GUIDEMO_Delay(4000);
  200. }
  201. #else
  202. void GUIDEMO_Speed_C(void);
  203. void GUIDEMO_Speed_C(void) {}
  204. #endif // SHOW_GUIDEMO_SPEED
  205. /*************************** End of file ****************************/