📄 startup.c
字号:
/* $Id: main.c 21434 2006-04-01 19:12:56Z greatlrd $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: lib/ddraw/ddraw.c
* PURPOSE: DirectDraw Library
* PROGRAMMER: Magnus Olsen (greatlrd)
*
*/
#include "rosdraw.h"
#include "ddrawgdi.h"
DDRAWI_DIRECTDRAW_GBL ddgbl;
DDRAWI_DDRAWSURFACE_GBL ddSurfGbl;
WCHAR classname[128];
WNDCLASSW wnd_class;
HRESULT WINAPI
Create_DirectDraw (LPGUID pGUID, LPDIRECTDRAW* pIface,
REFIID id, BOOL reenable)
{
LPDDRAWI_DIRECTDRAW_INT This;
DX_WINDBG_trace();
if ((IsBadReadPtr(pIface,sizeof(LPDIRECTDRAW))) ||
(IsBadWritePtr(pIface,sizeof(LPDIRECTDRAW))))
{
return DDERR_INVALIDPARAMS;
}
This = (LPDDRAWI_DIRECTDRAW_INT)*pIface;
/* fixme linking too second link when we shall not doing it */
if (IsBadReadPtr(This,sizeof(LPDIRECTDRAW)))
{
/* We do not have a DirectDraw interface, we need alloc it*/
LPDDRAWI_DIRECTDRAW_INT memThis;
DX_STUB_str("1. no linking\n");
DxHeapMemAlloc(memThis, sizeof(DDRAWI_DIRECTDRAW_INT));
if (memThis == NULL)
{
return DDERR_OUTOFMEMORY;
}
This = memThis;
/* Fixme release memory alloc if we fail */
DxHeapMemAlloc(This->lpLcl, sizeof(DDRAWI_DIRECTDRAW_LCL));
if (This->lpLcl == NULL)
{
return DDERR_OUTOFMEMORY;
}
}
else
{
/* We got the DirectDraw interface alloc and we need create the link */
LPDDRAWI_DIRECTDRAW_INT newThis;
DX_STUB_str("2.linking\n");
/* step 1.Alloc the new DDRAWI_DIRECTDRAW_INT for the lnking */
DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT));
if (newThis == NULL)
{
return DDERR_OUTOFMEMORY;
}
/* step 2 check if it not DDCREATE_HARDWAREONLY we got if so we fail */
if ((pGUID) && (pGUID != (LPGUID)DDCREATE_HARDWAREONLY))
{
if (pGUID !=NULL)
{
This = newThis;
return DDERR_INVALIDDIRECTDRAWGUID;
}
}
/* step 3 do the link the old interface are store in the new one */
newThis->lpLink = This;
/* step 4 we need create new local directdraw struct for the new linked interface */
DxHeapMemAlloc(newThis->lpLcl, sizeof(DDRAWI_DIRECTDRAW_LCL));
if (newThis->lpLcl == NULL)
{
This = newThis;
return DDERR_OUTOFMEMORY;
}
This = newThis;
}
This->lpLcl->lpGbl = &ddgbl;
*pIface = (LPDIRECTDRAW)This;
/* Get right interface we whant */
This->lpVtbl = 0;
if (IsEqualGUID(&IID_IDirectDraw7, id))
{
/* DirectDraw7 Vtable */
This->lpVtbl = &DirectDraw7_Vtable;
This->lpLcl->dwLocalFlags = This->lpLcl->dwLocalFlags + DDRAWILCL_DIRECTDRAW7;
*pIface = (LPDIRECTDRAW)&This->lpVtbl;
Main_DirectDraw_AddRef(This);
}
else if (IsEqualGUID(&IID_IDirectDraw4, id))
{
/* DirectDraw4 Vtable */
This->lpVtbl = &DirectDraw4_Vtable;
*pIface = (LPDIRECTDRAW)&This->lpVtbl;
Main_DirectDraw_AddRef(This);
}
else if (IsEqualGUID(&IID_IDirectDraw2, id))
{
/* DirectDraw2 Vtable */
This->lpVtbl = &DirectDraw2_Vtable;
*pIface = (LPDIRECTDRAW)&This->lpVtbl;
Main_DirectDraw_AddRef(This);
}
else if (IsEqualGUID(&IID_IDirectDraw, id))
{
/* DirectDraw Vtable */
This->lpVtbl = &DirectDraw_Vtable;
*pIface = (LPDIRECTDRAW)&This->lpVtbl;
Main_DirectDraw_AddRef(This);
}
if ( This->lpVtbl != 0)
{
DX_STUB_str("Got iface\n");
if (StartDirectDraw((LPDIRECTDRAW)This, pGUID, FALSE) == DD_OK);
{
/*
RtlZeroMemory(&wnd_class, sizeof(wnd_class));
wnd_class.style = CS_HREDRAW | CS_VREDRAW;
wnd_class.lpfnWndProc = DefWindowProcW;
wnd_class.cbClsExtra = 0;
wnd_class.cbWndExtra = 0;
wnd_class.hInstance = GetModuleHandleW(0);
wnd_class.hIcon = 0;
wnd_class.hCursor = 0;
wnd_class.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wnd_class.lpszMenuName = NULL;
wnd_class.lpszClassName = classname;
if(!RegisterClassW(&wnd_class))
{
DX_STUB_str("DDERR_GENERIC");
return DDERR_GENERIC;
}
*/
This->lpLcl->hDD = ddgbl.hDD;
return DD_OK;
}
}
return DDERR_INVALIDPARAMS;
}
HRESULT WINAPI
StartDirectDraw(LPDIRECTDRAW iface, LPGUID lpGuid, BOOL reenable)
{
LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface;
DWORD hal_ret = DD_FALSE;
DWORD hel_ret = DD_FALSE;
DWORD devicetypes = 0;
DWORD dwFlags = 0;
DX_WINDBG_trace();
/*
* ddgbl.dwPDevice is not longer in use in windows 2000 and higher
* I am using it for device type
* devicetypes = 1 : both hal and hel are enable
* devicetypes = 2 : both hal are enable
* devicetypes = 3 : both hel are enable
* devicetypes = 4 :loading a guid drv from the register
*/
ddgbl.lpDriverHandle = &ddgbl;
ddgbl.hDDVxd = -1;
if (reenable == FALSE)
{
if ((!IsBadReadPtr(This->lpLink,sizeof(LPDIRECTDRAW))) && (This->lpLink == NULL))
{
RtlZeroMemory(&ddgbl, sizeof(DDRAWI_DIRECTDRAW_GBL));
This->lpLcl->lpGbl->dwRefCnt++;
if (ddgbl.lpDDCBtmp == NULL)
{
// LPDDHAL_CALLBACKS
DxHeapMemAlloc( ddgbl.lpDDCBtmp , sizeof(DDHAL_CALLBACKS));
if (ddgbl.lpDDCBtmp == NULL)
{
DX_STUB_str("Out of memmory\n");
return DD_FALSE;
}
}
}
DxHeapMemAlloc(ddgbl.lpModeInfo, sizeof(DDHALMODEINFO));
if (!ddgbl.lpModeInfo)
{
return DDERR_OUTOFMEMORY;
}
}
/* Windows handler are by set of SetCooperLevel
* so do not set it
*/
if (reenable == FALSE)
{
if (lpGuid == NULL)
{
devicetypes= 1;
/* Create HDC for default, hal and hel driver */
// This->lpLcl->hWnd = (ULONG_PTR) GetActiveWindow();
This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
/* cObsolete is undoc in msdn it being use in CreateDCA */
RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
}
else if (lpGuid == (LPGUID) DDCREATE_HARDWAREONLY)
{
devicetypes = 2;
/* Create HDC for default, hal driver */
// This->lpLcl->hWnd =(ULONG_PTR) GetActiveWindow();
This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
/* cObsolete is undoc in msdn it being use in CreateDCA */
RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
}
else if (lpGuid == (LPGUID) DDCREATE_EMULATIONONLY)
{
devicetypes = 3;
/* Create HDC for default, hal and hel driver */
//This->lpLcl->hWnd = (ULONG_PTR) GetActiveWindow();
This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
/* cObsolete is undoc in msdn it being use in CreateDCA */
RtlCopyMemory(&ddgbl.cObsolete,&"DISPLAY",7);
RtlCopyMemory(&ddgbl.cDriverName,&"DISPLAY",7);
dwFlags |= DDRAWI_DISPLAYDRV | DDRAWI_GDIDRV;
}
else
{
/* FIXME : need getting driver from the GUID that have been pass in from
* the register. we do not support that yet
*/
devicetypes = 4;
//This->lpLcl->hDC = (ULONG_PTR) NULL ;
//This->lpLcl->hDC = (ULONG_PTR)CreateDCA("DISPLAY",NULL,NULL,NULL);
}
/*
if ( (HDC)This->lpLcl->hDC == NULL)
{
DX_STUB_str("DDERR_OUTOFMEMORY\n");
return DDERR_OUTOFMEMORY ;
}
*/
}
This->lpLcl->lpDDCB = ddgbl.lpDDCBtmp;
/* Startup HEL and HAL */
This->lpLcl->lpDDCB = This->lpLcl->lpGbl->lpDDCBtmp;
This->lpLcl->dwProcessId = GetCurrentProcessId();
switch (devicetypes)
{
case 2:
hal_ret = StartDirectDrawHal(iface, reenable);
This->lpLcl->lpDDCB->HELDD.dwFlags = 0;
break;
case 3:
hel_ret = StartDirectDrawHel(iface, reenable);
This->lpLcl->lpDDCB->HALDD.dwFlags = 0;
break;
default:
hal_ret = StartDirectDrawHal(iface, reenable);
hel_ret = StartDirectDrawHel(iface, reenable);
}
if (hal_ret!=DD_OK)
{
if (hel_ret!=DD_OK)
{
DX_STUB_str("DDERR_NODIRECTDRAWSUPPORT\n");
return DDERR_NODIRECTDRAWSUPPORT;
}
dwFlags |= DDRAWI_NOHARDWARE;
}
if (hel_ret!=DD_OK)
{
dwFlags |= DDRAWI_NOEMULATION;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -