public ADLDisplayInfo GetCurrentDisplay() { if (string.IsNullOrEmpty(_currentDisplay.DisplayName)) { _currentDisplay = GetDisplays().FirstOrDefault(); } return(_currentDisplay); }
public Screen GetScreenForDisplay(ADLDisplayInfo display) { var index = 0; foreach (var screen in Screen.AllScreens) { Logger.Debug($"SCREEN[{index}]: {screen.DeviceName}, {screen.DeviceFriendlyName()}, {screen.Primary}"); index++; } return(Screen.AllScreens.FirstOrDefault(x => x.DeviceFriendlyName().Equals(display.DisplayName))); }
public static bool SetDisplayHDRState(ADLDisplayInfo display, bool enabled) { var del = ADL.GetDelegate <ADL.ADL2_Display_HDRState_Set>(); if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null) { var ADLRet = del(context, display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID, enabled ? 1 : 0); return(CheckError(ADLRet, nameof(ADL.ADL2_Display_HDRState_Set))); } return(false); }
public static bool SetDisplayDitherState(ADLDisplayInfo display, ADLDitherState ditherState) { var del = ADL.GetDelegate <ADL.ADL_Display_DitherState_Set>(); if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null) { var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, (int)ditherState); return(CheckError(ADLRet, nameof(ADL.ADL_Display_DitherState_Set))); } return(false); }
public static bool SetDisplayColorDepth(ADLDisplayInfo display, ADLColorDepth colorDepth) { var del = ADL.GetDelegate <ADL.ADL_Display_ColorDepth_Set>(); if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null) { var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, (int)colorDepth); return(CheckError(ADLRet, nameof(ADL.ADL_Display_ColorDepth_Set))); } return(false); }
public static bool SetDisplayPixelFormat(ADLDisplayInfo display, ADLPixelFormat pixelFormat) { var del = ADL.GetDelegate <ADL.ADL_Display_PixelFormat_Set>(); if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null) { var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, (int)pixelFormat); return(CheckError(ADLRet, nameof(ADL.ADL_Display_PixelFormat_Set))); } return(false); }
public void SetCurrentDisplay(AmdPreset preset) { var displays = GetDisplays(); if (preset.primaryDisplay) { _currentDisplay = displays.FirstOrDefault(); } else { _currentDisplay = displays.FirstOrDefault(x => x.DisplayName.Equals(preset.displayName)); } }
public string GetFullDisplayName(ADLDisplayInfo display) { var name = display.DisplayName; var screen = GetScreenForDisplay(display); if (screen != null) { name = $"{screen.DeviceName} ({name})"; } return(name); }
public ADLDitherState GetDithering(ADLDisplayInfo display = default(ADLDisplayInfo)) { if (string.IsNullOrEmpty(display.DisplayName)) { display = GetCurrentDisplay(); } var ditherState = ADLDitherState.DRIVER_DEFAULT; if (ADLWrapper.GetDisplayDitherState(display, ref ditherState)) { return(ditherState); } return(ditherState); }
public static bool GetDisplayHDRState(ADLDisplayInfo display, ref bool supported, ref bool enabled) { var del = ADL.GetDelegate <ADL.ADL2_Display_HDRState_Get>(); if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null) { var supportedInt = 0; var enabledInt = 0; var ADLRet = del(context, display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID, ref supportedInt, ref enabledInt); supported = supportedInt != 0; enabled = enabledInt != 0; return(CheckError(ADLRet, nameof(ADL.ADL2_Display_HDRState_Get))); } return(false); }
public static bool GetDisplayResolution(ADLDisplayInfo display, ref int horizontal, ref int vertical) { var screen = Screen.PrimaryScreen; var bounds = screen.Bounds; horizontal = bounds.Width; vertical = bounds.Height; Logger.Debug($"GetDisplayResolution: {horizontal}x{vertical}"); //var del = ADL.GetDelegate<ADL.ADL_Display_Size_Get>(); //if (display.DisplayID.DisplayPhysicalIndex >= 0 && del != null) //{ // int lpDefaultWidth, lpDefaultHeight, lpMinWidth, lpMinHeight, lpMaxWidth, lpMaxHeight, lpStepWidth, lpStepHeight; // lpDefaultWidth = lpDefaultHeight = lpMinWidth = lpMinHeight = lpMaxWidth = lpMaxHeight = lpStepWidth = lpStepHeight = 0; // var ADLRet = del(display.DisplayID.DisplayLogicalAdapterIndex, display.DisplayID.DisplayLogicalIndex, ref horizontal, ref vertical, ref lpDefaultWidth, ref lpDefaultHeight, ref lpMinWidth, ref lpMinHeight, ref lpMaxWidth, ref lpMaxHeight, ref lpStepWidth, ref lpStepHeight); // return CheckError(ADLRet, nameof(ADL.ADL_Display_Size_Get)); //} return(true); }
static void Main(string[] args) { int ADLRet = -1; int NumberOfAdapters = 0; int NumberOfDisplays = 0; if (null != ADL.ADL_Main_Control_Create) { // Second parameter is 1: Get only the present adapters ADLRet = ADL.ADL_Main_Control_Create(ADL.ADL_Main_Memory_Alloc, 1); } if (ADL.ADL_SUCCESS == ADLRet) { if (null != ADL.ADL_Adapter_NumberOfAdapters_Get) { ADL.ADL_Adapter_NumberOfAdapters_Get(ref NumberOfAdapters); } Console.WriteLine("Number Of Adapters: " + NumberOfAdapters.ToString() + "\n"); if (0 < NumberOfAdapters) { // Get OS adpater info from ADL ADLAdapterInfoArray OSAdapterInfoData; OSAdapterInfoData = new ADLAdapterInfoArray(); if (null != ADL.ADL_Adapter_AdapterInfo_Get) { IntPtr AdapterBuffer = IntPtr.Zero; int size = Marshal.SizeOf(OSAdapterInfoData); AdapterBuffer = Marshal.AllocCoTaskMem((int)size); Marshal.StructureToPtr(OSAdapterInfoData, AdapterBuffer, false); if (null != ADL.ADL_Adapter_AdapterInfo_Get) { ADLRet = ADL.ADL_Adapter_AdapterInfo_Get(AdapterBuffer, size); if (ADL.ADL_SUCCESS == ADLRet) { OSAdapterInfoData = (ADLAdapterInfoArray)Marshal.PtrToStructure(AdapterBuffer, OSAdapterInfoData.GetType()); int IsActive = 0; for (int i = 0; i < NumberOfAdapters; i++) { // Check if the adapter is active if (null != ADL.ADL_Adapter_Active_Get) { ADLRet = ADL.ADL_Adapter_Active_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref IsActive); } if (ADL.ADL_SUCCESS == ADLRet) { Console.WriteLine("Adapter is : " + (0 == IsActive ? "DISABLED" : "ENABLED")); Console.WriteLine("Adapter Index: " + OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex.ToString()); Console.WriteLine("Adapter UDID : " + OSAdapterInfoData.ADLAdapterInfo[i].UDID); Console.WriteLine("Bus No : " + OSAdapterInfoData.ADLAdapterInfo[i].BusNumber.ToString()); Console.WriteLine("Driver No : " + OSAdapterInfoData.ADLAdapterInfo[i].DriverNumber.ToString()); Console.WriteLine("Function No : " + OSAdapterInfoData.ADLAdapterInfo[i].FunctionNumber.ToString()); Console.WriteLine("Vendor ID : " + OSAdapterInfoData.ADLAdapterInfo[i].VendorID.ToString()); Console.WriteLine("Adapter Name : " + OSAdapterInfoData.ADLAdapterInfo[i].AdapterName); Console.WriteLine("Display Name : " + OSAdapterInfoData.ADLAdapterInfo[i].DisplayName); Console.WriteLine("Present : " + (0 == OSAdapterInfoData.ADLAdapterInfo[i].Present ? "No" : "Yes")); Console.WriteLine("Exist : " + (0 == OSAdapterInfoData.ADLAdapterInfo[i].Exist ? "No" : "Yes")); Console.WriteLine("Driver Path : " + OSAdapterInfoData.ADLAdapterInfo[i].DriverPath); Console.WriteLine("Driver Path X: " + OSAdapterInfoData.ADLAdapterInfo[i].DriverPathExt); Console.WriteLine("PNP String : " + OSAdapterInfoData.ADLAdapterInfo[i].PNPString); // Obtain information about displays ADLDisplayInfo oneDisplayInfo = new ADLDisplayInfo(); if (null != ADL.ADL_Display_DisplayInfo_Get) { IntPtr DisplayBuffer = IntPtr.Zero; int j = 0; // Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection ADLRet = ADL.ADL_Display_DisplayInfo_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 1); if (ADL.ADL_SUCCESS == ADLRet) { List <ADLDisplayInfo> DisplayInfoData = new List <ADLDisplayInfo>(); for (j = 0; j < NumberOfDisplays; j++) { oneDisplayInfo = (ADLDisplayInfo)Marshal.PtrToStructure(new IntPtr(DisplayBuffer.ToInt32() + j * Marshal.SizeOf(oneDisplayInfo)), oneDisplayInfo.GetType()); DisplayInfoData.Add(oneDisplayInfo); } Console.WriteLine("\nTotal Number of Displays supported: " + NumberOfDisplays.ToString()); Console.WriteLine("\nDispID AdpID Type OutType CnctType Connected Mapped InfoValue DisplayName "); for (j = 0; j < NumberOfDisplays; j++) { int InfoValue = DisplayInfoData[j].DisplayInfoValue; string StrConnected = (1 == (InfoValue & 1)) ? "Yes" : "No "; string StrMapped = (2 == (InfoValue & 2)) ? "Yes" : "No "; int AdpID = DisplayInfoData[j].DisplayID.DisplayLogicalAdapterIndex; string StrAdpID = (AdpID < 0) ? "--" : AdpID.ToString("d2"); Console.WriteLine(DisplayInfoData[j].DisplayID.DisplayLogicalIndex.ToString() + " " + StrAdpID + " " + DisplayInfoData[j].DisplayType.ToString() + " " + DisplayInfoData[j].DisplayOutputType.ToString() + " " + DisplayInfoData[j].DisplayConnector.ToString() + " " + StrConnected + " " + StrMapped + " " + InfoValue.ToString("x4") + " " + DisplayInfoData[j].DisplayName.ToString()); } Console.WriteLine(); } else { Console.WriteLine("ADL_Display_DisplayInfo_Get() returned error code " + ADLRet.ToString()); } // Release the memory for the DisplayInfo structure if (IntPtr.Zero != DisplayBuffer) { Marshal.FreeCoTaskMem(DisplayBuffer); } } } } } else { Console.WriteLine("ADL_Adapter_AdapterInfo_Get() returned error code " + ADLRet.ToString()); } } // Release the memory for the AdapterInfo structure if (IntPtr.Zero != AdapterBuffer) { Marshal.FreeCoTaskMem(AdapterBuffer); } } } if (null != ADL.ADL_Main_Control_Destroy) { ADL.ADL_Main_Control_Destroy(); } } else { Console.WriteLine("ADL_Main_Control_Create() returned error code " + ADLRet.ToString()); Console.WriteLine("\nCheck if ADL is properly installed!\n"); } Console.WriteLine("Press ENTER to EXIT"); Console.ReadLine(); }
public AmdDisplayInfo(ADLDisplayInfo display, List <string> values, string infoLine) { Display = display; Values = values; InfoLine = infoLine; }
public static List <ADLDisplayInfo> GetAllDisplays(bool connected = true) { int ADLRet; int NumberOfDisplays = 0; var DisplayInfoData = new List <ADLDisplayInfo>(); var OSAdapterInfoData = GetAdapters(); if (OSAdapterInfoData == null || !OSAdapterInfoData.Value.ADLAdapterInfo.Any()) { return(DisplayInfoData); } var primaryAdapter = OSAdapterInfoData.Value.ADLAdapterInfo.First(); ADLDisplayInfo oneDisplayInfo = new ADLDisplayInfo(); var del = ADL.GetDelegate <ADL.ADL_Display_DisplayInfo_Get>(); if (null != del) { IntPtr DisplayBuffer = IntPtr.Zero; int j = 0; // Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection ADLRet = del(primaryAdapter.AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 1); if (ADL.ADL_SUCCESS == ADLRet) { for (j = 0; j < NumberOfDisplays; j++) { oneDisplayInfo = (ADLDisplayInfo)Marshal.PtrToStructure(new IntPtr(DisplayBuffer.ToInt64() + j * Marshal.SizeOf(oneDisplayInfo)), oneDisplayInfo.GetType()); if (!connected || (1 == (oneDisplayInfo.DisplayInfoValue & 1))) { DisplayInfoData.Add(oneDisplayInfo); } } Logger.Debug("Total Number of Displays supported: " + NumberOfDisplays.ToString()); Logger.Debug("DispID DispPhyId AdpID Type OutType CnctType Connected Mapped InfoValue DisplayName "); for (j = 0; j < DisplayInfoData.Count; j++) { int InfoValue = DisplayInfoData[j].DisplayInfoValue; string StrConnected = (1 == (InfoValue & 1)) ? "Yes" : "No "; string StrMapped = (2 == (InfoValue & 2)) ? "Yes" : "No "; int AdpID = DisplayInfoData[j].DisplayID.DisplayLogicalAdapterIndex; string StrAdpID = (AdpID < 0) ? "--" : AdpID.ToString("d2"); Logger.Debug(DisplayInfoData[j].DisplayID.DisplayLogicalIndex.ToString() + " " + DisplayInfoData[j].DisplayID.DisplayPhysicalIndex.ToString() + " " + StrAdpID + " " + DisplayInfoData[j].DisplayType.ToString() + " " + DisplayInfoData[j].DisplayOutputType.ToString() + " " + DisplayInfoData[j].DisplayConnector.ToString() + " " + StrConnected + " " + StrMapped + " " + InfoValue.ToString("x4") + " " + DisplayInfoData[j].DisplayName.ToString()); } } else { Logger.Debug("ADL_Display_DisplayInfo_Get() returned error code " + ADLRet.ToString()); } // Release the memory for the DisplayInfo structure if (IntPtr.Zero != DisplayBuffer) { Marshal.FreeCoTaskMem(DisplayBuffer); } } return(DisplayInfoData); }
public string GetDisplayDeviceName(ADLDisplayInfo display) { return(Screen.PrimaryScreen.DeviceName); }