ntdll: Implement RtlValidRelativeSecurityDescriptor.
[wine.git] / dlls / dxgi / utils.c
blobde3ef775d48610318abe956b84853f3cf720b506
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
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.
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.
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include "dxgi_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
27 #define WINE_DXGI_TO_STR(x) case x: return #x
29 const char *debug_dxgi_format(DXGI_FORMAT format)
31 switch(format)
33 WINE_DXGI_TO_STR(DXGI_FORMAT_UNKNOWN);
34 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32A32_TYPELESS);
35 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32A32_FLOAT);
36 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32A32_UINT);
37 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32A32_SINT);
38 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32_TYPELESS);
39 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32_FLOAT);
40 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32_UINT);
41 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32B32_SINT);
42 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_TYPELESS);
43 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_FLOAT);
44 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_UNORM);
45 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_UINT);
46 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_SNORM);
47 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16B16A16_SINT);
48 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32_TYPELESS);
49 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32_FLOAT);
50 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32_UINT);
51 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G32_SINT);
52 WINE_DXGI_TO_STR(DXGI_FORMAT_R32G8X24_TYPELESS);
53 WINE_DXGI_TO_STR(DXGI_FORMAT_D32_FLOAT_S8X24_UINT);
54 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS);
55 WINE_DXGI_TO_STR(DXGI_FORMAT_X32_TYPELESS_G8X24_UINT);
56 WINE_DXGI_TO_STR(DXGI_FORMAT_R10G10B10A2_TYPELESS);
57 WINE_DXGI_TO_STR(DXGI_FORMAT_R10G10B10A2_UNORM);
58 WINE_DXGI_TO_STR(DXGI_FORMAT_R10G10B10A2_UINT);
59 WINE_DXGI_TO_STR(DXGI_FORMAT_R11G11B10_FLOAT);
60 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_TYPELESS);
61 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_UNORM);
62 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
63 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_UINT);
64 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_SNORM);
65 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8B8A8_SINT);
66 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_TYPELESS);
67 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_FLOAT);
68 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_UNORM);
69 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_UINT);
70 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_SNORM);
71 WINE_DXGI_TO_STR(DXGI_FORMAT_R16G16_SINT);
72 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_TYPELESS);
73 WINE_DXGI_TO_STR(DXGI_FORMAT_D32_FLOAT);
74 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_FLOAT);
75 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_UINT);
76 WINE_DXGI_TO_STR(DXGI_FORMAT_R32_SINT);
77 WINE_DXGI_TO_STR(DXGI_FORMAT_R24G8_TYPELESS);
78 WINE_DXGI_TO_STR(DXGI_FORMAT_D24_UNORM_S8_UINT);
79 WINE_DXGI_TO_STR(DXGI_FORMAT_R24_UNORM_X8_TYPELESS);
80 WINE_DXGI_TO_STR(DXGI_FORMAT_X24_TYPELESS_G8_UINT);
81 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_TYPELESS);
82 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_UNORM);
83 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_UINT);
84 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_SNORM);
85 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_SINT);
86 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_TYPELESS);
87 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_FLOAT);
88 WINE_DXGI_TO_STR(DXGI_FORMAT_D16_UNORM);
89 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_UNORM);
90 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_UINT);
91 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_SNORM);
92 WINE_DXGI_TO_STR(DXGI_FORMAT_R16_SINT);
93 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_TYPELESS);
94 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_UNORM);
95 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_UINT);
96 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_SNORM);
97 WINE_DXGI_TO_STR(DXGI_FORMAT_R8_SINT);
98 WINE_DXGI_TO_STR(DXGI_FORMAT_A8_UNORM);
99 WINE_DXGI_TO_STR(DXGI_FORMAT_R1_UNORM);
100 WINE_DXGI_TO_STR(DXGI_FORMAT_R9G9B9E5_SHAREDEXP);
101 WINE_DXGI_TO_STR(DXGI_FORMAT_R8G8_B8G8_UNORM);
102 WINE_DXGI_TO_STR(DXGI_FORMAT_G8R8_G8B8_UNORM);
103 WINE_DXGI_TO_STR(DXGI_FORMAT_BC1_TYPELESS);
104 WINE_DXGI_TO_STR(DXGI_FORMAT_BC1_UNORM);
105 WINE_DXGI_TO_STR(DXGI_FORMAT_BC1_UNORM_SRGB);
106 WINE_DXGI_TO_STR(DXGI_FORMAT_BC2_TYPELESS);
107 WINE_DXGI_TO_STR(DXGI_FORMAT_BC2_UNORM);
108 WINE_DXGI_TO_STR(DXGI_FORMAT_BC2_UNORM_SRGB);
109 WINE_DXGI_TO_STR(DXGI_FORMAT_BC3_TYPELESS);
110 WINE_DXGI_TO_STR(DXGI_FORMAT_BC3_UNORM);
111 WINE_DXGI_TO_STR(DXGI_FORMAT_BC3_UNORM_SRGB);
112 WINE_DXGI_TO_STR(DXGI_FORMAT_BC4_TYPELESS);
113 WINE_DXGI_TO_STR(DXGI_FORMAT_BC4_UNORM);
114 WINE_DXGI_TO_STR(DXGI_FORMAT_BC4_SNORM);
115 WINE_DXGI_TO_STR(DXGI_FORMAT_BC5_TYPELESS);
116 WINE_DXGI_TO_STR(DXGI_FORMAT_BC5_UNORM);
117 WINE_DXGI_TO_STR(DXGI_FORMAT_BC5_SNORM);
118 WINE_DXGI_TO_STR(DXGI_FORMAT_B5G6R5_UNORM);
119 WINE_DXGI_TO_STR(DXGI_FORMAT_B5G5R5A1_UNORM);
120 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8A8_UNORM);
121 WINE_DXGI_TO_STR(DXGI_FORMAT_B8G8R8X8_UNORM);
122 default:
123 FIXME("Unrecognized DXGI_FORMAT %#x\n", format);
124 return "unrecognized";
128 #undef WINE_DXGI_TO_STR
130 DXGI_FORMAT dxgi_format_from_wined3dformat(enum wined3d_format_id format)
132 switch(format)
134 case WINED3DFMT_UNKNOWN: return DXGI_FORMAT_UNKNOWN;
135 case WINED3DFMT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS;
136 case WINED3DFMT_R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT;
137 case WINED3DFMT_R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT;
138 case WINED3DFMT_R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT;
139 case WINED3DFMT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS;
140 case WINED3DFMT_R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT;
141 case WINED3DFMT_R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT;
142 case WINED3DFMT_R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT;
143 case WINED3DFMT_R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS;
144 case WINED3DFMT_R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
145 case WINED3DFMT_R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
146 case WINED3DFMT_R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
147 case WINED3DFMT_R16G16B16A16_SNORM: return DXGI_FORMAT_R16G16B16A16_SNORM;
148 case WINED3DFMT_R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT;
149 case WINED3DFMT_R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS;
150 case WINED3DFMT_R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT;
151 case WINED3DFMT_R32G32_UINT: return DXGI_FORMAT_R32G32_UINT;
152 case WINED3DFMT_R32G32_SINT: return DXGI_FORMAT_R32G32_SINT;
153 case WINED3DFMT_R32G8X24_TYPELESS: return DXGI_FORMAT_R32G8X24_TYPELESS;
154 case WINED3DFMT_D32_FLOAT_S8X24_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
155 case WINED3DFMT_R32_FLOAT_X8X24_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
156 case WINED3DFMT_X32_TYPELESS_G8X24_UINT: return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
157 case WINED3DFMT_R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS;
158 case WINED3DFMT_R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM;
159 case WINED3DFMT_R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT;
160 case WINED3DFMT_R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT;
161 case WINED3DFMT_R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS;
162 case WINED3DFMT_R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
163 case WINED3DFMT_R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
164 case WINED3DFMT_R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
165 case WINED3DFMT_R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM;
166 case WINED3DFMT_R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT;
167 case WINED3DFMT_R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS;
168 case WINED3DFMT_R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT;
169 case WINED3DFMT_R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM;
170 case WINED3DFMT_R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
171 case WINED3DFMT_R16G16_SNORM: return DXGI_FORMAT_R16G16_SNORM;
172 case WINED3DFMT_R16G16_SINT: return DXGI_FORMAT_R16G16_SINT;
173 case WINED3DFMT_R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS;
174 case WINED3DFMT_D32_FLOAT: return DXGI_FORMAT_D32_FLOAT;
175 case WINED3DFMT_R32_FLOAT: return DXGI_FORMAT_R32_FLOAT;
176 case WINED3DFMT_R32_UINT: return DXGI_FORMAT_R32_UINT;
177 case WINED3DFMT_R32_SINT: return DXGI_FORMAT_R32_SINT;
178 case WINED3DFMT_R24G8_TYPELESS: return DXGI_FORMAT_R24G8_TYPELESS;
179 case WINED3DFMT_D24_UNORM_S8_UINT: return DXGI_FORMAT_D24_UNORM_S8_UINT;
180 case WINED3DFMT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
181 case WINED3DFMT_X24_TYPELESS_G8_UINT: return DXGI_FORMAT_X24_TYPELESS_G8_UINT;
182 case WINED3DFMT_R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS;
183 case WINED3DFMT_R8G8_UNORM: return DXGI_FORMAT_R8G8_UNORM;
184 case WINED3DFMT_R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
185 case WINED3DFMT_R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM;
186 case WINED3DFMT_R8G8_SINT: return DXGI_FORMAT_R8G8_SINT;
187 case WINED3DFMT_R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS;
188 case WINED3DFMT_R16_FLOAT: return DXGI_FORMAT_R16_FLOAT;
189 case WINED3DFMT_D16_UNORM: return DXGI_FORMAT_D16_UNORM;
190 case WINED3DFMT_R16_UNORM: return DXGI_FORMAT_R16_UNORM;
191 case WINED3DFMT_R16_UINT: return DXGI_FORMAT_R16_UINT;
192 case WINED3DFMT_R16_SNORM: return DXGI_FORMAT_R16_SNORM;
193 case WINED3DFMT_R16_SINT: return DXGI_FORMAT_R16_SINT;
194 case WINED3DFMT_R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS;
195 case WINED3DFMT_R8_UNORM: return DXGI_FORMAT_R8_UNORM;
196 case WINED3DFMT_R8_UINT: return DXGI_FORMAT_R8_UINT;
197 case WINED3DFMT_R8_SNORM: return DXGI_FORMAT_R8_SNORM;
198 case WINED3DFMT_R8_SINT: return DXGI_FORMAT_R8_SINT;
199 case WINED3DFMT_A8_UNORM: return DXGI_FORMAT_A8_UNORM;
200 case WINED3DFMT_R1_UNORM: return DXGI_FORMAT_R1_UNORM;
201 case WINED3DFMT_R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
202 case WINED3DFMT_R8G8_B8G8_UNORM: return DXGI_FORMAT_R8G8_B8G8_UNORM;
203 case WINED3DFMT_G8R8_G8B8_UNORM: return DXGI_FORMAT_G8R8_G8B8_UNORM;
204 case WINED3DFMT_BC1_TYPELESS: return DXGI_FORMAT_BC1_TYPELESS;
205 case WINED3DFMT_BC1_UNORM: return DXGI_FORMAT_BC1_UNORM;
206 case WINED3DFMT_BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB;
207 case WINED3DFMT_BC2_TYPELESS: return DXGI_FORMAT_BC2_TYPELESS;
208 case WINED3DFMT_BC2_UNORM: return DXGI_FORMAT_BC2_UNORM;
209 case WINED3DFMT_BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB;
210 case WINED3DFMT_BC3_TYPELESS: return DXGI_FORMAT_BC3_TYPELESS;
211 case WINED3DFMT_BC3_UNORM: return DXGI_FORMAT_BC3_UNORM;
212 case WINED3DFMT_BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB;
213 case WINED3DFMT_BC4_TYPELESS: return DXGI_FORMAT_BC4_TYPELESS;
214 case WINED3DFMT_BC4_UNORM: return DXGI_FORMAT_BC4_UNORM;
215 case WINED3DFMT_BC4_SNORM: return DXGI_FORMAT_BC4_SNORM;
216 case WINED3DFMT_BC5_TYPELESS: return DXGI_FORMAT_BC5_TYPELESS;
217 case WINED3DFMT_BC5_UNORM: return DXGI_FORMAT_BC5_UNORM;
218 case WINED3DFMT_BC5_SNORM: return DXGI_FORMAT_BC5_SNORM;
219 case WINED3DFMT_B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM;
220 case WINED3DFMT_B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM;
221 case WINED3DFMT_B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
222 case WINED3DFMT_B8G8R8X8_UNORM: return DXGI_FORMAT_B8G8R8X8_UNORM;
223 default:
224 FIXME("Unhandled wined3d format %#x.\n", format);
225 return DXGI_FORMAT_UNKNOWN;
229 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format)
231 switch(format)
233 case DXGI_FORMAT_UNKNOWN: return WINED3DFMT_UNKNOWN;
234 case DXGI_FORMAT_R32G32B32A32_TYPELESS: return WINED3DFMT_R32G32B32A32_TYPELESS;
235 case DXGI_FORMAT_R32G32B32A32_FLOAT: return WINED3DFMT_R32G32B32A32_FLOAT;
236 case DXGI_FORMAT_R32G32B32A32_UINT: return WINED3DFMT_R32G32B32A32_UINT;
237 case DXGI_FORMAT_R32G32B32A32_SINT: return WINED3DFMT_R32G32B32A32_SINT;
238 case DXGI_FORMAT_R32G32B32_TYPELESS: return WINED3DFMT_R32G32B32_TYPELESS;
239 case DXGI_FORMAT_R32G32B32_FLOAT: return WINED3DFMT_R32G32B32_FLOAT;
240 case DXGI_FORMAT_R32G32B32_UINT: return WINED3DFMT_R32G32B32_UINT;
241 case DXGI_FORMAT_R32G32B32_SINT: return WINED3DFMT_R32G32B32_SINT;
242 case DXGI_FORMAT_R16G16B16A16_TYPELESS: return WINED3DFMT_R16G16B16A16_TYPELESS;
243 case DXGI_FORMAT_R16G16B16A16_FLOAT: return WINED3DFMT_R16G16B16A16_FLOAT;
244 case DXGI_FORMAT_R16G16B16A16_UNORM: return WINED3DFMT_R16G16B16A16_UNORM;
245 case DXGI_FORMAT_R16G16B16A16_UINT: return WINED3DFMT_R16G16B16A16_UINT;
246 case DXGI_FORMAT_R16G16B16A16_SNORM: return WINED3DFMT_R16G16B16A16_SNORM;
247 case DXGI_FORMAT_R16G16B16A16_SINT: return WINED3DFMT_R16G16B16A16_SINT;
248 case DXGI_FORMAT_R32G32_TYPELESS: return WINED3DFMT_R32G32_TYPELESS;
249 case DXGI_FORMAT_R32G32_FLOAT: return WINED3DFMT_R32G32_FLOAT;
250 case DXGI_FORMAT_R32G32_UINT: return WINED3DFMT_R32G32_UINT;
251 case DXGI_FORMAT_R32G32_SINT: return WINED3DFMT_R32G32_SINT;
252 case DXGI_FORMAT_R32G8X24_TYPELESS: return WINED3DFMT_R32G8X24_TYPELESS;
253 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return WINED3DFMT_D32_FLOAT_S8X24_UINT;
254 case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: return WINED3DFMT_R32_FLOAT_X8X24_TYPELESS;
255 case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: return WINED3DFMT_X32_TYPELESS_G8X24_UINT;
256 case DXGI_FORMAT_R10G10B10A2_TYPELESS: return WINED3DFMT_R10G10B10A2_TYPELESS;
257 case DXGI_FORMAT_R10G10B10A2_UNORM: return WINED3DFMT_R10G10B10A2_UNORM;
258 case DXGI_FORMAT_R10G10B10A2_UINT: return WINED3DFMT_R10G10B10A2_UINT;
259 case DXGI_FORMAT_R11G11B10_FLOAT: return WINED3DFMT_R11G11B10_FLOAT;
260 case DXGI_FORMAT_R8G8B8A8_TYPELESS: return WINED3DFMT_R8G8B8A8_TYPELESS;
261 case DXGI_FORMAT_R8G8B8A8_UNORM: return WINED3DFMT_R8G8B8A8_UNORM;
262 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return WINED3DFMT_R8G8B8A8_UNORM_SRGB;
263 case DXGI_FORMAT_R8G8B8A8_UINT: return WINED3DFMT_R8G8B8A8_UINT;
264 case DXGI_FORMAT_R8G8B8A8_SNORM: return WINED3DFMT_R8G8B8A8_SNORM;
265 case DXGI_FORMAT_R8G8B8A8_SINT: return WINED3DFMT_R8G8B8A8_SINT;
266 case DXGI_FORMAT_R16G16_TYPELESS: return WINED3DFMT_R16G16_TYPELESS;
267 case DXGI_FORMAT_R16G16_FLOAT: return WINED3DFMT_R16G16_FLOAT;
268 case DXGI_FORMAT_R16G16_UNORM: return WINED3DFMT_R16G16_UNORM;
269 case DXGI_FORMAT_R16G16_UINT: return WINED3DFMT_R16G16_UINT;
270 case DXGI_FORMAT_R16G16_SNORM: return WINED3DFMT_R16G16_SNORM;
271 case DXGI_FORMAT_R16G16_SINT: return WINED3DFMT_R16G16_SINT;
272 case DXGI_FORMAT_R32_TYPELESS: return WINED3DFMT_R32_TYPELESS;
273 case DXGI_FORMAT_D32_FLOAT: return WINED3DFMT_D32_FLOAT;
274 case DXGI_FORMAT_R32_FLOAT: return WINED3DFMT_R32_FLOAT;
275 case DXGI_FORMAT_R32_UINT: return WINED3DFMT_R32_UINT;
276 case DXGI_FORMAT_R32_SINT: return WINED3DFMT_R32_SINT;
277 case DXGI_FORMAT_R24G8_TYPELESS: return WINED3DFMT_R24G8_TYPELESS;
278 case DXGI_FORMAT_D24_UNORM_S8_UINT: return WINED3DFMT_D24_UNORM_S8_UINT;
279 case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return WINED3DFMT_R24_UNORM_X8_TYPELESS;
280 case DXGI_FORMAT_X24_TYPELESS_G8_UINT: return WINED3DFMT_X24_TYPELESS_G8_UINT;
281 case DXGI_FORMAT_R8G8_TYPELESS: return WINED3DFMT_R8G8_TYPELESS;
282 case DXGI_FORMAT_R8G8_UNORM: return WINED3DFMT_R8G8_UNORM;
283 case DXGI_FORMAT_R8G8_UINT: return WINED3DFMT_R8G8_UINT;
284 case DXGI_FORMAT_R8G8_SNORM: return WINED3DFMT_R8G8_SNORM;
285 case DXGI_FORMAT_R8G8_SINT: return WINED3DFMT_R8G8_SINT;
286 case DXGI_FORMAT_R16_TYPELESS: return WINED3DFMT_R16_TYPELESS;
287 case DXGI_FORMAT_R16_FLOAT: return WINED3DFMT_R16_FLOAT;
288 case DXGI_FORMAT_D16_UNORM: return WINED3DFMT_D16_UNORM;
289 case DXGI_FORMAT_R16_UNORM: return WINED3DFMT_R16_UNORM;
290 case DXGI_FORMAT_R16_UINT: return WINED3DFMT_R16_UINT;
291 case DXGI_FORMAT_R16_SNORM: return WINED3DFMT_R16_SNORM;
292 case DXGI_FORMAT_R16_SINT: return WINED3DFMT_R16_SINT;
293 case DXGI_FORMAT_R8_TYPELESS: return WINED3DFMT_R8_TYPELESS;
294 case DXGI_FORMAT_R8_UNORM: return WINED3DFMT_R8_UNORM;
295 case DXGI_FORMAT_R8_UINT: return WINED3DFMT_R8_UINT;
296 case DXGI_FORMAT_R8_SNORM: return WINED3DFMT_R8_SNORM;
297 case DXGI_FORMAT_R8_SINT: return WINED3DFMT_R8_SINT;
298 case DXGI_FORMAT_A8_UNORM: return WINED3DFMT_A8_UNORM;
299 case DXGI_FORMAT_R1_UNORM: return WINED3DFMT_R1_UNORM;
300 case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: return WINED3DFMT_R9G9B9E5_SHAREDEXP;
301 case DXGI_FORMAT_R8G8_B8G8_UNORM: return WINED3DFMT_R8G8_B8G8_UNORM;
302 case DXGI_FORMAT_G8R8_G8B8_UNORM: return WINED3DFMT_G8R8_G8B8_UNORM;
303 case DXGI_FORMAT_BC1_TYPELESS: return WINED3DFMT_BC1_TYPELESS;
304 case DXGI_FORMAT_BC1_UNORM: return WINED3DFMT_BC1_UNORM;
305 case DXGI_FORMAT_BC1_UNORM_SRGB: return WINED3DFMT_BC1_UNORM_SRGB;
306 case DXGI_FORMAT_BC2_TYPELESS: return WINED3DFMT_BC2_TYPELESS;
307 case DXGI_FORMAT_BC2_UNORM: return WINED3DFMT_BC2_UNORM;
308 case DXGI_FORMAT_BC2_UNORM_SRGB: return WINED3DFMT_BC2_UNORM_SRGB;
309 case DXGI_FORMAT_BC3_TYPELESS: return WINED3DFMT_BC3_TYPELESS;
310 case DXGI_FORMAT_BC3_UNORM: return WINED3DFMT_BC3_UNORM;
311 case DXGI_FORMAT_BC3_UNORM_SRGB: return WINED3DFMT_BC3_UNORM_SRGB;
312 case DXGI_FORMAT_BC4_TYPELESS: return WINED3DFMT_BC4_TYPELESS;
313 case DXGI_FORMAT_BC4_UNORM: return WINED3DFMT_BC4_UNORM;
314 case DXGI_FORMAT_BC4_SNORM: return WINED3DFMT_BC4_SNORM;
315 case DXGI_FORMAT_BC5_TYPELESS: return WINED3DFMT_BC5_TYPELESS;
316 case DXGI_FORMAT_BC5_UNORM: return WINED3DFMT_BC5_UNORM;
317 case DXGI_FORMAT_BC5_SNORM: return WINED3DFMT_BC5_SNORM;
318 case DXGI_FORMAT_B5G6R5_UNORM: return WINED3DFMT_B5G6R5_UNORM;
319 case DXGI_FORMAT_B5G5R5A1_UNORM: return WINED3DFMT_B5G5R5A1_UNORM;
320 case DXGI_FORMAT_B8G8R8A8_UNORM: return WINED3DFMT_B8G8R8A8_UNORM;
321 case DXGI_FORMAT_B8G8R8X8_UNORM: return WINED3DFMT_B8G8R8X8_UNORM;
322 default:
323 FIXME("Unhandled DXGI_FORMAT %#x\n", format);
324 return WINED3DFMT_UNKNOWN;
328 void dxgi_sample_desc_from_wined3d(DXGI_SAMPLE_DESC *desc,
329 enum wined3d_multisample_type wined3d_type, unsigned int wined3d_quality)
331 desc->Count = wined3d_type == WINED3D_MULTISAMPLE_NONE ? 1 : wined3d_type;
332 desc->Quality = wined3d_quality;
335 void wined3d_sample_desc_from_dxgi(enum wined3d_multisample_type *wined3d_type,
336 unsigned int *wined3d_quality, const DXGI_SAMPLE_DESC *dxgi_desc)
338 if (dxgi_desc->Count > 1)
340 *wined3d_type = dxgi_desc->Count;
341 *wined3d_quality = dxgi_desc->Quality;
343 else
345 *wined3d_type = WINED3D_MULTISAMPLE_NONE;
346 *wined3d_quality = 0;
350 HRESULT dxgi_get_private_data(struct wined3d_private_store *store,
351 REFGUID guid, UINT *data_size, void *data)
353 const struct wined3d_private_data *stored_data;
354 DWORD size_in;
355 HRESULT hr;
357 if (!data_size)
358 return E_INVALIDARG;
360 wined3d_mutex_lock();
361 if (!(stored_data = wined3d_private_store_get_private_data(store, guid)))
363 hr = DXGI_ERROR_NOT_FOUND;
364 *data_size = 0;
365 goto done;
368 size_in = *data_size;
369 *data_size = stored_data->size;
370 if (!data)
372 hr = S_OK;
373 goto done;
375 if (size_in < stored_data->size)
377 hr = DXGI_ERROR_MORE_DATA;
378 goto done;
381 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
382 IUnknown_AddRef(stored_data->content.object);
383 memcpy(data, stored_data->content.data, stored_data->size);
384 hr = S_OK;
386 done:
387 wined3d_mutex_unlock();
389 return hr;
392 HRESULT dxgi_set_private_data(struct wined3d_private_store *store,
393 REFGUID guid, UINT data_size, const void *data)
395 struct wined3d_private_data *entry;
396 HRESULT hr;
398 if (!data)
400 wined3d_mutex_lock();
401 if (!(entry = wined3d_private_store_get_private_data(store, guid)))
403 wined3d_mutex_unlock();
404 return S_FALSE;
407 wined3d_private_store_free_private_data(store, entry);
408 wined3d_mutex_unlock();
410 return S_OK;
413 wined3d_mutex_lock();
414 hr = wined3d_private_store_set_private_data(store, guid, data, data_size, 0);
415 wined3d_mutex_unlock();
417 return hr;
420 HRESULT dxgi_set_private_data_interface(struct wined3d_private_store *store,
421 REFGUID guid, const IUnknown *object)
423 HRESULT hr;
425 if (!object)
426 return dxgi_set_private_data(store, guid, sizeof(object), &object);
428 wined3d_mutex_lock();
429 hr = wined3d_private_store_set_private_data(store,
430 guid, object, sizeof(object), WINED3DSPD_IUNKNOWN);
431 wined3d_mutex_unlock();
433 return hr;