wined3d: Simplify FindContext() a bit.

This commit is contained in:
Henri Verbeet 2009-07-22 10:41:08 +02:00 committed by Alexandre Julliard
parent ce436a76e2
commit 219d3abdd1
1 changed files with 60 additions and 79 deletions

View File

@ -1603,10 +1603,10 @@ static WineD3DContext *findThreadContextForSwapChain(IWineD3DSwapChain *swapchai
static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, DWORD tid) { static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, DWORD tid) {
IWineD3DSwapChain *swapchain = NULL; IWineD3DSwapChain *swapchain = NULL;
BOOL readTexture = wined3d_settings.offscreen_rendering_mode != ORM_FBO && This->render_offscreen; BOOL readTexture = wined3d_settings.offscreen_rendering_mode != ORM_FBO && This->render_offscreen;
WineD3DContext *context = This->activeContext;
BOOL oldRenderOffscreen = This->render_offscreen; BOOL oldRenderOffscreen = This->render_offscreen;
const struct StateEntry *StateTable = This->StateTable; const struct StateEntry *StateTable = This->StateTable;
const struct GlPixelFormatDesc *old, *new; const struct GlPixelFormatDesc *old, *new;
struct WineD3DContext *context;
if (SUCCEEDED(IWineD3DSurface_GetContainer(target, &IID_IWineD3DSwapChain, (void **)&swapchain))) { if (SUCCEEDED(IWineD3DSurface_GetContainer(target, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
TRACE("Rendering onscreen\n"); TRACE("Rendering onscreen\n");
@ -1625,50 +1625,26 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf
} }
} }
IWineD3DSwapChain_Release(swapchain); IWineD3DSwapChain_Release(swapchain);
if(oldRenderOffscreen) {
Context_MarkStateDirty(context, WINED3DTS_PROJECTION, StateTable);
Context_MarkStateDirty(context, STATE_VDECL, StateTable);
Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable);
Context_MarkStateDirty(context, STATE_FRONTFACE, StateTable);
} }
else
} else { {
TRACE("Rendering offscreen\n"); TRACE("Rendering offscreen\n");
This->render_offscreen = TRUE; This->render_offscreen = TRUE;
switch(wined3d_settings.offscreen_rendering_mode) { retry:
case ORM_FBO: if (wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER)
/* FBOs do not need a different context. Stay with whatever context is active at the moment */
if (This->activeContext && This->activeContext->tid == tid)
{
context = This->activeContext;
} else {
/* This may happen if the app jumps straight into offscreen rendering
* Start using the context of the primary swapchain. tid == 0 is no problem
* for findThreadContextForSwapChain.
*
* Can also happen on thread switches - in that case findThreadContextForSwapChain
* is perfect to call.
*/
context = findThreadContextForSwapChain(This->swapchains[0], tid);
}
break;
case ORM_PBUFFER:
{ {
IWineD3DSurfaceImpl *targetimpl = (IWineD3DSurfaceImpl *)target; IWineD3DSurfaceImpl *targetimpl = (IWineD3DSurfaceImpl *)target;
if(This->pbufferContext == NULL || if (!This->pbufferContext
This->pbufferWidth < targetimpl->currentDesc.Width || || This->pbufferWidth < targetimpl->currentDesc.Width
This->pbufferHeight < targetimpl->currentDesc.Height) { || This->pbufferHeight < targetimpl->currentDesc.Height)
if(This->pbufferContext) { {
DestroyContext(This, This->pbufferContext); if (This->pbufferContext) DestroyContext(This, This->pbufferContext);
}
/* The display is irrelevant here, the window is 0. But CreateContext needs a valid X connection. /* The display is irrelevant here, the window is 0. But
* Create the context on the same server as the primary swapchain. The primary swapchain is exists at this point. * CreateContext needs a valid X connection. Create the context
*/ * on the same server as the primary swapchain. The primary
* swapchain is exists at this point. */
This->pbufferContext = CreateContext(This, targetimpl, This->pbufferContext = CreateContext(This, targetimpl,
((IWineD3DSwapChainImpl *)This->swapchains[0])->context[0]->win_handle, ((IWineD3DSwapChainImpl *)This->swapchains[0])->context[0]->win_handle,
TRUE /* pbuffer */, &((IWineD3DSwapChainImpl *)This->swapchains[0])->presentParms); TRUE /* pbuffer */, &((IWineD3DSwapChainImpl *)This->swapchains[0])->presentParms);
@ -1676,45 +1652,50 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf
This->pbufferHeight = targetimpl->currentDesc.Height; This->pbufferHeight = targetimpl->currentDesc.Height;
} }
if(This->pbufferContext) { if (This->pbufferContext)
if(This->pbufferContext->tid != 0 && This->pbufferContext->tid != tid) { {
FIXME("The PBuffr context is only supported for one thread for now!\n"); if (This->pbufferContext->tid && This->pbufferContext->tid != tid)
{
FIXME("The PBuffer context is only supported for one thread for now!\n");
} }
This->pbufferContext->tid = tid; This->pbufferContext->tid = tid;
context = This->pbufferContext; context = This->pbufferContext;
break; }
} else { else
ERR("Failed to create a buffer context and drawable, falling back to back buffer offscreen rendering\n"); {
ERR("Failed to create a buffer context and drawable, falling back to back buffer offscreen rendering.\n");
wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER; wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
goto retry;
} }
} }
else
case ORM_BACKBUFFER: {
/* Stay with the currently active context for back buffer rendering */ /* Stay with the currently active context. */
if (This->activeContext && This->activeContext->tid == tid) if (This->activeContext && This->activeContext->tid == tid)
{ {
context = This->activeContext; context = This->activeContext;
} else { }
else
{
/* This may happen if the app jumps straight into offscreen rendering /* This may happen if the app jumps straight into offscreen rendering
* Start using the context of the primary swapchain. tid == 0 is no problem * Start using the context of the primary swapchain. tid == 0 is no problem
* for findThreadContextForSwapChain. * for findThreadContextForSwapChain.
* *
* Can also happen on thread switches - in that case findThreadContextForSwapChain * Can also happen on thread switches - in that case findThreadContextForSwapChain
* is perfect to call. * is perfect to call. */
*/
context = findThreadContextForSwapChain(This->swapchains[0], tid); context = findThreadContextForSwapChain(This->swapchains[0], tid);
} }
break; }
} }
if(!oldRenderOffscreen) { if (This->render_offscreen != oldRenderOffscreen)
{
Context_MarkStateDirty(context, WINED3DTS_PROJECTION, StateTable); Context_MarkStateDirty(context, WINED3DTS_PROJECTION, StateTable);
Context_MarkStateDirty(context, STATE_VDECL, StateTable); Context_MarkStateDirty(context, STATE_VDECL, StateTable);
Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable); Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable); Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable);
Context_MarkStateDirty(context, STATE_FRONTFACE, StateTable); Context_MarkStateDirty(context, STATE_FRONTFACE, StateTable);
} }
}
/* To compensate the lack of format switching with some offscreen rendering methods and on onscreen buffers /* To compensate the lack of format switching with some offscreen rendering methods and on onscreen buffers
* the alpha blend state changes with different render target formats. */ * the alpha blend state changes with different render target formats. */