📄 gpeflat.cpp
字号:
//**********************************************************************
//
// Filename: gpeflat.cpp
//
// Description: Flat driver for the EP9312.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to
// use this source code. For a copy of the EULA, please see the
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved
//
//**********************************************************************
#include "precomp.h"
#include "..\common\palette.h" // for 8Bpp we use the natural palette
#include <dispperf.h>
ULONG gBitMasks16[] = { 0xF800, 0x07E0, 0x001F }; // 565 MODE
ULONG gBitMasks24[] = { 0x00ff0000, 0x0000ff00, 0x000000ff}; // 24bpp MODE
ULONG gBitMasks8[] = { 0x0001,0x0002,0x0000 }; // 8bpp mode
DWORD gdwColorDepth;
INSTANTIATE_PALETTE
//
// Set up the debug zones.
//
INSTANTIATE_GPE_ZONES(0x0003,"Flat DDI Driver","Palette","unused2") // Start with errors and warnings
#define GPE_ZONE_PALETTE DEBUGZONE(14)
static GPE *gGPE = (GPE*)NULL;
// This prototype avoids problems exporting from .lib
BOOL APIENTRY GPEEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
PENGCALLBACKS engineCallbacks);
//****************************************************************************
// DrvEnableDriver
//****************************************************************************
//
BOOL APIENTRY DrvEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
PENGCALLBACKS engineCallbacks)
{
return GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
}
//****************************************************************************
// GetGPE
//****************************************************************************
// Main entry point for a GPE-compliant driver
//
//
GPE *GetGPE(void)
{
if (!gGPE)
{
gGPE = new GPEFlat();
}
return gGPE;
}
//****************************************************************************
// GPEFlat::GPEFlat
//****************************************************************************
// GPEFlat Constructor
//
GPEFlat::GPEFlat (void)
{
DWORD oldMode;
ULONG fbSize;
DEBUGMSG(GPE_ZONE_INIT,(TEXT("GPEFlat::GPEFlat\r\n")));
RETAILMSG(1,(TEXT("Init Raster engine\r\n")));
// oldMode = SetKMode(TRUE);
//
// Read in the settings from the registry.
//
GetDisplayRegistrySettings(&m_Registry);
//
// Initialize the values that are being used.
//
m_VirtualFrameBuffer = FRAMEBUF_VIRTUAL_MEMORY;
m_pvFlatFrameBuffer = FRAMEBUF_PHYSICAL_MEMORY;
m_ulColorDepth = m_Registry.ulColorDepth;
m_nScreenWidth = m_Registry.ulScreenWidth;
m_nScreenHeight = m_Registry.ulScreenHeight;
//
// If the flag Set Directly is used then take the Raster values directly
// from the registry.
//
if(m_Registry.ulSetDirectly)
{
//
// Use the values from the registry to setup the display.
//
GenericDisplaySetup(&m_Registry, FRAMEBUF_PHYSICAL_MEMORY, &m_StartStop);
}
else
{
//
// Use the generic CRT setup.
//
CRTVideoSetup
(
m_nScreenWidth,
m_nScreenHeight,
m_ulColorDepth,
m_Registry.ulFrequency,
m_pvFlatFrameBuffer,
&m_StartStop
);
}
//
// Save off the video attributes register.
//
m_ulVideoAttrib = *RASTER_VIDEOATTRIBS | VIDEOATTRIBS_SDSEL;
m_nScreenHeightSave = m_nScreenHeight;
m_nScreenWidthSave = m_nScreenWidth;
#ifdef BSP_EP93XX_DISPLAY_ROTATION
m_iRotate = GetRotateModeFromReg();
SetRotateParams();
#endif
//
// Program the proper color depth settings.
//
switch(m_ulColorDepth)
{
case 8:
//
// Set up the Color Look up table. There are two LUT's in hardware.
// the lookup table that is visible is not the one that is accessable.
//
SetPalette(_rgbIdentity, 0 , PALETTE_SIZE);
//
// Set up the Pixel mode.
//
*RASTER_PIXELMODE = PIXELMODE_C_LUT | PIXELMODE_M_BLINKDISABLED |
PIXELMODE_S_MODE1 | PIXELMODE_P_8BITS;
m_ModeInfo.format = gpe8Bpp;
break;
case 16:
*RASTER_PIXELMODE = PIXELMODE_C_565 | PIXELMODE_M_BLINKDISABLED | PIXELMODE_S_MODE1 |
PIXELMODE_P_16BITS;
//
// Since we are not using a palette, setup red, green and blue masks.
//
m_RedMaskSize = 5;
m_RedMaskPosition = 11;
m_GreenMaskSize = 6;
m_GreenMaskPosition = 5;
m_BlueMaskSize = 5;
m_BlueMaskPosition = 0;
m_ModeInfo.format = gpe16Bpp;
break;
case 24:
*RASTER_PIXELMODE = PIXELMODE_C_TRIPLE8 | PIXELMODE_M_BLINKDISABLED | PIXELMODE_S_MODE1 |
PIXELMODE_P_24BITS;
//
// Since we are not using a palette, setup red, green and blue masks.
//
m_RedMaskSize = 8;
m_RedMaskPosition = 16;
m_GreenMaskSize = 8;
m_GreenMaskPosition = 8;
m_BlueMaskSize = 8;
m_BlueMaskPosition = 0;
m_ModeInfo.format = gpe24Bpp;
break;
case 32:
//m_ModeInfo.format = gpe32Bpp;
//break;
default:
DEBUGMSG(GPE_ZONE_ERROR,(TEXT("Invalid BPP value passed to driver - %d\r\n"), m_ModeInfo.Bpp));
m_ModeInfo.format = gpeUndefined;
break;
}
m_pMode = &m_ModeInfo;
//
// Copy a few more variables.
//
m_cxPhysicalScreen = m_nScreenWidth;
m_cyPhysicalScreen = m_nScreenHeight;
#ifdef BSP_EP93XX_DISPLAY_ROTATION
m_cbScanLineLength = m_nScreenWidth > m_nScreenHeight ? m_nScreenWidth : m_nScreenHeight;
m_cbScanLineLength *= m_ulColorDepth;
m_cbScanLineLength /=8;
#else
m_cbScanLineLength = (m_cxPhysicalScreen * m_ulColorDepth) /8;
#endif
//
// set rest of ModeInfo values
//
m_ModeInfo.modeId = 0;
m_ModeInfo.width = m_nScreenWidth;
m_ModeInfo.height = m_nScreenHeight;
m_ModeInfo.Bpp = m_ulColorDepth;
m_ModeInfo.frequency = m_Registry.ulFrequency;
//
// Clear the screen.
//
RETAILMSG(1,(TEXT("Clearing screen\r\n")));
fbSize = m_cyPhysicalScreen * m_cbScanLineLength ;
memset ((void*)m_VirtualFrameBuffer, 0x0, fbSize);
RETAILMSG(1,(TEXT("memset of video\r\n")));
//
// Setup the cursor stuff.
//
m_CursorVisible = FALSE;
m_CursorDisabled = TRUE;
m_CursorForcedOff = FALSE;
memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));
m_CursorBackingStore = NULL;
m_CursorXorShape = NULL;
m_CursorAndShape = NULL;
gdwColorDepth = m_ulColorDepth; // for get bit mask
m_p2DVideoMemory = new Node2D(m_cbScanLineLength * 8UL / m_pMode->Bpp, fbSize / m_cbScanLineLength, 0, 0, 4);
if(!m_p2DVideoMemory)
{
RETAILMSG (1, (L"GPEFlat new Node2D failed\n"));
return;
}
if(FAILED(AllocSurface(&m_pPrimarySurface, m_nScreenWidthSave, m_nScreenHeightSave, m_pMode->format, GPE_REQUIRE_VIDEO_MEMORY)))
{
RETAILMSG (1, (L"Couldn't allocate primary surface\n"));
return;
}
m_ucCusorValue=NULL;
m_VideoMemSize = FRAMEBUF_MEMORY_SIZE- 4096; //the last 4K space is for cursor.
m_dwPhysCursorAddress = FRAMEBUF_PHYSICAL_MEMORY+m_VideoMemSize;
m_pCursor = (PUCHAR)(FRAMEBUF_VIRTUAL_MEMORY+m_VideoMemSize);
*RASTER_CURSOR_ADR_START = *RASTER_CURSOR_ADR_RESET = m_dwPhysCursorAddress;
*RASTER_CURSORCOLOR1 = 0;
*RASTER_CURSORCOLOR2 = 0xFFFFFF ;
*RASTER_CURSORXYLOC = 0;
*RASTER_CURSOR_BLINK1 = 0;
*RASTER_CURSOR_BLINK2 = 0;
*RASTER_CURSOR_BLINK = 0;
m_bCursorEnabled = FALSE;
//m_bCursorInitialized = FALSE;
m_bCursorHasShape = FALSE;
memset(&m_CursorRect, sizeof(m_CursorRect), 0);
memset(&m_CursorSize, sizeof(m_CursorSize), 0);
memset(&m_CursorHotspot, sizeof(m_CursorHotspot),0);
#ifdef BSP_EP93XX_DISPLAY_ROTATION
((GPESurfRotate *)m_pPrimarySurface)->SetRotation(m_nScreenWidth, m_nScreenHeight, m_iRotate);
#endif
RETAILMSG(1,(TEXT("Returning from DDI init\r\n")));
}
//****************************************************************************
// GPEFlat::SetMode
//****************************************************************************
// Sets the Graphics mode and the palette.
//
SCODE GPEFlat::SetMode (INT modeId, HPALETTE *palette)
{
DEBUGMSG(GPE_ZONE_INIT,(TEXT("GPEFlat::SetMode\r\n")));
if (modeId != 0)
{
DEBUGMSG(GPE_ZONE_ERROR,(TEXT("GPEFlat::SetMode Want mode %d, only have mode 0\r\n"),modeId));
return E_INVALIDARG;
}
if (palette)
{
switch (m_ulColorDepth)
{
case 8:
*palette = EngCreatePalette (PAL_INDEXED,
PALETTE_SIZE,
(ULONG*)_rgbIdentity,
0,
0,
0);
break;
case 16:
case 24:
case 32:
*palette = EngCreatePalette (PAL_BITFIELDS,
0,
NULL,
((1 << m_RedMaskSize) - 1) << m_RedMaskPosition,
((1 << m_GreenMaskSize) - 1) << m_GreenMaskPosition,
((1 << m_BlueMaskSize) - 1) << m_BlueMaskPosition);
break;
}
}
return S_OK;
}
//****************************************************************************
// GPEFlat::GetModeInfo
//****************************************************************************
//
//
SCODE GPEFlat::GetModeInfo(GPEMode *mode, INT modeNumber)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPEFlat::GetModeInfo\r\n")));
if (modeNumber != 0)
{
return E_INVALIDARG;
}
*mode = m_ModeInfo;
return S_OK;
}
//****************************************************************************
// GPEFlat::NumModes
//****************************************************************************
// Only one graphics mode currently supported.
//
//
int GPEFlat::NumModes()
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPEFlat::NumModes\r\n")));
return 1;
}
//
//****************************************************************************
// GPEFlat::SetPointerShape
//****************************************************************************
// Set the pointer shape.
SCODE GPEFlat::SetPointerShape
(
GPESurf *pMask,
GPESurf *pColorSurf,
INT xHot,
INT yHot,
INT cX,
INT cY
)
{
char bAnd;
char bXor;
int row;
int col;
// int bitMask;
int i;
UCHAR *andPtr; // input pointer
UCHAR *xorPtr; // input pointer
ULONG ulCursorSize = 0;
USHORT usMask;
BOOL bSizeChanged= FALSE;
if(!pMask)
{
if(m_bCursorHasShape)
{
m_bCursorHasShape = FALSE;
*RASTER_CURSORXYLOC = 0;
}
}
//
// Check to see if the size changed.
//
if( (cX != m_CursorSize.x) || (cY != m_CursorSize.y) )
{
bSizeChanged = TRUE;
}
//
// If the Size has changed then
//
switch(cX)
{
case 16:
ulCursorSize = CURSORSIZE_CWID_16PIXELS | CURSORSIZE_CSTEP_16PIXELS;
break;
case 32:
ulCursorSize = CURSORSIZE_CWID_32PIXELS | CURSORSIZE_CSTEP_32PIXELS;
break;
case 48:
ulCursorSize = CURSORSIZE_CWID_48PIXELS | CURSORSIZE_CSTEP_48PIXELS;
break;
case 64:
ulCursorSize = CURSORSIZE_CWID_64PIXELS | CURSORSIZE_CSTEP_64PIXELS;
break;
default:
//
// Return that it is not ok.
//
DEBUGMSG (GPE_ZONE_LINE, (TEXT("GPEFlat::SetPointerShape Invalid Cursor Width, cX = 0%08x\r\n"), cX));
return S_FALSE;
}
if( bSizeChanged ) {
if( m_ucCusorValue)
delete m_ucCusorValue;
m_ucCusorValue= new UCHAR[cX*cY];
if( !m_ucCusorValue )
return S_FALSE;
}
//
// Store size and hotspot for new cursor
//
m_CursorSize.x = cX;
m_CursorSize.y = cY;
m_CursorHotspot.x = xHot;
m_CursorHotspot.y = yHot;
//
// Disable the cursor if the size has changed.
//
if(m_bCursorEnabled && bSizeChanged)
{
*RASTER_CURSORXYLOC &= ~CURSORXYLOC_CEN;
//
// Program in the cursor size register.
//
*RASTER_CURSORSIZE = ulCursorSize | ((cY - 1)<<CURSORSIZE_CLINS_SHIFT);
}
int pos=0;
UCHAR ucTemp;
UCHAR * pValue=m_ucCusorValue;
//
// store OR and AND mask for new cursor
//
andPtr = (UCHAR*)pMask->Buffer();
for (row = 0; row < cY; row++)
{
xorPtr = andPtr + (cY * pMask->Stride());
for (col = 0; col < cX / 8; col++)
{
bAnd = ~andPtr[row * pMask->Stride() + col];
bXor = xorPtr[row * pMask->Stride() + col];
usMask = 0;
//following two loops invert the two bytes and the bits in the two bytes.
for ( i = 0; i < 4; i++)
{
ucTemp= (bAnd &(0x1<<i) ) ? 0x02 :0;
ucTemp|= (bXor &(0x1<<i) ) ? 0x01 :0;
pValue[4+pos + 3 -i]=ucTemp;
}
for ( i = 0; i < 4; i++)
{
ucTemp= (bAnd &(0x1<<(4+i) ) ) ? 0x02 :0;
ucTemp|= (bXor &(0x1<<(4+i) ) ) ? 0x01 :0;
pValue[pos+ 3- i]=ucTemp;
}
pos+=8;
}
}
return FlushPointer( cX, cY ,bSizeChanged);
}
//****************************************************************************
// GPEFlat::FlushPointer
//****************************************************************************
//
SCODE GPEFlat::FlushPointer( INT cX, INT cY ,BOOL bSizeChanged )
{
ULONG ulXYLOC;
UCHAR usMask;
int pos=0;
int row;
int col;
int iCursorBit=0;
int iMaxCol=cX/4;
int i;
UCHAR * pValue=m_ucCusorValue;
#ifdef BSP_EP93XX_DISPLAY_ROTATION
UCHAR * ucTempCursor= new UCHAR[cX*cY];
if( (!ucTempCursor) ){
if(ucTempCursor)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -