Commit 6f95f05a authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Move swapchain context retrieval to swapchain.c.

parent 3d64b44c
......@@ -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);
......
......@@ -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.
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment