You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.8 KiB

  1. /*
  2. Copyright 2005-2014 Intel Corporation. All Rights Reserved.
  3. This file is part of Threading Building Blocks.
  4. Threading Building Blocks is free software; you can redistribute it
  5. and/or modify it under the terms of the GNU General Public License
  6. version 2 as published by the Free Software Foundation.
  7. Threading Building Blocks is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  9. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with Threading Building Blocks; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  14. As a special exception, you may use this file as part of a free software
  15. library without restriction. Specifically, if other files instantiate
  16. templates or use macros or inline functions from this file, or you compile
  17. this file and link it with other files to produce an executable, this
  18. file does not by itself cause the resulting executable to be covered by
  19. the GNU General Public License. This exception does not however
  20. invalidate any other reasons why the executable file might be covered by
  21. the GNU General Public License.
  22. */
  23. #include "video.h"
  24. #include <cassert>
  25. #include <stdio.h>
  26. unsigned int * g_pImg = 0;
  27. int g_sizex, g_sizey;
  28. static video *g_video = 0;
  29. static int g_fps = 0;
  30. #if _WIN32 || _WIN64
  31. static DWORD g_msec = 0;
  32. #ifdef _WINDOWS
  33. HINSTANCE video::win_hInstance = 0;
  34. int video::win_iCmdShow = 0;
  35. void video::win_set_class(WNDCLASSEX &wcex) { }
  36. void video::win_load_accelerators(int idc) { }
  37. #endif //_WINDOWS
  38. #else
  39. #include <sched.h>
  40. #include <sys/time.h>
  41. struct timeval g_time;
  42. #endif //_WIN32||_WIN64
  43. video::video()
  44. // OpenGL* RGBA byte order for little-endian CPU
  45. : red_mask(0xff), red_shift(0), green_mask(0xff00),
  46. green_shift(8), blue_mask(0xff0000), blue_shift(16), depth(24)
  47. {
  48. assert(g_video == 0);
  49. g_video = this; title = "Video"; updating = calc_fps = false;
  50. }
  51. bool video::init_window(int x, int y)
  52. {
  53. g_sizex = x; g_sizey = y;
  54. g_pImg = new unsigned int[x*y];
  55. running = true;
  56. return false;
  57. }
  58. bool video::init_console()
  59. {
  60. running = true;
  61. return true;
  62. }
  63. void video::terminate()
  64. {
  65. if(calc_fps) {
  66. double fps = g_fps;
  67. #if _WIN32 || _WIN64
  68. fps /= (GetTickCount()-g_msec)/1000.0;
  69. #else
  70. struct timezone tz; struct timeval end_time; gettimeofday(&end_time, &tz);
  71. fps /= (end_time.tv_sec+1.0*end_time.tv_usec/1000000.0) - (g_time.tv_sec+1.0*g_time.tv_usec/1000000.0);
  72. #endif
  73. printf("%s: %.1f fps\n", title, fps);
  74. }
  75. g_video = 0; running = false;
  76. if(g_pImg) { delete[] g_pImg; g_pImg = 0; }
  77. }
  78. video::~video()
  79. {
  80. if(g_video) terminate();
  81. }
  82. //! Count and display FPS count in titlebar
  83. bool video::next_frame()
  84. {
  85. if(calc_fps){
  86. if(!g_fps) {
  87. #if _WIN32 || _WIN64
  88. g_msec = GetTickCount();
  89. #else
  90. struct timezone tz; gettimeofday(&g_time, &tz);
  91. #endif
  92. }
  93. g_fps++;
  94. }
  95. return running;
  96. }
  97. //! Do standard loop
  98. void video::main_loop()
  99. {
  100. on_process();
  101. }
  102. //! Change window title
  103. void video::show_title()
  104. {
  105. }
  106. ///////////////////////////////////////////// public methods of video class ///////////////////////
  107. drawing_area::drawing_area(int x, int y, int sizex, int sizey)
  108. : start_x(x), start_y(y), size_x(sizex), size_y(sizey), pixel_depth(24),
  109. base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex), ptr32(g_pImg)
  110. {
  111. assert(x < g_sizex); assert(y < g_sizey);
  112. assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey);
  113. index = base_index; // current index
  114. }
  115. void drawing_area::update() {}