wined3d: Merge wined3d_surface_prepare() and wined3d_volume_prepare_location().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Stefan Dösinger 2016-04-18 19:06:32 +02:00 committed by Alexandre Julliard
parent f519aca8b3
commit 1462f66d5d
4 changed files with 63 additions and 111 deletions

View File

@ -429,22 +429,6 @@ HRESULT wined3d_surface_create_dc(struct wined3d_surface *surface)
return WINED3D_OK;
}
static void surface_prepare_system_memory(struct wined3d_surface *surface)
{
TRACE("surface %p.\n", surface);
if (surface->resource.heap_memory)
return;
/* Whatever surface we have, make sure that there is memory allocated
* for the downloaded copy, or a PBO to map. */
if (!wined3d_resource_allocate_sysmem(&surface->resource))
ERR("Failed to allocate system memory.\n");
if (surface_get_sub_resource(surface)->locations & WINED3D_LOCATION_SYSMEM)
ERR("Surface without system memory has WINED3D_LOCATION_SYSMEM set.\n");
}
static void surface_evict_sysmem(struct wined3d_surface *surface)
{
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
@ -4396,38 +4380,6 @@ HRESULT wined3d_surface_init(struct wined3d_surface *surface, struct wined3d_tex
* WINED3D_NO3D mode. */
void wined3d_surface_prepare(struct wined3d_surface *surface, struct wined3d_context *context, DWORD location)
{
struct wined3d_texture *texture = surface->container;
switch (location)
{
case WINED3D_LOCATION_SYSMEM:
surface_prepare_system_memory(surface);
break;
case WINED3D_LOCATION_USER_MEMORY:
if (!texture->user_memory)
ERR("Map binding is set to WINED3D_LOCATION_USER_MEMORY but surface->user_memory is NULL.\n");
break;
case WINED3D_LOCATION_BUFFER:
wined3d_texture_prepare_buffer_object(texture,
surface_get_sub_resource_idx(surface), context->gl_info);
break;
case WINED3D_LOCATION_TEXTURE_RGB:
wined3d_texture_prepare_texture(texture, context, FALSE);
break;
case WINED3D_LOCATION_TEXTURE_SRGB:
wined3d_texture_prepare_texture(texture, context, TRUE);
break;
case WINED3D_LOCATION_RB_MULTISAMPLE:
wined3d_texture_prepare_rb(texture, context->gl_info, TRUE);
break;
case WINED3D_LOCATION_RB_RESOLVED:
wined3d_texture_prepare_rb(texture, context->gl_info, FALSE);
break;
}
wined3d_texture_prepare_location(surface->container,
surface_get_sub_resource_idx(surface), context, location);
}

View File

@ -1019,7 +1019,7 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT
}
/* Context activation is done by the caller. */
void wined3d_texture_prepare_buffer_object(struct wined3d_texture *texture,
static void wined3d_texture_prepare_buffer_object(struct wined3d_texture *texture,
unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info)
{
GLuint *buffer_object;
@ -1076,7 +1076,7 @@ void wined3d_texture_prepare_texture(struct wined3d_texture *texture, struct win
texture->flags |= alloc_flag;
}
void wined3d_texture_prepare_rb(struct wined3d_texture *texture,
static void wined3d_texture_prepare_rb(struct wined3d_texture *texture,
const struct wined3d_gl_info *gl_info, BOOL multisample)
{
const struct wined3d_format *format = texture->resource.format;
@ -1138,6 +1138,60 @@ void wined3d_texture_prepare_rb(struct wined3d_texture *texture,
}
}
/* Context activation is done by the caller. Context may be NULL in
* WINED3D_NO3D mode. */
BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_context *context, DWORD location)
{
switch (location)
{
case WINED3D_LOCATION_SYSMEM:
if (texture->sub_resources[sub_resource_idx].resource->heap_memory)
return TRUE;
if (!wined3d_resource_allocate_sysmem(texture->sub_resources[sub_resource_idx].resource))
{
ERR("Failed to allocate system memory.\n");
return FALSE;
}
return TRUE;
case WINED3D_LOCATION_USER_MEMORY:
if (!texture->user_memory)
ERR("Map binding is set to WINED3D_LOCATION_USER_MEMORY but surface->user_memory is NULL.\n");
return TRUE;
case WINED3D_LOCATION_BUFFER:
wined3d_texture_prepare_buffer_object(texture, sub_resource_idx, context->gl_info);
return TRUE;
case WINED3D_LOCATION_TEXTURE_RGB:
wined3d_texture_prepare_texture(texture, context, FALSE);
return TRUE;
case WINED3D_LOCATION_TEXTURE_SRGB:
wined3d_texture_prepare_texture(texture, context, TRUE);
return TRUE;
case WINED3D_LOCATION_DRAWABLE:
if (!texture->swapchain)
ERR("Texture %p does not have a drawable.\n", texture);
return TRUE;
case WINED3D_LOCATION_RB_MULTISAMPLE:
wined3d_texture_prepare_rb(texture, context->gl_info, TRUE);
return TRUE;
case WINED3D_LOCATION_RB_RESOLVED:
wined3d_texture_prepare_rb(texture, context->gl_info, FALSE);
return TRUE;
default:
ERR("Invalid location %s.\n", wined3d_debug_location(location));
return FALSE;
}
}
void CDECL wined3d_texture_generate_mipmaps(struct wined3d_texture *texture)
{
/* TODO: Implement filters using GL_SGI_generate_mipmaps. */
@ -1250,13 +1304,6 @@ static BOOL texture2d_load_location(struct wined3d_texture *texture, unsigned in
return SUCCEEDED(surface_load_location(texture->sub_resources[sub_resource_idx].u.surface, context, location));
}
static BOOL texture2d_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_context *context, DWORD location)
{
wined3d_surface_prepare(texture->sub_resources[sub_resource_idx].u.surface, context, location);
return TRUE;
}
/* Context activation is done by the caller. */
static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
{
@ -1339,7 +1386,6 @@ static const struct wined3d_texture_ops texture2d_ops =
{
texture2d_upload_data,
texture2d_load_location,
texture2d_prepare_location,
texture2d_prepare_texture,
texture2d_cleanup_sub_resources,
};
@ -1486,8 +1532,8 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
{
TRACE("WINED3D_MAP_DISCARD flag passed, marking %s as up to date.\n",
wined3d_debug_location(texture->resource.map_binding));
if ((ret = texture->texture_ops->texture_prepare_location(texture,
sub_resource_idx, context, texture->resource.map_binding)))
if ((ret = wined3d_texture_prepare_location(texture, sub_resource_idx,
context, texture->resource.map_binding)))
wined3d_texture_validate_location(texture, sub_resource_idx, texture->resource.map_binding);
}
else
@ -1871,12 +1917,6 @@ static BOOL texture3d_load_location(struct wined3d_texture *texture, unsigned in
return wined3d_volume_load_location(texture->sub_resources[sub_resource_idx].u.volume, context, location);
}
static BOOL texture3d_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_context *context, DWORD location)
{
return wined3d_volume_prepare_location(texture->sub_resources[sub_resource_idx].u.volume, context, location);
}
static void texture3d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
{
unsigned int sub_count = texture->level_count * texture->layer_count;
@ -1923,7 +1963,6 @@ static const struct wined3d_texture_ops texture3d_ops =
{
texture3d_upload_data,
texture3d_load_location,
texture3d_prepare_location,
texture3d_prepare_texture,
texture3d_cleanup_sub_resources,
};

View File

@ -27,47 +27,12 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
static BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
{
if (volume->resource.heap_memory)
return TRUE;
if (!wined3d_resource_allocate_sysmem(&volume->resource))
{
ERR("Failed to allocate system memory.\n");
return FALSE;
}
return TRUE;
}
/* Context activation is done by the caller. Context may be NULL in
* WINED3D_NO3D mode. */
BOOL wined3d_volume_prepare_location(struct wined3d_volume *volume,
struct wined3d_context *context, DWORD location)
{
struct wined3d_texture *texture = volume->container;
switch (location)
{
case WINED3D_LOCATION_SYSMEM:
return volume_prepare_system_memory(volume);
case WINED3D_LOCATION_BUFFER:
wined3d_texture_prepare_buffer_object(texture, volume->texture_level, context->gl_info);
return TRUE;
case WINED3D_LOCATION_TEXTURE_RGB:
wined3d_texture_prepare_texture(texture, context, FALSE);
return TRUE;
case WINED3D_LOCATION_TEXTURE_SRGB:
wined3d_texture_prepare_texture(texture, context, TRUE);
return TRUE;
default:
ERR("Invalid location %s.\n", wined3d_debug_location(location));
return FALSE;
}
return wined3d_texture_prepare_location(volume->container, volume->texture_level, context, location);
}
/* This call just uploads data, the caller is responsible for binding the

View File

@ -2428,8 +2428,6 @@ struct wined3d_texture_ops
const struct wined3d_context *context, const struct wined3d_sub_resource_data *data);
BOOL (*texture_load_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_context *context, DWORD location);
BOOL (*texture_prepare_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_context *context, DWORD location);
void (*texture_prepare_texture)(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb);
void (*texture_cleanup_sub_resources)(struct wined3d_texture *texture);
@ -2567,10 +2565,8 @@ void wined3d_texture_load(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void *wined3d_texture_map_bo_address(const struct wined3d_bo_address *data, size_t size,
const struct wined3d_gl_info *gl_info, GLenum binding, DWORD flags) DECLSPEC_HIDDEN;
void wined3d_texture_prepare_buffer_object(struct wined3d_texture *texture,
unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
void wined3d_texture_prepare_rb(struct wined3d_texture *texture,
const struct wined3d_gl_info *gl_info, BOOL multisample) DECLSPEC_HIDDEN;
BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
void wined3d_texture_prepare_texture(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void wined3d_texture_set_dirty(struct wined3d_texture *texture) DECLSPEC_HIDDEN;