DDDrvEsc.cpp
上传用户:fjqzjn
上传日期:2008-01-21
资源大小:2764k
文件大小:15k
- /******************************************************************************
- ** Copyright (c) 2004, Intel Corporation
- ** Copyright (c) 2003 by Imagination Technologies Limited.
- ** All rights reserved.
- **
- ** The source code contained or described herein and all documents related to the
- ** source code ("Material") are owned by Intel Corporation or its suppliers or
- ** licensors. Title to the Material remains with Intel Corporation or its suppliers
- ** and licensors. The Material contains trade secrets and proprietary and
- ** confidential information of Intel or its suppliers and licensors. The Material
- ** is protected by worldwide copyright and trade secret laws and treaty provisions.
- ** No part of the Material may be used, copied, reproduced, modified, published,
- ** uploaded, posted, transmitted, distributed, or disclosed in any way without
- ** Intel抯 prior express written permission.
- **
- ** No license under any patent, copyright, trade secret or other intellectual
- ** property right is granted to or conferred upon you by disclosure or delivery
- ** of the Materials, either expressly, by implication, inducement, estoppel or
- ** otherwise. Any license under such intellectual property rights must be express
- ** and approved by Intel in writing.
- *
- * Description : Dual display drvesc wrapper functions for DualDispDemo
- * application.
- *
- * Platform : Marathon/WinCE
- *
- ***********************************************************************************/
- #include "DDDrvEsc.h"
- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <assert.h>
- #include "dispconfig.h"
- extern FILE* gpStream;
- extern "C" BOOL VirtualCopy(
- LPVOID lpvDest,
- LPVOID lpvSrc,
- DWORD cbSize,
- DWORD fdwProtect
- );
- #ifndef GETVFRAMEPHYSICAL
- #define GETVFRAMEPHYSICAL 6144
- #endif
- void MarRegWrite(ULONG regindex, DWORD regvalue);
- DWORD MarRegRead(ULONG regindex);
- void ConfigPrefetchEnable(ULONG ul32FBSize, ULONG ul32Base);
- /***********************************************************************************
- Function Name : DE_CreateSecondarySurfBitmap
- Inputs : hdcMarathon
- Outputs : hdcMem
- hBitmap
- hOldBitmap
- sDisplayConfig
- Returns : Error code
- Description : Request that a secondary surface (bit map) be created.
- ************************************************************************************/
- LONG DE_CreateSecondarySurfBitmap(HDC hdcMarathon,
- HDC& hdcMem,
- HBITMAP& hBitmap,
- HGDIOBJ& hOldBitmap,
- BOOL& bSecondarySurfaceCreated)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- LONG nRetVal;
- /* A new secondary surface should only be created when the old one has been destroyed. */
- assert(bSecondarySurfaceCreated == FALSE);
- DISPCFG_CREATE_SURFACE sSecondarySurface;
- LONG nInputSize = sizeof (DISPCFG_CREATE_SURFACE);
- sSecondarySurface.wWidth = SECONDARYSURFACEWIDTH;
- sSecondarySurface.wHeight = SECONDARYSURFACEHEIGHT;
- assert(hdcMarathon != NULL);
- nRetVal = ExtEscape(hdcMarathon, DRVESC_CREATE_OFFSCREENSURFACE,
- nInputSize, (LPSTR) &sSecondarySurface, 0, NULL);
- if (nRetVal < 0)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DE_CreateSecondarySurfBitmap: DRVESC_CONFIG_DISPLAYSYSTEM error.n"));
- nDDRetVal |= DUALDISPERROR;
- assert(0);
- return nDDRetVal;
- }
- hdcMem = CreateCompatibleDC(hdcMarathon);
- hBitmap = CreateCompatibleBitmap(hdcMarathon, SECONDARYSURFACEWIDTH, SECONDARYSURFACEHEIGHT);
- hOldBitmap=GetCurrentObject(hdcMem, OBJ_BITMAP);
- SelectObject(hdcMem, hBitmap);
- /* Secondary surface has now been created. */
- bSecondarySurfaceCreated = TRUE;
- return nDDRetVal;
- }
- /*****************************************************************************
- FUNCTION : DE_ReleaseDualDisplay
-
- DESCRIPTION: Releases the Dual Screen lock
-
- PARAMETERS :
-
- RETURNS : BOOL - The current state of the lock
- *****************************************************************************/
- BOOL DE_ReleaseDualDisplay(HDC hdcMarathon)
- {
- DISPCFG_ACQUIRE_LOCK sAcquireLock;
- assert(hdcMarathon != NULL);
- sAcquireLock.bAcquire=FALSE;
- sAcquireLock.bRelease=TRUE;
-
-
- ExtEscape(
- hdcMarathon, // HDC hdc,
- DRVESC_ACQUIRE_DUALDISPLAY,
- sizeof(DISPCFG_ACQUIRE_LOCK) ,
- (LPCSTR )&sAcquireLock,
- sizeof(DISPCFG_ACQUIRE_LOCK) ,
- (LPSTR)&sAcquireLock
- );
- return FALSE;
- }
- /*****************************************************************************
- FUNCTION : AqcuireDualDisplay
-
- DESCRIPTION: Acquires the Dual Screen lock
-
- PARAMETERS :
-
- RETURNS : BOOL - The current state of the lock
- *****************************************************************************/
- BOOL DE_AcquireDualDisplay(HDC hdcMarathon)
- {
- DISPCFG_ACQUIRE_LOCK sAcquireLock;
- assert(hdcMarathon != NULL);
- sAcquireLock.bAcquire=TRUE;
- sAcquireLock.bRelease=FALSE;
-
-
- ExtEscape(
- hdcMarathon, // HDC hdc,
- DRVESC_ACQUIRE_DUALDISPLAY,
- sizeof(DISPCFG_ACQUIRE_LOCK) ,
- (LPCSTR )&sAcquireLock,
- sizeof(DISPCFG_ACQUIRE_LOCK) ,
- (LPSTR)&sAcquireLock
- );
- return (BOOL)sAcquireLock.bSuccess;
- }
- /***********************************************************************************
- Function Name : DE_ConfigureDisplaySystem
- Inputs : sDisplayConfig
- hdcMarathon
- Outputs :
- Returns : Error code
- Description : Pass a "display configuration" to a Marathon drvesc. sDisplayConfig
- stores the required configuration of the LCD Switch, and
- also describes which surface is to connected to the PDP,
- (i.e. Desktop surface or secondary display surface).
- The drvesc will program up the Marathon as specified by
- sDisplayConfig.
- ************************************************************************************/
- LONG DE_ConfigureDisplaySystem(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig, HDC hdcMarathon)
- {
- /* Connect Desktop or Off-Screen surface to PDP and program LCD Switch. */
- LONG nDDRetVal = DUALDISPSUCCESS;
- LONG nRetVal = 0;
- LONG nInput = sizeof(DISPCFG_DISPLAY_SYSTEM);
- assert(hdcMarathon != NULL);
- nRetVal = ExtEscape(hdcMarathon, DRVESC_CONFIG_DISPLAYSYSTEM, nInput, (LPSTR) &sDisplayConfig, 0, NULL);
- if (nRetVal < 0)
- {
- /* Note: this drvesc will fail when the requested mode cannot be found. */
- TEXTOUT(TEXT("DUALDISPDEMO: DE_ConfigureDisplaySystem: Drvesc failure: DRVESC_CONFIG_DISPLAYSYSTEM.n"));
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : DE_GetMarathonSurfaceInfo
- Inputs : eDisplaySurface
- hdcMarathon
- Outputs : sMarathonSurfaceInfo
- Returns : Error code
- Description : Return surface information about the surface specified by
- eDisplaySurface (Desktop or Secondary surface). A drvesc
- is called to obtain the surface information.
- ************************************************************************************/
- LONG DE_GetMarathonSurfaceInfo(DISPCFG_GET_SURFACE_INFO& sMarathonSurfaceInfo,
- DCFG_DISPLAY_SURFACE eDisplaySurface, HDC hdcMarathon)
- {
- /* Get DISPCFG_GET_SURFACE_INFO */
- LONG nDDRetVal = DUALDISPSUCCESS;
- LONG nInput = sizeof(DISPCFG_GET_SURFACE_INFO);
- LONG nOutput = sizeof(DISPCFG_GET_SURFACE_INFO);
- USHORT* pMarathonFB;
- ULONG ulAddr;
- LONG nRetVal;
- LONG nFBPixels;
- assert(hdcMarathon != NULL);
- sMarathonSurfaceInfo.eDisplaySurface = eDisplaySurface;
- nRetVal = ExtEscape(hdcMarathon, DRVESC_GET_SURFACEINFO, nInput, (LPSTR) &sMarathonSurfaceInfo,
- nOutput, (LPSTR) &sMarathonSurfaceInfo);
- if (nRetVal < 0)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DE_GetMarathonSurfaceInfo: DRVESC_GET_SURFACEINFO error.n"));
- nDDRetVal |= DUALDISPERROR;
- assert(0);
- return nDDRetVal;
- }
- /* Get frame buffer address */
- ulAddr = sMarathonSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress;
- if (ulAddr == NULL)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DE_GetMarathonSurfaceInfo: DRVESC_GET_SURFACEINFO failed to return ul32PhysAddress.n"));
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- /* Marathon surface could be either Desktop or secondary surface. */
- nFBPixels = sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth * sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight;
- ULONG ul32EnableCache = MARATHON_CACHE_ENABLED;
- /* Map it to a virtual address */
- pMarathonFB = (USHORT*) getMemory(ulAddr, (nFBPixels * sizeof(USHORT)), ul32EnableCache);
- if (pMarathonFB == NULL)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DE_GetMarathonSurfaceInfo: getMemory error.n"));
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- /* Write virtual memory address back to surface info */
- sMarathonSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress = (ULONG) pMarathonFB;
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : getMemory
- Inputs : dwPhysAddr
- size
- dwCacheEnabled
- Outputs :
- Returns : pvoid (pointer to virtual address).
- Description : Maps physical memory to a virtual address.
- ************************************************************************************/
- void* getMemory(DWORD dwPhysAddr, DWORD dwSize, DWORD dwCacheEnabled)
- {
- void* pVoid;
- DWORD dwPageNoCache;
- void* pvMemc = VirtualAlloc(0, dwSize, MEM_RESERVE, PAGE_NOACCESS);
-
- if (pvMemc == 0)
- {
- assert(0);
- return 0;
- }
-
- if (!dwCacheEnabled)
- {
- /* Disable cache */
- dwPageNoCache = PAGE_NOCACHE;
- }
- else
- {
- /* Do not disable cache */
- dwPageNoCache = 0;
- }
- /* Access SRAM */
- if (!VirtualCopy(pvMemc, (void*) (dwPhysAddr / 256),
- dwSize, PAGE_READWRITE | PAGE_PHYSICAL | dwPageNoCache))
- {
- /* Memory allocation has failed */
- /* Release virtual memory, close logfile and exit */
- VirtualFree(pvMemc, 0, MEM_RELEASE);
- assert(0);
- return NULL;
- }
- pVoid = (ULONG*) pvMemc;
- return pVoid;
- }
- #define PAGE_SIZE 0x1000
- #define ALIGNMENT_MASK (PAGE_SIZE-1)
- /***********************************************************************************
- Function Name : DE_GetXScaleSurfaceInfo
- Inputs : hdcXScale
- Outputs : sXScaleSurfaceInfo
- Returns : Error code
- Description : Fills in XScale surface information struct.
- ************************************************************************************/
- LONG DE_GetXScaleSurfaceInfo(XSCALE_SURFACE_INFO& sXScaleSurfaceInfo, HDC hdcXScale)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- LONG nRetVal;
- ULONG ulXScaleFB;
- LONG nOutput = sizeof(ULONG);
- LONG nInput = 0;
- assert(hdcXScale != NULL);
- sXScaleSurfaceInfo.ulBpp = XSCALE_DISPLAY_BPP;
- sXScaleSurfaceInfo.ulWidth = XSCALE_DISPLAY_WIDTH;
- sXScaleSurfaceInfo.ulHeight = XSCALE_DISPLAY_HEIGHT;
- sXScaleSurfaceInfo.ulStride = XSCALE_DISPLAY_STRIDE;
- sXScaleSurfaceInfo.nPhysicalRotation = XSCALE_DISPLAY_PHYS_ROTATION;
- sXScaleSurfaceInfo.bDouble = (BOOL) XSCALE_DISPLAY_DOUBLE;
- /* Get XScale Frame Buffer */
- nRetVal = ExtEscape(hdcXScale, GETVFRAMEPHYSICAL, nInput, NULL, nOutput,(LPSTR) &ulXScaleFB);
- if (nRetVal <= 0)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DE_CreateSecondarySurfBitmap: DRVESC_CONFIG_DISPLAYSYSTEM error.n"));
- nDDRetVal |= DUALDISPERROR;
- assert(0);
- return nDDRetVal;
- }
- /* Only page-aligned addresses can be mapped (page size is 4096 bytes). Hence, it may be
- necessary to map an address from the preceding page boundary. If so, the 'offset'
- must be added to the mapped address to obtain the frame buffer address. */
- void* pvPtr;
- ULONG ul32SourcePtr;
- ULONG ul32Offset;
- ULONG ul32ExtraFlags = 0;
- ULONG ul32MappedSize;
- BOOL bEnableCache = (BOOL) XSCALE_CACHE_ENABLED;
- ul32MappedSize = sXScaleSurfaceInfo.ulWidth * sXScaleSurfaceInfo.ulHeight * sizeof(USHORT);
- /* Mapping a virtual address */
- BOOL bPhysicalAddress = FALSE;
- ////////////////// Calculate require space and reserve linear range
- ul32Offset = ulXScaleFB & ALIGNMENT_MASK;
- ul32MappedSize += ul32Offset ? PAGE_SIZE : 0;
- pvPtr = VirtualAlloc(0, ul32MappedSize, MEM_RESERVE, PAGE_NOACCESS);
- if(pvPtr == NULL)
- return(FALSE);
- /////////////////////////////// Are we mapping a physical address ?
- ul32SourcePtr = (ulXScaleFB - ul32Offset);
- if (bPhysicalAddress)
- {
- ul32ExtraFlags = PAGE_PHYSICAL;
- ul32SourcePtr = ul32SourcePtr / 256;
- }
- if (bEnableCache == FALSE)
- {
- ul32ExtraFlags |= PAGE_NOCACHE;
- }
- ///////////////////////////////////// Map virtual address to linear
- if(!VirtualCopy(pvPtr, (PVOID)ul32SourcePtr, ul32MappedSize,
- PAGE_READWRITE | ul32ExtraFlags))
- {
- VirtualFree(pvPtr, 0, MEM_RELEASE);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- /* Copy this address so that it can eventually be de-allocated. */
- sXScaleSurfaceInfo.ulPageAddress = (ULONG) pvPtr;
- /* Get the frame buffer address - which may be an offset from the mapped address. */
- sXScaleSurfaceInfo.ulPhysAddress = (LONG) ( (PBYTE) pvPtr + ul32Offset);
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : DE_CheckForScreenUpdate
- Inputs : hdcMarathon
- Outputs : bIsDirty
- Returns : Error code
- Description : Calls a Marathon drvesc to find out whether the Marathon primary
- surface has been updated. This means that the 'Desktop to XScale'
- transfer functions only need to update the XScale frame buffer
- when a change has occurred.
- ************************************************************************************/
- LONG DE_CheckForScreenUpdate(HDC hdcMarathon, BOOL& bIsDirty)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- LONG nRetVal = 0;
- LONG nInput = sizeof(DISPCFG_DISPLAY_SYSTEM);
- assert(hdcMarathon != NULL);
- nRetVal = ExtEscape(hdcMarathon, DRVESC_DIRTY, 0, NULL, sizeof(BOOL), (LPSTR) &bIsDirty);
- if (nRetVal < 0)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Drvesc failure: DRVESC_CONFIG_DISPLAYSYSTEM.n"));
- nDDRetVal |= DUALDISPERROR;
- assert(0);
- return nDDRetVal;
- }
- return nDDRetVal;
- }