Module: wine Branch: master Commit: fede35d1c5fd6760ae908b25d6a6be9126b1802a URL: http://source.winehq.org/git/wine.git/?a=commit;h=fede35d1c5fd6760ae908b25d6...
Author: Henri Verbeet hverbeet@codeweavers.com Date: Mon Jun 15 09:06:49 2009 +0200
wined3d: Introduce surface_calculate_size().
---
dlls/wined3d/surface.c | 44 +++++++++++++++++++++++---------------- dlls/wined3d/surface_base.c | 18 ++------------- dlls/wined3d/wined3d_private.h | 1 + 3 files changed, 30 insertions(+), 33 deletions(-)
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 33fc51a..36ba6c5 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -94,6 +94,31 @@ static void surface_cleanup(IWineD3DSurfaceImpl *This) resource_cleanup((IWineD3DResource *)This); }
+UINT surface_calculate_size(const struct GlPixelFormatDesc *format_desc, UINT alignment, UINT width, UINT height) +{ + UINT size; + + if (format_desc->format == WINED3DFMT_UNKNOWN) + { + size = 0; + } + else if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED) + { + UINT row_block_count = (width + format_desc->block_width - 1) / format_desc->block_width; + UINT row_count = (height + format_desc->block_height - 1) / format_desc->block_height; + size = row_count * row_block_count * format_desc->block_byte_count; + } + else + { + /* The pitch is a multiple of 4 bytes. */ + size = height * (((width * format_desc->byte_count) + alignment - 1) & ~(alignment - 1)); + } + + if (format_desc->heightscale != 0.0) size *= format_desc->heightscale; + + return size; +} + HRESULT surface_init(IWineD3DSurfaceImpl *surface, WINED3DSURFTYPE surface_type, UINT alignment, UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type, UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, @@ -113,24 +138,7 @@ HRESULT surface_init(IWineD3DSurfaceImpl *surface, WINED3DSURFTYPE surface_type,
/* FIXME: Check that the format is supported by the device. */
- if (format == WINED3DFMT_UNKNOWN) - { - resource_size = 0; - } - else if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED) - { - UINT row_block_count = (width + format_desc->block_width - 1) / format_desc->block_width; - UINT row_count = (height + format_desc->block_height - 1) / format_desc->block_height; - resource_size = row_count * row_block_count * format_desc->block_byte_count; - } - else - { - /* The pitch is a multiple of 4 bytes. */ - resource_size = ((width * format_desc->byte_count) + alignment - 1) & ~(alignment - 1); - resource_size *= height; - } - - if (format_desc->heightscale != 0.0) resource_size *= format_desc->heightscale; + resource_size = surface_calculate_size(format_desc, alignment, width, height);
/* Look at the implementation and set the correct Vtable. */ switch (surface_type) diff --git a/dlls/wined3d/surface_base.c b/dlls/wined3d/surface_base.c index e17f892..1d1341b 100644 --- a/dlls/wined3d/surface_base.c +++ b/dlls/wined3d/surface_base.c @@ -519,21 +519,9 @@ HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3D }
TRACE("(%p) : Setting texture format to (%d,%s)\n", This, format, debug_d3dformat(format)); - if (format == WINED3DFMT_UNKNOWN) { - This->resource.size = 0; - } - else if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED) - { - UINT row_block_count = (This->pow2Width + format_desc->block_width - 1) / format_desc->block_width; - UINT row_count = (This->pow2Height + format_desc->block_height - 1) / format_desc->block_height; - This->resource.size = row_count * row_block_count * format_desc->block_byte_count; - } - else - { - unsigned char alignment = This->resource.wineD3DDevice->surface_alignment; - This->resource.size = ((This->pow2Width * format_desc->byte_count) + alignment - 1) & ~(alignment - 1); - This->resource.size *= This->pow2Height; - } + + This->resource.size = surface_calculate_size(format_desc, This->resource.wineD3DDevice->surface_alignment, + This->pow2Width, This->pow2Height);
This->Flags |= (WINED3DFMT_D16_LOCKABLE == format) ? SFLAG_LOCKABLE : 0;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index a1ac336..331015c 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1920,6 +1920,7 @@ struct IWineD3DSurfaceImpl extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl; extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
+UINT surface_calculate_size(const struct GlPixelFormatDesc *format_desc, UINT alignment, UINT width, UINT height); void surface_gdi_cleanup(IWineD3DSurfaceImpl *This); HRESULT surface_init(IWineD3DSurfaceImpl *surface, WINED3DSURFTYPE surface_type, UINT alignment, UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,