wined3d: Return a texture from the swapchain resource creation callback.

This commit is contained in:
Stefan Dösinger 2015-09-03 20:56:26 +02:00 committed by Alexandre Julliard
parent 38a9a232f7
commit fa0041954f
8 changed files with 91 additions and 108 deletions

View File

@ -2904,18 +2904,18 @@ static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *
return S_OK;
}
static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
void *container_parent, const struct wined3d_resource_desc *wined3d_desc, struct wined3d_surface **surface)
static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
void *container_parent, const struct wined3d_resource_desc *wined3d_desc,
struct wined3d_texture **wined3d_texture)
{
struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
struct wined3d_resource *sub_resource;
struct d3d_texture2d *texture;
ID3D10Texture2D *texture_iface;
D3D10_TEXTURE2D_DESC desc;
HRESULT hr;
FIXME("device_parent %p, container_parent %p, wined3d_desc %p, surface %p partial stub!\n",
device_parent, container_parent, wined3d_desc, surface);
FIXME("device_parent %p, container_parent %p, wined3d_desc %p, wined3d_texture %p partial stub!\n",
device_parent, container_parent, wined3d_desc, wined3d_texture);
FIXME("Implement DXGI<->wined3d usage conversion\n");
@ -2940,10 +2940,9 @@ static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_devic
texture = impl_from_ID3D10Texture2D(texture_iface);
sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
*surface = wined3d_surface_from_resource(sub_resource);
wined3d_surface_incref(*surface);
ID3D10Texture2D_Release(texture_iface);
*wined3d_texture = texture->wined3d_texture;
wined3d_texture_incref(*wined3d_texture);
ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
return S_OK;
}
@ -2982,7 +2981,7 @@ static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
device_parent_activate,
device_parent_surface_created,
device_parent_volume_created,
device_parent_create_swapchain_surface,
device_parent_create_swapchain_texture,
device_parent_create_swapchain,
};

View File

@ -3034,32 +3034,24 @@ static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *
return D3D_OK;
}
static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
void *container_parent, const struct wined3d_resource_desc *desc, struct wined3d_surface **surface)
static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
void *container_parent, const struct wined3d_resource_desc *desc, struct wined3d_texture **texture)
{
struct d3d8_device *device = device_from_device_parent(device_parent);
struct wined3d_resource_desc texture_desc;
struct d3d8_surface *d3d_surface;
struct wined3d_texture *texture;
HRESULT hr;
TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
device_parent, container_parent, desc, surface);
TRACE("device_parent %p, container_parent %p, desc %p, texture %p.\n",
device_parent, container_parent, desc, texture);
texture_desc = *desc;
texture_desc.resource_type = WINED3D_RTYPE_TEXTURE;
if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &texture_desc, 1,
WINED3D_SURFACE_MAPPABLE, NULL, &device->IDirect3DDevice8_iface, &d3d8_null_wined3d_parent_ops, &texture)))
if (FAILED(hr = wined3d_texture_create(device->wined3d_device, desc, 1,
WINED3D_SURFACE_MAPPABLE, NULL, &device->IDirect3DDevice8_iface, &d3d8_null_wined3d_parent_ops, texture)))
{
WARN("Failed to create texture, hr %#x.\n", hr);
return hr;
}
*surface = wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture, 0));
wined3d_surface_incref(*surface);
wined3d_texture_decref(texture);
d3d_surface = wined3d_surface_get_parent(*surface);
d3d_surface = wined3d_resource_get_parent(wined3d_texture_get_sub_resource(*texture, 0));
d3d_surface->parent_device = &device->IDirect3DDevice8_iface;
return hr;
@ -3095,7 +3087,7 @@ static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops =
device_parent_activate,
device_parent_surface_created,
device_parent_volume_created,
device_parent_create_swapchain_surface,
device_parent_create_swapchain_texture,
device_parent_create_swapchain,
};

View File

@ -3570,35 +3570,27 @@ static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *
return D3D_OK;
}
static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
void *container_parent, const struct wined3d_resource_desc *desc, struct wined3d_surface **surface)
static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
void *container_parent, const struct wined3d_resource_desc *desc, struct wined3d_texture **texture)
{
struct d3d9_device *device = device_from_device_parent(device_parent);
struct wined3d_resource_desc texture_desc;
struct d3d9_surface *d3d_surface;
struct wined3d_texture *texture;
HRESULT hr;
TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
device_parent, container_parent, desc, surface);
TRACE("device_parent %p, container_parent %p, desc %p, texture %p.\n",
device_parent, container_parent, desc, texture);
if (container_parent == device_parent)
container_parent = &device->IDirect3DDevice9Ex_iface;
texture_desc = *desc;
texture_desc.resource_type = WINED3D_RTYPE_TEXTURE;
if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &texture_desc, 1,
WINED3D_SURFACE_MAPPABLE, NULL, container_parent, &d3d9_null_wined3d_parent_ops, &texture)))
if (FAILED(hr = wined3d_texture_create(device->wined3d_device, desc, 1,
WINED3D_SURFACE_MAPPABLE, NULL, container_parent, &d3d9_null_wined3d_parent_ops, texture)))
{
WARN("Failed to create texture, hr %#x.\n", hr);
return hr;
}
*surface = wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture, 0));
wined3d_surface_incref(*surface);
wined3d_texture_decref(texture);
d3d_surface = wined3d_surface_get_parent(*surface);
d3d_surface = wined3d_resource_get_parent(wined3d_texture_get_sub_resource(*texture, 0));
d3d_surface->parent_device = &device->IDirect3DDevice9Ex_iface;
return hr;
@ -3635,7 +3627,7 @@ static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops =
device_parent_activate,
device_parent_surface_created,
device_parent_volume_created,
device_parent_create_swapchain_surface,
device_parent_create_swapchain_texture,
device_parent_create_swapchain,
};

View File

@ -4769,16 +4769,14 @@ static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops =
ddraw_frontbuffer_destroyed,
};
static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
void *container_parent, const struct wined3d_resource_desc *desc, struct wined3d_surface **surface)
static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
void *container_parent, const struct wined3d_resource_desc *desc, struct wined3d_texture **texture)
{
struct ddraw *ddraw = ddraw_from_device_parent(device_parent);
struct wined3d_resource_desc texture_desc;
struct wined3d_texture *texture;
HRESULT hr;
TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
device_parent, container_parent, desc, surface);
TRACE("device_parent %p, container_parent %p, desc %p, texture %p.\n",
device_parent, container_parent, desc, texture);
if (ddraw->wined3d_frontbuffer)
{
@ -4786,19 +4784,14 @@ static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_devic
return E_FAIL;
}
texture_desc = *desc;
texture_desc.resource_type = WINED3D_RTYPE_TEXTURE;
if (FAILED(hr = wined3d_texture_create(ddraw->wined3d_device, &texture_desc, 1,
WINED3D_SURFACE_MAPPABLE, NULL, ddraw, &ddraw_frontbuffer_parent_ops, &texture)))
if (FAILED(hr = wined3d_texture_create(ddraw->wined3d_device, desc, 1,
WINED3D_SURFACE_MAPPABLE, NULL, ddraw, &ddraw_frontbuffer_parent_ops, texture)))
{
WARN("Failed to create texture, hr %#x.\n", hr);
return hr;
}
*surface = wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture, 0));
ddraw->wined3d_frontbuffer = *surface;
wined3d_surface_incref(*surface);
wined3d_texture_decref(texture);
ddraw->wined3d_frontbuffer = wined3d_surface_from_resource(wined3d_texture_get_sub_resource(*texture, 0));
return hr;
}
@ -4831,7 +4824,7 @@ static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops =
device_parent_activate,
device_parent_surface_created,
device_parent_volume_created,
device_parent_create_swapchain_surface,
device_parent_create_swapchain_texture,
device_parent_create_swapchain,
};

View File

@ -197,19 +197,19 @@ static HRESULT STDMETHODCALLTYPE dxgi_device_CreateSurface(IWineDXGIDevice *ifac
memset(surface, 0, surface_count * sizeof(*surface));
for (i = 0; i < surface_count; ++i)
{
struct wined3d_surface *wined3d_surface;
struct wined3d_texture *wined3d_texture;
IUnknown *parent;
if (FAILED(hr = device_parent->ops->create_swapchain_surface(device_parent,
NULL, &surface_desc, &wined3d_surface)))
if (FAILED(hr = device_parent->ops->create_swapchain_texture(device_parent,
NULL, &surface_desc, &wined3d_texture)))
{
ERR("Failed to create surface, hr %#x.\n", hr);
goto fail;
}
parent = wined3d_surface_get_parent(wined3d_surface);
parent = wined3d_texture_get_parent(wined3d_texture);
hr = IUnknown_QueryInterface(parent, &IID_IDXGISurface, (void **)&surface[i]);
wined3d_surface_decref(wined3d_surface);
wined3d_texture_decref(wined3d_texture);
if (FAILED(hr))
{
ERR("Surface should implement IDXGISurface\n");

View File

@ -4685,32 +4685,37 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
}
if (swapchain->desc.enable_auto_depth_stencil)
{
struct wined3d_resource_desc surface_desc;
struct wined3d_surface *surface;
struct wined3d_resource_desc texture_desc;
struct wined3d_texture *texture;
struct wined3d_rendertarget_view_desc view_desc;
TRACE("Creating the depth stencil buffer\n");
surface_desc.resource_type = WINED3D_RTYPE_SURFACE;
surface_desc.format = swapchain->desc.auto_depth_stencil_format;
surface_desc.multisample_type = swapchain->desc.multisample_type;
surface_desc.multisample_quality = swapchain->desc.multisample_quality;
surface_desc.usage = WINED3DUSAGE_DEPTHSTENCIL;
surface_desc.pool = WINED3D_POOL_DEFAULT;
surface_desc.width = swapchain->desc.backbuffer_width;
surface_desc.height = swapchain->desc.backbuffer_height;
surface_desc.depth = 1;
surface_desc.size = 0;
texture_desc.resource_type = WINED3D_RTYPE_TEXTURE;
texture_desc.format = swapchain->desc.auto_depth_stencil_format;
texture_desc.multisample_type = swapchain->desc.multisample_type;
texture_desc.multisample_quality = swapchain->desc.multisample_quality;
texture_desc.usage = WINED3DUSAGE_DEPTHSTENCIL;
texture_desc.pool = WINED3D_POOL_DEFAULT;
texture_desc.width = swapchain->desc.backbuffer_width;
texture_desc.height = swapchain->desc.backbuffer_height;
texture_desc.depth = 1;
texture_desc.size = 0;
if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent,
device->device_parent, &surface_desc, &surface)))
if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent,
device->device_parent, &texture_desc, &texture)))
{
ERR("Failed to create the auto depth/stencil surface, hr %#x.\n", hr);
return WINED3DERR_INVALIDCALL;
}
hr = wined3d_rendertarget_view_create_from_surface(surface,
view_desc.format_id = texture->resource.format->id;
view_desc.u.texture.level_idx = 0;
view_desc.u.texture.layer_idx = 0;
view_desc.u.texture.layer_count = 1;
hr = wined3d_rendertarget_view_create(&view_desc, &texture->resource,
NULL, &wined3d_null_parent_ops, &device->auto_depth_stencil_view);
wined3d_surface_decref(surface);
wined3d_texture_decref(texture);
if (FAILED(hr))
{
ERR("Failed to create rendertarget view, hr %#x.\n", hr);

View File

@ -772,7 +772,7 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
struct wined3d_swapchain_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops)
{
const struct wined3d_adapter *adapter = device->adapter;
struct wined3d_resource_desc surface_desc;
struct wined3d_resource_desc texture_desc;
struct wined3d_surface *front_buffer;
BOOL displaymode_set = FALSE;
RECT client_rect;
@ -836,26 +836,26 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
TRACE("Creating front buffer.\n");
surface_desc.resource_type = WINED3D_RTYPE_SURFACE;
surface_desc.format = swapchain->desc.backbuffer_format;
surface_desc.multisample_type = swapchain->desc.multisample_type;
surface_desc.multisample_quality = swapchain->desc.multisample_quality;
surface_desc.usage = 0;
surface_desc.pool = WINED3D_POOL_DEFAULT;
surface_desc.width = swapchain->desc.backbuffer_width;
surface_desc.height = swapchain->desc.backbuffer_height;
surface_desc.depth = 1;
surface_desc.size = 0;
texture_desc.resource_type = WINED3D_RTYPE_TEXTURE;
texture_desc.format = swapchain->desc.backbuffer_format;
texture_desc.multisample_type = swapchain->desc.multisample_type;
texture_desc.multisample_quality = swapchain->desc.multisample_quality;
texture_desc.usage = 0;
texture_desc.pool = WINED3D_POOL_DEFAULT;
texture_desc.width = swapchain->desc.backbuffer_width;
texture_desc.height = swapchain->desc.backbuffer_height;
texture_desc.depth = 1;
texture_desc.size = 0;
if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent,
parent, &surface_desc, &front_buffer)))
if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent,
parent, &texture_desc, &swapchain->front_buffer)))
{
WARN("Failed to create front buffer, hr %#x.\n", hr);
goto err;
}
swapchain->front_buffer = front_buffer->container;
wined3d_texture_set_swapchain(swapchain->front_buffer, swapchain);
front_buffer = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0));
if (!(device->wined3d->flags & WINED3D_NO3D))
{
surface_validate_location(front_buffer, WINED3D_LOCATION_DRAWABLE);
@ -952,20 +952,17 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
goto err;
}
surface_desc.usage |= WINED3DUSAGE_RENDERTARGET;
texture_desc.usage |= WINED3DUSAGE_RENDERTARGET;
for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
{
struct wined3d_surface *back_buffer;
TRACE("Creating back buffer %u.\n", i);
if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent,
parent, &surface_desc, &back_buffer)))
if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent,
parent, &texture_desc, &swapchain->back_buffers[i])))
{
WARN("Failed to create back buffer %u, hr %#x.\n", i, hr);
swapchain->desc.backbuffer_count = i;
goto err;
}
swapchain->back_buffers[i] = back_buffer->container;
wined3d_texture_set_swapchain(swapchain->back_buffers[i], swapchain);
}
}
@ -976,21 +973,26 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
TRACE("Creating depth/stencil buffer.\n");
if (!device->auto_depth_stencil_view)
{
struct wined3d_surface *ds;
struct wined3d_texture *ds;
struct wined3d_rendertarget_view_desc desc;
surface_desc.format = swapchain->desc.auto_depth_stencil_format;
surface_desc.usage = WINED3DUSAGE_DEPTHSTENCIL;
texture_desc.format = swapchain->desc.auto_depth_stencil_format;
texture_desc.usage = WINED3DUSAGE_DEPTHSTENCIL;
if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent,
device->device_parent, &surface_desc, &ds)))
if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent,
device->device_parent, &texture_desc, &ds)))
{
WARN("Failed to create the auto depth/stencil surface, hr %#x.\n", hr);
goto err;
}
hr = wined3d_rendertarget_view_create_from_surface(ds,
NULL, &wined3d_null_parent_ops, &device->auto_depth_stencil_view);
wined3d_surface_decref(ds);
desc.format_id = ds->resource.format->id;
desc.u.texture.level_idx = 0;
desc.u.texture.layer_idx = 0;
desc.u.texture.layer_count = 1;
hr = wined3d_rendertarget_view_create(&desc, &ds->resource, NULL, &wined3d_null_parent_ops,
&device->auto_depth_stencil_view);
wined3d_texture_decref(ds);
if (FAILED(hr))
{
ERR("Failed to create rendertarget view, hr %#x.\n", hr);

View File

@ -2041,8 +2041,8 @@ struct wined3d_device_parent_ops
struct wined3d_surface *surface, void **parent, const struct wined3d_parent_ops **parent_ops);
HRESULT (__cdecl *volume_created)(struct wined3d_device_parent *device_parent, void *container_parent,
struct wined3d_volume *volume, void **parent, const struct wined3d_parent_ops **parent_ops);
HRESULT (__cdecl *create_swapchain_surface)(struct wined3d_device_parent *device_parent, void *container_parent,
const struct wined3d_resource_desc *desc, struct wined3d_surface **surface);
HRESULT (__cdecl *create_swapchain_texture)(struct wined3d_device_parent *device_parent, void *parent,
const struct wined3d_resource_desc *desc, struct wined3d_texture **texture);
HRESULT (__cdecl *create_swapchain)(struct wined3d_device_parent *device_parent,
struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain);
};