nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: PublicHeader: None nuclear@0: Filename : OVR_Display.h nuclear@0: Content : Contains platform independent display management nuclear@0: Created : May 6, 2014 nuclear@0: Notes : nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC 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 OVR_Display_h nuclear@0: #define OVR_Display_h nuclear@0: nuclear@0: #include "../Sensors/OVR_DeviceConstants.h" // Required for HmdTypeEnum nuclear@0: nuclear@0: #include "../Kernel/OVR_Types.h" nuclear@0: #include "../Kernel/OVR_Atomic.h" nuclear@0: #include "../Kernel/OVR_RefCount.h" nuclear@0: #include "../Kernel/OVR_Array.h" nuclear@0: #include "../Kernel/OVR_String.h" nuclear@0: #include "../Kernel/OVR_Math.h" nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: nuclear@0: class DisplaySearchHandle : virtual public RefCountBaseV nuclear@0: { nuclear@0: public: nuclear@0: DisplaySearchHandle() {} nuclear@0: nuclear@0: virtual ~DisplaySearchHandle() {} nuclear@0: nuclear@0: void operator= (const DisplaySearchHandle&) {} nuclear@0: }; nuclear@0: nuclear@0: //------------------------------------------------------------------------------------- nuclear@0: // ***** Display nuclear@0: nuclear@0: // Display object describes an Oculus HMD screen in LibOVR, providing information such nuclear@0: // as EDID serial number and resolution in platform-independent manner. nuclear@0: // nuclear@0: // Display is an abstract base class to support OS and driver specific implementations. nuclear@0: // It support HMD screen enumeration through GetDisplayCount/GetDisplay static functions. nuclear@0: // nuclear@0: // Examples of implementations of Display are the following: nuclear@0: // Display_Win32_Generic - Compatibly mode implementation that maintains operation on nuclear@0: // systems without drivers. nuclear@0: // Display_Win32_Driver - Driver-Based display nuclear@0: // Display_OSX_Generic - Additional compatibility mode implementation for OS X nuclear@0: nuclear@0: class Display : public RefCountBase nuclear@0: { nuclear@0: protected: nuclear@0: enum MirrorMode nuclear@0: { nuclear@0: MirrorEnabled = 0, nuclear@0: MirrorDisabled = 1 nuclear@0: }; nuclear@0: nuclear@0: MirrorMode mirrorMode; nuclear@0: nuclear@0: Display( nuclear@0: HmdTypeEnum deviceTypeGuess, nuclear@0: #ifdef OVR_OS_MAC nuclear@0: uint32_t displayID, nuclear@0: #else nuclear@0: const String& displayID, nuclear@0: #endif nuclear@0: const String& modelName, nuclear@0: const String& editSerial, nuclear@0: const Sizei& logicalRes, nuclear@0: const Sizei& nativeRes, nuclear@0: const Vector2i& displayOffset, nuclear@0: const uint64_t devNumber, nuclear@0: const uint32_t rotation, nuclear@0: const bool appExclusive): nuclear@0: mirrorMode(MirrorDisabled), nuclear@0: DeviceTypeGuess(deviceTypeGuess), nuclear@0: DisplayID(displayID), nuclear@0: ModelName(modelName), nuclear@0: EdidSerialNumber(editSerial), nuclear@0: LogicalResolutionInPixels(logicalRes), nuclear@0: NativeResolutionInPixels(nativeRes), nuclear@0: DesktopDisplayOffset(displayOffset), nuclear@0: DeviceNumber(devNumber), nuclear@0: Rotation(rotation), nuclear@0: ApplicationExclusive(appExclusive) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: void operator = (const Display&) { } // Quiet warning. nuclear@0: nuclear@0: public: nuclear@0: virtual ~Display() { } nuclear@0: nuclear@0: // ----- Platform specific static Display functionality ----- nuclear@0: nuclear@0: // Mandatory function that sets up the display environment with nuclear@0: // any necessary shimming and function hooks. This should be one nuclear@0: // of the very first things your application does when it nuclear@0: // initializes LibOVR nuclear@0: static bool Initialize(); nuclear@0: nuclear@0: // Returns a count of the detected displays. These are Rift displays nuclear@0: // attached directly to an active display port nuclear@0: static int GetDisplayCount( DisplaySearchHandle* handle = NULL, bool extended = true, bool applicationOnly = true, bool extendedEDIDSerials = false ); nuclear@0: // Returns a specific index of a display. Displays are sorted in no particular order. nuclear@0: static Ptr GetDisplay( int index = 0, DisplaySearchHandle* handle = NULL ); nuclear@0: nuclear@0: nuclear@0: // Returns true if we are referencing the same display; useful for matching display nuclear@0: // objects with the ones already detected. nuclear@0: bool MatchDisplay(const Display* other) nuclear@0: { nuclear@0: // Note this is not checking the DeviceName, which corresponds to which monitor the device is. nuclear@0: // This allows matching to match a display that has changed how it is plugged in. nuclear@0: return (DisplayID == other->DisplayID) && nuclear@0: (EdidSerialNumber == other->EdidSerialNumber) && nuclear@0: (NativeResolutionInPixels == other->NativeResolutionInPixels) && nuclear@0: (DesktopDisplayOffset == other->DesktopDisplayOffset) && nuclear@0: (ApplicationExclusive == other->ApplicationExclusive); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // ----- Device independent instance based Display functionality ----- nuclear@0: nuclear@0: // Device type guess based on display info. nuclear@0: const HmdTypeEnum DeviceTypeGuess; nuclear@0: #if defined(OVR_OS_MAC) nuclear@0: // CGDirectDisplayID for the rift. nuclear@0: const uint32_t DisplayID; nuclear@0: #else nuclear@0: // A string denoting the display device name so that apps can recognize the monitor nuclear@0: const String DisplayID; nuclear@0: #endif nuclear@0: // A literal string containing the name of the model, i.e. Rift DK2 nuclear@0: const String ModelName; nuclear@0: // Part of the serial number encoded in Edid, used for monitor <-> sensor matching. nuclear@0: const String EdidSerialNumber; nuclear@0: // Logical resolution is the display resolution in presentation terms. nuclear@0: // That is to say, the resolution that represents the orientation the nuclear@0: // display is projected to the user. For DK2, while being a portrait display nuclear@0: // the display is held in landscape and therefore the logical resolution nuclear@0: // is 1920x1080 nuclear@0: const Sizei LogicalResolutionInPixels; nuclear@0: // Native resolution is the resolution reported by the EDID and represents the nuclear@0: // exact hardware resolution of the Rift. For example, on DK2 nuclear@0: // this is 1080x1920 nuclear@0: // In theory, an OS rotated Rift's native and logical resolutions should match nuclear@0: const Sizei NativeResolutionInPixels; nuclear@0: // For displays that are attached to the desktop, this return value has meaning. nuclear@0: // Otherwise it should always return origin nuclear@0: const Vector2i DesktopDisplayOffset; nuclear@0: // For Windows machines this value stores the ChildUid used to identify this display nuclear@0: const uint64_t DeviceNumber; nuclear@0: // Stores the device specific default rotation of the screen nuclear@0: // E.g. DK2 is rotated 90 degrees as it is a portrait display nuclear@0: const uint32_t Rotation; nuclear@0: // Is set if the Display is capable in Application-Only mode nuclear@0: const bool ApplicationExclusive; nuclear@0: nuclear@0: // Functionality for rendering within the window nuclear@0: virtual MirrorMode SetMirrorMode( MirrorMode newMode ) = 0; nuclear@0: nuclear@0: // Functionality for enabling/disabling display nuclear@0: virtual bool SetDisplaySleep(bool off) nuclear@0: { nuclear@0: // Override to implement if supported nuclear@0: OVR_UNUSED(off); nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: // Check if right now the current rendering application should be in compatibility mode nuclear@0: static bool InCompatibilityMode( bool displaySearch = true ); nuclear@0: nuclear@0: // Get/set the mode for all applications nuclear@0: static bool GetDriverMode(bool& driverInstalled, bool& compatMode, bool& hideDK1Mode); nuclear@0: static bool SetDriverMode(bool compatMode, bool hideDK1Mode); nuclear@0: nuclear@0: static DisplaySearchHandle* GetDisplaySearchHandle(); nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: } // namespace OVR nuclear@0: nuclear@0: #endif