GUIDEMO_Speed.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*********************************************************************
  2. * Portions COPYRIGHT 2016 STMicroelectronics *
  3. * Portions SEGGER Microcontroller GmbH & Co. KG *
  4. * Solutions for real time microcontroller applications *
  5. **********************************************************************
  6. * *
  7. * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
  8. * *
  9. * Internet: www.segger.com Support: support@segger.com *
  10. * *
  11. **********************************************************************
  12. ** emWin V5.28 - Graphical user interface for embedded applications **
  13. All Intellectual Property rights in the Software belongs to SEGGER.
  14. emWin is protected by international copyright laws. Knowledge of the
  15. source code may not be used to write a similar product. This file may
  16. only be used in accordance with the following terms:
  17. The software has been licensed to STMicroelectronics International
  18. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  19. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  20. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  21. troller products commercialized by Licensee only, sublicensed and dis_
  22. tributed under the terms and conditions of the End User License Agree_
  23. ment supplied by STMicroelectronics International N.V.
  24. Full source code is available at: www.segger.com
  25. We appreciate your understanding and fairness.
  26. ----------------------------------------------------------------------
  27. File : GUIDEMO_Speed.c
  28. Purpose : Speed demo
  29. ----------------------------------------------------------------------
  30. */
  31. /**
  32. ******************************************************************************
  33. * @file GUIDEMO_Speed.c
  34. * @author MCD Application Team
  35. * @brief Speed demo
  36. ******************************************************************************
  37. * @attention
  38. *
  39. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
  40. * All rights reserved.</center></h2>
  41. *
  42. * Redistribution and use in source and binary forms, with or without
  43. * modification, are permitted, provided that the following conditions are met:
  44. *
  45. * 1. Redistribution of source code must retain the above copyright notice,
  46. * this list of conditions and the following disclaimer.
  47. * 2. Redistributions in binary form must reproduce the above copyright notice,
  48. * this list of conditions and the following disclaimer in the documentation
  49. * and/or other materials provided with the distribution.
  50. * 3. Neither the name of STMicroelectronics nor the names of other
  51. * contributors to this software may be used to endorse or promote products
  52. * derived from this software without specific written permission.
  53. * 4. This software, including modifications and/or derivative works of this
  54. * software, must execute solely and exclusively on microcontroller or
  55. * microprocessor devices manufactured by or for STMicroelectronics.
  56. * 5. Redistribution and use of this software other than as permitted under
  57. * this license is void and will automatically terminate your rights under
  58. * this license.
  59. *
  60. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  61. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  62. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  63. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  64. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  65. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  66. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  67. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  68. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  69. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  70. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  71. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  72. *
  73. ******************************************************************************
  74. */
  75. #include <stdlib.h> /* for rand */
  76. #include "GUIDEMO.h"
  77. #if (SHOW_GUIDEMO_SPEED)
  78. /*********************************************************************
  79. *
  80. * Static data
  81. *
  82. **********************************************************************
  83. */
  84. static const GUI_COLOR _aColor[8] = {
  85. 0x000000,
  86. 0x0000FF,
  87. 0x00FF00,
  88. 0x00FFFF,
  89. 0xFF0000,
  90. 0xFF00FF,
  91. 0xFFFF00,
  92. 0xFFFFFF
  93. };
  94. /*********************************************************************
  95. *
  96. * Static code
  97. *
  98. **********************************************************************
  99. */
  100. /*********************************************************************
  101. *
  102. * _GetPixelsPerSecond
  103. */
  104. static U32 _GetPixelsPerSecond(void) {
  105. GUI_COLOR Color, BkColor;
  106. U32 x0, y0, x1, y1, xSize, ySize;
  107. I32 t, t0;
  108. U32 Cnt, PixelsPerSecond, PixelCnt;
  109. //
  110. // Find an area which is not obstructed by any windows
  111. //
  112. xSize = LCD_GetXSize();
  113. ySize = LCD_GetYSize();
  114. Cnt = 0;
  115. x0 = 0;
  116. x1 = xSize - 1;
  117. y0 = 65;
  118. y1 = ySize - 60 - 1;
  119. Color = GUI_GetColor();
  120. BkColor = GUI_GetBkColor();
  121. GUI_SetColor(BkColor);
  122. //
  123. // Repeat fill as often as possible in 100 ms
  124. //
  125. t0 = GUIDEMO_GetTime();
  126. do {
  127. GUI_FillRect(x0, y0, x1, y1);
  128. Cnt++;
  129. t = GUIDEMO_GetTime();
  130. } while ((t - (t0 + 100)) <= 0);
  131. //
  132. // Compute result
  133. //
  134. t -= t0;
  135. PixelCnt = (x1 - x0 + 1) * (y1 - y0 + 1) * Cnt;
  136. PixelsPerSecond = PixelCnt / t * 1000;
  137. GUI_SetColor(Color);
  138. return PixelsPerSecond;
  139. }
  140. /*********************************************************************
  141. *
  142. * Public code
  143. *
  144. **********************************************************************
  145. */
  146. /*********************************************************************
  147. *
  148. * GUIDEMO_Speed
  149. */
  150. void GUIDEMO_Speed(void) {
  151. int TimeStart, i;
  152. U32 PixelsPerSecond;
  153. unsigned aColorIndex[8];
  154. int xSize, ySize, vySize;
  155. GUI_RECT Rect, ClipRect;
  156. char cText[40] = { 0 };
  157. xSize = LCD_GetXSize();
  158. ySize = LCD_GetYSize();
  159. vySize = LCD_GetVYSize();
  160. #if GUI_SUPPORT_CURSOR
  161. GUI_CURSOR_Hide();
  162. #endif
  163. if (vySize > ySize) {
  164. ClipRect.x0 = 0;
  165. ClipRect.y0 = 0;
  166. ClipRect.x1 = xSize;
  167. ClipRect.y1 = ySize;
  168. GUI_SetClipRect(&ClipRect);
  169. }
  170. GUIDEMO_ShowIntro("High speed",
  171. "Multi layer clipping\n"
  172. "Highly optimized drivers");
  173. for (i = 0; i< 8; i++) {
  174. aColorIndex[i] = GUI_Color2Index(_aColor[i]);
  175. }
  176. TimeStart = GUIDEMO_GetTime();
  177. for (i = 0; ((GUIDEMO_GetTime() - TimeStart) < 5000) && (GUIDEMO_CheckCancel() == 0); i++) {
  178. GUI_SetColorIndex(aColorIndex[i&7]);
  179. //
  180. // Calculate random positions
  181. //
  182. Rect.x0 = rand() % xSize - xSize / 2;
  183. Rect.y0 = rand() % ySize - ySize / 2;
  184. Rect.x1 = Rect.x0 + 20 + rand() % xSize;
  185. Rect.y1 = Rect.y0 + 20 + rand() % ySize;
  186. GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
  187. //
  188. // Clip rectangle to visible area and add the number of pixels (for speed computation)
  189. //
  190. if (Rect.x1 >= xSize) {
  191. Rect.x1 = xSize - 1;
  192. }
  193. if (Rect.y1 >= ySize) {
  194. Rect.y1 = ySize - 1;
  195. }
  196. if (Rect.x0 < 0 ) {
  197. Rect.x0 = 0;
  198. }
  199. if (Rect.y1 < 0) {
  200. Rect.y1 = 0;
  201. }
  202. GUI_Exec();
  203. //
  204. // Allow short breaks so we do not use all available CPU time ...
  205. //
  206. }
  207. GUIDEMO_NotifyStartNext();
  208. PixelsPerSecond = _GetPixelsPerSecond();
  209. GUI_SetClipRect(NULL);
  210. GUIDEMO_DrawBk(0);
  211. GUI_SetColor(GUI_WHITE);
  212. GUI_SetTextMode(GUI_TM_TRANS);
  213. GUI_SetFont(&GUI_FontRounded22);
  214. GUI_DrawBitmap(&bmSTLogo70x35, 5, 5);
  215. GUIDEMO_AddStringToString(cText, "Pixels/sec: ");
  216. GUIDEMO_AddIntToString(cText, PixelsPerSecond);
  217. GUI_DispStringHCenterAt(cText, xSize >> 1, (ySize - GUI_GetFontSizeY()) >> 1);
  218. GUIDEMO_Delay(4000);
  219. #if GUI_SUPPORT_CURSOR
  220. GUI_CURSOR_Show();
  221. #endif
  222. }
  223. #else
  224. void GUIDEMO_Speed(void) {}
  225. #endif
  226. /*************************** End of file ****************************/