aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Util/Util_ImageWindow.h
blob: 418598c62851699e19b662d379767a6f0251c20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/************************************************************************************

Filename    :   Util_ImageWindow.h
Content     :   An output object for windows that can display raw images for testing
Created     :   March 13, 2014
Authors     :   Dean Beeler

Copyright   :   Copyright 2014 Oculus VR, Inc. All Rights reserved.

Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); 
you may not use the Oculus VR Rift SDK except in compliance with the License, 
which is provided at the time of installation or download, or which 
otherwise accompanies this software in either electronic or hard copy form.

You may obtain a copy of the License at

http://www.oculusvr.com/licenses/LICENSE-3.1 

Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*************************************************************************************/

#ifndef UTIL_IMAGEWINDOW_H
#define UTIL_IMAGEWINDOW_H

#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include <d2d1.h>

#include "../../Include/OVR.h"
#include "../Kernel/OVR_Hash.h"
#include "../Kernel/OVR_Array.h"
#include "../Kernel/OVR_Threads.h"
#include "../Kernel/OVR_Deque.h"

#include <stdint.h>

namespace OVR { namespace Util {

class ImageWindow
{
	typedef struct 
	{
		float x;
		float y;
		float radius;
		float r;
		float g;
		float b;
		bool  fill;
	} CirclePlot;

	typedef struct  
	{
		float x;
		float y;
		float r;
		float g;
		float b;
		WCHAR* text;
	} TextPlot;

	typedef struct
	{
		Array<CirclePlot> plots;
		void*			  imageData;
		void*			  colorImageData;
		int				  width;
		int				  height;
		int				  colorPitch;
		bool			  ready;
	} Frame;

	static ID2D1Factory* pD2DFactory;

	HWND hWindow;
	ID2D1RenderTarget* pRT;
	D2D1_SIZE_U resolution;

	Mutex*						frontBufferMutex;

	InPlaceMutableDeque<Frame>	frames;

	ID2D1Bitmap*				greyBitmap;
	ID2D1Bitmap*				colorBitmap;

public:
	// constructors
	ImageWindow();
	ImageWindow( UINT width, UINT height );
	virtual ~ImageWindow();

	void OnPaint(); // Called by Windows when it receives a WM_PAINT message

	void UpdateImage( const UINT8* imageData, UINT width, UINT height ) { UpdateImageBW( imageData, width, height ); }
	void UpdateImageBW( const UINT8* imageData, UINT width, UINT height );
	void UpdateImageRGBA( const UINT8* imageData, UINT width, UINT height, UINT pitch );
	void Complete(); // Called by drawing thread to submit a frame

	void Process(); // Called by rendering thread to do window processing

	void AssociateSurface( void* surface );

	void addCircle( float x , float y, float radius, float r, float g, float b, bool fill );

	static ImageWindow*			GlobalWindow() { return globalWindow; }

private:


	static ImageWindow*			globalWindow;

	static bool running;
};

}} // namespace OVR::Util

#endif