wined3d: Return a wined3d_texture_sub_resource structure from wined3d_texture_get_sub_resource().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2016-04-04 18:43:02 +02:00 committed by Alexandre Julliard
parent 4f3648705e
commit 639dd9b9e3
3 changed files with 55 additions and 51 deletions

View File

@ -4036,9 +4036,10 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str
unsigned int sub_resource_idx, const struct wined3d_box *box, const void *data, unsigned int row_pitch,
unsigned int depth_pitch)
{
struct wined3d_resource *sub_resource;
struct wined3d_texture_sub_resource *sub_resource;
const struct wined3d_gl_info *gl_info;
struct wined3d_const_bo_address addr;
unsigned int width, height, level;
struct wined3d_context *context;
struct wined3d_texture *texture;
struct wined3d_surface *surface;
@ -4077,14 +4078,18 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str
WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
return;
}
surface = surface_from_resource(sub_resource);
surface = sub_resource->u.surface;
level = sub_resource_idx % texture->level_count;
width = wined3d_texture_get_level_width(texture, level);
height = wined3d_texture_get_level_height(texture, level);
src_rect.left = 0;
src_rect.top = 0;
if (box)
{
if (box->left >= box->right || box->right > sub_resource->width
|| box->top >= box->bottom || box->bottom > sub_resource->height
if (box->left >= box->right || box->right > width
|| box->top >= box->bottom || box->bottom > height
|| box->front >= box->back)
{
WARN("Invalid box %s specified.\n", debug_box(box));
@ -4098,8 +4103,8 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str
}
else
{
src_rect.right = sub_resource->width;
src_rect.bottom = sub_resource->height;
src_rect.right = width;
src_rect.bottom = height;
dst_point.x = 0;
dst_point.y = 0;
}
@ -4111,8 +4116,7 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str
gl_info = context->gl_info;
/* Only load the surface for partial updates. */
if (!dst_point.x && !dst_point.y && src_rect.right == sub_resource->width
&& src_rect.bottom == sub_resource->height)
if (!dst_point.x && !dst_point.y && src_rect.right == width && src_rect.bottom == height)
wined3d_texture_prepare_texture(texture, context, FALSE);
else
surface_load_location(surface, context, WINED3D_LOCATION_TEXTURE_RGB);

View File

@ -1003,8 +1003,8 @@ void CDECL wined3d_texture_generate_mipmaps(struct wined3d_texture *texture)
FIXME("texture %p stub!\n", texture);
}
struct wined3d_resource *wined3d_texture_get_sub_resource(const struct wined3d_texture *texture,
UINT sub_resource_idx)
struct wined3d_texture_sub_resource *wined3d_texture_get_sub_resource(struct wined3d_texture *texture,
unsigned int sub_resource_idx)
{
UINT sub_count = texture->level_count * texture->layer_count;
@ -1016,13 +1016,13 @@ struct wined3d_resource *wined3d_texture_get_sub_resource(const struct wined3d_t
return NULL;
}
return texture->sub_resources[sub_resource_idx].resource;
return &texture->sub_resources[sub_resource_idx];
}
HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture,
UINT layer, const struct wined3d_box *dirty_region)
{
struct wined3d_resource *sub_resource;
struct wined3d_texture_sub_resource *sub_resource;
struct wined3d_context *context;
unsigned int sub_resource_idx;
@ -1039,13 +1039,14 @@ HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture,
FIXME("Ignoring dirty_region %s.\n", debug_box(dirty_region));
context = context_acquire(texture->resource.device, NULL);
if (!texture->texture_ops->texture_load_location(texture, sub_resource_idx, context, sub_resource->map_binding))
if (!texture->texture_ops->texture_load_location(texture, sub_resource_idx,
context, sub_resource->resource->map_binding))
{
ERR("Failed to load location %s.\n", wined3d_debug_location(sub_resource->map_binding));
ERR("Failed to load location %s.\n", wined3d_debug_location(sub_resource->resource->map_binding));
context_release(context);
return E_OUTOFMEMORY;
}
wined3d_texture_invalidate_location(texture, sub_resource_idx, ~sub_resource->map_binding);
wined3d_texture_invalidate_location(texture, sub_resource_idx, ~sub_resource->resource->map_binding);
context_release(context);
return WINED3D_OK;
@ -1253,11 +1254,11 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
{
const struct wined3d_format *format = resource->format;
struct wined3d_texture_sub_resource *sub_resource;
struct wined3d_device *device = resource->device;
unsigned int fmt_flags = resource->format_flags;
const struct wined3d_gl_info *gl_info = NULL;
struct wined3d_context *context = NULL;
struct wined3d_resource *sub_resource;
struct wined3d_texture *texture;
struct wined3d_bo_address data;
unsigned int texture_level;
@ -1295,7 +1296,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
return WINED3DERR_INVALIDCALL;
}
if (sub_resource->map_count)
if (sub_resource->resource->map_count)
{
WARN("Sub-resource is already mapped.\n");
return WINED3DERR_INVALIDCALL;
@ -1312,17 +1313,17 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
if (flags & WINED3D_MAP_DISCARD)
{
TRACE("WINED3D_MAP_DISCARD flag passed, marking %s as up to date.\n",
wined3d_debug_location(sub_resource->map_binding));
wined3d_debug_location(sub_resource->resource->map_binding));
if ((ret = texture->texture_ops->texture_prepare_location(texture,
sub_resource_idx, context, sub_resource->map_binding)))
wined3d_texture_validate_location(texture, sub_resource_idx, sub_resource->map_binding);
sub_resource_idx, context, sub_resource->resource->map_binding)))
wined3d_texture_validate_location(texture, sub_resource_idx, sub_resource->resource->map_binding);
}
else
{
if (resource->usage & WINED3DUSAGE_DYNAMIC)
WARN_(d3d_perf)("Mapping a dynamic texture without WINED3D_MAP_DISCARD.\n");
ret = texture->texture_ops->texture_load_location(texture,
sub_resource_idx, context, sub_resource->map_binding);
sub_resource_idx, context, sub_resource->resource->map_binding);
}
if (!ret)
@ -1333,9 +1334,9 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
}
if (!(flags & (WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY)))
wined3d_texture_invalidate_location(texture, sub_resource_idx, ~sub_resource->map_binding);
wined3d_texture_invalidate_location(texture, sub_resource_idx, ~sub_resource->resource->map_binding);
wined3d_texture_get_memory(texture, sub_resource_idx, &data, sub_resource->map_binding);
wined3d_texture_get_memory(texture, sub_resource_idx, &data, sub_resource->resource->map_binding);
if (!data.buffer_object)
{
base_memory = data.addr;
@ -1349,7 +1350,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
GLbitfield map_flags = wined3d_resource_gl_map_flags(flags);
map_flags &= ~GL_MAP_FLUSH_EXPLICIT_BIT;
base_memory = GL_EXTCALL(glMapBufferRange(GL_PIXEL_UNPACK_BUFFER,
(INT_PTR)data.addr, sub_resource->size, map_flags));
(INT_PTR)data.addr, sub_resource->resource->size, map_flags));
}
else
{
@ -1412,7 +1413,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
TRACE("Mapped front buffer %s.\n", wine_dbgstr_rect(r));
}
++sub_resource->map_count;
++sub_resource->resource->map_count;
TRACE("Returning memory %p, row pitch %u, slice pitch %u.\n",
map_desc->data, map_desc->row_pitch, map_desc->slice_pitch);
@ -1422,8 +1423,8 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)
{
struct wined3d_texture_sub_resource *sub_resource;
const struct wined3d_gl_info *gl_info;
struct wined3d_resource *sub_resource;
struct wined3d_texture *texture;
struct wined3d_context *context;
@ -1433,13 +1434,13 @@ static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *reso
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
return E_INVALIDARG;
if (!sub_resource->map_count)
if (!sub_resource->resource->map_count)
{
WARN("Trying to unmap unmapped sub-resource.\n");
return WINEDDERR_NOTLOCKED;
}
switch (sub_resource->map_binding)
switch (sub_resource->resource->map_binding)
{
case WINED3D_LOCATION_SYSMEM:
case WINED3D_LOCATION_USER_MEMORY:
@ -1459,7 +1460,7 @@ static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *reso
break;
default:
ERR("Unexpected map binding %s.\n", wined3d_debug_location(sub_resource->map_binding));
ERR("Unexpected map binding %s.\n", wined3d_debug_location(sub_resource->resource->map_binding));
break;
}
@ -1476,7 +1477,7 @@ static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *reso
FIXME("Depth / stencil buffer locking is not implemented.\n");
}
--sub_resource->map_count;
--sub_resource->resource->map_count;
return WINED3D_OK;
}
@ -1936,7 +1937,7 @@ HRESULT CDECL wined3d_texture_blt(struct wined3d_texture *dst_texture, unsigned
const RECT *dst_rect, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx,
const RECT *src_rect, DWORD flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
{
struct wined3d_resource *dst_resource, *src_resource = NULL;
struct wined3d_texture_sub_resource *dst_resource, *src_resource = NULL;
TRACE("dst_texture %p, dst_sub_resource_idx %u, dst_rect %s, src_texture %p, "
"src_sub_resource_idx %u, src_rect %s, flags %#x, fx %p, filter %s.\n",
@ -1944,36 +1945,35 @@ HRESULT CDECL wined3d_texture_blt(struct wined3d_texture *dst_texture, unsigned
src_sub_resource_idx, wine_dbgstr_rect(src_rect), flags, fx, debug_d3dtexturefiltertype(filter));
if (!(dst_resource = wined3d_texture_get_sub_resource(dst_texture, dst_sub_resource_idx))
|| dst_resource->type != WINED3D_RTYPE_SURFACE)
|| dst_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
return WINED3DERR_INVALIDCALL;
if (src_texture)
{
if (!(src_resource = wined3d_texture_get_sub_resource(src_texture, src_sub_resource_idx))
|| src_resource->type != WINED3D_RTYPE_SURFACE)
|| src_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
return WINED3DERR_INVALIDCALL;
}
return wined3d_surface_blt(surface_from_resource(dst_resource), dst_rect,
src_resource ? surface_from_resource(src_resource) : NULL, src_rect, flags, fx, filter);
return wined3d_surface_blt(dst_resource->u.surface, dst_rect,
src_resource ? src_resource->u.surface : NULL, src_rect, flags, fx, filter);
}
HRESULT CDECL wined3d_texture_get_overlay_position(const struct wined3d_texture *texture,
unsigned int sub_resource_idx, LONG *x, LONG *y)
{
struct wined3d_resource *sub_resource;
struct wined3d_surface *surface;
TRACE("texture %p, sub_resource_idx %u, x %p, y %p.\n", texture, sub_resource_idx, x, y);
if (!(texture->resource.usage & WINED3DUSAGE_OVERLAY) || texture->resource.type != WINED3D_RTYPE_TEXTURE_2D
|| !(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
|| sub_resource_idx >= texture->level_count * texture->layer_count)
{
WARN("Invalid sub-resource specified.\n");
return WINEDDERR_NOTAOVERLAYSURFACE;
}
surface = surface_from_resource(sub_resource);
surface = texture->sub_resources[sub_resource_idx].u.surface;
if (!surface->overlay_dest)
{
TRACE("Overlay not visible.\n");
@ -1993,7 +1993,7 @@ HRESULT CDECL wined3d_texture_get_overlay_position(const struct wined3d_texture
HRESULT CDECL wined3d_texture_set_overlay_position(struct wined3d_texture *texture,
unsigned int sub_resource_idx, LONG x, LONG y)
{
struct wined3d_resource *sub_resource;
struct wined3d_texture_sub_resource *sub_resource;
struct wined3d_surface *surface;
LONG w, h;
@ -2006,7 +2006,7 @@ HRESULT CDECL wined3d_texture_set_overlay_position(struct wined3d_texture *textu
return WINEDDERR_NOTAOVERLAYSURFACE;
}
surface = surface_from_resource(sub_resource);
surface = sub_resource->u.surface;
w = surface->overlay_destrect.right - surface->overlay_destrect.left;
h = surface->overlay_destrect.bottom - surface->overlay_destrect.top;
surface->overlay_destrect.left = x;
@ -2021,7 +2021,7 @@ HRESULT CDECL wined3d_texture_update_overlay(struct wined3d_texture *texture, un
const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
const RECT *dst_rect, DWORD flags)
{
struct wined3d_resource *sub_resource, *dst_sub_resource;
struct wined3d_texture_sub_resource *sub_resource, *dst_sub_resource;
struct wined3d_surface *surface, *dst_surface;
TRACE("texture %p, sub_resource_idx %u, src_rect %s, dst_texture %p, "
@ -2043,13 +2043,13 @@ HRESULT CDECL wined3d_texture_update_overlay(struct wined3d_texture *texture, un
return WINED3DERR_INVALIDCALL;
}
surface = surface_from_resource(sub_resource);
surface = sub_resource->u.surface;
if (src_rect)
surface->overlay_srcrect = *src_rect;
else
SetRect(&surface->overlay_srcrect, 0, 0, surface->resource.width, surface->resource.height);
dst_surface = surface_from_resource(dst_sub_resource);
dst_surface = dst_sub_resource->u.surface;
if (dst_rect)
surface->overlay_destrect = *dst_rect;
else
@ -2225,8 +2225,8 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct
HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned int sub_resource_idx, HDC *dc)
{
struct wined3d_device *device = texture->resource.device;
struct wined3d_texture_sub_resource *sub_resource;
struct wined3d_context *context = NULL;
struct wined3d_resource *sub_resource;
struct wined3d_surface *surface;
HRESULT hr;
@ -2235,13 +2235,13 @@ HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned i
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
return WINED3DERR_INVALIDCALL;
if (sub_resource->type != WINED3D_RTYPE_SURFACE)
if (texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
{
WARN("Not supported on %s resources.\n", debug_d3dresourcetype(texture->resource.type));
return WINED3DERR_INVALIDCALL;
}
surface = surface_from_resource(sub_resource);
surface = sub_resource->u.surface;
/* Give more detailed info for ddraw. */
if (surface->flags & SFLAG_DCINUSE)
@ -2287,8 +2287,8 @@ HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned i
HRESULT CDECL wined3d_texture_release_dc(struct wined3d_texture *texture, unsigned int sub_resource_idx, HDC dc)
{
struct wined3d_device *device = texture->resource.device;
struct wined3d_texture_sub_resource *sub_resource;
struct wined3d_context *context = NULL;
struct wined3d_resource *sub_resource;
struct wined3d_surface *surface;
TRACE("texture %p, sub_resource_idx %u, dc %p.\n", texture, sub_resource_idx, dc);
@ -2296,13 +2296,13 @@ HRESULT CDECL wined3d_texture_release_dc(struct wined3d_texture *texture, unsign
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
return WINED3DERR_INVALIDCALL;
if (sub_resource->type != WINED3D_RTYPE_SURFACE)
if (texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
{
WARN("Not supported on %s resources.\n", debug_d3dresourcetype(texture->resource.type));
return WINED3DERR_INVALIDCALL;
}
surface = surface_from_resource(sub_resource);
surface = sub_resource->u.surface;
if (!(surface->flags & SFLAG_DCINUSE))
return WINEDDERR_NODC;

View File

@ -2528,8 +2528,8 @@ BOOL wined3d_texture_check_block_align(const struct wined3d_texture *texture,
GLenum wined3d_texture_get_gl_buffer(const struct wined3d_texture *texture) DECLSPEC_HIDDEN;
void wined3d_texture_get_memory(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_bo_address *data, DWORD locations) DECLSPEC_HIDDEN;
struct wined3d_resource *wined3d_texture_get_sub_resource(const struct wined3d_texture *texture,
UINT sub_resource_idx) DECLSPEC_HIDDEN;
struct wined3d_texture_sub_resource *wined3d_texture_get_sub_resource(struct wined3d_texture *texture,
unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
void wined3d_texture_invalidate_location(struct wined3d_texture *texture,
unsigned int sub_resource_idx, DWORD location) DECLSPEC_HIDDEN;
void wined3d_texture_load(struct wined3d_texture *texture,