📄 ddlcdc.cpp
字号:
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//------------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Copyright (C) 2004-2005, MOTOROLA, INC. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// MOTOROLA, INC.
//------------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Copyright (C) 2005-2006, 2007, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//---------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// File: DDLCDC.cpp
//
// Implementation of class DDLCDC.
//
//------------------------------------------------------------------------------
#include "precomp.h"
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
extern BOOL InitializeLCDC(BOOL bTVModeActive, BOOL bTVNTSCOut, DWORD dwPanelType);
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// EXPORTED FUNCTIONS
//------------------------------------------------------------------------------
// This prototype avoids problems exporting from .lib
BOOL APIENTRY GPEEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
PENGCALLBACKS engineCallbacks);
BOOL APIENTRY DrvEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
PENGCALLBACKS engineCallbacks)
{
return GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
}
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
INSTANTIATE_GPE_ZONES((GPE_ZONE_ERROR|GPE_ZONE_INIT|GPE_ZONE_WARNING),"MX27DDLcdc","unused1","unused2");
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
static DWORD g_dwlcdcSysintr;
static GPE *gGPE = (GPE *) NULL;
static EGPEFormat eFormat[] =
{
gpe8Bpp,
gpe16Bpp,
gpe24Bpp,
gpe32Bpp,
};
static EDDGPEPixelFormat ePixelFormat[4] =
{
ddgpePixelFormat_8bpp,
ddgpePixelFormat_565,
ddgpePixelFormat_8880, // not supported by i.MX27 LCDC, just for possible future expansion
ddgpePixelFormat_8888, // not supported by i.MX27 LCDC, just for possible future expansion
};
static ULONG BitMasks[][3] =
{
{ 0, 0, 0 },
{ 0xF800, 0x07E0, 0x001F },
{ 0xFF0000, 0x00FF00, 0x0000FF },
{ 0x00FF0000, 0x0000FF00, 0x000000FF }
};
//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
static DWORD MX27DDLcdcIntr(MX27DDLcdc *pClass);
//------------------------------------------------------------------------------
//
// Function: DrvGetMasks
//
// This function retrieves the color masks for the display device's current
// mode. The ClearType and anti-aliased font libraries use this function.
//
// Parameters:
// dhpdev
// [in] Handle to the display device for which to retrieve color
// mask information.
//
// Returns:
// A pointer to three consecutive ULONG values. Each ULONG represents
// the mask for a particular color component, red, green, or blue. For
// example, a RGB565 based display returns (0xf800, 0x07e0, 0x001f).
//
//------------------------------------------------------------------------------
PULONG APIENTRY DrvGetMasks(DHPDEV dhpdev)
{
if (gGPE == NULL)
return(BitMasks[0]);
int nBPP = ((MX27DDLcdc *)gGPE)->GetBpp()/8 - 1;
switch (((MX27DDLcdc *)gGPE)->GetBpp())
{
case 8:
case 16:
case 24:
case 32:
return(BitMasks[nBPP]);
break;
default:
break;
}
return(BitMasks[0]);
}
//------------------------------------------------------------------------------
//
// Function: GetGPE
//
// Main entry point for a GPE-compliant driver.
//
// Parameters:
// None.
//
// Returns:
// GPE class pointer.
//
//------------------------------------------------------------------------------
GPE *GetGPE(VOID)
{
if (!gGPE)
{
BOOL result;
gGPE = new MX27DDLcdc(&result);
if(!result)
{
DEBUGMSG(GPE_ZONE_ERROR, (TEXT("MX27DDLcdc: Failed to get GPE instance!\r\n")));
if(gGPE)
{
delete gGPE;
gGPE = NULL;
}
}
}
DEBUGMSG(GPE_ZONE_INIT, (TEXT("MX27DDLcdc: GetGPE(0x%08x)\r\n"), gGPE));
return gGPE;
}
//------------------------------------------------------------------------------
// CLASS MEMBER FUNCTIONS
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// FUNCTION: MX27DDLcdc
//
// DESCRIPTION: Constructor of MX27DDLcdc class
//
// Parameters:
// pbRet
// [in] Pointer to return value. TRUE if success, FALSE if failure.
//
// Returns:
//
//------------------------------------------------------------------------------
MX27DDLcdc::MX27DDLcdc(BOOL * pbRet)
{
BOOL result = TRUE;
// Initialze MX27DDLcdc class on software perspective
if(!Init())
{
result = FALSE;
goto _done;
}
// Setup video buffer
if(!SetupVideoMemory())
{
result = FALSE;
goto _done;
}
// Setup LCDC of i.MX27 processor
if(!InitHardware())
{
result = FALSE;
goto _done;
}
// Notify the system that we are a power-manageable device
m_Dx = D0;
if(!AdvertisePowerInterface(g_hmodDisplayDll))
{
result = FALSE;
goto _done;
}
_done:
if(!result)
Cleanup();
DEBUGMSG(GPE_ZONE_INIT, (TEXT("MX27DDLcdc: class construction %s!!\r\n"), result ? L"succeeds" : L"fails"));
*pbRet = result;
}
//------------------------------------------------------------------------------
//
// FUNCTION: ~MX27DDLcdc
//
// DESCRIPTION: Destructor of ~MX27DDLcdc
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
MX27DDLcdc::~MX27DDLcdc()
{
Cleanup();
}
//------------------------------------------------------------------------------
//
// Function: SetMode
//
// This method executes to enable the device driver
// based on the Graphics Primitive Engine (GPE)
// and to request a specific mode for the display.
//
// Parameters:
// modeID
// [in] Mode number to set.
//
// pPalette
// [in/out] Handle of palette.
//
// Returns:
// S_OK successful
// others failed
//
//------------------------------------------------------------------------------
SCODE MX27DDLcdc::SetMode(int modeNo, HPALETTE * pPalette)
{
if(m_bSetMode)
return S_OK;
if(modeNo != m_pMode->modeId)
{
// WindowCE doesn't allow to change display mode at run time
DEBUGMSG(GPE_ZONE_ERROR, (TEXT("MX27DDLcdc SetMode: failed to setMode, desired[%d], current[%d]\r\n"), modeNo, m_pMode->modeId));
return E_INVALIDARG;
}
m_bSetMode = TRUE;
m_dwPhysicalModeID = m_pMode->modeId;
int nBPP = m_nScreenBpp/8 - 1;
if (pPalette)
{
switch (m_nScreenBpp)
{
case 8:
break;
case 16:
case 24:
case 32:
*pPalette = EngCreatePalette (PAL_BITFIELDS,
0,
NULL,
BitMasks[nBPP][0],
BitMasks[nBPP][1],
BitMasks[nBPP][2]);
break;
default:
break;
}
}
m_nScreenHeightSave = m_pMode->height;
m_nScreenWidthSave = m_pMode->width;
DynRotate(m_iRotate);
// Start display driver!!
if(m_pPrimarySurface->OffsetInVideoMemory())
SetVisibleSurface((GPESurf *) m_pPrimarySurface);
return S_OK;
}
//------------------------------------------------------------------------------
//
// Function: GetModeInfo
//
// This method populates a GPEMode structure with data
// for the requested mode.
//
// Parameters:
// pMode
// [out] Pointer to a GPEMode structure.
//
// modeNo
// [in] Integer specifying the mode to return information about.
//
// Returns:
// S_OK successful
// others failed
//
//------------------------------------------------------------------------------
SCODE MX27DDLcdc::GetModeInfo(GPEMode * pMode, int modeNo)
{
if(modeNo >= NumModes())
{
DEBUGMSG(GPE_ZONE_ERROR, (TEXT("MX27DDLcdc GetModeInfo: wrong mode (%d)!!\r\n"), modeNo));
return E_INVALIDARG;
}
*pMode = *m_pMode;
return S_OK;
}
//------------------------------------------------------------------------------
//
// Function: GetModeInfoEx
//
// This method populates a GPEMode structure with data
// for the requested mode.
//
// Parameters:
// pMode
// [out] Pointer to a GPEModeEx structure.
//
// modeNo
// [in] Integer specifying the mode to return information about.
//
// Returns:
// S_OK successful
// others failed
//
//------------------------------------------------------------------------------
SCODE MX27DDLcdc::GetModeInfoEx(GPEModeEx * pModeEx, int modeNo)
{
if(modeNo >= NumModes())
{
DEBUGMSG(GPE_ZONE_ERROR, (TEXT("MX27DDLcdc GetModeInfoEx: wrong mode (%d)!!\r\n"), modeNo));
return E_INVALIDARG;
}
*pModeEx = *m_pModeEx;
return S_OK;
}
//------------------------------------------------------------------------------
//
// Function: NumModes
//
// This method returns the number of
// display modes supported by a driver.
//
// Parameters:
// None.
//
// Returns:
// The number of supported display modes
//
//------------------------------------------------------------------------------
int MX27DDLcdc::NumModes(VOID)
{
return BSPGetModeNum();
}
//------------------------------------------------------------------------------
//
// Function: GetPhysicalVideoMemory
//
// This method retrieves the information of video memory.
//
// NOTE: The VIRTUAL address should be passed back as defined by Microsoft.
//
// Parameters:
// pPhysicalMemoryBase
// [out] Pointer to physical memory.
//
// pVideoMemorySize
// [out] Pointer to video memory size.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
VOID MX27DDLcdc::GetPhysicalVideoMemory(PULONG pPhysicalMemoryBase, PULONG pVideoMemorySize)
{
// The return value should be virtual address
*pPhysicalMemoryBase = (ULONG) m_pLAW;
*pVideoMemorySize = m_nVideoMemorySize;
}
//------------------------------------------------------------------------------
//
// Function: GetBpp
//
// Return the Bpp of the current monitor.
//
// Parameters:
// None.
//
// Returns:
// BPP of the current monitor.
//
//------------------------------------------------------------------------------
int MX27DDLcdc::GetBpp(VOID)
{
return m_nScreenBpp;
}
//------------------------------------------------------------------------------
//
// FUNCTION: Init
//
// DESCRIPTION: Software perspective initialization of MX27DDLcdc class
//
// Parameters:
// None.
//
// Returns:
// TRUE successful
// FALSE failed
//
//------------------------------------------------------------------------------
BOOL MX27DDLcdc::Init(VOID)
{
BOOL result = TRUE;
UINT iLoop = 0;
BOOL bModeGot = FALSE;
int nBPP;
// Pre-Initialization
m_bSetMode = FALSE;
m_pPrimarySurface = NULL;
m_pBlankSurface = NULL;
m_pVisibleOverlay = NULL;
m_pVideoMemoryHeap = NULL;
m_nPreIntrStatus = 0;
m_nMask = 0; // for flicker
// Pre-setup display mode in DDGPE engine
m_pModeEx = &m_ModeInfoEx;
m_pMode = &m_ModeInfoEx.modeInfo;
memset(m_pModeEx, 0, sizeof(GPEModeEx));
m_pModeEx->dwSize = sizeof(GPEModeEx);
m_pModeEx->dwVersion = GPEMODEEX_CURRENTVERSION;
BSPInitLCDC(&m_LcdcCtx);
// setup local mode info structure
m_pMode = (GPEMode*)(m_LcdcCtx.pGPEModeInfo);
RETAILMSG (0, (TEXT("mode 0x%x\r\n"), m_pMode->modeId));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -