Commit 2efaddc7 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Merge wined3d_surface_update_desc() into wined3d_texture_update_desc().

parent bad48492
...@@ -1677,85 +1677,6 @@ static inline unsigned short float_32_to_16(const float *in) ...@@ -1677,85 +1677,6 @@ static inline unsigned short float_32_to_16(const float *in)
return ret; return ret;
} }
HRESULT wined3d_surface_update_desc(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info)
{
struct wined3d_resource *texture_resource = &surface->container->resource;
unsigned int width, height;
BOOL create_dib = FALSE;
DWORD valid_location = 0;
HRESULT hr;
if (surface->flags & SFLAG_DIBSECTION)
{
DeleteDC(surface->hDC);
DeleteObject(surface->dib.DIBsection);
surface->dib.bitmap_data = NULL;
surface->flags &= ~SFLAG_DIBSECTION;
create_dib = TRUE;
}
surface->locations = 0;
wined3d_resource_free_sysmem(&surface->resource);
width = texture_resource->width;
height = texture_resource->height;
surface->resource.width = width;
surface->resource.height = height;
if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || gl_info->supported[ARB_TEXTURE_RECTANGLE]
|| gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
{
surface->pow2Width = width;
surface->pow2Height = height;
}
else
{
surface->pow2Width = surface->pow2Height = 1;
while (surface->pow2Width < width)
surface->pow2Width <<= 1;
while (surface->pow2Height < height)
surface->pow2Height <<= 1;
}
if (surface->container->user_memory)
{
surface->resource.map_binding = WINED3D_LOCATION_USER_MEMORY;
valid_location = WINED3D_LOCATION_USER_MEMORY;
}
surface->resource.format = texture_resource->format;
surface->resource.multisample_type = texture_resource->multisample_type;
surface->resource.multisample_quality = texture_resource->multisample_quality;
surface->resource.size = surface->container->slice_pitch;
/* The format might be changed to a format that needs conversion.
* If the surface didn't use PBOs previously but could now, don't
* change it - whatever made us not use PBOs might come back, e.g.
* color keys. */
if (surface->resource.map_binding == WINED3D_LOCATION_BUFFER
&& !wined3d_texture_use_pbo(surface->container, gl_info))
surface->resource.map_binding = create_dib ? WINED3D_LOCATION_DIB : WINED3D_LOCATION_SYSMEM;
if (create_dib)
{
if (FAILED(hr = surface_create_dib_section(surface)))
{
ERR("Failed to create dib section, hr %#x.\n", hr);
return hr;
}
if (!valid_location)
valid_location = WINED3D_LOCATION_DIB;
}
if (!valid_location)
{
surface_prepare_system_memory(surface);
valid_location = WINED3D_LOCATION_SYSMEM;
}
surface_validate_location(surface, valid_location);
return WINED3D_OK;
}
static void convert_r32_float_r16_float(const BYTE *src, BYTE *dst, static void convert_r32_float_r16_float(const BYTE *src, BYTE *dst,
DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h) DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
{ {
......
...@@ -670,6 +670,8 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT ...@@ -670,6 +670,8 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT
const struct wined3d_format *format = wined3d_get_format(gl_info, format_id); const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
UINT resource_size = wined3d_format_calculate_size(format, device->surface_alignment, width, height, 1); UINT resource_size = wined3d_format_calculate_size(format, device->surface_alignment, width, height, 1);
struct wined3d_surface *surface; struct wined3d_surface *surface;
DWORD valid_location = 0;
BOOL create_dib = FALSE;
TRACE("texture %p, width %u, height %u, format %s, multisample_type %#x, multisample_quality %u, " TRACE("texture %p, width %u, height %u, format %s, multisample_type %#x, multisample_quality %u, "
"mem %p, pitch %u.\n", "mem %p, pitch %u.\n",
...@@ -713,13 +715,19 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT ...@@ -713,13 +715,19 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT
if (device->d3d_initialized) if (device->d3d_initialized)
texture->resource.resource_ops->resource_unload(&texture->resource); texture->resource.resource_ops->resource_unload(&texture->resource);
texture->resource.format = format; if (surface->flags & SFLAG_DIBSECTION)
texture->resource.multisample_type = multisample_type; {
texture->resource.multisample_quality = multisample_quality; DeleteDC(surface->hDC);
texture->resource.width = width; surface->hDC = NULL;
texture->resource.height = height; DeleteObject(surface->dib.DIBsection);
surface->dib.DIBsection = NULL;
surface->dib.bitmap_data = NULL;
surface->flags &= ~SFLAG_DIBSECTION;
create_dib = TRUE;
}
wined3d_resource_free_sysmem(&surface->resource);
texture->user_memory = mem;
if ((texture->row_pitch = pitch)) if ((texture->row_pitch = pitch))
texture->slice_pitch = height * pitch; texture->slice_pitch = height * pitch;
else else
...@@ -727,12 +735,63 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT ...@@ -727,12 +735,63 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT
wined3d_format_calculate_pitch(format, 1, width, height, wined3d_format_calculate_pitch(format, 1, width, height,
&texture->row_pitch, &texture->slice_pitch); &texture->row_pitch, &texture->slice_pitch);
texture->flags &= ~WINED3D_TEXTURE_COND_NP2_EMULATED; texture->resource.format = format;
texture->resource.multisample_type = multisample_type;
texture->resource.multisample_quality = multisample_quality;
texture->resource.width = width;
texture->resource.height = height;
surface->resource.format = format;
surface->resource.multisample_type = multisample_type;
surface->resource.multisample_quality = multisample_quality;
surface->resource.width = width;
surface->resource.height = height;
surface->resource.size = texture->slice_pitch;
if (((width & (width - 1)) || (height & (height - 1))) && !gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] if (((width & (width - 1)) || (height & (height - 1))) && !gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]
&& !gl_info->supported[ARB_TEXTURE_RECTANGLE] && !gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT]) && !gl_info->supported[ARB_TEXTURE_RECTANGLE] && !gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
{
texture->flags |= WINED3D_TEXTURE_COND_NP2_EMULATED; texture->flags |= WINED3D_TEXTURE_COND_NP2_EMULATED;
surface->pow2Width = surface->pow2Height = 1;
while (surface->pow2Width < width)
surface->pow2Width <<= 1;
while (surface->pow2Height < height)
surface->pow2Height <<= 1;
}
else
{
texture->flags &= ~WINED3D_TEXTURE_COND_NP2_EMULATED;
surface->pow2Width = width;
surface->pow2Height = height;
}
surface->locations = 0;
if ((texture->user_memory = mem))
{
surface->resource.map_binding = WINED3D_LOCATION_USER_MEMORY;
valid_location = WINED3D_LOCATION_USER_MEMORY;
}
else if (create_dib && SUCCEEDED(surface_create_dib_section(surface)))
{
valid_location = WINED3D_LOCATION_DIB;
}
else
{
wined3d_surface_prepare(surface, NULL, WINED3D_LOCATION_SYSMEM);
valid_location = WINED3D_LOCATION_SYSMEM;
}
/* The format might be changed to a format that needs conversion.
* If the surface didn't use PBOs previously but could now, don't
* change it - whatever made us not use PBOs might come back, e.g.
* color keys. */
if (surface->resource.map_binding == WINED3D_LOCATION_BUFFER && !wined3d_texture_use_pbo(texture, gl_info))
surface->resource.map_binding = surface->dib.DIBsection ? WINED3D_LOCATION_DIB : WINED3D_LOCATION_SYSMEM;
return wined3d_surface_update_desc(surface, gl_info); surface_validate_location(surface, valid_location);
return WINED3D_OK;
} }
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
......
...@@ -2623,8 +2623,6 @@ void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, ...@@ -2623,8 +2623,6 @@ void surface_set_compatible_renderbuffer(struct wined3d_surface *surface,
void surface_set_dirty(struct wined3d_surface *surface) DECLSPEC_HIDDEN; void surface_set_dirty(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
void surface_set_texture_target(struct wined3d_surface *surface, GLenum target, GLint level) DECLSPEC_HIDDEN; void surface_set_texture_target(struct wined3d_surface *surface, GLenum target, GLint level) DECLSPEC_HIDDEN;
void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN; void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN;
HRESULT wined3d_surface_update_desc(struct wined3d_surface *surface,
const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment