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
)
51 if (This
->refs
&& This
->device
) /* Possible only if early exit after a ctor failed */
52 (void) NineUnknown_Release(NineUnknown(This
->device
));
57 NineUnknown_QueryInterface( struct NineUnknown
*This
,
63 DBG("This=%p riid=%p ppvObject=%p\n", This
, riid
, ppvObject
);
65 if (!ppvObject
) return E_POINTER
;
68 if (GUID_equal(This
->guids
[i
], riid
)) {
71 NineUnknown_AddRef(This
);
74 } while (This
->guids
[++i
]);
81 NineUnknown_AddRef( struct NineUnknown
*This
)
85 return NineUnknown_AddRef(This
->container
);
87 r
= p_atomic_inc_return(&This
->refs
);
91 NineUnknown_AddRef(NineUnknown(This
->device
));
92 /* This shouldn't be necessary:
94 NineUnknown_Bind(NineUnknown(This->container)); */
100 NineUnknown_Release( struct NineUnknown
*This
)
103 return NineUnknown_Release(This
->container
);
105 ULONG r
= p_atomic_dec_return(&This
->refs
);
109 if (NineUnknown_Release(NineUnknown(This
->device
)) == 0)
110 return r
; /* everything's gone */
112 if (This
->container
) {
113 /* NineUnknown_Unbind(NineUnknown(This->container)); */
115 if (This
->bind
== 0) {
123 NineUnknown_GetDevice( struct NineUnknown
*This
,
124 IDirect3DDevice9
**ppDevice
)
126 user_assert(ppDevice
, E_POINTER
);
127 NineUnknown_AddRef(NineUnknown(This
->device
));
128 *ppDevice
= (IDirect3DDevice9
*)This
->device
;