Re: [Spice-devel] [PATCH v9 1/2] Modifying ioctl structures

2016-08-16 Thread Sameeh Jubran
On Tue, Aug 16, 2016 at 7:10 PM, Frediano Ziglio  wrote:

> >
> > This patch modifies the Qxl ioctl structures in order
> > to make them unified. Ioctls now should inherit QXL_ESCAPE
> > structure.
> >
> > Signed-off-by: Sameeh Jubran 
>
> Yes, but doing so with a XDDM driver will fail.
> ExtEscape ABI should remain the same.
> The structure with the code was done as D3D APIs does not take
> a constant but just a raw buffer so the new structures should
> be used just with D3DKMTEscape.
>
Then the second patch can be applied alone, this patch is not needed, I'll
resend the second patch.

>
> Frediano
>
> > ---
> >  vdagent/display_configuration.cpp | 28 ++--
> >  1 file changed, 14 insertions(+), 14 deletions(-)
> >
> > diff --git a/vdagent/display_configuration.cpp
> > b/vdagent/display_configuration.cpp
> > index 01fdbb0..cdbe5e8 100644
> > --- a/vdagent/display_configuration.cpp
> > +++ b/vdagent/display_configuration.cpp
> > @@ -153,26 +153,26 @@ struct DISPLAYCONFIG_PATH_INFO {
> >  UINT32 flags;
> >  };
> >
> > -struct QXLMonitorEscape {
> > +struct QXLMonitorEscape : QXL_ESCAPE {
> >  QXLMonitorEscape(DEVMODE* dev_mode)
> >  {
> > -ZeroMemory(&_head, sizeof(_head));
> > -_head.x = dev_mode->dmPosition.x;
> > -_head.y = dev_mode->dmPosition.y;
> > -_head.width = dev_mode->dmPelsWidth;
> > -_head.height = dev_mode->dmPelsHeight;
> > +ZeroMemory(&monitor_config, sizeof(monitor_config));
> > +ioctl = QXL_ESCAPE_MONITOR_CONFIG;
> > +monitor_config.x = dev_mode->dmPosition.x;
> > +monitor_config.y = dev_mode->dmPosition.y;
> > +monitor_config.width = dev_mode->dmPelsWidth;
> > +monitor_config.height = dev_mode->dmPelsHeight;
> >  }
> > -QXLHead _head;
> >  };
> >
> > -struct QxlCustomEscapeObj : public QXLEscapeSetCustomDisplay {
> > +struct QxlCustomEscapeObj : public QXL_ESCAPE {
> >  QxlCustomEscapeObj(uint32_t bitsPerPel, uint32_t width, uint32_t
> height)
> >  {
> > -xres = width;
> > -yres = height;
> > -bpp = bitsPerPel;
> > +ioctl = QXL_ESCAPE_SET_CUSTOM_DISPLAY;
> > +custom_display.xres = width;
> > +custom_display.yres = height;
> > +custom_display.bpp = bitsPerPel;
> >  }
> > -QxlCustomEscapeObj() {};
> >  };
> >
> >  DisplayConfig* DisplayConfig::create_config()
> > @@ -252,7 +252,7 @@ bool XPDMInterface::custom_display_escape(LPCTSTR
> > device_name, DEVMODE* dev_mode
> >  dev_mode->dmPelsWidth,
> >  dev_mode->dmPelsHeight);
> >
> >  int err = ExtEscape(hdc, QXL_ESCAPE_SET_CUSTOM_DISPLAY,
> > -  sizeof(QXLEscapeSetCustomDisplay), (LPCSTR)
> &custom_escape, 0,
> > NULL);
> > +  sizeof(QxlCustomEscapeObj), (LPCSTR) &custom_escape, 0,
> NULL);
> >  if (err <= 0) {
> >  vd_printf("%s: Can't set custom display, perhaps running with an
> >  older driver?",
> >  __FUNCTION__);
> > @@ -281,7 +281,7 @@ bool XPDMInterface::update_monitor_config(LPCTSTR
> > device_name, DisplayMode* mode
> >  return false;
> >  }
> >
> > -err = ExtEscape(hdc, QXL_ESCAPE_MONITOR_CONFIG, sizeof(QXLHead),
> > +err = ExtEscape(hdc, QXL_ESCAPE_MONITOR_CONFIG,
> > sizeof(QXLMonitorEscape),
> >  (LPCSTR) &monitor_config, 0, NULL);
> >  if (err < 0) {
> >  vd_printf("%s: %S can't update monitor config, may have old, old
> >  driver",
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin *
*Junior Software Engineer @ Daynix .*
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH v9 1/2] Modifying ioctl structures

2016-08-16 Thread Frediano Ziglio
> 
> This patch modifies the Qxl ioctl structures in order
> to make them unified. Ioctls now should inherit QXL_ESCAPE
> structure.
> 
> Signed-off-by: Sameeh Jubran 

Yes, but doing so with a XDDM driver will fail.
ExtEscape ABI should remain the same.
The structure with the code was done as D3D APIs does not take
a constant but just a raw buffer so the new structures should
be used just with D3DKMTEscape.

Frediano

> ---
>  vdagent/display_configuration.cpp | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/vdagent/display_configuration.cpp
> b/vdagent/display_configuration.cpp
> index 01fdbb0..cdbe5e8 100644
> --- a/vdagent/display_configuration.cpp
> +++ b/vdagent/display_configuration.cpp
> @@ -153,26 +153,26 @@ struct DISPLAYCONFIG_PATH_INFO {
>  UINT32 flags;
>  };
>  
> -struct QXLMonitorEscape {
> +struct QXLMonitorEscape : QXL_ESCAPE {
>  QXLMonitorEscape(DEVMODE* dev_mode)
>  {
> -ZeroMemory(&_head, sizeof(_head));
> -_head.x = dev_mode->dmPosition.x;
> -_head.y = dev_mode->dmPosition.y;
> -_head.width = dev_mode->dmPelsWidth;
> -_head.height = dev_mode->dmPelsHeight;
> +ZeroMemory(&monitor_config, sizeof(monitor_config));
> +ioctl = QXL_ESCAPE_MONITOR_CONFIG;
> +monitor_config.x = dev_mode->dmPosition.x;
> +monitor_config.y = dev_mode->dmPosition.y;
> +monitor_config.width = dev_mode->dmPelsWidth;
> +monitor_config.height = dev_mode->dmPelsHeight;
>  }
> -QXLHead _head;
>  };
>  
> -struct QxlCustomEscapeObj : public QXLEscapeSetCustomDisplay {
> +struct QxlCustomEscapeObj : public QXL_ESCAPE {
>  QxlCustomEscapeObj(uint32_t bitsPerPel, uint32_t width, uint32_t height)
>  {
> -xres = width;
> -yres = height;
> -bpp = bitsPerPel;
> +ioctl = QXL_ESCAPE_SET_CUSTOM_DISPLAY;
> +custom_display.xres = width;
> +custom_display.yres = height;
> +custom_display.bpp = bitsPerPel;
>  }
> -QxlCustomEscapeObj() {};
>  };
>  
>  DisplayConfig* DisplayConfig::create_config()
> @@ -252,7 +252,7 @@ bool XPDMInterface::custom_display_escape(LPCTSTR
> device_name, DEVMODE* dev_mode
>  dev_mode->dmPelsWidth,
>  dev_mode->dmPelsHeight);
>  
>  int err = ExtEscape(hdc, QXL_ESCAPE_SET_CUSTOM_DISPLAY,
> -  sizeof(QXLEscapeSetCustomDisplay), (LPCSTR) &custom_escape, 0,
> NULL);
> +  sizeof(QxlCustomEscapeObj), (LPCSTR) &custom_escape, 0, NULL);
>  if (err <= 0) {
>  vd_printf("%s: Can't set custom display, perhaps running with an
>  older driver?",
>  __FUNCTION__);
> @@ -281,7 +281,7 @@ bool XPDMInterface::update_monitor_config(LPCTSTR
> device_name, DisplayMode* mode
>  return false;
>  }
>  
> -err = ExtEscape(hdc, QXL_ESCAPE_MONITOR_CONFIG, sizeof(QXLHead),
> +err = ExtEscape(hdc, QXL_ESCAPE_MONITOR_CONFIG,
> sizeof(QXLMonitorEscape),
>  (LPCSTR) &monitor_config, 0, NULL);
>  if (err < 0) {
>  vd_printf("%s: %S can't update monitor config, may have old, old
>  driver",

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH v9 1/2] Modifying ioctl structures

2016-08-16 Thread Sameeh Jubran
This patch modifies the Qxl ioctl structures in order
to make them unified. Ioctls now should inherit QXL_ESCAPE
structure.

Signed-off-by: Sameeh Jubran 
---
 vdagent/display_configuration.cpp | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/vdagent/display_configuration.cpp 
b/vdagent/display_configuration.cpp
index 01fdbb0..cdbe5e8 100644
--- a/vdagent/display_configuration.cpp
+++ b/vdagent/display_configuration.cpp
@@ -153,26 +153,26 @@ struct DISPLAYCONFIG_PATH_INFO {
 UINT32 flags;
 };
 
-struct QXLMonitorEscape {
+struct QXLMonitorEscape : QXL_ESCAPE {
 QXLMonitorEscape(DEVMODE* dev_mode)
 {
-ZeroMemory(&_head, sizeof(_head));
-_head.x = dev_mode->dmPosition.x;
-_head.y = dev_mode->dmPosition.y;
-_head.width = dev_mode->dmPelsWidth;
-_head.height = dev_mode->dmPelsHeight;
+ZeroMemory(&monitor_config, sizeof(monitor_config));
+ioctl = QXL_ESCAPE_MONITOR_CONFIG;
+monitor_config.x = dev_mode->dmPosition.x;
+monitor_config.y = dev_mode->dmPosition.y;
+monitor_config.width = dev_mode->dmPelsWidth;
+monitor_config.height = dev_mode->dmPelsHeight;
 }
-QXLHead _head;
 };
 
-struct QxlCustomEscapeObj : public QXLEscapeSetCustomDisplay {
+struct QxlCustomEscapeObj : public QXL_ESCAPE {
 QxlCustomEscapeObj(uint32_t bitsPerPel, uint32_t width, uint32_t height)
 {
-xres = width;
-yres = height;
-bpp = bitsPerPel;
+ioctl = QXL_ESCAPE_SET_CUSTOM_DISPLAY;
+custom_display.xres = width;
+custom_display.yres = height;
+custom_display.bpp = bitsPerPel;
 }
-QxlCustomEscapeObj() {};
 };
 
 DisplayConfig* DisplayConfig::create_config()
@@ -252,7 +252,7 @@ bool XPDMInterface::custom_display_escape(LPCTSTR 
device_name, DEVMODE* dev_mode
 dev_mode->dmPelsWidth, 
dev_mode->dmPelsHeight);
 
 int err = ExtEscape(hdc, QXL_ESCAPE_SET_CUSTOM_DISPLAY,
-  sizeof(QXLEscapeSetCustomDisplay), (LPCSTR) &custom_escape, 0, 
NULL);
+  sizeof(QxlCustomEscapeObj), (LPCSTR) &custom_escape, 0, NULL);
 if (err <= 0) {
 vd_printf("%s: Can't set custom display, perhaps running with an older 
driver?",
 __FUNCTION__);
@@ -281,7 +281,7 @@ bool XPDMInterface::update_monitor_config(LPCTSTR 
device_name, DisplayMode* mode
 return false;
 }
 
-err = ExtEscape(hdc, QXL_ESCAPE_MONITOR_CONFIG, sizeof(QXLHead),
+err = ExtEscape(hdc, QXL_ESCAPE_MONITOR_CONFIG, sizeof(QXLMonitorEscape),
 (LPCSTR) &monitor_config, 0, NULL);
 if (err < 0) {
 vd_printf("%s: %S can't update monitor config, may have old, old 
driver",
-- 
2.7.4

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH v9 0/2] Adding multiple monitors and arbitrary resolution for Windows 10

2016-08-16 Thread Sameeh Jubran
Diffrences from previous patch:
* Rebased on master.

Tested on both Windows 10 and XP and seems to be working great. I've
modified the driver accordingly, I'll send the driver patches soon.
Those patches require the following patch to be applied first to
spice-protocol:
https://lists.freedesktop.org/archives/spice-devel/2016-August/031409.html

Sameeh Jubran (2):
  Modifying ioctl structures
  Implementing WDDM interface to support multiple monitors and arbitrary
resolution

 vdagent/display_configuration.cpp | 379 --
 vdagent/display_configuration.h   |  47 +
 2 files changed, 411 insertions(+), 15 deletions(-)

-- 
2.7.4

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH v9 2/2] Implementing WDDM interface to support multiple monitors and arbitrary resolution

2016-08-16 Thread Sameeh Jubran
The Direct3D 9 API operates on either the Windows XP display driver
model (XPDM) or the Windows Vista display driver model (WDDM), depending
on the operating system installed.

This patch implements the WDDM interface while using the CCD API to do
so. Moreover it introduces multiple monitors support and arbitrary
resolution for Windows 10 while preserving backward compatiblity with
previous versions of Windows.

Signed-off-by: Sameeh Jubran 
---
 vdagent/display_configuration.cpp | 351 +-
 vdagent/display_configuration.h   |  47 +
 2 files changed, 397 insertions(+), 1 deletion(-)

diff --git a/vdagent/display_configuration.cpp 
b/vdagent/display_configuration.cpp
index cdbe5e8..062c52d 100644
--- a/vdagent/display_configuration.cpp
+++ b/vdagent/display_configuration.cpp
@@ -153,6 +153,57 @@ struct DISPLAYCONFIG_PATH_INFO {
 UINT32 flags;
 };
 
+
+/* The following definitions and structures are taken
+ * from here 
https://github.com/notr1ch/DWMCapture/blob/master/DWMCaptureSource.cpp */
+
+enum D3DKMT_ESCAPETYPE {
+D3DKMT_ESCAPE_DRIVERPRIVATE = 0
+};
+
+struct D3DDDI_ESCAPEFLAGS {
+union {
+struct {
+UINTReserved : 31;
+};
+UINTValue;
+};
+};
+
+struct D3DKMT_ESCAPE {
+D3D_HANDLE hAdapter;
+D3D_HANDLE hDevice;
+D3DKMT_ESCAPETYPE Type;
+D3DDDI_ESCAPEFLAGS Flags;
+VOID* pPrivateDriverData;
+UINT PrivateDriverDataSize;
+D3D_HANDLE hContext;
+};
+
+struct D3DKMT_OPENADAPTERFROMHDC {
+HDC hDc;
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+UINT VidPnSourceId;
+};
+
+struct D3DKMT_CLOSEADAPTER {
+D3D_HANDLE hAdapter;
+};
+
+struct D3DKMT_OPENADAPTERFROMDEVICENAME {
+const WCHAR *pDeviceName;
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+};
+
+struct D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME {
+WCHAR DeviceName[32];
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+UINT VidPnSourceId;
+};
+
 struct QXLMonitorEscape : QXL_ESCAPE {
 QXLMonitorEscape(DEVMODE* dev_mode)
 {
@@ -175,10 +226,39 @@ struct QxlCustomEscapeObj : public QXL_ESCAPE {
 }
 };
 
+struct WDDMCustomDisplayEscape : public QXL_ESCAPE {
+WDDMCustomDisplayEscape(DEVMODE* dev_mode)
+{
+ioctl = QXL_ESCAPE_SET_CUSTOM_DISPLAY;
+custom_display.bpp  = dev_mode->dmBitsPerPel;
+custom_display.xres = dev_mode->dmPelsWidth;
+custom_display.yres = dev_mode->dmPelsHeight;
+}
+};
+
+struct WDDMMonitorConfigEscape : public QXL_ESCAPE {
+WDDMMonitorConfigEscape(DisplayMode* mode)
+{
+ioctl = QXL_ESCAPE_MONITOR_CONFIG;
+monitor_config.id = monitor_config.surface_id = 0;
+monitor_config.x = mode->get_pos_x();
+monitor_config.y = mode->get_pos_y();
+monitor_config.width = mode->get_width();
+monitor_config.height = mode->get_height();
+}
+};
+
 DisplayConfig* DisplayConfig::create_config()
 {
 DisplayConfig* new_interface;
-new_interface = new XPDMInterface();
+/* Try to open a WDDM adapter.
+If that failed, assume we have an XPDM driver */
+try {
+new_interface = new  WDDMInterface();
+}
+catch (std::exception& e) {
+new_interface = new XPDMInterface();
+}
 return new_interface;
 }
 
@@ -328,6 +408,275 @@ bool XPDMInterface::find_best_mode(LPCTSTR Device, 
DEVMODE* dev_mode)
 return NT_SUCCESS(status);
 }
 
+WDDMInterface::WDDMInterface()
+: _pfnOpen_adapter_hdc(NULL)
+, _pfnClose_adapter(NULL)
+, _pfnEscape(NULL)
+, _pfnOpen_adapter_device_name(NULL)
+, _pfnOpen_adapter_gdi_name(NULL)
+{
+LONG error(0);
+//Can we find the D3D calls we need?
+if (!init_d3d_api()) {
+throw std::exception();
+}
+
+//Initialize  CCD path stuff
+if (!_ccd.query_display_config()) {
+throw std::exception();
+}
+
+if (!_ccd.set_display_config(error)) {
+throw std::exception();
+}
+}
+
+bool WDDMInterface::is_attached(DISPLAY_DEVICE* dev_info)
+{
+return _ccd.is_attached(dev_info->DeviceName);
+}
+
+bool WDDMInterface::set_monitor_state(LPCTSTR device_name, DEVMODE* dev_mode, 
MONITOR_STATE state)
+{
+   return  _ccd.set_path_state(device_name, state);
+}
+
+bool WDDMInterface::custom_display_escape(LPCTSTR device_name, DEVMODE* 
dev_mode)
+{
+DISPLAYCONFIG_MODE_INFO* mode = _ccd.get_active_mode(device_name, false);
+if (!mode) {
+return false;
+}
+
+//Don't bother if we are already set to the new resolution
+if (mode->sourceMode.width == dev_mode->dmPelsWidth &&
+mode->sourceMode.height == dev_mode->dmPelsHeight) {
+return true;
+}
+
+vd_printf("%s: updating %S resolution\n", __FUNCTION__, device_name);
+
+WDDMCustomDisplayEscape wddm_escape(dev_mode);
+if (escape(device_name, &wddm_escape, sizeof(wddm_escape))) {
+return _ccd.update_mode_size(device_name, dev_mode);
+}
+
+vd_printf("%s: (%dx%d)", __FUNCTION_

Re: [Spice-devel] [PATCH qxl-wddm-dod 05/26] Fix Code Integrity error generated by the Drive Verifier

2016-08-16 Thread Frediano Ziglio

> From: Sandy Stutsman 
> 
> Add MdlMappingNoExecute to MmGetSystemAddressForMDLSafe call in
> ExecutePresentDisplayOnly.
> ---
>  qxldod/QxlDod.cpp | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/qxldod/QxlDod.cpp b/qxldod/QxlDod.cpp
> index 77f4f86..1225f04 100755
> --- a/qxldod/QxlDod.cpp
> +++ b/qxldod/QxlDod.cpp
> @@ -2720,7 +2720,7 @@ VgaDevice::ExecutePresentDisplayOnly(
>  // Note: double mapping the buffer this way causes lot of system
>  // overhead for large size buffers.
>  ctx->SrcAddr = reinterpret_cast
> -(MmGetSystemAddressForMdlSafe(mdl, NormalPagePriority ));
> +(MmGetSystemAddressForMdlSafe(mdl, NormalPagePriority |
> MdlMappingNoExecute));
>  
>  if(!ctx->SrcAddr) {
>  Status = STATUS_INSUFFICIENT_RESOURCES;
> @@ -3619,7 +3619,7 @@ QxlDevice::ExecutePresentDisplayOnly(
>  // Note: double mapping the buffer this way causes lot of system
>  // overhead for large size buffers.
>  ctx->SrcAddr = reinterpret_cast
> -(MmGetSystemAddressForMdlSafe(mdl, NormalPagePriority ));
> +(MmGetSystemAddressForMdlSafe(mdl, NormalPagePriority |
> MdlMappingNoExecute));
>  
>  if(!ctx->SrcAddr) {
>  Status = STATUS_INSUFFICIENT_RESOURCES;

Acked-by: Frediano Ziglio 

Frediano
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH qxl-wddm-dod 03/26] Add printer class to dump debug print statements to kernel debugger output

2016-08-16 Thread Frediano Ziglio
> 
> From: Sandy Stutsman 
> 
> Allows the usage of Kd_IHVVIDEO_Mask to control print level while debugging
> 
> Signed-off-by: Sameeh Jubran 
> ---
>  qxldod/driver.cpp | 24 +++-
>  qxldod/driver.h   | 20 
>  2 files changed, 39 insertions(+), 5 deletions(-)
> 
> diff --git a/qxldod/driver.cpp b/qxldod/driver.cpp
> index 4d1913c..d9946aa 100755
> --- a/qxldod/driver.cpp
> +++ b/qxldod/driver.cpp
> @@ -667,7 +667,29 @@ void DebugPrintFunc(const char *format, ...)
>  va_start(list, format);
>  vDbgPrintEx(DPFLTR_DEFAULT_ID, 9 | DPFLTR_MASK, format, list);
>  }
> +
> +kd_debug_printer::kd_debug_printer(ULONG level)
> +{
> +static const ULONG xlate[] = { 0, 0, 1, 2, 3 };
> +if (!level || level > 5) {
> +_level = 0x;
> +
> +}
> +else {
> +_level = xlate[level - 1];
> +}
> +}
> +
> +void kd_debug_printer::print(const char * fmt, ...)
> +{
> +if (_level == 0x) {
> +return;
> +}
> +va_list list;
> +va_start(list, fmt);
> +vDbgPrintEx(DPFLTR_IHVVIDEO_ID, _level, fmt, list);
> +va_end(list);
> +}
>  #endif
>  
>  #pragma code_seg(pop) // End Non-Paged Code
> -
> diff --git a/qxldod/driver.h b/qxldod/driver.h
> index e64c098..752f8e4 100755
> --- a/qxldod/driver.h
> +++ b/qxldod/driver.h
> @@ -208,15 +208,27 @@ DodSystemDisplayWrite(
>  _In_  UINT  PositionY);
>  
>  #if DBG
> +class kd_debug_printer
> +{
> +public:
> +kd_debug_printer(ULONG level);
> +void print(const char * fmt, ...);
> +private:
> +ULONG _level;
> + };
>  
>  extern int nDebugLevel;
>  void DebugPrintFuncSerial(const char *format, ...);
>  
> -void DebugPrintFunc(const char *format, ...);
> +void DebugPrintFunc(const char *format, ...);
> +
> +#define DbgPrint(level, line)   \
> +if (level > nDebugLevel) {} \
> +else {  \
> +   DebugPrintFuncSerial line;   \
> + }  \
> + kd_debug_printer(level).print line
>  
> -#define DbgPrint(level, line) \
> -if (level > nDebugLevel) {} \
> -else DebugPrintFuncSerial line
>  #else
>  #define DbgPrint(level, line)
>  #endif

This can be done much easier with variadic macros and a simple function.

void DebugPrint(int level, const char *fmt, ...);

#define DbgExpandArguments(...) __VA_ARGS__
#define DbgPrint(level, line) do { \
if (level <= nDebugLevel) DebugPrintFuncSerial line; \
DebugPrint(level, DbgExpandArguments line); \
} while(0)


and the definition


void DebugPrint(int level, const char *fmt, ...)
{
   static const ULONG xlate[] = { 0, 0, 1, 2, 3 };
   if (level <= 0 || level > 5)
   return;

   va_list list;
   va_start(list, fmt);
   vDbgPrintEx(DPFLTR_IHVVIDEO_ID, xlate[level - 1], fmt, list);
   va_end(list);
}


Cannot test but I can see the print is duplicated to DebugPrintFuncSerial
and vDbgPrintEx. Is this wanted?

Frediano
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH qxl-wddm-dod 02/26] Add delete operator

2016-08-16 Thread Frediano Ziglio
> 
> Based on a patch by Sandy Stutsman 
> 
> Signed-off-by: Sameeh Jubran 
> ---
>  qxldod/BaseObject.cpp | 11 +++
>  qxldod/BaseObject.h   |  1 +
>  2 files changed, 12 insertions(+)
> 
> diff --git a/qxldod/BaseObject.cpp b/qxldod/BaseObject.cpp
> index ac270fd..a93c040 100755
> --- a/qxldod/BaseObject.cpp
> +++ b/qxldod/BaseObject.cpp
> @@ -70,3 +70,14 @@ void __cdecl operator delete[](void* pObject)
>  ExFreePool(pObject);
>  }
>  }
> +
> +void __cdecl operator delete(void *pObject, size_t s)
> +{
> +PAGED_CODE();
> +
> +UNREFERENCED_PARAMETER(s);
> +
> +if (pObject != NULL) {
> +ExFreePool(pObject);
> +}
> +}
> diff --git a/qxldod/BaseObject.h b/qxldod/BaseObject.h
> index 66e66e4..94bd163 100755
> --- a/qxldod/BaseObject.h
> +++ b/qxldod/BaseObject.h
> @@ -57,3 +57,4 @@ _When_((PoolType & NonPagedPoolMustSucceed) != 0,
>  void* __cdecl operator new[](size_t Size, POOL_TYPE PoolType = PagedPool);
>  void  __cdecl operator delete(void* pObject);
>  void  __cdecl operator delete[](void* pObject);
> +void  __cdecl operator delete[](void *pObject, size_t s);

The declaration is about ::delete[] but the definition is about ::delete.
Is it a typo?

Frediano
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH win-vdagent v8 0/2] Adding multiple monitors and arbitrary resolution for Windows 10

2016-08-16 Thread Frediano Ziglio
> 
> Diffrences from previous patch:
> * Modified the ioctls structures
> 
> NOTE: The patch "Encapsulating XPDM implementation" was pushed, However
> I've modified the patch again.
> 

Please rebase on master

Frediano

> Tested on both Windows 10 and XP and seems to be working great. I've modified
> the driver accordingly, I'll send the driver patches soon.
> Those patches require the following patch to be applied first to
> spice-protocol:
> https://lists.freedesktop.org/archives/spice-devel/2016-August/031409.html
> 
> Sameeh Jubran (2):
>   Encapsulating XPDM implementation
>   Implementing WDDMinterface to support multiple monitors and arbitrary
> resolution
> 
>  vdagent/desktop_layout.cpp| 148 +++
>  vdagent/desktop_layout.h  |   9 +-
>  vdagent/display_configuration.cpp | 523
>  ++
>  vdagent/display_configuration.h   |  83 ++
>  4 files changed, 641 insertions(+), 122 deletions(-)
> 
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [spice 2/2] streaming: Stop streaming if the client reports a streaming error

2016-08-16 Thread Victor Toso
Hi,

On Thu, Aug 11, 2016 at 01:04:15PM +0200, Francois Gouget wrote:
> Signed-off-by: Francois Gouget 
> ---
> 
> If there's enough bandwidth it's as if nothing wrong ever happened :-)
> 
>  server/dcc.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/server/dcc.c b/server/dcc.c
> index d387e8b..b4066f5 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -937,6 +937,15 @@ static int dcc_handle_stream_report(DisplayChannelClient 
> *dcc,
>  return TRUE;
>  }
>
> +if (report->num_frames == 0 && report->num_drops == UINT_MAX) {
> +spice_warning("stream_report: the client does not support stream %u",
> +  report->stream_id);
> +/* Stop streaming the video so the client can see it */
> +agent->video_encoder->destroy(agent->video_encoder);
> +agent->video_encoder = NULL;
> +return TRUE;
> +}
> +

And what would happen as soon as a new stream is detected? Would it try
to create a new encoder (same as before) or would not allow streaming?

Best,
  toso

>  agent->video_encoder->client_stream_report(agent->video_encoder,
> report->num_frames,
> report->num_drops,
> -- 
> 2.8.1
> ___
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH win-vdagent v8 2/2] Implementing WDDMinterface to support multiple monitors and arbitrary resolution

2016-08-16 Thread Sameeh Jubran
The Direct3D 9 API operates on either the Windows XP display driver
model (XPDM) or the Windows Vista display driver model (WDDM), depending
on the operating system installed.

This patch implements the WDDM interface while using the CCD API to do
so. Moreover it introduces multiple monitors support and arbitrary
resolution for Windows 10 while preserving backward compatiblity with
previous
versions of Windows.

Based on a patch by Sandy Stutsman 

Signed-off-by: Dmitry Fleytman 
Signed-off-by: Sameeh Jubran 
---
 vdagent/display_configuration.cpp | 351 +-
 vdagent/display_configuration.h   |  47 +
 2 files changed, 397 insertions(+), 1 deletion(-)

diff --git a/vdagent/display_configuration.cpp 
b/vdagent/display_configuration.cpp
index b6ef88b..d351e48 100755
--- a/vdagent/display_configuration.cpp
+++ b/vdagent/display_configuration.cpp
@@ -153,6 +153,56 @@ struct DISPLAYCONFIG_PATH_INFO {
 UINT32 flags;
 };
 
+/* The following definitions and structures are taken
+from here 
https://github.com/notr1ch/DWMCapture/blob/master/DWMCaptureSource.cpp */
+
+enum D3DKMT_ESCAPETYPE {
+D3DKMT_ESCAPE_DRIVERPRIVATE = 0
+};
+
+struct D3DDDI_ESCAPEFLAGS {
+union {
+struct {
+UINTReserved : 31;
+};
+UINTValue;
+};
+};
+
+struct D3DKMT_ESCAPE {
+D3D_HANDLE hAdapter;
+D3D_HANDLE hDevice;
+D3DKMT_ESCAPETYPE Type;
+D3DDDI_ESCAPEFLAGS Flags;
+VOID* pPrivateDriverData;
+UINT PrivateDriverDataSize;
+D3D_HANDLE hContext;
+};
+
+struct D3DKMT_OPENADAPTERFROMHDC {
+HDC hDc;
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+UINT VidPnSourceId;
+};
+
+struct D3DKMT_CLOSEADAPTER {
+D3D_HANDLE hAdapter;
+};
+
+struct D3DKMT_OPENADAPTERFROMDEVICENAME {
+const WCHAR *pDeviceName;
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+};
+
+struct D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME {
+WCHAR DeviceName[32];
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+UINT VidPnSourceId;
+};
+
 struct QXLMonitorEscape : public QXL_ESCAPE {
 QXLMonitorEscape(DEVMODE* dev_mode)
 {
@@ -175,10 +225,39 @@ struct QxlCustomEscapeObj : public QXL_ESCAPE {
 }
 };
 
+struct WDDMCustomDisplayEscape : public QXL_ESCAPE {
+WDDMCustomDisplayEscape(DEVMODE* dev_mode)
+{
+ioctl = QXL_ESCAPE_SET_CUSTOM_DISPLAY;
+custom_display.bpp  = dev_mode->dmBitsPerPel;
+custom_display.xres = dev_mode->dmPelsWidth;
+custom_display.yres = dev_mode->dmPelsHeight;
+}
+};
+
+struct WDDMMonitorConfigEscape : public QXL_ESCAPE {
+WDDMMonitorConfigEscape(DisplayMode* mode)
+{
+ioctl = QXL_ESCAPE_MONITOR_CONFIG;
+monitor_config.id = monitor_config.surface_id = 0;
+monitor_config.x = mode->get_pos_x();
+monitor_config.y = mode->get_pos_y();
+monitor_config.width = mode->get_width();
+monitor_config.height = mode->get_height();
+}
+};
+
 DisplayConfig* DisplayConfig::create_config()
 {
 DisplayConfig* new_interface;
-new_interface = new XPDMInterface();
+/* Try to open a WDDM adapter.
+If that failed, assume we have an XPDM driver */
+try {
+new_interface = new  WDDMInterface();
+}
+catch (std::exception& e) {
+new_interface = new XPDMInterface();
+}
 return new_interface;
 }
 
@@ -327,6 +406,276 @@ bool XPDMInterface::find_best_mode(LPCTSTR Device, 
DEVMODE* dev_mode)
   CDS_UPDATEREGISTRY | CDS_NORESET, 
NULL);
 return NT_SUCCESS(status);
 }
+
+WDDMInterface::WDDMInterface()
+: _pfnOpen_adapter_hdc(NULL)
+, _pfnClose_adapter(NULL)
+, _pfnEscape(NULL)
+, _pfnOpen_adapter_device_name(NULL)
+, _pfnOpen_adapter_gdi_name(NULL)
+{
+LONG error(0);
+//Can we find the D3D calls we need?
+if (!init_d3d_api()) {
+throw std::exception();
+}
+
+//Initialize  CCD path stuff
+if (!_ccd.query_display_config()) {
+throw std::exception();
+}
+
+if (!_ccd.set_display_config(error)) {
+throw std::exception();
+}
+}
+
+bool WDDMInterface::is_attached(DISPLAY_DEVICE* dev_info)
+{
+return _ccd.is_attached(dev_info->DeviceName);
+}
+
+bool WDDMInterface::set_monitor_state(LPCTSTR device_name, DEVMODE* dev_mode, 
MONITOR_STATE state)
+{
+   return  _ccd.set_path_state(device_name, state);
+}
+
+bool WDDMInterface::custom_display_escape(LPCTSTR device_name, DEVMODE* 
dev_mode)
+{
+DISPLAYCONFIG_MODE_INFO* mode = _ccd.get_active_mode(device_name, false);
+if (!mode) {
+return false;
+}
+
+//Don't bother if we are already set to the new resolution
+if (mode->sourceMode.width == dev_mode->dmPelsWidth &&
+mode->sourceMode.height == dev_mode->dmPelsHeight) {
+return true;
+}
+
+vd_printf("%s: updating %S resolution\n", __FUNCTION__, device_name);
+
+WDDMCustomDisplayEscape wddm_escape(dev_mode);
+if (escape(device_

[Spice-devel] [PATCH win-vdagent v8 0/2] Adding multiple monitors and arbitrary resolution for Windows 10

2016-08-16 Thread Sameeh Jubran
Diffrences from previous patch:
* Modified the ioctls structures

NOTE: The patch "Encapsulating XPDM implementation" was pushed, However
I've modified the patch again.

Tested on both Windows 10 and XP and seems to be working great. I've modified
the driver accordingly, I'll send the driver patches soon.
Those patches require the following patch to be applied first to
spice-protocol:
https://lists.freedesktop.org/archives/spice-devel/2016-August/031409.html

Sameeh Jubran (2):
  Encapsulating XPDM implementation
  Implementing WDDMinterface to support multiple monitors and arbitrary
resolution

 vdagent/desktop_layout.cpp| 148 +++
 vdagent/desktop_layout.h  |   9 +-
 vdagent/display_configuration.cpp | 523 ++
 vdagent/display_configuration.h   |  83 ++
 4 files changed, 641 insertions(+), 122 deletions(-)

-- 
2.7.4

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [client 1/2] streaming: Send a special stream report to signal streaming errors

2016-08-16 Thread Victor Toso
Hi,

On Thu, Aug 11, 2016 at 01:04:09PM +0200, Francois Gouget wrote:
> Servers that recognize this special report then stop streaming (sending
> regular screen updates instead) while older ones essentially ignore it.
>
> Signed-off-by: Francois Gouget 
> ---
>
> This patchset is based on Victor Toso's idea [1] of using the stream
> reports to tell the server that, despite expectations, the client cannot
> handle a given stream.
>
> You'll notice that this patch does not directly check for
> create_xxx_decoder() errors. Instead it relies on the previous patchset
> [2] deleting broken streams so that the following messages will run into
> an unknown stream.
>
> Of course this could already happen in case of a malicious server
> sending garbage to the client. So this patchset is quite independent
> from the previous one.
>
> I don't know what the consequences of receiving an unknown message would
> be for the server so I chose to hook into the
> display_handle_stream_activate_report() as that's where we get notified
> that the server supports the stream reports.

The server sends SPICE_MSG_DISPLAY_STREAM_ACTIVATE_REPORT on
dcc_create_stream() just after SPICE_MSG_DISPLAY_STREAM_CREATE (might)
have been sent so, in the client, we have the difference of this two
sequential messages to identify that the decoder failed as this patch
will send the failure on display_handle_stream_activate_report().

/*
SPICE_MSGC_DISPLAY_STREAM_REPORT is being used in the client on
display_update_stream_report() later on display_handle_stream_data().
*/

I think what we want is to inform the server as soon as the error
happened (if possible), likely after stream is destroyed [0].

[0] 
https://cgit.freedesktop.org/spice/spice-gtk/tree/src/channel-display.c#n1127

We might want to improve the display_update_stream_report() to handle
this kind of situation.

> Maybe we should send such an error anywhere we receive a message with an
> unknown stream_id. There's really no reason for that to happen in those
> other places though, except if the server does not recognize the initial
> error stream report and continues streaming.

I'm not 100% about the stream protocol but it might be the case that we
receive messages with a unknow/failed stream_id while decoder fails and
the error is sent and properly handled in the server.

> In that case sending more error messages won't do any good. So sending
> an error in just this one place may make more sense.

Sending one error per stream-id might be enough indeed.

> We could also add an extra cap to identify servers that recognize this
> special type or stream report. But is it really worth it?

Maybe! To be honest, first thing it seems interesting to avoid is the
server sending stream while the client is not able to decode; second is
a better logic in the server to change the encoder in case previous one
failed with the client (based on client's capabilities); No more stream
in case we don't have another encoder options.

So far, we only had mjpeg but with GStreamer encoder/decoder, I'm
expecting more options to be available quickly in the future... if this
kind of decoder failure does not fit SPICE_MSGC_DISPLAY_STREAM_REPORT,
we might want a new message and capability just for that.

Thanks for the patch and discussion!

Cheers,
  toso

>
> [1] https://lists.freedesktop.org/archives/spice-devel/2016-August/031101.html
> [2] https://lists.freedesktop.org/archives/spice-devel/2016-August/031282.html
>
>
>  src/channel-display.c | 24 +---
>  1 file changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/src/channel-display.c b/src/channel-display.c
> index 709b3d2..3898f0a 100644
> --- a/src/channel-display.c
> +++ b/src/channel-display.c
> @@ -1530,10 +1530,28 @@ static void 
> display_handle_stream_activate_report(SpiceChannel *channel, SpiceMs
>
>  g_return_if_fail(c != NULL);
>  g_return_if_fail(c->streams != NULL);
> -g_return_if_fail(c->nstreams > op->stream_id);
>
> -st = c->streams[op->stream_id];
> -g_return_if_fail(st != NULL);
> +st = op->stream_id < c->nstreams ? c->streams[op->stream_id] : NULL;
> +if (st == NULL) {
> +SpiceMsgcDisplayStreamReport report;
> +SpiceMsgOut *msg;
> +
> +/* Send a special stream report to indicate there is no such stream 
> */
> +spice_printerr("notify the server that stream %u does not exist", 
> op->stream_id);
> +report.stream_id = op->stream_id;
> +report.unique_id = op->unique_id;
> +report.start_frame_mm_time = 0;
> +report.end_frame_mm_time = 0;
> +report.num_frames = 0;
> +report.num_drops = UINT_MAX;
> +report.last_frame_delay = 0;
> +report.audio_delay = 0;
> +
> +msg = spice_msg_out_new(SPICE_CHANNEL(channel), 
> SPICE_MSGC_DISPLAY_STREAM_REPORT);
> +msg->marshallers->msgc_display_stream_report(msg->marshaller, 
> &report);
> +spice_msg_out_send(msg);
> +return;
> + 

Re: [Spice-devel] [PATCH 5/5] Avoid to use _singleton for VDService

2016-08-16 Thread Frediano Ziglio
> 
> Hi,
> 
> Sorry for taking some time with the other patches ;)
> Remaining patches are good to go!
> 
> Acked-by: Victor Toso 
> 

Thanks

Frediano

> On Fri, Aug 12, 2016 at 12:02:09PM +0100, Frediano Ziglio wrote:
> > Signed-off-by: Frediano Ziglio 
> > ---
> >  vdservice/vdservice.cpp | 32 +---
> >  1 file changed, 9 insertions(+), 23 deletions(-)
> > 
> > diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
> > index ef1ed9f..d2bedaa 100644
> > --- a/vdservice/vdservice.cpp
> > +++ b/vdservice/vdservice.cpp
> > @@ -59,14 +59,13 @@ typedef std::queue VDControlQueue;
> >  
> >  class VDService {
> >  public:
> > -static VDService* get();
> > -~VDService();
> > -bool run();
> > -bool install();
> > -bool uninstall();
> > +static bool run();
> > +static bool install();
> > +static bool uninstall();
> >  
> >  private:
> >  VDService();
> > +~VDService();
> >  bool execute();
> >  void stop();
> >  static DWORD WINAPI control_handler(DWORD control, DWORD event_type,
> > @@ -87,7 +86,6 @@ private:
> >  }
> >  }
> >  private:
> > -static VDService* _singleton;
> >  SERVICE_STATUS _status;
> >  SERVICE_STATUS_HANDLE _status_handle;
> >  PROCESS_INFORMATION _agent_proc_info;
> > @@ -109,16 +107,6 @@ private:
> >  unsigned _events_count;
> >  };
> >  
> > -VDService* VDService::_singleton = NULL;
> > -
> > -VDService* VDService::get()
> > -{
> > -if (!_singleton) {
> > -_singleton = new VDService();
> > -}
> > -return (VDService*)_singleton;
> > -}
> > -
> >  VDService::VDService()
> >  : _status_handle (0)
> >  , _events (NULL)
> > @@ -138,7 +126,6 @@ VDService::VDService()
> >  _agent_path[0] = wchar_t('\0');
> >  MUTEX_INIT(_agent_mutex);
> >  MUTEX_INIT(_control_mutex);
> > -_singleton = this;
> >  }
> >  
> >  VDService::~VDService()
> > @@ -322,7 +309,7 @@ DWORD WINAPI VDService::control_handler(DWORD control,
> > DWORD event_type, LPVOID
> >  
> >  VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
> >  {
> > -VDService* s = _singleton;
> > +VDService* s = new VDService;
> >  SERVICE_STATUS* status;
> >  TCHAR log_path[MAX_PATH];
> >  TCHAR full_path[MAX_PATH];
> > @@ -382,6 +369,7 @@ VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
> >  SetServiceStatus(s->_status_handle, status);
> >  #endif //DEBUG_VDSERVICE
> >  vd_printf("***Service stopped***");
> > +delete s;
> >  }
> >  
> >  bool VDService::execute()
> > @@ -839,18 +827,16 @@ int _tmain(int argc, TCHAR* argv[])
> >  printf("vdservice is not supported in this system version\n");
> >  return -1;
> >  }
> > -VDService* vdservice = VDService::get();
> >  if (argc > 1) {
> >  if (lstrcmpi(argv[1], TEXT("install")) == 0) {
> > -success = vdservice->install();
> > +success = VDService::install();
> >  } else if (lstrcmpi(argv[1], TEXT("uninstall")) == 0) {
> > -success = vdservice->uninstall();
> > +success = VDService::uninstall();
> >  } else {
> >  printf("Use: vdservice install / uninstall\n");
> >  }
> >  } else {
> > -success = vdservice->run();
> > +success = VDService::run();
> >  }
> > -delete vdservice;
> >  return (success ? 0 : -1);
> >  }
> > --
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH win-vdagent v8 1/2] Encapsulating XPDM implementation

2016-08-16 Thread Sameeh Jubran
The Direct3D 9 API operates on either the Windows XP display driver
model (XPDM) or the Windows Vista display driver model (WDDM), depending
on the operating system installed.

This patch encapsulates the current XPDM interface implementation into
XPDMInterface class which inherits DisplayConfig class. This patch
makes it easier to introduce WDDM interface to Vdagent in future
patches.

Based on a patch by Sandy Stutsman 

Signed-off-by: Dmitry Fleytman 
Signed-off-by: Sameeh Jubran 
---
 vdagent/desktop_layout.cpp| 148 +++-
 vdagent/desktop_layout.h  |   9 +-
 vdagent/display_configuration.cpp | 174 ++
 vdagent/display_configuration.h   |  36 
 4 files changed, 245 insertions(+), 122 deletions(-)

diff --git a/vdagent/desktop_layout.cpp b/vdagent/desktop_layout.cpp
index a7666ca..9c3e873 100644
--- a/vdagent/desktop_layout.cpp
+++ b/vdagent/desktop_layout.cpp
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include "desktop_layout.h"
+#include "display_configuration.h"
 #include "vdlog.h"
 
 #ifdef __MINGW32__
@@ -35,15 +36,17 @@ void DisplayMode::set_res(DWORD width, DWORD height, DWORD 
depth)
 DesktopLayout::DesktopLayout()
 : _total_width (0)
 , _total_height (0)
-, _send_monitors_position(false)
+, _display_config (NULL)
 {
 MUTEX_INIT(_mutex);
+_display_config = DisplayConfig::create_config();
 get_displays();
 }
 
 DesktopLayout::~DesktopLayout()
 {
 clean_displays();
+delete _display_config;
 }
 
 void DesktopLayout::get_displays()
@@ -59,6 +62,7 @@ void DesktopLayout::get_displays()
 unlock();
 return;
 }
+_display_config->update_config_path();
 clean_displays();
 ZeroMemory(&dev_info, sizeof(dev_info));
 dev_info.cb = sizeof(dev_info);
@@ -82,12 +86,13 @@ void DesktopLayout::get_displays()
 _displays[i] = NULL;
 }
 }
-attached = !!(dev_info.StateFlags & 
DISPLAY_DEVICE_ATTACHED_TO_DESKTOP);
+attached = _display_config->is_attached(&dev_info);
+
 EnumDisplaySettings(dev_info.DeviceName, ENUM_CURRENT_SETTINGS, &mode);
 _displays[display_id] = new DisplayMode(mode.dmPosition.x, 
mode.dmPosition.y,
 mode.dmPelsWidth, 
mode.dmPelsHeight,
 mode.dmBitsPerPel, attached);
-update_monitor_config(dev_info.DeviceName, _displays[display_id]);
+_display_config->update_monitor_config(dev_info.DeviceName, 
_displays[display_id], &mode);
 }
 normalize_displays_pos();
 unlock();
@@ -121,6 +126,7 @@ void DesktopLayout::set_displays()
 unlock();
 return;
 }
+_display_config->update_config_path();
 ZeroMemory(&dev_info, sizeof(dev_info));
 dev_info.cb = sizeof(dev_info);
 ZeroMemory(&dev_mode, sizeof(dev_mode));
@@ -146,28 +152,32 @@ void DesktopLayout::set_displays()
 break;
 }
 DisplayMode * mode(_displays.at(display_id));
-if (!init_dev_mode(dev_info.DeviceName, &dev_mode, mode, normal_x, 
normal_y, true)) {
+if (!init_dev_mode(dev_info.DeviceName, &dev_mode, mode)) {
 vd_printf("No suitable mode found for display %S", 
dev_info.DeviceName);
 break;
 }
 vd_printf("Set display mode %lux%lu", dev_mode.dmPelsWidth, 
dev_mode.dmPelsHeight);
-LONG ret = ChangeDisplaySettingsEx(dev_info.DeviceName, &dev_mode, 
NULL,
-   CDS_UPDATEREGISTRY | CDS_NORESET, 
NULL);
-if (ret == DISP_CHANGE_SUCCESSFUL) {
+if (_display_config->update_dev_mode_position(dev_info.DeviceName, 
&dev_mode,
+ mode->_pos_x - normal_x,
+ mode->_pos_y - normal_y)) 
{
 dev_sets++;
-update_monitor_config(dev_info.DeviceName, mode);
+_display_config->update_monitor_config(dev_info.DeviceName, mode, 
&dev_mode);
 }
 if (!is_qxl) {
 display_id++;
 }
 }
 if (dev_sets) {
-ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
+_display_config->update_display_settings();
 normalize_displays_pos();
 }
 unlock();
 }
 
+void DesktopLayout::set_position_configurable(bool flag) {
+_display_config->set_monitors_config(flag);
+}
+
 // Normalize all display positions to non-negative coordinates and update 
total width and height of
 // the virtual desktop. Caller is responsible to lock() & unlock().
 void DesktopLayout::normalize_displays_pos()
@@ -265,125 +275,29 @@ bool DesktopLayout::get_qxl_device_id(WCHAR* device_key, 
DWORD* device_id)
 return key_found;
 }
 
-bool DesktopLayout::init_dev_mode(LPCTSTR dev_name, DEVMODE* dev_mode, 
DisplayMode* mode,
-  LONG normal_x, LONG normal_y, bool set_pos)

[Spice-devel] [PATCH spice-protocol v3] Add ioctls structures to qxl_windows.h

2016-08-16 Thread Sameeh Jubran
This patch defines the structures of ioctls that are used between
win-vdagent and the qxl-wddm-dod driver.

Signed-off-by: Sameeh Jubran 
---
 spice/qxl_windows.h | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/spice/qxl_windows.h b/spice/qxl_windows.h
index bc2ceff..6e9627d 100644
--- a/spice/qxl_windows.h
+++ b/spice/qxl_windows.h
@@ -2,7 +2,7 @@
 #define _H_QXL_WINDOWS
 
 #include 
-
+#include 
 #include 
 
 enum {
@@ -16,6 +16,14 @@ typedef struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
 uint32_t bpp;
 } QXLEscapeSetCustomDisplay;
 
+typedef struct SPICE_ATTR_PACKED QXL_ESCAPE {
+uint32_t ioctl;
+union {
+QXLEscapeSetCustomDisplay custom_display;
+QXLHead monitor_config;
+};
+} QXL_ESCAPE;
+
 #include 
 
 #endif /* _H_QXL_WINDOWS */
-- 
2.7.4

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH 5/5] Avoid to use _singleton for VDService

2016-08-16 Thread Victor Toso
Hi,

Sorry for taking some time with the other patches ;)
Remaining patches are good to go!

Acked-by: Victor Toso 

On Fri, Aug 12, 2016 at 12:02:09PM +0100, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio 
> ---
>  vdservice/vdservice.cpp | 32 +---
>  1 file changed, 9 insertions(+), 23 deletions(-)
> 
> diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
> index ef1ed9f..d2bedaa 100644
> --- a/vdservice/vdservice.cpp
> +++ b/vdservice/vdservice.cpp
> @@ -59,14 +59,13 @@ typedef std::queue VDControlQueue;
>  
>  class VDService {
>  public:
> -static VDService* get();
> -~VDService();
> -bool run();
> -bool install();
> -bool uninstall();
> +static bool run();
> +static bool install();
> +static bool uninstall();
>  
>  private:
>  VDService();
> +~VDService();
>  bool execute();
>  void stop();
>  static DWORD WINAPI control_handler(DWORD control, DWORD event_type,
> @@ -87,7 +86,6 @@ private:
>  }
>  }
>  private:
> -static VDService* _singleton;
>  SERVICE_STATUS _status;
>  SERVICE_STATUS_HANDLE _status_handle;
>  PROCESS_INFORMATION _agent_proc_info;
> @@ -109,16 +107,6 @@ private:
>  unsigned _events_count;
>  };
>  
> -VDService* VDService::_singleton = NULL;
> -
> -VDService* VDService::get()
> -{
> -if (!_singleton) {
> -_singleton = new VDService();
> -}
> -return (VDService*)_singleton;
> -}
> -
>  VDService::VDService()
>  : _status_handle (0)
>  , _events (NULL)
> @@ -138,7 +126,6 @@ VDService::VDService()
>  _agent_path[0] = wchar_t('\0');
>  MUTEX_INIT(_agent_mutex);
>  MUTEX_INIT(_control_mutex);
> -_singleton = this;
>  }
>  
>  VDService::~VDService()
> @@ -322,7 +309,7 @@ DWORD WINAPI VDService::control_handler(DWORD control, 
> DWORD event_type, LPVOID
>  
>  VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
>  {
> -VDService* s = _singleton;
> +VDService* s = new VDService;
>  SERVICE_STATUS* status;
>  TCHAR log_path[MAX_PATH];
>  TCHAR full_path[MAX_PATH];
> @@ -382,6 +369,7 @@ VOID WINAPI VDService::main(DWORD argc, TCHAR* argv[])
>  SetServiceStatus(s->_status_handle, status);
>  #endif //DEBUG_VDSERVICE
>  vd_printf("***Service stopped***");
> +delete s;
>  }
>  
>  bool VDService::execute()
> @@ -839,18 +827,16 @@ int _tmain(int argc, TCHAR* argv[])
>  printf("vdservice is not supported in this system version\n");
>  return -1;
>  }
> -VDService* vdservice = VDService::get();
>  if (argc > 1) {
>  if (lstrcmpi(argv[1], TEXT("install")) == 0) {
> -success = vdservice->install();
> +success = VDService::install();
>  } else if (lstrcmpi(argv[1], TEXT("uninstall")) == 0) {
> -success = vdservice->uninstall();
> +success = VDService::uninstall();
>  } else {
>  printf("Use: vdservice install / uninstall\n");
>  }
>  } else {
> -success = vdservice->run();
> +success = VDService::run();
>  }
> -delete vdservice;
>  return (success ? 0 : -1);
>  }
> -- 
> 2.7.4
> 
> ___
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-protocol v2] Add ioctls structures to qxl_windows.h

2016-08-16 Thread Daniel P. Berrange
On Tue, Aug 16, 2016 at 03:58:50PM +0300, Sameeh Jubran wrote:
> This patch defines the structures of ioctls that are used between
> win-vdagent and the qxl-wddm-dod driver.
> 
> Signed-off-by: Sameeh Jubran 
> ---
>  spice/qxl_windows.h | 15 +++
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/spice/qxl_windows.h b/spice/qxl_windows.h
> index bc2ceff..89aeac9 100644
> --- a/spice/qxl_windows.h
> +++ b/spice/qxl_windows.h
> @@ -2,7 +2,7 @@
>  #define _H_QXL_WINDOWS
>  
>  #include 
> -
> +#include 
>  #include 
>  
>  enum {
> @@ -11,11 +11,18 @@ enum {
>  };
>  
>  typedef struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
> -uint32_t xres;
> -uint32_t yres;
> -uint32_t bpp;
> +uint32_t _xres;
> +uint32_t _yres;
> +uint32_t _bpp;
>  } QXLEscapeSetCustomDisplay;

Renaming fields in structs breaks API for any app already using the
struct in previous releases of spice-protocol

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-protocol v2] Add ioctls structures to qxl_windows.h

2016-08-16 Thread Sameeh Jubran
This patch defines the structures of ioctls that are used between
win-vdagent and the qxl-wddm-dod driver.

Signed-off-by: Sameeh Jubran 
---
 spice/qxl_windows.h | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/spice/qxl_windows.h b/spice/qxl_windows.h
index bc2ceff..89aeac9 100644
--- a/spice/qxl_windows.h
+++ b/spice/qxl_windows.h
@@ -2,7 +2,7 @@
 #define _H_QXL_WINDOWS
 
 #include 
-
+#include 
 #include 
 
 enum {
@@ -11,11 +11,18 @@ enum {
 };
 
 typedef struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
-uint32_t xres;
-uint32_t yres;
-uint32_t bpp;
+uint32_t _xres;
+uint32_t _yres;
+uint32_t _bpp;
 } QXLEscapeSetCustomDisplay;
 
+typedef struct SPICE_ATTR_PACKED QXL_ESCAPE {
+uint32_t _ioctl;
+union {
+QXLEscapeSetCustomDisplay _custom_display;
+QXLHead _monitor_config;
+};
+} QXL_ESCAPE;
 #include 
 
 #endif /* _H_QXL_WINDOWS */
-- 
2.7.4

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH libcacard] Do not fail, if the caller didn't pick up response from previous call

2016-08-16 Thread Pavel Grunt
On Tue, 2016-08-16 at 12:15 +0200, Jakub Jelen wrote:
> On 08/16/2016 11:11 AM, Marc-André Lureau wrote:
> > 
> > Hi
> > 
> > - Original Message -
> > > 
> > > Hello all,
> > > cross-posting the originally opened pull request on github [1] (with
> > > attached patch):
> > > 
> > > During our testing of a new CAC driver in OpenSC, with this library, we
> > > encountered a problem with |libcacard| failing and the driver returning
> > > only a fraction of the requested objects.
> > > 
> > > The problem is that the Emulator wants to return the data (properly
> > > signalized by 61 (RESPONSE BYTES) in SW1), but this is ignored for some
> > > reason in some of our calls from OpenSC. The Emulator should not fail
> > > hard for the next independent request, rather silently drop the buffer
> > > and serve the ongoing APDU request (I would left for consideration to
> > > somehow log such problem).
> > > 
> > > Patch was successfully tested on Fedora 24 host and solves our problem
> > > (though we worked around the problem already in the driver too).
> > > 
> > > [1] https://github.com/SPICE/libcacard/pull/1
> > ack, and pushed
> > 
> > Please next time, use git send-email (with the default inline patch
> > attachment)
> Thanks,
> I would do that, but the guidelines, talk about "format-patch" [1] and 
> not "send-email", which was the source of the confusion:
> 
>  > The patch was prepared using git format-patch
> 
> If the send-email was intended, it should be mentioned explicitly.

Thanks for the suggestion, fixed

Pavel

> 
> [1] http://www.spice-space.org/developers.html
> 
> Regards,
> 
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH libcacard] Do not fail, if the caller didn't pick up response from previous call

2016-08-16 Thread Jakub Jelen

On 08/16/2016 11:11 AM, Marc-André Lureau wrote:

Hi

- Original Message -

Hello all,
cross-posting the originally opened pull request on github [1] (with
attached patch):

During our testing of a new CAC driver in OpenSC, with this library, we
encountered a problem with |libcacard| failing and the driver returning
only a fraction of the requested objects.

The problem is that the Emulator wants to return the data (properly
signalized by 61 (RESPONSE BYTES) in SW1), but this is ignored for some
reason in some of our calls from OpenSC. The Emulator should not fail
hard for the next independent request, rather silently drop the buffer
and serve the ongoing APDU request (I would left for consideration to
somehow log such problem).

Patch was successfully tested on Fedora 24 host and solves our problem
(though we worked around the problem already in the driver too).

[1] https://github.com/SPICE/libcacard/pull/1

ack, and pushed

Please next time, use git send-email (with the default inline patch attachment)

Thanks,
I would do that, but the guidelines, talk about "format-patch" [1] and 
not "send-email", which was the source of the confusion:


> The patch was prepared using git format-patch

If the send-email was intended, it should be mentioned explicitly.

[1] http://www.spice-space.org/developers.html

Regards,

--
Jakub Jelen
Associate Software Engineer
Security Technologies
Red Hat

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-protocol] Add ioctls structures to qxl_windows.h

2016-08-16 Thread Frediano Ziglio
> On Tue, Aug 16, 2016 at 1:27 PM, Frediano Ziglio < fzig...@redhat.com >
> wrote:

> > >
> 
> > > This patch defines the structures of ioctls that are used between
> 
> > > win-vdagent and the qxl-wddm-dod driver.
> 
> > >
> 
> > > Signed-off-by: Sameeh Jubran < sam...@daynix.com >
> 
> > > ---
> 
> > > spice/qxl_windows.h | 16 
> 
> > > 1 file changed, 12 insertions(+), 4 deletions(-)
> 
> > >
> 
> > > diff --git a/spice/qxl_windows.h b/spice/qxl_windows.h
> 
> > > index bc2ceff..c4776d4 100644
> 
> > > --- a/spice/qxl_windows.h
> 
> > > +++ b/spice/qxl_windows.h
> 
> > > @@ -2,20 +2,28 @@
> 
> > > #define _H_QXL_WINDOWS
> 
> > >
> 
> > > #include 
> 
> > > -
> 
> > > +#include 
> 
> > > #include 
> 
> > >
> 
> > > enum {
> 
> > > QXL_ESCAPE_SET_CUSTOM_DISPLAY = 0x10001,
> 
> > > - QXL_ESCAPE_MONITOR_CONFIG
> 
> > > + QXL_ESCAPE_MONITOR_CONFIG,
> 
> > > + QXL_ESCAPE_VDAGENT_RUNNING
> 

> > Didn't we decide to remove this?
> 

> We can't remove this unless there is a good working alternative. We use those
> enums when calling this function
> https://msdn.microsoft.com/en-us/library/windows/desktop/dd162708%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

Was referring to QXL_ESCAPE_VDAGENT_RUNNING , you are currently not using it 
and 
also you are not defining a structure for it. I think it's just some lines 
changes that do not 
own to this change. 

> > > };
> 
> > >
> 
> > > -typedef struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
> 
> > > +struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
> 
> > > uint32_t xres;
> 
> > > uint32_t yres;
> 
> > > uint32_t bpp;
> 
> > > -} QXLEscapeSetCustomDisplay;
> 
> > > +};
> 

> > API change here.
> 

> why? only removed unneeded typedef.

Yes, but this break C API, actually this would make this header not C 
compatible. 
This as using QXLEscapeSetCustomDisplay without struct (like in following line) 
would cause an error. 

> > >
> 
> > > +struct SPICE_ATTR_PACKED QXL_ESCAPE {
> 

I would use QXLEscape instead, all structures/enums use this kind of naming. 
Would stick to typedefs too. 

> > > + uint32_t ioctl;
> 
> > > + union {
> 
> > > + QXLEscapeSetCustomDisplay custom_display;
> 
> > > + QXLHead monitor_config;
> 
> > > + };
> 
> > > +};
> 
> > > #include 
> 
> > >
> 
> > > #endif /* _H_QXL_WINDOWS */
> 

Frediano 
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-protocol] Add ioctls structures to qxl_windows.h

2016-08-16 Thread Dmitry Fleytman


Sent from my iPhone

> On 16 Aug 2016, at 13:30, Sameeh Jubran  wrote:
> 
> 
>> On Tue, Aug 16, 2016 at 1:27 PM, Frediano Ziglio  wrote:
>> >
>> > This patch defines the structures of ioctls that are used between
>> > win-vdagent and the qxl-wddm-dod driver.
>> >
>> > Signed-off-by: Sameeh Jubran 
>> > ---
>> >  spice/qxl_windows.h | 16 
>> >  1 file changed, 12 insertions(+), 4 deletions(-)
>> >
>> > diff --git a/spice/qxl_windows.h b/spice/qxl_windows.h
>> > index bc2ceff..c4776d4 100644
>> > --- a/spice/qxl_windows.h
>> > +++ b/spice/qxl_windows.h
>> > @@ -2,20 +2,28 @@
>> >  #define _H_QXL_WINDOWS
>> >
>> >  #include 
>> > -
>> > +#include 
>> >  #include 
>> >
>> >  enum {
>> >  QXL_ESCAPE_SET_CUSTOM_DISPLAY = 0x10001,
>> > -QXL_ESCAPE_MONITOR_CONFIG
>> > +QXL_ESCAPE_MONITOR_CONFIG,
>> > +QXL_ESCAPE_VDAGENT_RUNNING
>> 
>> Didn't we decide to remove this?
> We can't remove this unless there is a good working alternative. We use those
> enums when calling this function 
> https://msdn.microsoft.com/en-us/library/windows/desktop/dd162708%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

I think QXL_ESCAPE_VDAGENT_RUNNING is not used indeed since it was decided to 
rework those patches.

Other entries are used.


> 
>  
>> 
>> >  };
>> >
>> > -typedef struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
>> > +struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
>> >  uint32_t xres;
>> >  uint32_t yres;
>> >  uint32_t bpp;
>> > -} QXLEscapeSetCustomDisplay;
>> > +};
>> 
>> API change here.
> why? only removed unneeded typedef. 
>> 
>> >
>> > +struct SPICE_ATTR_PACKED QXL_ESCAPE {
>> > +uint32_t ioctl;
>> > +union {
>> > +QXLEscapeSetCustomDisplay custom_display;
>> > +QXLHead monitor_config;
>> > +};
>> > +};
>> >  #include 
>> >
>> >  #endif /* _H_QXL_WINDOWS */
>> 
>> Frediano
> 
> 
> 
> -- 
> Respectfully,
> Sameeh Jubran
> Linkedin
> Junior Software Engineer @ Daynix.
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH win-vdagent v7 2/3] Encapsulating XPDM implementation

2016-08-16 Thread Sameeh Jubran
great thanks :)

On Tue, Aug 16, 2016 at 1:37 PM, Frediano Ziglio  wrote:

> >
> > The Direct3D 9 API operates on either the Windows XP display driver
> > model (XPDM) or the Windows Vista display driver model (WDDM), depending
> > on the operating system installed.
> >
> > This patch encapsulates the current XPDM interface implementation into
> > XPDMInterface class which inherits DisplayConfig class. This patch
> > makes it easier to introduce WDDM interface to Vdagent in future
> > patches.
> >
> > Based on a patch by Sandy Stutsman 
> >
> > Signed-off-by: Dmitry Fleytman 
> > Signed-off-by: Sameeh Jubran 
>
> Acked-by: Frediano Ziglio 
>
> Merged.
>
> Frediano
>
> ...
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin *
*Junior Software Engineer @ Daynix .*
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH win-vdagent v7 3/3] Implementing WDDM interface to support multiple monitors and arbitrary resolution

2016-08-16 Thread Frediano Ziglio
 
> The Direct3D 9 API operates on either the Windows XP display driver
> model (XPDM) or the Windows Vista display driver model (WDDM), depending
> on the operating system installed.
> 
> This patch implements the WDDM interface while using the CCD API to do
> so. Moreover it introduces multiple monitors support and arbitrary
> resolution for Windows 10 while preserving backward compatiblity with
> previous
> versions of Windows.
> 
> Based on a patch by Sandy Stutsman 
> 
> Signed-off-by: Dmitry Fleytman 
> Signed-off-by: Sameeh Jubran 

Acked-by: Frediano Ziglio 

Didn't merge, looking at your new mails looks like you want
to change it.

Frediano

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH win-vdagent v7 1/3] Introducing Windows CCD API

2016-08-16 Thread Frediano Ziglio
> 
> The Connecting and Configuring Displays (CCD) Win32 APIs
> provide more control over the desktop display setup. The CCD APIs
> move away from using Windows Graphics Device Interface (GDI)
> concepts like view name and toward Windows Display Driver Model
> (WDDM) concepts like adapter, source, and target identifiers.
> More info on the CCD API can be found here:
> https://msdn.microsoft.com/en-us/library/windows/hardware/ff539590(v=vs.85).aspx
> 
> This patch introduces partial functionality from the CCD API
> needed by vdagent. It is needed by vdagent in order to support
> multiple monitors and arbitrary resolution on Windows 10.
> 
> Acked-by: Frediano Ziglio 
> 

Merged. Rebased on master (just space changes)

Frediano

> Based on a patch by Sandy Stutsman 
> 
> Signed-off-by: Dmitry Fleytman 
> Signed-off-by: Sameeh Jubran 

...
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH win-vdagent v7 2/3] Encapsulating XPDM implementation

2016-08-16 Thread Frediano Ziglio
> 
> The Direct3D 9 API operates on either the Windows XP display driver
> model (XPDM) or the Windows Vista display driver model (WDDM), depending
> on the operating system installed.
> 
> This patch encapsulates the current XPDM interface implementation into
> XPDMInterface class which inherits DisplayConfig class. This patch
> makes it easier to introduce WDDM interface to Vdagent in future
> patches.
> 
> Based on a patch by Sandy Stutsman 
> 
> Signed-off-by: Dmitry Fleytman 
> Signed-off-by: Sameeh Jubran 

Acked-by: Frediano Ziglio 

Merged.

Frediano

...
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-protocol] Add ioctls structures to qxl_windows.h

2016-08-16 Thread Sameeh Jubran
On Tue, Aug 16, 2016 at 1:27 PM, Frediano Ziglio  wrote:

> >
> > This patch defines the structures of ioctls that are used between
> > win-vdagent and the qxl-wddm-dod driver.
> >
> > Signed-off-by: Sameeh Jubran 
> > ---
> >  spice/qxl_windows.h | 16 
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/spice/qxl_windows.h b/spice/qxl_windows.h
> > index bc2ceff..c4776d4 100644
> > --- a/spice/qxl_windows.h
> > +++ b/spice/qxl_windows.h
> > @@ -2,20 +2,28 @@
> >  #define _H_QXL_WINDOWS
> >
> >  #include 
> > -
> > +#include 
> >  #include 
> >
> >  enum {
> >  QXL_ESCAPE_SET_CUSTOM_DISPLAY = 0x10001,
> > -QXL_ESCAPE_MONITOR_CONFIG
> > +QXL_ESCAPE_MONITOR_CONFIG,
> > +QXL_ESCAPE_VDAGENT_RUNNING
>
> Didn't we decide to remove this?
>
We can't remove this unless there is a good working alternative. We use
those
enums when calling this function
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162708%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396



>
> >  };
> >
> > -typedef struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
> > +struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
> >  uint32_t xres;
> >  uint32_t yres;
> >  uint32_t bpp;
> > -} QXLEscapeSetCustomDisplay;
> > +};
>
> API change here.
>
why? only removed unneeded typedef.

>
> >
> > +struct SPICE_ATTR_PACKED QXL_ESCAPE {
> > +uint32_t ioctl;
> > +union {
> > +QXLEscapeSetCustomDisplay custom_display;
> > +QXLHead monitor_config;
> > +};
> > +};
> >  #include 
> >
> >  #endif /* _H_QXL_WINDOWS */
>
> Frediano
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin *
*Junior Software Engineer @ Daynix .*
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-protocol] Adding ioctl structures for win-vdagent/qxl-wddm-dod

2016-08-16 Thread Frediano Ziglio
> spice-protocol is a sub-project for win-vdagent. This patch intreduces the
> structures that are used in this patch
> https://lists.freedesktop.org/archives/spice-devel/2016-August/031389.html

No, it's not used... otherwise it won't compile... 

> On Tue, Aug 16, 2016 at 1:22 PM, Frediano Ziglio < fzig...@redhat.com >
> wrote:

> > >
> 
> > > This patch introduces structures that are used to communicate between
> 
> > > win-vdagent and qxl-wddm-dod.
> 
> > >
> 
> > > This patch should be applied before applying this patch:
> 
> > > https://lists.freedesktop.org/archives/spice-devel/2016-August/031386.html
> 
> > >
> 

> > Why? Code compile even without this patch
> 

> > > Sameeh Jubran (1):
> 
> > > Add ioctls structures to qxl_windows.h
> 
> > >
> 
> > > spice/qxl_windows.h | 18 ++
> 
> > > 1 file changed, 14 insertions(+), 4 deletions(-)
> 
> > >
> 

Frediano 
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-protocol] Adding ioctl structures for win-vdagent/qxl-wddm-dod

2016-08-16 Thread Sameeh Jubran
spice-protocol is a sub-project for win-vdagent. This patch intreduces the
structures that are used in this patch
*https://lists.freedesktop.org/archives/spice-devel/2016-August/031389.html
*

On Tue, Aug 16, 2016 at 1:22 PM, Frediano Ziglio  wrote:

> >
> > This patch introduces structures that are used to communicate between
> > win-vdagent and qxl-wddm-dod.
> >
> > This patch should be applied before applying this patch:
> > https://lists.freedesktop.org/archives/spice-devel/2016-
> August/031386.html
> >
>
> Why? Code compile even without this patch
>
> > Sameeh Jubran (1):
> >   Add ioctls structures to qxl_windows.h
> >
> >  spice/qxl_windows.h | 18 ++
> >  1 file changed, 14 insertions(+), 4 deletions(-)
> >
>
> Frediano
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin *
*Junior Software Engineer @ Daynix .*
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-protocol] Add ioctls structures to qxl_windows.h

2016-08-16 Thread Frediano Ziglio
> 
> This patch defines the structures of ioctls that are used between
> win-vdagent and the qxl-wddm-dod driver.
> 
> Signed-off-by: Sameeh Jubran 
> ---
>  spice/qxl_windows.h | 16 
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/spice/qxl_windows.h b/spice/qxl_windows.h
> index bc2ceff..c4776d4 100644
> --- a/spice/qxl_windows.h
> +++ b/spice/qxl_windows.h
> @@ -2,20 +2,28 @@
>  #define _H_QXL_WINDOWS
>  
>  #include 
> -
> +#include 
>  #include 
>  
>  enum {
>  QXL_ESCAPE_SET_CUSTOM_DISPLAY = 0x10001,
> -QXL_ESCAPE_MONITOR_CONFIG
> +QXL_ESCAPE_MONITOR_CONFIG,
> +QXL_ESCAPE_VDAGENT_RUNNING

Didn't we decide to remove this?

>  };
>  
> -typedef struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
> +struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
>  uint32_t xres;
>  uint32_t yres;
>  uint32_t bpp;
> -} QXLEscapeSetCustomDisplay;
> +};

API change here.

>  
> +struct SPICE_ATTR_PACKED QXL_ESCAPE {
> +uint32_t ioctl;
> +union {
> +QXLEscapeSetCustomDisplay custom_display;
> +QXLHead monitor_config;
> +};
> +};
>  #include 
>  
>  #endif /* _H_QXL_WINDOWS */

Frediano
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH spice-protocol] Adding ioctl structures for win-vdagent/qxl-wddm-dod

2016-08-16 Thread Frediano Ziglio
> 
> This patch introduces structures that are used to communicate between
> win-vdagent and qxl-wddm-dod.
> 
> This patch should be applied before applying this patch:
> https://lists.freedesktop.org/archives/spice-devel/2016-August/031386.html
> 

Why? Code compile even without this patch

> Sameeh Jubran (1):
>   Add ioctls structures to qxl_windows.h
> 
>  spice/qxl_windows.h | 18 ++
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 

Frediano
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-protocol] Adding ioctl structures for win-vdagent/qxl-wddm-dod

2016-08-16 Thread Sameeh Jubran
This patch introduces structures that are used to communicate between
win-vdagent and qxl-wddm-dod.

This patch should be applied before applying this patch:
https://lists.freedesktop.org/archives/spice-devel/2016-August/031386.html

Sameeh Jubran (1):
  Add ioctls structures to qxl_windows.h

 spice/qxl_windows.h | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

-- 
2.7.4

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH spice-protocol] Add ioctls structures to qxl_windows.h

2016-08-16 Thread Sameeh Jubran
This patch defines the structures of ioctls that are used between
win-vdagent and the qxl-wddm-dod driver.

Signed-off-by: Sameeh Jubran 
---
 spice/qxl_windows.h | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/spice/qxl_windows.h b/spice/qxl_windows.h
index bc2ceff..c4776d4 100644
--- a/spice/qxl_windows.h
+++ b/spice/qxl_windows.h
@@ -2,20 +2,28 @@
 #define _H_QXL_WINDOWS
 
 #include 
-
+#include 
 #include 
 
 enum {
 QXL_ESCAPE_SET_CUSTOM_DISPLAY = 0x10001,
-QXL_ESCAPE_MONITOR_CONFIG
+QXL_ESCAPE_MONITOR_CONFIG,
+QXL_ESCAPE_VDAGENT_RUNNING
 };
 
-typedef struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
+struct SPICE_ATTR_PACKED QXLEscapeSetCustomDisplay {
 uint32_t xres;
 uint32_t yres;
 uint32_t bpp;
-} QXLEscapeSetCustomDisplay;
+};
 
+struct SPICE_ATTR_PACKED QXL_ESCAPE {
+uint32_t ioctl;
+union {
+QXLEscapeSetCustomDisplay custom_display;
+QXLHead monitor_config;
+};
+};
 #include 
 
 #endif /* _H_QXL_WINDOWS */
-- 
2.7.4

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


Re: [Spice-devel] [PATCH libcacard] Do not fail, if the caller didn't pick up response from previous call

2016-08-16 Thread Marc-André Lureau
Hi

- Original Message -
> Hello all,
> cross-posting the originally opened pull request on github [1] (with
> attached patch):
> 
> During our testing of a new CAC driver in OpenSC, with this library, we
> encountered a problem with |libcacard| failing and the driver returning
> only a fraction of the requested objects.
> 
> The problem is that the Emulator wants to return the data (properly
> signalized by 61 (RESPONSE BYTES) in SW1), but this is ignored for some
> reason in some of our calls from OpenSC. The Emulator should not fail
> hard for the next independent request, rather silently drop the buffer
> and serve the ongoing APDU request (I would left for consideration to
> somehow log such problem).
> 
> Patch was successfully tested on Fedora 24 host and solves our problem
> (though we worked around the problem already in the driver too).
> 
> [1] https://github.com/SPICE/libcacard/pull/1

ack, and pushed

Please next time, use git send-email (with the default inline patch attachment)

Thanks
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH win-vdagent v7 3/3] Implementing WDDM interface to support multiple monitors and arbitrary resolution

2016-08-16 Thread Sameeh Jubran
The Direct3D 9 API operates on either the Windows XP display driver
model (XPDM) or the Windows Vista display driver model (WDDM), depending
on the operating system installed.

This patch implements the WDDM interface while using the CCD API to do
so. Moreover it introduces multiple monitors support and arbitrary
resolution for Windows 10 while preserving backward compatiblity with previous
versions of Windows.

Based on a patch by Sandy Stutsman 

Signed-off-by: Dmitry Fleytman 
Signed-off-by: Sameeh Jubran 
---
 vdagent/display_configuration.cpp | 355 +-
 vdagent/display_configuration.h   |  47 +
 2 files changed, 400 insertions(+), 2 deletions(-)

diff --git a/vdagent/display_configuration.cpp 
b/vdagent/display_configuration.cpp
index 01fdbb0..1504a60 100755
--- a/vdagent/display_configuration.cpp
+++ b/vdagent/display_configuration.cpp
@@ -153,6 +153,56 @@ struct DISPLAYCONFIG_PATH_INFO {
 UINT32 flags;
 };
 
+/* The following definitions and structures are taken
+from here 
https://github.com/notr1ch/DWMCapture/blob/master/DWMCaptureSource.cpp */
+
+enum D3DKMT_ESCAPETYPE {
+D3DKMT_ESCAPE_DRIVERPRIVATE = 0
+};
+
+struct D3DDDI_ESCAPEFLAGS {
+union {
+struct {
+UINTReserved : 31;
+};
+UINTValue;
+};
+};
+
+struct D3DKMT_ESCAPE {
+D3D_HANDLE hAdapter;
+D3D_HANDLE hDevice;
+D3DKMT_ESCAPETYPE Type;
+D3DDDI_ESCAPEFLAGS Flags;
+VOID* pPrivateDriverData;
+UINT PrivateDriverDataSize;
+D3D_HANDLE hContext;
+};
+
+struct D3DKMT_OPENADAPTERFROMHDC {
+HDC hDc;
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+UINT VidPnSourceId;
+};
+
+struct D3DKMT_CLOSEADAPTER {
+D3D_HANDLE hAdapter;
+};
+
+struct D3DKMT_OPENADAPTERFROMDEVICENAME {
+const WCHAR *pDeviceName;
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+};
+
+struct D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME {
+WCHAR DeviceName[32];
+D3D_HANDLE hAdapter;
+LUID AdapterLuid;
+UINT VidPnSourceId;
+};
+
 struct QXLMonitorEscape {
 QXLMonitorEscape(DEVMODE* dev_mode)
 {
@@ -172,13 +222,45 @@ struct QxlCustomEscapeObj : public 
QXLEscapeSetCustomDisplay {
 yres = height;
 bpp = bitsPerPel;
 }
-QxlCustomEscapeObj() {};
+};
+
+struct WDDMCustomDisplayEscape {
+WDDMCustomDisplayEscape(DEVMODE* dev_mode)
+{
+_ioctl = QXL_ESCAPE_SET_CUSTOM_DISPLAY;
+_custom.bpp  = dev_mode->dmBitsPerPel;
+_custom.xres = dev_mode->dmPelsWidth;
+_custom.yres = dev_mode->dmPelsHeight;
+}
+uint32_t_ioctl;
+QXLEscapeSetCustomDisplay   _custom;
+};
+
+struct WDDMMonitorConfigEscape {
+WDDMMonitorConfigEscape(DisplayMode* mode)
+{
+_ioctl = QXL_ESCAPE_MONITOR_CONFIG;
+_head.id = _head.surface_id = 0;
+_head.x = mode->get_pos_x();
+_head.y = mode->get_pos_y();
+_head.width = mode->get_width();
+_head.height = mode->get_height();
+}
+uint32_t_ioctl;
+QXLHead _head;
 };
 
 DisplayConfig* DisplayConfig::create_config()
 {
 DisplayConfig* new_interface;
-new_interface = new XPDMInterface();
+/* Try to open a WDDM adapter.
+If that failed, assume we have an XPDM driver */
+try {
+new_interface = new  WDDMInterface();
+}
+catch (std::exception& e) {
+new_interface = new XPDMInterface();
+}
 return new_interface;
 }
 
@@ -328,6 +410,275 @@ bool XPDMInterface::find_best_mode(LPCTSTR Device, 
DEVMODE* dev_mode)
 return NT_SUCCESS(status);
 }
 
+WDDMInterface::WDDMInterface()
+: _pfnOpen_adapter_hdc(NULL)
+, _pfnClose_adapter(NULL)
+, _pfnEscape(NULL)
+, _pfnOpen_adapter_device_name(NULL)
+, _pfnOpen_adapter_gdi_name(NULL)
+{
+LONG error(0);
+//Can we find the D3D calls we need?
+if (!init_d3d_api()) {
+throw std::exception();
+}
+
+//Initialize  CCD path stuff
+if (!_ccd.query_display_config()) {
+throw std::exception();
+}
+
+if (!_ccd.set_display_config(error)) {
+throw std::exception();
+}
+}
+
+bool WDDMInterface::is_attached(DISPLAY_DEVICE* dev_info)
+{
+return _ccd.is_attached(dev_info->DeviceName);
+}
+
+bool WDDMInterface::set_monitor_state(LPCTSTR device_name, DEVMODE* dev_mode, 
MONITOR_STATE state)
+{
+   return  _ccd.set_path_state(device_name, state);
+}
+
+bool WDDMInterface::custom_display_escape(LPCTSTR device_name, DEVMODE* 
dev_mode)
+{
+DISPLAYCONFIG_MODE_INFO* mode = _ccd.get_active_mode(device_name, false);
+if (!mode) {
+return false;
+}
+
+//Don't bother if we are already set to the new resolution
+if (mode->sourceMode.width == dev_mode->dmPelsWidth &&
+mode->sourceMode.height == dev_mode->dmPelsHeight) {
+return true;
+}
+
+vd_printf("%s: updating %S resolution\n", __FUNCTION__, device_name);
+
+WDDMCustomDisplayEscape wddm_escape(dev_mode);
+if (es

[Spice-devel] [PATCH win-vdagent v7 0/3] Adding multiple monitors and arbitrary resolution for Windows 10

2016-08-16 Thread Sameeh Jubran
Diffrences from previous patches:
* Fixed a bug when driver is disabled and enabled.
* Moved ioctls structures to qxl_windows.h
* Changes pointed out by Frediano.
* Cosmetic changes.


Sameeh Jubran (3):
  Introducing Windows CCD API
  Encapsulating XPDM implementation
  Implementing WDDM interface to support multiple monitors and arbitrary
resolution

 Makefile.am   |2 +
 vdagent/desktop_layout.cpp|  148 ++
 vdagent/desktop_layout.h  |9 +-
 vdagent/display_configuration.cpp | 1035 +
 vdagent/display_configuration.h   |  175 +++
 5 files changed, 1247 insertions(+), 122 deletions(-)
 create mode 100755 vdagent/display_configuration.cpp
 create mode 100755 vdagent/display_configuration.h

-- 
2.7.4

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH win-vdagent v7 2/3] Encapsulating XPDM implementation

2016-08-16 Thread Sameeh Jubran
The Direct3D 9 API operates on either the Windows XP display driver
model (XPDM) or the Windows Vista display driver model (WDDM), depending
on the operating system installed.

This patch encapsulates the current XPDM interface implementation into
XPDMInterface class which inherits DisplayConfig class. This patch
makes it easier to introduce WDDM interface to Vdagent in future
patches.

Based on a patch by Sandy Stutsman 

Signed-off-by: Dmitry Fleytman 
Signed-off-by: Sameeh Jubran 
---
 vdagent/desktop_layout.cpp| 148 +++-
 vdagent/desktop_layout.h  |   9 +-
 vdagent/display_configuration.cpp | 175 ++
 vdagent/display_configuration.h   |  36 
 4 files changed, 246 insertions(+), 122 deletions(-)

diff --git a/vdagent/desktop_layout.cpp b/vdagent/desktop_layout.cpp
index a7666ca..9c3e873 100644
--- a/vdagent/desktop_layout.cpp
+++ b/vdagent/desktop_layout.cpp
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include "desktop_layout.h"
+#include "display_configuration.h"
 #include "vdlog.h"
 
 #ifdef __MINGW32__
@@ -35,15 +36,17 @@ void DisplayMode::set_res(DWORD width, DWORD height, DWORD 
depth)
 DesktopLayout::DesktopLayout()
 : _total_width (0)
 , _total_height (0)
-, _send_monitors_position(false)
+, _display_config (NULL)
 {
 MUTEX_INIT(_mutex);
+_display_config = DisplayConfig::create_config();
 get_displays();
 }
 
 DesktopLayout::~DesktopLayout()
 {
 clean_displays();
+delete _display_config;
 }
 
 void DesktopLayout::get_displays()
@@ -59,6 +62,7 @@ void DesktopLayout::get_displays()
 unlock();
 return;
 }
+_display_config->update_config_path();
 clean_displays();
 ZeroMemory(&dev_info, sizeof(dev_info));
 dev_info.cb = sizeof(dev_info);
@@ -82,12 +86,13 @@ void DesktopLayout::get_displays()
 _displays[i] = NULL;
 }
 }
-attached = !!(dev_info.StateFlags & 
DISPLAY_DEVICE_ATTACHED_TO_DESKTOP);
+attached = _display_config->is_attached(&dev_info);
+
 EnumDisplaySettings(dev_info.DeviceName, ENUM_CURRENT_SETTINGS, &mode);
 _displays[display_id] = new DisplayMode(mode.dmPosition.x, 
mode.dmPosition.y,
 mode.dmPelsWidth, 
mode.dmPelsHeight,
 mode.dmBitsPerPel, attached);
-update_monitor_config(dev_info.DeviceName, _displays[display_id]);
+_display_config->update_monitor_config(dev_info.DeviceName, 
_displays[display_id], &mode);
 }
 normalize_displays_pos();
 unlock();
@@ -121,6 +126,7 @@ void DesktopLayout::set_displays()
 unlock();
 return;
 }
+_display_config->update_config_path();
 ZeroMemory(&dev_info, sizeof(dev_info));
 dev_info.cb = sizeof(dev_info);
 ZeroMemory(&dev_mode, sizeof(dev_mode));
@@ -146,28 +152,32 @@ void DesktopLayout::set_displays()
 break;
 }
 DisplayMode * mode(_displays.at(display_id));
-if (!init_dev_mode(dev_info.DeviceName, &dev_mode, mode, normal_x, 
normal_y, true)) {
+if (!init_dev_mode(dev_info.DeviceName, &dev_mode, mode)) {
 vd_printf("No suitable mode found for display %S", 
dev_info.DeviceName);
 break;
 }
 vd_printf("Set display mode %lux%lu", dev_mode.dmPelsWidth, 
dev_mode.dmPelsHeight);
-LONG ret = ChangeDisplaySettingsEx(dev_info.DeviceName, &dev_mode, 
NULL,
-   CDS_UPDATEREGISTRY | CDS_NORESET, 
NULL);
-if (ret == DISP_CHANGE_SUCCESSFUL) {
+if (_display_config->update_dev_mode_position(dev_info.DeviceName, 
&dev_mode,
+ mode->_pos_x - normal_x,
+ mode->_pos_y - normal_y)) 
{
 dev_sets++;
-update_monitor_config(dev_info.DeviceName, mode);
+_display_config->update_monitor_config(dev_info.DeviceName, mode, 
&dev_mode);
 }
 if (!is_qxl) {
 display_id++;
 }
 }
 if (dev_sets) {
-ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
+_display_config->update_display_settings();
 normalize_displays_pos();
 }
 unlock();
 }
 
+void DesktopLayout::set_position_configurable(bool flag) {
+_display_config->set_monitors_config(flag);
+}
+
 // Normalize all display positions to non-negative coordinates and update 
total width and height of
 // the virtual desktop. Caller is responsible to lock() & unlock().
 void DesktopLayout::normalize_displays_pos()
@@ -265,125 +275,29 @@ bool DesktopLayout::get_qxl_device_id(WCHAR* device_key, 
DWORD* device_id)
 return key_found;
 }
 
-bool DesktopLayout::init_dev_mode(LPCTSTR dev_name, DEVMODE* dev_mode, 
DisplayMode* mode,
-  LONG normal_x, LONG normal_y, bool set_pos)

[Spice-devel] [PATCH win-vdagent v7 1/3] Introducing Windows CCD API

2016-08-16 Thread Sameeh Jubran
The Connecting and Configuring Displays (CCD) Win32 APIs
provide more control over the desktop display setup. The CCD APIs
move away from using Windows Graphics Device Interface (GDI)
concepts like view name and toward Windows Display Driver Model
(WDDM) concepts like adapter, source, and target identifiers.
More info on the CCD API can be found here:
https://msdn.microsoft.com/en-us/library/windows/hardware/ff539590(v=vs.85).aspx

This patch introduces partial functionality from the CCD API
needed by vdagent. It is needed by vdagent in order to support
multiple monitors and arbitrary resolution on Windows 10.

Acked-by: Frediano Ziglio 

Based on a patch by Sandy Stutsman 

Signed-off-by: Dmitry Fleytman 
Signed-off-by: Sameeh Jubran 
---
 Makefile.am   |   2 +
 vdagent/display_configuration.cpp | 509 ++
 vdagent/display_configuration.h   |  92 +++
 3 files changed, 603 insertions(+)
 create mode 100755 vdagent/display_configuration.cpp
 create mode 100755 vdagent/display_configuration.h

diff --git a/Makefile.am b/Makefile.am
index c3fc6bf..84507e8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,6 +31,8 @@ vdagent_SOURCES = \
common/vdcommon.h   \
common/vdlog.cpp\
common/vdlog.h  \
+   vdagent/display_configuration.cpp \
+   vdagent/display_configuration.h \
vdagent/desktop_layout.cpp  \
vdagent/desktop_layout.h\
vdagent/display_setting.cpp \
diff --git a/vdagent/display_configuration.cpp 
b/vdagent/display_configuration.cpp
new file mode 100755
index 000..8e4ad16
--- /dev/null
+++ b/vdagent/display_configuration.cpp
@@ -0,0 +1,509 @@
+/*
+Copyright (C) 2015-2016 Red Hat, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of
+the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see .
+*/
+
+#include "display_configuration.h"
+#include 
+
+/* The following definitions and structures are taken
+from the wine project repository and can be found
+under: "wine/include/wingdi.h" */
+
+#define QDC_ALL_PATHS  0x0001
+
+#define SDC_USE_SUPPLIED_DISPLAY_CONFIG0x0020
+#define SDC_APPLY  0x0080
+#define SDC_SAVE_TO_DATABASE   0x0200
+#define SDC_FORCE_MODE_ENUMERATION 0x1000
+
+#define DISPLAYCONFIG_PATH_ACTIVE  0x0001
+#define DISPLAYCONFIG_PATH_MODE_IDX_INVALID0x
+
+enum DISPLAYCONFIG_DEVICE_INFO_TYPE {
+DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1
+};
+
+enum DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY {};
+
+enum DISPLAYCONFIG_ROTATION {};
+
+enum DISPLAYCONFIG_SCANLINE_ORDERING {};
+
+enum DISPLAYCONFIG_SCALING {};
+
+enum DISPLAYCONFIG_PIXELFORMAT {};
+
+enum DISPLAYCONFIG_MODE_INFO_TYPE {};
+
+struct DISPLAYCONFIG_DEVICE_INFO_HEADER {
+DISPLAYCONFIG_DEVICE_INFO_TYPE type;
+UINT32 size;
+LUID   adapterId;
+UINT32 id;
+};
+
+struct DISPLAYCONFIG_SOURCE_DEVICE_NAME {
+DISPLAYCONFIG_DEVICE_INFO_HEADER  header;
+WCHAR viewGdiDeviceName[CCHDEVICENAME];
+};
+
+struct DISPLAYCONFIG_DESKTOP_IMAGE_INFO {
+POINTL PathSourceSize;
+RECTL DesktopImageRegion;
+RECTL DesktopImageClip;
+};
+
+struct DISPLAYCONFIG_RATIONAL {
+UINT32Numerator;
+UINT32Denominator;
+};
+
+struct DISPLAYCONFIG_2DREGION {
+UINT32 cx;
+UINT32 cy;
+};
+
+struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO {
+UINT64 pixelRate;
+DISPLAYCONFIG_RATIONAL hSyncFreq;
+DISPLAYCONFIG_RATIONAL vSyncFreq;
+DISPLAYCONFIG_2DREGION activeSize;
+DISPLAYCONFIG_2DREGION totalSize;
+union {
+struct {
+UINT32 videoStandard :16;
+UINT32 vSyncFreqDivider :6;
+UINT32 reserved :10;
+} AdditionalSignalInfo;
+UINT32 videoStandard;
+} DUMMYUNIONNAME;
+DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
+};
+
+struct DISPLAYCONFIG_TARGET_MODE {
+DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
+};
+
+struct DISPLAYCONFIG_SOURCE_MODE {
+UINT32 width;
+UINT32 height;
+DISPLAYCONFIG_PIXELFORMAT pixelFormat;
+POINTL position;
+};
+
+struct DISPLAYCONFIG_MODE_INFO {
+DISPLAYCONFIG_MODE_INFO_TYPE infoType;
+UINT32 id;
+LUID adapterId;
+union {
+DI