static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT offset, UINT size, BYTE **data, DWORD flags) { struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface); struct wined3d_map_desc wined3d_map_desc; struct wined3d_box wined3d_box = {0}; HRESULT hr; TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n", iface, offset, size, data, flags); wined3d_box.left = offset; wined3d_box.right = offset + size; wined3d_mutex_lock(); hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->wined3d_buffer), 0, &wined3d_map_desc, &wined3d_box, wined3dmapflags_from_d3dmapflags(flags)); wined3d_mutex_unlock(); *data = wined3d_map_desc.data; return hr; }
static HRESULT WINAPI d3d8_surface_LockRect(IDirect3DSurface8 *iface, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); struct wined3d_box box; struct wined3d_map_desc map_desc; HRESULT hr; D3DRESOURCETYPE type; TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n", iface, locked_rect, wine_dbgstr_rect(rect), flags); wined3d_mutex_lock(); if (surface->texture) type = IDirect3DBaseTexture8_GetType(&surface->texture->IDirect3DBaseTexture8_iface); else type = D3DRTYPE_SURFACE; if (rect) { D3DSURFACE_DESC desc; IDirect3DSurface8_GetDesc(iface, &desc); if (type != D3DRTYPE_TEXTURE && ((rect->left < 0) || (rect->top < 0) || (rect->left >= rect->right) || (rect->top >= rect->bottom) || (rect->right > desc.Width) || (rect->bottom > desc.Height))) { WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n"); wined3d_mutex_unlock(); locked_rect->Pitch = 0; locked_rect->pBits = NULL; return D3DERR_INVALIDCALL; } wined3d_box_set(&box, rect->left, rect->top, rect->right, rect->bottom, 0, 1); } hr = wined3d_resource_map(wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx, &map_desc, rect ? &box : NULL, wined3dmapflags_from_d3dmapflags(flags, 0)); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) { locked_rect->Pitch = map_desc.row_pitch; locked_rect->pBits = map_desc.data; } else if (type != D3DRTYPE_TEXTURE) { locked_rect->Pitch = 0; locked_rect->pBits = NULL; } if (hr == E_INVALIDARG) return D3DERR_INVALIDCALL; return hr; }