ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

d3d9_swapchain.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS ReactX
00004  * FILE:            dll/directx/d3d9/d3d9_swapchain.c
00005  * PURPOSE:         Direct3D9's swap chain object
00006  * PROGRAMERS:      Gregor Gullwi <gbrunmar (dot) ros (at) gmail (dot) com>
00007  */
00008 #include "d3d9_swapchain.h"
00009 
00010 #include <debug.h>
00011 #include <ddraw.h>
00012 
00013 #include "d3d9_helpers.h"
00014 #include "d3d9_device.h"
00015 #include "d3d9_cursor.h"
00016 
00017 #define LOCK_D3DDEVICE9()   D3D9BaseObject_LockDevice(&This->BaseObject)
00018 #define UNLOCK_D3DDEVICE9() D3D9BaseObject_UnlockDevice(&This->BaseObject)
00019 
00020 /* Convert a IDirect3DSwapChain9 pointer safely to the internal implementation struct */
00021 LPDIRECT3DSWAPCHAIN9_INT IDirect3DSwapChain9ToImpl(LPDIRECT3DSWAPCHAIN9 iface)
00022 {
00023     if (NULL == iface)
00024         return NULL;
00025 
00026     return (LPDIRECT3DSWAPCHAIN9_INT)((ULONG_PTR)iface - FIELD_OFFSET(Direct3DSwapChain9_INT, lpVtbl));
00027 }
00028 
00029 /* IDirect3DSwapChain9: IUnknown implementation */
00030 static HRESULT WINAPI Direct3DSwapChain9_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, void** ppvObject)
00031 {
00032     LPDIRECT3DSWAPCHAIN9_INT This = IDirect3DSwapChain9ToImpl(iface);
00033 
00034     if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDirect3DSwapChain9))
00035     {
00036         IUnknown_AddRef(iface);
00037         *ppvObject = &This->lpVtbl;
00038         return S_OK;
00039     }
00040 
00041     *ppvObject = NULL;
00042     return E_NOINTERFACE;
00043 }
00044 
00045 static ULONG WINAPI Direct3DSwapChain9_AddRef(LPDIRECT3DSWAPCHAIN9 iface)
00046 {
00047     LPDIRECT3DSWAPCHAIN9_INT This = IDirect3DSwapChain9ToImpl(iface);
00048     return D3D9BaseObject_AddRef((D3D9BaseObject*) &This->BaseObject.lpVtbl);
00049 }
00050 
00051 static ULONG WINAPI Direct3DSwapChain9_Release(LPDIRECT3DSWAPCHAIN9 iface)
00052 {
00053     LPDIRECT3DSWAPCHAIN9_INT This = IDirect3DSwapChain9ToImpl(iface);
00054     return D3D9BaseObject_Release((D3D9BaseObject*) &This->BaseObject.lpVtbl);
00055 }
00056 
00057 /* IDirect3DSwapChain9 interface */
00058 static HRESULT WINAPI Direct3DSwapChain9_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion,DWORD dwFlags)
00059 {
00060     UNIMPLEMENTED
00061     return D3D_OK;
00062 }
00063 
00064 static HRESULT WINAPI Direct3DSwapChain9_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface)
00065 {
00066     UNIMPLEMENTED
00067     return D3D_OK;
00068 }
00069 
00070 static HRESULT WINAPI Direct3DSwapChain9_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer)
00071 {
00072     UNIMPLEMENTED
00073     return D3D_OK;
00074 }
00075 
00076 static HRESULT WINAPI Direct3DSwapChain9_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus)
00077 {
00078     UNIMPLEMENTED
00079     return D3D_OK;
00080 }
00081 
00082 static HRESULT WINAPI Direct3DSwapChain9_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode)
00083 {
00084     UNIMPLEMENTED
00085     return D3D_OK;
00086 }
00087 
00088 /*++
00089 * @name IDirect3DSwapChain9::GetDevice
00090 * @implemented
00091 *
00092 * The function Direct3DSwapChain9_GetDevice sets the ppDevice argument
00093 * to the device connected to create the swap chain.
00094 *
00095 * @param LPDIRECT3DSWAPCHAIN9 iface
00096 * Pointer to a IDirect3DSwapChain9 object returned from IDirect3D9Device::GetSwapChain()
00097 *
00098 * @param IDirect3DDevice9** ppDevice
00099 * Pointer to a IDirect3DDevice9* structure to be set to the device object.
00100 *
00101 * @return HRESULT
00102 * If the method successfully sets the ppDevice value, the return value is D3D_OK.
00103 * If ppDevice is a bad pointer the return value will be D3DERR_INVALIDCALL.
00104 * If the swap chain didn't contain any device, the return value will be D3DERR_INVALIDDEVICE.
00105 *
00106 */
00107 static HRESULT WINAPI Direct3DSwapChain9_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice)
00108 {
00109     LPDIRECT3DSWAPCHAIN9_INT This = IDirect3DSwapChain9ToImpl(iface);
00110     LOCK_D3DDEVICE9();
00111 
00112     if (NULL == ppDevice)
00113     {
00114         DPRINT1("Invalid ppDevice parameter specified");
00115         UNLOCK_D3DDEVICE9();
00116         return D3DERR_INVALIDCALL;
00117     }
00118 
00119     if (FAILED(D3D9BaseObject_GetDevice(&This->BaseObject, ppDevice)))
00120     {
00121         DPRINT1("Invalid This parameter speficied");
00122         UNLOCK_D3DDEVICE9();
00123         return D3DERR_INVALIDDEVICE;
00124     }
00125 
00126     UNLOCK_D3DDEVICE9();
00127     return D3D_OK;
00128 }
00129 
00130 /*++
00131 * @name IDirect3DSwapChain9::GetPresentParameters
00132 * @implemented
00133 *
00134 * The function Direct3DSwapChain9_GetPresentParameters fills the pPresentationParameters
00135 * argument with the D3DPRESENT_PARAMETERS parameters that was used to create the swap chain.
00136 *
00137 * @param LPDIRECT3DSWAPCHAIN9 iface
00138 * Pointer to a IDirect3DSwapChain9 object returned from IDirect3D9Device::GetSwapChain()
00139 *
00140 * @param D3DPRESENT_PARAMETERS* pPresentationParameters
00141 * Pointer to a D3DPRESENT_PARAMETERS structure to be filled with the creation parameters.
00142 *
00143 * @return HRESULT
00144 * If the method successfully fills the pPresentationParameters structure, the return value is D3D_OK.
00145 * If pPresentationParameters is a bad pointer the return value will be D3DERR_INVALIDCALL.
00146 *
00147 */
00148 static HRESULT WINAPI Direct3DSwapChain9_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters)
00149 {
00150     LPDIRECT3DSWAPCHAIN9_INT This = IDirect3DSwapChain9ToImpl(iface);
00151     LOCK_D3DDEVICE9();
00152 
00153     if (NULL == pPresentationParameters)
00154     {
00155         DPRINT1("Invalid pPresentationParameters parameter specified");
00156         UNLOCK_D3DDEVICE9();
00157         return D3DERR_INVALIDCALL;
00158     }
00159 
00160     *pPresentationParameters = This->PresentParameters;
00161 
00162     UNLOCK_D3DDEVICE9();
00163     return D3D_OK;
00164 }
00165 
00166 static IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
00167 {
00168     /* IUnknown */
00169     Direct3DSwapChain9_QueryInterface,
00170     Direct3DSwapChain9_AddRef,
00171     Direct3DSwapChain9_Release,
00172 
00173     /* IDirect3DSwapChain9 */
00174     Direct3DSwapChain9_Present,
00175     Direct3DSwapChain9_GetFrontBufferData,
00176     Direct3DSwapChain9_GetBackBuffer,
00177     Direct3DSwapChain9_GetRasterStatus,
00178     Direct3DSwapChain9_GetDisplayMode,
00179     Direct3DSwapChain9_GetDevice,
00180     Direct3DSwapChain9_GetPresentParameters,
00181 };
00182 
00183 Direct3DSwapChain9_INT* CreateDirect3DSwapChain9(enum REF_TYPE RefType, struct _Direct3DDevice9_INT* pBaseDevice, DWORD ChainIndex)
00184 {
00185     Direct3DSwapChain9_INT* pThisSwapChain;
00186     if (FAILED(AlignedAlloc((LPVOID*)&pThisSwapChain, sizeof(Direct3DSwapChain9_INT))))
00187     {
00188         DPRINT1("Could not create Direct3DSwapChain9_INT");
00189         return NULL;
00190     }
00191 
00192     InitD3D9BaseObject((D3D9BaseObject*) &pThisSwapChain->BaseObject.lpVtbl, RefType, (IUnknown*) &pBaseDevice->lpVtbl);
00193 
00194     pThisSwapChain->lpVtbl = &Direct3DSwapChain9_Vtbl;
00195 
00196     pThisSwapChain->ChainIndex = ChainIndex;
00197     pThisSwapChain->AdapterGroupIndex = ChainIndex;
00198     pThisSwapChain->pUnknown6BC = pBaseDevice->DeviceData[ChainIndex].pUnknown6BC;
00199     pThisSwapChain->pUnknown015c = (LPVOID)0xD3D9D3D9;
00200 
00201     return pThisSwapChain;
00202 }
00203 
00204 VOID Direct3DSwapChain9_SetDisplayMode(Direct3DSwapChain9_INT* pThisSwapChain, D3DPRESENT_PARAMETERS* pPresentationParameters)
00205 {
00206     pThisSwapChain->dwWidth = pPresentationParameters->BackBufferWidth;
00207     pThisSwapChain->dwHeight = pPresentationParameters->BackBufferHeight;
00208 }
00209 
00210 HRESULT Direct3DSwapChain9_Init(Direct3DSwapChain9_INT* pThisSwapChain, D3DPRESENT_PARAMETERS* pPresentationParameters)
00211 {
00212     int i;
00213     DIRECT3DDEVICE9_INT* pDevice;
00214 
00215     for (i = 0; i < 256; i++)
00216     {
00217         pThisSwapChain->GammaRamp.red[i] = 
00218             pThisSwapChain->GammaRamp.green[i] =
00219             pThisSwapChain->GammaRamp.blue[i] = i;
00220     }
00221 
00222     pThisSwapChain->PresentParameters = pPresentationParameters[pThisSwapChain->ChainIndex];
00223     pThisSwapChain->SwapEffect = pPresentationParameters->SwapEffect;
00224     Direct3DSwapChain9_SetDisplayMode(pThisSwapChain, &pThisSwapChain->PresentParameters);
00225     
00226     if (FAILED(D3D9BaseObject_GetDeviceInt(&pThisSwapChain->BaseObject, &pDevice)))
00227     {
00228         DPRINT1("Could not get the swapchain device");
00229         return DDERR_GENERIC;
00230     }
00231 
00232     pThisSwapChain->pCursor = CreateD3D9Cursor(pDevice, pThisSwapChain);
00233     if (NULL == pThisSwapChain->pCursor)
00234     {
00235         DPRINT1("Could not allocate D3D9Cursor");
00236         return DDERR_OUTOFMEMORY;
00237     }
00238 
00239     return Direct3DSwapChain9_Reset(pThisSwapChain, pPresentationParameters);
00240 }
00241 
00242 HRESULT Direct3DSwapChain9_Reset(Direct3DSwapChain9_INT* pThisSwapChain, D3DPRESENT_PARAMETERS* pPresentationParameters)
00243 {
00244     // TODO: Do all the dirty work...
00245     return D3D_OK;
00246 }
00247 
00248 VOID Direct3DSwapChain9_GetGammaRamp(Direct3DSwapChain9_INT* pThisSwapChain, D3DGAMMARAMP* pRamp)
00249 {
00250     memcpy(pRamp, &pThisSwapChain->GammaRamp, sizeof(D3DGAMMARAMP));
00251 }
00252 
00253 VOID Direct3DSwapChain9_SetGammaRamp(Direct3DSwapChain9_INT* pThisSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp)
00254 {
00255     UNIMPLEMENTED
00256 }

Generated on Sun May 27 2012 04:21:17 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.