ovr_sdk
view LibOVR/Src/Util/Util_ImageWindow.h @ 3:f12a8f74fe1f
added the Xcode project
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 21 Jan 2015 11:37:50 +0200 |
parents | |
children |
line source
1 /************************************************************************************
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
8 Copyright : Copyright 2014 Oculus, Inc. All Rights reserved.
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (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.
15 You may obtain a copy of the License at
17 http://www.oculusvr.com/licenses/LICENSE-3.2
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.
25 *************************************************************************************/
27 #ifndef UTIL_IMAGEWINDOW_H
28 #define UTIL_IMAGEWINDOW_H
30 #if defined(OVR_OS_WIN32)
31 #include <WinSock2.h>
32 #include <WS2tcpip.h>
33 #define WIN32_LEAN_AND_MEAN
34 #include <Windows.h>
35 #include <d2d1.h>
36 #include <dwrite.h>
37 #endif
39 #include "../Kernel/OVR_Hash.h"
40 #include "../Kernel/OVR_Array.h"
41 #include "../Kernel/OVR_Threads.h"
42 #include "../Kernel/OVR_Deque.h"
44 #include <stdint.h>
46 namespace OVR { namespace Util {
48 typedef struct
49 {
50 float x;
51 float y;
52 float radius;
53 float r;
54 float g;
55 float b;
56 bool fill;
57 } CirclePlot;
59 typedef struct
60 {
61 float x;
62 float y;
63 float r;
64 float g;
65 float b;
66 OVR::String text;
67 } TextPlot;
69 class Frame : virtual public RefCountBaseV<Frame>
70 {
71 public:
73 Frame( int frame ) :
74 frameNumber( frame ),
75 imageData( NULL ),
76 colorImageData( NULL ),
77 plots(),
78 textLines(),
79 width( 0 ),
80 height( 0 ),
81 colorPitch( 0 ),
82 ready( false )
83 {
85 }
87 ~Frame()
88 {
89 if( imageData )
90 free( imageData );
91 if( colorImageData )
92 free( colorImageData );
94 plots.ClearAndRelease();
95 textLines.ClearAndRelease();
96 }
98 int frameNumber;
100 Array<CirclePlot> plots;
101 Array<TextPlot> textLines;
102 void* imageData;
103 void* colorImageData;
104 int width;
105 int height;
106 int colorPitch;
107 bool ready;
108 };
110 #if defined(OVR_OS_WIN32)
111 class ImageWindow
112 {
113 HWND hWindow;
114 ID2D1RenderTarget* pRT;
115 D2D1_SIZE_U resolution;
117 Mutex* frontBufferMutex;
119 InPlaceMutableDeque< Ptr<Frame> > frames;
121 ID2D1Bitmap* greyBitmap;
122 ID2D1Bitmap* colorBitmap;
124 public:
125 // constructors
126 ImageWindow();
127 ImageWindow( uint32_t width, uint32_t height );
128 virtual ~ImageWindow();
130 void GetResolution( size_t& width, size_t& height ) { width = resolution.width; height = resolution.height; }
132 void OnPaint(); // Called by Windows when it receives a WM_PAINT message
134 void UpdateImage( const uint8_t* imageData, uint32_t width, uint32_t height ) { UpdateImageBW( imageData, width, height ); }
135 void UpdateImageBW( const uint8_t* imageData, uint32_t width, uint32_t height );
136 void UpdateImageRGBA( const uint8_t* imageData, uint32_t width, uint32_t height, uint32_t pitch );
137 void Complete(); // Called by drawing thread to submit a frame
139 void Process(); // Called by rendering thread to do window processing
141 void AssociateSurface( void* surface );
143 void addCircle( float x , float y, float radius, float r, float g, float b, bool fill );
144 void addText( float x, float y, float r, float g, float b, OVR::String text );
146 static ImageWindow* GlobalWindow( int window ) { return globalWindow[window]; }
147 static int WindowCount() { return windowCount; }
149 private:
151 Ptr<Frame> lastUnreadyFrame();
153 static const int MaxWindows = 4;
154 static ImageWindow* globalWindow[MaxWindows];
155 static int windowCount;
156 static ID2D1Factory* pD2DFactory;
157 static IDWriteFactory* pDWriteFactory;
158 static HINSTANCE hInstD2d1;
159 static HINSTANCE hInstDwrite;
161 };
163 #else
165 class ImageWindow
166 {
167 public:
168 // constructors
169 ImageWindow() {}
170 ImageWindow( uint32_t width, uint32_t height ) { OVR_UNUSED( width ); OVR_UNUSED( height ); }
171 virtual ~ImageWindow() { }
173 void GetResolution( size_t& width, size_t& height ) { width = 0; height = 0; }
175 void OnPaint() { }
177 void UpdateImage( const uint8_t* imageData, uint32_t width, uint32_t height ) { UpdateImageBW( imageData, width, height ); }
178 void UpdateImageBW( const uint8_t* imageData, uint32_t width, uint32_t height ) { OVR_UNUSED( imageData ); OVR_UNUSED( width ); OVR_UNUSED( height ); }
179 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 ); }
180 void Complete() { }
182 void Process() { }
184 void AssociateSurface( void* surface ) { OVR_UNUSED(surface); }
186 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 ); }
187 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 ); }
189 static ImageWindow* GlobalWindow( int window ) { return globalWindow[window]; }
190 static int WindowCount() { return windowCount; }
192 private:
194 static const int MaxWindows = 4;
195 static ImageWindow* globalWindow[4];
196 static int windowCount;
197 };
199 #endif
201 }} // namespace OVR::Util
204 #endif