nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: Filename : Util_ImageWindow.h nuclear@0: Content : An output object for windows that can display raw images for testing nuclear@0: Created : March 13, 2014 nuclear@0: Authors : Dean Beeler nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus, Inc. All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: *************************************************************************************/ nuclear@0: nuclear@0: #ifndef UTIL_IMAGEWINDOW_H nuclear@0: #define UTIL_IMAGEWINDOW_H nuclear@0: nuclear@0: #if defined(OVR_OS_WIN32) nuclear@0: #include nuclear@0: #include nuclear@0: #define WIN32_LEAN_AND_MEAN nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #endif nuclear@0: nuclear@0: #include "../Kernel/OVR_Hash.h" nuclear@0: #include "../Kernel/OVR_Array.h" nuclear@0: #include "../Kernel/OVR_Threads.h" nuclear@0: #include "../Kernel/OVR_Deque.h" nuclear@0: nuclear@0: #include nuclear@0: nuclear@0: namespace OVR { namespace Util { nuclear@0: nuclear@0: typedef struct nuclear@0: { nuclear@0: float x; nuclear@0: float y; nuclear@0: float radius; nuclear@0: float r; nuclear@0: float g; nuclear@0: float b; nuclear@0: bool fill; nuclear@0: } CirclePlot; nuclear@0: nuclear@0: typedef struct nuclear@0: { nuclear@0: float x; nuclear@0: float y; nuclear@0: float r; nuclear@0: float g; nuclear@0: float b; nuclear@0: OVR::String text; nuclear@0: } TextPlot; nuclear@0: nuclear@0: class Frame : virtual public RefCountBaseV nuclear@0: { nuclear@0: public: nuclear@0: nuclear@0: Frame( int frame ) : nuclear@0: frameNumber( frame ), nuclear@0: imageData( NULL ), nuclear@0: colorImageData( NULL ), nuclear@0: plots(), nuclear@0: textLines(), nuclear@0: width( 0 ), nuclear@0: height( 0 ), nuclear@0: colorPitch( 0 ), nuclear@0: ready( false ) nuclear@0: { nuclear@0: nuclear@0: } nuclear@0: nuclear@0: ~Frame() nuclear@0: { nuclear@0: if( imageData ) nuclear@0: free( imageData ); nuclear@0: if( colorImageData ) nuclear@0: free( colorImageData ); nuclear@0: nuclear@0: plots.ClearAndRelease(); nuclear@0: textLines.ClearAndRelease(); nuclear@0: } nuclear@0: nuclear@0: int frameNumber; nuclear@0: nuclear@0: Array plots; nuclear@0: Array textLines; nuclear@0: void* imageData; nuclear@0: void* colorImageData; nuclear@0: int width; nuclear@0: int height; nuclear@0: int colorPitch; nuclear@0: bool ready; nuclear@0: }; nuclear@0: nuclear@0: #if defined(OVR_OS_WIN32) nuclear@0: class ImageWindow nuclear@0: { nuclear@0: HWND hWindow; nuclear@0: ID2D1RenderTarget* pRT; nuclear@0: D2D1_SIZE_U resolution; nuclear@0: nuclear@0: Mutex* frontBufferMutex; nuclear@0: nuclear@0: InPlaceMutableDeque< Ptr > frames; nuclear@0: nuclear@0: ID2D1Bitmap* greyBitmap; nuclear@0: ID2D1Bitmap* colorBitmap; nuclear@0: nuclear@0: public: nuclear@0: // constructors nuclear@0: ImageWindow(); nuclear@0: ImageWindow( uint32_t width, uint32_t height ); nuclear@0: virtual ~ImageWindow(); nuclear@0: nuclear@0: void GetResolution( size_t& width, size_t& height ) { width = resolution.width; height = resolution.height; } nuclear@0: nuclear@0: void OnPaint(); // Called by Windows when it receives a WM_PAINT message nuclear@0: nuclear@0: void UpdateImage( const uint8_t* imageData, uint32_t width, uint32_t height ) { UpdateImageBW( imageData, width, height ); } nuclear@0: void UpdateImageBW( const uint8_t* imageData, uint32_t width, uint32_t height ); nuclear@0: void UpdateImageRGBA( const uint8_t* imageData, uint32_t width, uint32_t height, uint32_t pitch ); nuclear@0: void Complete(); // Called by drawing thread to submit a frame nuclear@0: nuclear@0: void Process(); // Called by rendering thread to do window processing nuclear@0: nuclear@0: void AssociateSurface( void* surface ); nuclear@0: nuclear@0: void addCircle( float x , float y, float radius, float r, float g, float b, bool fill ); nuclear@0: void addText( float x, float y, float r, float g, float b, OVR::String text ); nuclear@0: nuclear@0: static ImageWindow* GlobalWindow( int window ) { return globalWindow[window]; } nuclear@0: static int WindowCount() { return windowCount; } nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: Ptr lastUnreadyFrame(); nuclear@0: nuclear@0: static const int MaxWindows = 4; nuclear@0: static ImageWindow* globalWindow[MaxWindows]; nuclear@0: static int windowCount; nuclear@0: static ID2D1Factory* pD2DFactory; nuclear@0: static IDWriteFactory* pDWriteFactory; nuclear@0: static HINSTANCE hInstD2d1; nuclear@0: static HINSTANCE hInstDwrite; nuclear@0: nuclear@0: }; nuclear@0: nuclear@0: #else nuclear@0: nuclear@0: class ImageWindow nuclear@0: { nuclear@0: public: nuclear@0: // constructors nuclear@0: ImageWindow() {} nuclear@0: ImageWindow( uint32_t width, uint32_t height ) { OVR_UNUSED( width ); OVR_UNUSED( height ); } nuclear@0: virtual ~ImageWindow() { } nuclear@0: nuclear@0: void GetResolution( size_t& width, size_t& height ) { width = 0; height = 0; } nuclear@0: nuclear@0: void OnPaint() { } nuclear@0: nuclear@0: void UpdateImage( const uint8_t* imageData, uint32_t width, uint32_t height ) { UpdateImageBW( imageData, width, height ); } nuclear@0: void UpdateImageBW( const uint8_t* imageData, uint32_t width, uint32_t height ) { OVR_UNUSED( imageData ); OVR_UNUSED( width ); OVR_UNUSED( height ); } nuclear@0: 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: void Complete() { } nuclear@0: nuclear@0: void Process() { } nuclear@0: nuclear@0: void AssociateSurface( void* surface ) { OVR_UNUSED(surface); } nuclear@0: nuclear@0: 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: 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: nuclear@0: static ImageWindow* GlobalWindow( int window ) { return globalWindow[window]; } nuclear@0: static int WindowCount() { return windowCount; } nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: static const int MaxWindows = 4; nuclear@0: static ImageWindow* globalWindow[4]; nuclear@0: static int windowCount; nuclear@0: }; nuclear@0: nuclear@0: #endif nuclear@0: nuclear@0: }} // namespace OVR::Util nuclear@0: nuclear@0: nuclear@0: #endif