static HRESULT WINAPI d3d8_surface_FreePrivateData(IDirect3DSurface8 *iface, REFGUID guid) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); return d3d8_resource_free_private_data(&surface->resource, guid); }
/* IDirect3DSurface8 IDirect3DResource8 Interface follow: */ static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, device %p.\n", iface, device); if (This->forwardReference) { IDirect3DResource8 *resource; HRESULT hr; hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource8, (void **)&resource); if (SUCCEEDED(hr)) { hr = IDirect3DResource8_GetDevice(resource, device); IDirect3DResource8_Release(resource); TRACE("Returning device %p.\n", *device); } return hr; } *device = This->parentDevice; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static ULONG WINAPI d3d8_surface_AddRef(IDirect3DSurface8 *iface) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); TRACE("iface %p.\n", iface); if (surface->forwardReference) { /* Forward refcounting */ TRACE("Forwarding to %p.\n", surface->forwardReference); return IUnknown_AddRef(surface->forwardReference); } else { /* No container, handle our own refcounting */ ULONG ref = InterlockedIncrement(&surface->resource.refcount); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { if (surface->parent_device) IDirect3DDevice8_AddRef(surface->parent_device); wined3d_mutex_lock(); wined3d_surface_incref(surface->wined3d_surface); wined3d_mutex_unlock(); } return ref; } }
static ULONG WINAPI d3d8_surface_Release(IDirect3DSurface8 *iface) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); TRACE("iface %p.\n", iface); if (surface->forwardReference) { /* Forward refcounting */ TRACE("Forwarding to %p.\n", surface->forwardReference); return IUnknown_Release(surface->forwardReference); } else { /* No container, handle our own refcounting */ ULONG ref = InterlockedDecrement(&surface->resource.refcount); TRACE("%p decreasing refcount to %u.\n", iface, ref); if (!ref) { IDirect3DDevice8 *parent_device = surface->parent_device; /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */ wined3d_mutex_lock(); wined3d_surface_decref(surface->wined3d_surface); wined3d_mutex_unlock(); if (parent_device) IDirect3DDevice8_Release(parent_device); } return ref; } }
static ULONG WINAPI IDirect3DSurface8Impl_AddRef(IDirect3DSurface8 *iface) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); TRACE("iface %p.\n", iface); if (This->forwardReference) { /* Forward refcounting */ TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference); return IUnknown_AddRef(This->forwardReference); } else { /* No container, handle our own refcounting */ ULONG ref = InterlockedIncrement(&This->ref); TRACE("%p increasing refcount to %u.\n", iface, ref); if (ref == 1) { if (This->parentDevice) IUnknown_AddRef(This->parentDevice); wined3d_mutex_lock(); wined3d_surface_incref(This->wined3d_surface); wined3d_mutex_unlock(); } return ref; } }
static ULONG WINAPI IDirect3DSurface8Impl_Release(IDirect3DSurface8 *iface) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); TRACE("iface %p.\n", iface); if (This->forwardReference) { /* Forward refcounting */ TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference); return IUnknown_Release(This->forwardReference); } else { /* No container, handle our own refcounting */ ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u.\n", iface, ref); if (ref == 0) { IDirect3DDevice8 *parentDevice = This->parentDevice; /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */ wined3d_mutex_lock(); wined3d_surface_decref(This->wined3d_surface); wined3d_mutex_unlock(); if (parentDevice) IDirect3DDevice8_Release(parentDevice); } return ref; } }
static ULONG WINAPI d3d8_surface_AddRef(IDirect3DSurface8 *iface) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); ULONG refcount; TRACE("iface %p.\n", iface); if (surface->texture) { TRACE("Forwarding to %p.\n", surface->texture); return IDirect3DBaseTexture8_AddRef(&surface->texture->IDirect3DBaseTexture8_iface); } refcount = InterlockedIncrement(&surface->resource.refcount); TRACE("%p increasing refcount to %u.\n", iface, refcount); if (refcount == 1) { if (surface->parent_device) IDirect3DDevice8_AddRef(surface->parent_device); wined3d_mutex_lock(); if (surface->wined3d_rtv) wined3d_rendertarget_view_incref(surface->wined3d_rtv); wined3d_texture_incref(surface->wined3d_texture); wined3d_mutex_unlock(); } return refcount; }
static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(IDirect3DSurface8 *iface, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); HRESULT hr; TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags); wined3d_mutex_lock(); if (pRect) { D3DSURFACE_DESC desc; IDirect3DSurface8_GetDesc(iface, &desc); if ((pRect->left < 0) || (pRect->top < 0) || (pRect->left >= pRect->right) || (pRect->top >= pRect->bottom) || (pRect->right > desc.Width) || (pRect->bottom > desc.Height)) { WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n"); wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; } } hr = wined3d_surface_map(This->wined3d_surface, (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags); wined3d_mutex_unlock(); return hr; }
struct d3d8_surface *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface) { if (!iface) return NULL; assert(iface->lpVtbl == &d3d8_surface_vtbl); return impl_from_IDirect3DSurface8(iface); }
IDirect3DSurface8Impl *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface) { if (!iface) return NULL; assert(iface->lpVtbl == &Direct3DSurface8_Vtbl); return impl_from_IDirect3DSurface8(iface); }
static HRESULT WINAPI d3d8_surface_GetPrivateData(IDirect3DSurface8 *iface, REFGUID guid, void *data, DWORD *data_size) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, guid %s, data %p, data_size %p.\n", iface, debugstr_guid(guid), data, data_size); return d3d8_resource_get_private_data(&surface->resource, guid, data, data_size); }
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; TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n", iface, locked_rect, wine_dbgstr_rect(rect), flags); wined3d_mutex_lock(); if (rect) { D3DSURFACE_DESC desc; IDirect3DSurface8_GetDesc(iface, &desc); if ((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(); return D3DERR_INVALIDCALL; } box.left = rect->left; box.top = rect->top; box.right = rect->right; box.bottom = rect->bottom; box.front = 0; box.back = 1; } hr = wined3d_texture_map(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; } else { locked_rect->Pitch = 0; locked_rect->pBits = NULL; } return hr; }
static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(IDirect3DSurface8 *iface, REFGUID guid) { IDirect3DSurface8Impl *surface = impl_from_IDirect3DSurface8(iface); struct wined3d_resource *resource; HRESULT hr; TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid)); wined3d_mutex_lock(); resource = wined3d_surface_get_resource(surface->wined3d_surface); hr = wined3d_resource_free_private_data(resource, guid); wined3d_mutex_unlock(); return hr; }
/* IDirect3DSurface8 Interface follow: */ static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(IDirect3DSurface8 *iface, REFIID riid, void **ppContainer) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); HRESULT res; TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer); if (!This->container) return E_NOINTERFACE; res = IUnknown_QueryInterface(This->container, riid, ppContainer); TRACE("(%p) : returning %p\n", This, *ppContainer); return res; }
static HRESULT WINAPI d3d8_surface_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, device %p.\n", iface, device); if (surface->texture) return IDirect3DBaseTexture8_GetDevice(&surface->texture->IDirect3DBaseTexture8_iface, device); *device = surface->parent_device; IDirect3DDevice8_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d8_surface_GetContainer(IDirect3DSurface8 *iface, REFIID riid, void **container) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); HRESULT hr; TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), container); if (!surface->container) return E_NOINTERFACE; hr = IUnknown_QueryInterface(surface->container, riid, container); TRACE("Returning %p.\n", *container); return hr; }
static HRESULT WINAPI d3d8_surface_SetPrivateData(IDirect3DSurface8 *iface, REFGUID guid, const void *data, DWORD data_size, DWORD flags) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(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_surface_get_resource(surface->wined3d_surface); hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags); wined3d_mutex_unlock(); 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_texture_unmap(surface->wined3d_texture, surface->sub_resource_idx); wined3d_mutex_unlock(); switch(hr) { case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL; default: return hr; } }
static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(IDirect3DSurface8 *iface, REFGUID guid, void *data, DWORD *data_size) { IDirect3DSurface8Impl *surface = impl_from_IDirect3DSurface8(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_surface_get_resource(surface->wined3d_surface); hr = wined3d_resource_get_private_data(resource, guid, data, data_size); wined3d_mutex_unlock(); return hr; }
static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(IDirect3DSurface8 *iface) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); HRESULT hr; TRACE("iface %p.\n", iface); wined3d_mutex_lock(); hr = wined3d_surface_unmap(This->wined3d_surface); wined3d_mutex_unlock(); switch(hr) { case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL; default: return hr; } }
/* IDirect3DSurface8 IUnknown parts follow: */ static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(IDirect3DSurface8 *iface, REFIID riid, void **ppobj) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj); if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDirect3DResource8) || IsEqualGUID(riid, &IID_IDirect3DSurface8)) { IUnknown_AddRef(iface); *ppobj = This; return S_OK; } WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj); *ppobj = NULL; return E_NOINTERFACE; }
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 HRESULT WINAPI d3d8_surface_GetDesc(IDirect3DSurface8 *iface, D3DSURFACE_DESC *desc) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); struct wined3d_sub_resource_desc wined3d_desc; TRACE("iface %p, desc %p.\n", iface, desc); wined3d_mutex_lock(); wined3d_texture_get_sub_resource_desc(surface->wined3d_texture, surface->sub_resource_idx, &wined3d_desc); wined3d_mutex_unlock(); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = D3DRTYPE_SURFACE; desc->Usage = d3dusage_from_wined3dusage(wined3d_desc.usage, wined3d_desc.bind_flags); desc->Pool = d3dpool_from_wined3daccess(wined3d_desc.access, wined3d_desc.usage); desc->Size = wined3d_desc.size; desc->MultiSampleType = wined3d_desc.multisample_type; desc->Width = wined3d_desc.width; desc->Height = wined3d_desc.height; return D3D_OK; }
static ULONG WINAPI d3d8_surface_Release(IDirect3DSurface8 *iface) { struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface); ULONG refcount; TRACE("iface %p.\n", iface); if (surface->texture) { TRACE("Forwarding to %p.\n", surface->texture); return IDirect3DBaseTexture8_Release(&surface->texture->IDirect3DBaseTexture8_iface); } if (!surface->resource.refcount) { WARN("Surface does not have any references.\n"); return 0; } refcount = InterlockedDecrement(&surface->resource.refcount); TRACE("%p decreasing refcount to %u.\n", iface, refcount); if (!refcount) { IDirect3DDevice8 *parent_device = surface->parent_device; wined3d_mutex_lock(); if (surface->wined3d_rtv) wined3d_rendertarget_view_decref(surface->wined3d_rtv); wined3d_texture_decref(surface->wined3d_texture); wined3d_mutex_unlock(); if (parent_device) IDirect3DDevice8_Release(parent_device); } return refcount; }
static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(IDirect3DSurface8 *iface, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); 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); wined3d_mutex_lock(); if (rect) { D3DSURFACE_DESC desc; IDirect3DSurface8_GetDesc(iface, &desc); if ((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(); return D3DERR_INVALIDCALL; } } hr = wined3d_surface_map(This->wined3d_surface, &map_desc, rect, flags); wined3d_mutex_unlock(); locked_rect->Pitch = map_desc.row_pitch; locked_rect->pBits = map_desc.data; return hr; }
static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(IDirect3DSurface8 *iface, D3DSURFACE_DESC *desc) { IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface); struct wined3d_resource_desc wined3d_desc; struct wined3d_resource *wined3d_resource; TRACE("iface %p, desc %p.\n", iface, desc); wined3d_mutex_lock(); wined3d_resource = wined3d_surface_get_resource(This->wined3d_surface); wined3d_resource_get_desc(wined3d_resource, &wined3d_desc); wined3d_mutex_unlock(); desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format); desc->Type = wined3d_desc.resource_type; desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK; desc->Pool = wined3d_desc.pool; desc->Size = wined3d_desc.size; desc->MultiSampleType = wined3d_desc.multisample_type; desc->Width = wined3d_desc.width; desc->Height = wined3d_desc.height; return D3D_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; }