d3dcompiler: Implement ID3DBlob::GetBufferSize().
[wine.git] / dlls / d3dcompiler_43 / blob.c
blobdd3c388997214e6e8599f55adb992e2bfbf3ba55
1 /*
2 * Direct3D blob file
4 * Copyright 2010 Rico Schüller
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.
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.
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include "d3dcompiler_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
30 /* IUnknown methods */
32 static HRESULT STDMETHODCALLTYPE d3dcompiler_blob_QueryInterface(ID3DBlob *iface, REFIID riid, void **object)
34 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
36 if (IsEqualGUID(riid, &IID_ID3D10Blob)
37 || IsEqualGUID(riid, &IID_IUnknown))
39 IUnknown_AddRef(iface);
40 *object = iface;
41 return S_OK;
44 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
46 *object = NULL;
47 return E_NOINTERFACE;
50 static ULONG STDMETHODCALLTYPE d3dcompiler_blob_AddRef(ID3DBlob *iface)
52 struct d3dcompiler_blob *blob = (struct d3dcompiler_blob *)iface;
53 ULONG refcount = InterlockedIncrement(&blob->refcount);
55 TRACE("%p increasing refcount to %u\n", blob, refcount);
57 return refcount;
60 static ULONG STDMETHODCALLTYPE d3dcompiler_blob_Release(ID3DBlob *iface)
62 struct d3dcompiler_blob *blob = (struct d3dcompiler_blob *)iface;
63 ULONG refcount = InterlockedDecrement(&blob->refcount);
65 TRACE("%p decreasing refcount to %u\n", blob, refcount);
67 if (!refcount)
69 HeapFree(GetProcessHeap(), 0, blob->data);
70 HeapFree(GetProcessHeap(), 0, blob);
73 return refcount;
76 /* ID3DBlob methods */
78 static void * STDMETHODCALLTYPE d3dcompiler_blob_GetBufferPointer(ID3DBlob *iface)
80 struct d3dcompiler_blob *blob = (struct d3dcompiler_blob *)iface;
82 TRACE("iface %p\n", iface);
84 return blob->data;
87 static SIZE_T STDMETHODCALLTYPE d3dcompiler_blob_GetBufferSize(ID3DBlob *iface)
89 struct d3dcompiler_blob *blob = (struct d3dcompiler_blob *)iface;
91 TRACE("iface %p\n", iface);
93 return blob->size;
96 const struct ID3D10BlobVtbl d3dcompiler_blob_vtbl =
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,
107 HRESULT d3dcompiler_blob_init(struct d3dcompiler_blob *blob, SIZE_T data_size)
109 blob->vtbl = &d3dcompiler_blob_vtbl;
110 blob->refcount = 1;
111 blob->size = data_size;
113 blob->data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, data_size);
114 if (!blob->data)
116 ERR("Failed to allocate D3D blob data memory\n");
117 return E_OUTOFMEMORY;
120 return S_OK;