aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Displays/OVR_Display.h
blob: 3184182b5ffbcb8318af60937de388fab6d2819a (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/************************************************************************************

PublicHeader:   None
Filename    :   OVR_Display.h
Content     :   Contains platform independent display management
Created     :   May 6, 2014
Notes       : 

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 OVR_Display_h
#define OVR_Display_h

#include "../Sensors/OVR_DeviceConstants.h" // Required for HmdTypeEnum

#include "../Kernel/OVR_Types.h"
#include "../Kernel/OVR_Atomic.h"
#include "../Kernel/OVR_RefCount.h"
#include "../Kernel/OVR_Array.h"
#include "../Kernel/OVR_String.h"
#include "../Kernel/OVR_Math.h"

namespace OVR {


class DisplaySearchHandle : virtual public RefCountBaseV<DisplaySearchHandle>
{
public:
	DisplaySearchHandle() {}

	virtual ~DisplaySearchHandle() {}

	void operator= (const DisplaySearchHandle&) {}
};

//-------------------------------------------------------------------------------------
// ***** Display

// Display object describes an Oculus HMD screen in LibOVR, providing information such
// as EDID serial number and resolution in platform-independent manner.
//
// Display is an abstract base class to support OS and driver specific implementations.
// It support HMD screen enumeration through GetDisplayCount/GetDisplay static functions.
//
// Examples of implementations of Display are the following:
// Display_Win32_Generic - Compatibly mode implementation that maintains operation on
//						   systems without drivers.
// Display_Win32_Driver  - Driver-Based display
// Display_OSX_Generic   - Additional compatibility mode implementation for OS X

class Display : public RefCountBase<Display>
{
protected:
	enum MirrorMode
	{
		MirrorEnabled = 0,
		MirrorDisabled = 1
	};

	MirrorMode mirrorMode;

	Display(
            HmdTypeEnum deviceTypeGuess,
#ifdef OVR_OS_MAC
            uint32_t displayID,
#else
			const String& displayID,
#endif
			const String& modelName,
			const String& editSerial,
            const Sizei& logicalRes,
			const Sizei& nativeRes,
			const Vector2i& displayOffset, 
			const uint64_t devNumber,
			const uint32_t rotation,
			const bool appExclusive):
		DeviceTypeGuess(deviceTypeGuess),
        DisplayID(displayID),
		ModelName(modelName),
		EdidSerialNumber(editSerial),
		LogicalResolutionInPixels(logicalRes),
		NativeResolutionInPixels(nativeRes),
		DesktopDisplayOffset(displayOffset),
		DeviceNumber(devNumber),
		Rotation(rotation),
		ApplicationExclusive(appExclusive)
    {
	}

    void operator = (const Display&) { } // Quiet warning.

public:
	virtual ~Display() { }

	// ----- Platform specific static Display functionality -----

	// Mandatory function that sets up the display environment with
	// any necessary shimming and function hooks. This should be one
	// of the very first things your application does when it
	// initializes LibOVR
	static bool         Initialize();

	// Returns a count of the detected displays. These are Rift displays
	// attached directly to an active display port
	static int          GetDisplayCount( DisplaySearchHandle* handle = NULL, bool extended = true, bool applicationOnly = true, bool extendedEDIDSerials = false );
	// Returns a specific index of a display. Displays are sorted in no particular order.
	static Ptr<Display> GetDisplay( int index = 0, DisplaySearchHandle* handle = NULL ); 


    // Returns true if we are referencing the same display; useful for matching display
    // objects with the ones already detected.
    bool MatchDisplay(const Display* other)
    {
		// Note this is not checking the DeviceName, which corresponds to which monitor the device is.
		// This allows matching to match a display that has changed how it is plugged in.
		return (DisplayID == other->DisplayID) &&
               (EdidSerialNumber == other->EdidSerialNumber) &&
               (NativeResolutionInPixels == other->NativeResolutionInPixels) &&
               (DesktopDisplayOffset == other->DesktopDisplayOffset) &&
               (ApplicationExclusive == other->ApplicationExclusive);
    }


	// ----- Device independent instance based Display functionality -----

    // Device type guess based on display info.
    const HmdTypeEnum   DeviceTypeGuess;
#if defined(OVR_OS_MAC)
    // CGDirectDisplayID for the rift.
    const uint32_t      DisplayID; 
#else
	// A string denoting the display device name so that apps can recognize the monitor
	const String        DisplayID;
#endif
    // A literal string containing the name of the model, i.e. Rift DK2
    const String        ModelName;
    // Part of the serial number encoded in Edid, used for monitor <-> sensor matching.
    const String        EdidSerialNumber;
    // Logical resolution is the display resolution in presentation terms.
    // That is to say, the resolution that represents the orientation the
    // display is projected to the user. For DK2, while being a portrait display
    // the display is held in landscape and therefore the logical resolution
    // is 1920x1080
    const Sizei         LogicalResolutionInPixels;
    // Native resolution is the resolution reported by the EDID and represents the
    // exact hardware resolution of the Rift. For example, on DK2
    // this is 1080x1920
    // In theory, an OS rotated Rift's native and logical resolutions should match
    const Sizei         NativeResolutionInPixels;
    // For displays that are attached to the desktop, this return value has meaning.
    // Otherwise it should always return origin
    const Vector2i      DesktopDisplayOffset;
	// For Windows machines this value stores the ChildUid used to identify this display
	const uint64_t	    DeviceNumber;
	// Stores the device specific default rotation of the screen
	// E.g. DK2 is rotated 90 degrees as it is a portrait display
	const uint32_t	    Rotation;
	// Is set if the Display is capable in Application-Only mode
	const bool			ApplicationExclusive;

	// Functionality for rendering within the window
	virtual MirrorMode SetMirrorMode( MirrorMode newMode ) = 0;

	// Functionality for enabling/disabling display
    virtual bool SetDisplaySleep(bool off)
    {
        // Override to implement if supported
        OVR_UNUSED(off);
        return false;
    }

    // Check if right now the current rendering application should be in compatibility mode
    static bool InCompatibilityMode( bool displaySearch = true );

    static DisplaySearchHandle* GetDisplaySearchHandle();
};


} // namespace OVR

#endif