[v3 1/6] d3d9: improved d3d9_device_UpdateSurface
Riccardo Bortolato
rikyz619 at gmail.com
Thu Oct 22 04:50:11 CDT 2015
enabled previously failing test in device.c
removed wined3d_device_update_surface from wined3d and replaced its usage with surface_upload_from_surface.
---
dlls/d3d9/device.c | 67 ++++++++++++++++++++++++++++++++++++++++++++---
dlls/d3d9/tests/device.c | 2 +-
dlls/wined3d/device.c | 24 ++---------------
dlls/wined3d/wined3d.spec | 1 -
include/wine/wined3d.h | 2 --
5 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 4af6ffb..0768934 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -1224,19 +1224,80 @@ static HRESULT WINAPI d3d9_device_UpdateSurface(IDirect3DDevice9Ex *iface,
IDirect3DSurface9 *src_surface, const RECT *src_rect,
IDirect3DSurface9 *dst_surface, const POINT *dst_point)
{
- struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
struct d3d9_surface *src = unsafe_impl_from_IDirect3DSurface9(src_surface);
struct d3d9_surface *dst = unsafe_impl_from_IDirect3DSurface9(dst_surface);
+ unsigned int src_w, src_h;
+ struct wined3d_resource *sub_resource;
+ struct wined3d_resource_desc wined3d_desc;
+ enum wined3d_format_id src_format, dst_format;
HRESULT hr;
TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
iface, src_surface, src_rect, dst_surface, dst_point);
wined3d_mutex_lock();
- hr = wined3d_device_update_surface(device->wined3d_device, src->wined3d_surface, src_rect,
- dst->wined3d_surface, dst_point);
+ sub_resource = wined3d_texture_get_sub_resource(src->wined3d_texture, src->sub_resource_idx);
+ wined3d_resource_get_desc(sub_resource, &wined3d_desc);
+ if (wined3d_desc.usage & WINED3DUSAGE_DEPTHSTENCIL || wined3d_desc.multisample_type
+ || wined3d_desc.pool != WINED3D_POOL_SYSTEM_MEM)
+ {
+ WARN("Source surface %p cannot be updated. Returning D3DERR_INVALIDCALL.\n", src_surface);
+ wined3d_mutex_unlock();
+ return D3DERR_INVALIDCALL;
+ }
+ src_format = wined3d_desc.format;
+ src_w = wined3d_desc.width;
+ src_h = wined3d_desc.height;
+
+ sub_resource = wined3d_texture_get_sub_resource(dst->wined3d_texture, dst->sub_resource_idx);
+ wined3d_resource_get_desc(sub_resource, &wined3d_desc);
+ if (wined3d_desc.usage & WINED3DUSAGE_DEPTHSTENCIL || wined3d_desc.multisample_type
+ || wined3d_desc.pool != WINED3D_POOL_DEFAULT)
+ {
+ WARN("Destination surface %p cannot be updated. Returning D3DERR_INVALIDCALL.\n", dst_surface);
+ wined3d_mutex_unlock();
+ return D3DERR_INVALIDCALL;
+ }
+ dst_format = wined3d_desc.format;
+
+ /* Check that the source and destination formats match */
+ if (src_format != dst_format)
+ {
+ WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
+ src_surface, dst_surface);
+ wined3d_mutex_unlock();
+ return D3DERR_INVALIDCALL;
+ }
+
+ if (!src_rect && !dst_point)
+ {
+ RECT rect = {0, 0, src_w, src_h};
+ hr = wined3d_texture_blt(dst->wined3d_texture, dst->sub_resource_idx, &rect,
+ src->wined3d_texture, src->sub_resource_idx, &rect, 0, NULL, WINED3D_TEXF_POINT);
+ }
+ else
+ {
+ unsigned int w = src_rect->right - src_rect->left;
+ unsigned int h = src_rect->bottom - src_rect->top;
+
+ if (src_rect && dst_point)
+ {
+ RECT dst_rect = {dst_point->x, dst_point->y, dst_point->x + w, dst_point->y + h};
+ hr = wined3d_texture_blt(dst->wined3d_texture, dst->sub_resource_idx, &dst_rect,
+ src->wined3d_texture, src->sub_resource_idx, src_rect, 0, NULL, WINED3D_TEXF_POINT);
+ }
+ else
+ {
+ RECT dst_rect = {0, 0, w, h};
+ hr = wined3d_texture_blt(dst->wined3d_texture, dst->sub_resource_idx, &dst_rect,
+ src->wined3d_texture, src->sub_resource_idx, src_rect, 0, NULL, WINED3D_TEXF_POINT);
+ }
+ }
wined3d_mutex_unlock();
+ if (FAILED(hr))
+ return D3DERR_INVALIDCALL;
+
return hr;
}
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 326e789..08c52b2 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -9881,7 +9881,7 @@ static void test_mipmap_lock(void)
hr = IDirect3DDevice9_UpdateSurface(device, surface, NULL, surface_dst, NULL);
ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
hr = IDirect3DDevice9_UpdateSurface(device, surface2, NULL, surface_dst2, NULL);
- todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
+ ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
/* Apparently there's no validation on the container. */
hr = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture,
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 087dc33..15ceb65 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3571,7 +3571,7 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
src_surface = surface_from_resource(wined3d_texture_get_sub_resource(src_texture,
i + src_skip_levels));
dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture, i));
- hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL);
+ hr = surface_upload_from_surface(dst_surface, NULL, src_surface, NULL);
if (FAILED(hr))
{
WARN("Failed to update surface, hr %#x.\n", hr);
@@ -3596,7 +3596,7 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
i * src_levels + j + src_skip_levels));
dst_surface = surface_from_resource(wined3d_texture_get_sub_resource(dst_texture,
i * dst_levels + j));
- hr = wined3d_device_update_surface(device, src_surface, NULL, dst_surface, NULL);
+ hr = surface_upload_from_surface(dst_surface, NULL, src_surface, NULL);
if (FAILED(hr))
{
WARN("Failed to update surface, hr %#x.\n", hr);
@@ -3771,26 +3771,6 @@ float CDECL wined3d_device_get_npatch_mode(const struct wined3d_device *device)
return 0.0f;
}
-/* FIXME: Callers should probably use wined3d_device_update_sub_resource()
- * instead. */
-HRESULT CDECL wined3d_device_update_surface(struct wined3d_device *device,
- struct wined3d_surface *src_surface, const RECT *src_rect,
- struct wined3d_surface *dst_surface, const POINT *dst_point)
-{
- TRACE("device %p, src_surface %p, src_rect %s, dst_surface %p, dst_point %s.\n",
- device, src_surface, wine_dbgstr_rect(src_rect),
- dst_surface, wine_dbgstr_point(dst_point));
-
- if (src_surface->resource.pool != WINED3D_POOL_SYSTEM_MEM || dst_surface->resource.pool != WINED3D_POOL_DEFAULT)
- {
- WARN("source %p must be SYSTEMMEM and dest %p must be DEFAULT, returning WINED3DERR_INVALIDCALL\n",
- src_surface, dst_surface);
- return WINED3DERR_INVALIDCALL;
- }
-
- return surface_upload_from_surface(dst_surface, dst_point, src_surface, src_rect);
-}
-
void CDECL wined3d_device_copy_resource(struct wined3d_device *device,
struct wined3d_resource *dst_resource, struct wined3d_resource *src_resource)
{
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index 9a266c9..3250c15 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -159,7 +159,6 @@
@ cdecl wined3d_device_uninit_3d(ptr)
@ cdecl wined3d_device_uninit_gdi(ptr)
@ cdecl wined3d_device_update_sub_resource(ptr ptr long ptr ptr long long)
-@ cdecl wined3d_device_update_surface(ptr ptr ptr ptr ptr)
@ cdecl wined3d_device_update_texture(ptr ptr ptr)
@ cdecl wined3d_device_validate_device(ptr ptr)
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 6f98c34..322dd83 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2318,8 +2318,6 @@ HRESULT __cdecl wined3d_device_uninit_gdi(struct wined3d_device *device);
void __cdecl wined3d_device_update_sub_resource(struct wined3d_device *device, struct wined3d_resource *resource,
unsigned int sub_resource_idx, const struct wined3d_box *box, const void *data, unsigned int row_pitch,
unsigned int depth_pitch);
-HRESULT __cdecl wined3d_device_update_surface(struct wined3d_device *device, struct wined3d_surface *src_surface,
- const RECT *src_rect, struct wined3d_surface *dst_surface, const POINT *dst_point);
HRESULT __cdecl wined3d_device_update_texture(struct wined3d_device *device,
struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture);
HRESULT __cdecl wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes);
--
1.9.1
More information about the wine-patches
mailing list