Repository navigation
Conversation
Let the driver start with <count>0</count> so no virtual monitor is reported while it is not in use, and add two pipe commands to plug the configured monitor(s) in and out at runtime without reinitializing the adapter: - ATTACH: if no monitor is attached, create <count> monitors (one when <count> is 0). Replies ATTACHED or ERROR. - DETACH: report departure of every attached monitor. Replies DETACHED or ERROR. The adapter still declares at least one supported monitor so ATTACH works when starting from zero. Existing configurations (count >= 1) and existing pipe commands behave as before.
The adapter is re-initialized on every D0 entry (e.g. after sleep), which drops all monitors. Remember the last ATTACH/DETACH request and restore it in FinishInit, so an attached monitor comes back after resume and a detached one does not reappear. Without ATTACH/DETACH, <count> decides as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Applications that only need a virtual display for the length of a session — game-streaming hosts, apps that turn a
tablet or another device into a secondary monitor — currently have two options with VDD:
Display settings, it can be enabled again with Win+P ("Extend"), and windows can end up on a screen nobody is
looking at.
<count>and reinitialize the adapter (SETDISPLAYCOUNT/RELOAD_DRIVER) or disable/enable the device.That is heavier than plugging a monitor in, and
<count>0</count>is currently turned into 1, so "no monitor"cannot be expressed at all.
In #487 the Sunshine maintainers mentioned they are considering shipping VDD with Sunshine. The usual pattern for a
streaming host is "create the display when a client connects, remove it when the session ends", so this PR adds a
small, opt-in way to do exactly that.
Changes
<count>0</count>invdd_settings.xmlis now honoured: the driver starts with no monitor. The adapter stilldeclares
MaxMonitorsSupported = 1in that case so a monitor can be added later.ATTACH: if no monitor is attached, creates<count>monitors (one when<count>is 0) throughthe existing
CreateMonitorpath. Idempotent. RepliesATTACHEDorERROR.DETACH: callsIddCxMonitorDeparturefor every attached monitor. Idempotent. RepliesDETACHEDor
ERROR.IndirectDeviceContexttracks the monitors that have arrived (m_Monitors). A global pointer to the device contextis set in
FinishInitand cleared in the destructor, guarded by a mutex that also serializes ATTACH/DETACH withFinishInit. (The pipe thread has no WDF object to look the context up from.)<count>0</count>and the two commands.vdd_settings.xml: one comment line next to<count>; the default value stays1.ATTACH/DETACH do not re-read
vdd_settings.xml; they use the settings loaded at startup. Re-reading settings onATTACH (e.g. to pick up a client's resolution) could be a follow-up if wanted.
Backward compatibility
<count>>= 1 the same monitors are created at startup as before.<count>0</count>, which previously meant 1 monitor and nowmeans 0. The shipped
vdd_settings.xmluses 1.ATTACH/DETACHare new names; no existing pipe command is changed. Clients that do not send them see nodifference.
Notes for reviewers
CreateMonitor,FinishInitand the destructor, which Harden monitor lifetime and mode handling #514 (monitor lifetime) and Fix IddCx watchdog crashes in swap-chain assign/unassign #532 (swap-chainassign/unassign) also change. Happy to rebase on whichever lands first. With Harden monitor lifetime and mode handling #514,
m_Monitorscould move into theper-monitor context it introduces.
DETACHmakes IddCx callEvtIddCxMonitorUnassignSwapChain, so it goes through the same unassign path that Fix IddCx watchdog crashes in swap-chain assign/unassign #532hardens.
ATTACHED/DETACHEDreply (same as forother commands).
InitAdapterinEvtDeviceD0Entry), e.g. after sleep, whichdrops all monitors. The driver keeps the last
ATTACH/DETACHrequest andFinishInitrestores that state, so anattached monitor comes back after resume and a detached one does not reappear. Clients that never send
ATTACH/DETACHkeep the old<count>behaviour. The same applies afterRELOAD_DRIVER.ATTACHarrives before the adapter has finished initializing, the reply isERROR, but the request is stillremembered and applied when initialization finishes.
Testing
Built
MttVDD.vcxprojx64 Release locally (VS 2022, WDK 10.0.26100 NuGet packages, UMDF 2.35 headers). CI buildnot run yet.
Runtime test of this branch: not done yet. Suggested manual test:
<count>0</count>, restart the device. Display settings shows no virtual monitor; Win+P does not bring oneback.
ATTACH→ replyATTACHED, a monitor appears. SendATTACHagain →ATTACHED, no second monitor.DETACH→ replyDETACHED, the monitor disappears and windows move to the physical display. SendDETACHagain →
DETACHED.<count>1</count>(default): one monitor at startup as before;DETACHthenATTACHrestores it.Example client (PowerShell):