Util_ImageWindow.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /************************************************************************************
  2. Filename : Util_ImageWindow.h
  3. Content : An output object for windows that can display raw images for testing
  4. Created : March 13, 2014
  5. Authors : Dean Beeler
  6. Copyright : Copyright 2014 Oculus, Inc. All Rights reserved.
  7. Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
  8. you may not use the Oculus VR Rift SDK except in compliance with the License,
  9. which is provided at the time of installation or download, or which
  10. otherwise accompanies this software in either electronic or hard copy form.
  11. You may obtain a copy of the License at
  12. http://www.oculusvr.com/licenses/LICENSE-3.2
  13. Unless required by applicable law or agreed to in writing, the Oculus VR SDK
  14. distributed under the License is distributed on an "AS IS" BASIS,
  15. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. See the License for the specific language governing permissions and
  17. limitations under the License.
  18. *************************************************************************************/
  19. #ifndef OVR_Util_ImageWindow_h
  20. #define OVR_Util_ImageWindow_h
  21. #if defined(OVR_OS_WIN32)
  22. #include "Kernel/OVR_Win32_IncludeWindows.h"
  23. #include <d2d1.h>
  24. #include <dwrite.h>
  25. #endif
  26. #include "Kernel/OVR_Hash.h"
  27. #include "Kernel/OVR_Array.h"
  28. #include "Kernel/OVR_Threads.h"
  29. #include "Kernel/OVR_Deque.h"
  30. #include <stdint.h>
  31. namespace OVR { namespace Util {
  32. typedef struct
  33. {
  34. float x;
  35. float y;
  36. float radius;
  37. float r;
  38. float g;
  39. float b;
  40. bool fill;
  41. } CirclePlot;
  42. typedef struct
  43. {
  44. float x;
  45. float y;
  46. float r;
  47. float g;
  48. float b;
  49. OVR::String text;
  50. } TextPlot;
  51. class Frame : virtual public RefCountBaseV<Frame>
  52. {
  53. public:
  54. Frame( int frame ) :
  55. frameNumber( frame ),
  56. plots(),
  57. textLines(),
  58. imageData( NULL ),
  59. colorImageData( NULL ),
  60. width( 0 ),
  61. height( 0 ),
  62. colorPitch( 0 ),
  63. ready( false )
  64. {
  65. }
  66. ~Frame()
  67. {
  68. if( imageData )
  69. free( imageData );
  70. if( colorImageData )
  71. free( colorImageData );
  72. plots.ClearAndRelease();
  73. textLines.ClearAndRelease();
  74. }
  75. int frameNumber;
  76. Array<CirclePlot> plots;
  77. Array<TextPlot> textLines;
  78. void* imageData;
  79. void* colorImageData;
  80. int width;
  81. int height;
  82. int colorPitch;
  83. bool ready;
  84. };
  85. #if defined(OVR_OS_WIN32)
  86. class ImageWindow
  87. {
  88. HWND hWindow;
  89. ID2D1RenderTarget* pRT;
  90. D2D1_SIZE_U resolution;
  91. Mutex* frontBufferMutex;
  92. InPlaceMutableDeque< Ptr<Frame> > frames;
  93. ID2D1Bitmap* greyBitmap;
  94. ID2D1Bitmap* colorBitmap;
  95. public:
  96. // constructors
  97. ImageWindow();
  98. ImageWindow( uint32_t width, uint32_t height );
  99. virtual ~ImageWindow();
  100. void GetResolution( size_t& width, size_t& height ) { width = resolution.width; height = resolution.height; }
  101. void OnPaint(); // Called by Windows when it receives a WM_PAINT message
  102. void UpdateImage( const uint8_t* imageData, uint32_t width, uint32_t height ) { UpdateImageBW( imageData, width, height ); }
  103. void UpdateImageBW( const uint8_t* imageData, uint32_t width, uint32_t height );
  104. void UpdateImageRGBA( const uint8_t* imageData, uint32_t width, uint32_t height, uint32_t pitch );
  105. void Complete(); // Called by drawing thread to submit a frame
  106. void Process(); // Called by rendering thread to do window processing
  107. void AssociateSurface( void* surface );
  108. void addCircle( float x , float y, float radius, float r, float g, float b, bool fill );
  109. void addText( float x, float y, float r, float g, float b, OVR::String text );
  110. static ImageWindow* GlobalWindow( int window ) { return globalWindow[window]; }
  111. static int WindowCount() { return windowCount; }
  112. private:
  113. Ptr<Frame> lastUnreadyFrame();
  114. static const int MaxWindows = 4;
  115. static ImageWindow* globalWindow[MaxWindows];
  116. static int windowCount;
  117. static ID2D1Factory* pD2DFactory;
  118. static IDWriteFactory* pDWriteFactory;
  119. static HINSTANCE hInstD2d1;
  120. static HINSTANCE hInstDwrite;
  121. };
  122. #else
  123. class ImageWindow
  124. {
  125. public:
  126. // constructors
  127. ImageWindow() {}
  128. ImageWindow( uint32_t width, uint32_t height ) { OVR_UNUSED( width ); OVR_UNUSED( height ); }
  129. virtual ~ImageWindow() { }
  130. void GetResolution( size_t& width, size_t& height ) { width = 0; height = 0; }
  131. void OnPaint() { }
  132. void UpdateImage( const uint8_t* imageData, uint32_t width, uint32_t height ) { UpdateImageBW( imageData, width, height ); }
  133. void UpdateImageBW( const uint8_t* imageData, uint32_t width, uint32_t height ) { OVR_UNUSED( imageData ); OVR_UNUSED( width ); OVR_UNUSED( height ); }
  134. void UpdateImageRGBA( const uint8_t* imageData, uint32_t width, uint32_t height, uint32_t pitch ) { OVR_UNUSED( imageData ); OVR_UNUSED( width ); OVR_UNUSED( height ); OVR_UNUSED( pitch ); }
  135. void Complete() { }
  136. void Process() { }
  137. void AssociateSurface( void* surface ) { OVR_UNUSED(surface); }
  138. void addCircle( float x , float y, float radius, float r, float g, float b, bool fill ) { OVR_UNUSED( x ); OVR_UNUSED( y ); OVR_UNUSED( radius ); OVR_UNUSED( r ); OVR_UNUSED( g ); OVR_UNUSED( b ); OVR_UNUSED( fill ); }
  139. void addText( float x, float y, float r, float g, float b, OVR::String text ) { OVR_UNUSED( x ); OVR_UNUSED( y ); OVR_UNUSED( r ); OVR_UNUSED( g ); OVR_UNUSED( b ); OVR_UNUSED( text ); }
  140. static ImageWindow* GlobalWindow( int window ) { return globalWindow[window]; }
  141. static int WindowCount() { return windowCount; }
  142. private:
  143. static const int MaxWindows = 4;
  144. static ImageWindow* globalWindow[4];
  145. static int windowCount;
  146. };
  147. #endif
  148. }} // namespace OVR::Util
  149. #endif