wined3d: Move swapchain context retrieval to swapchain.c.

This commit is contained in:
Henri Verbeet 2011-01-19 19:20:11 +01:00 committed by Alexandre Julliard
parent 3d64b44c8c
commit 6f95f05aaf
3 changed files with 21 additions and 37 deletions

View File

@ -1859,32 +1859,10 @@ static void SetupForBlit(IWineD3DDeviceImpl *This, struct wined3d_context *conte
This->frag_pipe->enable_extension(FALSE);
}
/*****************************************************************************
* findThreadContextForSwapChain
*
* Searches a swapchain for all contexts and picks one for the thread tid.
* If none can be found the swapchain is requested to create a new context
*
*****************************************************************************/
static struct wined3d_context *findThreadContextForSwapChain(struct IWineD3DSwapChainImpl *swapchain, DWORD tid)
{
unsigned int i;
for (i = 0; i < swapchain->num_contexts; ++i)
{
if (swapchain->context[i]->tid == tid)
return swapchain->context[i];
}
/* Create a new context for the thread */
return swapchain_create_context_for_thread(swapchain);
}
/* Do not call while under the GL lock. */
static struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target)
{
struct wined3d_context *current_context = context_get_current();
DWORD tid = GetCurrentThreadId();
struct wined3d_context *context;
if (current_context && current_context->destroyed) current_context = NULL;
@ -1915,27 +1893,18 @@ static struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSur
{
TRACE("Rendering onscreen\n");
context = findThreadContextForSwapChain(target->container.u.swapchain, tid);
context = swapchain_get_context(target->container.u.swapchain);
}
else
{
TRACE("Rendering offscreen\n");
/* Stay with the currently active context. */
/* Stay with the current context if possible. Otherwise use the
* context for the primary swapchain. */
if (current_context && current_context->swapchain->device == This)
{
context = current_context;
}
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((IWineD3DSwapChainImpl *)This->swapchains[0], tid);
}
context = swapchain_get_context((IWineD3DSwapChainImpl *)This->swapchains[0]);
}
context_validate(context);

View File

@ -783,7 +783,7 @@ err:
}
/* Do not call while under the GL lock. */
struct wined3d_context *swapchain_create_context_for_thread(IWineD3DSwapChainImpl *swapchain)
static struct wined3d_context *swapchain_create_context(struct IWineD3DSwapChainImpl *swapchain)
{
struct wined3d_context **newArray;
struct wined3d_context *ctx;
@ -813,6 +813,21 @@ struct wined3d_context *swapchain_create_context_for_thread(IWineD3DSwapChainImp
return ctx;
}
struct wined3d_context *swapchain_get_context(struct IWineD3DSwapChainImpl *swapchain)
{
DWORD tid = GetCurrentThreadId();
unsigned int i;
for (i = 0; i < swapchain->num_contexts; ++i)
{
if (swapchain->context[i]->tid == tid)
return swapchain->context[i];
}
/* Create a new context for the thread */
return swapchain_create_context(swapchain);
}
void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height)
{
/* The drawable size of an onscreen drawable is the surface size.

View File

@ -2634,7 +2634,7 @@ HRESULT WINAPI IWineD3DBaseSwapChainImpl_SetGammaRamp(IWineD3DSwapChain *iface,
HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetGammaRamp(IWineD3DSwapChain *iface,
WINED3DGAMMARAMP *pRamp) DECLSPEC_HIDDEN;
struct wined3d_context *swapchain_create_context_for_thread(struct IWineD3DSwapChainImpl *swapchain) DECLSPEC_HIDDEN;
struct wined3d_context *swapchain_get_context(struct IWineD3DSwapChainImpl *swapchain) DECLSPEC_HIDDEN;
HRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface_type,
IWineD3DDeviceImpl *device, WINED3DPRESENT_PARAMETERS *present_parameters, void *parent) DECLSPEC_HIDDEN;