Commit 2f938ef3 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

ddraw: Track location for surfaces with the second texture.

parent 041ff96f
...@@ -155,6 +155,9 @@ void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS *pIn, DDSCAPS2 *pOut) DECLSPEC_H ...@@ -155,6 +155,9 @@ void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS *pIn, DDSCAPS2 *pOut) DECLSPEC_H
void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2 *pIn, DDDEVICEIDENTIFIER *pOut) DECLSPEC_HIDDEN; void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2 *pIn, DDDEVICEIDENTIFIER *pOut) DECLSPEC_HIDDEN;
struct wined3d_vertex_declaration *ddraw_find_decl(struct ddraw *ddraw, DWORD fvf) DECLSPEC_HIDDEN; struct wined3d_vertex_declaration *ddraw_find_decl(struct ddraw *ddraw, DWORD fvf) DECLSPEC_HIDDEN;
#define DDRAW_SURFACE_LOCATION_DEFAULT 0x00000001
#define DDRAW_SURFACE_LOCATION_DRAW 0x00000002
struct ddraw_surface struct ddraw_surface
{ {
/* IUnknown fields */ /* IUnknown fields */
...@@ -175,6 +178,7 @@ struct ddraw_surface ...@@ -175,6 +178,7 @@ struct ddraw_surface
/* Connections to other Objects */ /* Connections to other Objects */
struct ddraw *ddraw; struct ddraw *ddraw;
unsigned int texture_location;
struct wined3d_texture *wined3d_texture; struct wined3d_texture *wined3d_texture;
struct wined3d_texture *draw_texture; struct wined3d_texture *draw_texture;
unsigned int sub_resource_idx; unsigned int sub_resource_idx;
...@@ -654,22 +658,48 @@ static inline BOOL ddraw_surface_can_be_lost(const struct ddraw_surface *surface ...@@ -654,22 +658,48 @@ static inline BOOL ddraw_surface_can_be_lost(const struct ddraw_surface *surface
return surface->sysmem_fallback; return surface->sysmem_fallback;
} }
static inline void d3d_surface_sync_textures(struct ddraw_surface *surface, BOOL upload) #define DDRAW_SURFACE_READ 0x00000001
#define DDRAW_SURFACE_WRITE 0x00000002
#define DDRAW_SURFACE_RW (DDRAW_SURFACE_READ | DDRAW_SURFACE_WRITE)
static inline struct wined3d_texture *ddraw_surface_get_default_texture(struct ddraw_surface *surface, unsigned int flags)
{
if (surface->draw_texture)
{
if (flags & DDRAW_SURFACE_READ && !(surface->texture_location & DDRAW_SURFACE_LOCATION_DEFAULT))
{
wined3d_device_copy_sub_resource_region(surface->ddraw->wined3d_device,
wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx, 0, 0, 0,
wined3d_texture_get_resource(surface->draw_texture), surface->sub_resource_idx, NULL, 0);
surface->texture_location |= DDRAW_SURFACE_LOCATION_DEFAULT;
}
if (flags & DDRAW_SURFACE_WRITE)
surface->texture_location = DDRAW_SURFACE_LOCATION_DEFAULT;
}
return surface->wined3d_texture;
}
static inline struct wined3d_texture *ddraw_surface_get_draw_texture(struct ddraw_surface *surface, unsigned int flags)
{ {
if (!surface->draw_texture) if (!surface->draw_texture)
return; return surface->wined3d_texture;
if (upload) if (flags & DDRAW_SURFACE_READ && !(surface->texture_location & DDRAW_SURFACE_LOCATION_DRAW))
{
wined3d_device_copy_sub_resource_region(surface->ddraw->wined3d_device, wined3d_device_copy_sub_resource_region(surface->ddraw->wined3d_device,
wined3d_texture_get_resource(surface->draw_texture), surface->sub_resource_idx, 0, 0, 0, wined3d_texture_get_resource(surface->draw_texture), surface->sub_resource_idx, 0, 0, 0,
wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx, NULL, 0); wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx, NULL, 0);
else surface->texture_location |= DDRAW_SURFACE_LOCATION_DRAW;
wined3d_device_copy_sub_resource_region(surface->ddraw->wined3d_device, }
wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx, 0, 0, 0,
wined3d_texture_get_resource(surface->draw_texture), surface->sub_resource_idx, NULL, 0); if (flags & DDRAW_SURFACE_WRITE)
surface->texture_location = DDRAW_SURFACE_LOCATION_DRAW;
return surface->draw_texture;
} }
void d3d_device_sync_surfaces(struct d3d_device *device, BOOL upload) DECLSPEC_HIDDEN; void d3d_device_sync_surfaces(struct d3d_device *device) DECLSPEC_HIDDEN;
/* Used for generic dumping */ /* Used for generic dumping */
struct flag_info struct flag_info
......
...@@ -3427,7 +3427,7 @@ static HRESULT d3d_device_prepare_vertex_buffer(struct d3d_device *device, UINT ...@@ -3427,7 +3427,7 @@ static HRESULT d3d_device_prepare_vertex_buffer(struct d3d_device *device, UINT
return D3D_OK; return D3D_OK;
} }
static void d3d_device_sync_rendertarget(struct d3d_device *device, BOOL upload) static void d3d_device_sync_rendertarget(struct d3d_device *device)
{ {
struct wined3d_rendertarget_view *rtv; struct wined3d_rendertarget_view *rtv;
...@@ -3435,13 +3435,13 @@ static void d3d_device_sync_rendertarget(struct d3d_device *device, BOOL upload) ...@@ -3435,13 +3435,13 @@ static void d3d_device_sync_rendertarget(struct d3d_device *device, BOOL upload)
return; return;
if ((rtv = wined3d_device_get_rendertarget_view(device->wined3d_device, 0))) if ((rtv = wined3d_device_get_rendertarget_view(device->wined3d_device, 0)))
d3d_surface_sync_textures(wined3d_rendertarget_view_get_parent(rtv), upload); ddraw_surface_get_draw_texture(wined3d_rendertarget_view_get_parent(rtv), DDRAW_SURFACE_RW);
if ((rtv = wined3d_device_get_depth_stencil_view(device->wined3d_device))) if ((rtv = wined3d_device_get_depth_stencil_view(device->wined3d_device)))
d3d_surface_sync_textures(wined3d_rendertarget_view_get_parent(rtv), upload); ddraw_surface_get_draw_texture(wined3d_rendertarget_view_get_parent(rtv), DDRAW_SURFACE_RW);
} }
void d3d_device_sync_surfaces(struct d3d_device *device, BOOL upload) void d3d_device_sync_surfaces(struct d3d_device *device)
{ {
const struct wined3d_stateblock_state *state = device->stateblock_state; const struct wined3d_stateblock_state *state = device->stateblock_state;
struct ddraw_surface *surface; struct ddraw_surface *surface;
...@@ -3450,7 +3450,7 @@ void d3d_device_sync_surfaces(struct d3d_device *device, BOOL upload) ...@@ -3450,7 +3450,7 @@ void d3d_device_sync_surfaces(struct d3d_device *device, BOOL upload)
if (device->hardware_device) if (device->hardware_device)
return; return;
d3d_device_sync_rendertarget(device, upload); d3d_device_sync_rendertarget(device);
for (i = 0; i < ARRAY_SIZE(state->textures); ++i) for (i = 0; i < ARRAY_SIZE(state->textures); ++i)
{ {
...@@ -3462,7 +3462,7 @@ void d3d_device_sync_surfaces(struct d3d_device *device, BOOL upload) ...@@ -3462,7 +3462,7 @@ void d3d_device_sync_surfaces(struct d3d_device *device, BOOL upload)
{ {
if (!surface->draw_texture) if (!surface->draw_texture)
break; break;
d3d_surface_sync_textures(surface, upload); ddraw_surface_get_draw_texture(surface, DDRAW_SURFACE_READ);
++j; ++j;
} }
} }
...@@ -3522,9 +3522,8 @@ static HRESULT d3d_device7_DrawPrimitive(IDirect3DDevice7 *iface, ...@@ -3522,9 +3522,8 @@ static HRESULT d3d_device7_DrawPrimitive(IDirect3DDevice7 *iface,
wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf)); wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf));
wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0); wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / stride, vertex_count); hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / stride, vertex_count);
d3d_device_sync_surfaces(device, FALSE);
done: done:
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -3736,9 +3735,8 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface, ...@@ -3736,9 +3735,8 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0); wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0);
wined3d_stateblock_set_base_vertex_index(device->state, vb_pos / stride); wined3d_stateblock_set_base_vertex_index(device->state, vb_pos / stride);
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(*indices), index_count); hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(*indices), index_count);
d3d_device_sync_surfaces(device, FALSE);
done: done:
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -4064,9 +4062,8 @@ static HRESULT d3d_device7_DrawPrimitiveStrided(IDirect3DDevice7 *iface, D3DPRIM ...@@ -4064,9 +4062,8 @@ static HRESULT d3d_device7_DrawPrimitiveStrided(IDirect3DDevice7 *iface, D3DPRIM
wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0); wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / dst_stride, vertex_count); hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / dst_stride, vertex_count);
d3d_device_sync_surfaces(device, FALSE);
done: done:
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -4202,9 +4199,8 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface, ...@@ -4202,9 +4199,8 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf)); wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf));
wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0); wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(WORD), index_count); hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(WORD), index_count);
d3d_device_sync_surfaces(device, FALSE);
done: done:
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -4326,9 +4322,8 @@ static HRESULT d3d_device7_DrawPrimitiveVB(IDirect3DDevice7 *iface, D3DPRIMITIVE ...@@ -4326,9 +4322,8 @@ static HRESULT d3d_device7_DrawPrimitiveVB(IDirect3DDevice7 *iface, D3DPRIMITIVE
/* Now draw the primitives */ /* Now draw the primitives */
wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0); wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex, vertex_count); hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex, vertex_count);
d3d_device_sync_surfaces(device, FALSE);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -4482,9 +4477,8 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface, ...@@ -4482,9 +4477,8 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0); wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_ddraw(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(WORD), index_count); hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(WORD), index_count);
d3d_device_sync_surfaces(device, FALSE);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -5323,9 +5317,8 @@ static HRESULT d3d_device7_Clear(IDirect3DDevice7 *iface, DWORD count, ...@@ -5323,9 +5317,8 @@ static HRESULT d3d_device7_Clear(IDirect3DDevice7 *iface, DWORD count,
wined3d_mutex_lock(); wined3d_mutex_lock();
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_rendertarget(device, TRUE); d3d_device_sync_rendertarget(device);
hr = wined3d_device_clear(device->wined3d_device, count, (RECT *)rects, flags, &c, z, stencil); hr = wined3d_device_clear(device->wined3d_device, count, (RECT *)rects, flags, &c, z, stencil);
d3d_device_sync_rendertarget(device, FALSE);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
return hr; return hr;
...@@ -6178,8 +6171,10 @@ static void copy_mipmap_chain(struct d3d_device *device, struct ddraw_surface *d ...@@ -6178,8 +6171,10 @@ static void copy_mipmap_chain(struct d3d_device *device, struct ddraw_surface *d
UINT src_h = src_rect.bottom - src_rect.top; UINT src_h = src_rect.bottom - src_rect.top;
RECT dst_rect = {point.x, point.y, point.x + src_w, point.y + src_h}; RECT dst_rect = {point.x, point.y, point.x + src_w, point.y + src_h};
if (FAILED(hr = wined3d_texture_blt(dst_level->wined3d_texture, dst_level->sub_resource_idx, &dst_rect, if (FAILED(hr = wined3d_texture_blt(ddraw_surface_get_default_texture(dst_level, DDRAW_SURFACE_RW),
src_level->wined3d_texture, src_level->sub_resource_idx, &src_rect, 0, NULL, WINED3D_TEXF_POINT))) dst_level->sub_resource_idx, &dst_rect,
ddraw_surface_get_default_texture(src_level, DDRAW_SURFACE_READ),
src_level->sub_resource_idx, &src_rect, 0, NULL, WINED3D_TEXF_POINT)))
ERR("Blit failed, hr %#x.\n", hr); ERR("Blit failed, hr %#x.\n", hr);
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE; ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
......
...@@ -81,10 +81,9 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d ...@@ -81,10 +81,9 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d
ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX)); ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
for (i = 0; i < count; ++i) for (i = 0; i < count; ++i)
wined3d_device_draw_primitive(device->wined3d_device, p[i].wFirst, p[i].wCount); wined3d_device_draw_primitive(device->wined3d_device, p[i].wFirst, p[i].wCount);
d3d_device_sync_surfaces(device, FALSE);
instr += sizeof(*p) * count; instr += sizeof(*p) * count;
break; break;
...@@ -191,9 +190,8 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d ...@@ -191,9 +190,8 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d
ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX)); ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
wined3d_stateblock_set_index_buffer(device->state, buffer->index_buffer, WINED3DFMT_R16_UINT); wined3d_stateblock_set_index_buffer(device->state, buffer->index_buffer, WINED3DFMT_R16_UINT);
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
wined3d_device_draw_indexed_primitive(device->wined3d_device, index_pos, index_count); wined3d_device_draw_indexed_primitive(device->wined3d_device, index_pos, index_count);
d3d_device_sync_surfaces(device, FALSE);
buffer->index_pos = index_pos + index_count; buffer->index_pos = index_pos + index_count;
break; break;
...@@ -314,10 +312,9 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d ...@@ -314,10 +312,9 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d
ddraw_find_decl(device->ddraw, op == D3DPROCESSVERTICES_TRANSFORMLIGHT ddraw_find_decl(device->ddraw, op == D3DPROCESSVERTICES_TRANSFORMLIGHT
? D3DFVF_VERTEX : D3DFVF_LVERTEX)); ? D3DFVF_VERTEX : D3DFVF_LVERTEX));
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device, TRUE); d3d_device_sync_surfaces(device);
wined3d_device_process_vertices(device->wined3d_device, ci->wStart, ci->wDest, wined3d_device_process_vertices(device->wined3d_device, ci->wStart, ci->wDest,
ci->dwCount, buffer->dst_vertex_buffer, NULL, 0, D3DFVF_TLVERTEX); ci->dwCount, buffer->dst_vertex_buffer, NULL, 0, D3DFVF_TLVERTEX);
d3d_device_sync_surfaces(device, FALSE);
break; break;
case D3DPROCESSVERTICES_COPY: case D3DPROCESSVERTICES_COPY:
......
...@@ -56,8 +56,8 @@ static BOOL ddraw_gdi_is_front(struct ddraw *ddraw) ...@@ -56,8 +56,8 @@ static BOOL ddraw_gdi_is_front(struct ddraw *ddraw)
HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface, HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface,
const RECT *rect, BOOL read, unsigned int swap_interval) const RECT *rect, BOOL read, unsigned int swap_interval)
{ {
struct wined3d_texture *dst_texture, *wined3d_texture;
struct ddraw *ddraw = surface->ddraw; struct ddraw *ddraw = surface->ddraw;
struct wined3d_texture *dst_texture;
HDC surface_dc, screen_dc; HDC surface_dc, screen_dc;
int x, y, w, h; int x, y, w, h;
HRESULT hr; HRESULT hr;
...@@ -112,8 +112,9 @@ HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface, ...@@ -112,8 +112,9 @@ HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface,
else else
dst_texture = ddraw->wined3d_frontbuffer; dst_texture = ddraw->wined3d_frontbuffer;
if (SUCCEEDED(hr = wined3d_texture_blt(dst_texture, 0, rect, surface->wined3d_texture, if (SUCCEEDED(hr = wined3d_texture_blt(dst_texture, 0, rect,
surface->sub_resource_idx, rect, 0, NULL, WINED3D_TEXF_POINT)) && swap_interval) ddraw_surface_get_default_texture(surface, DDRAW_SURFACE_READ), surface->sub_resource_idx, rect, 0,
NULL, WINED3D_TEXF_POINT)) && swap_interval)
{ {
hr = wined3d_swapchain_present(ddraw->wined3d_swapchain, rect, rect, NULL, swap_interval, 0); hr = wined3d_swapchain_present(ddraw->wined3d_swapchain, rect, rect, NULL, swap_interval, 0);
ddraw->flags |= DDRAW_SWAPPED; ddraw->flags |= DDRAW_SWAPPED;
...@@ -121,7 +122,10 @@ HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface, ...@@ -121,7 +122,10 @@ HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface,
return hr; return hr;
} }
if (FAILED(hr = wined3d_texture_get_dc(surface->wined3d_texture, surface->sub_resource_idx, &surface_dc))) wined3d_texture = ddraw_surface_get_default_texture(surface, read ? (rect ? DDRAW_SURFACE_RW : DDRAW_SURFACE_WRITE)
: DDRAW_SURFACE_READ);
if (FAILED(hr = wined3d_texture_get_dc(wined3d_texture, surface->sub_resource_idx, &surface_dc)))
{ {
ERR("Failed to get surface DC, hr %#x.\n", hr); ERR("Failed to get surface DC, hr %#x.\n", hr);
return hr; return hr;
...@@ -131,7 +135,7 @@ HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface, ...@@ -131,7 +135,7 @@ HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface,
if (!(screen_dc = GetDC(NULL))) if (!(screen_dc = GetDC(NULL)))
{ {
wined3d_texture_release_dc(surface->wined3d_texture, surface->sub_resource_idx, surface_dc); wined3d_texture_release_dc(wined3d_texture, surface->sub_resource_idx, surface_dc);
ERR("Failed to get screen DC.\n"); ERR("Failed to get screen DC.\n");
return E_FAIL; return E_FAIL;
} }
...@@ -144,7 +148,7 @@ HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface, ...@@ -144,7 +148,7 @@ HRESULT ddraw_surface_update_frontbuffer(struct ddraw_surface *surface,
surface_dc, x, y, SRCCOPY); surface_dc, x, y, SRCCOPY);
ReleaseDC(NULL, screen_dc); ReleaseDC(NULL, screen_dc);
wined3d_texture_release_dc(surface->wined3d_texture, surface->sub_resource_idx, surface_dc); wined3d_texture_release_dc(wined3d_texture, surface->sub_resource_idx, surface_dc);
if (!ret) if (!ret)
{ {
...@@ -1057,9 +1061,9 @@ static HRESULT surface_lock(struct ddraw_surface *surface, ...@@ -1057,9 +1061,9 @@ static HRESULT surface_lock(struct ddraw_surface *surface,
if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
hr = ddraw_surface_update_frontbuffer(surface, rect, TRUE, 0); hr = ddraw_surface_update_frontbuffer(surface, rect, TRUE, 0);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
hr = wined3d_resource_map(wined3d_texture_get_resource(surface->wined3d_texture), hr = wined3d_resource_map(wined3d_texture_get_resource
surface->sub_resource_idx, &map_desc, rect ? &box : NULL, (ddraw_surface_get_default_texture(surface, DDRAW_SURFACE_RW)), surface->sub_resource_idx,
wined3dmapflags_from_ddrawmapflags(flags)); &map_desc, rect ? &box : NULL, wined3dmapflags_from_ddrawmapflags(flags));
if (FAILED(hr)) if (FAILED(hr))
{ {
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -1235,7 +1239,8 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH ddraw_surface1_Unlock(IDirectDrawSurface ...@@ -1235,7 +1239,8 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH ddraw_surface1_Unlock(IDirectDrawSurface
TRACE("iface %p, data %p.\n", iface, data); TRACE("iface %p, data %p.\n", iface, data);
wined3d_mutex_lock(); wined3d_mutex_lock();
hr = wined3d_resource_unmap(wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx); hr = wined3d_resource_unmap(wined3d_texture_get_resource
(ddraw_surface_get_default_texture(surface, 0)), surface->sub_resource_idx);
if (SUCCEEDED(hr) && surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) if (SUCCEEDED(hr) && surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
hr = ddraw_surface_update_frontbuffer(surface, &surface->ddraw->primary_lock, FALSE, 0); hr = ddraw_surface_update_frontbuffer(surface, &surface->ddraw->primary_lock, FALSE, 0);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -1507,7 +1512,6 @@ static HRESULT ddraw_surface_blt(struct ddraw_surface *dst_surface, const RECT * ...@@ -1507,7 +1512,6 @@ static HRESULT ddraw_surface_blt(struct ddraw_surface *dst_surface, const RECT *
struct wined3d_device *wined3d_device = dst_surface->ddraw->wined3d_device; struct wined3d_device *wined3d_device = dst_surface->ddraw->wined3d_device;
struct wined3d_color colour; struct wined3d_color colour;
DWORD wined3d_flags; DWORD wined3d_flags;
HRESULT hr;
if (flags & DDBLT_COLORFILL) if (flags & DDBLT_COLORFILL)
{ {
...@@ -1520,12 +1524,10 @@ static HRESULT ddraw_surface_blt(struct ddraw_surface *dst_surface, const RECT * ...@@ -1520,12 +1524,10 @@ static HRESULT ddraw_surface_blt(struct ddraw_surface *dst_surface, const RECT *
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
wined3d_device_apply_stateblock(wined3d_device, dst_surface->ddraw->state); wined3d_device_apply_stateblock(wined3d_device, dst_surface->ddraw->state);
d3d_surface_sync_textures(dst_surface, TRUE); ddraw_surface_get_draw_texture(dst_surface, dst_rect ? DDRAW_SURFACE_RW : DDRAW_SURFACE_WRITE);
hr = wined3d_device_clear_rendertarget_view(wined3d_device, return wined3d_device_clear_rendertarget_view(wined3d_device,
ddraw_surface_get_rendertarget_view(dst_surface), ddraw_surface_get_rendertarget_view(dst_surface),
dst_rect, wined3d_flags, &colour, 0.0f, 0); dst_rect, wined3d_flags, &colour, 0.0f, 0);
d3d_surface_sync_textures(dst_surface, FALSE);
return hr;
} }
if (flags & DDBLT_DEPTHFILL) if (flags & DDBLT_DEPTHFILL)
...@@ -1539,12 +1541,10 @@ static HRESULT ddraw_surface_blt(struct ddraw_surface *dst_surface, const RECT * ...@@ -1539,12 +1541,10 @@ static HRESULT ddraw_surface_blt(struct ddraw_surface *dst_surface, const RECT *
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
wined3d_device_apply_stateblock(wined3d_device, dst_surface->ddraw->state); wined3d_device_apply_stateblock(wined3d_device, dst_surface->ddraw->state);
d3d_surface_sync_textures(dst_surface, TRUE); ddraw_surface_get_draw_texture(dst_surface, dst_rect ? DDRAW_SURFACE_RW : DDRAW_SURFACE_WRITE);
hr = wined3d_device_clear_rendertarget_view(wined3d_device, return wined3d_device_clear_rendertarget_view(wined3d_device,
ddraw_surface_get_rendertarget_view(dst_surface), ddraw_surface_get_rendertarget_view(dst_surface),
dst_rect, wined3d_flags, NULL, colour.r, 0); dst_rect, wined3d_flags, NULL, colour.r, 0);
d3d_surface_sync_textures(dst_surface, FALSE);
return hr;
} }
wined3d_flags = flags & ~DDBLT_ASYNC; wined3d_flags = flags & ~DDBLT_ASYNC;
...@@ -1557,8 +1557,9 @@ static HRESULT ddraw_surface_blt(struct ddraw_surface *dst_surface, const RECT * ...@@ -1557,8 +1557,9 @@ static HRESULT ddraw_surface_blt(struct ddraw_surface *dst_surface, const RECT *
if (!(flags & DDBLT_ASYNC)) if (!(flags & DDBLT_ASYNC))
wined3d_flags |= WINED3D_BLT_SYNCHRONOUS; wined3d_flags |= WINED3D_BLT_SYNCHRONOUS;
return wined3d_texture_blt(dst_surface->wined3d_texture, dst_surface->sub_resource_idx, dst_rect, return wined3d_texture_blt(ddraw_surface_get_default_texture(dst_surface, DDRAW_SURFACE_RW),
src_surface->wined3d_texture, src_surface->sub_resource_idx, src_rect, wined3d_flags, fx, filter); dst_surface->sub_resource_idx, dst_rect, ddraw_surface_get_default_texture(src_surface, DDRAW_SURFACE_READ),
src_surface->sub_resource_idx, src_rect, wined3d_flags, fx, filter);
} }
static HRESULT ddraw_surface_blt_clipped(struct ddraw_surface *dst_surface, const RECT *dst_rect_in, static HRESULT ddraw_surface_blt_clipped(struct ddraw_surface *dst_surface, const RECT *dst_rect_in,
...@@ -2328,7 +2329,7 @@ static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *dc) ...@@ -2328,7 +2329,7 @@ static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *dc)
else if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) else if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
hr = ddraw_surface_update_frontbuffer(surface, NULL, TRUE, 0); hr = ddraw_surface_update_frontbuffer(surface, NULL, TRUE, 0);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
hr = wined3d_texture_get_dc(surface->wined3d_texture, surface->sub_resource_idx, dc); hr = wined3d_texture_get_dc(ddraw_surface_get_default_texture(surface, DDRAW_SURFACE_RW), surface->sub_resource_idx, dc);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
...@@ -2424,7 +2425,8 @@ static HRESULT WINAPI ddraw_surface7_ReleaseDC(IDirectDrawSurface7 *iface, HDC h ...@@ -2424,7 +2425,8 @@ static HRESULT WINAPI ddraw_surface7_ReleaseDC(IDirectDrawSurface7 *iface, HDC h
{ {
hr = DDERR_NODC; hr = DDERR_NODC;
} }
else if (SUCCEEDED(hr = wined3d_texture_release_dc(surface->wined3d_texture, surface->sub_resource_idx, hdc))) else if (SUCCEEDED(hr = wined3d_texture_release_dc(ddraw_surface_get_default_texture(surface, 0),
surface->sub_resource_idx, hdc)))
{ {
surface->dc = NULL; surface->dc = NULL;
if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
...@@ -4404,8 +4406,9 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH ddraw_surface7_BltFast(IDirectDrawSurfac ...@@ -4404,8 +4406,9 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH ddraw_surface7_BltFast(IDirectDrawSurfac
if (src_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) if (src_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
hr = ddraw_surface_update_frontbuffer(src_impl, src_rect, TRUE, 0); hr = ddraw_surface_update_frontbuffer(src_impl, src_rect, TRUE, 0);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
hr = wined3d_texture_blt(dst_impl->wined3d_texture, dst_impl->sub_resource_idx, &dst_rect, hr = wined3d_texture_blt(ddraw_surface_get_default_texture(dst_impl, DDRAW_SURFACE_RW),
src_impl->wined3d_texture, src_impl->sub_resource_idx, src_rect, flags, NULL, WINED3D_TEXF_POINT); dst_impl->sub_resource_idx, &dst_rect, ddraw_surface_get_default_texture(src_impl,DDRAW_SURFACE_READ),
src_impl->sub_resource_idx, src_rect, flags, NULL, WINED3D_TEXF_POINT);
if (SUCCEEDED(hr) && (dst_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) if (SUCCEEDED(hr) && (dst_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
hr = ddraw_surface_update_frontbuffer(dst_impl, &dst_rect, FALSE, 0); hr = ddraw_surface_update_frontbuffer(dst_impl, &dst_rect, FALSE, 0);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -5341,8 +5344,8 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu ...@@ -5341,8 +5344,8 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu
wined3d_mutex_lock(); wined3d_mutex_lock();
dst_resource = wined3d_texture_get_resource(dst_surface->wined3d_texture); dst_resource = wined3d_texture_get_resource(ddraw_surface_get_default_texture(dst_surface, DDRAW_SURFACE_WRITE));
src_resource = wined3d_texture_get_resource(src_surface->wined3d_texture); src_resource = wined3d_texture_get_resource(ddraw_surface_get_default_texture(src_surface, DDRAW_SURFACE_READ));
if (((src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) if (((src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
!= (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)) != (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP))
...@@ -6782,6 +6785,7 @@ void ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, ...@@ -6782,6 +6785,7 @@ void ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw,
wined3d_texture_incref(surface->wined3d_texture = wined3d_texture); wined3d_texture_incref(surface->wined3d_texture = wined3d_texture);
surface->sub_resource_idx = sub_resource_idx; surface->sub_resource_idx = sub_resource_idx;
*parent_ops = &ddraw_surface_wined3d_parent_ops; *parent_ops = &ddraw_surface_wined3d_parent_ops;
surface->texture_location = DDRAW_SURFACE_LOCATION_DEFAULT;
wined3d_private_store_init(&surface->private_store); wined3d_private_store_init(&surface->private_store);
} }
......
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