hhctrl.ocx: Open a specific topic when requested.
[wine/multimedia.git] / dlls / d3dx9_36 / util.c
blobddb54c35a369212f8096e3bdc198fa8d08452148
1 /*
2 * Copyright (C) 2009 Tony Wasserka
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 "wine/debug.h"
21 #include "d3dx9_36_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
25 /************************************************************
26 * pixel format table providing info about number of bytes per pixel,
27 * number of bits per channel and format type.
29 * Call get_format_info to request information about a specific format.
31 static const PixelFormatDesc formats[] =
33 /* format bits per channel shifts per channel bpp type */
34 { D3DFMT_R8G8B8, { 0, 8, 8, 8 }, { 0, 16, 8, 0 }, 3, FORMAT_ARGB },
35 { D3DFMT_A8R8G8B8, { 8, 8, 8, 8 }, { 24, 16, 8, 0 }, 4, FORMAT_ARGB },
36 { D3DFMT_X8R8G8B8, { 0, 8, 8, 8 }, { 0, 16, 8, 0 }, 4, FORMAT_ARGB },
37 { D3DFMT_A8B8G8R8, { 8, 8, 8, 8 }, { 24, 0, 8, 16 }, 4, FORMAT_ARGB },
38 { D3DFMT_X8B8G8R8, { 0, 8, 8, 8 }, { 0, 0, 8, 16 }, 4, FORMAT_ARGB },
39 { D3DFMT_R5G6B5, { 0, 5, 6, 5 }, { 0, 11, 5, 0 }, 2, FORMAT_ARGB },
40 { D3DFMT_X1R5G5B5, { 0, 5, 5, 5 }, { 0, 10, 5, 0 }, 2, FORMAT_ARGB },
41 { D3DFMT_A1R5G5B5, { 1, 5, 5, 5 }, { 15, 10, 5, 0 }, 2, FORMAT_ARGB },
42 { D3DFMT_R3G3B2, { 0, 3, 3, 2 }, { 0, 5, 2, 0 }, 1, FORMAT_ARGB },
43 { D3DFMT_A8R3G3B2, { 8, 3, 3, 2 }, { 8, 5, 2, 0 }, 2, FORMAT_ARGB },
44 { D3DFMT_A4R4G4B4, { 4, 4, 4, 4 }, { 12, 8, 4, 0 }, 2, FORMAT_ARGB },
45 { D3DFMT_X4R4G4B4, { 0, 4, 4, 4 }, { 0, 8, 4, 0 }, 2, FORMAT_ARGB },
46 { D3DFMT_A2R10G10B10, { 2, 10, 10, 10 }, { 30, 20, 10, 0 }, 4, FORMAT_ARGB },
47 { D3DFMT_A2B10G10R10, { 2, 10, 10, 10 }, { 30, 0, 10, 20 }, 4, FORMAT_ARGB },
48 { D3DFMT_G16R16, { 0, 16, 16, 0 }, { 0, 0, 16, 0 }, 4, FORMAT_ARGB },
49 { D3DFMT_A8, { 8, 0, 0, 0 }, { 0, 0, 0, 0 }, 1, FORMAT_ARGB },
51 { D3DFMT_UNKNOWN, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, 0, FORMAT_UNKNOWN }, /* marks last element */
55 /************************************************************
56 * map_view_of_file
58 * Loads a file into buffer and stores the number of read bytes in length.
60 * PARAMS
61 * filename [I] name of the file to be loaded
62 * buffer [O] pointer to destination buffer
63 * length [O] size of the obtained data
65 * RETURNS
66 * Success: D3D_OK
67 * Failure:
68 * see error codes for CreateFileW, GetFileSize, CreateFileMapping and MapViewOfFile
70 * NOTES
71 * The caller must UnmapViewOfFile when it doesn't need the data anymore
74 HRESULT map_view_of_file(LPCWSTR filename, LPVOID *buffer, DWORD *length)
76 HANDLE hfile, hmapping = NULL;
78 hfile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
79 if(hfile == INVALID_HANDLE_VALUE) goto error;
81 *length = GetFileSize(hfile, NULL);
82 if(*length == INVALID_FILE_SIZE) goto error;
84 hmapping = CreateFileMappingW(hfile, NULL, PAGE_READONLY, 0, 0, NULL);
85 if(!hmapping) goto error;
87 *buffer = MapViewOfFile(hmapping, FILE_MAP_READ, 0, 0, 0);
88 if(*buffer == NULL) goto error;
90 CloseHandle(hmapping);
91 CloseHandle(hfile);
93 return S_OK;
95 error:
96 CloseHandle(hmapping);
97 CloseHandle(hfile);
98 return HRESULT_FROM_WIN32(GetLastError());
101 /************************************************************
102 * load_resource_into_memory
104 * Loads a resource into buffer and stores the number of
105 * read bytes in length.
107 * PARAMS
108 * module [I] handle to the module
109 * resinfo [I] handle to the resource's information block
110 * buffer [O] pointer to destination buffer
111 * length [O] size of the obtained data
113 * RETURNS
114 * Success: D3D_OK
115 * Failure:
116 * See error codes for SizeofResource, LoadResource and LockResource
118 * NOTES
119 * The memory doesn't need to be freed by the caller manually
122 HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, LPVOID *buffer, DWORD *length)
124 HGLOBAL resource;
126 *length = SizeofResource(module, resinfo);
127 if(*length == 0) return HRESULT_FROM_WIN32(GetLastError());
129 resource = LoadResource(module, resinfo);
130 if( !resource ) return HRESULT_FROM_WIN32(GetLastError());
132 *buffer = LockResource(resource);
133 if(*buffer == NULL) return HRESULT_FROM_WIN32(GetLastError());
135 return S_OK;
139 /************************************************************
140 * get_format_info
142 * Returns information about the specified format.
143 * If the format is unsupported, it's filled with the D3DFMT_UNKNOWN desc.
145 * PARAMS
146 * format [I] format whose description is queried
147 * desc [O] pointer to a StaticPixelFormatDesc structure
150 const PixelFormatDesc *get_format_info(D3DFORMAT format)
152 unsigned int i = 0;
153 while(formats[i].format != format && formats[i].format != D3DFMT_UNKNOWN) i++;
154 if(formats[i].format == D3DFMT_UNKNOWN)
155 FIXME("Unknown format %#x\n", format);
156 return &formats[i];
159 const PixelFormatDesc *get_format_info_idx(int idx)
161 if(idx >= sizeof(formats) / sizeof(formats[0]))
162 return NULL;
163 if(formats[idx].format == D3DFMT_UNKNOWN)
164 return NULL;
165 return &formats[idx];
168 #define WINE_D3DX_TO_STR(x) case x: return #x
170 const char *debug_d3dxparameter_class(D3DXPARAMETER_CLASS c)
172 switch (c)
174 WINE_D3DX_TO_STR(D3DXPC_SCALAR);
175 WINE_D3DX_TO_STR(D3DXPC_VECTOR);
176 WINE_D3DX_TO_STR(D3DXPC_MATRIX_ROWS);
177 WINE_D3DX_TO_STR(D3DXPC_MATRIX_COLUMNS);
178 WINE_D3DX_TO_STR(D3DXPC_OBJECT);
179 WINE_D3DX_TO_STR(D3DXPC_STRUCT);
180 default:
181 FIXME("Unrecognized D3DXPARAMETER_CLASS %#x.\n", c);
182 return "unrecognized";
186 const char *debug_d3dxparameter_type(D3DXPARAMETER_TYPE t)
188 switch (t)
190 WINE_D3DX_TO_STR(D3DXPT_VOID);
191 WINE_D3DX_TO_STR(D3DXPT_BOOL);
192 WINE_D3DX_TO_STR(D3DXPT_INT);
193 WINE_D3DX_TO_STR(D3DXPT_FLOAT);
194 WINE_D3DX_TO_STR(D3DXPT_STRING);
195 WINE_D3DX_TO_STR(D3DXPT_TEXTURE);
196 WINE_D3DX_TO_STR(D3DXPT_TEXTURE1D);
197 WINE_D3DX_TO_STR(D3DXPT_TEXTURE2D);
198 WINE_D3DX_TO_STR(D3DXPT_TEXTURE3D);
199 WINE_D3DX_TO_STR(D3DXPT_TEXTURECUBE);
200 WINE_D3DX_TO_STR(D3DXPT_SAMPLER);
201 WINE_D3DX_TO_STR(D3DXPT_SAMPLER1D);
202 WINE_D3DX_TO_STR(D3DXPT_SAMPLER2D);
203 WINE_D3DX_TO_STR(D3DXPT_SAMPLER3D);
204 WINE_D3DX_TO_STR(D3DXPT_SAMPLERCUBE);
205 WINE_D3DX_TO_STR(D3DXPT_PIXELSHADER);
206 WINE_D3DX_TO_STR(D3DXPT_VERTEXSHADER);
207 WINE_D3DX_TO_STR(D3DXPT_PIXELFRAGMENT);
208 WINE_D3DX_TO_STR(D3DXPT_VERTEXFRAGMENT);
209 WINE_D3DX_TO_STR(D3DXPT_UNSUPPORTED);
210 default:
211 FIXME("Unrecognized D3DXPARAMETER_TYP %#x.\n", t);
212 return "unrecognized";
216 #undef WINE_D3DX_TO_STR