📄 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 <windows.h>
#include "rosdraw.h"
#include "d3dhal.h"
#include "ddrawgdi.h"
DDRAWI_DIRECTDRAW_GBL ddgbl;
DDRAWI_DDRAWSURFACE_GBL ddSurfGbl;
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;
DEVMODE devmode;
HBITMAP hbmp;
const UINT bmiSize = sizeof(BITMAPINFOHEADER) + 0x10;
UCHAR *pbmiData;
BITMAPINFO *pbmi;
DWORD *pMasks;
INT devicetypes = 0;
DWORD dwFlags = 0;
DX_WINDBG_trace();
if (reenable == FALSE)
{
if (This->lpLink == NULL)
{
RtlZeroMemory(&ddgbl, sizeof(DDRAWI_DIRECTDRAW_GBL));
This->lpLcl->lpGbl->dwRefCnt++;
if (ddgbl.lpDDCBtmp == NULL)
{
ddgbl.lpDDCBtmp = (LPDDHAL_CALLBACKS) DxHeapMemAlloc(sizeof(DDHAL_CALLBACKS));
if (ddgbl.lpDDCBtmp == NULL)
{
DX_STUB_str("Out of memmory");
return DD_FALSE;
}
}
}
}
/*
Visual studio think this code is a break point if we call
second time to this function, press on continue in visual
studio the program will work. No real bug. gcc 3.4.5 genreate
code that look like MS visual studio break point.
*/
This->lpLcl->lpDDCB = ddgbl.lpDDCBtmp;
/* Same for HEL and HAL */
if (ddgbl.lpModeInfo == NULL)
{
ddgbl.lpModeInfo = (DDHALMODEINFO*) DxHeapMemAlloc(1 * sizeof(DDHALMODEINFO));
if (ddgbl.lpModeInfo == NULL)
{
DX_STUB_str("DD_FALSE");
return DD_FALSE;
}
}
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);
This->lpLcl->lpGbl->lpModeInfo[0].dwWidth = devmode.dmPelsWidth;
This->lpLcl->lpGbl->lpModeInfo[0].dwHeight = devmode.dmPelsHeight;
This->lpLcl->lpGbl->lpModeInfo[0].dwBPP = devmode.dmBitsPerPel;
This->lpLcl->lpGbl->lpModeInfo[0].lPitch = (devmode.dmPelsWidth*devmode.dmBitsPerPel)/8;
This->lpLcl->lpGbl->lpModeInfo[0].wRefreshRate = (WORD)devmode.dmDisplayFrequency;
if (reenable == FALSE)
{
if (lpGuid == NULL)
{
devicetypes = 1;
/* Create HDC for default, hal and hel driver */
This->lpLcl->hDC = (ULONG_PTR) CreateDCW(L"DISPLAY",L"DISPLAY",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 and hel driver */
This->lpLcl->hDC = (ULONG_PTR)CreateDCW(L"DISPLAY",L"DISPLAY",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->hDC = (ULONG_PTR) CreateDCW(L"DISPLAY",L"DISPLAY",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 ;
}
if ( (HDC)This->lpLcl->hDC == NULL)
{
DX_STUB_str("DDERR_OUTOFMEMORY");
return DDERR_OUTOFMEMORY ;
}
}
hbmp = CreateCompatibleBitmap((HDC) This->lpLcl->hDC, 1, 1);
if (hbmp==NULL)
{
DxHeapMemFree(This->lpLcl->lpGbl->lpModeInfo);
DeleteDC((HDC) This->lpLcl->hDC);
DX_STUB_str("DDERR_OUTOFMEMORY");
return DDERR_OUTOFMEMORY;
}
pbmiData = (UCHAR *) DxHeapMemAlloc(bmiSize);
pbmi = (BITMAPINFO*)pbmiData;
if (pbmiData==NULL)
{
DxHeapMemFree(This->lpLcl->lpGbl->lpModeInfo);
DeleteDC((HDC) This->lpLcl->hDC);
DeleteObject(hbmp);
DX_STUB_str("DDERR_OUTOFMEMORY");
return DDERR_OUTOFMEMORY;
}
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biBitCount = (WORD)devmode.dmBitsPerPel;
pbmi->bmiHeader.biCompression = BI_BITFIELDS;
pbmi->bmiHeader.biWidth = 1;
pbmi->bmiHeader.biHeight = 1;
GetDIBits((HDC) This->lpLcl->hDC, hbmp, 0, 0, NULL, pbmi, 0);
DeleteObject(hbmp);
pMasks = (DWORD*)(pbmiData + sizeof(BITMAPINFOHEADER));
This->lpLcl->lpGbl->lpModeInfo[0].dwRBitMask = pMasks[0];
This->lpLcl->lpGbl->lpModeInfo[0].dwGBitMask = pMasks[1];
This->lpLcl->lpGbl->lpModeInfo[0].dwBBitMask = pMasks[2];
This->lpLcl->lpGbl->lpModeInfo[0].dwAlphaBitMask = pMasks[3];
DxHeapMemFree(pbmiData);
/* Startup HEL and HAL */
// RtlZeroMemory(&ddgbl, sizeof(DDRAWI_DIRECTDRAW_GBL));
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");
return DDERR_NODIRECTDRAWSUPPORT;
}
dwFlags |= DDRAWI_NOHARDWARE;
}
if (hel_ret!=DD_OK)
{
dwFlags |= DDRAWI_NOEMULATION;
}
else
{
dwFlags |= DDRAWI_EMULATIONINITIALIZED;
}
This->lpLcl->lpGbl->dwFlags = dwFlags | DDRAWI_ATTACHEDTODESKTOP;
This->lpLcl->hDD = This->lpLcl->lpGbl->hDD;
/* Mix the DDCALLBACKS */
This->lpLcl->lpDDCB = This->lpLcl->lpGbl->lpDDCBtmp;
This->lpLcl->lpDDCB->cbDDCallbacks.dwSize = sizeof(This->lpLcl->lpDDCB->cbDDCallbacks);
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_CANCREATESURFACE) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_CANCREATESURFACE;
This->lpLcl->lpDDCB->cbDDCallbacks.CanCreateSurface = This->lpLcl->lpDDCB->HALDD.CanCreateSurface;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_CANCREATESURFACE) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_CANCREATESURFACE;
This->lpLcl->lpDDCB->cbDDCallbacks.CanCreateSurface = This->lpLcl->lpDDCB->HELDD.CanCreateSurface;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_CREATESURFACE) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_CREATESURFACE;
This->lpLcl->lpDDCB->cbDDCallbacks.CreateSurface = This->lpLcl->lpDDCB->HALDD.CreateSurface;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_CREATESURFACE) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_CREATESURFACE;
This->lpLcl->lpDDCB->cbDDCallbacks.CreateSurface = This->lpLcl->lpDDCB->HELDD.CreateSurface;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_CREATEPALETTE) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_CREATEPALETTE;
This->lpLcl->lpDDCB->cbDDCallbacks.CreatePalette = This->lpLcl->lpDDCB->HALDD.CreatePalette;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_CREATEPALETTE) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_CREATEPALETTE;
This->lpLcl->lpDDCB->cbDDCallbacks.CreatePalette = This->lpLcl->lpDDCB->HELDD.CreatePalette;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_DESTROYDRIVER) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_DESTROYDRIVER;
This->lpLcl->lpDDCB->cbDDCallbacks.DestroyDriver = This->lpLcl->lpDDCB->HALDD.DestroyDriver;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_DESTROYDRIVER) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_DESTROYDRIVER;
This->lpLcl->lpDDCB->cbDDCallbacks.DestroyDriver = This->lpLcl->lpDDCB->HELDD.DestroyDriver;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_FLIPTOGDISURFACE) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_FLIPTOGDISURFACE;
This->lpLcl->lpDDCB->cbDDCallbacks.FlipToGDISurface = This->lpLcl->lpDDCB->HALDD.FlipToGDISurface;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_FLIPTOGDISURFACE) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_FLIPTOGDISURFACE;
This->lpLcl->lpDDCB->cbDDCallbacks.FlipToGDISurface = This->lpLcl->lpDDCB->HELDD.FlipToGDISurface;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_GETSCANLINE) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_GETSCANLINE;
This->lpLcl->lpDDCB->cbDDCallbacks.GetScanLine = This->lpLcl->lpDDCB->HALDD.GetScanLine;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_GETSCANLINE) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_GETSCANLINE;
This->lpLcl->lpDDCB->cbDDCallbacks.GetScanLine = This->lpLcl->lpDDCB->HELDD.GetScanLine;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_SETCOLORKEY) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_SETCOLORKEY;
This->lpLcl->lpDDCB->cbDDCallbacks.SetColorKey = This->lpLcl->lpDDCB->HALDD.SetColorKey;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_SETCOLORKEY) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_SETCOLORKEY;
This->lpLcl->lpDDCB->cbDDCallbacks.SetColorKey = This->lpLcl->lpDDCB->HELDD.SetColorKey;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_SETEXCLUSIVEMODE) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_SETEXCLUSIVEMODE;
This->lpLcl->lpDDCB->cbDDCallbacks.SetExclusiveMode = This->lpLcl->lpDDCB->HALDD.SetExclusiveMode;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_SETEXCLUSIVEMODE) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_SETEXCLUSIVEMODE;
This->lpLcl->lpDDCB->cbDDCallbacks.SetExclusiveMode = This->lpLcl->lpDDCB->HELDD.SetExclusiveMode;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_SETMODE) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_SETMODE;
This->lpLcl->lpDDCB->cbDDCallbacks.SetMode = This->lpLcl->lpDDCB->HALDD.SetMode;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_SETMODE) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_SETMODE;
This->lpLcl->lpDDCB->cbDDCallbacks.SetMode = This->lpLcl->lpDDCB->HELDD.SetMode;
}
if ((This->lpLcl->lpDDCB->HALDD.dwFlags & DDHAL_CB32_WAITFORVERTICALBLANK) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_WAITFORVERTICALBLANK;
This->lpLcl->lpDDCB->cbDDCallbacks.WaitForVerticalBlank =
This->lpLcl->lpDDCB->HALDD.WaitForVerticalBlank;
}
else if ((This->lpLcl->lpDDCB->HELDD.dwFlags & DDHAL_CB32_WAITFORVERTICALBLANK) && (devicetypes !=2))
{
This->lpLcl->lpDDCB->cbDDCallbacks.dwFlags |= DDHAL_CB32_WAITFORVERTICALBLANK;
This->lpLcl->lpDDCB->cbDDCallbacks.WaitForVerticalBlank =
This->lpLcl->lpDDCB->HELDD.WaitForVerticalBlank;
}
/* Mix the DDSURFACE CALLBACKS */
This->lpLcl->lpDDCB->cbDDSurfaceCallbacks.dwSize = sizeof(This->lpLcl->lpDDCB->cbDDSurfaceCallbacks);
if ((This->lpLcl->lpDDCB->HALDDSurface.dwFlags & DDHAL_SURFCB32_ADDATTACHEDSURFACE) && (devicetypes !=3))
{
This->lpLcl->lpDDCB->cbDDSurfaceCallbacks.dwFlags |= DDHAL_SURFCB32_ADDATTACHEDSURFACE;
This->lpLcl->lpDDCB->cbDDSurfaceCallbacks.AddAttachedSurface =
This->lpLcl->lpDDCB->HALDDSurface.AddAttachedSurface;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -