ovr_sdk
diff 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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/Util/Util_ImageWindow.h Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,204 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : Util_ImageWindow.h 1.7 +Content : An output object for windows that can display raw images for testing 1.8 +Created : March 13, 2014 1.9 +Authors : Dean Beeler 1.10 + 1.11 +Copyright : Copyright 2014 Oculus, Inc. All Rights reserved. 1.12 + 1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.15 +which is provided at the time of installation or download, or which 1.16 +otherwise accompanies this software in either electronic or hard copy form. 1.17 + 1.18 +You may obtain a copy of the License at 1.19 + 1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.21 + 1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.23 +distributed under the License is distributed on an "AS IS" BASIS, 1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.25 +See the License for the specific language governing permissions and 1.26 +limitations under the License. 1.27 + 1.28 +*************************************************************************************/ 1.29 + 1.30 +#ifndef UTIL_IMAGEWINDOW_H 1.31 +#define UTIL_IMAGEWINDOW_H 1.32 + 1.33 +#if defined(OVR_OS_WIN32) 1.34 +#include <WinSock2.h> 1.35 +#include <WS2tcpip.h> 1.36 +#define WIN32_LEAN_AND_MEAN 1.37 +#include <Windows.h> 1.38 +#include <d2d1.h> 1.39 +#include <dwrite.h> 1.40 +#endif 1.41 + 1.42 +#include "../Kernel/OVR_Hash.h" 1.43 +#include "../Kernel/OVR_Array.h" 1.44 +#include "../Kernel/OVR_Threads.h" 1.45 +#include "../Kernel/OVR_Deque.h" 1.46 + 1.47 +#include <stdint.h> 1.48 + 1.49 +namespace OVR { namespace Util { 1.50 + 1.51 + typedef struct 1.52 + { 1.53 + float x; 1.54 + float y; 1.55 + float radius; 1.56 + float r; 1.57 + float g; 1.58 + float b; 1.59 + bool fill; 1.60 + } CirclePlot; 1.61 + 1.62 + typedef struct 1.63 + { 1.64 + float x; 1.65 + float y; 1.66 + float r; 1.67 + float g; 1.68 + float b; 1.69 + OVR::String text; 1.70 + } TextPlot; 1.71 + 1.72 +class Frame : virtual public RefCountBaseV<Frame> 1.73 + { 1.74 +public: 1.75 + 1.76 + Frame( int frame ) : 1.77 + frameNumber( frame ), 1.78 + imageData( NULL ), 1.79 + colorImageData( NULL ), 1.80 + plots(), 1.81 + textLines(), 1.82 + width( 0 ), 1.83 + height( 0 ), 1.84 + colorPitch( 0 ), 1.85 + ready( false ) 1.86 + { 1.87 + 1.88 + } 1.89 + 1.90 + ~Frame() 1.91 + { 1.92 + if( imageData ) 1.93 + free( imageData ); 1.94 + if( colorImageData ) 1.95 + free( colorImageData ); 1.96 + 1.97 + plots.ClearAndRelease(); 1.98 + textLines.ClearAndRelease(); 1.99 + } 1.100 + 1.101 + int frameNumber; 1.102 + 1.103 + Array<CirclePlot> plots; 1.104 + Array<TextPlot> textLines; 1.105 + void* imageData; 1.106 + void* colorImageData; 1.107 + int width; 1.108 + int height; 1.109 + int colorPitch; 1.110 + bool ready; 1.111 +}; 1.112 + 1.113 +#if defined(OVR_OS_WIN32) 1.114 +class ImageWindow 1.115 +{ 1.116 + HWND hWindow; 1.117 + ID2D1RenderTarget* pRT; 1.118 + D2D1_SIZE_U resolution; 1.119 + 1.120 + Mutex* frontBufferMutex; 1.121 + 1.122 + InPlaceMutableDeque< Ptr<Frame> > frames; 1.123 + 1.124 + ID2D1Bitmap* greyBitmap; 1.125 + ID2D1Bitmap* colorBitmap; 1.126 + 1.127 +public: 1.128 + // constructors 1.129 + ImageWindow(); 1.130 + ImageWindow( uint32_t width, uint32_t height ); 1.131 + virtual ~ImageWindow(); 1.132 + 1.133 + void GetResolution( size_t& width, size_t& height ) { width = resolution.width; height = resolution.height; } 1.134 + 1.135 + void OnPaint(); // Called by Windows when it receives a WM_PAINT message 1.136 + 1.137 + void UpdateImage( const uint8_t* imageData, uint32_t width, uint32_t height ) { UpdateImageBW( imageData, width, height ); } 1.138 + void UpdateImageBW( const uint8_t* imageData, uint32_t width, uint32_t height ); 1.139 + void UpdateImageRGBA( const uint8_t* imageData, uint32_t width, uint32_t height, uint32_t pitch ); 1.140 + void Complete(); // Called by drawing thread to submit a frame 1.141 + 1.142 + void Process(); // Called by rendering thread to do window processing 1.143 + 1.144 + void AssociateSurface( void* surface ); 1.145 + 1.146 + void addCircle( float x , float y, float radius, float r, float g, float b, bool fill ); 1.147 + void addText( float x, float y, float r, float g, float b, OVR::String text ); 1.148 + 1.149 + static ImageWindow* GlobalWindow( int window ) { return globalWindow[window]; } 1.150 + static int WindowCount() { return windowCount; } 1.151 + 1.152 +private: 1.153 + 1.154 + Ptr<Frame> lastUnreadyFrame(); 1.155 + 1.156 + static const int MaxWindows = 4; 1.157 + static ImageWindow* globalWindow[MaxWindows]; 1.158 + static int windowCount; 1.159 + static ID2D1Factory* pD2DFactory; 1.160 + static IDWriteFactory* pDWriteFactory; 1.161 + static HINSTANCE hInstD2d1; 1.162 + static HINSTANCE hInstDwrite; 1.163 + 1.164 +}; 1.165 + 1.166 +#else 1.167 + 1.168 +class ImageWindow 1.169 +{ 1.170 +public: 1.171 + // constructors 1.172 + ImageWindow() {} 1.173 + ImageWindow( uint32_t width, uint32_t height ) { OVR_UNUSED( width ); OVR_UNUSED( height ); } 1.174 + virtual ~ImageWindow() { } 1.175 + 1.176 + void GetResolution( size_t& width, size_t& height ) { width = 0; height = 0; } 1.177 + 1.178 + void OnPaint() { } 1.179 + 1.180 + void UpdateImage( const uint8_t* imageData, uint32_t width, uint32_t height ) { UpdateImageBW( imageData, width, height ); } 1.181 + void UpdateImageBW( const uint8_t* imageData, uint32_t width, uint32_t height ) { OVR_UNUSED( imageData ); OVR_UNUSED( width ); OVR_UNUSED( height ); } 1.182 + 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 ); } 1.183 + void Complete() { } 1.184 + 1.185 + void Process() { } 1.186 + 1.187 + void AssociateSurface( void* surface ) { OVR_UNUSED(surface); } 1.188 + 1.189 + 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 ); } 1.190 + 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 ); } 1.191 + 1.192 + static ImageWindow* GlobalWindow( int window ) { return globalWindow[window]; } 1.193 + static int WindowCount() { return windowCount; } 1.194 + 1.195 +private: 1.196 + 1.197 + static const int MaxWindows = 4; 1.198 + static ImageWindow* globalWindow[4]; 1.199 + static int windowCount; 1.200 +}; 1.201 + 1.202 +#endif 1.203 + 1.204 +}} // namespace OVR::Util 1.205 + 1.206 + 1.207 +#endif