Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 31828)
@@ -39,5 +39,10 @@
 HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
         IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc,
-        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     HRESULT hr;
@@ -46,5 +51,5 @@
             size, usage, format_desc, pool, parent, parent_ops
 #ifdef VBOXWDDM
-            , NULL, NULL /* <- no need this info here */
+            , shared_handle, pvClientMem
 #endif
             );
@@ -262,5 +267,20 @@
     if (gl_tex->name == 0) {
         *set_surface_desc = TRUE;
-        glGenTextures(1, &gl_tex->name);
+#ifdef VBOXWDDM
+        if (VBOXSHRC_IS_SHARED_OPENED(This))
+        {
+            gl_tex->name = VBOXSHRC_GET_SHAREHANDLE(This);
+        }
+        else
+#endif
+        {
+            glGenTextures(1, &gl_tex->name);
+#ifdef VBOXWDDM
+            if (VBOXSHRC_IS_SHARED(This))
+            {
+                VBOXSHRC_SET_SHAREHANDLE(This, gl_tex->name);
+            }
+#endif
+        }
         checkGLcall("glGenTextures");
         TRACE("Generated texture %d\n", gl_tex->name);
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 31828)
@@ -1508,4 +1508,8 @@
         GL_EXTCALL(glProvokingVertexEXT(GL_FIRST_VERTEX_CONVENTION_EXT));
     }
+
+#ifdef VBOXWDDM
+    GL_EXTCALL(glChromiumParameteriCR(GL_SHARE_CONTEXT_RESOURCES_CR, GL_TRUE));
+#endif
 
     LEAVE_GL();
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 31828)
@@ -489,5 +489,10 @@
 
     hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_CUBETEXTURE,
-            device, 0, usage, format_desc, pool, parent, parent_ops);
+            device, 0, usage, format_desc, pool, parent, parent_ops
+#ifdef VBOXWDDM
+        , NULL
+        , NULL
+#endif
+            );
     if (FAILED(hr))
     {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 31828)
@@ -2182,4 +2182,8 @@
     gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
 
+#ifdef VBOXWDDM
+    gl_info->supported[VBOX_SHARED_CONTEXTS] = TRUE;
+#endif
+
     while (*GL_Extensions)
     {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 31828)
@@ -66,4 +66,13 @@
         resource->heapMemory = NULL;
     }
+    else if (pool == WINED3DPOOL_DEFAULT && shared_handle)
+    {
+        resource->allocatedMemory = NULL;
+        resource->heapMemory = NULL;
+        resource->sharerc_handle = shared_handle;
+        resource->sharerc_flags = VBOXSHRC_F_SHARED;
+        if (*shared_handle)
+            resource->sharerc_flags |= VBOXSHRC_F_SHARED_OPENED;
+    }
     else
 #endif
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 31828)
@@ -482,4 +482,10 @@
         return hr;
     }
+#ifdef VBOXWDDM
+    if (shared_handle && !*shared_handle)
+    {
+        *shared_handle = VBOXSHRC_GET_SHAREHANDLE(surface);
+    }
+#endif
 
     return hr;
@@ -521,4 +527,10 @@
     }
 
+#ifdef VBOXWDDM
+    if (VBOXSHRC_IS_SHARED(This))
+    {
+        VBOXSHRC_SET_SHAREHANDLE(This, new_name);
+    }
+#endif
     *name = new_name;
     surface_force_reload(iface);
@@ -979,4 +991,8 @@
 }
 
+#ifdef VBOXWDDM
+static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect);
+#endif
+
 /* Slightly inefficient way to handle multiple dirty rects but it works :) */
 void surface_add_dirty_rect(IWineD3DSurface *iface, const RECT *dirty_rect)
@@ -985,8 +1001,21 @@
     IWineD3DBaseTexture *baseTexture = NULL;
 
-    if (!(This->Flags & SFLAG_INSYSMEM) && (This->Flags & SFLAG_INTEXTURE))
-        IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
-
-    IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
+#ifdef VBOXWDDM
+    if (VBOXSHRC_IS_SHARED(This))
+    {
+        if (!VBOXSHRC_IS_SHARED_OPENED(This))
+            IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INTEXTURE, NULL);
+        else
+            This->Flags |= SFLAG_INTEXTURE;
+    }
+    else
+#endif
+    {
+        if (!(This->Flags & SFLAG_INSYSMEM) && (This->Flags & SFLAG_INTEXTURE))
+            IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
+
+        IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
+    }
+
     if (dirty_rect)
     {
@@ -2601,5 +2630,20 @@
         {
             if (!*name) {
-                glGenTextures(1, name);
+#ifdef VBOXWDDM
+                if (VBOXSHRC_IS_SHARED_OPENED(This))
+                {
+                    *name = VBOXSHRC_GET_SHAREHANDLE(This);
+                }
+                else
+#endif
+                {
+                    glGenTextures(1, name);
+#ifdef VBOXWDDM
+                    if (VBOXSHRC_IS_SHARED(This))
+                    {
+                        VBOXSHRC_SET_SHAREHANDLE(This, *name);
+                    }
+#endif
+                }
                 checkGLcall("glGenTextures");
                 TRACE("Surface %p given name %d\n", This, *name);
@@ -4022,5 +4066,10 @@
     }
 
-    This->Flags |= SFLAG_INSYSMEM;
+#ifdef VBOXWDDM
+    if (!VBOXSHRC_IS_SHARED(This))
+#endif
+    {
+        This->Flags |= SFLAG_INSYSMEM;
+    }
 
     return WINED3D_OK;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 31828)
@@ -513,5 +513,9 @@
 
     hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE,
-            device, 0, usage, format_desc, pool, parent, parent_ops);
+            device, 0, usage, format_desc, pool, parent, parent_ops
+#ifdef VBOXWDDM
+            , shared_handle, pvClientMem
+#endif
+        );
     if (FAILED(hr))
     {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c	(revision 31828)
@@ -410,5 +410,9 @@
 
     hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_VOLUMETEXTURE,
-            device, 0, usage, format_desc, pool, parent, parent_ops);
+            device, 0, usage, format_desc, pool, parent, parent_ops
+#ifdef VBOXWDDM
+        , NULL, NULL
+#endif
+            );
     if (FAILED(hr))
     {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 31828)
@@ -1842,4 +1842,8 @@
     WGL_ARB_PIXEL_FORMAT,
     WGL_WINE_PIXEL_FORMAT_PASSTHROUGH,
+
+#ifdef VBOXWDDM
+    VBOX_SHARED_CONTEXTS,
+#endif
     /* Internally used */
     WINE_NORMALIZED_TEXRECT,
@@ -3768,4 +3772,16 @@
 typedef BOOL (WINAPI *WINED3D_PFNWGLSETPIXELFORMATWINE)(HDC hdc, int iPixelFormat,
         const PIXELFORMATDESCRIPTOR *ppfd);
+
+#ifdef VBOXWDDM
+#define GL_SHARE_CONTEXT_RESOURCES_CR 0x8B27
+typedef void (WINE_GLAPI *PGLFNCHROMIUMPARAMETERUCR)(GLenum param, GLint value);
+
+# define VBOXWDDM_GL_EXT_FUNCS_GEN \
+        USE_GL_FUNC(PGLFNCHROMIUMPARAMETERUCR, \
+                glChromiumParameteriCR,                VBOX_SHARED_CONTEXTS,            NULL) \
+
+#else
+# define VBOXWDDM_GL_EXT_FUNCS_GEN
+#endif
 
 #define GL_EXT_FUNCS_GEN \
@@ -4494,5 +4510,6 @@
             glXGetVideoSyncSGI,                         SGI_VIDEO_SYNC,                 NULL) \
     USE_GL_FUNC(PGLXFNWAITVIDEOSYNCSGIPROC, \
-            glXWaitVideoSyncSGI,                        SGI_VIDEO_SYNC,                 NULL)
+            glXWaitVideoSyncSGI,                        SGI_VIDEO_SYNC,                 NULL) \
+    VBOXWDDM_GL_EXT_FUNCS_GEN
 
 #define WGL_EXT_FUNCS_GEN \
Index: trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 31827)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 31828)
@@ -53,4 +53,8 @@
 #include "wine/list.h"
 #include "wine/rbtree.h"
+
+#ifdef VBOXWDDM
+# include "vboxsharedrc.h"
+#endif
 
 /* Driver quirks */
@@ -1804,4 +1808,8 @@
     BYTE                   *allocatedMemory; /* Pointer to the real data location */
     BYTE                   *heapMemory; /* Pointer to the HeapAlloced block of memory */
+#ifdef VBOXWDDM
+    DWORD                   sharerc_flags; /* shared resource flags */
+    DWORD                   sharerc_handle;
+#endif
     struct list             privateData;
     struct list             resource_list_entry;
@@ -1921,5 +1929,10 @@
 HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
         IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc,
-        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        ) DECLSPEC_HIDDEN;
 HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface,
         WINED3DTEXTUREFILTERTYPE filter_type) DECLSPEC_HIDDEN;
@@ -2230,5 +2243,4 @@
 #ifdef VBOXWDDM
 # define SFLAG_CLIENTMEM     0x10000000 /* SYSMEM surface using client-supplied memory buffer */
-
 # define SFLAG_DONOTFREE_VBOXWDDM SFLAG_CLIENTMEM
 #else
