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