[PATCH] WineD3D: support redirecting the primary context=0A=

Stefan Doesinger stefan at codeweavers.com
Tue Jul 29 12:09:34 CDT 2008


=0A=
---=0A=
 dlls/wined3d/device.c          |  153 =
++++++++++++++++++++++------------------=0A=
 dlls/wined3d/swapchain.c       |    6 +-=0A=
 dlls/wined3d/wined3d_private.h |    3 +=0A=
 3 files changed, 92 insertions(+), 70 deletions(-)=0A=
=0A=
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c=0A=
index 836b318..abcd90f 100644=0A=
--- a/dlls/wined3d/device.c=0A=
+++ b/dlls/wined3d/device.c=0A=
@@ -7239,15 +7239,92 @@ static BOOL =
is_display_mode_supported(IWineD3DDeviceImpl *This, WINED3DPRESENT_P=0A=
     return FALSE;=0A=
 }=0A=
 =0A=
+void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain =
*swapchain_iface) {=0A=
+    IWineD3DDeviceImpl *This =3D (IWineD3DDeviceImpl *) iface;=0A=
+    IWineD3DSwapChainImpl *swapchain =3D (IWineD3DSwapChainImpl *) =
swapchain_iface;=0A=
+    UINT i;=0A=
+    IWineD3DBaseShaderImpl *shader;=0A=
+=0A=
+    if (wined3d_settings.offscreen_rendering_mode =3D=3D ORM_FBO) {=0A=
+        reset_fbo_state((IWineD3DDevice *) This);=0A=
+    }=0A=
+=0A=
+    IWineD3DDevice_EnumResources(iface, reset_unload_resources, NULL);=0A=
+    LIST_FOR_EACH_ENTRY(shader, &This->shaders, IWineD3DBaseShaderImpl, =
baseShader.shader_list_entry) {=0A=
+        This->shader_backend->shader_destroy((IWineD3DBaseShader *) =
shader);=0A=
+    }=0A=
+=0A=
+    ENTER_GL();=0A=
+    if(This->depth_blt_texture) {=0A=
+        glDeleteTextures(1, &This->depth_blt_texture);=0A=
+        This->depth_blt_texture =3D 0;=0A=
+    }=0A=
+    if (This->depth_blt_rb) {=0A=
+        GL_EXTCALL(glDeleteRenderbuffersEXT(1, &This->depth_blt_rb));=0A=
+        This->depth_blt_rb =3D 0;=0A=
+        This->depth_blt_rb_w =3D 0;=0A=
+        This->depth_blt_rb_h =3D 0;=0A=
+    }=0A=
+    This->frag_pipe->free_private(iface);=0A=
+    This->shader_backend->shader_free_private(iface);=0A=
+=0A=
+    for (i =3D 0; i < GL_LIMITS(textures); i++) {=0A=
+        /* Textures are recreated below */=0A=
+        glDeleteTextures(1, &This->dummyTextureName[i]);=0A=
+        checkGLcall("glDeleteTextures(1, &This->dummyTextureName[i])");=0A=
+        This->dummyTextureName[i] =3D 0;=0A=
+    }=0A=
+    LEAVE_GL();=0A=
+=0A=
+    while(This->numContexts) {=0A=
+        DestroyContext(This, This->contexts[0]);=0A=
+    }=0A=
+    This->activeContext =3D NULL;=0A=
+    HeapFree(GetProcessHeap(), 0, swapchain->context);=0A=
+    swapchain->context =3D NULL;=0A=
+    swapchain->num_contexts =3D 0;=0A=
+}=0A=
+=0A=
+HRESULT create_primary_opengl_context(IWineD3DDevice *iface, =
IWineD3DSwapChain *swapchain_iface) {=0A=
+    IWineD3DDeviceImpl *This =3D (IWineD3DDeviceImpl *) iface;=0A=
+    IWineD3DSwapChainImpl *swapchain =3D (IWineD3DSwapChainImpl *) =
swapchain_iface;=0A=
+    HRESULT hr;=0A=
+    IWineD3DSurfaceImpl *target;=0A=
+=0A=
+    /* Recreate the primary swapchain's context */=0A=
+    swapchain->context =3D HeapAlloc(GetProcessHeap(), 0, =
sizeof(*swapchain->context));=0A=
+    if(swapchain->backBuffer) {=0A=
+        target =3D (IWineD3DSurfaceImpl *) swapchain->backBuffer[0];=0A=
+    } else {=0A=
+        target =3D (IWineD3DSurfaceImpl *) swapchain->frontBuffer;=0A=
+    }=0A=
+    swapchain->context[0] =3D CreateContext(This, target, =
swapchain->win_handle, FALSE,=0A=
+                                          &swapchain->presentParms);=0A=
+    swapchain->num_contexts =3D 1;=0A=
+    This->activeContext =3D swapchain->context[0];=0A=
+=0A=
+    create_dummy_textures(This);=0A=
+=0A=
+    hr =3D This->shader_backend->shader_alloc_private(iface);=0A=
+    if(FAILED(hr)) {=0A=
+        ERR("Failed to recreate shader private data\n");=0A=
+        return hr;=0A=
+    }=0A=
+    hr =3D This->frag_pipe->alloc_private(iface);=0A=
+    if(FAILED(hr)) {=0A=
+        TRACE("Fragment pipeline private data couldn't be allocated\n");=0A=
+        return hr;=0A=
+    }=0A=
+=0A=
+    return WINED3D_OK;=0A=
+}=0A=
+=0A=
 static HRESULT WINAPI IWineD3DDeviceImpl_Reset(IWineD3DDevice* iface, =
WINED3DPRESENT_PARAMETERS* pPresentationParameters) {=0A=
     IWineD3DDeviceImpl *This =3D (IWineD3DDeviceImpl *) iface;=0A=
     IWineD3DSwapChainImpl *swapchain;=0A=
     HRESULT hr;=0A=
     BOOL DisplayModeChanged =3D FALSE;=0A=
     WINED3DDISPLAYMODE mode;=0A=
-    IWineD3DBaseShaderImpl *shader;=0A=
-    IWineD3DSurfaceImpl *target;=0A=
-    UINT i;=0A=
     TRACE("(%p)\n", This);=0A=
 =0A=
     hr =3D IWineD3DDevice_GetSwapChain(iface, 0, (IWineD3DSwapChain **) =
&swapchain);=0A=
@@ -7308,46 +7385,9 @@ static HRESULT WINAPI =
IWineD3DDeviceImpl_Reset(IWineD3DDevice* iface, WINED3DPRE=0A=
         ERR("What do do about a changed auto depth stencil =
parameter?\n");=0A=
     }=0A=
 =0A=
-    if (wined3d_settings.offscreen_rendering_mode =3D=3D ORM_FBO) {=0A=
-        reset_fbo_state((IWineD3DDevice *) This);=0A=
-    }=0A=
-=0A=
-    IWineD3DDevice_EnumResources(iface, reset_unload_resources, NULL);=0A=
-    LIST_FOR_EACH_ENTRY(shader, &This->shaders, IWineD3DBaseShaderImpl, =
baseShader.shader_list_entry) {=0A=
-        This->shader_backend->shader_destroy((IWineD3DBaseShader *) =
shader);=0A=
-    }=0A=
-=0A=
-    ENTER_GL();=0A=
-    if(This->depth_blt_texture) {=0A=
-        glDeleteTextures(1, &This->depth_blt_texture);=0A=
-        This->depth_blt_texture =3D 0;=0A=
-    }=0A=
-    if (This->depth_blt_rb) {=0A=
-        GL_EXTCALL(glDeleteRenderbuffersEXT(1, &This->depth_blt_rb));=0A=
-        This->depth_blt_rb =3D 0;=0A=
-        This->depth_blt_rb_w =3D 0;=0A=
-        This->depth_blt_rb_h =3D 0;=0A=
-    }=0A=
-    This->frag_pipe->free_private(iface);=0A=
-    This->shader_backend->shader_free_private(iface);=0A=
-=0A=
-    for (i =3D 0; i < GL_LIMITS(textures); i++) {=0A=
-        /* Textures are recreated below */=0A=
-        glDeleteTextures(1, &This->dummyTextureName[i]);=0A=
-        checkGLcall("glDeleteTextures(1, &This->dummyTextureName[i])");=0A=
-        This->dummyTextureName[i] =3D 0;=0A=
-    }=0A=
-    LEAVE_GL();=0A=
-=0A=
-    while(This->numContexts) {=0A=
-        DestroyContext(This, This->contexts[0]);=0A=
-    }=0A=
-    This->activeContext =3D NULL;=0A=
-    HeapFree(GetProcessHeap(), 0, swapchain->context);=0A=
-    swapchain->context =3D NULL;=0A=
-    swapchain->num_contexts =3D 0;=0A=
+    delete_opengl_contexts(iface, (IWineD3DSwapChain *) swapchain);=0A=
 =0A=
-     if(pPresentationParameters->Windowed) {=0A=
+    if(pPresentationParameters->Windowed) {=0A=
         mode.Width =3D swapchain->orig_width;=0A=
         mode.Height =3D swapchain->orig_height;=0A=
         mode.RefreshRate =3D 0;=0A=
@@ -7413,41 +7453,18 @@ static HRESULT WINAPI =
IWineD3DDeviceImpl_Reset(IWineD3DDevice* iface, WINED3DPRE=0A=
         This->exStyle =3D exStyle;=0A=
     }=0A=
 =0A=
-    /* Recreate the primary swapchain's context */=0A=
-    swapchain->context =3D HeapAlloc(GetProcessHeap(), 0, =
sizeof(*swapchain->context));=0A=
-    if(swapchain->backBuffer) {=0A=
-        target =3D (IWineD3DSurfaceImpl *) swapchain->backBuffer[0];=0A=
-    } else {=0A=
-        target =3D (IWineD3DSurfaceImpl *) swapchain->frontBuffer;=0A=
-    }=0A=
-    swapchain->context[0] =3D CreateContext(This, target, =
swapchain->win_handle, FALSE,=0A=
-                                          &swapchain->presentParms);=0A=
-    swapchain->num_contexts =3D 1;=0A=
-    This->activeContext =3D swapchain->context[0];=0A=
-    IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);=0A=
-=0A=
     hr =3D IWineD3DStateBlock_InitStartupStateBlock((IWineD3DStateBlock =
*) This->stateBlock);=0A=
     if(FAILED(hr)) {=0A=
         ERR("Resetting the stateblock failed with error 0x%08x\n", hr);=0A=
     }=0A=
-    create_dummy_textures(This);=0A=
-=0A=
 =0A=
-    hr =3D This->shader_backend->shader_alloc_private(iface);=0A=
-    if(FAILED(hr)) {=0A=
-        ERR("Failed to recreate shader private data\n");=0A=
-        return hr;=0A=
-    }=0A=
-    hr =3D This->frag_pipe->alloc_private(iface);=0A=
-    if(FAILED(hr)) {=0A=
-        TRACE("Fragment pipeline private data couldn't be allocated\n");=0A=
-        return hr;=0A=
-    }=0A=
+    hr =3D create_primary_opengl_context(iface, (IWineD3DSwapChain *) =
swapchain);=0A=
+    IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);=0A=
 =0A=
     /* All done. There is no need to reload resources or shaders, this =
will happen automatically on the=0A=
      * first use=0A=
      */=0A=
-    return WINED3D_OK;=0A=
+    return hr;=0A=
 }=0A=
 =0A=
 static HRESULT WINAPI =
IWineD3DDeviceImpl_SetDialogBoxMode(IWineD3DDevice *iface, BOOL =
bEnableDialogs) {=0A=
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c=0A=
index 72b1c7c..9ec296c 100644=0A=
--- a/dlls/wined3d/swapchain.c=0A=
+++ b/dlls/wined3d/swapchain.c=0A=
@@ -149,11 +149,13 @@ static HRESULT WINAPI =
IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CO=0A=
 =0A=
         TRACE("Performing dest override of swapchain %p from window %p =
to %p\n", This, This->win_handle, hDestWindowOverride);=0A=
         if(This->context[0] =3D=3D This->wineD3DDevice->contexts[0]) {=0A=
-            /* The primary context 'owns' all the opengl resources. =
Destroying and recreating that context would require downloading=0A=
+            /* The primary context 'owns' all the opengl resources. =
Destroying and recreating that context requires downloading=0A=
              * all opengl resources, deleting the gl resources, =
destroying all other contexts, then recreating all other contexts=0A=
              * and reload the resources=0A=
              */=0A=
-            ERR("Cannot change the destination window of the owner of =
the primary context\n");=0A=
+            delete_opengl_contexts((IWineD3DDevice *) =
This->wineD3DDevice, iface);=0A=
+            This->win_handle             =3D hDestWindowOverride;=0A=
+            create_primary_opengl_context((IWineD3DDevice *) =
This->wineD3DDevice, iface);=0A=
         } else {=0A=
             This->win_handle             =3D hDestWindowOverride;=0A=
 =0A=
diff --git a/dlls/wined3d/wined3d_private.h =
b/dlls/wined3d/wined3d_private.h=0A=
index 0c163f4..3cdfd1a 100644=0A=
--- a/dlls/wined3d/wined3d_private.h=0A=
+++ b/dlls/wined3d/wined3d_private.h=0A=
@@ -629,6 +629,9 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl =
*This, IWineD3DSurfaceImpl *tar=0A=
 void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context);=0A=
 void apply_fbo_state(IWineD3DDevice *iface);=0A=
 =0A=
+void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain =
*swapchain);=0A=
+HRESULT create_primary_opengl_context(IWineD3DDevice *iface, =
IWineD3DSwapChain *swapchain);=0A=
+=0A=
 /* Macros for doing basic GPU detection based on opengl capabilities */=0A=
 #define WINE_D3D6_CAPABLE(gl_info) =
(gl_info->supported[ARB_MULTITEXTURE])=0A=
 #define WINE_D3D7_CAPABLE(gl_info) =
(gl_info->supported[ARB_TEXTURE_COMPRESSION] && =
gl_info->supported[ARB_TEXTURE_CUBE_MAP] && =
gl_info->supported[ARB_TEXTURE_ENV_DOT3])=0A=
-- =0A=
1.5.4.5=0A=
=0A=

------=_NextPart_000_0019_01C90123.E5C4E8A0--




More information about the wine-patches mailing list