https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e7b199daff6bc0951fc2ce...
commit e7b199daff6bc0951fc2ce3b50b9cd17156ae0b5 Author: Amine Khaldi amine.khaldi@reactos.org AuthorDate: Fri Jan 25 13:10:23 2019 +0100 Commit: Amine Khaldi amine.khaldi@reactos.org CommitDate: Fri Jan 25 13:10:23 2019 +0100
[D3DX9_*] Sync with Wine Staging 4.0. CORE-15682 --- dll/directx/wine/d3dx9_36/font.c | 5 +- dll/directx/wine/d3dx9_36/math.c | 24 ++++-- dll/directx/wine/d3dx9_36/shader.c | 8 +- dll/directx/wine/d3dx9_36/surface.c | 150 ++++++++++++++++++++++++++++-------- media/doc/README.WINE | 2 +- 5 files changed, 141 insertions(+), 48 deletions(-)
diff --git a/dll/directx/wine/d3dx9_36/font.c b/dll/directx/wine/d3dx9_36/font.c index b4b9600320..05e490fd2a 100644 --- a/dll/directx/wine/d3dx9_36/font.c +++ b/dll/directx/wine/d3dx9_36/font.c @@ -134,7 +134,7 @@ static HRESULT WINAPI ID3DXFontImpl_GetDescA(ID3DXFont *iface, D3DXFONT_DESCA *d
if( !desc ) return D3DERR_INVALIDCALL; memcpy(desc, &This->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName)); - WideCharToMultiByte(CP_ACP, 0, This->desc.FaceName, -1, desc->FaceName, sizeof(desc->FaceName) / sizeof(CHAR), NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, This->desc.FaceName, -1, desc->FaceName, ARRAY_SIZE(desc->FaceName), NULL, NULL);
return D3D_OK; } @@ -483,8 +483,7 @@ HRESULT WINAPI D3DXCreateFontIndirectA(IDirect3DDevice9 *device, const D3DXFONT_ /* Copy everything but the last structure member. This requires the two D3DXFONT_DESC structures to be equal until the FaceName member */ memcpy(&widedesc, desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName)); - MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1, - widedesc.FaceName, sizeof(widedesc.FaceName)/sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1, widedesc.FaceName, ARRAY_SIZE(widedesc.FaceName)); return D3DXCreateFontIndirectW(device, &widedesc, font); }
diff --git a/dll/directx/wine/d3dx9_36/math.c b/dll/directx/wine/d3dx9_36/math.c index 8909c3c6b2..03ccbd04e1 100644 --- a/dll/directx/wine/d3dx9_36/math.c +++ b/dll/directx/wine/d3dx9_36/math.c @@ -794,24 +794,34 @@ D3DXMATRIX* WINAPI D3DXMatrixTransformation(D3DXMATRIX *pout, const D3DXVECTOR3
D3DXMatrixTranslation(&m1, -psc.x, -psc.y, -psc.z);
- if ( !pscalingrotation ) + if ( !pscalingrotation || !pscaling ) { D3DXMatrixIdentity(&m2); D3DXMatrixIdentity(&m4); } else { + D3DXQUATERNION temp; + D3DXMatrixRotationQuaternion(&m4, pscalingrotation); - D3DXMatrixInverse(&m2, NULL, &m4); + temp.w = pscalingrotation->w; + temp.x = -pscalingrotation->x; + temp.y = -pscalingrotation->y; + temp.z = -pscalingrotation->z; + D3DXMatrixRotationQuaternion(&m2, &temp); }
- if ( !pscaling ) D3DXMatrixIdentity(&m3); - else D3DXMatrixScaling(&m3, pscaling->x, pscaling->y, pscaling->z); + if ( !pscaling ) + D3DXMatrixIdentity(&m3); + else + D3DXMatrixScaling(&m3, pscaling->x, pscaling->y, pscaling->z);
- if ( !protation ) D3DXMatrixIdentity(&m6); - else D3DXMatrixRotationQuaternion(&m6, protation); + if ( !protation ) + D3DXMatrixIdentity(&m6); + else + D3DXMatrixRotationQuaternion(&m6, protation);
- D3DXMatrixTranslation(&m5, psc.x - prc.x, psc.y - prc.y, psc.z - prc.z); + D3DXMatrixTranslation(&m5, psc.x - prc.x, psc.y - prc.y, psc.z - prc.z); D3DXMatrixTranslation(&m7, prc.x + pt.x, prc.y + pt.y, prc.z + pt.z); D3DXMatrixMultiply(&m1, &m1, &m2); D3DXMatrixMultiply(&m1, &m1, &m3); diff --git a/dll/directx/wine/d3dx9_36/shader.c b/dll/directx/wine/d3dx9_36/shader.c index d3f6570f9f..fc0f503c69 100644 --- a/dll/directx/wine/d3dx9_36/shader.c +++ b/dll/directx/wine/d3dx9_36/shader.c @@ -2776,18 +2776,20 @@ HRESULT WINAPI D3DXCreateTextureShader(const DWORD *function, ID3DXTextureShader
static unsigned int get_instr_length(const DWORD *byte_code, unsigned int major, unsigned int minor) { + DWORD opcode = *byte_code & 0xffff; unsigned int len = 0;
+ if (opcode == D3DSIO_COMMENT) + return (*byte_code & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT; + if (major > 1) return (*byte_code & D3DSI_INSTLENGTH_MASK) >> D3DSI_INSTLENGTH_SHIFT;
- switch (*byte_code & 0xffff) + switch (opcode) { case D3DSIO_END: ERR("Unexpected END token.\n"); return 0; - case D3DSIO_COMMENT: - return (*byte_code & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT; case D3DSIO_DEF: case D3DSIO_DEFI: return 5; diff --git a/dll/directx/wine/d3dx9_36/surface.c b/dll/directx/wine/d3dx9_36/surface.c index 73a1cbde1a..ed82bcfbbd 100644 --- a/dll/directx/wine/d3dx9_36/surface.c +++ b/dll/directx/wine/d3dx9_36/surface.c @@ -1875,10 +1875,14 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, DWORD filter, D3DCOLOR color_key) { const struct pixel_format_desc *srcformatdesc, *destformatdesc; + void *tmp_src_memory = NULL, *tmp_dst_memory = NULL; + dxtn_conversion_func pre_convert = NULL, post_convert = NULL; + IDirect3DSurface9 *surface = dst_surface; + IDirect3DDevice9 *device; D3DSURFACE_DESC surfdesc; D3DLOCKED_RECT lockrect; struct volume src_size, dst_size; - HRESULT ret = D3D_OK; + HRESULT hr = D3D_OK;
TRACE("(%p, %p, %s, %p, %#x, %u, %p, %s, %#x, 0x%08x)\n", dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_memory, src_format, @@ -1934,6 +1938,26 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, return E_NOTIMPL; }
+ if (surfdesc.Pool == D3DPOOL_DEFAULT && !(surfdesc.Usage & D3DUSAGE_DYNAMIC)) + { + IDirect3DSurface9_GetDevice(dst_surface, &device); + hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, surfdesc.Width, + surfdesc.Height, surfdesc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL); + IDirect3DDevice9_Release(device); + if (FAILED(hr)) + { + WARN("Failed to create staging surface, hr %#x.\n", hr); + return D3DERR_INVALIDCALL; + } + } + + if (FAILED(IDirect3DSurface9_LockRect(surface, &lockrect, dst_rect, 0))) + { + if (surface != dst_surface) + IDirect3DSurface9_Release(surface); + return D3DXERR_INVALIDDATA; + } + if (src_format == surfdesc.Format && dst_size.width == src_size.width && dst_size.height == src_size.height @@ -1947,21 +1971,15 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, && src_size.height != surfdesc.Height)) { WARN("Source rect %s is misaligned.\n", wine_dbgstr_rect(src_rect)); - return D3DXERR_INVALIDDATA; + hr = D3DXERR_INVALIDDATA; + goto done; }
- if (FAILED(IDirect3DSurface9_LockRect(dst_surface, &lockrect, dst_rect, 0))) - return D3DXERR_INVALIDDATA; - copy_pixels(src_memory, src_pitch, 0, lockrect.pBits, lockrect.Pitch, 0, &src_size, srcformatdesc); - - IDirect3DSurface9_UnlockRect(dst_surface); } else /* Stretching or format conversion. */ { - dxtn_conversion_func pre_convert, post_convert; - void *tmp_src_memory = NULL, *tmp_dst_memory = NULL; UINT tmp_src_pitch, tmp_dst_pitch;
pre_convert = get_dxtn_conversion_func(srcformatdesc->format, FALSE); @@ -1971,27 +1989,25 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, (!post_convert && !is_conversion_to_supported(destformatdesc))) { FIXME("Unsupported format conversion %#x -> %#x.\n", src_format, surfdesc.Format); - return E_NOTIMPL; + hr = E_NOTIMPL; + goto done; }
- if (FAILED(IDirect3DSurface9_LockRect(dst_surface, &lockrect, dst_rect, 0))) - return D3DXERR_INVALIDDATA; - /* handle pre-conversion */ if (pre_convert) { tmp_src_memory = HeapAlloc(GetProcessHeap(), 0, src_size.width * src_size.height * sizeof(DWORD)); if (!tmp_src_memory) { - ret = E_OUTOFMEMORY; - goto error; + hr = E_OUTOFMEMORY; + goto done; } tmp_src_pitch = src_size.width * sizeof(DWORD); if (!pre_convert(src_memory, tmp_src_memory, src_pitch, tmp_src_pitch, WINED3DFMT_B8G8R8A8_UNORM, src_size.width, src_size.height)) { - ret = E_FAIL; - goto error; + hr = E_FAIL; + goto done; } srcformatdesc = get_format_info(D3DFMT_A8R8G8B8); } @@ -2007,8 +2023,8 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, tmp_dst_memory = HeapAlloc(GetProcessHeap(), 0, dst_size.width * dst_size.height * sizeof(DWORD)); if (!tmp_dst_memory) { - ret = E_OUTOFMEMORY; - goto error; + hr = E_OUTOFMEMORY; + goto done; } tmp_dst_pitch = dst_size.width * sizeof(DWORD); destformatdesc = get_format_info(D3DFMT_A8R8G8B8); @@ -2041,12 +2057,24 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, if (!post_convert(tmp_dst_memory, lockrect.pBits, tmp_dst_pitch, lockrect.Pitch, WINED3DFMT_B8G8R8A8_UNORM, dst_size.width, dst_size.height)) { - ret = E_FAIL; - goto error; + hr = E_FAIL; + goto done; } } + } + +done: + IDirect3DSurface9_UnlockRect(surface); + if (surface != dst_surface) + { + if (SUCCEEDED(hr)) + { + IDirect3DSurface9_GetDevice(dst_surface, &device); + hr = IDirect3DDevice9_UpdateSurface(device, surface, NULL, dst_surface, NULL); + IDirect3DDevice9_Release(device); + } + IDirect3DSurface9_Release(surface);
-error: if (pre_convert) HeapFree(GetProcessHeap(), 0, tmp_src_memory); if (post_convert) @@ -2054,7 +2082,7 @@ error: IDirect3DSurface9_UnlockRect(dst_surface); }
- return ret; + return hr; }
/************************************************************ @@ -2083,10 +2111,13 @@ HRESULT WINAPI D3DXLoadSurfaceFromSurface(IDirect3DSurface9 *dst_surface, const PALETTEENTRY *dst_palette, const RECT *dst_rect, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect, DWORD filter, D3DCOLOR color_key) { - RECT rect; + IDirect3DSurface9 *surface = src_surface; + D3DTEXTUREFILTERTYPE d3d_filter; + IDirect3DDevice9 *device; + D3DSURFACE_DESC src_desc; D3DLOCKED_RECT lock; - D3DSURFACE_DESC SrcDesc; HRESULT hr; + RECT s;
TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_surface %p, " "src_palette %p, src_rect %s, filter %#x, color_key 0x%08x.\n", @@ -2096,20 +2127,71 @@ HRESULT WINAPI D3DXLoadSurfaceFromSurface(IDirect3DSurface9 *dst_surface, if (!dst_surface || !src_surface) return D3DERR_INVALIDCALL;
- IDirect3DSurface9_GetDesc(src_surface, &SrcDesc); + if (!dst_palette && !src_palette && !color_key) + { + switch (filter) + { + case D3DX_FILTER_NONE: + d3d_filter = D3DTEXF_NONE; + break; + + case D3DX_FILTER_POINT: + d3d_filter = D3DTEXF_POINT; + break; + + case D3DX_FILTER_LINEAR: + d3d_filter = D3DTEXF_LINEAR; + break; + + default: + d3d_filter = ~0u; + break; + } + + if (d3d_filter != ~0u) + { + IDirect3DSurface9_GetDevice(src_surface, &device); + hr = IDirect3DDevice9_StretchRect(device, src_surface, src_rect, dst_surface, dst_rect, d3d_filter); + IDirect3DDevice9_Release(device); + if (SUCCEEDED(hr)) + return D3D_OK; + } + } + + IDirect3DSurface9_GetDesc(src_surface, &src_desc);
if (!src_rect) - SetRect(&rect, 0, 0, SrcDesc.Width, SrcDesc.Height); - else - rect = *src_rect; + { + SetRect(&s, 0, 0, src_desc.Width, src_desc.Height); + src_rect = &s; + }
- if (FAILED(IDirect3DSurface9_LockRect(src_surface, &lock, NULL, D3DLOCK_READONLY))) - return D3DXERR_INVALIDDATA; + if (FAILED(IDirect3DSurface9_LockRect(surface, &lock, NULL, D3DLOCK_READONLY))) + { + IDirect3DSurface9_GetDevice(src_surface, &device); + if (FAILED(IDirect3DDevice9_CreateRenderTarget(device, src_desc.Width, src_desc.Height, + src_desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, &surface, NULL))) + { + IDirect3DDevice9_Release(device); + return D3DXERR_INVALIDDATA; + }
- hr = D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, - lock.pBits, SrcDesc.Format, lock.Pitch, src_palette, &rect, filter, color_key); + if (SUCCEEDED(hr = IDirect3DDevice9_StretchRect(device, src_surface, NULL, surface, NULL, D3DTEXF_NONE))) + hr = IDirect3DSurface9_LockRect(surface, &lock, NULL, D3DLOCK_READONLY); + IDirect3DDevice9_Release(device); + if (FAILED(hr)) + { + IDirect3DSurface9_Release(surface); + return D3DXERR_INVALIDDATA; + } + }
- IDirect3DSurface9_UnlockRect(src_surface); + hr = D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, lock.pBits, + src_desc.Format, lock.Pitch, src_palette, src_rect, filter, color_key); + + IDirect3DSurface9_UnlockRect(surface); + if (surface != src_surface) + IDirect3DSurface9_Release(surface);
return hr; } diff --git a/media/doc/README.WINE b/media/doc/README.WINE index c5b71b8082..64c9a50a12 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -26,7 +26,7 @@ reactos/dll/directx/wine/d3d8 # Synced to WineStaging-3.9 reactos/dll/directx/wine/d3d9 # Synced to WineStaging-3.9 reactos/dll/directx/wine/d3dcompiler_43 # Synced to WineStaging-4.0 reactos/dll/directx/wine/d3drm # Synced to WineStaging-4.0 -reactos/dll/directx/wine/d3dx9_24 => 43 # Synced to WineStaging-3.17 +reactos/dll/directx/wine/d3dx9_24 => 43 # Synced to WineStaging-4.0 reactos/dll/directx/wine/d3dxof # Synced to WineStaging-3.17 reactos/dll/directx/wine/ddraw # Synced to WineStaging-3.9 reactos/dll/directx/wine/devenum # Synced to WineStaging-3.9