Path: blob/21.2-virgl/src/gallium/frontends/nine/iunknown.h
4561 views
/*1* Copyright 2011 Joakim Sindholt <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122#ifndef _NINE_IUNKNOWN_H_23#define _NINE_IUNKNOWN_H_2425#include "pipe/p_compiler.h"2627#include "util/u_atomic.h"28#include "util/u_memory.h"2930#include "guid.h"31#include "nine_flags.h"32#include "nine_debug.h"33#include "nine_quirk.h"3435#include "d3d9.h"3637struct Nine9;38struct NineDevice9;3940struct NineUnknown41{42/* pointer to vtable (can be overriden outside gallium nine) */43void *vtable;44/* pointer to internal vtable */45void *vtable_internal;4647int32_t refs; /* external reference count */48int32_t bind; /* internal bind count */49boolean forward; /* whether to forward references to the container */5051/* container: for surfaces and volumes only.52* Can be a texture, a volume texture or a swapchain.53* forward is set to false for the swapchain case.54* If forward is set, refs are passed to the container if forward is set55* and the container has bind increased if the object has non null bind. */56struct NineUnknown *container;57struct NineDevice9 *device; /* referenced if (refs) */5859const GUID **guids; /* for QueryInterface */6061/* for [GS]etPrivateData/FreePrivateData */62struct hash_table *pdata;6364void (*dtor)(void *data); /* top-level dtor */65};66static inline struct NineUnknown *67NineUnknown( void *data )68{69return (struct NineUnknown *)data;70}7172/* Use this instead of a shitload of arguments: */73struct NineUnknownParams74{75void *vtable;76const GUID **guids;77void (*dtor)(void *data);78struct NineUnknown *container;79struct NineDevice9 *device;80bool start_with_bind_not_ref;81};8283HRESULT84NineUnknown_ctor( struct NineUnknown *This,85struct NineUnknownParams *pParams );8687void88NineUnknown_dtor( struct NineUnknown *This );8990/*** Direct3D public methods ***/9192HRESULT NINE_WINAPI93NineUnknown_QueryInterface( struct NineUnknown *This,94REFIID riid,95void **ppvObject );9697ULONG NINE_WINAPI98NineUnknown_AddRef( struct NineUnknown *This );99100ULONG NINE_WINAPI101NineUnknown_Release( struct NineUnknown *This );102103ULONG NINE_WINAPI104NineUnknown_ReleaseWithDtorLock( struct NineUnknown *This );105106HRESULT NINE_WINAPI107NineUnknown_GetDevice( struct NineUnknown *This,108IDirect3DDevice9 **ppDevice );109110HRESULT NINE_WINAPI111NineUnknown_SetPrivateData( struct NineUnknown *This,112REFGUID refguid,113const void *pData,114DWORD SizeOfData,115DWORD Flags );116117HRESULT NINE_WINAPI118NineUnknown_GetPrivateData( struct NineUnknown *This,119REFGUID refguid,120void *pData,121DWORD *pSizeOfData );122123HRESULT NINE_WINAPI124NineUnknown_FreePrivateData( struct NineUnknown *This,125REFGUID refguid );126127/*** Nine private methods ***/128129static inline void130NineUnknown_Destroy( struct NineUnknown *This )131{132assert(!(This->refs | This->bind));133This->dtor(This);134}135136static inline UINT137NineUnknown_Bind( struct NineUnknown *This )138{139UINT b = p_atomic_inc_return(&This->bind);140assert(b);141142if (b == 1 && This->forward)143NineUnknown_Bind(This->container);144145return b;146}147148static inline UINT149NineUnknown_Unbind( struct NineUnknown *This )150{151UINT b = p_atomic_dec_return(&This->bind);152153if (b == 0 && This->forward)154NineUnknown_Unbind(This->container);155else if (b == 0 && This->refs == 0 && !This->container)156This->dtor(This);157158return b;159}160161static inline void162NineUnknown_ConvertRefToBind( struct NineUnknown *This )163{164NineUnknown_Bind(This);165NineUnknown_Release(This);166}167168/* Detach from container. */169static inline void170NineUnknown_Detach( struct NineUnknown *This )171{172assert(This->container && !This->forward);173174This->container = NULL;175if (!(This->refs | This->bind))176This->dtor(This);177}178179#endif /* _NINE_IUNKNOWN_H_ */180181182