![]() |
libdisplaydevice master
C++ library to modify display devices.
|
Default implementation for the WinApiLayerInterface. More...
#include <src/windows/include/display_device/windows/win_api_layer.h>
Public Member Functions | |
| std::string | getDeviceId (const DISPLAYCONFIG_PATH_INFO &path) const override |
| Get a stable and persistent device id for the path. | |
| std::string | getDisplayName (const DISPLAYCONFIG_PATH_INFO &path) const override |
| Get the logical display name for the path. | |
| std::optional< Rational > | getDisplayScale (std::string_view display_name, const DISPLAYCONFIG_SOURCE_MODE &source_mode) const override |
| Get the scaling value for the display. | |
| std::vector< std::byte > | getEdid (const DISPLAYCONFIG_PATH_INFO &path) const override |
| Get EDID byte array for the path. | |
| std::string | getErrorString (LONG error_code) const override |
| Stringify the error code from Windows API. | |
| std::string | getFriendlyName (const DISPLAYCONFIG_PATH_INFO &path) const override |
| Get the user-friendly name for the path. | |
| std::optional< HdrState > | getHdrState (const DISPLAYCONFIG_PATH_INFO &path) const override |
| Get the HDR state the path. | |
| std::string | getMonitorDevicePath (const DISPLAYCONFIG_PATH_INFO &path) const override |
| Get a string that represents a path from the adapter to the display target. | |
| bool | keepDisplayAwake () override |
| Request that Windows keep the current thread's display awake. | |
| std::optional< PathAndModeData > | queryDisplayConfig (QueryType type) const override |
| Query Windows for the device paths and associated modes. | |
| bool | restorePowerRequest () override |
| Clear the current thread's display keep-awake request. | |
| LONG | setDisplayConfig (std::vector< DISPLAYCONFIG_PATH_INFO > paths, std::vector< DISPLAYCONFIG_MODE_INFO > modes, UINT32 flags) override |
| Direct wrapper around the SetDisplayConfig WinAPI. | |
| bool | setHdrState (const DISPLAYCONFIG_PATH_INFO &path, HdrState state) override |
| Set the HDR state for the path. | |
| bool | wakeDisplay (std::chrono::milliseconds timeout) override |
| Ask Windows to wake the display and wait before retrying detection. | |
Public Member Functions inherited from display_device::WinApiLayerInterface | |
| virtual | ~WinApiLayerInterface ()=default |
| Default virtual destructor. | |
Default implementation for the WinApiLayerInterface.
|
nodiscardoverridevirtual |
Get a stable and persistent device id for the path.
This function tries to generate a unique id for the path that is persistent between driver re-installs and physical unplugging and replugging of the device.
The best candidate for it could have been a "ContainerID" from the registry, however it was found to be unstable for the virtual display (probably because it uses the EDID for the id generation and the current virtual displays have incomplete EDID information). The "ContainerID" also does not change if the physical device is plugged into a different port (which does not satisfy the "device id for the path" part) and is unstable for virtual displays, therefore other solution was used.
The accepted solution was to use the "InstanceID" and EDID (just to be on the safe side). "InstanceID" is semi-stable, it has some parts that change between driver re-installs, and it has a part that changes based on the GPU port that the display is connected to. It is most likely to be unique, but since the MS documentation is lacking we are also hashing EDID information (contains serial ids, timestamps, etc. that should guarantee that identical displays are differentiated like with the "ContainerID"). Most importantly this information is stable for the virtual displays.
After we remove the unstable parts from the "InstanceID" and hash everything together, we get an id that changes only when you connect the display to a different GPU port which seems to be acceptable.
As a fallback we are using a hashed device path, in case the "InstanceID" or EDID is not available. At least if you don't do driver re-installs often and change the GPU ports, it will be stable for a while.
| path | Path to get the device id for. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Get the logical display name for the path.
These are the "\\\\.\\DISPLAY1", "\\\\.\\DISPLAY2" and etc. display names that can change whenever Windows wants to change them.
| path | Path to get user display name for. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Get the scaling value for the display.
| display_name | Display to get the scaling for. |
| source_mode | Source mode to get the scaling for. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Get EDID byte array for the path.
| path | Path to get the EDID for. |
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Stringify the error code from Windows API.
| error_code | Error code to stringify. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Get the user-friendly name for the path.
| path | Path to get user-friendly name for. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Get the HDR state the path.
| path | Path to get HDR state for. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Get a string that represents a path from the adapter to the display target.
| path | Path to get the string for. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Request that Windows keep the current thread's display awake.
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Query Windows for the device paths and associated modes.
| type | Specify device type to query for. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Clear the current thread's display keep-awake request.
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Direct wrapper around the SetDisplayConfig WinAPI.
It implements no additional logic, just a direct pass-trough.
| paths | List of paths to pass. |
| modes | List of modes to pass. |
| flags | Flags to pass. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Set the HDR state for the path.
| path | Path to set HDR state for. |
| state | Specify new HDR state. |
*Examples**
Implements display_device::WinApiLayerInterface.
|
nodiscardoverridevirtual |
Ask Windows to wake the display and wait before retrying detection.
Windows accepts a display-required execution-state request, but this low-level call does not prove that a specific output is active afterward.
| timeout | Maximum time to wait after issuing the wake request. |
Implements display_device::WinApiLayerInterface.