ReactOS 0.4.17-dev-934-g091855f
blob.c
Go to the documentation of this file.
1/*
2 * Copyright 2017 Józef Kucia for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#ifndef __MINGW32__
20#define WIDL_C_INLINE_WRAPPERS
21#endif
22#define COBJMACROS
23#define CONST_VTABLE
24#include "vkd3d.h"
25#include "vkd3d_blob.h"
26#include "vkd3d_memory.h"
27#include "d3d12shader.h"
28
30{
32 unsigned int refcount;
33
34 void *buffer;
36};
37
39{
40 return CONTAINING_RECORD(iface, struct vkd3d_blob, ID3DBlob_iface);
41}
42
44{
45 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
46
47 if (IsEqualGUID(riid, &IID_ID3DBlob)
49 {
50 ID3D10Blob_AddRef(iface);
51 *object = iface;
52 return S_OK;
53 }
54
55 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
56
57 *object = NULL;
58 return E_NOINTERFACE;
59}
60
62{
63 struct vkd3d_blob *blob = impl_from_ID3DBlob(iface);
64 unsigned int refcount = vkd3d_atomic_increment_u32(&blob->refcount);
65
66 TRACE("%p increasing refcount to %u.\n", blob, refcount);
67
68 return refcount;
69}
70
72{
73 struct vkd3d_blob *blob = impl_from_ID3DBlob(iface);
74 unsigned int refcount = vkd3d_atomic_decrement_u32(&blob->refcount);
75
76 TRACE("%p decreasing refcount to %u.\n", blob, refcount);
77
78 if (!refcount)
79 {
80 vkd3d_free(blob->buffer);
81
83 }
84
85 return refcount;
86}
87
89{
90 struct vkd3d_blob *blob = impl_from_ID3DBlob(iface);
91
92 TRACE("iface %p.\n", iface);
93
94 return blob->buffer;
95}
96
98{
99 struct vkd3d_blob *blob = impl_from_ID3DBlob(iface);
100
101 TRACE("iface %p.\n", iface);
102
103 return blob->size;
104}
105
106static const struct ID3D10BlobVtbl vkd3d_blob_vtbl =
107{
108 /* IUnknown methods */
112 /* ID3DBlob methods */
115};
116
117static void vkd3d_blob_init(struct vkd3d_blob *blob, void *buffer, SIZE_T size)
118{
119 blob->ID3DBlob_iface.lpVtbl = &vkd3d_blob_vtbl;
120 blob->refcount = 1;
121
122 blob->buffer = buffer;
123 blob->size = size;
124}
125
127{
128 struct vkd3d_blob *object;
129
130 if (!(object = vkd3d_malloc(sizeof(*object))))
131 return E_OUTOFMEMORY;
132
133 vkd3d_blob_init(object, buffer, size);
134
135 TRACE("Created blob object %p.\n", object);
136
137 *blob = &object->ID3DBlob_iface;
138
139 return S_OK;
140}
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
static struct d3dcompiler_blob * impl_from_ID3DBlob(ID3DBlob *iface)
Definition: blob.c:35
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define debugstr_guid
Definition: kernel32.h:35
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
static ULONG STDMETHODCALLTYPE vkd3d_blob_Release(ID3DBlob *iface)
Definition: blob.c:71
static SIZE_T STDMETHODCALLTYPE vkd3d_blob_GetBufferSize(ID3DBlob *iface)
Definition: blob.c:97
static const struct ID3D10BlobVtbl vkd3d_blob_vtbl
Definition: blob.c:106
static void vkd3d_blob_init(struct vkd3d_blob *blob, void *buffer, SIZE_T size)
Definition: blob.c:117
static void *STDMETHODCALLTYPE vkd3d_blob_GetBufferPointer(ID3DBlob *iface)
Definition: blob.c:88
static HRESULT STDMETHODCALLTYPE vkd3d_blob_QueryInterface(ID3DBlob *iface, REFIID riid, void **object)
Definition: blob.c:43
HRESULT vkd3d_blob_create(void *buffer, SIZE_T size, ID3D10Blob **blob)
Definition: blob.c:126
static ULONG STDMETHODCALLTYPE vkd3d_blob_AddRef(ID3DBlob *iface)
Definition: blob.c:61
#define TRACE(s)
Definition: solgame.cpp:4
Definition: image.c:229
unsigned int refcount
Definition: blob.c:32
ID3D10Blob ID3DBlob_iface
Definition: blob.c:31
SIZE_T size
Definition: blob.c:35
void * buffer
Definition: blob.c:34
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
static uint32_t vkd3d_atomic_decrement_u32(uint32_t volatile *x)
Definition: vkd3d_common.h:477
static uint32_t vkd3d_atomic_increment_u32(uint32_t volatile *x)
Definition: vkd3d_common.h:482
static void vkd3d_free(void *ptr)
Definition: vkd3d_memory.h:52
static void * vkd3d_malloc(size_t size)
Definition: vkd3d_memory.h:28
#define E_NOINTERFACE
Definition: winerror.h:3479