wined3d: Move shader caps setting into the arb and glsl shader backends.
[wine] / dlls / quartz / main.c
1 /*              DirectShow Base Functions (QUARTZ.DLL)
2  *
3  * Copyright 2002 Lionel Ulmer
4  *
5  * This file contains the (internal) driver registration functions,
6  * driver enumeration APIs and DirectDraw creation functions.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24 #include "wine/debug.h"
25
26 #include "quartz_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
29
30 static DWORD dll_ref = 0;
31
32 /* For the moment, do nothing here. */
33 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
34 {
35     switch(fdwReason) {
36         case DLL_PROCESS_ATTACH:
37             DisableThreadLibraryCalls(hInstDLL);
38             break;
39         case DLL_PROCESS_DETACH:
40             break;
41     }
42     return TRUE;
43 }
44
45 /******************************************************************************
46  * DirectShow ClassFactory
47  */
48 typedef struct {
49     IClassFactory ITF_IClassFactory;
50
51     LONG ref;
52     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
53 } IClassFactoryImpl;
54
55 struct object_creation_info
56 {
57     const CLSID *clsid;
58     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
59 };
60
61 static const struct object_creation_info object_creation[] =
62 {
63     { &CLSID_FilterGraph, FilterGraph_create },
64     { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
65     { &CLSID_FilterMapper, FilterMapper_create },
66     { &CLSID_FilterMapper2, FilterMapper2_create },
67     { &CLSID_AsyncReader, AsyncReader_create },
68     { &CLSID_MemoryAllocator, StdMemAllocator_create },
69     { &CLSID_AviSplitter, AVISplitter_create },
70     { &CLSID_MPEG1Splitter, MPEGSplitter_create },
71     { &CLSID_VideoRenderer, VideoRenderer_create },
72     { &CLSID_NullRenderer, NullRenderer_create },
73     { &CLSID_VideoRendererDefault, VideoRendererDefault_create },
74     { &CLSID_DSoundRender, DSoundRender_create },
75     { &CLSID_AVIDec, AVIDec_create },
76     { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
77     { &CLSID_ACMWrapper, &ACMWrapper_create },
78     { &CLSID_WAVEParser, &WAVEParser_create }
79 };
80
81 static HRESULT WINAPI
82 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
83 {
84     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
85
86     if (IsEqualGUID(riid, &IID_IUnknown)
87         || IsEqualGUID(riid, &IID_IClassFactory))
88     {
89         IClassFactory_AddRef(iface);
90         *ppobj = This;
91         return S_OK;
92     }
93
94     *ppobj = NULL;
95     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
96     return E_NOINTERFACE;
97 }
98
99 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
100 {
101     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
102     return InterlockedIncrement(&This->ref);
103 }
104
105 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
106 {
107     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
108
109     ULONG ref = InterlockedDecrement(&This->ref);
110
111     if (ref == 0)
112         CoTaskMemFree(This);
113
114     return ref;
115 }
116
117
118 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
119                                           REFIID riid, LPVOID *ppobj)
120 {
121     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
122     HRESULT hres;
123     LPUNKNOWN punk;
124     
125     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
126
127     *ppobj = NULL;
128     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
129     if (SUCCEEDED(hres)) {
130         hres = IUnknown_QueryInterface(punk, riid, ppobj);
131         IUnknown_Release(punk);
132     }
133     return hres;
134 }
135
136 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
137 {
138     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
139     FIXME("(%p)->(%d),stub!\n",This,dolock);
140     return S_OK;
141 }
142
143 static const IClassFactoryVtbl DSCF_Vtbl =
144 {
145     DSCF_QueryInterface,
146     DSCF_AddRef,
147     DSCF_Release,
148     DSCF_CreateInstance,
149     DSCF_LockServer
150 };
151
152 /*******************************************************************************
153  * DllGetClassObject [QUARTZ.@]
154  * Retrieves class object from a DLL object
155  *
156  * NOTES
157  *    Docs say returns STDAPI
158  *
159  * PARAMS
160  *    rclsid [I] CLSID for the class object
161  *    riid   [I] Reference to identifier of interface for class object
162  *    ppv    [O] Address of variable to receive interface pointer for riid
163  *
164  * RETURNS
165  *    Success: S_OK
166  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
167  *             E_UNEXPECTED
168  */
169 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
170 {
171     unsigned int i;
172     IClassFactoryImpl *factory;
173     
174     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
175     
176     if ( !IsEqualGUID( &IID_IClassFactory, riid )
177          && ! IsEqualGUID( &IID_IUnknown, riid) )
178         return E_NOINTERFACE;
179
180     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
181     {
182         if (IsEqualGUID(object_creation[i].clsid, rclsid))
183             break;
184     }
185
186     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
187     {
188         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
189         return CLASS_E_CLASSNOTAVAILABLE;
190     }
191
192     factory = CoTaskMemAlloc(sizeof(*factory));
193     if (factory == NULL) return E_OUTOFMEMORY;
194
195     factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
196     factory->ref = 1;
197
198     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
199
200     *ppv = &(factory->ITF_IClassFactory);
201     return S_OK;
202 }
203
204 /***********************************************************************
205  *              DllCanUnloadNow (QUARTZ.@)
206  */
207 HRESULT WINAPI DllCanUnloadNow(void)
208 {
209     return dll_ref != 0 ? S_FALSE : S_OK;
210 }
211
212
213 #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
214     { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } , #name },
215
216 static const struct {
217         const GUID      riid;
218         const char      *name;
219 } InterfaceDesc[] =
220 {
221 #include "uuids.h"
222     { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
223 };
224
225 /***********************************************************************
226  *              qzdebugstr_guid (internal)
227  *
228  * Gives a text version of DirectShow GUIDs
229  */
230 const char * qzdebugstr_guid( const GUID * id )
231 {
232     int i;
233     char * name = NULL;
234
235     for (i=0;InterfaceDesc[i].name && !name;i++) {
236         if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
237     }
238     return debugstr_guid(id);
239 }
240
241 /***********************************************************************
242  *              qzdebugstr_State (internal)
243  *
244  * Gives a text version of the FILTER_STATE enumeration
245  */
246 const char * qzdebugstr_State(FILTER_STATE state)
247 {
248     switch (state)
249     {
250     case State_Stopped:
251         return "State_Stopped";
252     case State_Running:
253         return "State_Running";
254     case State_Paused:
255         return "State_Paused";
256     default:
257         return "State_Unknown";
258     }
259 }
260
261 LONG WINAPI AmpFactorToDB(LONG ampfactor)
262 {
263     FIXME("(%d) Stub!\n", ampfactor);
264     return 0;
265 }
266
267 LONG WINAPI DBToAmpFactor(LONG db)
268 {
269     FIXME("(%d) Stub!\n", db);
270     /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
271     if (db < -1000)
272         return 0;
273     return 100;
274 }
275
276 /***********************************************************************
277  *              AMGetErrorTextA (QUARTZ.@)
278  */
279 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
280 {
281     int len;
282     static const char format[] = "Error: 0x%x";
283     char error[MAX_ERROR_TEXT_LEN];
284
285     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
286
287     if (!buffer) return 0;
288     wsprintfA(error, format, hr);
289     if ((len = lstrlenA(error)) >= maxlen) return 0; 
290     lstrcpyA(buffer, error);
291     return len;
292 }
293
294 /***********************************************************************
295  *              AMGetErrorTextW (QUARTZ.@)
296  */
297 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
298 {
299     int len;
300     static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
301     WCHAR error[MAX_ERROR_TEXT_LEN];
302
303     FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
304
305     if (!buffer) return 0;
306     wsprintfW(error, format, hr);
307     if ((len = lstrlenW(error)) >= maxlen) return 0; 
308     lstrcpyW(buffer, error);
309     return len;
310 }