wined3d: Store the swapchain instead of the surface in the context.

This commit is contained in:
Henri Verbeet 2010-03-15 21:07:25 +01:00 committed by Alexandre Julliard
parent b281f23efe
commit 18ec2525a4
6 changed files with 54 additions and 62 deletions

View File

@ -576,7 +576,7 @@ static inline void shader_arb_vs_local_constants(IWineD3DDeviceImpl* deviceImpl)
/* GL locking is done by the caller (state handler) */
static void shader_arb_load_constants(const struct wined3d_context *context, char usePixelShader, char useVertexShader)
{
IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
IWineD3DDeviceImpl *device = context->swapchain->device;
IWineD3DStateBlockImpl* stateBlock = device->stateBlock;
const struct wined3d_gl_info *gl_info = context->gl_info;
@ -606,7 +606,7 @@ static void shader_arb_update_float_vertex_constants(IWineD3DDevice *iface, UINT
/* We don't want shader constant dirtification to be an O(contexts), so just dirtify the active
* context. On a context switch the old context will be fully dirtified */
if (!context || ((IWineD3DSurfaceImpl *)context->surface)->resource.device != This) return;
if (!context || context->swapchain->device != This) return;
memset(context->vshader_const_dirty + start, 1, sizeof(*context->vshader_const_dirty) * count);
This->highest_dirty_vs_const = max(This->highest_dirty_vs_const, start + count);
@ -619,7 +619,7 @@ static void shader_arb_update_float_pixel_constants(IWineD3DDevice *iface, UINT
/* We don't want shader constant dirtification to be an O(contexts), so just dirtify the active
* context. On a context switch the old context will be fully dirtified */
if (!context || ((IWineD3DSurfaceImpl *)context->surface)->resource.device != This) return;
if (!context || context->swapchain->device != This) return;
memset(context->pshader_const_dirty + start, 1, sizeof(*context->pshader_const_dirty) * count);
This->highest_dirty_ps_const = max(This->highest_dirty_ps_const, start + count);
@ -4339,7 +4339,7 @@ static inline void find_arb_vs_compile_args(IWineD3DVertexShaderImpl *shader, IW
/* GL locking is done by the caller */
static void shader_arb_select(const struct wined3d_context *context, BOOL usePS, BOOL useVS)
{
IWineD3DDeviceImpl *This = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
IWineD3DDeviceImpl *This = context->swapchain->device;
struct shader_arb_priv *priv = This->shader_priv;
const struct wined3d_gl_info *gl_info = context->gl_info;
int i;

View File

@ -317,8 +317,8 @@ static void context_check_fbo_status(struct wined3d_context *context)
static struct fbo_entry *context_create_fbo_entry(struct wined3d_context *context)
{
IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
IWineD3DDeviceImpl *device = context->swapchain->device;
struct fbo_entry *entry;
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
@ -334,8 +334,8 @@ static struct fbo_entry *context_create_fbo_entry(struct wined3d_context *contex
/* GL locking is done by the caller */
static void context_reuse_fbo_entry(struct wined3d_context *context, struct fbo_entry *entry)
{
IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
IWineD3DDeviceImpl *device = context->swapchain->device;
context_bind_fbo(context, GL_FRAMEBUFFER, &entry->id);
context_clean_fbo_attachments(gl_info);
@ -363,8 +363,8 @@ static void context_destroy_fbo_entry(struct wined3d_context *context, struct fb
/* GL locking is done by the caller */
static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context)
{
IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
IWineD3DDeviceImpl *device = context->swapchain->device;
struct fbo_entry *entry;
LIST_FOR_EACH_ENTRY(entry, &context->fbo_list, struct fbo_entry, entry)
@ -399,8 +399,8 @@ static struct fbo_entry *context_find_fbo_entry(struct wined3d_context *context)
/* GL locking is done by the caller */
static void context_apply_fbo_entry(struct wined3d_context *context, struct fbo_entry *entry)
{
IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
IWineD3DDeviceImpl *device = context->swapchain->device;
unsigned int i;
context_bind_fbo(context, GL_FRAMEBUFFER, &entry->id);
@ -1147,10 +1147,10 @@ static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc,
* pPresentParameters: contains the pixelformats to use for onscreen rendering
*
*****************************************************************************/
struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target,
HWND win_handle, const WINED3DPRESENT_PARAMETERS *pPresentParms)
struct wined3d_context *context_create(IWineD3DSwapChainImpl *swapchain, IWineD3DSurfaceImpl *target)
{
const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
IWineD3DDeviceImpl *device = swapchain->device;
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
const struct GlPixelFormatDesc *color_format_desc;
const struct GlPixelFormatDesc *ds_format_desc;
struct wined3d_context *ret;
@ -1163,8 +1163,7 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
HGLRC ctx;
HDC hdc;
TRACE("device %p, target %p, window %p, present parameters %p.\n",
This, target, win_handle, pPresentParms);
TRACE("swapchain %p, target %p, window %p.\n", swapchain, target, swapchain->win_handle);
ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
if (!ret)
@ -1173,7 +1172,7 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
return NULL;
}
if (!(hdc = GetDC(win_handle)))
if (!(hdc = GetDC(swapchain->win_handle)))
{
ERR("Failed to retrieve a device context.\n");
goto out;
@ -1206,34 +1205,34 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
/* Retrieve the depth stencil format from the present parameters.
* The choice of the proper format can give a nice performance boost
* in case of GPU limited programs. */
if (pPresentParms->EnableAutoDepthStencil)
if (swapchain->presentParms.EnableAutoDepthStencil)
{
TRACE("Auto depth stencil enabled, using format %s.\n",
debug_d3dformat(pPresentParms->AutoDepthStencilFormat));
ds_format_desc = getFormatDescEntry(pPresentParms->AutoDepthStencilFormat, gl_info);
debug_d3dformat(swapchain->presentParms.AutoDepthStencilFormat));
ds_format_desc = getFormatDescEntry(swapchain->presentParms.AutoDepthStencilFormat, gl_info);
}
/* D3D only allows multisampling when SwapEffect is set to WINED3DSWAPEFFECT_DISCARD. */
if (pPresentParms->MultiSampleType && (pPresentParms->SwapEffect == WINED3DSWAPEFFECT_DISCARD))
if (swapchain->presentParms.MultiSampleType && (swapchain->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD))
{
if (!gl_info->supported[ARB_MULTISAMPLE])
WARN("The application is requesting multisampling without support.\n");
else
{
TRACE("Requesting multisample type %#x.\n", pPresentParms->MultiSampleType);
numSamples = pPresentParms->MultiSampleType;
TRACE("Requesting multisample type %#x.\n", swapchain->presentParms.MultiSampleType);
numSamples = swapchain->presentParms.MultiSampleType;
}
}
/* Try to find a pixel format which matches our requirements. */
pixel_format = WineD3D_ChoosePixelFormat(This, hdc, color_format_desc, ds_format_desc,
pixel_format = WineD3D_ChoosePixelFormat(device, hdc, color_format_desc, ds_format_desc,
auxBuffers, numSamples, FALSE /* findCompatible */);
/* Try to locate a compatible format if we weren't able to find anything. */
if (!pixel_format)
{
TRACE("Trying to locate a compatible pixel format because an exact match failed.\n");
pixel_format = WineD3D_ChoosePixelFormat(This, hdc, color_format_desc, ds_format_desc,
pixel_format = WineD3D_ChoosePixelFormat(device, hdc, color_format_desc, ds_format_desc,
auxBuffers, 0 /* numSamples */, TRUE /* findCompatible */);
}
@ -1252,13 +1251,13 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
}
ctx = pwglCreateContext(hdc);
if (This->numContexts)
if (device->numContexts)
{
if (!pwglShareLists(This->contexts[0]->glCtx, ctx))
if (!pwglShareLists(device->contexts[0]->glCtx, ctx))
{
DWORD err = GetLastError();
ERR("wglShareLists(%p, %p) failed, last error %#x.\n",
This->contexts[0]->glCtx, ctx, err);
device->contexts[0]->glCtx, ctx, err);
}
}
@ -1267,7 +1266,7 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
goto out;
}
if (!device_context_add(This, ret))
if (!device_context_add(device, ret))
{
ERR("Failed to add the newly created context to the context list\n");
if (!pwglDeleteContext(ctx))
@ -1284,11 +1283,11 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
* on the first use of the context. */
for (state = 0; state <= STATE_HIGHEST; ++state)
{
if (This->StateTable[state].representative)
Context_MarkStateDirty(ret, state, This->StateTable);
if (device->StateTable[state].representative)
Context_MarkStateDirty(ret, state, device->StateTable);
}
ret->surface = (IWineD3DSurface *) target;
ret->swapchain = swapchain;
ret->current_rt = (IWineD3DSurface *)target;
ret->tid = GetCurrentThreadId();
@ -1297,19 +1296,20 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
ret->valid = 1;
ret->glCtx = ctx;
ret->win_handle = win_handle;
ret->win_handle = swapchain->win_handle;
ret->hdc = hdc;
if(This->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *) This)) {
if (device->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *)device))
{
/* Create the dirty constants array and initialize them to dirty */
ret->vshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
sizeof(*ret->vshader_const_dirty) * This->d3d_vshader_constantF);
sizeof(*ret->vshader_const_dirty) * device->d3d_vshader_constantF);
ret->pshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
sizeof(*ret->pshader_const_dirty) * This->d3d_pshader_constantF);
sizeof(*ret->pshader_const_dirty) * device->d3d_pshader_constantF);
memset(ret->vshader_const_dirty, 1,
sizeof(*ret->vshader_const_dirty) * This->d3d_vshader_constantF);
sizeof(*ret->vshader_const_dirty) * device->d3d_vshader_constantF);
memset(ret->pshader_const_dirty, 1,
sizeof(*ret->pshader_const_dirty) * This->d3d_pshader_constantF);
sizeof(*ret->pshader_const_dirty) * device->d3d_pshader_constantF);
}
ret->free_occlusion_query_size = 4;
@ -1364,10 +1364,10 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
glPixelStorei(GL_PACK_ALIGNMENT, This->surface_alignment);
checkGLcall("glPixelStorei(GL_PACK_ALIGNMENT, This->surface_alignment);");
glPixelStorei(GL_UNPACK_ALIGNMENT, This->surface_alignment);
checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, This->surface_alignment);");
glPixelStorei(GL_PACK_ALIGNMENT, device->surface_alignment);
checkGLcall("glPixelStorei(GL_PACK_ALIGNMENT, device->surface_alignment);");
glPixelStorei(GL_UNPACK_ALIGNMENT, device->surface_alignment);
checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, device->surface_alignment);");
if (gl_info->supported[APPLE_CLIENT_STORAGE])
{
@ -1436,7 +1436,7 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
LEAVE_GL();
This->frag_pipe->enable_extension((IWineD3DDevice *) This, TRUE);
device->frag_pipe->enable_extension((IWineD3DDevice *)device, TRUE);
TRACE("Created context %p.\n", ret);
@ -1759,7 +1759,7 @@ static struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSur
{
if (current_context
&& current_context->current_rt
&& ((IWineD3DSurfaceImpl *)current_context->surface)->resource.device == This)
&& current_context->swapchain->device == This)
{
target = current_context->current_rt;
}
@ -1791,7 +1791,7 @@ static struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWineD3DSur
TRACE("Rendering offscreen\n");
/* Stay with the currently active context. */
if (current_context && ((IWineD3DSurfaceImpl *)current_context->surface)->resource.device == This)
if (current_context && current_context->swapchain->device == This)
{
context = current_context;
}

View File

@ -6442,8 +6442,7 @@ HRESULT create_primary_opengl_context(IWineD3DDevice *iface, IWineD3DSwapChain *
}
target = (IWineD3DSurfaceImpl *)(swapchain->backBuffer ? swapchain->backBuffer[0] : swapchain->frontBuffer);
context = context_create(This, target, swapchain->win_handle, &swapchain->presentParms);
if (!context)
if (!(context = context_create(swapchain, target)))
{
WARN("Failed to create context.\n");
HeapFree(GetProcessHeap(), 0, swapchain->context);
@ -7155,13 +7154,12 @@ void get_drawable_size_fbo(struct wined3d_context *context, UINT *width, UINT *h
void get_drawable_size_backbuffer(struct wined3d_context *context, UINT *width, UINT *height)
{
IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)context->surface;
IWineD3DSwapChainImpl *swapchain = context->swapchain;
/* The drawable size of a backbuffer / aux buffer offscreen target is the size of the
* current context's drawable, which is the size of the back buffer of the swapchain
* the active context belongs to. The back buffer of the swapchain is stored as the
* surface the context belongs to. */
*width = surface->currentDesc.Width;
*height = surface->currentDesc.Height;
* the active context belongs to. */
*width = swapchain->presentParms.BackBufferWidth;
*height = swapchain->presentParms.BackBufferHeight;
}
LRESULT device_process_message(IWineD3DDeviceImpl *device, HWND window,

View File

@ -719,8 +719,8 @@ static void shader_glsl_load_np2fixup_constants(
static void shader_glsl_load_constants(const struct wined3d_context *context,
char usePixelShader, char useVertexShader)
{
IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
IWineD3DDeviceImpl *device = context->swapchain->device;
IWineD3DStateBlockImpl* stateBlock = device->stateBlock;
struct shader_glsl_priv *priv = device->shader_priv;
@ -4530,8 +4530,8 @@ static GLhandleARB create_glsl_blt_shader(const struct wined3d_gl_info *gl_info,
/* GL locking is done by the caller */
static void shader_glsl_select(const struct wined3d_context *context, BOOL usePS, BOOL useVS)
{
IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
IWineD3DDeviceImpl *device = context->swapchain->device;
struct shader_glsl_priv *priv = device->shader_priv;
GLhandleARB program_id = 0;
GLenum old_vertex_color_clamp, current_vertex_color_clamp;

View File

@ -546,8 +546,7 @@ static HRESULT WINAPI IWineD3DSwapChainImpl_SetDestWindowOverride(IWineD3DSwapCh
IWineD3DSurface_UnlockRect(This->backBuffer[0]);
context_destroy(This->device, This->context[0]);
This->context[0] = context_create(This->device, (IWineD3DSurfaceImpl *)This->frontBuffer,
This->win_handle, &This->presentParms);
This->context[0] = context_create(This, (IWineD3DSurfaceImpl *)This->frontBuffer);
context_release(This->context[0]);
IWineD3DSurface_LockRect(This->backBuffer[0], &r, NULL, WINED3DLOCK_DISCARD);
@ -816,9 +815,7 @@ HRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface
if (surface_type == SURFACE_OPENGL)
{
swapchain->context[0] = context_create(device, (IWineD3DSurfaceImpl *)swapchain->frontBuffer,
window, present_parameters);
if (!swapchain->context[0])
if (!(swapchain->context[0] = context_create(swapchain, (IWineD3DSurfaceImpl *)swapchain->frontBuffer)))
{
WARN("Failed to create context.\n");
hr = WINED3DERR_NOTAVAILABLE;
@ -935,9 +932,7 @@ struct wined3d_context *swapchain_create_context_for_thread(IWineD3DSwapChain *i
TRACE("Creating a new context for swapchain %p, thread %d\n", This, GetCurrentThreadId());
ctx = context_create(This->device, (IWineD3DSurfaceImpl *)This->frontBuffer,
This->context[0]->win_handle, &This->presentParms);
if (!ctx)
if (!(ctx = context_create(This, (IWineD3DSurfaceImpl *)This->frontBuffer)))
{
ERR("Failed to create a new context for the swapchain\n");
return NULL;

View File

@ -1051,7 +1051,7 @@ struct wined3d_context
DWORD numDirtyEntries;
DWORD isStateDirty[STATE_HIGHEST / (sizeof(DWORD) * CHAR_BIT) + 1]; /* Bitmap to find out quickly if a state is dirty */
IWineD3DSurface *surface;
IWineD3DSwapChainImpl *swapchain;
IWineD3DSurface *current_rt;
DWORD tid; /* Thread ID which owns this context at the moment */
@ -1199,8 +1199,7 @@ void context_attach_depth_stencil_fbo(struct wined3d_context *context,
GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer) DECLSPEC_HIDDEN;
void context_attach_surface_fbo(const struct wined3d_context *context,
GLenum fbo_target, DWORD idx, IWineD3DSurface *surface) DECLSPEC_HIDDEN;
struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target,
HWND win, const WINED3DPRESENT_PARAMETERS *present_parameters) DECLSPEC_HIDDEN;
struct wined3d_context *context_create(IWineD3DSwapChainImpl *swapchain, IWineD3DSurfaceImpl *target) DECLSPEC_HIDDEN;
void context_destroy(IWineD3DDeviceImpl *This, struct wined3d_context *context) DECLSPEC_HIDDEN;
void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;