From b1e9e6c295384fdf4545381a621986f6bd458cb7 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sat, 19 Jun 2021 09:48:47 +1200 Subject: [PATCH] [WIP] Added HDR functions to lib --- DisplayMagicianShared/AMD/ADL.cs | 143 +++++++++++++++++++++++- DisplayMagicianShared/AMD/ADLWrapper.cs | 32 +++++- 2 files changed, 171 insertions(+), 4 deletions(-) diff --git a/DisplayMagicianShared/AMD/ADL.cs b/DisplayMagicianShared/AMD/ADL.cs index 10ae53b..4a962df 100644 --- a/DisplayMagicianShared/AMD/ADL.cs +++ b/DisplayMagicianShared/AMD/ADL.cs @@ -136,6 +136,16 @@ namespace ATI.ADL /// return ADL Error Code internal delegate int ADL2_Display_DeviceConfig_Get(IntPtr ADLContextHandle, int adapterIndex, int displayIndex, out ADLDisplayConfig displayConfig); + /// ADL2 function to query whether a display is HDR Supported and Enabled + /// Handle to ADL client context. + /// Adapter Index + /// DisplayID for the desired display + /// return a pointer to the int whose value is set to true if the display supports HDR + /// return a pointer to the int whose value is set to true if HDR is enabled on this display + /// return ADL Error Code + internal delegate int ADL2_Display_HDRState_Get(IntPtr ADLContextHandle, int adapterIndex, ADLDisplayID displayID, out int support, out int enable); + + // ADL version of function delagates /// ADL Create Function to create ADL Data @@ -368,7 +378,7 @@ namespace ATI.ADL internal struct ADLAdapterInfoX2 { /// The size of the structure - int Size; + internal int Size; /// Adapter Index internal int AdapterIndex; /// Adapter UDID @@ -383,10 +393,10 @@ namespace ATI.ADL /// Adapter Vendor ID internal int VendorID; /// Adapter Adapter name - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)] + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_DISPLAY_NAME)] internal string AdapterName; /// Adapter Display name - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_PATH)] + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)ADL.ADL_MAX_DISPLAY_NAME)] internal string DisplayName; /// Adapter Present status internal int Present; @@ -527,6 +537,35 @@ namespace ATI.ADL internal int[] Reserved; } + internal struct ConvertedDDCInfoFlag + { + /// Indicates the display is a projector . + internal bool PROJECTORDEVICE; + /// Indicates the display has an EDID extension + internal bool EDIDEXTENSION; + /// Indicates the display is a digital device + internal bool DIGITALDEVICE; + /// Indicates the display has HDMI audio capabilities + internal bool HDMIAUDIODEVICE; + /// Indicates the display supports AI + internal bool SUPPORTS_AI; + /// Indicates the display supports xvYCC601 + internal bool SUPPORT_xvYCC601; + /// Indicates the display supports xvYCC709 + internal bool SUPPORT_xvYCC709; + } + + internal struct ConvertedSupportedHDR + { + /// HDR10/CEA861.3 HDR supported + internal bool CEA861_3; + /// DolbyVision HDR supported + internal bool DOLBYVISION; + /// FreeSync HDR supported. + internal bool FREESYNC_HDR; + } + + /// ADLDisplayID Structure [StructLayout(LayoutKind.Sequential)] internal struct ADLDisplayID @@ -1011,6 +1050,28 @@ namespace ATI.ADL /// Indicates the display is a projector internal const int ADL_DISPLAY_DISPLAYINFO_SHOWTYPE_PROJECTOR = 0x00100000; + // DDCInfoX2 DDCInfo Flag values + /// Indicates the display is a projector + internal const int ADL_DISPLAYDDCINFOEX_FLAG_PROJECTORDEVICE = (1 << 0); + /// Indicates the display is a projector + internal const int ADL_DISPLAYDDCINFOEX_FLAG_EDIDEXTENSION = (1 << 1); + /// Indicates the display is a projector + internal const int ADL_DISPLAYDDCINFOEX_FLAG_DIGITALDEVICE = (1 << 2); + /// Indicates the display is a projector + internal const int ADL_DISPLAYDDCINFOEX_FLAG_HDMIAUDIODEVICE = (1 << 3); + /// Indicates the display is a projector + internal const int ADL_DISPLAYDDCINFOEX_FLAG_SUPPORTS_AI = (1 << 4); + /// Indicates the display is a projector + internal const int ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC601 = (1 << 5); + /// Indicates the display is a projector + internal const int ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC709 = (1 << 6); + + /// HDR10/CEA861.3 HDR supported + internal const int ADL_HDR_CEA861_3 = 0x0001; + /// DolbyVision HDR supported + internal const int ADL_HDR_DOLBYVISION = 0x0002; + /// FreeSync HDR supported. + internal const int ADL_HDR_FREESYNC_HDR = 0x0004; #endregion Internal Constant @@ -1086,6 +1147,9 @@ namespace ATI.ADL [DllImport(Atiadlxx_FileName)] internal static extern int ADL2_Display_DeviceConfig_Get(IntPtr ADLContextHandle, int adapterIndex, int displayIndex, out ADLDisplayConfig displayConfig); + [DllImport(Atiadlxx_FileName)] + internal static extern int ADL2_Display_HDRState_Get(IntPtr ADLContextHandle, int adapterIndex, ADLDisplayID displayID, out int support, out int enable); + [DllImport(Atiadlxx_FileName)] internal static extern int ADL_Main_Control_Create (ADL_Main_Memory_Alloc callback, int enumConnectedAdapters); @@ -1534,6 +1598,31 @@ namespace ATI.ADL private static bool ADL2_Display_DeviceConfig_Get_Check = false; #endregion ADL2_Display_DeviceConfig_Get + #region ADL2_Display_HDRState_Get + /// ADL2_Display_HDRState_Get Delegates + internal static ADL2_Display_HDRState_Get ADL2_Display_HDRState_Get + { + get + { + if (!ADL2_Display_HDRState_Get_Check && null == ADL2_Display_HDRState_Get_) + { + ADL2_Display_HDRState_Get_Check = true; + if (ADLCheckLibrary.IsFunctionValid("ADL2_Display_HDRState_Get")) + { + ADL2_Display_HDRState_Get_ = ADLImport.ADL2_Display_HDRState_Get; + } + } + return ADL2_Display_HDRState_Get_; + } + } + /// Private Delegate + private static ADL2_Display_HDRState_Get ADL2_Display_HDRState_Get_ = null; + /// check flag to indicate the delegate has been checked + private static bool ADL2_Display_HDRState_Get_Check = false; + #endregion ADL2_Display_HDRState_Get + + // ================================ + #region ADL_Main_Control_Create /// ADL_Main_Control_Create Delegates internal static ADL_Main_Control_Create ADL_Main_Control_Create @@ -1842,6 +1931,54 @@ namespace ATI.ADL #region ADL Helper Functions + internal static ConvertedDDCInfoFlag ConvertDDCInfoFlag(int DDCInfoValue) + { + ConvertedDDCInfoFlag expandedDDCInfoValue = new ConvertedDDCInfoFlag(); + + // Indicates the display is a digital device + if ((DDCInfoValue & ADL.ADL_DISPLAYDDCINFOEX_FLAG_DIGITALDEVICE) == ADL.ADL_DISPLAYDDCINFOEX_FLAG_DIGITALDEVICE) + expandedDDCInfoValue.DIGITALDEVICE = true; + // Indicates the display supports EDID queries + if ((DDCInfoValue & ADL.ADL_DISPLAYDDCINFOEX_FLAG_EDIDEXTENSION) == ADL.ADL_DISPLAYDDCINFOEX_FLAG_EDIDEXTENSION) + expandedDDCInfoValue.EDIDEXTENSION = true; + // Indicates the display suports HDMI Audio + if ((DDCInfoValue & ADL.ADL_DISPLAYDDCINFOEX_FLAG_HDMIAUDIODEVICE) == ADL.ADL_DISPLAYDDCINFOEX_FLAG_HDMIAUDIODEVICE) + expandedDDCInfoValue.HDMIAUDIODEVICE = true; + // Indicates the display is a projector + if ((DDCInfoValue & ADL.ADL_DISPLAYDDCINFOEX_FLAG_PROJECTORDEVICE) == ADL.ADL_DISPLAYDDCINFOEX_FLAG_PROJECTORDEVICE) + expandedDDCInfoValue.PROJECTORDEVICE = true; + // Indicates the display supports AI + if ((DDCInfoValue & ADL.ADL_DISPLAYDDCINFOEX_FLAG_SUPPORTS_AI) == ADL.ADL_DISPLAYDDCINFOEX_FLAG_SUPPORTS_AI) + expandedDDCInfoValue.SUPPORTS_AI = true; + // Indicates the display supports YCC601 + if ((DDCInfoValue & ADL.ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC601) == ADL.ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC601) + expandedDDCInfoValue.SUPPORT_xvYCC601 = true; + // Indicates the display supports YCC709 + if ((DDCInfoValue & ADL.ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC709) == ADL.ADL_DISPLAYDDCINFOEX_FLAG_SUPPORT_xvYCC709) + expandedDDCInfoValue.SUPPORT_xvYCC709 = true; + + return expandedDDCInfoValue; + + } + + internal static ConvertedSupportedHDR ConvertSupportedHDR(int supportedHDR) + { + ConvertedSupportedHDR expandedSupportedHDR = new ConvertedSupportedHDR(); + + // Indicates the display is a digital device + if ((supportedHDR & ADL.ADL_HDR_CEA861_3) == ADL.ADL_HDR_CEA861_3) + expandedSupportedHDR.CEA861_3 = true; + // Indicates the display supports EDID queries + if ((supportedHDR & ADL.ADL_HDR_DOLBYVISION) == ADL.ADL_HDR_DOLBYVISION) + expandedSupportedHDR.DOLBYVISION = true; + // Indicates the display suports HDMI Audio + if ((supportedHDR & ADL.ADL_HDR_FREESYNC_HDR) == ADL.ADL_HDR_FREESYNC_HDR) + expandedSupportedHDR.FREESYNC_HDR = true; + + return expandedSupportedHDR; + + } + internal static ConvertedDisplayInfoValue ConvertDisplayInfoValue(int displayInfoValue) { ConvertedDisplayInfoValue expandedDisplayInfoValue = new ConvertedDisplayInfoValue(); diff --git a/DisplayMagicianShared/AMD/ADLWrapper.cs b/DisplayMagicianShared/AMD/ADLWrapper.cs index 937d6b7..983297a 100644 --- a/DisplayMagicianShared/AMD/ADLWrapper.cs +++ b/DisplayMagicianShared/AMD/ADLWrapper.cs @@ -353,7 +353,7 @@ namespace DisplayMagicianShared.AMD Console.WriteLine($"Display Info Value = {oneDisplayInfo.DisplayInfoValue}"); Console.WriteLine($"Display Manufacturer Name = {oneDisplayInfo.DisplayManufacturerName}"); Console.WriteLine($"Display Name = {oneDisplayInfo.DisplayName}"); - Console.WriteLine($"Display Output Type = {oneDisplayInfo.DisplayOutputType}"); + Console.WriteLine($"Display Output Type = {oneDisplayInfo.DisplayOutputType.ToString("G")}"); Console.WriteLine($"Display Type = {oneDisplayInfo.DisplayType}"); Console.WriteLine($"Display Info Value DISPLAYCONNECTED = {displayInfoValue.DISPLAYCONNECTED}"); @@ -402,6 +402,13 @@ namespace DisplayMagicianShared.AMD ADLRet = ADL.ADL2_Display_DDCInfo2_Get(_adlContextHandle, oneAdapter.AdapterIndex, oneDisplayInfo.DisplayID.DisplayPhysicalIndex, out displayDDCInfo2); if (ADLRet == ADL.ADL_OK) { + + // Convert the DDCInfoFlag to something usable using a library function I made + ConvertedDDCInfoFlag DDCInfoFlag = ADL.ConvertDDCInfoFlag(displayDDCInfo2.DDCInfoFlag); + + // Convert the DDCInfoFlag to something usable using a library function I made + ConvertedSupportedHDR supportedHDR= ADL.ConvertSupportedHDR(displayDDCInfo2.SupportedHDR); + Console.WriteLine($"### Display DDCInfo2 for Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex} ###"); Console.WriteLine($"Display AvgLuminanceData = {displayDDCInfo2.AvgLuminanceData}"); Console.WriteLine($"Display DDCInfoFlag = {displayDDCInfo2.DDCInfoFlag}"); @@ -440,12 +447,35 @@ namespace DisplayMagicianShared.AMD Console.WriteLine($"Display SupportedHDR = {displayDDCInfo2.SupportedHDR}"); Console.WriteLine($"Display SupportedTransferFunction = {displayDDCInfo2.SupportedTransferFunction}"); Console.WriteLine($"Display SupportsDDC = {displayDDCInfo2.SupportsDDC}"); + Console.WriteLine($"Display DDCInfoFlag Digital Device = {DDCInfoFlag.DIGITALDEVICE}"); + Console.WriteLine($"Display DDCInfoFlag EDID Extension = {DDCInfoFlag.EDIDEXTENSION}"); + Console.WriteLine($"Display DDCInfoFlag HDMI Audio Device = {DDCInfoFlag.HDMIAUDIODEVICE}"); + Console.WriteLine($"Display DDCInfoFlag Projector Device = {DDCInfoFlag.PROJECTORDEVICE}"); + Console.WriteLine($"Display DDCInfoFlag Supports AI = {DDCInfoFlag.SUPPORTS_AI}"); + Console.WriteLine($"Display DDCInfoFlag Supports xvYCC601 = {DDCInfoFlag.SUPPORT_xvYCC601}"); + Console.WriteLine($"Display DDCInfoFlag Supports xvYCC709 = {DDCInfoFlag.SUPPORT_xvYCC709}"); + Console.WriteLine($"Display SupportedHDR Supports CEA861_3 = {supportedHDR.CEA861_3}"); + Console.WriteLine($"Display SupportedHDR Supports DOLBYVISION = {supportedHDR.DOLBYVISION}"); + Console.WriteLine($"Display SupportedHDR Supports FREESYNC_HDR = {supportedHDR.FREESYNC_HDR}"); } else { Console.WriteLine($"Error running ADL_vDisplay_EdidData_Get on Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex}: {ADL.ConvertADLReturnValueIntoWords(ADLRet)}"); } } + int HDRSupported = 0; + int HDREnabled = 0; + if (ADL.ADL2_Display_HDRState_Get != null) + { + // Get the HDR State from the Display + ADLRet = ADL.ADL2_Display_HDRState_Get(_adlContextHandle, oneAdapter.AdapterIndex, oneDisplayInfo.DisplayID, out HDRSupported, out HDREnabled); + if (ADLRet == ADL.ADL_OK) + { + Console.WriteLine($"### Display HDR State for Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex} ###"); + Console.WriteLine($"Display HDR Supported = {HDRSupported}"); + Console.WriteLine($"Display HDR Enabled = {HDREnabled}"); + } + } // Create an array of all the important display info we need to record