From d0c9dbe7633c0618660dcf85bb8e6bc7f367a8e7 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 20 Aug 2013 10:20:10 +0200 Subject: [PATCH] d3d9: Always create textures for surfaces. --- dlls/d3d9/device.c | 72 +++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 738a274ea13..261591bb626 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -25,6 +25,13 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d9); +static void STDMETHODCALLTYPE d3d9_null_wined3d_object_destroyed(void *parent) {} + +static const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops = +{ + d3d9_null_wined3d_object_destroyed, +}; + D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format) { BYTE *c = (BYTE *)&format; @@ -909,7 +916,10 @@ static HRESULT d3d9_device_create_surface(struct d3d9_device *device, UINT width D3DFORMAT format, DWORD flags, IDirect3DSurface9 **surface, UINT usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) { - struct d3d9_surface *object; + struct wined3d_resource *sub_resource; + struct wined3d_resource_desc desc; + struct d3d9_surface *surface_impl; + struct wined3d_texture *texture; HRESULT hr; TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p.\n" @@ -917,22 +927,36 @@ static HRESULT d3d9_device_create_surface(struct d3d9_device *device, UINT width device, width, height, format, flags, surface, usage, pool, multisample_type, multisample_quality); - if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)))) - { - FIXME("Failed to allocate surface memory.\n"); - return D3DERR_OUTOFVIDEOMEMORY; - } + desc.resource_type = WINED3D_RTYPE_TEXTURE; + desc.format = wined3dformat_from_d3dformat(format); + desc.multisample_type = multisample_type; + desc.multisample_quality = multisample_quality; + desc.usage = usage & WINED3DUSAGE_MASK; + desc.pool = pool; + desc.width = width; + desc.height = height; + desc.depth = 1; + desc.size = 0; - if (FAILED(hr = surface_init(object, device, width, height, format, - flags, usage, pool, multisample_type, multisample_quality))) + wined3d_mutex_lock(); + + if (FAILED(hr = wined3d_texture_create_2d(device->wined3d_device, &desc, + 1, flags, NULL, &d3d9_null_wined3d_parent_ops, &texture))) { - WARN("Failed to initialize surface, hr %#x.\n", hr); - HeapFree(GetProcessHeap(), 0, object); + wined3d_mutex_unlock(); + WARN("Failed to create texture, hr %#x.\n", hr); return hr; } - TRACE("Created surface %p.\n", object); - *surface = &object->IDirect3DSurface9_iface; + sub_resource = wined3d_texture_get_sub_resource(texture, 0); + surface_impl = wined3d_resource_get_parent(sub_resource); + surface_impl->forwardReference = NULL; + surface_impl->parent_device = &device->IDirect3DDevice9Ex_iface; + *surface = &surface_impl->IDirect3DSurface9_iface; + IDirect3DSurface9_AddRef(*surface); + wined3d_texture_decref(texture); + + wined3d_mutex_unlock(); return D3D_OK; } @@ -1989,13 +2013,6 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface return hr; } -static void STDMETHODCALLTYPE d3d9_null_wined3d_object_destroyed(void *parent) {} - -static const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops = -{ - d3d9_null_wined3d_object_destroyed, -}; - /* The caller is responsible for wined3d locking */ static HRESULT d3d9_device_prepare_vertex_buffer(struct d3d9_device *device, UINT min_size) { @@ -3292,14 +3309,23 @@ static HRESULT CDECL device_parent_create_texture_surface(struct wined3d_device_ TRACE("device_parent %p, container_parent %p, desc %p, sub_resource_idx %u, flags %#x, surface %p.\n", device_parent, container_parent, desc, sub_resource_idx, flags, surface); - if (FAILED(hr = d3d9_device_create_surface(device, desc->width, desc->height, - d3dformat_from_wined3dformat(desc->format), flags, (IDirect3DSurface9 **)&d3d_surface, - desc->usage, desc->pool, desc->multisample_type, desc->multisample_quality))) + if (!(d3d_surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*d3d_surface)))) { - WARN("Failed to create surface, hr %#x.\n", hr); + FIXME("Failed to allocate surface memory.\n"); + return D3DERR_OUTOFVIDEOMEMORY; + } + + if (FAILED(hr = surface_init(d3d_surface, device, desc->width, desc->height, + d3dformat_from_wined3dformat(desc->format), flags, desc->usage, desc->pool, + desc->multisample_type, desc->multisample_quality))) + { + WARN("Failed to initialize surface, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, d3d_surface); return hr; } + TRACE("Created surface %p.\n", d3d_surface); + *surface = d3d_surface->wined3d_surface; wined3d_surface_incref(*surface);