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_flags.h"
32 #include "nine_debug.h"
33 #include "nine_quirk.h"
42 /* pointer to vtable (can be overriden outside gallium nine) */
44 /* pointer to internal vtable */
45 void *vtable_internal
;
47 int32_t refs
; /* external reference count */
48 int32_t bind
; /* internal bind count */
49 boolean forward
; /* whether to forward references to the container */
51 struct NineUnknown
*container
; /* referenced if (refs | bind) */
52 struct NineDevice9
*device
; /* referenced if (refs) */
54 const GUID
**guids
; /* for QueryInterface */
56 void (*dtor
)(void *data
); /* top-level dtor */
58 static inline struct NineUnknown
*
59 NineUnknown( void *data
)
61 return (struct NineUnknown
*)data
;
64 /* Use this instead of a shitload of arguments: */
65 struct NineUnknownParams
69 void (*dtor
)(void *data
);
70 struct NineUnknown
*container
;
71 struct NineDevice9
*device
;
75 NineUnknown_ctor( struct NineUnknown
*This
,
76 struct NineUnknownParams
*pParams
);
79 NineUnknown_dtor( struct NineUnknown
*This
);
81 /*** Direct3D public methods ***/
84 NineUnknown_QueryInterface( struct NineUnknown
*This
,
89 NineUnknown_AddRef( struct NineUnknown
*This
);
92 NineUnknown_Release( struct NineUnknown
*This
);
95 NineUnknown_GetDevice( struct NineUnknown
*This
,
96 IDirect3DDevice9
**ppDevice
);
98 /*** Nine private methods ***/
101 NineUnknown_Destroy( struct NineUnknown
*This
)
103 assert(!(This
->refs
| This
->bind
));
108 NineUnknown_Bind( struct NineUnknown
*This
)
110 UINT b
= ++This
->bind
;
112 if (b
== 1 && This
->container
) {
113 if (This
->container
!= NineUnknown(This
->device
))
114 NineUnknown_Bind(This
->container
);
120 NineUnknown_Unbind( struct NineUnknown
*This
)
122 UINT b
= --This
->bind
;
124 if (This
->container
) {
125 if (This
->container
!= NineUnknown(This
->device
))
126 NineUnknown_Unbind(This
->container
);
128 if (This
->refs
== 0) {
136 NineUnknown_ConvertRefToBind( struct NineUnknown
*This
)
138 NineUnknown_Bind(This
);
139 NineUnknown_Release(This
);
142 /* Detach from container. */
144 NineUnknown_Detach( struct NineUnknown
*This
)
146 assert(This
->container
&& !This
->forward
);
148 NineUnknown_Unbind(This
->container
);
150 NineUnknown_Unbind(This
->container
);
151 This
->container
= NULL
;
152 if (!(This
->refs
| This
->bind
))
156 #endif /* _NINE_IUNKNOWN_H_ */