struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *resource) { D3D11_RESOURCE_DIMENSION dimension; ID3D11Resource_GetType(resource, &dimension); switch (dimension) { case D3D11_RESOURCE_DIMENSION_BUFFER: return wined3d_buffer_get_resource(unsafe_impl_from_ID3D11Buffer( (ID3D11Buffer *)resource)->wined3d_buffer); case D3D11_RESOURCE_DIMENSION_TEXTURE2D: return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture2D( (ID3D11Texture2D *)resource)->wined3d_texture); case D3D11_RESOURCE_DIMENSION_TEXTURE3D: return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture3D( (ID3D11Texture3D *)resource)->wined3d_texture); default: FIXME("Unhandled resource dimension %#x.\n", dimension); return NULL; } }
static HRESULT WINAPI d3d9_surface_LockRect(IDirect3DSurface9 *iface, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags) { struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface); struct wined3d_box box; struct wined3d_map_desc map_desc; HRESULT hr; TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n", iface, locked_rect, wine_dbgstr_rect(rect), flags); if (rect) { box.left = rect->left; box.top = rect->top; box.right = rect->right; box.bottom = rect->bottom; box.front = 0; box.back = 1; } wined3d_mutex_lock(); hr = wined3d_resource_sub_resource_map(wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx, &map_desc, rect ? &box : NULL, flags); wined3d_mutex_unlock(); if (SUCCEEDED(hr)) { locked_rect->Pitch = map_desc.row_pitch; locked_rect->pBits = map_desc.data; } return hr; }
static HRESULT STDMETHODCALLTYPE d3d10_texture3d_Map(ID3D10Texture3D *iface, UINT sub_resource_idx, D3D10_MAP map_type, UINT map_flags, D3D10_MAPPED_TEXTURE3D *mapped_texture) { struct d3d_texture3d *texture = impl_from_ID3D10Texture3D(iface); struct wined3d_map_desc wined3d_map_desc; HRESULT hr; TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n", iface, sub_resource_idx, map_type, map_flags, mapped_texture); if (map_flags) FIXME("Ignoring map_flags %#x.\n", map_flags); wined3d_mutex_lock(); if (SUCCEEDED(hr = wined3d_resource_map(wined3d_texture_get_resource(texture->wined3d_texture), sub_resource_idx, &wined3d_map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type)))) { mapped_texture->pData = wined3d_map_desc.data; mapped_texture->RowPitch = wined3d_map_desc.row_pitch; mapped_texture->DepthPitch = wined3d_map_desc.slice_pitch; } wined3d_mutex_unlock(); return hr; }
static void STDMETHODCALLTYPE d3d10_texture3d_Unmap(ID3D10Texture3D *iface, UINT sub_resource_idx) { struct d3d_texture3d *texture = impl_from_ID3D10Texture3D(iface); TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx); wined3d_mutex_lock(); wined3d_resource_unmap(wined3d_texture_get_resource(texture->wined3d_texture), sub_resource_idx); wined3d_mutex_unlock(); }
static HRESULT WINAPI d3d8_volume_UnlockBox(IDirect3DVolume8 *iface) { struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface); HRESULT hr; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); hr = wined3d_resource_sub_resource_unmap(wined3d_texture_get_resource(volume->wined3d_texture), volume->sub_resource_idx); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI d3d8_texture_3d_FreePrivateData(IDirect3DVolumeTexture8 *iface, REFGUID guid) { struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface); struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); wined3d_mutex_lock(); resource = wined3d_texture_get_resource(texture->wined3d_texture); hr = wined3d_resource_free_private_data(resource, guid); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(IDirect3DVolumeTexture9 *iface, REFGUID refguid) { IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface); struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid)); wined3d_mutex_lock(); resource = wined3d_texture_get_resource(This->wined3d_texture); hr = wined3d_resource_free_private_data(resource, refguid); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI d3d8_texture_3d_GetPrivateData(IDirect3DVolumeTexture8 *iface, REFGUID guid, void *data, DWORD *data_size) { struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface); struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(guid), data, data_size); wined3d_mutex_lock(); resource = wined3d_texture_get_resource(texture->wined3d_texture); hr = wined3d_resource_get_private_data(resource, guid, data, data_size); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetPrivateData(IDirect3DVolumeTexture8 *iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) { IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface); struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(refguid), pData, pSizeOfData); wined3d_mutex_lock(); resource = wined3d_texture_get_resource(This->wined3d_texture); hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI d3d9_surface_UnlockRect(IDirect3DSurface9 *iface) { struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface); HRESULT hr; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); hr = wined3d_resource_sub_resource_unmap(wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx); wined3d_mutex_unlock(); switch(hr) { case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL; default: return hr; } }
static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetPrivateData(IDirect3DVolumeTexture9 *iface, REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) { IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface); struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(refguid), pData, SizeOfData, Flags); wined3d_mutex_lock(); resource = wined3d_texture_get_resource(This->wined3d_texture); hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI d3d8_texture_cube_SetPrivateData(IDirect3DCubeTexture8 *iface, REFGUID guid, const void *data, DWORD data_size, DWORD flags) { struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface); struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n", iface, debugstr_guid(guid), data, data_size, flags); wined3d_mutex_lock(); resource = wined3d_texture_get_resource(texture->wined3d_texture); hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); wined3d_mutex_unlock(); return hr; }
static struct wined3d_resource *wined3d_resource_from_resource(ID3D10Resource *resource) { D3D10_RESOURCE_DIMENSION dimension; ID3D10Resource_GetType(resource, &dimension); switch(dimension) { case D3D10_RESOURCE_DIMENSION_BUFFER: return wined3d_buffer_get_resource(((struct d3d10_buffer *)resource)->wined3d_buffer); case D3D10_RESOURCE_DIMENSION_TEXTURE2D: return wined3d_texture_get_resource(((struct d3d10_texture2d *)resource)->wined3d_texture); default: FIXME("Unhandled resource dimension %#x.\n", dimension); return NULL; } }
void surface_init(struct d3d9_surface *surface, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, struct wined3d_surface *wined3d_surface, const struct wined3d_parent_ops **parent_ops) { struct wined3d_resource_desc desc; IDirect3DBaseTexture9 *texture; surface->IDirect3DSurface9_iface.lpVtbl = &d3d9_surface_vtbl; d3d9_resource_init(&surface->resource); surface->resource.refcount = 0; surface->wined3d_surface = wined3d_surface; list_init(&surface->rtv_entry); surface->container = wined3d_texture_get_parent(wined3d_texture); surface->wined3d_texture = wined3d_texture; surface->sub_resource_idx = sub_resource_idx; if (surface->container && SUCCEEDED(IUnknown_QueryInterface(surface->container, &IID_IDirect3DBaseTexture9, (void **)&texture))) { surface->texture = unsafe_impl_from_IDirect3DBaseTexture9(texture); IDirect3DBaseTexture9_Release(texture); } wined3d_resource_get_desc(wined3d_texture_get_resource(wined3d_texture), &desc); switch (d3dformat_from_wined3dformat(desc.format)) { case D3DFMT_A8R8G8B8: case D3DFMT_X8R8G8B8: case D3DFMT_R5G6B5: case D3DFMT_X1R5G5B5: case D3DFMT_A1R5G5B5: case D3DFMT_R8G8B8: surface->getdc_supported = TRUE; break; default: surface->getdc_supported = FALSE; break; } *parent_ops = &d3d9_surface_wined3d_parent_ops; }
static HRESULT WINAPI d3d8_volume_LockBox(IDirect3DVolume8 *iface, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags) { struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface); struct wined3d_map_desc map_desc; HRESULT hr; TRACE("iface %p, locked_box %p, box %p, flags %#x.\n", iface, locked_box, box, flags); wined3d_mutex_lock(); hr = wined3d_resource_sub_resource_map(wined3d_texture_get_resource(volume->wined3d_texture), volume->sub_resource_idx, &map_desc, (const struct wined3d_box *)box, flags); wined3d_mutex_unlock(); locked_box->RowPitch = map_desc.row_pitch; locked_box->SlicePitch = map_desc.slice_pitch; locked_box->pBits = map_desc.data; return hr; }
static HRESULT WINAPI d3d8_surface_UnlockRect(IDirect3DSurface8 *iface) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); HRESULT hr; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); hr = wined3d_resource_unmap(wined3d_texture_get_resource(surface->wined3d_texture), surface->sub_resource_idx); wined3d_mutex_unlock(); if (hr == WINEDDERR_NOTLOCKED) { D3DRESOURCETYPE type; if (surface->texture) type = IDirect3DBaseTexture8_GetType(&surface->texture->IDirect3DBaseTexture8_iface); else type = D3DRTYPE_SURFACE; hr = type == D3DRTYPE_TEXTURE ? D3D_OK : D3DERR_INVALIDCALL; } return hr; }
static void STDMETHODCALLTYPE d3d11_texture2d_GetDesc(ID3D11Texture2D *iface, D3D11_TEXTURE2D_DESC *desc) { struct d3d_texture2d *texture = impl_from_ID3D11Texture2D(iface); struct wined3d_resource_desc wined3d_desc; TRACE("iface %p, desc %p.\n", iface, desc); *desc = texture->desc; wined3d_mutex_lock(); wined3d_resource_get_desc(wined3d_texture_get_resource(texture->wined3d_texture), &wined3d_desc); wined3d_mutex_unlock(); /* FIXME: Resizing swapchain buffers can cause these to change. We'd like * to get everything from wined3d, but e.g. bind flags don't exist as such * there (yet). */ desc->Width = wined3d_desc.width; desc->Height = wined3d_desc.height; desc->Format = dxgi_format_from_wined3dformat(wined3d_desc.format); desc->SampleDesc.Count = wined3d_desc.multisample_type == WINED3D_MULTISAMPLE_NONE ? 1 : wined3d_desc.multisample_type; desc->SampleDesc.Quality = wined3d_desc.multisample_quality; }
static HRESULT d3d_texture2d_init(struct d3d_texture2d *texture, struct d3d_device *device, const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data) { struct wined3d_resource_desc wined3d_desc; unsigned int levels; HRESULT hr; texture->ID3D11Texture2D_iface.lpVtbl = &d3d11_texture2d_vtbl; texture->ID3D10Texture2D_iface.lpVtbl = &d3d10_texture2d_vtbl; texture->refcount = 1; wined3d_mutex_lock(); wined3d_private_store_init(&texture->private_store); texture->desc = *desc; if (desc->ArraySize != 1) FIXME("Array textures not implemented.\n"); if (desc->SampleDesc.Count > 1) FIXME("Multisampled textures not implemented.\n"); wined3d_desc.resource_type = WINED3D_RTYPE_TEXTURE; wined3d_desc.format = wined3dformat_from_dxgi_format(desc->Format); wined3d_desc.multisample_type = desc->SampleDesc.Count > 1 ? desc->SampleDesc.Count : WINED3D_MULTISAMPLE_NONE; wined3d_desc.multisample_quality = desc->SampleDesc.Quality; wined3d_desc.usage = wined3d_usage_from_d3d11(desc->BindFlags, desc->Usage); wined3d_desc.pool = WINED3D_POOL_DEFAULT; wined3d_desc.width = desc->Width; wined3d_desc.height = desc->Height; wined3d_desc.depth = 1; wined3d_desc.size = 0; levels = desc->MipLevels ? desc->MipLevels : wined3d_log2i(max(desc->Width, desc->Height)) + 1; if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &wined3d_desc, levels, 0, (struct wined3d_sub_resource_data *)data, texture, &d3d_texture2d_wined3d_parent_ops, &texture->wined3d_texture))) { WARN("Failed to create wined3d texture, hr %#x.\n", hr); wined3d_private_store_cleanup(&texture->private_store); wined3d_mutex_unlock(); return hr; } texture->desc.MipLevels = levels; if (desc->MipLevels == 1 && desc->ArraySize == 1) { IWineDXGIDevice *wine_device; if (FAILED(hr = ID3D10Device1_QueryInterface(&device->ID3D10Device1_iface, &IID_IWineDXGIDevice, (void **)&wine_device))) { ERR("Device should implement IWineDXGIDevice.\n"); wined3d_texture_decref(texture->wined3d_texture); wined3d_mutex_unlock(); return E_FAIL; } hr = IWineDXGIDevice_create_surface(wine_device, wined3d_texture_get_resource(texture->wined3d_texture), 0, NULL, (IUnknown *)&texture->ID3D10Texture2D_iface, (void **)&texture->dxgi_surface); IWineDXGIDevice_Release(wine_device); if (FAILED(hr)) { ERR("Failed to create DXGI surface, returning %#x\n", hr); texture->dxgi_surface = NULL; wined3d_texture_decref(texture->wined3d_texture); wined3d_mutex_unlock(); return hr; } } wined3d_mutex_unlock(); texture->device = &device->ID3D11Device_iface; ID3D11Device_AddRef(texture->device); return S_OK; }
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; }