wined3d: Pass a wined3d_resource_desc structure to surface_init().

This commit is contained in:
Henri Verbeet 2013-11-15 08:24:32 +01:00 committed by Alexandre Julliard
parent afc3d2ab70
commit bb00811d60
3 changed files with 28 additions and 38 deletions

View File

@ -6766,13 +6766,12 @@ cpu:
return surface_cpu_blt(dst_surface, &dst_rect, src_surface, &src_rect, flags, fx, filter); return surface_cpu_blt(dst_surface, &dst_rect, src_surface, &src_rect, flags, fx, filter);
} }
static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UINT width, UINT height, static HRESULT surface_init(struct wined3d_surface *surface, const struct wined3d_resource_desc *desc,
enum wined3d_multisample_type multisample_type, UINT multisample_quality, struct wined3d_device *device, DWORD flags)
struct wined3d_device *device, DWORD usage, enum wined3d_format_id format_id,
enum wined3d_pool pool, DWORD flags)
{ {
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
const struct wined3d_format *format = wined3d_get_format(gl_info, format_id); const struct wined3d_format *format = wined3d_get_format(gl_info, desc->format);
UINT multisample_quality = desc->multisample_quality;
BOOL lockable = flags & WINED3D_SURFACE_MAPPABLE; BOOL lockable = flags & WINED3D_SURFACE_MAPPABLE;
unsigned int resource_size; unsigned int resource_size;
HRESULT hr; HRESULT hr;
@ -6787,15 +6786,16 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
* TODO: remove this after surfaces, usage and lockability have been debugged properly * TODO: remove this after surfaces, usage and lockability have been debugged properly
* this function is too deep to need to care about things like this. * this function is too deep to need to care about things like this.
* Levels need to be checked too, since they all affect what can be done. */ * Levels need to be checked too, since they all affect what can be done. */
switch (pool) switch (desc->pool)
{ {
case WINED3D_POOL_MANAGED: case WINED3D_POOL_MANAGED:
if (usage & WINED3DUSAGE_DYNAMIC) if (desc->usage & WINED3DUSAGE_DYNAMIC)
FIXME("Called with a pool of MANAGED and a usage of DYNAMIC which are mutually exclusive.\n"); FIXME("Called with a pool of MANAGED and a usage of DYNAMIC which are mutually exclusive.\n");
break; break;
case WINED3D_POOL_DEFAULT: case WINED3D_POOL_DEFAULT:
if (lockable && !(usage & (WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL))) if (lockable && !(desc->usage & (WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL)))
WARN("Creating a lockable surface with a POOL of DEFAULT, that doesn't specify DYNAMIC usage.\n"); WARN("Creating a lockable surface with a POOL of DEFAULT, that doesn't specify DYNAMIC usage.\n");
break; break;
@ -6804,16 +6804,16 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
break; break;
default: default:
FIXME("Unknown pool %#x.\n", pool); FIXME("Unknown pool %#x.\n", desc->pool);
break; break;
}; };
if (usage & WINED3DUSAGE_RENDERTARGET && pool != WINED3D_POOL_DEFAULT) if (desc->usage & WINED3DUSAGE_RENDERTARGET && desc->pool != WINED3D_POOL_DEFAULT)
FIXME("Trying to create a render target that isn't in the default pool.\n"); FIXME("Trying to create a render target that isn't in the default pool.\n");
/* FIXME: Check that the format is supported by the device. */ /* FIXME: Check that the format is supported by the device. */
resource_size = wined3d_format_calculate_size(format, alignment, width, height, 1); resource_size = wined3d_format_calculate_size(format, device->surface_alignment, desc->width, desc->height, 1);
if (!resource_size) if (!resource_size)
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
@ -6823,7 +6823,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
surface->surface_ops = &surface_ops; surface->surface_ops = &surface_ops;
if (FAILED(hr = resource_init(&surface->resource, device, WINED3D_RTYPE_SURFACE, format, if (FAILED(hr = resource_init(&surface->resource, device, WINED3D_RTYPE_SURFACE, format,
multisample_type, multisample_quality, usage, pool, width, height, 1, desc->multisample_type, multisample_quality, desc->usage, desc->pool, desc->width, desc->height, 1,
resource_size, NULL, &wined3d_null_parent_ops, &surface_resource_ops))) resource_size, NULL, &wined3d_null_parent_ops, &surface_resource_ops)))
{ {
WARN("Failed to initialize resource, returning %#x.\n", hr); WARN("Failed to initialize resource, returning %#x.\n", hr);
@ -6841,7 +6841,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
surface->flags |= SFLAG_DISCARD; surface->flags |= SFLAG_DISCARD;
if (flags & WINED3D_SURFACE_PIN_SYSMEM) if (flags & WINED3D_SURFACE_PIN_SYSMEM)
surface->flags |= SFLAG_PIN_SYSMEM; surface->flags |= SFLAG_PIN_SYSMEM;
if (lockable || format_id == WINED3DFMT_D16_LOCKABLE) if (lockable || desc->format == WINED3DFMT_D16_LOCKABLE)
surface->resource.access_flags |= WINED3D_RESOURCE_ACCESS_CPU; surface->resource.access_flags |= WINED3D_RESOURCE_ACCESS_CPU;
/* I'm not sure if this qualifies as a hack or as an optimization. It /* I'm not sure if this qualifies as a hack or as an optimization. It
@ -6851,7 +6851,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
* ddraw applications access surface memory while the surface isn't * ddraw applications access surface memory while the surface isn't
* mapped. The SFLAG_DYNLOCK behaviour of keeping SYSMEM around for * mapped. The SFLAG_DYNLOCK behaviour of keeping SYSMEM around for
* future locks prevents these from crashing. */ * future locks prevents these from crashing. */
if (lockable && (usage & WINED3DUSAGE_RENDERTARGET)) if (lockable && (desc->usage & WINED3DUSAGE_RENDERTARGET))
surface->flags |= SFLAG_DYNLOCK; surface->flags |= SFLAG_DYNLOCK;
/* Mark the texture as dirty so that it gets loaded first time around. */ /* Mark the texture as dirty so that it gets loaded first time around. */
@ -6873,7 +6873,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
/* Similar to lockable rendertargets above, creating the DIB section /* Similar to lockable rendertargets above, creating the DIB section
* during surface initialization prevents the sysmem pointer from changing * during surface initialization prevents the sysmem pointer from changing
* after a wined3d_surface_getdc() call. */ * after a wined3d_surface_getdc() call. */
if ((usage & WINED3DUSAGE_OWNDC) && !surface->hDC if ((desc->usage & WINED3DUSAGE_OWNDC) && !surface->hDC
&& SUCCEEDED(surface_create_dib_section(surface))) && SUCCEEDED(surface_create_dib_section(surface)))
{ {
wined3d_resource_free_sysmem(&surface->resource); wined3d_resource_free_sysmem(&surface->resource);
@ -6884,27 +6884,23 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
} }
HRESULT CDECL wined3d_surface_create(struct wined3d_device *device, void *container_parent, HRESULT CDECL wined3d_surface_create(struct wined3d_device *device, void *container_parent,
UINT width, UINT height, enum wined3d_format_id format_id, DWORD usage, enum wined3d_pool pool, const struct wined3d_resource_desc *desc, DWORD flags, struct wined3d_surface **surface)
enum wined3d_multisample_type multisample_type, DWORD multisample_quality, DWORD flags,
struct wined3d_surface **surface)
{ {
const struct wined3d_parent_ops *parent_ops; const struct wined3d_parent_ops *parent_ops;
struct wined3d_surface *object; struct wined3d_surface *object;
void *parent; void *parent;
HRESULT hr; HRESULT hr;
TRACE("device %p, container_parent %p, width %u, height %u, format %s\n", TRACE("device %p, container_parent %p, width %u, height %u, format %s, usage %s (%#x), "
device, container_parent, width, height, debug_d3dformat(format_id)); "pool %s, multisample_type %#x, multisample_quality %u, flags %#x, surface %p.\n",
TRACE("surface %p, usage %s (%#x), pool %s, multisample_type %#x, multisample_quality %u\n", device, container_parent, desc->width, desc->height, debug_d3dformat(desc->format),
surface, debug_d3dusage(usage), usage, debug_d3dpool(pool), multisample_type, multisample_quality); debug_d3dusage(desc->usage), desc->usage, debug_d3dpool(desc->pool),
TRACE("flags %#x.\n", flags); desc->multisample_type, desc->multisample_quality, flags, surface);
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
if (!object) return E_OUTOFMEMORY;
return WINED3DERR_OUTOFVIDEOMEMORY;
if (FAILED(hr = surface_init(object, device->surface_alignment, width, height, multisample_type, if (FAILED(hr = surface_init(object, desc, device, flags)))
multisample_quality, device, usage, format_id, pool, flags)))
{ {
WARN("Failed to initialize surface, returning %#x.\n", hr); WARN("Failed to initialize surface, returning %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object); HeapFree(GetProcessHeap(), 0, object);

View File

@ -860,9 +860,7 @@ static HRESULT cubetexture_init(struct wined3d_texture *texture, const struct wi
UINT idx = j * texture->level_count + i; UINT idx = j * texture->level_count + i;
struct wined3d_surface *surface; struct wined3d_surface *surface;
if (FAILED(hr = wined3d_surface_create(device, parent, surface_desc.width, surface_desc.height, if (FAILED(hr = wined3d_surface_create(device, parent, &surface_desc, surface_flags, &surface)))
surface_desc.format, surface_desc.usage, surface_desc.pool, surface_desc.multisample_type,
surface_desc.multisample_quality, surface_flags, &surface)))
{ {
WARN("Failed to create surface, hr %#x.\n", hr); WARN("Failed to create surface, hr %#x.\n", hr);
wined3d_texture_cleanup(texture); wined3d_texture_cleanup(texture);
@ -1017,9 +1015,7 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
{ {
struct wined3d_surface *surface; struct wined3d_surface *surface;
if (FAILED(hr = wined3d_surface_create(device, parent, surface_desc.width, surface_desc.height, if (FAILED(hr = wined3d_surface_create(device, parent, &surface_desc, surface_flags, &surface)))
surface_desc.format, surface_desc.usage, surface_desc.pool, surface_desc.multisample_type,
surface_desc.multisample_quality, surface_flags, &surface)))
{ {
WARN("Failed to create surface, hr %#x.\n", hr); WARN("Failed to create surface, hr %#x.\n", hr);
wined3d_texture_cleanup(texture); wined3d_texture_cleanup(texture);

View File

@ -2273,10 +2273,8 @@ void surface_update_draw_binding(struct wined3d_surface *surface) DECLSPEC_HIDDE
HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point, HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
struct wined3d_surface *src_surface, const RECT *src_rect) DECLSPEC_HIDDEN; struct wined3d_surface *src_surface, const RECT *src_rect) DECLSPEC_HIDDEN;
void surface_validate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN; void surface_validate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN;
HRESULT wined3d_surface_create(struct wined3d_device *device, void *container_parent, HRESULT CDECL wined3d_surface_create(struct wined3d_device *device, void *container_parent,
UINT width, UINT height, enum wined3d_format_id format_id, DWORD usage, enum wined3d_pool pool, const struct wined3d_resource_desc *desc, DWORD flags, struct wined3d_surface **surface) DECLSPEC_HIDDEN;
enum wined3d_multisample_type multisample_type, DWORD multisample_quality, DWORD flags,
struct wined3d_surface **surface) DECLSPEC_HIDDEN;
void get_drawable_size_swapchain(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN; void get_drawable_size_swapchain(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
void get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN; void get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;