![]() |
libdisplaydevice latest
C++ library to modify display devices.
|
Lowest level Windows API wrapper for easy mocking. More...
#include <src/windows/include/display_device/windows/win_api_layer_interface.h>
Public Member Functions | |
| virtual std::string | getDeviceId (const DISPLAYCONFIG_PATH_INFO &path) const =0 |
| Get a stable and persistent device id for the path. | |
| virtual std::string | getDisplayName (const DISPLAYCONFIG_PATH_INFO &path) const =0 |
| Get the logical display name for the path. | |
| virtual std::optional< Rational > | getDisplayScale (const std::string &display_name, const DISPLAYCONFIG_SOURCE_MODE &source_mode) const =0 |
| Get the scaling value for the display. | |
| virtual std::vector< std::byte > | getEdid (const DISPLAYCONFIG_PATH_INFO &path) const =0 |
| Get EDID byte array for the path. | |
| virtual std::string | getErrorString (LONG error_code) const =0 |
| Stringify the error code from Windows API. | |
| virtual std::string | getFriendlyName (const DISPLAYCONFIG_PATH_INFO &path) const =0 |
| Get the user-friendly name for the path. | |
| virtual std::optional< HdrState > | getHdrState (const DISPLAYCONFIG_PATH_INFO &path) const =0 |
| Get the HDR state the path. | |
| virtual std::string | getMonitorDevicePath (const DISPLAYCONFIG_PATH_INFO &path) const =0 |
| Get a string that represents a path from the adapter to the display target. | |
| virtual std::optional< PathAndModeData > | queryDisplayConfig (QueryType type) const =0 |
| Query Windows for the device paths and associated modes. | |
| virtual LONG | setDisplayConfig (std::vector< DISPLAYCONFIG_PATH_INFO > paths, std::vector< DISPLAYCONFIG_MODE_INFO > modes, UINT32 flags)=0 |
| Direct wrapper around the SetDisplayConfig WinAPI. | |
| virtual bool | setHdrState (const DISPLAYCONFIG_PATH_INFO &path, HdrState state)=0 |
| Set the HDR state for the path. | |
| virtual | ~WinApiLayerInterface ()=default |
| Default virtual destructor. | |
Lowest level Windows API wrapper for easy mocking.
|
nodiscardpure virtual |
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**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
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**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
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**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
Get EDID byte array for the path.
| path | Path to get the EDID for. |
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
Stringify the error code from Windows API.
| error_code | Error code to stringify. |
*Examples**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
Get the user-friendly name for the path.
| path | Path to get user-friendly name for. |
*Examples**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
Get the HDR state the path.
| path | Path to get HDR state for. |
*Examples**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
Get a string that represents a path from the adapter to the display target.
| path | Path to get the string for. |
*Examples**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
Query Windows for the device paths and associated modes.
| type | Specify device type to query for. |
*Examples**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
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**
Implemented in display_device::WinApiLayer.
|
nodiscardpure virtual |
Set the HDR state for the path.
| path | Path to set HDR state for. |
| state | Specify new HDR state. |
*Examples**
Implemented in display_device::WinApiLayer.