setupapi: Added tests for SetupDiGetINFClassA.
[wine] / dlls / d3dcompiler_43 / blob.c
1 /*
2  * Direct3D blob file
3  *
4  * Copyright 2010 Rico Schüller
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include "d3dcompiler_private.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
29
30 /* IUnknown methods */
31
32 static HRESULT STDMETHODCALLTYPE d3dcompiler_blob_QueryInterface(ID3DBlob *iface, REFIID riid, void **object)
33 {
34     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
35
36     if (IsEqualGUID(riid, &IID_ID3D10Blob)
37             || IsEqualGUID(riid, &IID_IUnknown))
38     {
39         IUnknown_AddRef(iface);
40         *object = iface;
41         return S_OK;
42     }
43
44     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
45
46     *object = NULL;
47     return E_NOINTERFACE;
48 }
49
50 static ULONG STDMETHODCALLTYPE d3dcompiler_blob_AddRef(ID3DBlob *iface)
51 {
52     struct d3dcompiler_blob *blob = (struct d3dcompiler_blob *)iface;
53     ULONG refcount = InterlockedIncrement(&blob->refcount);
54
55     TRACE("%p increasing refcount to %u\n", blob, refcount);
56
57     return refcount;
58 }
59
60 static ULONG STDMETHODCALLTYPE d3dcompiler_blob_Release(ID3DBlob *iface)
61 {
62     struct d3dcompiler_blob *blob = (struct d3dcompiler_blob *)iface;
63     ULONG refcount = InterlockedDecrement(&blob->refcount);
64
65     TRACE("%p decreasing refcount to %u\n", blob, refcount);
66
67     if (!refcount)
68     {
69         HeapFree(GetProcessHeap(), 0, blob->data);
70         HeapFree(GetProcessHeap(), 0, blob);
71     }
72
73     return refcount;
74 }
75
76 /* ID3DBlob methods */
77
78 static void * STDMETHODCALLTYPE d3dcompiler_blob_GetBufferPointer(ID3DBlob *iface)
79 {
80     struct d3dcompiler_blob *blob = (struct d3dcompiler_blob *)iface;
81
82     TRACE("iface %p\n", iface);
83
84     return blob->data;
85 }
86
87 static SIZE_T STDMETHODCALLTYPE d3dcompiler_blob_GetBufferSize(ID3DBlob *iface)
88 {
89     struct d3dcompiler_blob *blob = (struct d3dcompiler_blob *)iface;
90
91     TRACE("iface %p\n", iface);
92
93     return blob->size;
94 }
95
96 const struct ID3D10BlobVtbl d3dcompiler_blob_vtbl =
97 {
98     /* IUnknown methods */
99     d3dcompiler_blob_QueryInterface,
100     d3dcompiler_blob_AddRef,
101     d3dcompiler_blob_Release,
102     /* ID3DBlob methods */
103     d3dcompiler_blob_GetBufferPointer,
104     d3dcompiler_blob_GetBufferSize,
105 };
106
107 HRESULT d3dcompiler_blob_init(struct d3dcompiler_blob *blob, SIZE_T data_size)
108 {
109     blob->vtbl = &d3dcompiler_blob_vtbl;
110     blob->refcount = 1;
111     blob->size = data_size;
112
113     blob->data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, data_size);
114     if (!blob->data)
115     {
116         ERR("Failed to allocate D3D blob data memory\n");
117         return E_OUTOFMEMORY;
118     }
119
120     return S_OK;
121 }