⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s3c2443disp.cpp

📁 2443 wince5.0 bsp, source code
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft 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 LICENSE.RTF on your
// install media.
//
/*++
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.

Module Name:

Abstract:

Functions:

Notes:

--*/

#include "precomp.h"
#include <syspal.h>    // for 8Bpp we use the natural palette
#include <gxinfo.h>
#define DISPPERF_DECLARE
#include "dispperf.h"
#include "s3c2443_lcd.h"

INSTANTIATE_GPE_ZONES(0x3,"MGDI Driver","unused1","unused2")    // Start with errors and warnings

DDGPE * gGPE = (DDGPE *)NULL;

// 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);
}

// this routine converts a string into a GUID and returns TRUE if the
// conversion was successful.
BOOL 
ConvertStringToGuid (LPCTSTR pszGuid, GUID *pGuid)
{
	UINT Data4[8];
	int  Count;
	BOOL fOk = FALSE;
	TCHAR *pszGuidFormat = _T("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");

	DEBUGCHK(pGuid != NULL && pszGuid != NULL);
	__try
	{
		if (_stscanf(pszGuid, pszGuidFormat, &pGuid->Data1, 
		    &pGuid->Data2, &pGuid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3], 
		    &Data4[4], &Data4[5], &Data4[6], &Data4[7]) == 11)
		{
			for(Count = 0; Count < (sizeof(Data4) / sizeof(Data4[0])); Count++)
			{
	        	        pGuid->Data4[Count] = (UCHAR) Data4[Count];
			}
		}
		fOk = TRUE;
	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
	}

	return fOk;
}

// This routine notifies the OS that we support the Power Manager IOCTLs (through
// ExtEscape(), which calls DrvEscape()).
BOOL
AdvertisePowerInterface(HMODULE hInst)
{
	BOOL fOk = FALSE;
	HKEY hk;
	DWORD dwStatus;
	TCHAR szTemp[MAX_PATH];
	GUID gClass;

	// assume we are advertising the default class
	fOk = ConvertStringToGuid(PMCLASS_DISPLAY, &gClass);
	DEBUGCHK(fOk);

	// check for an override in the registry
	dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\GDI\\Drivers"), 0, 0, &hk);
	if(dwStatus == ERROR_SUCCESS)
	{
		DWORD dwType, dwSize;
		dwSize = sizeof(szTemp);
		dwStatus = RegQueryValueEx(hk, _T("DisplayPowerClass"), NULL, &dwType, (LPBYTE) szTemp, &dwSize);
		szTemp[MAX_PATH-1] = 0;
		if(dwStatus == ERROR_SUCCESS && dwType == REG_SZ)
		{
			// got a guid string, convert it to a guid
			GUID gTemp;
			fOk = ConvertStringToGuid(szTemp, &gTemp);
			DEBUGCHK(fOk);
			if(fOk)
			{
				gClass = gTemp;
			}
		}

		// release the registry key
		RegCloseKey(hk);
	}

	// figure out what device name to advertise
	if(fOk)
	{
		fOk = GetModuleFileName(hInst, szTemp, sizeof(szTemp) / sizeof(szTemp[0]));
		DEBUGCHK(fOk);
	}

	// now advertise the interface
	if(fOk)
	{
		fOk = AdvertiseInterface(&gClass, szTemp, TRUE);
		DEBUGCHK(fOk);
	}
    
	return fOk;
}

//
// Main entry point for a GPE-compliant driver
//

GPE *
GetGPE()
{
    if (!gGPE)
    {
        gGPE = new S3C2443DISP();
    }

    return gGPE;
}

ULONG gBitMasks[] = { 0xf800,0x07e0,0x001f};

S3C2443DISP::S3C2443DISP()
{
    DWORD      oldMode;
    ULONG      fbSize;
    ULONG      fbOffset;
    ULONG      offsetX;
    ULONG      offsetY;

    m_InDDraw = FALSE;

    DEBUGMSG(GPE_ZONE_INIT,(TEXT("S3C2443DISP::S3C2443DISP\r\n")));

    oldMode = SetKMode(TRUE);

                m_RedMaskSize = 5;
                m_RedMaskPosition = 11;
                m_GreenMaskSize = 6;
                m_GreenMaskPosition = 5;
                m_BlueMaskSize = 5;
                m_BlueMaskPosition = 0;

                gBitMasks[0] =((1<<m_RedMaskSize) -1) << m_RedMaskPosition;  
                gBitMasks[1] =((1<<m_GreenMaskSize)-1) << m_GreenMaskPosition;
                gBitMasks[2] =((1<<m_BlueMaskSize) -1) << m_BlueMaskPosition;
                
    m_VesaMode = 0;
    m_nScreenWidth = LCD_XSIZE_TFT;
    m_nScreenHeight = LCD_YSIZE_TFT;
    m_colorDepth = 16;
    m_cxPhysicalScreen = LCD_XSIZE_TFT;
    m_cyPhysicalScreen = LCD_YSIZE_TFT;
//////    m_pvFlatFrameBuffer = 0xac100000;
    m_pvFlatFrameBuffer = 0x30100000;
    m_cbScanLineLength = m_nScreenWidth * 2;
	m_FrameBufferSize = m_nScreenHeight * m_cbScanLineLength;
	m_VideoPowerState = VideoPowerOn;

    m_iRotate = GetRotateModeFromReg();
    SetRotateParams();

    SetKMode(oldMode);

    // set rest of ModeInfo values
    m_ModeInfo.modeId = 0;
    m_ModeInfo.width = m_nScreenWidth;
    m_ModeInfo.height = m_nScreenHeight;
    m_ModeInfo.Bpp = m_colorDepth;
    m_ModeInfo.frequency = 60;    // ?
    switch (m_colorDepth)
    {
        case    8:
            m_ModeInfo.format = gpe8Bpp;
            break;

        case    16:
            m_ModeInfo.format = gpe16Bpp;
            break;

        case    24:
            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;

    // compute frame buffer displayable area offset
    offsetX = (m_cxPhysicalScreen - m_nScreenWidthSave) / 2;
    offsetY = (m_cyPhysicalScreen - m_nScreenHeightSave) / 2;
    fbOffset = (offsetY * m_cbScanLineLength) + offsetX;

    // compute physical frame buffer size
    fbSize = m_cyPhysicalScreen * m_cbScanLineLength;

    // for DDraw enabled, make sure we also have some off-screen video memory available for surface allocations
    fbSize = 0x100000;

    // Use CreateFileMapping/MapViewOfFile to guarantee the VirtualFrameBuffer
    // pointer is allocated in shared memory.

    m_hVFBMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, fbSize, NULL);

    if (m_hVFBMapping != NULL) {
            m_VirtualFrameBuffer = (DWORD)MapViewOfFile(m_hVFBMapping, FILE_MAP_WRITE, 0, 0, 0);
    } else {
        m_VirtualFrameBuffer = NULL;
    }

//////    if (m_VesaMode != 0)
//////    {
        if (VirtualCopy((void *)m_VirtualFrameBuffer, (void *)(m_pvFlatFrameBuffer >> 8), fbSize, PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL)) {
            CeSetMemoryAttributes ((void *)m_VirtualFrameBuffer, (void *)(m_pvFlatFrameBuffer >> 8), fbSize, PAGE_WRITECOMBINE);
        }
//////    }
//////    else
//////    {
//////        if (VirtualCopy((void *)m_VirtualFrameBuffer, (void *)m_pvFlatFrameBuffer, fbSize, PAGE_READWRITE | PAGE_NOCACHE)) {
//////            // since we don't know if the physical address under is contiguious or not, we have to settle with
//////            // PHYSICAL_ADDRESS_UNKNOWN and hope that the CPU supports it.
//////            CeSetMemoryAttributes ((void *)m_VirtualFrameBuffer, PHYSICAL_ADDRESS_UNKNOWN, fbSize, PAGE_WRITECOMBINE);
//////        }
//////    }

    PREFAST_ASSERT(m_VirtualFrameBuffer);

//////    {
//////        DWORD index;
//////        volatile PUSHORT ptr = (PUSHORT)m_VirtualFrameBuffer;
//////
//////		for (index = 0; index < 320*240; index++)
//////		{
//////			if(index < 240*80)
//////			{
//////				ptr[index] = 0xf800;
//////			}
//////			else if(index < 240*160)
//////			{
//////				ptr[index] = 0x07e0;
//////			}
//////			else if(index < 240*240)
//////			{
//////				ptr[index] = 0x001f;
//////			}
//////			else
//////			{
//////				ptr[index] = 0xffff;
//////			}
//////		}
//////
//////    }

    memset ((void*)m_VirtualFrameBuffer, 0x0, fbSize);

    m_VirtualFrameBuffer += fbOffset;
    fbSize -= fbOffset;

    m_p2DVideoMemory = new Node2D(m_cbScanLineLength * 8UL / m_pMode->Bpp, fbSize / m_cbScanLineLength, 0, 0, 4);
    if(!m_p2DVideoMemory)
    {
        RETAILMSG (1, (L"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_pPrimarySurface->SetRotation(m_nScreenWidth, m_nScreenHeight, m_iRotate);

    m_CursorVisible = FALSE;
    m_CursorDisabled = TRUE;
    m_CursorForcedOff = FALSE;
    memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));
    
	AdvertisePowerInterface(g_hmodDisplayDll);    
}

S3C2443DISP::~S3C2443DISP()
{
    if (m_VirtualFrameBuffer != NULL)
        UnmapViewOfFile((LPVOID)m_VirtualFrameBuffer);
    if (m_hVFBMapping != NULL)
        CloseHandle(m_hVFBMapping);
}

SCODE    S3C2443DISP::SetMode (INT modeId, HPALETTE *palette)
{
    DEBUGMSG(GPE_ZONE_INIT,(TEXT("S3C2443DISP::SetMode\r\n")));

    if (modeId != 0)
    {
        DEBUGMSG(GPE_ZONE_ERROR,(TEXT("S3C2443DISP::SetMode Want mode %d, only have mode 0\r\n"),modeId));
        return    E_INVALIDARG;
    }

    if (palette)
    {
        switch (m_colorDepth)
        {
            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;
        }
    }
    
	DynRotate(m_iRotate);
    return S_OK;
}

SCODE    S3C2443DISP::GetModeInfo(GPEMode *mode,    INT modeNumber)
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("S3C2443DISP::GetModeInfo\r\n")));

    if (modeNumber != 0)
    {
        return E_INVALIDARG;
    }

    *mode = m_ModeInfo;

    return S_OK;
}

int        S3C2443DISP::NumModes()
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("S3C2443DISP::NumModes\r\n")));
    return    1;
}

void    S3C2443DISP::CursorOn (void)
{
    UCHAR    *ptrScreen = (UCHAR*)m_pPrimarySurface->Buffer();
    UCHAR    *ptrLine;
    UCHAR    *cbsLine;
    int        x, y;

    if (!m_CursorForcedOff && !m_CursorDisabled && !m_CursorVisible)
    {
        RECTL cursorRectSave = m_CursorRect;
        int   iRotate;
        RotateRectl(&m_CursorRect);
        for (y = m_CursorRect.top; y < m_CursorRect.bottom; y++)
        {
            if (y < 0)
            {
                continue;
            }
            if (y >= m_nScreenHeightSave)
            {
                break;
            }

            ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
            cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_colorDepth >> 3))];

            for (x = m_CursorRect.left; x < m_CursorRect.right; x++)
            {
                if (x < 0)
                {
                    continue;
                }
                if (x >= m_nScreenWidthSave)
                {
                    break;
                }

                // x' = x - m_CursorRect.left; y' = y - m_CursorRect.top;
                // Width = m_CursorSize.x;   Height = m_CursorSize.y;
                switch (m_iRotate)
                {
                    case DMDO_0:
                        iRotate = (y - m_CursorRect.top)*m_CursorSize.x + x - m_CursorRect.left;
                        break;
                    case DMDO_90:
                        iRotate = (x - m_CursorRect.left)*m_CursorSize.x + m_CursorSize.y - 1 - (y - m_CursorRect.top);   
                        break;
                    case DMDO_180:
                        iRotate = (m_CursorSize.y - 1 - (y - m_CursorRect.top))*m_CursorSize.x + m_CursorSize.x - 1 - (x - m_CursorRect.left);
                        break;
                    case DMDO_270:
                        iRotate = (m_CursorSize.x -1 - (x - m_CursorRect.left))*m_CursorSize.x + y - m_CursorRect.top;
                        break;
                    default:
                        iRotate = (y - m_CursorRect.top)*m_CursorSize.x + x - m_CursorRect.left;
                        break;
                }
                cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3)] = ptrLine[x * (m_colorDepth >> 3)];
                ptrLine[x * (m_colorDepth >> 3)] &= m_CursorAndShape[iRotate];
                ptrLine[x * (m_colorDepth >> 3)] ^= m_CursorXorShape[iRotate];
                if (m_colorDepth > 8)
                {
                    cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 1] = ptrLine[x * (m_colorDepth >> 3) + 1];
                    ptrLine[x * (m_colorDepth >> 3) + 1] &= m_CursorAndShape[iRotate];
                    ptrLine[x * (m_colorDepth >> 3) + 1] ^= m_CursorXorShape[iRotate];
                    if (m_colorDepth > 16)
                    {
                        cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 2] = ptrLine[x * (m_colorDepth >> 3) + 2];
                        ptrLine[x * (m_colorDepth >> 3) + 2] &= m_CursorAndShape[iRotate];
                        ptrLine[x * (m_colorDepth >> 3) + 2] ^= m_CursorXorShape[iRotate];
                    }
                }
            }
        }
        m_CursorRect = cursorRectSave;
        m_CursorVisible = TRUE;
    }
}

void    S3C2443DISP::CursorOff (void)
{
	UCHAR	*ptrScreen = (UCHAR*)m_pPrimarySurface->Buffer();
	UCHAR	*ptrLine;
	UCHAR	*cbsLine;
	int		x, y;

	if (!m_CursorForcedOff && !m_CursorDisabled && m_CursorVisible)
	{
		RECTL rSave = m_CursorRect;
		RotateRectl(&m_CursorRect);
		for (y = m_CursorRect.top; y < m_CursorRect.bottom; y++)
		{
			// clip to displayable screen area (top/bottom)
			if (y < 0)
			{
				continue;
			}
			if (y >= m_nScreenHeightSave)
			{
				break;
			}

			ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
			cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_colorDepth >> 3))];

			for (x = m_CursorRect.left; x < m_CursorRect.right; x++)
			{
				// clip to displayable screen area (left/right)
				if (x < 0)
				{
					continue;
				}
				if (x >= m_nScreenWidthSave)
				{
					break;
				}

				ptrLine[x * (m_colorDepth >> 3)] = cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3)];
				if (m_colorDepth > 8)
				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -