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_atomic.h"
29 #include "util/u_memory.h"
32 #include "nine_flags.h"
33 #include "nine_debug.h"
34 #include "nine_quirk.h"
43 /* pointer to vtable (can be overriden outside gallium nine) */
45 /* pointer to internal vtable */
46 void *vtable_internal
;
48 int32_t refs
; /* external reference count */
49 int32_t bind
; /* internal bind count */
50 boolean forward
; /* whether to forward references to the container */
52 /* container: for surfaces and volumes only.
53 * Can be a texture, a volume texture or a swapchain.
54 * forward is set to false for the swapchain case.
55 * If forward is set, refs are passed to the container if forward is set
56 * and the container has bind increased if the object has non null bind. */
57 struct NineUnknown
*container
;
58 struct NineDevice9
*device
; /* referenced if (refs) */
60 const GUID
**guids
; /* for QueryInterface */
62 /* for [GS]etPrivateData/FreePrivateData */
63 struct hash_table
*pdata
;
65 void (*dtor
)(void *data
); /* top-level dtor */
67 static inline struct NineUnknown
*
68 NineUnknown( void *data
)
70 return (struct NineUnknown
*)data
;
73 /* Use this instead of a shitload of arguments: */
74 struct NineUnknownParams
78 void (*dtor
)(void *data
);
79 struct NineUnknown
*container
;
80 struct NineDevice9
*device
;
81 bool start_with_bind_not_ref
;
85 NineUnknown_ctor( struct NineUnknown
*This
,
86 struct NineUnknownParams
*pParams
);
89 NineUnknown_dtor( struct NineUnknown
*This
);
91 /*** Direct3D public methods ***/
94 NineUnknown_QueryInterface( struct NineUnknown
*This
,
99 NineUnknown_AddRef( struct NineUnknown
*This
);
102 NineUnknown_Release( struct NineUnknown
*This
);
105 NineUnknown_ReleaseWithDtorLock( struct NineUnknown
*This
);
108 NineUnknown_GetDevice( struct NineUnknown
*This
,
109 IDirect3DDevice9
**ppDevice
);
112 NineUnknown_SetPrivateData( struct NineUnknown
*This
,
119 NineUnknown_GetPrivateData( struct NineUnknown
*This
,
122 DWORD
*pSizeOfData
);
125 NineUnknown_FreePrivateData( struct NineUnknown
*This
,
128 /*** Nine private methods ***/
131 NineUnknown_Destroy( struct NineUnknown
*This
)
133 assert(!(This
->refs
| This
->bind
));
138 NineUnknown_Bind( struct NineUnknown
*This
)
140 UINT b
= p_atomic_inc_return(&This
->bind
);
143 if (b
== 1 && This
->forward
)
144 NineUnknown_Bind(This
->container
);
150 NineUnknown_Unbind( struct NineUnknown
*This
)
152 UINT b
= p_atomic_dec_return(&This
->bind
);
154 if (b
== 0 && This
->forward
)
155 NineUnknown_Unbind(This
->container
);
156 else if (b
== 0 && This
->refs
== 0 && !This
->container
)
163 NineUnknown_ConvertRefToBind( struct NineUnknown
*This
)
165 NineUnknown_Bind(This
);
166 NineUnknown_Release(This
);
169 /* Detach from container. */
171 NineUnknown_Detach( struct NineUnknown
*This
)
173 assert(This
->container
&& !This
->forward
);
175 This
->container
= NULL
;
176 if (!(This
->refs
| This
->bind
))
180 #endif /* _NINE_IUNKNOWN_H_ */