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

ddraw_main.c
Go to the documentation of this file.
00001 /* $Id: ddraw_main.c 49872 2010-11-30 16:29:49Z fireball $
00002  *
00003  * COPYRIGHT:            See COPYING in the top level directory
00004  * PROJECT:              ReactOS DirectX
00005  * FILE:                 ddraw/ddraw/ddraw_main.c
00006  * PURPOSE:              IDirectDraw7 Implementation
00007  * PROGRAMMER:           Magnus Olsen, Maarten Bosma
00008  *
00009  */
00010 
00011 /* TODO
00012  * add warper functions for dx 1 - 6
00013  * map the  DirectDraw4_Vtable, DirectDraw2_Vtable, DirectDraw_Vtable
00014  * table to right version of the functions
00015  */
00016 
00017 
00018 
00019 #include "rosdraw.h"
00020 
00021 #include <string.h>
00022 
00023 LPDDRAWI_DIRECTDRAW_INT
00024 internal_directdraw_int_alloc(LPDDRAWI_DIRECTDRAW_INT This)
00025 {
00026     LPDDRAWI_DIRECTDRAW_INT  newThis;
00027     DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT));
00028     if (newThis)
00029     {
00030         newThis->lpLcl = This->lpLcl;
00031         newThis->lpLink = This;
00032     }
00033 
00034     return  newThis;
00035 }
00036 
00037 HRESULT WINAPI
00038 Main_DirectDraw_QueryInterface (LPDDRAWI_DIRECTDRAW_INT This,
00039                                 REFIID id,
00040                                 LPVOID *obj)
00041 {
00042     HRESULT retVal = DD_OK;
00043 
00044     DX_WINDBG_trace();
00045 
00046     _SEH2_TRY
00047     {
00048         /* FIXME
00049             the D3D object can be optained from here
00050             Direct3D7
00051         */
00052         if (IsEqualGUID(&IID_IDirectDraw7, id))
00053         {
00054             if (This->lpVtbl != &DirectDraw7_Vtable)
00055             {
00056                 This = internal_directdraw_int_alloc(This);
00057                 if (!This)
00058                 {
00059                     retVal = DDERR_OUTOFVIDEOMEMORY;
00060                     _SEH2_LEAVE;
00061                 }
00062             }
00063 
00064             This->lpVtbl = &DirectDraw7_Vtable;
00065             *obj = This;
00066             Main_DirectDraw_AddRef(This);
00067         }
00068         else if (IsEqualGUID(&IID_IDirectDraw4, id))
00069         {
00070             if (This->lpVtbl != &DirectDraw4_Vtable)
00071             {
00072                 This = internal_directdraw_int_alloc(This);
00073                 if (!This)
00074                 {
00075                     retVal = DDERR_OUTOFVIDEOMEMORY;
00076                     _SEH2_LEAVE;
00077                 }
00078             }
00079 
00080             This->lpVtbl = &DirectDraw4_Vtable;
00081             *obj = This;
00082             Main_DirectDraw_AddRef(This);
00083         }
00084 
00085         else if (IsEqualGUID(&IID_IDirectDraw2, id))
00086         {
00087             if (This->lpVtbl != &DirectDraw2_Vtable)
00088             {
00089                 This = internal_directdraw_int_alloc(This);
00090                 if (!This)
00091                 {
00092                     retVal = DDERR_OUTOFVIDEOMEMORY;
00093                     _SEH2_LEAVE;
00094                 }
00095             }
00096 
00097             This->lpVtbl = &DirectDraw2_Vtable;
00098             *obj = This;
00099             Main_DirectDraw_AddRef(This);
00100         }
00101         else if (IsEqualGUID(&IID_IDirectDraw, id))
00102         {
00103             if (This->lpVtbl != &DirectDraw_Vtable)
00104             {
00105                 This = internal_directdraw_int_alloc(This);
00106                 if (!This)
00107                 {
00108                     retVal = DDERR_OUTOFVIDEOMEMORY;
00109                     _SEH2_LEAVE;
00110                 }
00111             }
00112 
00113             This->lpVtbl = &DirectDraw_Vtable;
00114             *obj = This;
00115             Main_DirectDraw_AddRef(This);
00116         }
00117         else
00118         {
00119             *obj = NULL;
00120             DX_STUB_str("E_NOINTERFACE");
00121             retVal = E_NOINTERFACE;
00122         }
00123     }
00124     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00125     {
00126     }
00127     _SEH2_END;
00128 
00129     return retVal;
00130 }
00131 
00132 /*++
00133 * @name DDraw->AddRef
00134 * @implemented
00135 *
00136 * The function DDraw->AddRef manages all ref counters in the COM object DDraw->
00137 
00138 * @return
00139 * Returns the local Ref counter value for the COM object
00140 *
00141 * @remarks.
00142 * none
00143 *
00144 *--*/
00145 ULONG WINAPI
00146 Main_DirectDraw_AddRef (LPDDRAWI_DIRECTDRAW_INT This)
00147 {
00148     ULONG retValue = 0;
00149 
00150     DX_WINDBG_trace();
00151 
00152     /* Lock the thread */
00153     AcquireDDThreadLock();
00154 
00155     _SEH2_TRY
00156     {
00157         /* Increment the internal ref counter */
00158         This->dwIntRefCnt++;
00159 
00160         /* Increment the local internal ref counter */
00161         This->lpLcl->dwLocalRefCnt++;
00162 
00163         if (This->lpLcl->lpGbl != NULL)
00164         {
00165             /* Increment the gobal internal ref counter */
00166             This->lpLcl->lpGbl->dwRefCnt++;
00167         }
00168     }
00169     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00170     {
00171     }
00172     _SEH2_END;
00173 
00174     _SEH2_TRY
00175     {
00176         retValue = This->dwIntRefCnt;
00177     }
00178     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00179     {
00180         retValue = 0;
00181     }
00182     _SEH2_END;
00183 
00184     /* Release the thread lock */
00185     ReleaseDDThreadLock();
00186 
00187     /* Return the local Ref counter */
00188     return retValue;
00189 }
00190 
00191 
00192 
00193 
00194 ULONG WINAPI
00195 Main_DirectDraw_Release (LPDDRAWI_DIRECTDRAW_INT This)
00196 {
00197     ULONG Counter = 0;
00198 
00199     DX_WINDBG_trace();
00200 
00201     /* Lock the thread */
00202     AcquireDDThreadLock();
00203 
00204     _SEH2_TRY
00205     {
00206         if (This!=NULL)
00207         {
00208             This->lpLcl->dwLocalRefCnt--;
00209             This->dwIntRefCnt--;
00210 
00211             if (This->lpLcl->lpGbl != NULL)
00212             {
00213                 This->lpLcl->lpGbl->dwRefCnt--;
00214             }
00215 
00216             if ( This->lpLcl->lpGbl->dwRefCnt == 0)
00217             {
00218                 // set resoltion back to the one in registry
00219                 /*if(This->cooperative_level & DDSCL_EXCLUSIVE)
00220                 {
00221                     ChangeDisplaySettings(NULL, 0);
00222                 }*/
00223 
00224                 Cleanup(This);
00225             }
00226 
00227             /* FIXME cleanup being not call why ?? */
00228             Counter = This->dwIntRefCnt;
00229         }
00230         else
00231         {
00232             Counter = This->dwIntRefCnt;
00233         }
00234     }
00235     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00236     {
00237     }
00238     _SEH2_END;
00239 
00240     /* Release the thread lock */
00241     ReleaseDDThreadLock();
00242 
00243     return Counter;
00244 }
00245 
00246 
00247 HRESULT WINAPI
00248 Main_DirectDraw_Initialize (LPDDRAWI_DIRECTDRAW_INT This, LPGUID lpGUID)
00249 {
00250     return DDERR_ALREADYINITIALIZED;
00251 }
00252 
00253 
00254 /*++
00255 * @name DDraw->Compact
00256 * @implemented
00257 *
00258 * In exlusive mode the function DDraw->Compact returns DERR_NOEXCLUSIVEMODE, otherwise it returns DD_OK
00259 *
00260 * @return
00261 * Returns only error code DD_OK or DERR_NOEXCLUSIVEMODE
00262 *
00263 * @remarks.
00264 *  Microsoft says Compact is not implemented in ddraw.dll, but it returns  DDERR_NOEXCLUSIVEMODE or DD_OK
00265 *
00266 *--*/
00267 HRESULT WINAPI
00268 Main_DirectDraw_Compact(LPDDRAWI_DIRECTDRAW_INT This)
00269 {
00270     HRESULT retVal = DD_OK;
00271 
00272     DX_WINDBG_trace();
00273 
00274     /* Lock the thread */
00275     AcquireDDThreadLock();
00276 
00277     _SEH2_TRY
00278     {
00279         /* Check if Exclusive mode has been activated */
00280         if (This->lpLcl->lpGbl->lpExclusiveOwner != This->lpLcl)
00281         {
00282             retVal = DDERR_NOEXCLUSIVEMODE;
00283         }
00284     }
00285     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00286     {
00287     }
00288     _SEH2_END;
00289 
00290     /* Release the thread lock */
00291     ReleaseDDThreadLock();
00292 
00293     return retVal;
00294 }
00295 
00296 HRESULT WINAPI
00297 Main_DirectDraw_GetAvailableVidMem(LPDDRAWI_DIRECTDRAW_INT This, LPDDSCAPS ddscaps, LPDWORD dwTotal, LPDWORD dwFree)
00298 {
00299     DDSCAPS2 myddscaps;
00300     HRESULT retValue = DD_OK;
00301 
00302     ZeroMemory(&myddscaps, sizeof(DDSCAPS2));
00303 
00304     _SEH2_TRY
00305     {
00306         myddscaps.dwCaps =  ddscaps->dwCaps;
00307         retValue = Main_DirectDraw_GetAvailableVidMem4(This, &myddscaps, dwTotal, dwFree);
00308     }
00309     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00310     {
00311          retValue = DDERR_INVALIDPARAMS;
00312     }
00313     _SEH2_END;
00314 
00315     return retValue;
00316 }
00317 
00318 HRESULT WINAPI
00319 Main_DirectDraw_GetAvailableVidMem4(LPDDRAWI_DIRECTDRAW_INT This, LPDDSCAPS2 ddscaps,
00320                    LPDWORD dwTotal, LPDWORD dwFree)
00321 {
00322     HRESULT retVal = DD_OK;
00323     DDHAL_GETAVAILDRIVERMEMORYDATA  memdata;
00324 
00325     DX_WINDBG_trace();
00326 
00327     _SEH2_TRY
00328     {
00329         // There is no HEL implentation of this api
00330         if (!(This->lpLcl->lpDDCB->HALDDMiscellaneous.dwFlags & DDHAL_MISCCB32_GETAVAILDRIVERMEMORY) ||
00331             (This->lpLcl->lpGbl->dwFlags & DDRAWI_NOHARDWARE) )
00332         {
00333             retVal = DDERR_NODIRECTDRAWHW;
00334         }
00335         else
00336         {
00337             if ((!dwTotal && !dwFree) || !ddscaps)
00338             {
00339                 retVal = DDERR_INVALIDPARAMS;
00340                 _SEH2_LEAVE;
00341             }
00342 
00343             if ( ddscaps->dwCaps & (DDSCAPS_BACKBUFFER  | DDSCAPS_COMPLEX   | DDSCAPS_FLIP |
00344                                     DDSCAPS_FRONTBUFFER | DDSCAPS_PALETTE   | DDSCAPS_SYSTEMMEMORY |
00345                                     DDSCAPS_VISIBLE     | DDSCAPS_WRITEONLY | DDSCAPS_OWNDC))
00346             {
00347                 retVal = DDERR_INVALIDPARAMS;
00348                 _SEH2_LEAVE;
00349             }
00350 
00351 
00352             /*   ddscaps->dwCaps2 & 0x01
00353                 this flag is outdate and are
00354                 set to 0 in ms dxsdk  the name of
00355                 this flag is DDSCAPS2_HARDWAREDEINTERLACE
00356             */
00357 
00358             if ( ddscaps->dwCaps2 & 0x01)
00359             {
00360                 retVal = DDERR_INVALIDCAPS;
00361                 _SEH2_LEAVE;
00362             }
00363 
00364             if ( ddscaps->dwCaps3 & ~( DDSCAPS3_MULTISAMPLE_QUALITY_MASK | DDSCAPS3_MULTISAMPLE_MASK |
00365                                        DDSCAPS3_RESERVED1                | DDSCAPS3_RESERVED2        |
00366                                        DDSCAPS3_LIGHTWEIGHTMIPMAP        | DDSCAPS3_AUTOGENMIPMAP    |
00367                                        DDSCAPS3_DMAP))
00368             {
00369                 retVal = DDERR_INVALIDCAPS;
00370                 _SEH2_LEAVE;
00371             }
00372 
00373             if ( ddscaps->dwCaps4)
00374             {
00375                 retVal = DDERR_INVALIDCAPS;
00376                 _SEH2_LEAVE;
00377             }
00378 
00379             ZeroMemory(&memdata, sizeof(DDHAL_GETAVAILDRIVERMEMORYDATA));
00380             memdata.lpDD = This->lpLcl->lpGbl;
00381             memdata.ddRVal = DDERR_INVALIDPARAMS;
00382 
00383             memdata.ddsCapsEx.dwCaps2 = ddscaps->dwCaps2;
00384             memdata.ddsCapsEx.dwCaps3 = ddscaps->dwCaps3;
00385 
00386             This->lpLcl->lpGbl->hDD = This->lpLcl->hDD;
00387 
00388             if (This->lpLcl->lpDDCB->HALDDMiscellaneous.GetAvailDriverMemory(&memdata) == DDHAL_DRIVER_NOTHANDLED)
00389             {
00390                 retVal = DDERR_NODIRECTDRAWHW;
00391 
00392                 if (dwTotal)
00393                     *dwTotal = 0;
00394 
00395                 if (dwFree)
00396                     *dwFree = 0;
00397             }
00398             else
00399             {
00400                 if (dwTotal)
00401                     *dwTotal = memdata.dwTotal;
00402 
00403                 if (dwFree)
00404                     *dwFree = memdata.dwFree;
00405 
00406                 retVal = memdata.ddRVal;
00407             }
00408         }
00409     }
00410     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00411     {
00412     }
00413     _SEH2_END;
00414 
00415     return retVal;
00416 }
00417 
00418 HRESULT WINAPI
00419 Main_DirectDraw_GetFourCCCodes(LPDDRAWI_DIRECTDRAW_INT This, LPDWORD lpNumCodes, LPDWORD lpCodes)
00420 {
00421     HRESULT retVal = DD_OK;
00422 
00423     DX_WINDBG_trace();
00424 
00425 
00426      // EnterCriticalSection(&ddcs);
00427 
00428     _SEH2_TRY
00429     {
00430         if(IsBadWritePtr(lpNumCodes,sizeof(LPDWORD)))
00431         {
00432             retVal = DDERR_INVALIDPARAMS;
00433         }
00434         else
00435         {
00436             if(!(IsBadWritePtr(lpNumCodes,sizeof(LPDWORD))))
00437             {
00438                 DWORD size;
00439 
00440                 if (*lpNumCodes > This->lpLcl->lpGbl->dwNumFourCC)
00441                 {
00442                     *lpNumCodes = This->lpLcl->lpGbl->dwNumFourCC;
00443                 }
00444 
00445                 size =  *lpNumCodes * sizeof(DWORD);
00446 
00447                 if(!IsBadWritePtr(lpCodes, size ))
00448                 {
00449                     memcpy(lpCodes, This->lpLcl->lpGbl->lpdwFourCC, size );
00450                 }
00451                 else
00452                 {
00453                     *lpNumCodes = This->lpLcl->lpGbl->dwNumFourCC;
00454                 }
00455             }
00456         }
00457     }
00458     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00459     {
00460     }
00461     _SEH2_END;
00462 
00463     //LeaveCriticalSection(&ddcs);
00464     return retVal;
00465 }
00466 
00467 
00468 /*
00469  * We can optain the version of the directdraw object by compare the
00470  * vtl table pointer from iface we do not need pass which version
00471  * we whant to use
00472  *
00473  * Main_DirectDraw_CreateSurface is dead at moment we do only support
00474  * directdraw 7 at moment
00475  */
00476 
00477 /* For DirectDraw 1 - 3 */
00478 HRESULT WINAPI
00479 Main_DirectDraw_CreateSurface (LPDDRAWI_DIRECTDRAW_INT This, LPDDSURFACEDESC pDDSD,
00480                                LPDDRAWI_DDRAWSURFACE_INT *ppSurf, IUnknown *pUnkOuter)
00481 {
00482    HRESULT ret = DDERR_GENERIC;
00483    DDSURFACEDESC2 dd_desc_v2;
00484 
00485    DX_WINDBG_trace();
00486 
00487     EnterCriticalSection(&ddcs);
00488     *ppSurf = NULL;
00489 
00490     _SEH2_TRY
00491     {
00492         if (pDDSD->dwSize == sizeof(DDSURFACEDESC))
00493         {
00494             CopyDDSurfDescToDDSurfDesc2(&dd_desc_v2, (LPDDSURFACEDESC)pDDSD);
00495             ret = Internal_CreateSurface(This,
00496                                          &dd_desc_v2,
00497                                          ppSurf,
00498                                          pUnkOuter);
00499         }
00500         else
00501         {
00502             ret = DDERR_INVALIDPARAMS;
00503         }
00504     }
00505     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00506     {
00507         ret = DDERR_INVALIDPARAMS;
00508     }
00509     _SEH2_END;
00510     LeaveCriticalSection(&ddcs);
00511     return ret;
00512 }
00513 
00514 
00515 /* For DirectDraw 4 - 7 */
00516 HRESULT WINAPI
00517 Main_DirectDraw_CreateSurface4(LPDDRAWI_DIRECTDRAW_INT This, LPDDSURFACEDESC2 pDDSD,
00518                                LPDDRAWI_DDRAWSURFACE_INT *ppSurf, IUnknown *pUnkOuter)
00519 {
00520     HRESULT ret = DD_OK;
00521     DX_WINDBG_trace();
00522 
00523     EnterCriticalSection(&ddcs);
00524     *ppSurf = NULL;
00525 
00526     _SEH2_TRY
00527     {
00528         ret = Internal_CreateSurface(This, pDDSD, ppSurf, pUnkOuter);
00529     }
00530     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00531     {
00532         ret = DDERR_INVALIDPARAMS;
00533     }
00534     _SEH2_END;
00535 
00536     if(*ppSurf != NULL)
00537         Main_DirectDraw_AddRef(This);
00538 
00539     LeaveCriticalSection(&ddcs);
00540     return ret;
00541 }
00542 
00543 /* 5 of 31 DirectDraw7_Vtable api are working simluare to windows */
00544 /* 8 of 31 DirectDraw7_Vtable api are under devloping / testing */
00545 
00546 HRESULT WINAPI Main_DirectDraw_CreatePalette(LPDDRAWI_DIRECTDRAW_INT This, DWORD dwFlags,
00547                   LPPALETTEENTRY palent, LPDIRECTDRAWPALETTE* ppPalette, LPUNKNOWN pUnkOuter)
00548 {
00549     HRESULT ret = DD_OK;
00550     DX_WINDBG_trace();
00551 
00552     EnterCriticalSection(&ddcs);
00553     *ppPalette = NULL;
00554 
00555     _SEH2_TRY
00556     {
00557         ret = Internal_CreatePalette(This, dwFlags, palent, ppPalette, pUnkOuter);
00558     }
00559     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00560     {
00561         ret = DDERR_INVALIDPARAMS;
00562     }
00563     _SEH2_END;
00564 
00565     //Versions 7 and 4 are addref'ed
00566     if((This->lpVtbl == &DirectDraw7_Vtable || This->lpVtbl == &DirectDraw4_Vtable) && *ppPalette != NULL)
00567         Main_DirectDraw_AddRef(This) ;
00568 
00569     LeaveCriticalSection(&ddcs);
00570     return ret;
00571 }
00572 
00573 
00574 
00575 
00576 
00577 
00578 

Generated on Sat May 26 2012 04:19:59 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.