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. */
24 #include "util/u_atomic.h"
25 #include "nine_helpers.h"
27 #define DBG_CHANNEL DBG_UNKNOWN
30 NineUnknown_ctor( struct NineUnknown
*This
,
31 struct NineUnknownParams
*pParams
)
33 This
->refs
= pParams
->container
? 0 : 1;
35 This
->forward
= !This
->refs
;
36 This
->container
= pParams
->container
;
37 This
->device
= pParams
->device
;
38 if (This
->refs
&& This
->device
)
39 NineUnknown_AddRef(NineUnknown(This
->device
));
41 This
->vtable
= pParams
->vtable
;
42 This
->guids
= pParams
->guids
;
43 This
->dtor
= pParams
->dtor
;
49 NineUnknown_dtor( struct NineUnknown
*This
)
55 NineUnknown_QueryInterface( struct NineUnknown
*This
,
61 DBG("This=%p riid=%p ppvObject=%p\n", This
, riid
, ppvObject
);
63 if (!ppvObject
) return E_POINTER
;
66 if (GUID_equal(This
->guids
[i
], riid
)) {
69 NineUnknown_AddRef(This
);
72 } while (This
->guids
[++i
]);
79 NineUnknown_AddRef( struct NineUnknown
*This
)
83 return NineUnknown_AddRef(This
->container
);
85 r
= p_atomic_inc_return(&This
->refs
);
89 NineUnknown_AddRef(NineUnknown(This
->device
));
90 /* This shouldn't be necessary:
92 NineUnknown_Bind(NineUnknown(This->container)); */
98 NineUnknown_Release( struct NineUnknown
*This
)
101 return NineUnknown_Release(This
->container
);
103 ULONG r
= p_atomic_dec_return(&This
->refs
);
107 if (NineUnknown_Release(NineUnknown(This
->device
)) == 0)
108 return r
; /* everything's gone */
110 if (This
->container
) {
111 /* NineUnknown_Unbind(NineUnknown(This->container)); */
113 if (This
->bind
== 0) {
121 NineUnknown_GetDevice( struct NineUnknown
*This
,
122 IDirect3DDevice9
**ppDevice
)
124 user_assert(ppDevice
, E_POINTER
);
125 NineUnknown_AddRef(NineUnknown(This
->device
));
126 *ppDevice
= (IDirect3DDevice9
*)This
->device
;