📄 halsurf.cpp
字号:
/*
* $Workfile: halsurf.cpp $
* $Revision: 6 $
* $Date: 4/07/00 9:12a $
* $Modtime: 4/07/00 8:58a $
* $Author: Sarma $
*
* Copyright (c) 1998 National Semiconductor Corporation.
* All Rights Reserved.
*
* This software is the confidential and proprietary information of National
* Semiconductor Corporation. ("Confidential Information").
* You shall not disclose such Confidential Information and shall use it only
* in accordance with the terms of the license agreement you entered into
* with National Semiconductor Corporation.
* This code is supplied as is.
*
*/
/*
*$Log: /CE/Platform/Nsc/Drivers/Video/gxvideo/ddraw/halsurf.cpp $
*
* 6 4/07/00 9:12a Sarma
* Removed Cyrix Corporation from the legal/confidentail information. Also
* added for files not containing this info.
*
*$History: halsurf.cpp $
*
* ***************** Version 6 *****************
* User: Sarma Date: 4/07/00 Time: 9:12a
* Updated in $/CE/Platform/Nsc/Drivers/Video/gxvideo/ddraw
* Removed Cyrix Corporation from the legal/confidentail information. Also
* added for files not containing this info.
*
*/
#include "precomp.h"
#ifdef DURANGO
#include "gfx_rtns.h" //Durango includes
#endif
#ifdef DD_SUPPORT
#include "ddpalcur.h"
#include "vpe.h"
FLIPRECORD flipRecord;
//FLIPRECORD *pflipRecord;
OVERLAYDATA OverlayData;
OVERLAYDATA *pOverlayData;
OVERLAYDATA UnderlayData;
//OVERLAYDATA *pUnderlayData;
DDRAWDATA DriverData;//used to allocate memory for DDRAWDATA *
DDRAWDATA *pDriverData;
VPEDATA VPEData;
FLIPRECORD unflipRecord;
//FLIPRECORD *punflipRecord;
DWORD fourCC[] = {
FOURCC_YUY2,
FOURCC_YVYU,
FOURCC_UYVY,
FOURCC_EMMA
};
#define MAX_FOURCC sizeof(fourCC)/sizeof(DWORD)
//extern DWORD fourCC[4];
extern DWORD dwConnectionCaps;
extern pGPE;
// dummy pointer for EMMA surface
#define PTR_EMMA (FLATPTR)FOURCC_EMMA
int GUIDIndex = 0;
static BOOL fEMMA=FALSE;
DWORD TestVidMem;
void DhruvaSetBuffer(DWORD SizeBytes) {
// RETAILMSG(1,(TEXT("DhruvaSetBuffer\r\n")));
DWORD RegData;
DWORD VPStatus;
// Unlock
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, 0x4758);
// Calc and write out video buffer size in 64B granularity
RegData = MEM_READ_32(pDriverData->RegLinear, DC_BUF_SIZE);
VPStatus = MEM_READ_32(pDriverData->VIPLinear, 0x00000008);
//jp
VPStatus &= 0x00000001;
if(VPStatus == 1) {
SizeBytes = SizeBytes * 2;
}
MEM_WRITE_32(pDriverData->RegLinear, DC_BUF_SIZE, RegData |
((SizeBytes >> 6) << DC_VID_BUF_SZ_POS));
// Lock
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, 0x0);
return;
}
DWORD WINAPI HalFlipToGDISurface( LPDDHAL_FLIPTOGDISURFACEDATA pd )
{
DWORD RegGenData;
// RETAILMSG(1,(TEXT("HalFlipToGDISurface\r\n")));
//DEBUGENTER( HalFlipToGDISurface );
/*
typedef struct _DDHAL_FLIPTOGDISURFACEDATA
{
LPDDRAWI_DIRECTDRAW_GBL lpDD; // driver struct
DWORD dwToGDI; // TRUE if flipping to the GDI surface, FALSE if flipping away
DWORD dwReserved; // reserved for future use
HRESULT ddRVal; // return value
LPDDHAL_FLIPTOGDISURFACE FlipToGDISurface; // PRIVATE: ptr to callback
} DDHAL_FLIPTOGDISURFACEDATA;
*/
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, 0x4758);
// turn on the cursor.
RegGenData = MEM_READ_32(pDriverData->RegLinear, DC_GENERAL_CFG);
RegGenData |= 0x00000002;
MEM_WRITE_32(pDriverData->RegLinear, DC_GENERAL_CFG, RegGenData);
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, 0x0);
DDGPEFlipToGDISurface(pd);
pd->ddRVal = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD WINAPI HalCreateSurface( LPDDHAL_CREATESURFACEDATA pcsd )
{
//DebugBreak();
// DEBUGENTER( HalCreateSurface );
//RETAILMSG(1,(TEXT("pDriverData->RegLinear = %X\r\n"), pDriverData->RegLinear));
//RETAILMSG(1,(TEXT("pDriverData->FbLinear = %X\r\n"), pDriverData->FbLinear));
//RETAILMSG(1,(TEXT("pDriverData->dwWidth = %X\r\n"),pDriverData->dwWidth));
//RETAILMSG(1,(TEXT("pDriverData->dwHeight = %X\r\n"),pDriverData->dwHeight));
//RETAILMSG(1,(TEXT("pDriverData->lPitch = %X\r\n"),pDriverData->lPitch));
//RETAILMSG(1,(TEXT("pDriverData->dwBPP = %X\r\n"),pDriverData->dwBpp));
//RETAILMSG(1,(TEXT("pDriverData->dwRefreshRate = %X\r\n"),pDriverData->dwRefreshRate));
/*
typedef struct _DDHAL_CREATESURFACEDATA
{
LPDDRAWI_DIRECTDRAW_GBL lpDD; // driver struct
LPDDSURFACEDESC lpDDSurfaceDesc;// description of surface being created
LPDDRAWI_DDRAWSURFACE_LCL FAR *lplpSList; // list of created surface objects
DWORD dwSCnt; // number of surfaces in SList
HRESULT ddRVal; // return value
LPDDHAL_CREATESURFACE CreateSurface; // PRIVATE: ptr to callback
} DDHAL_CREATESURFACEDATA;
*/
// Implementation
//pd->ddRVal = DD_OK;
//
//return DDHAL_DRIVER_HANDLED;
SCODE sc;
LPDDRAWI_DIRECTDRAW_GBL pdrv;
BOOL handled;
int i;
LPDDRAWI_DDRAWSURFACE_LCL psurf;
LPDDRAWI_DDRAWSURFACE_GBL psurf_gbl;
DWORD width;
DWORD RegGenData;
int Width;
int Height;
DDGPESurf *pDDGPESurf;
EGPEFormat Format;
EDDGPEPixelFormat PixelFormat;
/*
* NOTES:
*
* This callback is invoked once the surface objects have been created.
* You can:
* - compute the size of the block, by returning
* DDHAL_PLEASEALLOC_BLOCKSIZE in fpVidMem, and putting the size
* in dwBlockSizeX and dwBlockSizeY
* - override some fields in the surface structure, like the pitch.
* (you must specifiy the pitch if you are computing the size)
*/
pdrv = pcsd->lpDD;
//DPF( "in CreateSurface, pcsd->lpDD=%08lx, pcsd->lpDDSurfaceDesc = %08lx",
// pdrv, pcsd->lpDDSurfaceDesc );
//DPF( "pcsd->lplpSList=%08lx, pcsd->dwSCnt = %d", pcsd->lplpSList, pcsd->dwSCnt );
/*
* see if any of these surfaces are FOURCC codes...
*/
handled = FALSE;
for( i=0;i<(int)pcsd->dwSCnt;i++ )
{
psurf = pcsd->lplpSList[i];
psurf_gbl = psurf->lpGbl;
//psurf_gbl->fpVidMem = pDriverData->FbLinear; //ullas - temp
//DPF( "psurf=%08lx, psurf->lpGbl=%08lx", psurf, psurf_gbl );
/*
* Major hack to get around a Microsoft Rectangular Memory Manager
* bug. It seems that with complex offscreen surfaces the pitch field
* is carried over from the primary surface pitch witch won't work.
* The memory manager special cases the primary surface so the
* the real pitch can be used but on all other surfaces the pitch
* must be width*bpp.
*/
if(pcsd->lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_OVERLAY)
{
// if( (pcsd->lpDDSurfaceDesc->dwFlags & DDRAWISURF_HASPIXELFORMAT) &&
// (pcsd->lpDDSurfaceDesc->ddpfSurface.dwFlags & DDPF_FOURCC) )
// {
/*
* we know the FOURCC code is OK, because we validated it
* during CanCreateSurface. Compute a block size based
* on the code, and ask DirectDraw to allocate the block for
* us.
*
* NOTE: BLOCKSIZE IS JUST A MADE UP NUMBER. THE REAL SIZE
* OF THE BLOCK NEEDS TO BE COMPUTED.
*/
switch( psurf_gbl->ddpfSurface.dwFourCC )
{
case FOURCC_YVYU:
OverlayData.VidFormat = YVYU;
psurf_gbl->ddpfSurface.dwYUVBitCount = 16;
PixelFormat = ddgpePixelFormat_YUYV422;
break;
case FOURCC_YUY2:
OverlayData.VidFormat = YUYV;
psurf_gbl->ddpfSurface.dwYUVBitCount = 8;
PixelFormat = ddgpePixelFormat_YUYV422;
break;
case FOURCC_UYVY:
OverlayData.VidFormat = UYVY;
psurf_gbl->ddpfSurface.dwYUVBitCount = 16;
PixelFormat = ddgpePixelFormat_UYVY422;
break;
// Added the foll. -Balaji
case FOURCC_EMMA:
OverlayData.VidFormat = EMMA;
//This line is bogus...
psurf_gbl->ddpfSurface.dwYUVBitCount = 8;
PixelFormat = ddgpePixelFormat_YUYV422;
break;
case FOURCC_YUYV:
OverlayData.VidFormat = YUYV;
psurf_gbl->ddpfSurface.dwYUVBitCount = 8;
PixelFormat = ddgpePixelFormat_YUYV422;
break;
default:
OverlayData.VidFormat = RGB8;
PixelFormat = ddgpePixelFormat_565;
}
/* else
{
//DPF( "RGB OK!" );
OverlayData.VidFormat = RGB8;
PixelFormat = ddgpePixelFormat_565;
}
*/
Format = EDDGPEPixelFormatToEGPEFormat[PixelFormat];
//
// Get width and height.
//
Width = (pcsd->lpDDSurfaceDesc->dwFlags & DDSD_WIDTH) ?
(pcsd->lpDDSurfaceDesc->dwWidth) : g_pGPE->ScreenWidth();
// Width = pcsd->lpDDSurfaceDesc->dwWidth;
Height = (pcsd->lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT) ?
(pcsd->lpDDSurfaceDesc->dwHeight) : g_pGPE->ScreenHeight();
// Height = pcsd->lpDDSurfaceDesc->dwHeight;
if ( Width >= 640 ){
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, 0x4758);
// turn off the cursor.
RegGenData = MEM_READ_32(pDriverData->RegLinear, DC_GENERAL_CFG);
RegGenData &= 0xfffffffd;
MEM_WRITE_32(pDriverData->RegLinear, DC_GENERAL_CFG, RegGenData);
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, 0x0);
}
// Added the foll. -Balaji
if (psurf_gbl->ddpfSurface.dwFourCC == FOURCC_EMMA)
psurf_gbl->fpVidMem = PTR_EMMA;
else {
// psurf_gbl->fpVidMem = (FLATPTR) DDHAL_PLEASEALLOC_BLOCKSIZE;
GPE *pGPE = GetGPE();
sc = ((GxVideo *)pGPE)->AllocOverlaySurface(
&pDDGPESurf,
Width,
Height,
Format,
PixelFormat,
GPE_REQUIRE_VIDEO_MEMORY);
if (!(FAILED(sc))) {
// Associate DDGPESurf with DD surface.
psurf_gbl->dwReserved1 = (DWORD) pDDGPESurf;
// Associate DD surface with DDGPESurf.
pDDGPESurf->lpDDSurface = psurf_gbl;
psurf_gbl->fpVidMem = (ULONG) (g_pVideoMemory +
pDDGPESurf->OffsetInVideoMemory());
psurf_gbl->lPitch = pDDGPESurf->Stride();
// RETAILMSG(1,(TEXT("TestVidMem = %08x\r\n"),TestVidMem));
TestVidMem=psurf_gbl->fpVidMem;
// RETAILMSG(1,(TEXT("TestVidMem = %08x\r\n"),TestVidMem));
// RETAILMSG(1,(TEXT("psurf->lpGbl->fpVidMem = %08x\r\n"),psurf->lpGbl->fpVidMem));
pcsd->lpDDSurfaceDesc->ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
}
else if (sc == E_OUTOFMEMORY) {
sc = DDERR_OUTOFVIDEOMEMORY;
}
if (FAILED(sc)) {
pcsd->ddRVal = sc;
return DDHAL_DRIVER_HANDLED;
}
pDDGPESurf->SetColorKeyLow(pcsd->lpDDSurfaceDesc->ddckCKDestBlt.dwColorSpaceLowValue);
pDDGPESurf->SetColorKeyHigh(pcsd->lpDDSurfaceDesc->ddckCKDestBlt.dwColorSpaceHighValue);
}
width = psurf_gbl->wWidth;
#ifdef HWHACK
// HACK for video hardware bug, force linear with fixed pitch
if(psurf_gbl->wWidth <= 384)
width = 384;
else
width = 768;
#endif
// Linear
// psurf_gbl->dwBlockSizeX = pDriverData->lPitch;
// psurf_gbl->dwBlockSizeY = (psurf_gbl->wHeight * width * 2 /
// pDriverData->lPitch) + 2;
// psurf_gbl->lPitch = width * 2;
OverlayData.VidBufSize = (psurf_gbl->wHeight * width * 2);
#ifdef DURANGO // SetVideoBufferSize(OverlayData.VidBufSize)
RETAILMSG( 0, ( TEXT("Durango Set_Video_size\n") ) );
gfx_set_video_size(psurf_gbl->wWidth, psurf_gbl->wHeight);
#endif
// Early on
SetVideoOutput(TRUE);
handled = TRUE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -