From cea59537439aaf4e67ad4c2f9a9eadd1d8e70c11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Sat, 4 Jan 2014 01:02:15 +0100
Subject: wined3d: Remove surface_invalidate_location.

---
 dlls/wined3d/arb_program_shader.c |  2 +-
 dlls/wined3d/context.c            |  2 +-
 dlls/wined3d/device.c             |  4 ++--
 dlls/wined3d/drawprim.c           |  2 +-
 dlls/wined3d/surface.c            | 47 ++++++++++++++++-----------------------
 dlls/wined3d/swapchain.c          |  6 ++---
 dlls/wined3d/texture.c            |  6 ++---
 dlls/wined3d/wined3d_private.h    |  1 -
 8 files changed, 29 insertions(+), 41 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index e22b558..c2a6a96 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -7895,7 +7895,7 @@ static void arbfp_blit_surface(struct wined3d_device *device, enum wined3d_blit_
     context_release(context);
 
     wined3d_resource_validate_location(&dst_surface->resource, dst_surface->container->resource.draw_binding);
-    surface_invalidate_location(dst_surface, ~dst_surface->container->resource.draw_binding);
+    wined3d_resource_invalidate_location(&dst_surface->resource, ~dst_surface->container->resource.draw_binding);
 }
 
 static HRESULT arbfp_blit_color_fill(struct wined3d_device *device, struct wined3d_surface *dst_surface,
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 1e357e7..230946d 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -3311,7 +3311,7 @@ static void context_setup_target(struct wined3d_context *context, struct wined3d
             if (texture->texture_srgb.name)
                 wined3d_texture_load(texture, context, TRUE);
             wined3d_texture_load(texture, context, FALSE);
-            surface_invalidate_location(context->current_rt, WINED3D_LOCATION_DRAWABLE);
+            wined3d_resource_invalidate_location(&context->current_rt->resource, WINED3D_LOCATION_DRAWABLE);
         }
     }
 
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index bacd887..a9ac2ca 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -399,7 +399,7 @@ void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, c
             if (rt)
             {
                 wined3d_resource_validate_location(&rt->resource, rt->container->resource.draw_binding);
-                surface_invalidate_location(rt, ~rt->container->resource.draw_binding);
+                wined3d_resource_invalidate_location(&rt->resource, ~rt->container->resource.draw_binding);
             }
         }
 
@@ -4065,7 +4065,7 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str
     context_release(context);
 
     wined3d_resource_validate_location(&surface->resource, WINED3D_LOCATION_TEXTURE_RGB);
-    surface_invalidate_location(surface, ~WINED3D_LOCATION_TEXTURE_RGB);
+    wined3d_resource_invalidate_location(&surface->resource, ~WINED3D_LOCATION_TEXTURE_RGB);
 }
 
 HRESULT CDECL wined3d_device_clear_rendertarget_view(struct wined3d_device *device,
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 75489db..9ba6ef7 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -628,7 +628,7 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co
             if (state->render_states[WINED3D_RS_COLORWRITEENABLE])
             {
                 surface_load_location(target, context, target->container->resource.draw_binding);
-                surface_invalidate_location(target, ~target->container->resource.draw_binding);
+                wined3d_resource_invalidate_location(&target->resource, ~target->container->resource.draw_binding);
             }
             else
             {
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 728b4b2..374b1da 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -597,7 +597,7 @@ static void surface_evict_sysmem(struct wined3d_surface *surface)
         return;
 
     wined3d_resource_free_sysmem(&surface->resource);
-    surface_invalidate_location(surface, WINED3D_LOCATION_SYSMEM);
+    wined3d_resource_invalidate_location(&surface->resource, WINED3D_LOCATION_SYSMEM);
 }
 
 static BOOL surface_use_pbo(const struct wined3d_surface *surface)
@@ -1095,7 +1095,7 @@ static void surface_remove_pbo(struct wined3d_surface *surface, const struct win
     checkGLcall("glDeleteBuffers(1, &surface->pbo)");
 
     surface->pbo = 0;
-    surface_invalidate_location(surface, WINED3D_LOCATION_BUFFER);
+    wined3d_resource_invalidate_location(&surface->resource, WINED3D_LOCATION_BUFFER);
 }
 
 static ULONG surface_resource_incref(struct wined3d_resource *resource)
@@ -1135,21 +1135,21 @@ static void surface_unload(struct wined3d_resource *resource)
         if (resource->usage & WINED3DUSAGE_DEPTHSTENCIL)
         {
             wined3d_resource_validate_location(&surface->resource, WINED3D_LOCATION_DISCARDED);
-            surface_invalidate_location(surface, ~WINED3D_LOCATION_DISCARDED);
+            wined3d_resource_invalidate_location(&surface->resource, ~WINED3D_LOCATION_DISCARDED);
         }
         else
         {
             surface_prepare_system_memory(surface);
             memset(surface->resource.heap_memory, 0, surface->resource.size);
             wined3d_resource_validate_location(&surface->resource, WINED3D_LOCATION_SYSMEM);
-            surface_invalidate_location(surface, ~WINED3D_LOCATION_SYSMEM);
+            wined3d_resource_invalidate_location(&surface->resource, ~WINED3D_LOCATION_SYSMEM);
         }
     }
     else
     {
         surface_prepare_map_memory(surface);
         surface_load_location(surface, context, surface->resource.map_binding);
-        surface_invalidate_location(surface, ~surface->resource.map_binding);
+        wined3d_resource_invalidate_location(&surface->resource, ~surface->resource.map_binding);
     }
 
     /* Destroy PBOs, but load them into real sysmem before */
@@ -1200,7 +1200,10 @@ static HRESULT surface_resource_sub_resource_unmap(struct wined3d_resource *reso
 
 static void wined3d_surface_location_invalidated(struct wined3d_resource *resource, DWORD location)
 {
-    ERR("Not yet implemented.\n");
+    struct wined3d_surface *surface = surface_from_resource(resource);
+
+    if (location & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
+        wined3d_texture_set_dirty(surface->container);
 }
 
 static const struct wined3d_resource_ops surface_resource_ops =
@@ -1678,7 +1681,7 @@ HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const P
     context_release(context);
 
     wined3d_resource_validate_location(&dst_surface->resource, WINED3D_LOCATION_TEXTURE_RGB);
-    surface_invalidate_location(dst_surface, ~WINED3D_LOCATION_TEXTURE_RGB);
+    wined3d_resource_invalidate_location(&dst_surface->resource, ~WINED3D_LOCATION_TEXTURE_RGB);
 
     return WINED3D_OK;
 }
@@ -2678,7 +2681,7 @@ HRESULT CDECL wined3d_surface_map(struct wined3d_surface *surface,
     }
 
     if (!(flags & (WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY)))
-        surface_invalidate_location(surface, ~surface->resource.map_binding);
+        wined3d_resource_invalidate_location(&surface->resource, ~surface->resource.map_binding);
 
     switch (surface->resource.map_binding)
     {
@@ -2788,7 +2791,7 @@ HRESULT CDECL wined3d_surface_getdc(struct wined3d_surface *surface, HDC *dc)
     }
 
     surface_load_location(surface, context, WINED3D_LOCATION_DIB);
-    surface_invalidate_location(surface, ~WINED3D_LOCATION_DIB);
+    wined3d_resource_invalidate_location(&surface->resource, ~WINED3D_LOCATION_DIB);
 
     if (context)
         context_release(context);
@@ -2837,7 +2840,7 @@ HRESULT CDECL wined3d_surface_releasedc(struct wined3d_surface *surface, HDC dc)
             context = context_acquire(device, NULL);
 
         surface_load_location(surface, context, surface->resource.map_binding);
-        surface_invalidate_location(surface, WINED3D_LOCATION_DIB);
+        wined3d_resource_invalidate_location(&surface->resource, WINED3D_LOCATION_DIB);
         if (context)
             context_release(context);
     }
@@ -3144,7 +3147,7 @@ static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struc
     /* The texture is now most up to date - If the surface is a render target
      * and has a drawable, this path is never entered. */
     wined3d_resource_validate_location(&dst_surface->resource, WINED3D_LOCATION_TEXTURE_RGB);
-    surface_invalidate_location(dst_surface, ~WINED3D_LOCATION_TEXTURE_RGB);
+    wined3d_resource_invalidate_location(&dst_surface->resource, ~WINED3D_LOCATION_TEXTURE_RGB);
 }
 
 /* Uses the hardware to stretch and flip the image */
@@ -3212,7 +3215,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
         checkGLcall("glEnable(texture_target)");
 
         /* For now invalidate the texture copy of the back buffer. Drawable and sysmem copy are untouched */
-        src_surface->resource.locations &= ~WINED3D_LOCATION_TEXTURE_RGB;
+        wined3d_resource_invalidate_location(&src_surface->resource, WINED3D_LOCATION_TEXTURE_RGB);
     }
 
     /* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
@@ -3417,7 +3420,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
     /* The texture is now most up to date - If the surface is a render target
      * and has a drawable, this path is never entered. */
     wined3d_resource_validate_location(&dst_surface->resource, WINED3D_LOCATION_TEXTURE_RGB);
-    surface_invalidate_location(dst_surface, ~WINED3D_LOCATION_TEXTURE_RGB);
+    wined3d_resource_invalidate_location(&dst_surface->resource, ~WINED3D_LOCATION_TEXTURE_RGB);
 }
 
 /* Front buffer coordinates are always full screen coordinates, but our GL
@@ -3894,18 +3897,6 @@ void surface_load_ds_location(struct wined3d_surface *surface, struct wined3d_co
     surface->ds_current_size.cy = surface->resource.height;
 }
 
-void surface_invalidate_location(struct wined3d_surface *surface, DWORD location)
-{
-    TRACE("surface %p, location %s.\n", surface, wined3d_debug_location(location));
-
-    if (location & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
-        wined3d_texture_set_dirty(surface->container);
-    surface->resource.locations &= ~location;
-
-    if (!surface->resource.locations)
-        ERR("Surface %p does not have any up to date location.\n", surface);
-}
-
 static DWORD resource_access_from_location(DWORD location)
 {
     switch (location)
@@ -4472,7 +4463,7 @@ static void ffp_blit_blit_surface(struct wined3d_device *device, enum wined3d_bl
             (old_color_key_flags & WINED3D_CKEY_SRC_BLT) ? &old_blt_key : NULL);
 
     wined3d_resource_validate_location(&dst_surface->resource, dst_surface->container->resource.draw_binding);
-    surface_invalidate_location(dst_surface, ~dst_surface->container->resource.draw_binding);
+    wined3d_resource_invalidate_location(&dst_surface->resource, ~dst_surface->container->resource.draw_binding);
 }
 
 const struct blit_shader ffp_blit =  {
@@ -5458,7 +5449,7 @@ HRESULT CDECL wined3d_surface_blt(struct wined3d_surface *dst_surface, const REC
                 context_release(context);
 
                 wined3d_resource_validate_location(&dst_surface->resource, dst_surface->container->resource.draw_binding);
-                surface_invalidate_location(dst_surface, ~dst_surface->container->resource.draw_binding);
+                wined3d_resource_invalidate_location(&dst_surface->resource, ~dst_surface->container->resource.draw_binding);
 
                 return WINED3D_OK;
             }
@@ -5581,7 +5572,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text
     {
         wined3d_resource_free_sysmem(&surface->resource);
         wined3d_resource_validate_location(&surface->resource, WINED3D_LOCATION_DIB);
-        surface_invalidate_location(surface, WINED3D_LOCATION_SYSMEM);
+        wined3d_resource_invalidate_location(&surface->resource, WINED3D_LOCATION_SYSMEM);
     }
 
     return hr;
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index 68f12e5..2797067 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -526,7 +526,7 @@ static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT
     if (!swapchain->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
     {
         surface_load_location(back_buffer, context, WINED3D_LOCATION_TEXTURE_RGB);
-        surface_invalidate_location(back_buffer, WINED3D_LOCATION_DRAWABLE);
+        wined3d_resource_invalidate_location(&back_buffer->resource, WINED3D_LOCATION_DRAWABLE);
         swapchain->render_to_fbo = TRUE;
         swapchain_update_draw_bindings(swapchain);
     }
@@ -571,7 +571,7 @@ static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT
     front = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0));
 
     wined3d_resource_validate_location(&front->resource, WINED3D_LOCATION_DRAWABLE);
-    surface_invalidate_location(front, ~WINED3D_LOCATION_DRAWABLE);
+    wined3d_resource_invalidate_location(&front->resource, ~WINED3D_LOCATION_DRAWABLE);
     /* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM
      * and INTEXTURE copies can keep their old content if they have any defined content.
      * If the swapeffect is COPY, the content remains the same.
@@ -844,7 +844,7 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
     if (!(device->wined3d->flags & WINED3D_NO3D))
     {
         wined3d_resource_validate_location(&front_buffer->resource, WINED3D_LOCATION_DRAWABLE);
-        surface_invalidate_location(front_buffer, ~WINED3D_LOCATION_DRAWABLE);
+        wined3d_resource_invalidate_location(&front_buffer->resource, ~WINED3D_LOCATION_DRAWABLE);
     }
 
     /* MSDN says we're only allowed a single fullscreen swapchain per device,
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 8f4c625..b6d21cb 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -776,7 +776,7 @@ static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub
     context = context_acquire(surface->resource.device, NULL);
     surface_load_location(surface, context, surface->resource.map_binding);
     context_release(context);
-    surface_invalidate_location(surface, ~surface->resource.map_binding);
+    wined3d_resource_invalidate_location(&surface->resource, ~surface->resource.map_binding);
 }
 
 static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource)
@@ -788,9 +788,7 @@ static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource
 
 static void texture2d_sub_resource_invalidate_location(struct wined3d_resource *sub_resource, DWORD location)
 {
-    struct wined3d_surface *surface = surface_from_resource(sub_resource);
-
-    surface_invalidate_location(surface, location);
+    wined3d_resource_invalidate_location(sub_resource, location);
 }
 
 static void texture2d_sub_resource_validate_location(struct wined3d_resource *sub_resource, DWORD location)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 0a10b6b..ac43834 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2460,7 +2460,6 @@ HRESULT surface_color_fill(struct wined3d_surface *s,
 GLenum surface_get_gl_buffer(const struct wined3d_surface *surface) DECLSPEC_HIDDEN;
 void surface_get_drawable_size(const struct wined3d_surface *surface, const struct wined3d_context *context,
         unsigned int *width, unsigned int *height) DECLSPEC_HIDDEN;
-void surface_invalidate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN;
 void surface_load(struct wined3d_surface *surface, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
 void surface_load_ds_location(struct wined3d_surface *surface,
         struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
-- 
2.6.4

