2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 #ifndef _NINE_IUNKNOWN_H_
24 #define _NINE_IUNKNOWN_H_
26 #include "pipe/p_compiler.h"
28 #include "util/u_memory.h"
31 #include "nine_debug.h"
32 #include "nine_quirk.h"
41 /* pointer to vtable */
44 int32_t refs
; /* external reference count */
45 int32_t bind
; /* internal bind count */
46 boolean forward
; /* whether to forward references to the container */
48 struct NineUnknown
*container
; /* referenced if (refs | bind) */
49 struct NineDevice9
*device
; /* referenced if (refs) */
51 const GUID
**guids
; /* for QueryInterface */
53 void (*dtor
)(void *data
); /* top-level dtor */
55 static INLINE
struct NineUnknown
*
56 NineUnknown( void *data
)
58 return (struct NineUnknown
*)data
;
61 /* Use this instead of a shitload of arguments: */
62 struct NineUnknownParams
66 void (*dtor
)(void *data
);
67 struct NineUnknown
*container
;
68 struct NineDevice9
*device
;
72 NineUnknown_ctor( struct NineUnknown
*This
,
73 struct NineUnknownParams
*pParams
);
76 NineUnknown_dtor( struct NineUnknown
*This
);
78 /*** Direct3D public methods ***/
81 NineUnknown_QueryInterface( struct NineUnknown
*This
,
86 NineUnknown_AddRef( struct NineUnknown
*This
);
89 NineUnknown_Release( struct NineUnknown
*This
);
92 NineUnknown_GetDevice( struct NineUnknown
*This
,
93 IDirect3DDevice9
**ppDevice
);
95 /*** Nine private methods ***/
98 NineUnknown_Destroy( struct NineUnknown
*This
)
100 assert(!(This
->refs
| This
->bind
));
105 NineUnknown_Bind( struct NineUnknown
*This
)
107 UINT b
= ++This
->bind
;
109 if (b
== 1 && This
->container
) {
110 if (This
->container
!= NineUnknown(This
->device
))
111 NineUnknown_Bind(This
->container
);
117 NineUnknown_Unbind( struct NineUnknown
*This
)
119 UINT b
= --This
->bind
;
121 if (This
->container
) {
122 if (This
->container
!= NineUnknown(This
->device
))
123 NineUnknown_Unbind(This
->container
);
125 if (This
->refs
== 0) {
133 NineUnknown_ConvertRefToBind( struct NineUnknown
*This
)
135 NineUnknown_Bind(This
);
136 NineUnknown_Release(This
);
139 /* Detach from container. */
141 NineUnknown_Detach( struct NineUnknown
*This
)
143 assert(This
->container
&& !This
->forward
);
145 NineUnknown_Unbind(This
->container
);
147 NineUnknown_Unbind(This
->container
);
148 This
->container
= NULL
;
149 if (!(This
->refs
| This
->bind
))
153 #endif /* _NINE_IUNKNOWN_H_ */