Module: wine Branch: master Commit: 9cafbd6de0be23350cbb1442444c3767d7796352 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=9cafbd6de0be23350cbb1442...
Author: Stefan Dösinger stefan@codeweavers.com Date: Sun Sep 24 09:49:05 2006 +0200
wined3d: Surface data is 32 bit aligned.
---
dlls/d3d9/tests/surface.c | 22 ++++++++++++++++++++++ dlls/wined3d/device.c | 4 +++- dlls/wined3d/surface.c | 5 ++++- dlls/wined3d/surface_gdi.c | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/dlls/d3d9/tests/surface.c b/dlls/d3d9/tests/surface.c index 23b8d73..7934d1f 100644 --- a/dlls/d3d9/tests/surface.c +++ b/dlls/d3d9/tests/surface.c @@ -113,6 +113,27 @@ cleanup: if (surface_ptr) IDirect3DSurface9_Release(surface_ptr); }
+static void test_surface_alignment(IDirect3DDevice9 *device_ptr) +{ + IDirect3DSurface9 *surface_ptr = 0; + HRESULT hr; + + /* Test a sysmem surface as those aren't affected by the hardware's np2 restrictions */ + hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device_ptr, 5, 5, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &surface_ptr, 0); + ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08lx\n", hr); + + if(surface_ptr) + { + D3DLOCKED_RECT lockedRect; + hr = IDirect3DSurface9_LockRect(surface_ptr, &lockedRect, NULL, 0); + ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned %08lx\n", hr); + /* test is deactivated until out np2 support doesn't report the full power of 2 pitch to the app */ + todo_wine ok(lockedRect.Pitch == 12, "Got pitch %d, expected 12\n", lockedRect.Pitch); + hr = IDirect3DSurface9_UnlockRect(surface_ptr); + IDirect3DSurface9_Release(surface_ptr); + } +} + START_TEST(surface) { HMODULE d3d9_handle; @@ -129,4 +150,5 @@ START_TEST(surface) if (!device_ptr) return;
test_surface_get_container(device_ptr); + test_surface_alignment(device_ptr); } diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index c4b9767..7aef3ac 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1001,7 +1001,9 @@ static HRESULT WINAPI IWineD3DDeviceImp Format == WINED3DFMT_DXT4 || Format == WINED3DFMT_DXT5) { Size = ((max(pow2Width,4) * tableEntry->bpp) * max(pow2Height,4)); } else { - Size = (pow2Width * tableEntry->bpp) * pow2Height; + /* The pitch is a multiple of 4 bytes */ + Size = ((pow2Width * tableEntry->bpp) + 3) & ~3; + Size *= pow2Height; }
/** Create and initialise the surface resource **/ diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 908211e..3146475 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -2170,7 +2170,8 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SetFo format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5) { This->resource.size = ((max(This->pow2Width, 4) * formatEntry->bpp) * max(This->pow2Height, 4)); } else { - This->resource.size = (This->pow2Width * formatEntry->bpp) * This->pow2Height; + This->resource.size = ((This->pow2Width * formatEntry->bpp) + 3) & ~3; + This->resource.size *= This->pow2Height; }
@@ -3063,6 +3064,8 @@ DWORD WINAPI IWineD3DSurfaceImpl_GetPitc } else { ret = This->bytesPerPixel * This->pow2Width; } + /* Surfaces are 32 bit aligned */ + ret = (ret + 3) & ~3; } TRACE("(%p) Returning %ld\n", This, ret); return ret; diff --git a/dlls/wined3d/surface_gdi.c b/dlls/wined3d/surface_gdi.c index f9b20c1..65c8aae 100644 --- a/dlls/wined3d/surface_gdi.c +++ b/dlls/wined3d/surface_gdi.c @@ -1516,7 +1516,7 @@ IWineGDISurfaceImpl_PrivateSetup(IWineD3 This->resource.allocatedMemory = NULL;
/* We don't mind the nonpow2 stuff in GDI */ - This->resource.size = This->currentDesc.Width * getFormatDescEntry(This->resource.format)->bpp * This->currentDesc.Height; + This->resource.size = IWineD3DSurface_GetPitch(iface) * This->currentDesc.Height; This->pow2Size = This->resource.size; This->pow2Width = This->currentDesc.Width; This->pow2Height = This->currentDesc.Height;