query.c revision a3133ef29cdf3656735d569fd64e54c9286effc0
af062818b47340eef15700d2f0211576ba3506eevboxsync/*
af062818b47340eef15700d2f0211576ba3506eevboxsync * IDirect3DQuery9 implementation
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright 2002-2003 Raphael Junqueira
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright 2002-2003 Jason Edmeades
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright 2005 Oliver Stieber
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * This library is free software; you can redistribute it and/or
af062818b47340eef15700d2f0211576ba3506eevboxsync * modify it under the terms of the GNU Lesser General Public
af062818b47340eef15700d2f0211576ba3506eevboxsync * License as published by the Free Software Foundation; either
af062818b47340eef15700d2f0211576ba3506eevboxsync * version 2.1 of the License, or (at your option) any later version.
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * This library is distributed in the hope that it will be useful,
af062818b47340eef15700d2f0211576ba3506eevboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
af062818b47340eef15700d2f0211576ba3506eevboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * Lesser General Public License for more details.
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * You should have received a copy of the GNU Lesser General Public
af062818b47340eef15700d2f0211576ba3506eevboxsync * License along with this library; if not, write to the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
af062818b47340eef15700d2f0211576ba3506eevboxsync */
af062818b47340eef15700d2f0211576ba3506eevboxsync
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync/*
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * other than GPL or LGPL is available it will apply instead, Sun elects to use only
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * a choice of LGPL license versions is made available with the language indicating
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * of the LGPL is applied is otherwise unspecified.
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync */
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync#include "config.h"
af062818b47340eef15700d2f0211576ba3506eevboxsync#include "d3d9_private.h"
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncWINE_DEFAULT_DEBUG_CHANNEL(d3d9);
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync/* IDirect3DQuery9 IUnknown parts follow: */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IDirect3DQuery9Impl_QueryInterface(LPDIRECT3DQUERY9 iface, REFIID riid, LPVOID* ppobj) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) Relay\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync if (IsEqualGUID(riid, &IID_IUnknown)
af062818b47340eef15700d2f0211576ba3506eevboxsync || IsEqualGUID(riid, &IID_IDirect3DQuery9)) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9_AddRef(iface);
af062818b47340eef15700d2f0211576ba3506eevboxsync *ppobj = This;
af062818b47340eef15700d2f0211576ba3506eevboxsync return S_OK;
af062818b47340eef15700d2f0211576ba3506eevboxsync }
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
af062818b47340eef15700d2f0211576ba3506eevboxsync *ppobj = NULL;
af062818b47340eef15700d2f0211576ba3506eevboxsync return E_NOINTERFACE;
af062818b47340eef15700d2f0211576ba3506eevboxsync}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic ULONG WINAPI IDirect3DQuery9Impl_AddRef(LPDIRECT3DQUERY9 iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync ULONG ref = InterlockedIncrement(&This->ref);
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : AddRef from %d\n", This, ref - 1);
af062818b47340eef15700d2f0211576ba3506eevboxsync return ref;
af062818b47340eef15700d2f0211576ba3506eevboxsync}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic ULONG WINAPI IDirect3DQuery9Impl_Release(LPDIRECT3DQUERY9 iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync ULONG ref = InterlockedDecrement(&This->ref);
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : ReleaseRef to %d\n", This, ref);
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync if (ref == 0) {
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_lock();
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQuery_Release(This->wineD3DQuery);
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_unlock();
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DDevice9Ex_Release(This->parentDevice);
af062818b47340eef15700d2f0211576ba3506eevboxsync HeapFree(GetProcessHeap(), 0, This);
af062818b47340eef15700d2f0211576ba3506eevboxsync }
af062818b47340eef15700d2f0211576ba3506eevboxsync return ref;
af062818b47340eef15700d2f0211576ba3506eevboxsync}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync/* IDirect3DQuery9 Interface follow: */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(LPDIRECT3DQUERY9 iface, IDirect3DDevice9** ppDevice) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DDevice* pDevice;
af062818b47340eef15700d2f0211576ba3506eevboxsync HRESULT hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) Relay\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_lock();
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
af062818b47340eef15700d2f0211576ba3506eevboxsync if(hr != D3D_OK){
af062818b47340eef15700d2f0211576ba3506eevboxsync *ppDevice = NULL;
af062818b47340eef15700d2f0211576ba3506eevboxsync }else{
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DDevice_GetParent(pDevice, (IUnknown **)ppDevice);
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DDevice_Release(pDevice);
af062818b47340eef15700d2f0211576ba3506eevboxsync }
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_unlock();
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync return hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync HRESULT hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) Relay\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_lock();
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DQuery_GetType(This->wineD3DQuery);
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_unlock();
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync return hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync DWORD ret;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) Relay\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_lock();
af062818b47340eef15700d2f0211576ba3506eevboxsync ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_unlock();
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync return ret;
af062818b47340eef15700d2f0211576ba3506eevboxsync}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync HRESULT hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) Relay\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_lock();
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_unlock();
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync return hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync HRESULT hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) Relay\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_lock();
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_unlock();
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync return hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
af062818b47340eef15700d2f0211576ba3506eevboxsync{
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl_QueryInterface,
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl_AddRef,
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl_Release,
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl_GetDevice,
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl_GetType,
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl_GetDataSize,
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl_Issue,
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl_GetData
af062818b47340eef15700d2f0211576ba3506eevboxsync};
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync/* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */
af062818b47340eef15700d2f0211576ba3506eevboxsyncHRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DQuery9Impl *object = NULL;
af062818b47340eef15700d2f0211576ba3506eevboxsync HRESULT hr = D3D_OK;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) Relay\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync if (!ppQuery)
af062818b47340eef15700d2f0211576ba3506eevboxsync {
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_lock();
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_unlock();
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync return hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync }
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Allocate the storage for the device */
af062818b47340eef15700d2f0211576ba3506eevboxsync object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl));
af062818b47340eef15700d2f0211576ba3506eevboxsync if (NULL == object) {
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
af062818b47340eef15700d2f0211576ba3506eevboxsync return D3DERR_OUTOFVIDEOMEMORY;
af062818b47340eef15700d2f0211576ba3506eevboxsync }
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync object->lpVtbl = &Direct3DQuery9_Vtbl;
af062818b47340eef15700d2f0211576ba3506eevboxsync object->ref = 1;
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_lock();
af062818b47340eef15700d2f0211576ba3506eevboxsync hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);
a3133ef29cdf3656735d569fd64e54c9286effc0vboxsync wined3d_mutex_unlock();
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync if (FAILED(hr)) {
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync /* free up object */
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync WARN("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync HeapFree(GetProcessHeap(), 0, object);
af062818b47340eef15700d2f0211576ba3506eevboxsync } else {
af062818b47340eef15700d2f0211576ba3506eevboxsync IDirect3DDevice9Ex_AddRef(iface);
af062818b47340eef15700d2f0211576ba3506eevboxsync object->parentDevice = iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync *ppQuery = (LPDIRECT3DQUERY9) object;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : Created query %p\n", This , object);
af062818b47340eef15700d2f0211576ba3506eevboxsync }
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : returning %x\n", This, hr);
af062818b47340eef15700d2f0211576ba3506eevboxsync return hr;
af062818b47340eef15700d2f0211576ba3506eevboxsync}