ovr_sdk

annotate LibOVR/Src/Util/Util_ImageWindow.h @ 0:1b39a1b46319

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