wined3d: Add a separate function for query initialization.

This commit is contained in:
Henri Verbeet 2010-01-17 21:31:30 +01:00 committed by Alexandre Julliard
parent bfb63a8634
commit a2624ae82e
3 changed files with 96 additions and 96 deletions

View File

@ -784,104 +784,33 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DDeviceImpl_CreateQuery(IWineD3DDevice *iface, WINED3DQUERYTYPE Type, IWineD3DQuery **ppQuery, IUnknown* parent) {
static HRESULT WINAPI IWineD3DDeviceImpl_CreateQuery(IWineD3DDevice *iface,
WINED3DQUERYTYPE type, IWineD3DQuery **query, IUnknown *parent)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
IWineD3DQueryImpl *object; /*NOTE: impl ref allowed since this is a create function */
HRESULT hr = WINED3DERR_NOTAVAILABLE;
const IWineD3DQueryVtbl *vtable;
IWineD3DQueryImpl *object;
HRESULT hr;
/* Just a check to see if we support this type of query */
switch(Type) {
case WINED3DQUERYTYPE_OCCLUSION:
TRACE("(%p) occlusion query\n", This);
if (gl_info->supported[ARB_OCCLUSION_QUERY])
hr = WINED3D_OK;
else
WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY/NV_OCCLUSION_QUERY\n");
TRACE("iface %p, type %#x, query %p, parent %p.\n", iface, type, query, parent);
vtable = &IWineD3DOcclusionQuery_Vtbl;
break;
case WINED3DQUERYTYPE_EVENT:
if (!gl_info->supported[NV_FENCE] && !gl_info->supported[APPLE_FENCE])
{
/* Half-Life 2 needs this query. It does not render the main menu correctly otherwise
* Pretend to support it, faking this query does not do much harm except potentially lowering performance
*/
FIXME("(%p) Event query: Unimplemented, but pretending to be supported\n", This);
}
vtable = &IWineD3DEventQuery_Vtbl;
hr = WINED3D_OK;
break;
case WINED3DQUERYTYPE_VCACHE:
case WINED3DQUERYTYPE_RESOURCEMANAGER:
case WINED3DQUERYTYPE_VERTEXSTATS:
case WINED3DQUERYTYPE_TIMESTAMP:
case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
case WINED3DQUERYTYPE_TIMESTAMPFREQ:
case WINED3DQUERYTYPE_PIPELINETIMINGS:
case WINED3DQUERYTYPE_INTERFACETIMINGS:
case WINED3DQUERYTYPE_VERTEXTIMINGS:
case WINED3DQUERYTYPE_PIXELTIMINGS:
case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
case WINED3DQUERYTYPE_CACHEUTILIZATION:
default:
/* Use the base Query vtable until we have a special one for each query */
vtable = &IWineD3DQuery_Vtbl;
FIXME("(%p) Unhandled query type %d\n", This, Type);
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
{
ERR("Failed to allocate query memory.\n");
return E_OUTOFMEMORY;
}
if(NULL == ppQuery || hr != WINED3D_OK) {
hr = query_init(object, This, type, parent);
if (FAILED(hr))
{
WARN("Failed to initialize query, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
return hr;
}
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if(!object)
{
ERR("Out of memory\n");
*ppQuery = NULL;
return WINED3DERR_OUTOFVIDEOMEMORY;
}
TRACE("Created query %p.\n", object);
*query = (IWineD3DQuery *)object;
object->lpVtbl = vtable;
object->type = Type;
object->state = QUERY_CREATED;
object->device = This;
object->parent = parent;
object->ref = 1;
*ppQuery = (IWineD3DQuery *)object;
/* allocated the 'extended' data based on the type of query requested */
switch(Type){
case WINED3DQUERYTYPE_OCCLUSION:
object->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_occlusion_query));
((struct wined3d_occlusion_query *)object->extendedData)->context = NULL;
break;
case WINED3DQUERYTYPE_EVENT:
object->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_event_query));
((struct wined3d_event_query *)object->extendedData)->context = NULL;
break;
case WINED3DQUERYTYPE_VCACHE:
case WINED3DQUERYTYPE_RESOURCEMANAGER:
case WINED3DQUERYTYPE_VERTEXSTATS:
case WINED3DQUERYTYPE_TIMESTAMP:
case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
case WINED3DQUERYTYPE_TIMESTAMPFREQ:
case WINED3DQUERYTYPE_PIPELINETIMINGS:
case WINED3DQUERYTYPE_INTERFACETIMINGS:
case WINED3DQUERYTYPE_VERTEXTIMINGS:
case WINED3DQUERYTYPE_PIXELTIMINGS:
case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
case WINED3DQUERYTYPE_CACHEUTILIZATION:
default:
object->extendedData = 0;
FIXME("(%p) Unhandled query type %d\n",This , Type);
}
TRACE("(%p) : Created Query %p\n", This, object);
return WINED3D_OK;
}

View File

@ -626,7 +626,7 @@ static HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIs
* IWineD3DQuery VTbl follows
**********************************************************/
const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
static const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
{
/*** IUnknown methods ***/
IWineD3DQueryImpl_QueryInterface,
@ -640,7 +640,7 @@ const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
IWineD3DQueryImpl_Issue
};
const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl =
static const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl =
{
/*** IUnknown methods ***/
IWineD3DQueryImpl_QueryInterface,
@ -654,7 +654,7 @@ const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl =
IWineD3DEventQueryImpl_Issue
};
const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
static const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
{
/*** IUnknown methods ***/
IWineD3DQueryImpl_QueryInterface,
@ -667,3 +667,75 @@ const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
IWineD3DQueryImpl_GetType,
IWineD3DOcclusionQueryImpl_Issue
};
HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
WINED3DQUERYTYPE type, IUnknown *parent)
{
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
switch (type)
{
case WINED3DQUERYTYPE_OCCLUSION:
TRACE("Occlusion query.\n");
if (!gl_info->supported[ARB_OCCLUSION_QUERY])
{
WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY/NV_OCCLUSION_QUERY\n");
return WINED3DERR_NOTAVAILABLE;
}
query->lpVtbl = &IWineD3DOcclusionQuery_Vtbl;
query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_occlusion_query));
if (!query->extendedData)
{
ERR("Failed to allocate occlusion query extended data.\n");
return E_OUTOFMEMORY;
}
((struct wined3d_occlusion_query *)query->extendedData)->context = NULL;
break;
case WINED3DQUERYTYPE_EVENT:
TRACE("Event query.\n");
if (!gl_info->supported[NV_FENCE] && !gl_info->supported[APPLE_FENCE])
{
/* Half-Life 2 needs this query. It does not render the main
* menu correctly otherwise. Pretend to support it, faking
* this query does not do much harm except potentially
* lowering performance. */
FIXME("Event query: Unimplemented, but pretending to be supported.\n");
}
query->lpVtbl = &IWineD3DEventQuery_Vtbl;
query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_event_query));
if (!query->extendedData)
{
ERR("Failed to allocate event query extended data.\n");
return E_OUTOFMEMORY;
}
((struct wined3d_event_query *)query->extendedData)->context = NULL;
break;
case WINED3DQUERYTYPE_VCACHE:
case WINED3DQUERYTYPE_RESOURCEMANAGER:
case WINED3DQUERYTYPE_VERTEXSTATS:
case WINED3DQUERYTYPE_TIMESTAMP:
case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
case WINED3DQUERYTYPE_TIMESTAMPFREQ:
case WINED3DQUERYTYPE_PIPELINETIMINGS:
case WINED3DQUERYTYPE_INTERFACETIMINGS:
case WINED3DQUERYTYPE_VERTEXTIMINGS:
case WINED3DQUERYTYPE_PIXELTIMINGS:
case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
case WINED3DQUERYTYPE_CACHEUTILIZATION:
default:
/* Use the base query vtable until we have a special one for each query. */
query->lpVtbl = &IWineD3DQuery_Vtbl;
FIXME("Unhandled query type %#x.\n", type);
return WINED3DERR_NOTAVAILABLE;
}
query->type = type;
query->state = QUERY_CREATED;
query->device = device;
query->parent = parent;
query->ref = 1;
return WINED3D_OK;
}

View File

@ -2347,9 +2347,8 @@ typedef struct IWineD3DQueryImpl
void *extendedData;
} IWineD3DQueryImpl;
extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl DECLSPEC_HIDDEN;
extern const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl DECLSPEC_HIDDEN;
extern const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl DECLSPEC_HIDDEN;
HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
WINED3DQUERYTYPE type, IUnknown *parent) DECLSPEC_HIDDEN;
/* IWineD3DBuffer */