mfplat/sample: Optimize copying to 2d buffer.
[wine.git] / dlls / d3dxof / main.c
bloba3a3358dbd4cacdfcfec684d7f4da07a52c509c7
1 /*
2 * DirectX Files Functions (D3DXOF.DLL)
4 * Copyright 2004 Christian Costa
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
21 #include "d3dxof_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dxof);
25 /******************************************************************************
26 * DirectX File ClassFactory
28 typedef struct {
29 IClassFactory IClassFactory_iface;
31 LONG ref;
32 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
33 } IClassFactoryImpl;
35 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
37 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
40 struct object_creation_info
42 const CLSID *clsid;
43 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
46 static const struct object_creation_info object_creation[] =
48 { &CLSID_CDirectXFile, IDirectXFileImpl_Create },
51 static HRESULT WINAPI XFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppobj)
53 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
55 if (IsEqualGUID(riid, &IID_IUnknown)
56 || IsEqualGUID(riid, &IID_IClassFactory))
58 IClassFactory_AddRef(iface);
59 *ppobj = &This->IClassFactory_iface;
60 return S_OK;
63 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
64 return E_NOINTERFACE;
67 static ULONG WINAPI XFCF_AddRef(LPCLASSFACTORY iface)
69 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
70 return InterlockedIncrement(&This->ref);
73 static ULONG WINAPI XFCF_Release(LPCLASSFACTORY iface)
75 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
77 ULONG ref = InterlockedDecrement(&This->ref);
79 if (ref == 0)
80 HeapFree(GetProcessHeap(), 0, This);
82 return ref;
85 static HRESULT WINAPI XFCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
87 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
88 HRESULT hres;
89 LPUNKNOWN punk;
91 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
93 *ppobj = NULL;
94 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
95 if (SUCCEEDED(hres)) {
96 hres = IUnknown_QueryInterface(punk, riid, ppobj);
97 IUnknown_Release(punk);
99 return hres;
102 static HRESULT WINAPI XFCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
104 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
105 FIXME("(%p)->(%d), stub!\n",This,dolock);
106 return S_OK;
109 static const IClassFactoryVtbl XFCF_Vtbl =
111 XFCF_QueryInterface,
112 XFCF_AddRef,
113 XFCF_Release,
114 XFCF_CreateInstance,
115 XFCF_LockServer
118 /***********************************************************************
119 * DirectXFileCreate (D3DXOF.@)
121 HRESULT WINAPI DirectXFileCreate(LPDIRECTXFILE* lplpDirectXFile)
123 HRESULT hr;
125 TRACE("(%p)\n", lplpDirectXFile);
127 if (!lplpDirectXFile)
128 return DXFILEERR_BADVALUE;
130 hr = IDirectXFileImpl_Create(NULL, (LPVOID)lplpDirectXFile);
132 if (FAILED(hr))
133 return DXFILEERR_BADALLOC;
135 return S_OK;
138 /*******************************************************************************
139 * DllGetClassObject [D3DXOF.@]
140 * Retrieves class object from a DLL object
142 * NOTES
143 * Docs say returns STDAPI
145 * PARAMS
146 * rclsid [I] CLSID for the class object
147 * riid [I] Reference to identifier of interface for class object
148 * ppv [O] Address of variable to receive interface pointer for riid
150 * RETURNS
151 * Success: S_OK
152 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
153 * E_UNEXPECTED
155 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
157 unsigned int i;
158 IClassFactoryImpl *factory;
160 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
162 if ( !IsEqualGUID( &IID_IClassFactory, riid )
163 && ! IsEqualGUID( &IID_IUnknown, riid) )
164 return E_NOINTERFACE;
166 for (i = 0; i < ARRAY_SIZE(object_creation); i++)
168 if (IsEqualGUID(object_creation[i].clsid, rclsid))
169 break;
172 if (i == ARRAY_SIZE(object_creation))
174 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
175 return CLASS_E_CLASSNOTAVAILABLE;
178 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
179 if (factory == NULL) return E_OUTOFMEMORY;
181 factory->IClassFactory_iface.lpVtbl = &XFCF_Vtbl;
182 factory->ref = 1;
184 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
186 *ppv = &(factory->IClassFactory_iface);
187 return S_OK;