static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) { IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)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) IDirect3DDevice9Ex_AddRef(This->parentDevice); wined3d_mutex_lock(); IWineD3DSurface_AddRef(This->wineD3DSurface); wined3d_mutex_unlock(); } return ref; } }
HRESULT WINAPI IWineD3DBaseSwapChainImpl_PresentRt(IWineD3DSwapChain* iface, IWineD3DSurface* surf) { IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl*)iface; IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)surf; if (This->presentRt != surf) { if (surf) { IWineD3DSurface_AddRef(surf); if (surface->presentSwapchain) { ERR("not expected"); Assert(surface->presentSwapchain != iface); IWineD3DBaseSwapChainImpl_PresentRt(surface->presentSwapchain, NULL); } surface->presentSwapchain = iface; } if (This->presentRt) { IWineD3DSurfaceImpl *old = (IWineD3DSurfaceImpl*)This->presentRt; Assert(old->presentSwapchain == iface); old->presentSwapchain = NULL; IWineD3DSurface_Release(This->presentRt); } This->presentRt = surf; } if (surf) return IWineD3DBaseSwapChainImpl_PresentRtPerform(This); return S_OK; }
HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetBackBuffer(IWineD3DSwapChain *iface, UINT back_buffer_idx, WINED3DBACKBUFFER_TYPE type, IWineD3DSurface **back_buffer) { IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)iface; TRACE("iface %p, back_buffer_idx %u, type %#x, back_buffer %p.\n", iface, back_buffer_idx, type, back_buffer); /* Return invalid if there is no backbuffer array, otherwise it will * crash when ddraw is used (there swapchain->back_buffers is always NULL). * We need this because this function is called from * IWineD3DStateBlockImpl_InitStartupStateBlock() to get the default * scissorrect dimensions. */ if (!swapchain->back_buffers || back_buffer_idx >= swapchain->presentParms.BackBufferCount) { WARN("Invalid back buffer index.\n"); /* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it * here in wined3d to avoid problems in other libs. */ *back_buffer = NULL; return WINED3DERR_INVALIDCALL; } *back_buffer = (IWineD3DSurface *)swapchain->back_buffers[back_buffer_idx]; if (*back_buffer) IWineD3DSurface_AddRef(*back_buffer); TRACE("Returning back buffer %p.\n", *back_buffer); return WINED3D_OK; }
static ULONG STDMETHODCALLTYPE d3d10_texture2d_AddRef(ID3D10Texture2D *iface) { struct d3d10_texture2d *This = (struct d3d10_texture2d *)iface; ULONG refcount = InterlockedIncrement(&This->refcount); TRACE("%p increasing refcount to %u\n", This, refcount); if (refcount == 1 && This->wined3d_surface) IWineD3DSurface_AddRef(This->wined3d_surface); return refcount; }
static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) { IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface; HRESULT hr = WINED3DERR_INVALIDCALL; if (Level < This->baseTexture.levels) { *ppSurfaceLevel = This->surfaces[Level]; IWineD3DSurface_AddRef(This->surfaces[Level]); hr = WINED3D_OK; TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level); } if (WINED3D_OK != hr) { WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels); *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */ } return hr; }
static HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT sub_resource_idx, IWineD3DSurface **surface) { IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl *)iface; IWineD3DSurface *s; TRACE("iface %p, sub_resource_idx %u, surface %p.\n", iface, sub_resource_idx, surface); if (!(s = (IWineD3DSurface *)basetexture_get_sub_resource(texture, sub_resource_idx))) { WARN("Failed to get sub-resource.\n"); return WINED3DERR_INVALIDCALL; } IWineD3DSurface_AddRef(s); *surface = s; TRACE("Returning surface %p.\n", *surface); return WINED3D_OK; }