using System; using WindowsDisplayAPI.Native; using WindowsDisplayAPI.Native.DeviceContext; namespace WindowsDisplayAPI { /// /// Contains information about the device capabilities of a display device /// public sealed class MonitorCapabilities : IDisposable { private readonly DCHandle _dcHandle; internal MonitorCapabilities(DCHandle dcHandle) { _dcHandle = dcHandle; var tech = (DisplayTechnology) DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.Technology); if (tech != DisplayTechnology.RasterDisplay) { throw new NotSupportedException(); } } /// /// Gets the actual color resolution of the device, in bits per pixel. /// public int ActualColorDepth { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.ColorResolution) * ColorPlanes; } /// /// Gets a boolean value indicating if the device is capable of clipping to a rectangle. /// public bool ClipToRectangleCapability { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.ClipCapabilities) > 0; } /// /// Gets the color management capabilities of the device /// public DisplayColorManagementCapabilities ColorManagementCapabilities { get => (DisplayColorManagementCapabilities) DeviceContextApi.GetDeviceCaps( _dcHandle, DeviceCapability.ColorManagementCapabilities ); } /// /// Gets the number of color planes. /// public int ColorPlanes { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.Planes); } /// /// Gets the curve capabilities of the device /// public DisplayCurveCapabilities CurveCapabilities { get => (DisplayCurveCapabilities) DeviceContextApi.GetDeviceCaps( _dcHandle, DeviceCapability.CurveCapabilities ); } /// /// Gets the diagonal width of the device pixel used for line drawing. /// public int DevicePixelDiagonalWidth { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.HypotenuseAspect); } /// /// Gets the relative height of a device pixel used for line drawing. /// public int DevicePixelRelativeHeight { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.VerticalAspect); } /// /// Gets the relative width of a device pixel used for line drawing. /// public int DevicePixelRelativeWidth { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.HorizontalAspect); } /// /// Gets the diagonal length of the physical screen in millimeters. /// public int DiagonalSizeInMM { get => (int) Math.Round(Math.Pow(Math.Pow(VerticalSizeInMM, 2) + Math.Pow(HorizontalSizeInMM, 2), 0.5)); } /// /// Gets the device driver version. /// public int DriverVersion { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.DriverVersion); } /// /// Gets the effective color resolution of the device, in bits per pixel. /// public int EffectiveColorDepth { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.BitsPerPixel) * ColorPlanes; } /// /// Gets the number of pixels per logical inch along the screen width. /// public int HorizontalPixelPerInch { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.HorizontalLogicalPixels); } /// /// Gets the height of screen in raster lines. /// public int HorizontalResolution { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.HorizontalResolution); } /// /// Gets the width of the physical screen in millimeters. /// public int HorizontalSizeInMM { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.HorizontalSizeInMM); } /// /// Gets the line capabilities of the device /// public DisplayLineCapabilities LineCapabilities { get => (DisplayLineCapabilities) DeviceContextApi.GetDeviceCaps( _dcHandle, DeviceCapability.LineCapabilities ); } /// /// Gets the polygon capabilities of the device /// public DisplayPolygonalCapabilities PolygonalCapabilities { get => (DisplayPolygonalCapabilities) DeviceContextApi.GetDeviceCaps( _dcHandle, DeviceCapability.PolygonalCapabilities ); } /// /// Gets the preferred horizontal drawing alignment, expressed as a multiple of pixels. For best drawing performance, /// windows should be horizontally aligned to a multiple of this value. A value of null indicates that the device is /// accelerated, and any alignment may be used. /// public int? PreferredHorizontalDrawingAlignment { get { var value = DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.PreferredBLTAlignment); if (value == 0) { return null; } return value; } } /// /// Gets the raster capabilities of the device /// public DisplayRasterCapabilities RasterCapabilities { get => (DisplayRasterCapabilities) DeviceContextApi.GetDeviceCaps( _dcHandle, DeviceCapability.RasterCapabilities ); } /// /// Gets the shader blending capabilities of the device /// public DisplayShaderBlendingCapabilities ShaderBlendingCapabilities { get => (DisplayShaderBlendingCapabilities) DeviceContextApi.GetDeviceCaps( _dcHandle, DeviceCapability.ShadeBlendingCapabilities ); } /// /// Gets the text capabilities of the device /// public DisplayTextCapabilities TextCapabilities { get => (DisplayTextCapabilities) DeviceContextApi.GetDeviceCaps( _dcHandle, DeviceCapability.TextCapabilities ); } /// /// Gets the number of pixels per logical inch along the screen height. /// public int VerticalPixelPerInch { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.VerticalLogicalPixels); } /// /// Gets the current vertical refresh rate of the device, in cycles per second (Hz) or null for display hardware's /// default refresh rate. /// public int? VerticalRefreshRateInHz { get { var value = DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.VerticalRefreshRateInHz); if (value <= 1) { return null; } return value; } } /// /// Gets the width of the screen in pixels. /// public int VerticalResolution { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.VerticalResolution); } /// /// Gets the height of the physical screen in millimeters. /// public int VerticalSizeInMM { get => DeviceContextApi.GetDeviceCaps(_dcHandle, DeviceCapability.VerticalSizeInMM); } /// public void Dispose() { _dcHandle?.Dispose(); } } }