Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h	(revision 42499)
@@ -192,5 +192,11 @@
 
 HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
-        HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
+        HWND focus_window, DWORD flags
+#ifdef VBOX_WITH_WDDM
+        , VBOXWINEEX_D3DPRESENT_PARAMETERS *parameters
+#else
+        , D3DPRESENT_PARAMETERS *parameters
+#endif
+        ) DECLSPEC_HIDDEN;
 
 /* IDirect3DDevice9: */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 42499)
@@ -3153,6 +3153,17 @@
 };
 
+#ifdef VBOX_WITH_WDDM
+# define PP_BASE(_p) (&(_p)->Base)
+#else
+# define PP_BASE(_p) (_p)
+#endif
 HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
-        HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
+        HWND focus_window, DWORD flags
+#ifdef VBOX_WITH_WDDM
+        , VBOXWINEEX_D3DPRESENT_PARAMETERS *parameters
+#else
+        , D3DPRESENT_PARAMETERS *parameters
+#endif
+        )
 {
     WINED3DPRESENT_PARAMETERS *wined3d_parameters;
@@ -3209,20 +3220,23 @@
     for (i = 0; i < count; ++i)
     {
-        wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
-        wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
-        wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
-        wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
-        wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
-        wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
-        wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
-        wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
-        wined3d_parameters[i].Windowed = parameters[i].Windowed;
-        wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
+        wined3d_parameters[i].BackBufferWidth = PP_BASE(&parameters[i])->BackBufferWidth;
+        wined3d_parameters[i].BackBufferHeight =PP_BASE(&parameters[i])->BackBufferHeight;
+        wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(PP_BASE(&parameters[i])->BackBufferFormat);
+        wined3d_parameters[i].BackBufferCount = PP_BASE(&parameters[i])->BackBufferCount;
+        wined3d_parameters[i].MultiSampleType =PP_BASE(&parameters[i])->MultiSampleType;
+        wined3d_parameters[i].MultiSampleQuality =PP_BASE(&parameters[i])->MultiSampleQuality;
+        wined3d_parameters[i].SwapEffect =PP_BASE(&parameters[i])->SwapEffect;
+        wined3d_parameters[i].hDeviceWindow =PP_BASE(&parameters[i])->hDeviceWindow;
+        wined3d_parameters[i].Windowed =PP_BASE(&parameters[i])->Windowed;
+        wined3d_parameters[i].EnableAutoDepthStencil =PP_BASE(&parameters[i])->EnableAutoDepthStencil;
         wined3d_parameters[i].AutoDepthStencilFormat =
-                wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
-        wined3d_parameters[i].Flags = parameters[i].Flags;
-        wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
-        wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
+                wined3dformat_from_d3dformat(PP_BASE(&parameters[i])->AutoDepthStencilFormat);
+        wined3d_parameters[i].Flags =PP_BASE(&parameters[i])->Flags;
+        wined3d_parameters[i].FullScreen_RefreshRateInHz =PP_BASE(&parameters[i])->FullScreen_RefreshRateInHz;
+        wined3d_parameters[i].PresentationInterval =PP_BASE(&parameters[i])->PresentationInterval;
         wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
+#ifdef VBOX_WITH_WDDM
+        wined3d_parameters[i].pHgsmi = parameters[i].pHgsmi;
+#endif
     }
 
@@ -3244,19 +3258,19 @@
     for (i = 0; i < count; ++i)
     {
-        parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
-        parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
-        parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
-        parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
-        parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
-        parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
-        parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
-        parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
-        parameters[i].Windowed = wined3d_parameters[i].Windowed;
-        parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
-        parameters[i].AutoDepthStencilFormat =
+        PP_BASE(&parameters[i])->BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
+        PP_BASE(&parameters[i])->BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
+        PP_BASE(&parameters[i])->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
+        PP_BASE(&parameters[i])->BackBufferCount = wined3d_parameters[i].BackBufferCount;
+        PP_BASE(&parameters[i])->MultiSampleType = wined3d_parameters[i].MultiSampleType;
+        PP_BASE(&parameters[i])->MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
+        PP_BASE(&parameters[i])->SwapEffect = wined3d_parameters[i].SwapEffect;
+        PP_BASE(&parameters[i])->hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
+        PP_BASE(&parameters[i])->Windowed = wined3d_parameters[i].Windowed;
+        PP_BASE(&parameters[i])->EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
+        PP_BASE(&parameters[i])->AutoDepthStencilFormat =
                 d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
-        parameters[i].Flags = wined3d_parameters[i].Flags;
-        parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
-        parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
+        PP_BASE(&parameters[i])->Flags = wined3d_parameters[i].Flags;
+        PP_BASE(&parameters[i])->FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
+        PP_BASE(&parameters[i])->PresentationInterval = wined3d_parameters[i].PresentationInterval;
     }
     HeapFree(GetProcessHeap(), 0, wined3d_parameters);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 42499)
@@ -523,5 +523,9 @@
     }
 
-    hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
+    hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags,
+#ifdef VBOX_WITH_WDDM
+        (VBOXWINEEX_D3DPRESENT_PARAMETERS *)
+#endif
+                    parameters);
     if (FAILED(hr))
     {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/VBoxWineEx.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/VBoxWineEx.h	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/VBoxWineEx.h	(revision 42499)
@@ -84,4 +84,10 @@
 VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9Present(IDirect3DSwapChain9 *iface,
                                 IDirect3DSurface9 *surf); /* use the given surface as a frontbuffer content source */
+
+typedef struct VBOXWINEEX_D3DPRESENT_PARAMETERS
+{
+    D3DPRESENT_PARAMETERS Base;
+    struct VBOXUHGSMI *pHgsmi;
+} VBOXWINEEX_D3DPRESENT_PARAMETERS, *PVBOXWINEEX_D3DPRESENT_PARAMETERS;
 #ifdef __cplusplus
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/wine/wined3d.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/wine/wined3d.h	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/libWineStub/include/wine/wined3d.h	(revision 42499)
@@ -2262,4 +2262,7 @@
     UINT PresentationInterval;
     BOOL AutoRestoreDisplayMode;
+#ifdef VBOX_WITH_WDDM
+    struct VBOXUHGSMI *pHgsmi;
+#endif
 } WINED3DPRESENT_PARAMETERS;
 typedef struct _WINED3DSURFACE_DESC {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 42499)
@@ -1532,5 +1532,9 @@
  *****************************************************************************/
 struct wined3d_context *context_create(IWineD3DSwapChainImpl *swapchain, IWineD3DSurfaceImpl *target,
-        const struct wined3d_format_desc *ds_format_desc)
+        const struct wined3d_format_desc *ds_format_desc
+#ifdef VBOX_WITH_WDDM
+        , struct VBOXUHGSMI *pHgsmi
+#endif
+        )
 {
     IWineD3DDeviceImpl *device = swapchain->device;
@@ -1549,4 +1553,12 @@
     TRACE("swapchain %p, target %p, window %p.\n", swapchain, target, swapchain->win_handle);
 
+#ifdef VBOX_WITH_WDDM
+    if (!pHgsmi)
+    {
+        ERR("HGSMI should be specified!");
+        return NULL;
+    }
+#endif
+
     ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
     if (!ret)
@@ -1644,5 +1656,11 @@
     }
 
-    ctx = pwglCreateContext(hdc);
+    ctx = pVBoxCreateContext(hdc
+#ifdef VBOX_WITH_WDDM
+            , pHgsmi
+#else
+            , NULL
+#endif
+            );
     if (device->numContexts)
     {
@@ -1955,5 +1973,9 @@
     {
         Assert(!device->NumberOfSwapChains);
-        context = context_create(swapchain, target, ds_format_desc);
+        context = context_create(swapchain, target, ds_format_desc
+#ifdef VBOX_WITH_WDDM
+                , device->pHgsmi
+#endif
+                );
     }
     else
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 42499)
@@ -1605,4 +1605,12 @@
     if(!This->adapter->opengl) return WINED3DERR_INVALIDCALL;
 
+#ifdef VBOX_WITH_WDDM
+    if (!pPresentationParameters->pHgsmi)
+    {
+        ERR("hgsmi not specified!");
+        return WINED3DERR_INVALIDCALL;
+    }
+    This->pHgsmi = pPresentationParameters->pHgsmi;
+#endif
     TRACE("(%p) : Creating stateblock\n", This);
     /* Creating the startup stateBlock - Note Special Case: 0 => Don't fill in yet! */
@@ -6456,4 +6464,8 @@
     IWineD3DSurfaceImpl *target;
 
+#ifdef VBOX_WITH_WDDM
+    ERR("Should not be here!");
+#endif
+
 #ifndef VBOX_WITH_WDDM
     /* Recreate the primary swapchain's context */
@@ -6467,5 +6479,9 @@
 
     target = (IWineD3DSurfaceImpl *)(swapchain->backBuffer ? swapchain->backBuffer[0] : swapchain->frontBuffer);
-    if (!(context = context_create(swapchain, target, swapchain->ds_format)))
+    if (!(context = context_create(swapchain, target, swapchain->ds_format
+#ifdef VBOX_WITH_WDDM
+                , This->pHgsmi
+#endif
+            )))
     {
         WARN("Failed to create context.\n");
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 42499)
@@ -36,4 +36,8 @@
 #include <stdio.h>
 #include "wined3d_private.h"
+
+#ifdef VBOX_WITH_WDDM
+# include <VBox/VBoxCrHgsmi.h>
+#endif
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
@@ -254,5 +258,5 @@
 }
 
-static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
+static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx, struct VBOXUHGSMI *pHgsmi)
 {
     PIXELFORMATDESCRIPTOR pfd;
@@ -300,5 +304,5 @@
 
     /* Create a GL context. */
-    ctx->gl_ctx = pwglCreateContext(ctx->dc);
+    ctx->gl_ctx = pVBoxCreateContext(ctx->dc, pHgsmi);
     if (!ctx->gl_ctx)
     {
@@ -5309,4 +5313,5 @@
     BOOL ret;
     int ps_selected_mode, vs_selected_mode;
+    struct VBOXUHGSMI *pHgsmi = NULL;
 
     /* No need to hold any lock. The calling library makes sure only one thread calls
@@ -5355,4 +5360,5 @@
 #define USE_WGL_FUNC(pfn) p##pfn = (void*)GetProcAddress(mod_gl, #pfn);
     WGL_FUNCS_GEN;
+    VBOX_FUNCS_GEN;
 #undef USE_WGL_FUNC
 
@@ -5380,4 +5386,13 @@
     glDisableWINE = glDisable;
 
+#ifdef VBOX_WITH_WDDM
+    pHgsmi = VBoxCrHgsmiCreate();
+    if (!pHgsmi)
+    {
+        ERR("VBoxCrHgsmiCreate failed");
+        goto nogl_adapter;
+    }
+#endif
+
     /* For now only one default adapter */
     {
@@ -5406,5 +5421,5 @@
                 adapter->luid.HighPart, adapter->luid.LowPart);
 
-        if (!WineD3D_CreateFakeGLContext(&fake_gl_ctx))
+        if (!WineD3D_CreateFakeGLContext(&fake_gl_ctx, pHgsmi))
         {
             ERR("Failed to get a gl context for default adapter\n");
@@ -5595,4 +5610,9 @@
     TRACE("%u adapters successfully initialized\n", This->adapter_count);
 
+#ifdef VBOX_WITH_WDDM
+    VBoxCrHgsmiDestroy(pHgsmi);
+    pHgsmi = NULL;
+#endif
+
     return TRUE;
 
@@ -5615,4 +5635,12 @@
 #endif
     initPixelFormatsNoGL(&This->adapters[0].gl_info);
+
+#ifdef VBOX_WITH_WDDM
+    if (pHgsmi)
+    {
+        VBoxCrHgsmiDestroy(pHgsmi);
+        pHgsmi = NULL;
+    }
+#endif
 
     This->adapter_count = 1;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c	(revision 42499)
@@ -1233,5 +1233,13 @@
     TRACE("Creating a new context for swapchain %p, thread %d\n", This, GetCurrentThreadId());
 
-    if (!(ctx = context_create(This, (IWineD3DSurfaceImpl *)This->frontBuffer, This->ds_format)))
+#ifdef VBOX_WITH_WDDM
+     ERR("Should not be here");
+#endif
+
+    if (!(ctx = context_create(This, (IWineD3DSurfaceImpl *)This->frontBuffer, This->ds_format
+#ifdef VBOX_WITH_WDDM
+                , This->device->pHgsmi
+#endif
+            )))
     {
         ERR("Failed to create a new context for the swapchain\n");
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxext.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxext.c	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vboxext.c	(revision 42499)
@@ -18,4 +18,8 @@
 #include "wined3d_private.h"
 #include "vboxext.h"
+#ifdef VBOX_WITH_WDDM
+#include <VBox/VBoxCrHgsmi.h>
+#include <iprt/err.h>
+#endif
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_vbox);
@@ -282,6 +286,21 @@
 {
     HRESULT hr = S_OK;
+#ifdef VBOX_WITH_WDDM
+    int rc = VBoxCrHgsmiInit();
+    if (!RT_SUCCESS(rc))
+    {
+        ERR("VBoxCrHgsmiInit failed rc %d", rc);
+        return E_FAIL;
+    }
+#endif
     memset(&g_VBoxExtGlobal, 0, sizeof (g_VBoxExtGlobal));
     hr = VBoxExtWorkerCreate(&g_VBoxExtGlobal.Worker);
+    if (SUCCEEDED(hr))
+        return S_OK;
+
+    /* failure branch */
+#ifdef VBOX_WITH_WDDM
+    VBoxCrHgsmiTerm();
+#endif
     return hr;
 }
@@ -305,4 +324,9 @@
         return hr;
     }
+
+#ifdef VBOX_WITH_WDDM
+    VBoxCrHgsmiTerm();
+#endif
+
     return S_OK;
 }
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 42499)
@@ -1374,5 +1374,4 @@
 
 /* WGL functions */
-HGLRC (WINAPI *pwglCreateContext)(HDC) DECLSPEC_HIDDEN;
 BOOL (WINAPI *pwglDeleteContext)(HGLRC) DECLSPEC_HIDDEN;
 HGLRC (WINAPI *pwglGetCurrentContext)(void) DECLSPEC_HIDDEN;
@@ -1382,4 +1381,6 @@
 BOOL (WINAPI *pwglSwapLayerBuffers)(HDC, UINT) DECLSPEC_HIDDEN;
 BOOL (WINAPI *pwglShareLists)(HGLRC, HGLRC) DECLSPEC_HIDDEN;
+
+HGLRC (WINAPI *pVBoxCreateContext)(HDC, struct VBOXUHGSMI*) DECLSPEC_HIDDEN;
 
 #define GL_FUNCS_GEN \
@@ -1721,5 +1722,4 @@
 
 #define WGL_FUNCS_GEN \
-    USE_WGL_FUNC(wglCreateContext) \
     USE_WGL_FUNC(wglDeleteContext) \
     USE_WGL_FUNC(wglGetCurrentContext) \
@@ -1729,4 +1729,7 @@
     USE_WGL_FUNC(wglShareLists) \
     USE_WGL_FUNC(wglSwapLayerBuffers)
+
+#define VBOX_FUNCS_GEN \
+    USE_WGL_FUNC(VBoxCreateContext)
 
 /* OpenGL extensions. */
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 42426)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 42499)
@@ -1283,5 +1283,9 @@
         GLenum fbo_target, DWORD idx, IWineD3DSurfaceImpl *surface) DECLSPEC_HIDDEN;
 struct wined3d_context *context_create(IWineD3DSwapChainImpl *swapchain, IWineD3DSurfaceImpl *target,
-        const struct wined3d_format_desc *ds_format_desc) DECLSPEC_HIDDEN;
+        const struct wined3d_format_desc *ds_format_desc
+#ifdef VBOX_WITH_WDDM
+                , struct VBOXUHGSMI *pHgsmi
+#endif
+        ) DECLSPEC_HIDDEN;
 struct IWineD3DDeviceImpl *context_get_device(const struct wined3d_context *context); DECLSPEC_HIDDEN;
 #ifdef VBOX_WITH_WDDM
@@ -1800,4 +1804,8 @@
     struct wined3d_context **contexts;
     UINT                    numContexts;
+
+#ifdef VBOX_WITH_WDDM
+    struct VBOXUHGSMI *pHgsmi;
+#endif
 
 #ifdef VBOX_WINE_WITH_SHADER_CACHE
