<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 15, 2016 at 6:10 PM, Frediano Ziglio <span dir="ltr"><<a href="mailto:fziglio@redhat.com" target="_blank">fziglio@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:"times new roman","new york",times,serif;font-size:12pt;color:rgb(0,0,0)"><div><div class="h5"><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 15, 2016 at 10:52 AM, Frediano Ziglio <span dir="ltr"><<a href="mailto:fziglio@redhat.com" target="_blank">fziglio@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>><br>
> The Direct3D 9 API operates on either the Windows XP display driver<br>
> model (XPDM) or the Windows Vista display driver model (WDDM), depending<br>
> on the operating system installed.<br>
><br>
> This patch implements the WDDM interface while using the CCD API to do<br>
> so. Moreover it introduces multiple monitors support and arbitrary<br>
> resolution for Windows 10 while preserving backward compatiblity with<br>
> previous<br>
> versions of Windows.<br>
><br>
> Based on a patch by Sandy Stutsman <<a href="mailto:sstutsma@redhat.com" target="_blank">sstutsma@redhat.com</a>><br>
><br>
> Signed-off-by: Dmitry Fleytman <<a href="mailto:dfleytma@redhat.com" target="_blank">dfleytma@redhat.com</a>><br>
> Signed-off-by: Sameeh Jubran <<a href="mailto:sameeh@daynix.com" target="_blank">sameeh@daynix.com</a>><br>
> ---<br>
>  vdagent/display_configuration.<wbr>cpp | 355<br>
>  ++++++++++++++++++++++++++++++<wbr>+++++++-<br>
>  vdagent/display_configuration.<wbr>h   |  47 +++++<br>
>  2 files changed, 401 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/vdagent/display_<wbr>configuration.cpp<br>
> b/vdagent/display_<wbr>configuration.cpp<br>
> index 5e40d05..4db093f 100755<br>
> --- a/vdagent/display_<wbr>configuration.cpp<br>
> +++ b/vdagent/display_<wbr>configuration.cpp<br>
> @@ -152,6 +152,54 @@ struct DISPLAYCONFIG_PATH_INFO {<br>
>      UINT32 flags;<br>
>  };<br>
><br>
> +<br>
> +enum D3DKMT_ESCAPETYPE {<br>
> +    D3DKMT_ESCAPE_DRIVERPRIVATE = 0<br>
> +};<br>
> +<br>
> +struct D3DDDI_ESCAPEFLAGS {<br>
> +    union {<br>
> +        struct {<br>
> +            UINT    Reserved : 31;<br>
> +        };<br>
> +        UINT        Value;<br>
> +    };<br>
> +};<br>
> +<br>
> +struct D3DKMT_ESCAPE {<br>
> +    D3D_HANDLE hAdapter;<br>
> +    D3D_HANDLE hDevice;<br>
> +    D3DKMT_ESCAPETYPE Type;<br>
> +    D3DDDI_ESCAPEFLAGS Flags;<br>
> +    VOID* pPrivateDriverData;<br>
> +    UINT PrivateDriverDataSize;<br>
> +    D3D_HANDLE hContext;<br>
> +};<br>
> +<br>
> +struct D3DKMT_OPENADAPTERFROMHDC {<br>
> +    HDC hDc;<br>
> +    D3D_HANDLE hAdapter;<br>
> +    LUID AdapterLuid;<br>
> +    UINT VidPnSourceId;<br>
> +};<br>
> +<br>
> +struct D3DKMT_CLOSEADAPTER {<br>
> +    D3D_HANDLE hAdapter;<br>
> +};<br>
> +<br>
> +struct D3DKMT_<wbr>OPENADAPTERFROMDEVICENAME {<br>
> +    const WCHAR *pDeviceName;<br>
> +    D3D_HANDLE hAdapter;<br>
> +    LUID AdapterLuid;<br>
> +};<br>
> +<br>
> +struct D3DKMT_<wbr>OPENADAPTERFROMGDIDISPLAYNAME {<br>
> +    WCHAR DeviceName[32];<br>
> +    D3D_HANDLE hAdapter;<br>
> +    LUID AdapterLuid;<br>
> +    UINT VidPnSourceId;<br>
> +};<br>
> +<br><br></div></div>Where these definition came from ?<br></blockquote><div>We have already discussed this in previous versions of the patches:</div><div><a href="https://mail.google.com/mail/u/0/#search/in%3Asent+from+scratch/15650fbeba9cfd30" target="_blank">https://mail.google.com/mail/<wbr>u/0/#search/in%3Asent+from+<wbr>scratch/15650fbeba9cfd30</a><br></div><div>We have written from scratch the ones that we didn't find here:</div><div><a href="https://github.com/notr1ch/DWMCapture/blob/master/DWMCaptureSource.cpp" target="_blank">https://github.com/notr1ch/<wbr>DWMCapture/blob/master/<wbr>DWMCaptureSource.cpp</a><br></div></div></div></div></blockquote></div></div><div><div>Just put a comment.</div><div>And the "written from scratch" does not make sense, it's an API and you cannot get these</div><div>information from nothing, you need to know the protocol.</div></div><div><div class="h5"><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br>
>  struct QXLMonitorEscape {<br>
>      QXLMonitorEscape(DEVMODE* dev_mode)<br>
>      {<br>
> @@ -174,10 +222,43 @@ struct QxlCustomEscapeObj : public<br>
> QXLEscapeSetCustomDisplay {<br>
>      QxlCustomEscapeObj() {};<br>
>  };<br>
><br>
> +struct WDDMCustomDisplayEscape {<br>
> +    WDDMCustomDisplayEscape(<wbr>DEVMODE* dev_mode)<br>
> +    {<br>
> +        _ioctl = QXL_ESCAPE_SET_CUSTOM_DISPLAY;<br>
> +        _custom.bpp  = dev_mode->dmBitsPerPel;<br>
> +        _custom.xres = dev_mode->dmPelsWidth;<br>
> +        _custom.yres = dev_mode->dmPelsHeight;<br>
> +    }<br>
> +    int                         _ioctl;<br>
> +    QXLEscapeSetCustomDisplay   _custom;<br>
> +};<br>
> +<br>
> +struct WDDMMonitorConfigEscape {<br>
> +    WDDMMonitorConfigEscape(<wbr>DisplayMode* mode)<br>
> +    {<br>
> +        _ioctl = QXL_ESCAPE_MONITOR_CONFIG;<br>
> +        _<a href="http://head.id" rel="noreferrer" target="_blank">head.id</a> = _head.surface_id = 0;<br>
> +        _head.x = mode->get_pos_x();<br>
> +        _head.y = mode->get_pos_y();<br>
> +        _head.width = mode->get_width();<br>
> +        _head.height = mode->get_height();<br>
> +    }<br>
> +    int         _ioctl;<br>
> +    QXLHead     _head;<br>
> +};<br>
> +<br>
>  DisplayConfig* DisplayConfig::create_config()<br>
>  {<br>
>      DisplayConfig* new_interface;<br>
> -    new_interface = new XPDMInterface();<br>
> +    /* Try to open a WDDM adapter.<br>
> +    If that failed, assume we have an XPDM driver */<br>
> +    try {<br>
> +        new_interface = new  WDDMInterface();<br>
> +    }<br>
> +    catch (std::exception& e) {<br>
> +        new_interface = new XPDMInterface();<br>
> +    }<br>
>      return new_interface;<br>
>  }<br>
><br>
> @@ -326,6 +407,278 @@ bool XPDMInterface::find_best_mode(<wbr>LPCTSTR Device,<br>
> DEVMODE* dev_mode)<br>
>      return NT_SUCCESS(status);<br>
>  }<br>
><br>
> +WDDMInterface::WDDMInterface(<wbr>)<br>
> +    : _pfnOpen_adapter_hdc(NULL)<br>
> +    , _pfnClose_adapter(NULL)<br>
> +    , _pfnEscape(NULL)<br>
> +    , _pfnOpen_adapter_device_name(<wbr>NULL)<br>
> +    , _pfnOpen_adapter_gdi_name(<wbr>NULL)<br>
> +{<br>
> +    LONG error(0);<br>
> +    //Can we find the D3D calls we need?<br>
> +    if (!init_d3d_api()) {<br>
> +        throw std::exception();<br>
> +    }<br>
> +<br>
> +    //Initialize  CCD path stuff<br>
> +    if (!_ccd.query_display_config()) {<br>
> +        throw std::exception();<br>
> +    }<br>
> +<br>
> +    if (!_ccd.set_display_config(<wbr>error)) {<br>
> +        throw std::exception();<br>
> +    }<br>
> +}<br>
> +<br>
> +bool WDDMInterface::is_attached(<wbr>DISPLAY_DEVICE* dev_info)<br>
> +{<br>
> +    return _ccd.is_attached(dev_info-><wbr>DeviceName);<br>
> +}<br>
> +<br>
> +bool WDDMInterface::set_monitor_<wbr>state(LPCTSTR device_name, DEVMODE*<br>
> dev_mode, MONITOR_STATE state)<br>
> +{<br>
> +   return  _ccd.set_path_state(device_<wbr>name, state);<br>
> +}<br>
> +<br>
> +bool WDDMInterface::custom_display_<wbr>escape(LPCTSTR device_name, DEVMODE*<br>
> dev_mode)<br>
> +{<br>
> +    DISPLAYCONFIG_MODE_INFO* mode = _ccd.get_active_mode(device_<wbr>name,<br>
> false);<br>
> +    if (!mode) {<br>
> +        return false;<br>
> +    }<br>
> +<br>
> +    //Don't bother if we are already set to the new resolution<br>
> +    if (mode->sourceMode.width == dev_mode->dmPelsWidth &&<br>
> +        mode->sourceMode.height == dev_mode->dmPelsHeight) {<br>
> +        return true;<br>
> +    }<br>
> +<br>
> +    vd_printf("%s: updating %S resolution\n", __FUNCTION__, device_name);<br>
> +<br>
> +    WDDMCustomDisplayEscape wddm_escape(dev_mode);<br>
> +    if (escape(device_name, &wddm_escape, sizeof(wddm_escape))) {<br><br></div></div>This is not portable,  not even between 32 and 64 bit.<br></blockquote><div><br></div><div>Can you please further explain why? </div></div></div></div></blockquote><div><br></div></div></div><div><div>You are sending to the driver a structure that you defined here.</div><div>Usually there is an header that both include which is used to make sure you are</div><div>using the same structure layout. Also you have to define the structure in order (on a</div><div>system that can have 32/64 bit mixed) avoid bit size problems.</div><div><br></div><div>Now you send two structure which are</div><div><br></div><div>struct Xxx {</div><div>   int ioctl;</div><div>   shared_defined_structure ioctl_data;</div><div>};</div><div><br></div><div>depending on shared_defined_structure alignment the structure layout between 32 and 64</div><div>can potentially change. You are lucky and the 2 structure have the same alignment</div><div>on both sizes (QXLHead and QXLEscapeSetCustomDisplay are packed so</div><div>aligned to 4 bytes) and the alignment is compatible with int.<br>So now works but it's not hard to break this adding a new escape ioctl that does not</div><div>follow these rules. So what's the rule? A packed structure after an int?</div><div>Potentially this will cause the protocol to have unaligned accesses if a field should</div><div>be 8-byte aligned (for instance a pointer/handle). Intel architecture have just some speed</div><div>penalty but if you define the protocol differently you can avoid this penalty.</div><div>If you look at ioctl structures rarely they are packet for this reason.</div></div></div></div></blockquote><div>The size of int is defined as 4 bytes on windows, however I think it would be better to change it to uint32_t. There seem</div><div>to be no alignment issue inside the current structures, all of the members are "uint32_t". Moving The structure to</div><div>"spice-protocol\spice\qxl-windows.h" would be a better approach?</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:"times new roman","new york",times,serif;font-size:12pt;color:rgb(0,0,0)"><div><div><br></div></div><div><div class="h5"><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span><br>
> +        return _ccd.update_mode_size(device_<wbr>name, dev_mode);<br>
> +    }<br>
> +<br>
> +    vd_printf("%s: (%dx%d)", __FUNCTION__, mode->sourceMode.width,<br>
> mode->sourceMode.height);<br>
> +    return false;<br>
> +}<br>
> +<br>
> +bool WDDMInterface::update_monitor_<wbr>config(LPCTSTR device_name, DisplayMode*<br>
> display_mode,<br>
> +                                           DEVMODE* dev_mode)<br>
> +{<br>
> +    if (!display_mode || !display_mode->get_attached()) {<br>
> +        return false;<br>
> +    }<br>
> +    DISPLAYCONFIG_MODE_INFO* mode = _ccd.get_active_mode(device_<wbr>name,<br>
> false);<br>
> +    if (!mode || !_send_monitors_config)<br>
> +        return false;<br>
> +<br>
> +    WDDMMonitorConfigEscape wddm_escape(display_mode);<br>
> +    if (escape(device_name, &wddm_escape, sizeof(wddm_escape))) {<br>
<br>
</span>Same as above. It's not clear who is receiving these escape commands...<br>
the driver?<br></blockquote><div>Yes the driver is receiving those escape commands.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br>
> +        //Update the path position<br>
> +        return _ccd.update_mode_position(<wbr>device_name, dev_mode);<br>
> +    }<br>
> +<br>
> +    vd_printf("%s: %S failed", __FUNCTION__, device_name);<br>
> +    return false;<br>
> +<br>
> +}<br>
> +<br>
> +LONG WDDMInterface::update_display_<wbr>settings()<br>
> +{<br>
> +    LONG error(0);<br>
> +    //If we removed the primary monitor since the last call, we need to<br>
> +    //reorder the other monitors, making the leftmost one the primary<br>
> +    _ccd.verify_primary_position()<wbr>;<br>
> +    _ccd.set_display_config(error)<wbr>;<br>
> +    return error;<br>
> +}<br>
> +<br>
> +void WDDMInterface::update_config_<wbr>path()<br>
> +{<br>
> +    _ccd.query_display_config();<br>
> +}<br>
> +<br>
> +bool WDDMInterface::update_dev_<wbr>mode_position(LPCTSTR device_name, DEVMODE*<br>
> dev_mode,<br>
> +                                             LONG x, LONG y)<br>
> +{<br>
> +    //Convert the position so that the primary is always at (0,0)<br><br></div></div>This comment does not make any sense here.<br><div><div><br>
> +    dev_mode->dmPosition.x = x;<br>
> +    dev_mode->dmPosition.y = y;<br>
> +    return _ccd.update_mode_position(<wbr>device_name, dev_mode);<br>
> +}<br>
> +<br>
> +bool WDDMInterface::init_d3d_api()<br>
> +{<br>
> +    HMODULE hModule = LoadLibrary(L"gdi32.dll");<br>
> +<br>
> +    //Look for the gdi32 functions we need to perform driver escapes<br>
> +    if (!hModule) {<br>
> +        vd_printf("%s something wildly wrong as we can't open gdi32.dll",<br>
> __FUNCTION__);<br>
> +        return false;<br>
> +    }<br>
> +<br>
> +    do {<br>
> +        _pfnClose_adapter = (PFND3DKMT_CLOSEADAPTER)<br>
> +            GetProcAddress(hModule, "D3DKMTCloseAdapter");<br>
> +        if (!_pfnClose_adapter) {<br>
> +            break;<br>
> +        }<br>
> +<br>
> +        _pfnEscape = (PFND3DKMT_ESCAPE) GetProcAddress(hModule,<br>
> "D3DKMTEscape");<br>
> +        if (!_pfnEscape) {<br>
> +            break;<br>
> +        }<br>
> +<br>
> +        _pfnOpen_adapter_hdc = (PFND3DKMT_OPENADAPTERFROMHDC)<br>
> +            GetProcAddress(hModule, "D3DKMTOpenAdapterFromHdc");<br>
> +        if (!_pfnOpen_adapter_hdc) {<br>
> +            break;<br>
> +        }<br>
> +<br>
> +        _pfnOpen_adapter_device_name = (PFND3DKMT_<wbr>OPENADAPTERFROMDEVICENAME)<br>
> +            GetProcAddress(hModule, "<wbr>D3DKMTOpenAdapterFromDeviceNam<wbr>e");<br>
> +        if (!_pfnOpen_adapter_device_<wbr>name) {<br>
> +            break;<br>
> +        }<br>
> +<br>
> +        _pfnOpen_adapter_gdi_name =<br>
> (PFND3DKMT_<wbr>OPENADAPTERFROMGDIDISPLAYNAME)<br>
> +            GetProcAddress(hModule, "<wbr>D3DKMTOpenAdapterFromGdiDispla<wbr>yName");<br>
> +        if (!_pfnOpen_adapter_gdi_name) {<br>
> +            break;<br>
> +        }<br>
> +<br>
> +    }<br>
> +    while(0);<br>
> +<br>
> +    FreeLibrary(hModule);<br>
> +<br><br></div></div>If the library was loaded the program is going to crash as the function<br>
will disappear from memory.<br></blockquote><div><br></div><div>I'll use GetModuleHandle instead.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span><br>
> +    //Did we get them ?<br>
> +    if (!_pfnClose_adapter || !_pfnOpen_adapter_hdc || !_pfnEscape)  {<br>
> +        return false;<br>
> +    }<br>
> +    return true;<br>
> +}<br>
> +<br>
> +D3D_HANDLE WDDMInterface::adapter_handle(<wbr>LPCTSTR device_name)<br>
> +{<br>
> +    D3D_HANDLE hAdapter(0);<br>
> +<br>
> +    //For some reason, unknown to me, this call will occasionally fail.<br>
<br>
</span>Who is the "me" here? Would be better to make it explicit.<br><div><div><br>
> +    if ((hAdapter = handle_from_DC(device_name))) {<br>
> +        return hAdapter;<br>
> +    }<br>
> +        //So try other available methods.<br>
> +    if (_pfnOpen_adapter_device_name && (hAdapter =<br>
> handle_from_device_name(<wbr>device_name))) {<br>
> +        return hAdapter;<br>
> +    }<br>
> +    //One last chance to open this guy<br>
> +    if (_pfnOpen_adapter_gdi_name) {<br>
> +        hAdapter = handle_from_GDI_name(device_<wbr>name);<br>
> +    }<br>
> +<br>
> +    if (!hAdapter) {<br>
> +        vd_printf("%s: failed to open adapter %S", __FUNCTION__,<br>
> device_name);<br>
> +    }<br>
> +<br>
> +    return hAdapter;<br>
> +}<br>
> +<br>
> +D3D_HANDLE WDDMInterface::handle_from_DC(<wbr>LPCTSTR adapter_name)<br>
> +{<br>
> +    NTSTATUS status;<br>
> +    D3DKMT_OPENADAPTERFROMHDC open_data;<br>
> +    HDC hDc(CreateDC(adapter_name, NULL, NULL, NULL));<br>
> +<br>
> +    if (!hDc) {<br>
> +        vd_printf("%s: %S CreateDC failed with %lu", __FUNCTION__,<br>
> adapter_name, GetLastError());<br>
> +        return 0;<br>
> +    }<br>
> +<br>
> +    ZeroMemory(&open_data, sizeof(D3DKMT_<wbr>OPENADAPTERFROMHDC));<br>
> +    open_data.hDc = hDc;<br>
> +<br>
> +    if (!NT_SUCCESS(status = _pfnOpen_adapter_hdc(&open_<wbr>data))) {<br>
> +        vd_printf("%s: %S open adapter from hdc failed with %lu",<br>
> __FUNCTION__, adapter_name,<br>
> +            status);<br>
> +        open_data.hAdapter = 0;<br>
> +    }<br>
> +<br>
> +    DeleteDC(hDc);<br>
> +    return open_data.hAdapter;<br>
> +}<br>
> +<br>
> +D3D_HANDLE WDDMInterface::handle_from_<wbr>device_name(LPCTSTR adapter_name)<br>
> +{<br>
> +    D3DKMT_<wbr>OPENADAPTERFROMDEVICENAME display_name_data;<br>
> +    NTSTATUS  status;<br>
> +<br>
> +    ZeroMemory(&display_name_data, sizeof(display_name_data));<br>
> +    display_name_data.pDeviceName = adapter_name;<br>
> +<br>
> +    if (NT_SUCCESS(status =<br>
> _pfnOpen_adapter_device_name(&<wbr>display_name_data))) {<br>
> +        return display_name_data.hAdapter;<br>
> +    }<br>
> +<br>
> +    vd_printf("%s %S failed with 0x%lx", __FUNCTION__, adapter_name,<br>
> status);<br>
> +    return 0;<br>
> +}<br>
> +<br>
> +D3D_HANDLE WDDMInterface::handle_from_<wbr>GDI_name(LPCTSTR adapter_name)<br>
> +{<br>
> +    D3DKMT_<wbr>OPENADAPTERFROMGDIDISPLAYNAME gdi_display_name;<br>
> +    NTSTATUS status;<br>
> +<br>
> +    ZeroMemory(&gdi_display_name, sizeof(gdi_display_name));<br>
> +    memcpy((void *) gdi_display_name.DeviceName, adapter_name,<br>
> sizeof(TCHAR)* CCHDEVICENAME);<br>
> +<br><br></div></div>This assume adapter_name is into a buffer of CCHDEVICENAME characters so<br>
can in theory overflow. As the destination buffer is already 0 filled<br>
would be better a strncpy style function. The void * conversion is useless<br>
and misleading.</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br>
> +    if (NT_SUCCESS(status = _pfnOpen_adapter_gdi_name(&<wbr>gdi_display_name))) {<br>
> +        return  gdi_display_name.hAdapter;<br>
> +    }<br>
> +<br>
> +    vd_printf("%s: %S aurrrgghh nothing works..error  is 0x%lx",<br>
> __FUNCTION__, adapter_name,<br>
> +            status);<br>
> +    return 0;<br>
> +}<br>
> +<br>
> +void WDDMInterface::close_adapter(<wbr>D3D_HANDLE handle)<br>
> +{<br>
> +    D3DKMT_CLOSEADAPTER closeData;<br>
> +    if (handle) {<br>
> +        closeData.hAdapter = handle;<br>
> +        _pfnClose_adapter(&closeData);<br>
> +    }<br>
> +}<br>
> +<br>
> +bool WDDMInterface::escape(LPCTSTR device_name, void* data, UINT size_data)<br>
> +{<br>
> +    D3DKMT_ESCAPE   escapeData;<br>
> +    NTSTATUS        status;<br>
> +    D3D_HANDLE   hAdapter(0);<br>
> +<br>
> +    if (!(hAdapter = adapter_handle(device_name)))<br>
> +        return false;<br>
> +<br>
> +    escapeData.hAdapter = hAdapter;<br>
> +    escapeData.hDevice = 0;<br>
> +    escapeData.hContext = 0;<br>
> +    escapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;<br>
> +    escapeData.Flags.Value = 0;<br>
> +    escapeData.pPrivateDriverData = data;<br>
> +    escapeData.<wbr>PrivateDriverDataSize = size_data;<br>
> +<br>
> +    status = _pfnEscape(&escapeData);<br>
> +<br>
> +    if (!NT_SUCCESS(status)) {<br>
> +        vd_printf("%s: this should never happen. Status is 0x%lx",<br>
> __FUNCTION__, status);<br>
> +    }<br>
> +<br>
> +    //Close the handle to this device<br>
> +    close_adapter(hAdapter);<br>
> +    return NT_SUCCESS(status);<br>
> +}<br>
> +<br>
>  CCD::CCD()<br>
>      :_numPathElements(0)<br>
>      ,_numModeElements(0)<br>
> diff --git a/vdagent/display_<wbr>configuration.h<br>
> b/vdagent/display_<wbr>configuration.h<br>
> index 05b35f4..e5ee90d 100755<br>
> --- a/vdagent/display_<wbr>configuration.h<br>
> +++ b/vdagent/display_<wbr>configuration.h<br>
> @@ -125,4 +125,51 @@ private:<br>
>      bool find_best_mode(LPCTSTR Device, DEVMODE* dev_mode);<br>
>  };<br>
><br>
> +//DisplayConfig implementation for guest with WDDM graphics drivers<br>
> +typedef UINT D3D_HANDLE;<br>
> +<br>
> +struct D3DKMT_ESCAPE;<br>
> +struct D3DKMT_<wbr>OPENADAPTERFROMGDIDISPLAYNAME;<br>
> +struct D3DKMT_<wbr>OPENADAPTERFROMDEVICENAME;<br>
> +struct D3DKMT_CLOSEADAPTER;<br>
> +struct D3DKMT_OPENADAPTERFROMHDC;<br>
> +<br>
> +typedef NTSTATUS(APIENTRY* PFND3DKMT_ESCAPE)(CONST D3DKMT_ESCAPE*);<br>
> +typedef NTSTATUS(APIENTRY*<br>
> PFND3DKMT_<wbr>OPENADAPTERFROMGDIDISPLAYNAME)<wbr>(D3DKMT_<wbr>OPENADAPTERFROMGDIDISPLAYNAME*<wbr>);<br>
> +typedef NTSTATUS(APIENTRY*<br>
> PFND3DKMT_<wbr>OPENADAPTERFROMDEVICENAME)(<wbr>D3DKMT_<wbr>OPENADAPTERFROMDEVICENAME*);<br>
> +typedef NTSTATUS(APIENTRY* PFND3DKMT_CLOSEADAPTER)(<wbr>D3DKMT_CLOSEADAPTER*);<br>
> +typedef NTSTATUS(APIENTRY*<br>
> PFND3DKMT_OPENADAPTERFROMHDC)(<wbr>D3DKMT_OPENADAPTERFROMHDC*);<br>
> +<br>
> +class WDDMInterface : public DisplayConfig {<br>
> +public:<br>
> +    WDDMInterface();<br>
> +    bool is_attached(DISPLAY_DEVICE* dev_info);<br>
> +    bool set_monitor_state(LPCTSTR device_name, DEVMODE* dev_mode,<br>
> MONITOR_STATE state);<br>
> +    LONG update_display_settings();<br>
> +    bool custom_display_escape(LPCTSTR device_name, DEVMODE* dev_mode);<br>
> +    bool update_monitor_config(LPCTSTR device_name, DisplayMode* mode,<br>
> DEVMODE* dev_mode);<br>
> +    bool update_dev_mode_position(<wbr>LPCTSTR device_name, DEVMODE * dev_mode,<br>
> LONG x, LONG y);<br>
> +    void update_config_path();<br>
> +<br>
> +private:<br>
> +    bool init_d3d_api();<br>
> +    D3D_HANDLE adapter_handle(LPCTSTR device_name);<br>
> +    D3D_HANDLE handle_from_DC(LPCTSTR adapter_name);<br>
> +    D3D_HANDLE handle_from_device_name(<wbr>LPCTSTR adapter_name);<br>
> +    D3D_HANDLE handle_from_GDI_name(LPCTSTR adapter_name);<br>
> +<br>
> +    void close_adapter(D3D_HANDLE handle);<br>
> +    bool escape(LPCTSTR device_name, void* data, UINT sizeData);<br>
> +<br>
> +    //GDI Function pointers<br>
> +    PFND3DKMT_OPENADAPTERFROMHDC _pfnOpen_adapter_hdc;<br>
> +    PFND3DKMT_CLOSEADAPTER  _pfnClose_adapter;<br>
> +    PFND3DKMT_ESCAPE _pfnEscape;<br>
> +    PFND3DKMT_<wbr>OPENADAPTERFROMDEVICENAME _pfnOpen_adapter_device_name;<br>
> +    PFND3DKMT_<wbr>OPENADAPTERFROMGDIDISPLAYNAME _pfnOpen_adapter_gdi_name;<br>
> +<br>
> +    //object handles the CCD API<br>
> +    CCD _ccd;<br>
> +};<br>
> +<br>
>  #endif<br>
> \ No newline at end of file<br><br></div></div>The update_ prefix is confusing. I would personally use set/get/query/read/write.<br>
The reason is that is not clear if they are updating a class internal state (so<br>
reading from the device) or updating the device state or a mix of the two.<br></blockquote></div></div></div></blockquote><div><br>Frediano</div><div><br></div></div></div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font size="4" color="#0b5394" face="times new roman, serif">Respectfully,<br></font><div style="font-size:12.8px;color:rgb(136,136,136)"><font size="4" color="#0b5394" face="times new roman, serif"><b><i>Sameeh Jubran</i></b></font></div><div style="font-size:12.8px;color:rgb(136,136,136)"><i style="color:rgb(7,55,99);font-family:"times new roman",serif;font-size:large"><span style="line-height:15px"><a href="https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a" title="View public profile" name="UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_UNIQUE_ID_SafeHtmlFilter_14e2c1de96f8c195_UNIQUE_ID_SafeHtmlFilter_SafeHtmlFilter_SafeHtmlFilter_webProfileURL" style="color:rgb(17,85,204);margin:0px;padding:0px;border-width:0px;outline:none;vertical-align:baseline;text-decoration:none" target="_blank">Linkedin</a></span></i><br></div><div style="font-size:12.8px;color:rgb(136,136,136)"><font size="4" face="times new roman, serif" color="#073763"><i>Junior Software Engineer @ <a href="http://www.daynix.com" target="_blank">Daynix</a>.</i></font></div></div></div></div></div></div></div>
</div></div>