Commit 81fb749e authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Introduce a separate function to calculate the pitch for a given format and width.

parent a1c63c27
...@@ -2435,7 +2435,7 @@ struct wined3d_palette * CDECL wined3d_surface_get_palette(const struct wined3d_ ...@@ -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) DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
{ {
const struct wined3d_format *format = surface->resource.format; unsigned int alignment;
DWORD pitch; DWORD pitch;
TRACE("surface %p.\n", surface); TRACE("surface %p.\n", surface);
...@@ -2443,19 +2443,9 @@ DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface) ...@@ -2443,19 +2443,9 @@ DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
if (surface->pitch) if (surface->pitch)
return surface->pitch; return surface->pitch;
if (format->flags & WINED3DFMT_FLAG_BLOCKS) alignment = surface->resource.device->surface_alignment;
{ pitch = wined3d_format_calculate_pitch(surface->resource.format, surface->resource.width);
/* Since compressed formats are block based, pitch means the amount of pitch = (pitch + alignment - 1) & ~(alignment - 1);
* 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);
}
TRACE("Returning %u.\n", pitch); TRACE("Returning %u.\n", pitch);
......
...@@ -2019,9 +2019,20 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl ...@@ -2019,9 +2019,20 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl
return &gl_info->formats[idx]; 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 wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
UINT width, UINT height, UINT depth) UINT width, UINT height, UINT depth)
{ {
UINT pitch = wined3d_format_calculate_pitch(format, width);
UINT size; UINT size;
if (format->id == WINED3DFMT_UNKNOWN) if (format->id == WINED3DFMT_UNKNOWN)
...@@ -2030,13 +2041,12 @@ UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT ali ...@@ -2030,13 +2041,12 @@ UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT ali
} }
else if (format->flags & WINED3DFMT_FLAG_BLOCKS) 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; 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 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) if (format->flags & WINED3DFMT_FLAG_HEIGHT_SCALE)
......
...@@ -3040,6 +3040,7 @@ struct wined3d_format ...@@ -3040,6 +3040,7 @@ struct wined3d_format
const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info, const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info,
enum wined3d_format_id format_id) DECLSPEC_HIDDEN; 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 wined3d_format_calculate_size(const struct wined3d_format *format,
UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN; UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface, DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment