From f647fdb1959507c9efac2160fc333defca6c2eb0 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 21 Feb 2016 23:30:15 +0100
Subject: Revert "wined3d: Introduce wined3d_texture_check_block_align()."

This reverts commit 58719f60d5dca15f0f0de625bc307e04b01fc6d9.
---
 dlls/wined3d/surface.c         | 31 +++++++++++++++++++++++++++++--
 dlls/wined3d/texture.c         | 29 -----------------------------
 dlls/wined3d/volume.c          | 31 +++++++++++++++++++++++++++++--
 dlls/wined3d/wined3d_private.h |  2 --
 4 files changed, 58 insertions(+), 35 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 4e59ca8..6ddf257 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -1539,11 +1539,38 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w
     }
 }
 
+static BOOL surface_check_block_align(struct wined3d_surface *surface, const struct wined3d_box *box)
+{
+    UINT width_mask, height_mask;
+
+    if (!box->left && !box->top
+            && box->right == surface->resource.width
+            && box->bottom == surface->resource.height)
+        return TRUE;
+
+    if ((box->left >= box->right)
+            || (box->top >= box->bottom)
+            || (box->right > surface->resource.width)
+            || (box->bottom > surface->resource.height))
+        return FALSE;
+
+    /* This assumes power of two block sizes, but NPOT block sizes would be
+     * silly anyway. */
+    width_mask = surface->resource.format->block_width - 1;
+    height_mask = surface->resource.format->block_height - 1;
+
+    if (!(box->left & width_mask) && !(box->top & height_mask)
+            && !(box->right & width_mask) && !(box->bottom & height_mask))
+        return TRUE;
+
+    return FALSE;
+}
+
 static BOOL surface_check_block_align_rect(struct wined3d_surface *surface, const RECT *rect)
 {
     struct wined3d_box box = {rect->left, rect->top, rect->right, rect->bottom, 0, 1};
 
-    return wined3d_texture_check_block_align(surface->container, surface->texture_level, &box);
+    return surface_check_block_align(surface, &box);
 }
 
 HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
@@ -2423,7 +2450,7 @@ HRESULT wined3d_surface_map(struct wined3d_surface *surface, struct wined3d_map_
     }
 
     if ((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && box
-            && !wined3d_texture_check_block_align(surface->container, surface->texture_level, box))
+            && !surface_check_block_align(surface, box))
     {
         WARN("Map box %s is misaligned for %ux%u blocks.\n",
                 debug_box(box), format->block_width, format->block_height);
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 24f149b..c4ba1c5 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -1209,35 +1209,6 @@ static const struct wined3d_texture_ops texture3d_ops =
     texture3d_prepare_texture,
 };
 
-BOOL wined3d_texture_check_block_align(const struct wined3d_texture *texture,
-        unsigned int level, const struct wined3d_box *box)
-{
-    const struct wined3d_format *format = texture->resource.format;
-    unsigned int height = max(1, texture->resource.height >> level);
-    unsigned int width = max(1, texture->resource.width >> level);
-    unsigned int width_mask, height_mask;
-
-    if ((box->left >= box->right)
-            || (box->top >= box->bottom)
-            || (box->right > width)
-            || (box->bottom > height))
-        return FALSE;
-
-    /* This assumes power of two block sizes, but NPOT block sizes would be
-     * silly anyway.
-     *
-     * This also assumes that the format's block depth is 1. */
-    width_mask = format->block_width - 1;
-    height_mask = format->block_height - 1;
-
-    if ((box->left & width_mask) || (box->top & height_mask)
-            || (box->right & width_mask && box->right != width)
-            || (box->bottom & height_mask && box->bottom != height))
-        return FALSE;
-
-    return TRUE;
-}
-
 static HRESULT texture3d_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
         struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
 {
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 6f5de73..75585d8 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -433,6 +433,34 @@ static void volume_unload(struct wined3d_resource *resource)
     resource_unload(resource);
 }
 
+static BOOL volume_check_block_align(const struct wined3d_volume *volume,
+        const struct wined3d_box *box)
+{
+    UINT width_mask, height_mask;
+    const struct wined3d_format *format = volume->resource.format;
+
+    if (!box)
+        return TRUE;
+
+    /* This assumes power of two block sizes, but NPOT block sizes would be
+     * silly anyway.
+     *
+     * This also assumes that the format's block depth is 1. */
+    width_mask = format->block_width - 1;
+    height_mask = format->block_height - 1;
+
+    if (box->left & width_mask)
+        return FALSE;
+    if (box->top & height_mask)
+        return FALSE;
+    if (box->right & width_mask && box->right != volume->resource.width)
+        return FALSE;
+    if (box->bottom & height_mask && box->bottom != volume->resource.height)
+        return FALSE;
+
+    return TRUE;
+}
+
 static BOOL wined3d_volume_check_box_dimensions(const struct wined3d_volume *volume,
         const struct wined3d_box *box)
 {
@@ -484,8 +512,7 @@ HRESULT wined3d_volume_map(struct wined3d_volume *volume,
         WARN("Map box is invalid.\n");
         return WINED3DERR_INVALIDCALL;
     }
-    if ((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && box
-            && !wined3d_texture_check_block_align(volume->container, volume->texture_level, box))
+    if ((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !volume_check_block_align(volume, box))
     {
         WARN("Map box %s is misaligned for %ux%u blocks.\n",
                 debug_box(box), format->block_width, format->block_height);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index cce0929..cf51a38 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2407,8 +2407,6 @@ void wined3d_texture_bind(struct wined3d_texture *texture,
         struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
 void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture,
         struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
-BOOL wined3d_texture_check_block_align(const struct wined3d_texture *texture,
-        unsigned int level, const struct wined3d_box *box) DECLSPEC_HIDDEN;
 void wined3d_texture_force_reload(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
 struct wined3d_resource *wined3d_texture_get_sub_resource(const struct wined3d_texture *texture,
         UINT sub_resource_idx) DECLSPEC_HIDDEN;
-- 
2.7.1

