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.

138 lines
3.8 KiB

  1. /*
  2. Copyright 2005-2013 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. : red_mask(0xff0000), red_shift(16), green_mask(0xff00),
  45. green_shift(8), blue_mask(0xff), blue_shift(0), depth(24)
  46. {
  47. assert(g_video == 0);
  48. g_video = this; title = "Video"; updating = calc_fps = false;
  49. }
  50. bool video::init_window(int x, int y)
  51. {
  52. g_sizex = x; g_sizey = y;
  53. g_pImg = new unsigned int[x*y];
  54. running = true;
  55. return false;
  56. }
  57. bool video::init_console()
  58. {
  59. running = true;
  60. return true;
  61. }
  62. void video::terminate()
  63. {
  64. if(calc_fps) {
  65. double fps = g_fps;
  66. #if _WIN32 || _WIN64
  67. fps /= (GetTickCount()-g_msec)/1000.0;
  68. #else
  69. struct timezone tz; struct timeval end_time; gettimeofday(&end_time, &tz);
  70. 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);
  71. #endif
  72. printf("%s: %.1f fps\n", title, fps);
  73. }
  74. g_video = 0; running = false;
  75. if(g_pImg) { delete[] g_pImg; g_pImg = 0; }
  76. }
  77. video::~video()
  78. {
  79. if(g_video) terminate();
  80. }
  81. //! Count and display FPS count in titlebar
  82. bool video::next_frame()
  83. {
  84. if(calc_fps){
  85. if(!g_fps) {
  86. #if _WIN32 || _WIN64
  87. g_msec = GetTickCount();
  88. #else
  89. struct timezone tz; gettimeofday(&g_time, &tz);
  90. #endif
  91. }
  92. g_fps++;
  93. }
  94. return running;
  95. }
  96. //! Do standard loop
  97. void video::main_loop()
  98. {
  99. on_process();
  100. }
  101. //! Change window title
  102. void video::show_title()
  103. {
  104. }
  105. ///////////////////////////////////////////// public methods of video class ///////////////////////
  106. drawing_area::drawing_area(int x, int y, int sizex, int sizey)
  107. : start_x(x), start_y(y), size_x(sizex), size_y(sizey), pixel_depth(24),
  108. base_index(y*g_sizex + x), max_index(g_sizex*g_sizey), index_stride(g_sizex), ptr32(g_pImg)
  109. {
  110. assert(x < g_sizex); assert(y < g_sizey);
  111. assert(x+sizex <= g_sizex); assert(y+sizey <= g_sizey);
  112. index = base_index; // current index
  113. }
  114. void drawing_area::update() {}