Henri Verbeet : wined3d: Introduce a separate function to calculate the pitch for a given format and width.
Alexandre Julliard
julliard at winehq.org
Wed Apr 23 14:17:32 CDT 2014
Module: wine
Branch: master
Commit: 81fb749ecf5a4d009d26df2609f3d62e4525d7f0
URL: http://source.winehq.org/git/wine.git/?a=commit;h=81fb749ecf5a4d009d26df2609f3d62e4525d7f0
Author: Henri Verbeet <hverbeet at codeweavers.com>
Date: Wed Apr 23 14:35:19 2014 +0200
wined3d: Introduce a separate function to calculate the pitch for a given format and width.
---
dlls/wined3d/surface.c | 18 ++++--------------
dlls/wined3d/utils.c | 16 +++++++++++++---
dlls/wined3d/wined3d_private.h | 1 +
3 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 7c5f053..0e85b08 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -2435,7 +2435,7 @@ struct wined3d_palette * CDECL wined3d_surface_get_palette(const struct wined3d_
DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
{
- const struct wined3d_format *format = surface->resource.format;
+ unsigned int alignment;
DWORD pitch;
TRACE("surface %p.\n", surface);
@@ -2443,19 +2443,9 @@ DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
if (surface->pitch)
return surface->pitch;
- if (format->flags & WINED3DFMT_FLAG_BLOCKS)
- {
- /* Since compressed formats are block based, pitch means the amount of
- * bytes to the next row of block rather than the next row of pixels. */
- UINT row_block_count = (surface->resource.width + format->block_width - 1) / format->block_width;
- pitch = row_block_count * format->block_byte_count;
- }
- else
- {
- unsigned char alignment = surface->resource.device->surface_alignment;
- pitch = surface->resource.format->byte_count * surface->resource.width; /* Bytes / row */
- pitch = (pitch + alignment - 1) & ~(alignment - 1);
- }
+ alignment = surface->resource.device->surface_alignment;
+ pitch = wined3d_format_calculate_pitch(surface->resource.format, surface->resource.width);
+ pitch = (pitch + alignment - 1) & ~(alignment - 1);
TRACE("Returning %u.\n", pitch);
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 32426d9..78060e2 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -2019,9 +2019,20 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl
return &gl_info->formats[idx];
}
+UINT wined3d_format_calculate_pitch(const struct wined3d_format *format, UINT width)
+{
+ /* For block based formats, pitch means the amount of bytes to the next
+ * row of blocks rather than the next row of pixels. */
+ if (format->flags & WINED3DFMT_FLAG_BLOCKS)
+ return format->block_byte_count * ((width + format->block_width - 1) / format->block_width);
+
+ return format->byte_count * width;
+}
+
UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
UINT width, UINT height, UINT depth)
{
+ UINT pitch = wined3d_format_calculate_pitch(format, width);
UINT size;
if (format->id == WINED3DFMT_UNKNOWN)
@@ -2030,13 +2041,12 @@ UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT ali
}
else if (format->flags & WINED3DFMT_FLAG_BLOCKS)
{
- UINT row_block_count = (width + format->block_width - 1) / format->block_width;
UINT row_count = (height + format->block_height - 1) / format->block_height;
- size = row_count * (((row_block_count * format->block_byte_count) + alignment - 1) & ~(alignment - 1));
+ size = row_count * ((pitch + alignment - 1) & ~(alignment - 1));
}
else
{
- size = height * (((width * format->byte_count) + alignment - 1) & ~(alignment - 1));
+ size = height * ((pitch + alignment - 1) & ~(alignment - 1));
}
if (format->flags & WINED3DFMT_FLAG_HEIGHT_SCALE)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 4ab45cc..9d526fc 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -3040,6 +3040,7 @@ struct wined3d_format
const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info,
enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
+UINT wined3d_format_calculate_pitch(const struct wined3d_format *format, UINT width) DECLSPEC_HIDDEN;
UINT wined3d_format_calculate_size(const struct wined3d_format *format,
UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface,
More information about the wine-cvs
mailing list