[PATCH 1/5] wined3d: Store render targets as IWineD3DSurfaceImpl pointers in the device.

Henri Verbeet hverbeet at codeweavers.com
Mon Apr 19 13:46:59 CDT 2010


---
 dlls/wined3d/arb_program_shader.c |    2 +-
 dlls/wined3d/context.c            |   11 +++-----
 dlls/wined3d/device.c             |   45 ++++++++++++++++++++----------------
 dlls/wined3d/drawprim.c           |    9 +++----
 dlls/wined3d/glsl_shader.c        |    2 +-
 dlls/wined3d/state.c              |    6 ++--
 dlls/wined3d/surface.c            |   23 ++++++++++---------
 dlls/wined3d/wined3d_private.h    |    2 +-
 8 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index a40b940..6d1d2d9 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -509,7 +509,7 @@ static inline void shader_arb_ps_local_constants(IWineD3DDeviceImpl* deviceImpl)
         */
         float val[4];
         val[0] = context->render_offscreen ? 0.0f
-                : ((IWineD3DSurfaceImpl *) deviceImpl->render_targets[0])->currentDesc.Height;
+                : deviceImpl->render_targets[0]->currentDesc.Height;
         val[1] = context->render_offscreen ? 1.0f : -1.0f;
         val[2] = 1.0f;
         val[3] = 0.0f;
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 870ab37..dc54249 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -413,17 +413,14 @@ static void context_apply_fbo_entry(struct wined3d_context *context, struct fbo_
         /* Apply render targets */
         for (i = 0; i < gl_info->limits.buffers; ++i)
         {
-            IWineD3DSurfaceImpl *render_target = (IWineD3DSurfaceImpl *)device->render_targets[i];
-            context_attach_surface_fbo(context, GL_FRAMEBUFFER, i, render_target);
+            context_attach_surface_fbo(context, GL_FRAMEBUFFER, i, device->render_targets[i]);
         }
 
         /* Apply depth targets */
         if (device->stencilBufferTarget)
         {
-            unsigned int w = ((IWineD3DSurfaceImpl *)device->render_targets[0])->pow2Width;
-            unsigned int h = ((IWineD3DSurfaceImpl *)device->render_targets[0])->pow2Height;
-
-            surface_set_compatible_renderbuffer((IWineD3DSurfaceImpl *)device->stencilBufferTarget, w, h);
+            surface_set_compatible_renderbuffer((IWineD3DSurfaceImpl *)device->stencilBufferTarget,
+                    device->render_targets[0]->pow2Width, device->render_targets[0]->pow2Height);
         }
         context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, (IWineD3DSurfaceImpl *)device->stencilBufferTarget, TRUE);
 
@@ -434,7 +431,7 @@ static void context_apply_fbo_entry(struct wined3d_context *context, struct fbo_
         for (i = 0; i < gl_info->limits.buffers; ++i)
         {
             if (device->render_targets[i])
-                context_apply_attachment_filter_states((IWineD3DSurfaceImpl *)device->render_targets[i]);
+                context_apply_attachment_filter_states(device->render_targets[i]);
         }
         if (device->stencilBufferTarget)
             context_apply_attachment_filter_states((IWineD3DSurfaceImpl *)device->stencilBufferTarget);
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 5ae2b5c..7b1103a 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1554,7 +1554,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface,
     IWineD3DStateBlock_AddRef((IWineD3DStateBlock*)This->updateStateBlock);
 
     This->render_targets = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-            sizeof(IWineD3DSurface *) * gl_info->limits.buffers);
+            sizeof(*This->render_targets) * gl_info->limits.buffers);
     This->draw_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
             sizeof(GLenum) * gl_info->limits.buffers);
 
@@ -1612,13 +1612,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface,
 
     if(swapchain->backBuffer && swapchain->backBuffer[0]) {
         TRACE("Setting rendertarget to %p\n", swapchain->backBuffer);
-        This->render_targets[0] = swapchain->backBuffer[0];
+        This->render_targets[0] = (IWineD3DSurfaceImpl *)swapchain->backBuffer[0];
     }
     else {
         TRACE("Setting rendertarget to %p\n", swapchain->frontBuffer);
-        This->render_targets[0] = swapchain->frontBuffer;
+        This->render_targets[0] = (IWineD3DSurfaceImpl *)swapchain->frontBuffer;
     }
-    IWineD3DSurface_AddRef(This->render_targets[0]);
+    IWineD3DSurface_AddRef((IWineD3DSurface *)This->render_targets[0]);
 
     /* Depth Stencil support */
     This->stencilBufferTarget = This->auto_depth_stencil_buffer;
@@ -1862,7 +1862,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Uninit3D(IWineD3DDevice *iface,
     This->stencilBufferTarget = NULL;
 
     TRACE("Releasing the render target at %p\n", This->render_targets[0]);
-    IWineD3DSurface_Release(This->render_targets[0]);
+    IWineD3DSurface_Release((IWineD3DSurface *)This->render_targets[0]);
 
     TRACE("Setting rendertarget to NULL\n");
     This->render_targets[0] = NULL;
@@ -4527,10 +4527,10 @@ HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfac
     return WINED3D_OK;
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_Clear(IWineD3DDevice *iface, DWORD Count, CONST WINED3DRECT* pRects,
-                                        DWORD Flags, WINED3DCOLOR Color, float Z, DWORD Stencil) {
+static HRESULT WINAPI IWineD3DDeviceImpl_Clear(IWineD3DDevice *iface, DWORD Count,
+        const WINED3DRECT *pRects, DWORD Flags, WINED3DCOLOR Color, float Z, DWORD Stencil)
+{
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *)This->render_targets[0];
 
     TRACE("(%p) Count (%d), pRects (%p), Flags (%x), Color (0x%08x), Z (%f), Stencil (%d)\n", This,
           Count, pRects, Flags, Color, Z, Stencil);
@@ -4541,7 +4541,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Clear(IWineD3DDevice *iface, DWORD Coun
         return WINED3DERR_INVALIDCALL;
     }
 
-    return IWineD3DDeviceImpl_ClearSurface(This, target, Count, pRects, Flags, Color, Z, Stencil);
+    return IWineD3DDeviceImpl_ClearSurface(This, This->render_targets[0], Count, pRects, Flags, Color, Z, Stencil);
 }
 
 /*****
@@ -5586,7 +5586,7 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_GetRenderTarget(IWineD3DDevice* iface
         return WINED3DERR_INVALIDCALL;
     }
 
-    *ppRenderTarget = This->render_targets[RenderTargetIndex];
+    *ppRenderTarget = (IWineD3DSurface *)This->render_targets[RenderTargetIndex];
     TRACE("(%p) : RenderTarget %d Index returning %p\n", This, RenderTargetIndex, *ppRenderTarget);
     /* Note inc ref on returned surface */
     if(*ppRenderTarget != NULL)
@@ -5868,13 +5868,16 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetRenderTarget(IWineD3DDevice *iface,
     }
 
     /* If we are trying to set what we already have, don't bother */
-    if (pRenderTarget == This->render_targets[RenderTargetIndex]) {
+    if (pRenderTarget == (IWineD3DSurface *)This->render_targets[RenderTargetIndex])
+    {
         TRACE("Trying to do a NOP SetRenderTarget operation\n");
         return WINED3D_OK;
     }
-    if(pRenderTarget) IWineD3DSurface_AddRef(pRenderTarget);
-    if(This->render_targets[RenderTargetIndex]) IWineD3DSurface_Release(This->render_targets[RenderTargetIndex]);
-    This->render_targets[RenderTargetIndex] = pRenderTarget;
+    if (pRenderTarget)
+        IWineD3DSurface_AddRef(pRenderTarget);
+    if (This->render_targets[RenderTargetIndex])
+        IWineD3DSurface_Release((IWineD3DSurface *)This->render_targets[RenderTargetIndex]);
+    This->render_targets[RenderTargetIndex] = (IWineD3DSurfaceImpl *)pRenderTarget;
 
     /* Render target 0 is special */
     if(RenderTargetIndex == 0 && set_viewport) {
@@ -5882,8 +5885,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetRenderTarget(IWineD3DDevice *iface,
          * Tests show that stateblock recording is ignored, the change goes
          * directly into the primary stateblock.
          */
-        This->stateBlock->viewport.Height = ((IWineD3DSurfaceImpl *)This->render_targets[0])->currentDesc.Height;
-        This->stateBlock->viewport.Width  = ((IWineD3DSurfaceImpl *)This->render_targets[0])->currentDesc.Width;
+        This->stateBlock->viewport.Height = This->render_targets[0]->currentDesc.Height;
+        This->stateBlock->viewport.Width  = This->render_targets[0]->currentDesc.Width;
         This->stateBlock->viewport.X      = 0;
         This->stateBlock->viewport.Y      = 0;
         This->stateBlock->viewport.MaxZ   = 1.0f;
@@ -5920,8 +5923,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetDepthStencilSurface(IWineD3DDevice *
             if (((IWineD3DSwapChainImpl *)This->swapchains[0])->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
                     || ((IWineD3DSurfaceImpl *)This->stencilBufferTarget)->Flags & SFLAG_DISCARD) {
                 surface_modify_ds_location((IWineD3DSurfaceImpl *)This->stencilBufferTarget, SFLAG_DS_DISCARDED);
-            } else {
-                struct wined3d_context *context = context_acquire(This, This->render_targets[0], CTXUSAGE_RESOURCELOAD);
+            }
+            else
+            {
+                struct wined3d_context *context = context_acquire(This,
+                        (IWineD3DSurface *)This->render_targets[0], CTXUSAGE_RESOURCELOAD);
                 surface_load_ds_location((IWineD3DSurfaceImpl *)This->stencilBufferTarget, context, SFLAG_DS_OFFSCREEN);
                 surface_modify_ds_location((IWineD3DSurfaceImpl *)This->stencilBufferTarget, SFLAG_DS_OFFSCREEN);
                 context_release(context);
@@ -6680,9 +6686,8 @@ void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resour
             {
                 for (i = 0; i < This->adapter->gl_info.limits.buffers; ++i)
                 {
-                    if (This->render_targets[i] == (IWineD3DSurface *)resource) {
+                    if (This->render_targets[i] == (IWineD3DSurfaceImpl *)resource)
                         This->render_targets[i] = NULL;
-                    }
                 }
                 if (This->stencilBufferTarget == (IWineD3DSurface *)resource) {
                     This->stencilBufferTarget = NULL;
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index ed641a6..590f31c 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -572,7 +572,6 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT
 {
 
     IWineD3DDeviceImpl           *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DSurfaceImpl          *target;
     struct wined3d_context *context;
     unsigned int i;
 
@@ -583,11 +582,11 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT
         /* Invalidate the back buffer memory so LockRect will read it the next time */
         for (i = 0; i < This->adapter->gl_info.limits.buffers; ++i)
         {
-            target = (IWineD3DSurfaceImpl *)This->render_targets[i];
+            IWineD3DSurface *target = (IWineD3DSurface *)This->render_targets[i];
             if (target)
             {
-                IWineD3DSurface_LoadLocation((IWineD3DSurface *)target, SFLAG_INDRAWABLE, NULL);
-                IWineD3DSurface_ModifyLocation((IWineD3DSurface *)target, SFLAG_INDRAWABLE, TRUE);
+                IWineD3DSurface_LoadLocation(target, SFLAG_INDRAWABLE, NULL);
+                IWineD3DSurface_ModifyLocation(target, SFLAG_INDRAWABLE, TRUE);
             }
         }
     }
@@ -595,7 +594,7 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT
     /* Signals other modules that a drawing is in progress and the stateblock finalized */
     This->isInDraw = TRUE;
 
-    context = context_acquire(This, This->render_targets[0], CTXUSAGE_DRAWPRIM);
+    context = context_acquire(This, (IWineD3DSurface *)This->render_targets[0], CTXUSAGE_DRAWPRIM);
     if (!context->valid)
     {
         context_release(context);
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 9bce13b..a04aaa7 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -1034,7 +1034,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont
                  */
                 FIXME("Cannot find a free uniform for vpos correction params\n");
                 shader_addline(buffer, "const vec4 ycorrection = vec4(%f, %f, 0.0, 0.0);\n",
-                        context->render_offscreen ? 0.0f : ((IWineD3DSurfaceImpl *)device->render_targets[0])->currentDesc.Height,
+                        context->render_offscreen ? 0.0f : device->render_targets[0]->currentDesc.Height,
                         context->render_offscreen ? 1.0f : -1.0f);
             }
             shader_addline(buffer, "vec4 vpos;\n");
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index bfde5e4..64a8721 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -233,7 +233,7 @@ static void state_ambient(DWORD state, IWineD3DStateBlockImpl *stateblock, struc
 
 static void state_blend(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *)stateblock->device->render_targets[0];
+    IWineD3DSurfaceImpl *target = stateblock->device->render_targets[0];
     int srcBlend = GL_ZERO;
     int dstBlend = GL_ZERO;
 
@@ -4644,7 +4644,7 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock, s
 
 static void viewport_miscpart(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *)stateblock->device->render_targets[0];
+    IWineD3DSurfaceImpl *target = stateblock->device->render_targets[0];
     UINT width, height;
     WINED3DVIEWPORT vp = stateblock->viewport;
 
@@ -4802,7 +4802,7 @@ static void light(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3
 
 static void scissorrect(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    IWineD3DSurfaceImpl *target = (IWineD3DSurfaceImpl *)stateblock->device->render_targets[0];
+    IWineD3DSurfaceImpl *target = stateblock->device->render_targets[0];
     RECT *pRect = &stateblock->scissorRect;
     UINT height;
     UINT width;
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index b7580c5..b6b59ab 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -554,8 +554,9 @@ static void surface_bind_and_dirtify(IWineD3DSurfaceImpl *This, BOOL srgb) {
 /* This function checks if the primary render target uses the 8bit paletted format. */
 static BOOL primary_render_target_is_p8(IWineD3DDeviceImpl *device)
 {
-    if (device->render_targets && device->render_targets[0]) {
-        IWineD3DSurfaceImpl* render_target = (IWineD3DSurfaceImpl*)device->render_targets[0];
+    if (device->render_targets && device->render_targets[0])
+    {
+        IWineD3DSurfaceImpl *render_target = device->render_targets[0];
         if ((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET)
                 && (render_target->resource.format_desc->format == WINED3DFMT_P8_UINT))
             return TRUE;
@@ -1700,7 +1701,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED
     }
 
     if (!(wined3d_settings.rendertargetlock_mode == RTL_DISABLE
-            && ((This->Flags & SFLAG_SWAPCHAIN) || iface == device->render_targets[0])))
+            && ((This->Flags & SFLAG_SWAPCHAIN) || This == device->render_targets[0])))
     {
         IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, pass_rect);
     }
@@ -1891,7 +1892,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_UnlockRect(IWineD3DSurface *iface) {
         goto unlock_end;
     }
 
-    if ((This->Flags & SFLAG_SWAPCHAIN) || (device->render_targets && iface == device->render_targets[0]))
+    if ((This->Flags & SFLAG_SWAPCHAIN) || (device->render_targets && This == device->render_targets[0]))
     {
         if(wined3d_settings.rendertargetlock_mode == RTL_DISABLE) {
             static BOOL warned = FALSE;
@@ -2152,7 +2153,7 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_
              * in which the main render target uses p8. Some games like GTA Vice City use P8 for texturing which
              * conflicts with this.
              */
-            if (!((blit_supported && device->render_targets && This == (IWineD3DSurfaceImpl*)device->render_targets[0]))
+            if (!((blit_supported && device->render_targets && This == device->render_targets[0]))
                     || colorkey_active || !use_texturing)
             {
                 desc->glFormat = GL_RGBA;
@@ -3377,8 +3378,8 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, const
 
     /* Early sort out of cases where no render target is used */
     if (!dstSwapchain && !srcSwapchain
-            && SrcSurface != device->render_targets[0]
-            && This != (IWineD3DSurfaceImpl *)device->render_targets[0])
+            && Src != device->render_targets[0]
+            && This != device->render_targets[0])
     {
         TRACE("No surface is render target, not using hardware blit. Src = %p, dst = %p\n", Src, This);
         return WINED3DERR_INVALIDCALL;
@@ -3498,17 +3499,17 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, const
     }
     else if (dstSwapchain)
     {
-        /* Handled with regular texture -> swapchain blit. */
-        if (SrcSurface == device->render_targets[0])
+        /* Handled with regular texture -> swapchain blit */
+        if (Src == device->render_targets[0])
             TRACE("Blit from active render target to a swapchain\n");
     }
-    else if (srcSwapchain && This == (IWineD3DSurfaceImpl *)device->render_targets[0])
+    else if (srcSwapchain && This == device->render_targets[0])
     {
         FIXME("Implement blit from a swapchain to the active render target\n");
         return WINED3DERR_INVALIDCALL;
     }
 
-    if ((srcSwapchain || SrcSurface == device->render_targets[0]) && !dstSwapchain)
+    if ((srcSwapchain || Src == device->render_targets[0]) && !dstSwapchain)
     {
         /* Blit from render target to texture */
         BOOL stretchx;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index a0b398a..596935e 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1666,7 +1666,7 @@ struct IWineD3DDeviceImpl
     unsigned int            highest_dirty_ps_const, highest_dirty_vs_const;
 
     /* Render Target Support */
-    IWineD3DSurface       **render_targets;
+    IWineD3DSurfaceImpl **render_targets;
     IWineD3DSurface        *auto_depth_stencil_buffer;
     IWineD3DSurface        *stencilBufferTarget;
 
-- 
1.6.4.4




More information about the wine-patches mailing list