DualDispDemo.cpp
上传用户:fjqzjn
上传日期:2008-01-21
资源大小:2764k
文件大小:127k
- /******************************************************************************
- ** 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 example application. See dualdispdemo.txt
- for further information.
- *
- * Platform : Marathon/WinCE/PocketPC
- *
- * OSV_PPC must be defined in order to build for PocketPC.
- *
- ***********************************************************************************/
- #include <windows.h>
- #include <assert.h>
- #include <string.h>
- #include <memory.h>
- #include "dispconfig.h"
- #include "DDDrvEsc.h"
- #include "resource.h"
- #include <commctrl.h>
- //#include <pkfuncs.h>
- #include <aygshell.h>
- /* Set rotation angle of desktop for the external screen. Only an angle of 0 degrees
- is currently supported. */
- #define EXTERNALDISPLAYROTATION 0
- #define DESKTOPTOXSCALEDELAY 100
- /* Enable/disable 'desktop transfer' efficiency test code. */
- #define CHECK_MEM_COPY_SPEED 0
- #define TEMP_BUFFER_SIZE (800 * 600)
- /* For Config_TestDualDisplay retain each tested configuration for this length of time. */
- #define TEST_DISPLAYMODEDURATION 10000
- static HANDLE hEvent_StopDesktopTransfer = NULL;
- static HANDLE hThread_DesktopTransfer = NULL;
- static HANDLE hEvent_StopGDIRectangles = NULL;
- static HANDLE hThread_GDIRectangles = NULL;
- static HDC hdcXScale = NULL;
- static HDC hdcMem = NULL;
- static HBITMAP hBitmap = NULL;
- static HGDIOBJ hOldBitmap = NULL;
- static HWND hwndDialog = NULL;
- static HDC hdcMarathon = NULL;
- static USHORT usTempBuffer[TEMP_BUFFER_SIZE];
- static LONG lInitialDesktopRotation = 0;
- static BOOL bSecondarySurfaceCreated = FALSE;
- static TCHAR szTestResults[12][200];
- DISPCFG_DISPLAY_SYSTEM sDisplayConfig;
- DISPCFG_GET_SURFACE_INFO sDesktopSurfaceInfo;
- DISPCFG_GET_SURFACE_INFO s2700GSecondadrySurfInfo;
- XSCALE_SURFACE_INFO sXScaleSurfaceInfo;
- FILE* gpStream = NULL;
- class RefreshDisplay
- {
- private:
- /* Copy of WinMain parameters */
- HINSTANCE m_hInstance;
- HINSTANCE m_hPrevInstance;
- LPTSTR m_szCmdLine;
- int m_iCmdShow;
- HWND m_hwnd;
- int m_nScreenWidth;
- int m_nScreenHeight;
- public:
- void Init(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR szCmdLine,
- int iCmdShow);
- void SetSize (int nWidth, int nHeight) { m_nScreenWidth = nWidth; m_nScreenHeight = nHeight;}
- void MaskDesktop();
- void RevealDesktop();
- void Close();
- };
- RefreshDisplay classRefreshDisplay;
- /***** Select Dual Display Configuration ******************************************/
- LONG Config_TestDualDisplay(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale,
- BOOL bQuickTest);
- LONG Config_DefaultDisplay(DISPCFG_DISPLAY_SYSTEM& sDefaultConfig);
- LONG Config_MirrorModeIncompatible(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sMarathonSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale);
- LONG Config_MirrorModeCompatible(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig);
- LONG Config_CustomGDIApplication(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale);
- LONG Config_CustomFBApplication(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale);
- LONG Config_ExternalDispOnlyDesktop(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig);
- LONG Config_InternalDispOnlySecSurf(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo);
- LONG Config_ExternalDispOnlySecSurf(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo);
- LONG Config_VideoMode(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale);
- /**********************************************************************************/
- /***** Perform Dual Display Configuration *****************************************/
- void LCDInternal(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- BOOL bValid,
- BOOL bActivate,
- DCFG_LCD_SOURCE eLcdSource,
- DCFG_LCD_IN_FORMAT eXScaleFormat);
- void LCDExternal(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- BOOL bValid,
- BOOL bActivate,
- DCFG_LCD_SOURCE eLcdSource,
- DCFG_LCD_IN_FORMAT eXScaleFormat);
- void ConfigSurfaceForPDP(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DCFG_DISPLAY_SURFACE eSurface,
- ULONG ulBorderColor,
- BOOL bFillScreen,
- ULONG ulRefreshRate,
- ULONG ulPhysRotation,
- BOOL bSet);
- /**********************************************************************************/
- /***** Transfer a Display Surface from Marathon to XSCale *************************/
- LONG BeginDesktopToXScaleTransfer(DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC hdcXScale);
- DWORD WINAPI DesktopToXScaleTransfer(LPVOID lpParameter);
- LONG StopDesktopToXScaleTransfer();
- LONG CopyToXScaleFB(DISPCFG_GET_SURFACE_INFO& sMarathonSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo);
- LONG CopyAndDoubleToXScaleFB(DISPCFG_GET_SURFACE_INFO& sMarathonSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo);
- LONG RotateToBuffer(USHORT* pulDestBuffer, USHORT* pulSrcBuffer,
- ULONG ulDestWidth, ULONG ulDestHeight, ULONG ulRequiredRotation,
- ULONG ulSrcWidth, ULONG ulSrcHeight, ULONG ulSrcStride);
- LONG RotateAndDoubleToBuffer(USHORT* pulDestBuffer, USHORT* pulSrcBuffer,
- ULONG ulDestWidth, ULONG ulDestHeight, ULONG ulRequiredRotation,
- ULONG ulSrcWidth, ULONG ulSrcHeight, ULONG ulSrcStride);
- void AdjustRefreshRate(BOOL bIsDirty,
- ULONG& nConsecutiveScreenUpdates,
- DWORD& dwDelayInMilliseconds);
- /**********************************************************************************/
- /***** Use secondary display surface **********************************************/
- LONG GetSecondarySurfaceInfo(DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo);
- LONG WriteToSecSurfFrameBuffer(DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo);
- void DestroySecondarySurface();
- /**********************************************************************************/
- /*********** GDI ******************************************************************/
- DWORD WINAPI GDIRectangles(LPVOID lpParameter);
- LONG StopGDIRectangles();
- LONG RandomRectangles();
- /**********************************************************************************/
- /***** Miscellaneous **************************************************************/
- void GetCommandLineArgs(LPTSTR lpCmdLine, ULONG& ulArgc, char **argv, char* ArgBuffer);
- void ConvertTToC(char* pszDest, const TCHAR* pszSrc);
- LONG ProcessOptions(int ulArgc, char **argv,
- SELECT_DUAL_DISP_CONFIG& SelectDualDispConfig);
- void CloseAllThreads();
- void CloseAllHDCs();
- LONG RestoreDefaultDisplayMode();
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK WndProcRefreshDisplay (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
- LONG DualDisplaySetup(DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo);
- void DualDisplayTestSetup(DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo, BOOL& bTestSetupSuccess);
- void VerifyTestSuccess(TCHAR* szTestName, ULONG ulTestNumber,
- LONG nDDRetVal, BOOL& bTestFailure);
- /**********************************************************************************/
- /***********************************************************************************
- Function Name : GDIRectangles
- Inputs : lpParameter
- Outputs :
- Returns : Error code
- Description : Displays rectangles of random size and colour at random
- locations on the surface.
- ************************************************************************************/
- DWORD WINAPI GDIRectangles(LPVOID lpParameter)
- {
- DWORD dwDDRetVal = DUALDISPSUCCESS;
- DWORD dwDelayInMilliseconds = 50;
- DWORD dwWaitObjRetVal = 0;
- LONG nLeftRect;
- LONG nTopRect;
- LONG nRightRect;
- LONG nBottomRect;
- HBRUSH hBrush, hBrushOld;
- LONG nRed, nGreen, nBlue;
- LONG nWidth = SECONDARYSURFACEWIDTH;
- LONG nHeight = SECONDARYSURFACEHEIGHT;
- DISPCFG_DISPLAY_SYSTEM* sDisplayConfig;
- sDisplayConfig = (DISPCFG_DISPLAY_SYSTEM*) lpParameter;
- /* Make sure handle to bitmap memory is valid. */
- if (hdcMem == NULL)
- {
- dwDDRetVal |= DUALDISPERROR;
- return dwDDRetVal;
- }
- for (;;)
- {
- dwWaitObjRetVal = WaitForSingleObject(hEvent_StopGDIRectangles, dwDelayInMilliseconds);
- if (dwWaitObjRetVal == WAIT_TIMEOUT)
- {
- nLeftRect = rand() % nWidth;
- nTopRect = rand() % nHeight;
- nRightRect = rand() % nWidth;
- nBottomRect = rand() % nHeight;
- nRed = rand() & 255;
- nGreen = rand() & 255;
- nBlue = rand() & 255;
- hBrush = CreateSolidBrush(RGB(nRed, nGreen, nBlue));
- hBrushOld = (HBRUSH) SelectObject(hdcMem, hBrush);
- Rectangle(hdcMem, nLeftRect,nTopRect, nRightRect, nBottomRect);
- assert(hBrushOld != NULL);
- SelectObject(hdcMem, hBrushOld);
- DeleteObject(hBrush);
- }
- else if (dwWaitObjRetVal == WAIT_OBJECT_0)
- {
- /* hEvent_StopDesktopTransfer event object signalled - so stop transfer */
- /* clean up first */
- TEXTOUT(TEXT("DUALDISPDEMO: GDIRectangles: exited thread.n"));
- /* Delete secondary surface bitmap. */
- DestroySecondarySurface();
- return dwDDRetVal;
- }
- else if (dwWaitObjRetVal == WAIT_FAILED)
- {
- assert(0);
- dwDDRetVal |= DUALDISPERROR;
- return dwDDRetVal;
- }
- else
- {
- assert(0);
- dwDDRetVal |= DUALDISPERROR;
- return dwDDRetVal;
- }
- }
- }
- /***********************************************************************************
- Function Name : RandomRectangles
- Inputs :
- Outputs :
- Returns : Error code
- Description : Displays rectangles of random size and colour at random
- locations on the surface.
- ************************************************************************************/
- LONG RandomRectangles()
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- DWORD dwDelayInMilliseconds = 50;
- DWORD dwWaitObjRetVal = 0;
- LONG i;
- LONG nLeftRect;
- LONG nTopRect;
- LONG nRightRect;
- LONG nBottomRect;
- HBRUSH hBrush, hBrushOld;
- LONG nRed, nGreen, nBlue;
- LONG nWidth = SECONDARYSURFACEWIDTH;
- LONG nHeight = SECONDARYSURFACEHEIGHT;
- /* Make sure handle to bitmap memory is valid. */
- if (hdcMem == NULL)
- {
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- for (i = 0; i < 200; i++)
- {
- nLeftRect = rand() % nWidth;
- nTopRect = rand() % nHeight;
- nRightRect = rand() % nWidth;
- nBottomRect = rand() % nHeight;
- nRed = rand() & 255;
- nGreen = rand() & 255;
- nBlue = rand() & 255;
- hBrush = CreateSolidBrush(RGB(nRed, nGreen, nBlue));
- hBrushOld = (HBRUSH) SelectObject(hdcMem, hBrush);
- Rectangle(hdcMem, nLeftRect,nTopRect, nRightRect, nBottomRect);
- assert(hBrushOld != NULL);
- SelectObject(hdcMem, hBrushOld);
- DeleteObject(hBrush);
- Sleep(dwDelayInMilliseconds);
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : DestroySecondarySurface
- Inputs :
- Outputs :
- Returns :
- Description : Delete the secondary surface bitmap.
- ************************************************************************************/
- void DestroySecondarySurface()
- {
- if (bSecondarySurfaceCreated)
- {
- assert(((hdcMem != NULL) && (hOldBitmap != NULL) && (hBitmap != NULL)));
- SelectObject(hdcMem, hOldBitmap);
- DeleteObject(hBitmap);
- hBitmap = NULL;
- DeleteDC(hdcMem);
- hdcMem = NULL;
- /* Secondary surface has now been destroyed. */
- bSecondarySurfaceCreated = FALSE;
- }
- }
- /***********************************************************************************
- Function Name : ConvertTToC
- Inputs : pszSrc
- Outputs : pszDest
- Returns :
- Description : Converts a unicode string to an ANSI string.
- ************************************************************************************/
- void ConvertTToC(char* pszDest, const TCHAR* pszSrc)
- {
- unsigned int i;
- for(i = 0; i <= _tcslen(pszSrc); i++)
- pszDest[i] = (CHAR) pszSrc[i];
- }
- /***********************************************************************************
- Function Name : GetCommandLineArgs
- Inputs : lpCmdLine
- Outputs : ArgBuffer
- ulArgc
- argv
- Returns :
- Description : Converts a unicode command line string into an array of ANSI
- tokens.
- ************************************************************************************/
- void GetCommandLineArgs(LPTSTR lpCmdLine, ULONG& ulArgc, char **argv, char* ArgBuffer)
- {
- char *ptr = ArgBuffer;
- ulArgc = 0;
- ConvertTToC(ArgBuffer, lpCmdLine);
- /* Store arguments in argv */
- argv[ulArgc++] = "DualDisplayDemo.exe";
- if (ArgBuffer[0])
- argv[ulArgc++] = ArgBuffer;
- while (*ptr != ' ')
- {
- if ((*ptr == ' ') || (*ptr == 't'))
- {
- *ptr++ = ' ';
- while ((*ptr == ' ') || (*ptr == 't'))
- {
- ptr++;
- }
- if (*ptr != ' ')
- {
- argv[ulArgc++] = ptr;
- }
- }
- else
- {
- ptr++;
- }
- }
- }
- /***********************************************************************************
- Function Name : ProcessOptions
- Inputs : ulArgc
- argv
- Outputs : SelectDualDispConfig
- Returns :
- Description : Processes an array of tokens (command line options) in order
- to determine which 'Dual Display' mode has been selected.
- ************************************************************************************/
- LONG ProcessOptions (int ulArgc, char **argv, SELECT_DUAL_DISP_CONFIG& SelectDualDispConfig)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- int i;
- if (ulArgc == 1) // if no args, go into mirror
- {
- SelectDualDispConfig = eMirrorModeIncompatible;
- return DUALDISPSUCCESS;
- }
- for (i = 1; i < ulArgc; i++)
- {
- if (!strcmp(argv[i], "--default") || !strcmp(argv[i], "-d"))
- {
- SelectDualDispConfig = eDefaultDisplay;
- }
- else if (!strcmp(argv[i], "--mirror") || !strcmp(argv[i], "-m"))
- {
- SelectDualDispConfig = eMirrorModeIncompatible;
- }
- else if (!strcmp(argv[i], "--mirrorcompatible"))
- {
- SelectDualDispConfig = eMirrorModeCompatible;
- }
- else if (!strcmp(argv[i], "--video"))
- {
- SelectDualDispConfig = eVideoMode;
- }
- else if (!strcmp(argv[i], "--gdi") || !strcmp(argv[i], "-g"))
- {
- SelectDualDispConfig = eCustomGDIApplication;
- }
- else if (!strcmp(argv[i], "--framebuffer") || !strcmp(argv[i], "-f"))
- {
- SelectDualDispConfig = eCustomFBApplication;
- }
- else if (!strcmp(argv[i], "--extdesktop"))
- {
- SelectDualDispConfig = eExternalDispOnlyDesktop;
- }
- else if (!strcmp(argv[i], "--intsecsurf"))
- {
- SelectDualDispConfig = eInternalDispOnlySecSurf;
- }
- else if (!strcmp(argv[i], "--extsecsurf"))
- {
- SelectDualDispConfig = eExternalDispOnlySecSurf;
- }
- else if (!strcmp(argv[i], "--test"))
- {
- SelectDualDispConfig = eSlowTestMode;
- }
- else if (!strcmp(argv[i], "--quicktest"))
- {
- SelectDualDispConfig = eQuickTestMode;
- }
- else
- {
- SelectDualDispConfig = eModeInvalid;
- nDDRetVal = DUALDISPERROR;
- }
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_TestDualDisplay
- Inputs :
-
- Outputs : sDisplayConfig
- sDesktopSurfaceInfo
- sXScaleSurfaceInfo
- Returns : Error code
- Description : Tests all the dual display configurations defined in the
- Config_xxxxxxx functions. Note: these tests are only performed
- for the default rotation angle and screen resolution as
- defined in powervr.reg.
- Excerpt from powervr.reg during testing:
-
- [HKEY_LOCAL_MACHINEDriversDisplayPowerVR]
- "Width"=dword:140
- "Height"=dword:f0
- "BitsPerPixel"=dword:10
- "Prefetch"=dword:1
- #"BondConfig"=dword:3
- "Panel"=dword:00000005
- "PanelExt"=dword:C0000005
- See dualdispdemo.txt for further information about this test.
- ************************************************************************************/
- LONG Config_TestDualDisplay(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale,
- BOOL bQuickTest)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- ULONG ulDisplayModeDuration;
- BOOL bTestFailure = FALSE;
- TCHAR szBuffer[500];
- LONG ulTestNumber = 0;
- BOOL bTestSetupSuccess = TRUE;
- if (bQuickTest == TRUE)
- {
- /* For a quick test, set delay to 1 millisecond */
- ulDisplayModeDuration = 1;
- }
- else
- {
- /* This time delay should allow time for visual inspection of each display configuration. */
- ulDisplayModeDuration = TEST_DISPLAYMODEDURATION;
- }
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplayn"));
- /* Test Config_DefaultDisplay */
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST1: Config_DefaultDisplayn"));
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- nDDRetVal = Config_DefaultDisplay(sDisplayConfig);
- Sleep(ulDisplayModeDuration);
- VerifyTestSuccess(TEXT("Config_DefaultDisplay"), ulTestNumber++, nDDRetVal, bTestFailure);
- /* Test Config_MirrorModeIncompatible */
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST2: Config_MirrorModeIncompatiblen"));
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- nDDRetVal = Config_MirrorModeIncompatible(sDisplayConfig, sDesktopSurfaceInfo, sXScaleSurfaceInfo, hdcXScale);
- Sleep(ulDisplayModeDuration);
- VerifyTestSuccess(TEXT("Config_MirrorModeIncompatible"), ulTestNumber++, nDDRetVal, bTestFailure);
- /* Test Config_MirrorModeCompatible */
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST3: Config_MirrorModeCompatiblen"));
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- nDDRetVal = Config_MirrorModeCompatible(sDisplayConfig);
- Sleep(ulDisplayModeDuration);
- VerifyTestSuccess(TEXT("Config_MirrorModeCompatible"), ulTestNumber++, nDDRetVal, bTestFailure);
- /* Test Config_CustomGDIApplication */
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST4: Config_CustomGDIApplicationn"));
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- nDDRetVal = Config_CustomGDIApplication(sDisplayConfig, sDesktopSurfaceInfo, s2700GSecondadrySurfInfo, sXScaleSurfaceInfo, hdcXScale);
- Sleep(ulDisplayModeDuration);
- VerifyTestSuccess(TEXT("Config_CustomGDIApplication"), ulTestNumber++, nDDRetVal, bTestFailure);
- /* Test Config_CustomFBApplication */
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST5: Config_CustomFBApplicationn"));
- nDDRetVal = Config_CustomFBApplication(sDisplayConfig, sDesktopSurfaceInfo, s2700GSecondadrySurfInfo, sXScaleSurfaceInfo, hdcXScale);
- Sleep(ulDisplayModeDuration);
- VerifyTestSuccess(TEXT("Config_CustomFBApplication"), ulTestNumber++, nDDRetVal, bTestFailure);
- /* Test Config_ExternalDispOnlyDesktop */
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST6: Config_ExternalDispOnlyDesktopn"));
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- nDDRetVal = Config_ExternalDispOnlyDesktop(sDisplayConfig);
- Sleep(ulDisplayModeDuration);
- VerifyTestSuccess(TEXT("Config_ExternalDispOnlyDesktop"), ulTestNumber++, nDDRetVal, bTestFailure);
- /* Test Config_InternalDispOnlySecSurf - sleep not required as test has inbuilt delay. */
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST7: Config_InternalDispOnlySecSurfn"));
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- nDDRetVal = Config_InternalDispOnlySecSurf(sDisplayConfig, s2700GSecondadrySurfInfo);
- VerifyTestSuccess(TEXT("Config_InternalDispOnlySecSurf"), ulTestNumber++, nDDRetVal, bTestFailure);
- /* Test Config_ExternalDispOnlySecSurf - sleep not required as test has inbuilt delay. */
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST8: Config_ExternalDispOnlySecSurfn"));
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- nDDRetVal = Config_ExternalDispOnlySecSurf(sDisplayConfig, s2700GSecondadrySurfInfo);
- VerifyTestSuccess(TEXT("Config_ExternalDispOnlySecSurf"), ulTestNumber++, nDDRetVal, bTestFailure);
- /* Test Config_VideoMode */
- TEXTOUT(TEXT("DUALDISPDEMO: Config_TestDualDisplay: TEST9: Config_VideoModen"));
- DualDisplayTestSetup(sDesktopSurfaceInfo, bTestSetupSuccess);
- nDDRetVal = Config_VideoMode(sDisplayConfig, sDesktopSurfaceInfo, sXScaleSurfaceInfo, hdcXScale);
- Sleep(ulDisplayModeDuration);
- VerifyTestSuccess(TEXT("Config_VideoMode"), ulTestNumber++, nDDRetVal, bTestFailure);
- RestoreDefaultDisplayMode();
- /* Output test results */
- TEXTOUT(TEXT("nn****************** DUALDISPDEMO TEST ******************n"));
- TEXTOUT(TEXT("For all tests to pass, suitable displays must be specified (via Panel and PanelExt in powervr.reg).n"));
- if (bTestSetupSuccess == FALSE)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DualDisplayTestSetup FAILEDn"));
- }
- else
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DualDisplayTestSetup PASSEDn"));
- }
- for (LONG i = 0; i < ulTestNumber; i++)
- {
- TEXTOUT(szTestResults[i]);
- }
- if (bTestFailure)
- {
- wsprintf(szBuffer, TEXT("nn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!n"));
- wcscat(szBuffer, TEXT ("!!!!!!!!! FAILED: One or more DUALDISPDEMO tests FAILED !!!!!!!!!n"));
- wcscat(szBuffer, TEXT ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!nn"));
- TEXTOUT(szBuffer);
- nDDRetVal = DUALDISPERROR;
- }
- else
- {
- wsprintf(szBuffer, TEXT("nn*****************************************************n"));
- wcscat(szBuffer, TEXT ("********* PASSED: DUALDISPDEMO tests PASSED *********n"));
- wcscat(szBuffer, TEXT ("*****************************************************nn"));
- TEXTOUT(szBuffer);
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : VerifyTestSuccess
- Inputs : szTestName
- nDDRetVal
- Input/Output : bTestFailure
- Returns :
- Description : Process the return value of each test.
- ************************************************************************************/
- void VerifyTestSuccess(TCHAR* szTestName, ULONG ulTestNumber,
- LONG nDDRetVal, BOOL& bTestFailure)
- {
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- wsprintf(szTestResults[ulTestNumber], TEXT("%s: FAILEDn"), szTestName);
- bTestFailure = TRUE;
- }
- else
- {
- wsprintf(szTestResults[ulTestNumber], TEXT("%s: PASSEDn"), szTestName);
- }
- }
- /***********************************************************************************
- Function Name : Config_MirrorModeCompatible
- Inputs :
- Outputs : sDisplayConfig
- Returns :
- Description : Configures Simple Mirror Mode. In this mode, the Desktop
- is connected to the PDP which connects to both the internal
- and external displays via the LCD switch. In order to use
- this mode, the internal and external panels must have
- compatible timings.
- ************************************************************************************/
- LONG Config_MirrorModeCompatible(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* Set default desktop rotation angle */
- ULONG ulPhysRotation = sDesktopSurfaceInfo.sPhysSurfaceInfo.lPhysicalRotation;
- /* PDP will connect to the internal LCD */
- LCDInternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* PDP will connect to the external LCD */
- LCDExternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* Desktop will be connected to the PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_DESKTOP, PARAM_NOT_APPLICABLE, FALSE,
- PARAM_NOT_APPLICABLE, ulPhysRotation, TRUE);
- /* Program LCD switch and connect PDP to the specified surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_MirrorModeCompatible: returning error value.n"));
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_DefaultDisplay
- Inputs :
- Outputs : sDisplayConfig
- Returns :
- Description : This function enables/restores the standard mode of operation,
- The Desktop is displayed on the internal screen. The external
- screen is not in use.
- ************************************************************************************/
- LONG Config_DefaultDisplay(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* Set default rotation (i.e. rotation angle of desktop on internal panel when not in dual display mode). */
- ULONG ulPhysRotation = lInitialDesktopRotation;
- /* PDP will connect to the internal LCD */
- LCDInternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* Disable external LCD */
- LCDExternal(sDisplayConfig, TRUE, FALSE, DCFG_SOURCE_NOT_APPLICABLE, DCFG_FORMAT_NOT_APPLICABLE);
- /* Desktop will be connected to the PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_DESKTOP, PARAM_NOT_APPLICABLE, FALSE,
- PARAM_NOT_APPLICABLE, ulPhysRotation, TRUE);
- /* Program LCD switch and connect PDP to the specified surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_DefaultDisplay: returning error value.n"));
- assert(0);
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_MirrorModeIncompatible
- Inputs :
- Outputs : sDisplayConfig
- sDesktopSurfaceInfo
- Returns : Error code
- Description : Configures and executes Mirror Mode - desktop will be output
- to the internal and external displays.
- ************************************************************************************/
- LONG Config_MirrorModeIncompatible(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* HOST will be connected to the internal LCD */
- LCDInternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_XSCALE, DCFG_LCD_IN_565);
- /* PDP will be connected to the external LCD */
- LCDExternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* Desktop will be connected to PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_DESKTOP, PARAM_NOT_APPLICABLE, FALSE,
- PARAM_NOT_APPLICABLE, EXTERNALDISPLAYROTATION, TRUE);
- /* Hide the existing desktop from view - it is about to be "messed up". */
- classRefreshDisplay.MaskDesktop();
- /* Program LCD switch and connect PDP to the desktop surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon); // TODO :
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_MirrorModeIncompatible: Call to DE_ConfigDisplaySystem failed.n"));
- return nDDRetVal;
- }
- /* The desktop will now be transferred to the HOST (i.e. XScale) to be
- displayed on the internal screen. The LCD switch must be programmed
- to use the HOST as the "internal display source", before transferring
- desktop data to the HOST. */
- nDDRetVal |= BeginDesktopToXScaleTransfer(sDesktopSurfaceInfo, sXScaleSurfaceInfo, hdcXScale);
- /* Display the new "refreshed" desktop */
- classRefreshDisplay.RevealDesktop();
- /* Marathon driver knows it is in mirror mode (i.e. DCFG_DESKTOP is connected to
- PDP), therefore no further action is required here. */
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_MirrorModeIncompatible: returning error value.n"));
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_VideoMode
- Inputs :
- Outputs : sDisplayConfig
- sDesktopSurfaceInfo
- sXScaleSurfaceInfo
- Returns : Error code
- Description : VideoMode is essentially the same thing as MirrorModeIncompatible.
- However, the initial (default) desktop rotation angle is retained
- - thus if the desktop is rotated in default mode, it will also appear
- rotated on the external panel. This means that it may appear
- 'sideways' from the user's point of view. The purpose of this
- is to ensure that a video application has full access to the
- external screen - i.e. to allow it to be displayed in landscape
- mode. This prevents video being displayed on top of a small 'bordered
- portrait' desktop.
- Video mode has another advantage over MirrorModeIncompatible: it is not
- necessary for the DesktopToXScale function to rotate the desktop
- greatly improving its performance.
- ************************************************************************************/
- LONG Config_VideoMode(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* Use the default desktop rotation for the external panel. This means that
- a 'portrait' desktop will be displayed on its side - allowing video to be
- played full-screen. */
- ULONG ulPhysRotation = lInitialDesktopRotation;
- /* HOST will be connected to the internal LCD */
- LCDInternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_XSCALE, DCFG_LCD_IN_565);
- /* PDP will be connected to the external LCD */
- LCDExternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* Desktop will be connected to PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_DESKTOP, PARAM_NOT_APPLICABLE, FALSE,
- PARAM_NOT_APPLICABLE, ulPhysRotation, TRUE);
- /* Hide the existing desktop from view - it is about to be "messed up". */
- classRefreshDisplay.MaskDesktop();
- /* Program LCD switch and connect PDP to the desktop surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon); // TODO :
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_MirrorModeIncompatible: Call to DE_ConfigDisplaySystem failed.n"));
- return nDDRetVal;
- }
- /* The desktop will now be transferred to the HOST (i.e. XScale) to be
- displayed on the internal screen. The LCD switch must be programmed
- to use the HOST as the "internal display source", before transferring
- desktop data to the HOST. */
- nDDRetVal |= BeginDesktopToXScaleTransfer(sDesktopSurfaceInfo, sXScaleSurfaceInfo, hdcXScale);
- /* Display the new "refreshed" desktop */
- classRefreshDisplay.RevealDesktop();
- /* Marathon driver knows it is in mirror mode (i.e. DCFG_DESKTOP is connected to
- PDP), therefore no further action is required here. */
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_MirrorModeIncompatible: returning error value.n"));
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_CustomGDIApplication
- Inputs :
- Outputs : sDisplayConfig
- sDesktopSurfaceInfo
- s2700GSecondadrySurfInfo
- Returns :
- Description : Configure dual display for "Custom application" mode. This
- means that the desktop surface is transfered from the Marathon
- to the XScale processor (to be displayed on the internal
- screen). A secondary surface will be created for the custom
- application to use. This surface can be accessed via an
- HDC (for GDI); or the secondary surface frame buffer can be
- accessed directly.
- The secondary surface will be output to the external display.
- In this example, the thread GDIRectangles is created to
- perform a GDI test-write to the secondary surface. See
- Config_CustomFBApplication for an example using the secondary
- secondary surface frame buffer.
- ************************************************************************************/
- LONG Config_CustomGDIApplication(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* Host will connect to the internal display. */
- LCDInternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_XSCALE, DCFG_LCD_IN_565);
- /* PDP will connect to the external display. */
- LCDExternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* "secondary display surface" will be connected to PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_SECONDARYSURFACE, 0, FALSE, 60, PARAM_NOT_APPLICABLE, TRUE);
- /* Create the off-screen surface. */
- nDDRetVal |= DE_CreateSecondarySurfBitmap(hdcMarathon, hdcMem, hBitmap, hOldBitmap,
- bSecondarySurfaceCreated);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_CustomGDIApplication: Call to DE_CreateSecondarySurfBitmap failed.n"));
- return nDDRetVal;
- }
- /* Program LCD switch and connect PDP to the off-screen surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_CustomGDIApplication: Call to DE_ConfigureDisplaySystem failed.n"));
- return nDDRetVal;
- }
- /* The desktop should not be rotated by this application - rotation is
- only required in MirrorModeIncompatible. */
- /* The desktop will now be transferred to the HOST (i.e. XScale) to be
- displayed on the internal screen. The LCD switch must be programmed
- to use the HOST as the "internal display source", before transferring
- desktop data to the HOST. */
- nDDRetVal |= BeginDesktopToXScaleTransfer(sDesktopSurfaceInfo, sXScaleSurfaceInfo, hdcXScale);
- nDDRetVal |= GetSecondarySurfaceInfo(s2700GSecondadrySurfInfo);
- /* Perform GDI test-write to secondary surface via hdcMem */
- /* Create an event to control thread termination. */
- hEvent_StopGDIRectangles = CreateEvent(NULL, TRUE, FALSE, TEXT("StopCustomGDI"));
- if (hEvent_StopGDIRectangles == NULL)
- {
- /* Failed to create event object */
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- /* Start GDIRectangles thread */
- hThread_GDIRectangles = CreateThread(NULL, 0, GDIRectangles,
- (void*) &sDisplayConfig, 0, NULL);
- if (hThread_GDIRectangles == NULL)
- {
- /* Failed to create thread */
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_CustomApplication: returning error value.n"));
- assert(0);
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_CustomFBApplication
- Inputs :
- Outputs : sDisplayConfig
- sDesktopSurfaceInfo
- s2700GSecondadrySurfInfo
- Returns :
- Description : Configure dual display for "Custom application" mode. This
- means that the desktop surface is transfered from the Marathon
- to the XScale processor (to be displayed on the internal
- display). A secondary surface will be created for the custom
- application to use. This surface can be accessed via an
- HDC (for GDI); or the secondary surface frame buffer can be
- accessed directly.
- The secondary surface will be output to the external display.
- In this example, the secondary surface frame buffer is
- written to directly. See Config_CustomGDIApplication for
- a GDI example.
- ************************************************************************************/
- LONG Config_CustomFBApplication(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC& hdcXScale)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* Host will connect to the internal display. */
- LCDInternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_XSCALE, DCFG_LCD_IN_565);
- /* PDP will connect to the external display. */
- LCDExternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* "secondary display surface" will be connected to PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_SECONDARYSURFACE, 0, FALSE, 60, PARAM_NOT_APPLICABLE, TRUE);
- /* Create the off-screen surface. */
- nDDRetVal |= DE_CreateSecondarySurfBitmap(hdcMarathon, hdcMem, hBitmap, hOldBitmap,
- bSecondarySurfaceCreated);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_CustomFBApplication: Call to DE_CreateSecondarySurfBitmap failed.n"));
- return nDDRetVal;
- }
- /* Program LCD switch and connect PDP to the off-screen surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_CustomFBApplication: Call to DE_ConfigureDisplaySystem failed.n"));
- return nDDRetVal;
- }
- /* The desktop will now be transferred to the HOST (i.e. XScale) to be
- displayed on the internal screen. The LCD switch must be programmed
- to use the HOST as the "internal display source", before transferring
- desktop data to the HOST. */
- nDDRetVal |= BeginDesktopToXScaleTransfer(sDesktopSurfaceInfo, sXScaleSurfaceInfo, hdcXScale);
- /* Perform test-write to secondary surface frame buffer */
- /* Get DISPCFG_GET_SURFACE_INFO for the secondary surface. The secondary can then be
- written to via: s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulPhysAddress */
- nDDRetVal |= GetSecondarySurfaceInfo(s2700GSecondadrySurfInfo);
- nDDRetVal |= WriteToSecSurfFrameBuffer(s2700GSecondadrySurfInfo);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Config_CustomApplication: returning error value.n"));
- assert(0);
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_InternalDispOnlySecSurf
- Inputs :
- Outputs : sDisplayConfig
- s2700GSecondadrySurfInfo
- Returns :
- Description : Select the configuration "Internal display only with secondary
- surface". No desktop.
- ************************************************************************************/
- LONG Config_InternalDispOnlySecSurf(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* PDP will be connected to the internal LCD */
- LCDInternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* Disable external LCD */
- LCDExternal(sDisplayConfig, TRUE, FALSE, DCFG_SOURCE_NOT_APPLICABLE, DCFG_FORMAT_NOT_APPLICABLE);
- /* "secondary display surface" will be connected to PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_SECONDARYSURFACE, 0, FALSE, 60, PARAM_NOT_APPLICABLE, TRUE);
- /* Create the off-screen surface. */
- nDDRetVal |= DE_CreateSecondarySurfBitmap(hdcMarathon, hdcMem, hBitmap, hOldBitmap,
- bSecondarySurfaceCreated);
- /* Program LCD switch and connect PDP to the off-screen surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon);
- nDDRetVal |= GetSecondarySurfaceInfo(s2700GSecondadrySurfInfo);
- /* Code to write to secondary surface goes here. */
- /* Example write: GDI rectangles (20 seconds) */
- nDDRetVal |= RandomRectangles();
- /* Example write: to Secondary surface frame buffer */
- nDDRetVal |= WriteToSecSurfFrameBuffer(s2700GSecondadrySurfInfo);
- Sleep(4000);
- /* Delete secondary surface bitmap. */
- DestroySecondarySurface();
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_ExternalDispOnlyDesktop
- Inputs :
- Outputs : sDisplayConfig
- Returns :
- Description : Select the configuration "Desktop on external display only".
- ************************************************************************************/
- LONG Config_ExternalDispOnlyDesktop(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* Disable internal LCD */
- LCDInternal(sDisplayConfig, TRUE, FALSE, DCFG_SOURCE_NOT_APPLICABLE, DCFG_FORMAT_NOT_APPLICABLE);
- /* PDP will connect to the external display. */
- LCDExternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* Desktop will connect to the PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_DESKTOP,
- PARAM_NOT_APPLICABLE, FALSE, PARAM_NOT_APPLICABLE, EXTERNALDISPLAYROTATION, TRUE);
- /* Hide the existing desktop from view - it is about to be "messed up". */
- classRefreshDisplay.MaskDesktop();
- /* Program LCD switch and connect PDP to the desktop surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon);
- /* Display the new "refreshed" desktop */
- classRefreshDisplay.RevealDesktop();
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : Config_ExternalDispOnlySecSurf
- Inputs :
- Outputs : sDisplayConfig
- s2700GSecondadrySurfInfo
- Returns :
- Description : Select the configuration "External display only with secondary
- surface". No desktop.
- ************************************************************************************/
- LONG Config_ExternalDispOnlySecSurf(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* Disable internal LCD */
- LCDInternal(sDisplayConfig, TRUE, FALSE, DCFG_SOURCE_NOT_APPLICABLE, DCFG_FORMAT_NOT_APPLICABLE);
- /* PDP will connect to the external display. */
- LCDExternal(sDisplayConfig, TRUE, TRUE, DCFG_SOURCE_MARATHON, DCFG_FORMAT_NOT_APPLICABLE);
- /* "Secondary display surface" will connect to the PDP */
- ConfigSurfaceForPDP(sDisplayConfig, DCFG_SECONDARYSURFACE, 0, FALSE, 60, PARAM_NOT_APPLICABLE, TRUE);
- /* Create the off-screen surface. */
- nDDRetVal |= DE_CreateSecondarySurfBitmap(hdcMarathon, hdcMem, hBitmap, hOldBitmap,
- bSecondarySurfaceCreated);
- /* Program LCD switch and connect PDP to the off-screen surface. */
- nDDRetVal |= DE_ConfigureDisplaySystem(sDisplayConfig, hdcMarathon);
- /* Get DISPCFG_GET_SURFACE_INFO for the secondary surface. The secondary can then be
- written to via: s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulPhysAddress */
- nDDRetVal |= GetSecondarySurfaceInfo(s2700GSecondadrySurfInfo);
- /* Code to write to secondary surface goes here. */
- /* Example write: GDI rectangles (5 seconds) */
- nDDRetVal |= RandomRectangles();
- /* Example write: to Secondary surface frame buffer */
- nDDRetVal |= WriteToSecSurfFrameBuffer(s2700GSecondadrySurfInfo);
- Sleep(4000);
- /* Delete the secondary surface bitmap. */
- DestroySecondarySurface();
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : LCDInternal
- Inputs : Valid
- bActivate
- eLcdSource
- eXScaleFormat
- Outputs : sDisplayConfig
- Returns :
- Description : Copy the values specified in Valid, bActivate, eLcdSource
- and eXScaleFormat to sDisplayConfig.sLcdInternal.
- ************************************************************************************/
- void LCDInternal(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- BOOL bValid,
- BOOL bActivate,
- DCFG_LCD_SOURCE eLcdSource,
- DCFG_LCD_IN_FORMAT eXScaleFormat)
- {
- /* Configure internal LCD */
- sDisplayConfig.sLcdInternal.bValid = bValid;
- sDisplayConfig.sLcdInternal.bActivate = bActivate;
- sDisplayConfig.sLcdInternal.eLcdSource = eLcdSource;
- sDisplayConfig.sLcdInternal.eXScaleFormat = eXScaleFormat; // only applicable when HOST is source
- }
- /***********************************************************************************
- Function Name : LCDExternal
- Inputs : Valid
- bActivate
- eLcdSource
- eXScaleFormat
- Outputs : sDisplayConfig
- Returns :
- Description : Copy the values specified in Valid, bActivate, eLcdSource
- and eXScaleFormat to sDisplayConfig.sLcdExternal.
- ************************************************************************************/
- void LCDExternal(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- BOOL bValid,
- BOOL bActivate,
- DCFG_LCD_SOURCE eLcdSource,
- DCFG_LCD_IN_FORMAT eXScaleFormat)
- {
- /* Configure external LCD */
- sDisplayConfig.sLcdExternal.bValid = bValid;
- sDisplayConfig.sLcdExternal.bActivate = bActivate;
- sDisplayConfig.sLcdExternal.eLcdSource = eLcdSource;
- sDisplayConfig.sLcdExternal.eXScaleFormat = eXScaleFormat; // only applicable when HOST is source
- }
- /***********************************************************************************
- Function Name : ConfigSurfaceForPDP
- Inputs : eSurface
- ulBorderColor
- bFillScreen
- ulRefreshRate
- Outputs : sDisplayConfig
- Returns :
- Description : Copy the values specified in ulBorderColor, bFillScreen and
- ulRefreshRate to sDisplayConfig.
- ************************************************************************************/
- void ConfigSurfaceForPDP(DISPCFG_DISPLAY_SYSTEM& sDisplayConfig,
- DCFG_DISPLAY_SURFACE eSurface,
- ULONG ulBorderColor,
- BOOL bFillScreen,
- ULONG ulRefreshRate,
- ULONG ulPhysRotation,
- BOOL bSet)
- {
- /* SET a display configuration or GET existing configuration? */
- sDisplayConfig.bSet = bSet;
- /* Describe surface to be connected to PDP.
- Colour, screen and refresh rate attributes are not applicable
- when connecting PDP to a desktop surface. */
- sDisplayConfig.sConnectSurface.eSurface = eSurface;
- sDisplayConfig.sConnectSurface.ulBorderColor = ulBorderColor;
- sDisplayConfig.sConnectSurface.ulRefreshRate = ulRefreshRate;
- /* Rotation angle of Desktop (only applicable when Desktop is connected to the PDP). */
- sDisplayConfig.sConnectSurface.ulPhysRotation = ulPhysRotation;
- }
- /***********************************************************************************
- Function Name : StopDesktopToXScaleTransfer
- Inputs :
- Outputs :
- Returns : Error code
- Description : Stops the desktop to xscale transfer mechanism
- ************************************************************************************/
- LONG StopDesktopToXScaleTransfer()
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- BOOL bEventRetVal = 0;
- DWORD dwWaitInMilliseconds = 10000;
- DWORD nRetVal = WAIT_FAILED;
- TEXTOUT(TEXT("DUALDISPDEMO: StopDesktopToXScaleTransfer: exiting DesktopTransfer thread.n"));
- bEventRetVal = SetEvent(hEvent_StopDesktopTransfer);
- if (bEventRetVal)
- {
- /* StopDesktopTransfer event has been signalled */
- nRetVal = WaitForSingleObject(hThread_DesktopTransfer, dwWaitInMilliseconds);
- if (nRetVal == WAIT_TIMEOUT)
- {
- /* Error - DesktopToXScaleTransfer thread should have terminated by now. */
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- else if (nRetVal == WAIT_OBJECT_0)
- {
- BOOL bCloseRetVal = 0;
- /* Thread object has signalled state. Thread has been exited. */
- bCloseRetVal = CloseHandle(hThread_DesktopTransfer);
- hThread_DesktopTransfer = NULL;
- TEXTOUT(TEXT("DUALDISPDEMO: StopDesktopToXScaleTransfer: exited DesktopTransfer thread.n"));
- if (bCloseRetVal == 0)
- {
- /* Error - Failed to close handle */
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- }
- else if (nRetVal == WAIT_FAILED)
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- }
- else
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : StopGDIRectangles
- Inputs :
- Outputs :
-
- Returns :
- Description : Shuts down the GDIRectangles thread.
- ************************************************************************************/
- LONG StopGDIRectangles()
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- BOOL bEventRetVal = 0;
- DWORD dwWaitInMilliseconds = 1000;
- DWORD nRetVal = WAIT_FAILED;
- bEventRetVal = SetEvent(hEvent_StopGDIRectangles);
- TEXTOUT(TEXT("DUALDISPDEMO: StopGDIRectangles: exiting thread.n"));
- if (bEventRetVal)
- {
- /* StopDesktopTransfer event has been signalled */
- nRetVal = WaitForSingleObject(hThread_GDIRectangles, dwWaitInMilliseconds);
- if (nRetVal == WAIT_TIMEOUT)
- {
- /* Error - thread should have terminated by now. */
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- else if (nRetVal == WAIT_OBJECT_0)
- {
- BOOL bCloseRetVal = 0;
- /* Thread object has signalled state. Thread has been exited. */
- TEXTOUT(TEXT("DUALDISPDEMO: StopGDIRectangles: GDIRectangles thread has exited.n"));
- bCloseRetVal = CloseHandle(hThread_GDIRectangles);
- hThread_GDIRectangles = NULL;
- if (bCloseRetVal == 0)
- {
- /* Error - Failed to close handle */
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- }
- else if (nRetVal == WAIT_FAILED)
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- }
- else
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : BeginDesktopToXScaleTransfer
- Inputs : hdcXScale
- Outputs : sDesktopSurfaceInfo
- sXScaleSurfaceInfo
- Returns :
- Description : Transfer the desktop surface from the Marathon primary
- surface to the XScale primary surface.
- ************************************************************************************/
- LONG BeginDesktopToXScaleTransfer(DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo,
- HDC hdcXScale)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- /* The LCD switch must be programmed correctly before beginning desktop transfer. */
-
- /* Get desktop surface information from Marathon, i.e. mode information,
- orientation, and physical address of Marathon frame buffer. */
- /* Note: This function should always be called twice when desktop is to be transfered:
- firstly it is called in WinMain, and secondly here. This second call must be made after
- the call to DE_ConfigureDisplaySystem (by a Config_xxxxxx function). DE_ConfigureDisplaySystem
- will force the Marathon driver to set a new rotation angle for the surface (if it is required).
- Thus bDriverRealigned can be correctly set (indicating whether Marathon driver has changed the
- desktop surface rotation angle in order to support the external display) by comparing the
- 'initial' desktop rotation angle with the 'current' desktop rotation angle. */
- nDDRetVal |= DE_GetMarathonSurfaceInfo(sDesktopSurfaceInfo, DCFG_DESKTOP, hdcMarathon);
-
- /* Check to see if surface has been realigned. Compare the new rotation angle with the old
- rotation angle. */
- if (sDesktopSurfaceInfo.sPhysSurfaceInfo.lPhysicalRotation == lInitialDesktopRotation)
- {
- sDesktopSurfaceInfo.sPhysSurfaceInfo.bDriverRealigned = FALSE;
- }
- else
- {
- sDesktopSurfaceInfo.sPhysSurfaceInfo.bDriverRealigned = TRUE;
- }
- /* Get destination (XScale) surface information: width, height, bpp, stride,
- buffer address. */
- nDDRetVal |= DE_GetXScaleSurfaceInfo(sXScaleSurfaceInfo, hdcXScale);
-
- /* Check there are no errors before starting 'Desktop to XScale' transfer thread. */
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- return nDDRetVal;
- }
- /* Data transfer engine is used to copy the Desktop from the Marathon primary
- surface to the XScale primary surface. */
- /* Create an event object to control termination of 'Desktop to XScale' Transfer thread.
- Event object has attributes: 'auto-reset', 'initially nonsignalled'. */
- hEvent_StopDesktopTransfer = CreateEvent(NULL, FALSE, FALSE, TEXT("StopDesktopTransfer"));
- if (hEvent_StopDesktopTransfer == NULL)
- {
- /* Failed to create event object */
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- hThread_DesktopTransfer = CreateThread(NULL, 0, DesktopToXScaleTransfer,
- NULL, 0, NULL);
- if (hThread_DesktopTransfer == NULL)
- {
- /* Failed to create thread */
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: BeginDesktopToXScaleTransfer: Error.n"));
- }
- TEXTOUT(TEXT("DUALDISPDEMO: BeginDesktoptoXScaleTransfer exit.n"));
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : DesktopToXScaleTransfer
- Inputs : lpParameter
- Inputs/Outputs :
- Returns : Error code
- Description : Controls Desktop to XScale transfer process. The routine will
- decide whether to perform line and pixel doubling. It will
- also perform any required rotation.
- ************************************************************************************/
- DWORD WINAPI DesktopToXScaleTransfer(LPVOID lpParameter)
- {
- ULONG nDDRetVal = DUALDISPSUCCESS;
- BOOL bPixelDouble;
- ULONG ulSrcWidth, ulSrcHeight, ulDestWidth, ulDestHeight, ulSrcLength, ulDestLength, ulSrcStride;
- /* Make sure this surface is displaying the desktop. */
- assert(sDesktopSurfaceInfo.eDisplaySurface == DCFG_DESKTOP);
- if (sDesktopSurfaceInfo.eDisplaySurface != DCFG_DESKTOP)
- {
- /* Error: this function can only transfer a Desktop surface to the XScale. */
- TEXTOUT(TEXT("DUALDISPDEMO: DesktopToXScaleTransfer works for a Desktop surface only.n"));
- return DUALDISPERROR;
- }
- ulDestWidth = sXScaleSurfaceInfo.ulWidth;
- ulDestHeight = sXScaleSurfaceInfo.ulHeight;
- ulSrcWidth = sDesktopSurfaceInfo.sPhysSurfaceInfo.ulWidth;
- ulSrcHeight = sDesktopSurfaceInfo.sPhysSurfaceInfo.ulHeight;
- ulSrcStride = sDesktopSurfaceInfo.sPhysSurfaceInfo.ulStride;
- /* Find out whether or not pixel doubling is required. */
- ulSrcLength = (ulSrcWidth > ulSrcHeight) ? ulSrcWidth : ulSrcHeight;
- ulDestLength = (ulDestWidth > ulDestHeight) ? ulDestWidth : ulDestHeight;
- if (ulSrcLength == ulDestLength)
- {
- /* Pixel doubling not required */
- bPixelDouble = FALSE;
- }
- else if ((ulSrcLength * 2) == ulDestLength)
- {
- /* Perform pixel doubling */
- bPixelDouble = TRUE;
- }
- else
- {
- /* Source and destination aspect ratios do not match. */
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- /* Has the Marathon surface been re-aligned? */
- if ( sDesktopSurfaceInfo.sPhysSurfaceInfo.bDriverRealigned)
- {
- /* MIRROR MODE: Marathon surface has been realigned in order to
- support an external display. This means that standard rotation
- angle (used to compensate for the angle at which the internal panel
- is mounted and/or viewed), will not be applied in this case.
-
- Hence the surface must be rotated here instead. */
-
- ULONG srcAddress, destAddress, ulRequiredRotation;
- destAddress = sXScaleSurfaceInfo.ulPhysAddress;
- srcAddress = sDesktopSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress;
- ulRequiredRotation = lInitialDesktopRotation;
- /* Is Pixel/Line doubling required? */
- if (bPixelDouble)
- {
- /* Mirror mode with pixel/line doubling */
-
- /* Rotate Marathon frame buffer to XScale frame buffer.
- Perform pixel/line doubling. */
- nDDRetVal |= RotateAndDoubleToBuffer((USHORT*) destAddress, (USHORT*) srcAddress,
- ulDestWidth, ulDestHeight, ulRequiredRotation, ulSrcWidth, ulSrcHeight, ulSrcStride);
- }
- else // Mirror mode without pixel/line doubling
- {
- /* Rotate Marathon frame buffer to the XScale frame buffer.
- Do not pixel/line double. */
- nDDRetVal |= RotateToBuffer((USHORT*) destAddress, (USHORT*) srcAddress,
- ulDestWidth, ulDestHeight, ulRequiredRotation, ulSrcWidth, ulSrcHeight, ulSrcStride);
- }
- }
- else
- {
- /* Marathon surface has not been re-aligned. It should be copied to XScale frame
- buffer without rotation. */
-
- /* There are two scenarios in which the Desktop will not have been realigned and
- thus rotation is not required:
-
- (1) When the dual display mode is NOT MirrorMode
- (2) In MirrorMode when the desktop does NOT require rotation in order to be
- displayed on the internal panel.
-
- */
- /* Is Pixel/Line doubling required? */
- if (bPixelDouble)
- {
- /* Copy Marathon frame buffer to XScale frame buffer. Perform
- pixel/line doubling. Do not rotate. */
- TEXTOUT(TEXT("DUALDISPDEMO: Copying Desktop to XScale with pixel doubling.n"));
- nDDRetVal |= CopyAndDoubleToXScaleFB(sDesktopSurfaceInfo, sXScaleSurfaceInfo);
- }
- else // Custom application mode without pixel/line doubling
- {
- /* Copy Marathon frame buffer to XScale frame bufer.
- Do not perform pixel/line doubling. */
- TEXTOUT(TEXT("DUALDISPDEMO: Copying Desktop to XScale without pixel doubling.n"));
- nDDRetVal |= CopyToXScaleFB(sDesktopSurfaceInfo, sXScaleSurfaceInfo);
- }
- }
- TEXTOUT(TEXT("DUALDISPDEMO: DesktopToXScaleTransfer: Exiting Desktop to XScale Transfer thread.n"));
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DesktopToXScaleTransfer: Error.n"));
- }
- return nDDRetVal;
- }
- /* Turn off optimization for 'Desktop to XScale copy routine' (PocketPC, release builds) to prevent underrun. */
- #ifdef OSV_PPC
- #ifdef NDEBUG
- #pragma optimize("", off)
- #endif
- #endif
- /***********************************************************************************
- Function Name : CopyToXScaleFB
- Inputs/Outputs : sMarathonSurfaceInfo
- sXScaleSurfaceInfo
- Outputs :
- Returns : Error Code
- Description : Copies the Marathon frame buffer to the XScale frame buffer.
- Pixel and line doubling are not performed.
- ************************************************************************************/
- LONG CopyToXScaleFB(DISPCFG_GET_SURFACE_INFO& sMarathonSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo)
- {
- ULONG nDDRetVal = DUALDISPSUCCESS;
- DWORD dwWaitObjRetVal = 0;
- DWORD dwDelayInMilliseconds = DESKTOPTOXSCALEDELAY;
- ULONG SourceFrameBufSizeInInt32;
- ULONG* pulSourceBuf, * pulDestinationBuf;
- TCHAR wstrOutput[200];
- BOOL bIsDirty = FALSE;
- wsprintf(wstrOutput, TEXT("DUALDISPDEMO: CopyToXScaleFB: Delay = %d ms.n"), dwDelayInMilliseconds);
- TEXTOUT(wstrOutput);
- /* ulStride indicates the physical dimensions of the surface - irrespective of the intended viewing angle.
- Note: a 'portrait' image is described by the driver as having ('height' > 'width') and a landscape image is
- described as having ('width' > 'height'). Thus the driver describes the 'logical view'. However, in order to
- copy from the frame buffer, the 'logical view' must be converted to the 'physical view'. */
- if (sMarathonSurfaceInfo.sPhysSurfaceInfo.ulStride != (sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth * 2))
- {
- /* Swap width and height in order to obtain a physical description of the frame buffer. */
- ULONG ulTemp = sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth;
- sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth = sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight;
- sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight = ulTemp;
- }
- /* This function can only operate when the source and destination frame buffers have
- the same width and height. */
- assert(sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth == sXScaleSurfaceInfo.ulWidth);
- assert(sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight == sXScaleSurfaceInfo.ulHeight);
- /* Verify display aspect ratios */
- if ((sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth != sXScaleSurfaceInfo.ulWidth) ||
- (sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight != sXScaleSurfaceInfo.ulHeight))
- {
- TEXTOUT(TEXT("DUALDISPDEMO: CopyToXScaleFB: Error - source and destination buffers incompatible.n"));
- return DUALDISPERROR;
- }
- /* Verify frame buffer addresses */
- if ((sMarathonSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress == NULL) ||
- (sXScaleSurfaceInfo.ulPhysAddress == NULL))
- {
- TEXTOUT(TEXT("DUALDISPDEMO: CopyToXScaleFB: Error - frame buffer address invalid.n"));
- return DUALDISPERROR;
- }
- SourceFrameBufSizeInInt32 = sMarathonSurfaceInfo.sPhysSurfaceInfo.ulStride *
- sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight / sizeof(ULONG);
- for(;;)
- {
- static ULONG nConsecutiveScreenUpdates = 0;
- dwWaitObjRetVal = WaitForSingleObject(hEvent_StopDesktopTransfer, dwDelayInMilliseconds);
- /* See if Marathon frame buffer has changed since it was last copied to the
- XScale display surface. */
- DE_CheckForScreenUpdate(hdcMarathon, bIsDirty);
- /* Adjust the rate of screen update checks. NOTE: only use this function if GSB cannot
- cope with bandwidth requirements of DesktopToXScaleTransfer. */
- // AdjustRefreshRate(bIsDirty, nConsecutiveScreenUpdates, dwDelayInMilliseconds);
- /* If bIsDirty is TRUE, then an attempt should be made to update the screen by
- executing the 'if-else' statement below (which processes dwWaitObjRetVal). If
- dwWaitObjRetVal does NOT equal WAIT_TIMEOUT, then the 'if-else' statement below
- MUST be executed to catch WAIT_FAILED and WAIT_OBJECT_0. */
- if ((bIsDirty == FALSE) && (dwWaitObjRetVal == WAIT_TIMEOUT))
- {
- continue;
- }
- /* Marathon frame buffer has changed, therefore update XScale frame buffer. */
- if (dwWaitObjRetVal == WAIT_TIMEOUT)
- {
- pulSourceBuf = (ULONG*) sMarathonSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress;
- pulDestinationBuf = (ULONG*) sXScaleSurfaceInfo.ulPhysAddress;
- #if (CHECK_MEM_COPY_SPEED == 1)
- //////////////////////// Monitor copy loop speed //////////////////////////////
- DWORD dwStart = GetTickCount();
- ///////////////////////////////////////////////////////////////////////////////
- #endif
- for (ULONG i = 0; i < SourceFrameBufSizeInInt32; i++)
- {
- *pulDestinationBuf++ = *pulSourceBuf++;
- }
- #if (CHECK_MEM_COPY_SPEED == 1)
- ////////////////////////////////////////////////////////////////////////////////
- DWORD dwEnd = GetTickCount();
- DWORD timetaken = dwEnd - dwStart;
- TCHAR outstring[100];
- wsprintf(outstring, TEXT("DUALDISPDEMO: Loop time: %dn"), timetaken);
- TEXTOUT(outstring);
- ////////////////////////////////////////////////////////////////////////////////
- #endif
- }
- else if (dwWaitObjRetVal == WAIT_OBJECT_0)
- {
- /* hEvent_StopDesktopTransfer event object signalled - therefore stop transfer */
- TEXTOUT(TEXT("DUALDISPDEMO: CopyToXScaleFB: Exiting desktop transfer.n"));
- return nDDRetVal;
- }
- else if (dwWaitObjRetVal == WAIT_FAILED)
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- else
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- }
- return nDDRetVal;
- }
- /* Restore optimization */
- #ifdef OSV_PPC
- #ifdef NDEBUG
- #pragma optimize("", on)
- #endif
- #endif
- /* Turn off optimization for 'Desktop to XScale copy routine' (PocketPC, release builds) to prevent underrun. */
- #ifdef OSV_PPC
- #ifdef NDEBUG
- #pragma optimize("", off)
- #endif
- #endif
- /***********************************************************************************
- Function Name : CopyAndDoubleToXScaleFB
- Inputs/Outputs : sMarathonSurfaceInfo
- sXScaleSurfaceInfo
- Outputs :
- Returns : Error code
- Description : Copies the Marathon frame buffer to the XScale frame buffer.
- Pixel and line doubling are performed.
- ************************************************************************************/
- LONG CopyAndDoubleToXScaleFB(DISPCFG_GET_SURFACE_INFO& sMarathonSurfaceInfo,
- XSCALE_SURFACE_INFO& sXScaleSurfaceInfo)
- {
- ULONG nDDRetVal = DUALDISPSUCCESS;
- DWORD dwDelayInMilliseconds = DESKTOPTOXSCALEDELAY;
- DWORD dwWaitObjRetVal = 0;
- USHORT* pulSourceBuf, * pulDestinationBuf;
- BOOL bIsDirty = FALSE;
- /* ulStride indicates the physical dimensions of the surface - irrespective of the intended viewing angle.
- Note: a 'portrait' image is described by the driver as having ('height' > 'width') and a landscape image is
- described as having ('width' > 'height'). Thus the driver describes the 'logical view'. However, in order to
- copy from the frame buffer, the 'logical view' must be converted to the 'physical view'. */
- if (sMarathonSurfaceInfo.sPhysSurfaceInfo.ulStride != (sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth * 2))
- {
- /* Swap width and height in order to obtain a physical description of the frame buffer. */
- ULONG ulTemp = sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth;
- sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth = sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight;
- sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight = ulTemp;
- }
- /* This function can only operate when width and height of destination buffer are
- twice the width and height of the source buffer. */
- assert((sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth * 2) == sXScaleSurfaceInfo.ulWidth);
- assert((sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight * 2) == sXScaleSurfaceInfo.ulHeight);
- /* Verify display aspect ratios */
- if (((sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth * 2) != sXScaleSurfaceInfo.ulWidth) ||
- ((sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight * 2) != sXScaleSurfaceInfo.ulHeight))
- {
- TEXTOUT(TEXT("DUALDISPDEMO: CopyAndDoubleToXScaleFB: Error - source and destination buffers incompatible.n"));
- return DUALDISPERROR;
- }
- /* Verify frame buffer addresses */
- if ((sMarathonSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress == NULL) ||
- (sXScaleSurfaceInfo.ulPhysAddress == NULL))
- {
- TEXTOUT(TEXT("DUALDISPDEMO: CopyAndDoubleToXScaleFB: Error - frame buffer address invalid.n"));
- return DUALDISPERROR;
- }
- for(;;)
- {
- static ULONG nConsecutiveScreenUpdates = 0;
- dwWaitObjRetVal = WaitForSingleObject(hEvent_StopDesktopTransfer, dwDelayInMilliseconds);
- /* See if Marathon frame buffer has changed since it was last copied to the
- XScale display surface. */
- DE_CheckForScreenUpdate(hdcMarathon, bIsDirty);
- /* Adjust the rate of screen update checks. NOTE: only use this function if GSB cannot
- cope with bandwidth requirements of DesktopToXScaleTransfer. */
- // AdjustRefreshRate(bIsDirty, nConsecutiveScreenUpdates, dwDelayInMilliseconds);
- /* If bIsDirty is TRUE, then an attempt should be made to update the screen by
- executing the 'if-else' statement below (which processes dwWaitObjRetVal). If
- dwWaitObjRetVal does NOT equal WAIT_TIMEOUT, then the 'if-else' statement below
- MUST be executed to catch WAIT_FAILED and WAIT_OBJECT_0. */
- if ((bIsDirty == FALSE) && (dwWaitObjRetVal == WAIT_TIMEOUT))
- {
- continue;
- }
- if (dwWaitObjRetVal == WAIT_TIMEOUT)
- {
- /* Copy one frame of desktop surface to XScale frame buffer. */
- pulSourceBuf = (USHORT*) sMarathonSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress;
- pulDestinationBuf = (USHORT*) sXScaleSurfaceInfo.ulPhysAddress;
- /* Invalidate the data cache. This must be done because the Marathon frame buffer is
- written by a different process (via a different virtual address). Hence cache
- coherency will not be maintained. Invalidating the data-cache will ensure that
- all pixels are re-read from the Marathon frame buffer. */
- // InvalidateDataCache causing application to hang
- // SetKMode(TRUE);
- // InvalidateDataCache();
- // SetKMode(FALSE);
- /* This may not be necessary due to cache size (32KB).
- Round-robin cache-line eviction will ensure that all cache-lines are overwritten
- before there is a possibility of a cache hit. Note: this assumes that the Marathon
- frame buffer is a least twice the size of the cache (32 KB). Frame buffer:
- 320 * 240 = 150 KB. */
-
- #if (CHECK_MEM_COPY_SPEED == 1)
- //////////////////////// Monitor copy loop speed //////////////////////////////
- DWORD dwStart = GetTickCount();
- ///////////////////////////////////////////////////////////////////////////////
- #endif
- /* Perform pixel/line doubling */
- for (ULONG i = 0; i < sMarathonSurfaceInfo.sPhysSurfaceInfo.ulHeight; i++)
- {
- // Copy a line from Marathon frame buffer to XScale frame buffer
- for (ULONG j = 0; j < sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth; j++)
- {
- usTempBuffer[j] = pulSourceBuf[j];
- }
- for (ULONG k = 0; k < sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth; k++)
- {
- *pulDestinationBuf = usTempBuffer[k];
- /* Write to the corresponding pixel in the next line */
- *(pulDestinationBuf + sXScaleSurfaceInfo.ulWidth) = usTempBuffer[k];
- pulDestinationBuf++;
- *pulDestinationBuf = usTempBuffer[k];
- /* Write to the corresponding pixel in the next line */
- *(pulDestinationBuf + sXScaleSurfaceInfo.ulWidth) = usTempBuffer[k];
- pulDestinationBuf++;
- }
- pulDestinationBuf += sXScaleSurfaceInfo.ulWidth;
- pulSourceBuf += sMarathonSurfaceInfo.sPhysSurfaceInfo.ulWidth;
- }
- #if (CHECK_MEM_COPY_SPEED == 1)
- ////////////////////////////////////////////////////////////////////////////////
- DWORD dwEnd = GetTickCount();
- DWORD timetaken = dwEnd - dwStart;
- TCHAR outstring[100];
- wsprintf(outstring, TEXT("DUALDISPDEMO: Loop time: %dn"), timetaken);
- TEXTOUT(outstring);
- ////////////////////////////////////////////////////////////////////////////////
- #endif
- }
- else if (dwWaitObjRetVal == WAIT_OBJECT_0)
- {
- /* hEvent_StopDesktopTransfer event object signalled - therefore stop transfer */
- TEXTOUT(TEXT("DUALDISPDEMO: CopyAndDoubleToXScaleFB: exiting DesktopTransfer thread.n"));
- return nDDRetVal;
- }
- else if (dwWaitObjRetVal == WAIT_FAILED)
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- else
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- }
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: CopyAndDoubleToXScaleFB: returning error value.n"));
- assert(0);
- }
- return nDDRetVal;
- }
- /* Restore optimization */
- #ifdef OSV_PPC
- #ifdef NDEBUG
- #pragma optimize("", on)
- #endif
- #endif
- /* Turn off optimization for 'Desktop to XScale copy routine' (PocketPC, release builds) to prevent underrun. */
- #ifdef OSV_PPC
- #ifdef NDEBUG
- #pragma optimize("", off)
- #endif
- #endif
- /***********************************************************************************
- Function Name : RotateToBuffer
- Inputs : pulSrcBuffer
- ulDestWidth
- ulDestHeight
- destRotation
- ulSrcWidth
- ulSrcHeight
- Outputs : pulDestBuffer
- Returns : Error code
- Description : Copy the source buffer to the destination buffer. Perform the
- required rotation. Do not pixel/line double.
- ************************************************************************************/
- LONG RotateToBuffer(USHORT* pulDestBuffer, USHORT* pulSrcBuffer,
- ULONG ulDestWidth, ULONG ulDestHeight, ULONG ulRequiredRotation,
- ULONG ulSrcWidth, ULONG ulSrcHeight, ULONG ulSrcStride)
- {
- ULONG nDDRetVal = DUALDISPSUCCESS;
- DWORD dwDelayInMilliseconds = DESKTOPTOXSCALEDELAY;
- DWORD dwWaitObjRetVal = 0;
- ULONG srcX, srcY;
- LONG destX, destY;
- BOOL bIsDirty = FALSE;
- /* ulStride indicates the physical dimensions of the surface - irrespective of the intended viewing angle.
- Note: a 'portrait' image is described by the driver as having ('height' > 'width') and a landscape image is
- described as having ('width' > 'height'). Thus the driver describes the 'logical view'. However, in order to
- copy from the frame buffer, the 'logical view' must be converted to the 'physical view'. */
- if (ulSrcStride != (ulSrcWidth * 2))
- {
- /* Swap width and height in order to obtain a physical description of the frame buffer. */
- ULONG ulTemp = ulSrcWidth;
- ulSrcWidth = ulSrcHeight;
- ulSrcHeight = ulTemp;
- }
- /* Verify frame buffer addresses */
- if ((pulDestBuffer == NULL) || (pulSrcBuffer == NULL))
- {
- TEXTOUT(TEXT("DUALDISPDEMO: RotateToBuffer: Error - frame buffer address invalid.n"));
- return DUALDISPERROR;
- }
- for(;;)
- {
- static ULONG nConsecutiveScreenUpdates = 0;
- dwWaitObjRetVal = WaitForSingleObject(hEvent_StopDesktopTransfer, dwDelayInMilliseconds);
- /* See if Marathon frame buffer has changed since it was last copied to the
- XScale display surface. */
- DE_CheckForScreenUpdate(hdcMarathon, bIsDirty);
- /* Adjust the rate of screen update checks. NOTE: only use this function if GSB cannot
- cope with bandwidth requirements of DesktopToXScaleTransfer. */
- // AdjustRefreshRate(bIsDirty, nConsecutiveScreenUpdates, dwDelayInMilliseconds);
- /* If bIsDirty is TRUE, then an attempt should be made to update the screen by
- executing the 'if-else' statement below (which processes dwWaitObjRetVal). If
- dwWaitObjRetVal does NOT equal WAIT_TIMEOUT, then the 'if-else' statement below
- MUST be executed to catch WAIT_FAILED and WAIT_OBJECT_0. */
- if ((bIsDirty == FALSE) && (dwWaitObjRetVal == WAIT_TIMEOUT))
- {
- continue;
- }
- if (dwWaitObjRetVal == WAIT_TIMEOUT)
- {
- /* Transfer one frame from Desktop surface to XScale frame buffer. */
- #if (CHECK_MEM_COPY_SPEED == 1)
- //////////////////////// Monitor copy loop speed //////////////////////////////
- DWORD dwStart = GetTickCount();
- ///////////////////////////////////////////////////////////////////////////////
- #endif
- if (ulRequiredRotation == 0)
- {
- assert(ulDestWidth == ulSrcWidth);
- assert(ulDestHeight == ulDestHeight);
- for (srcY = 0; srcY < ulSrcHeight; srcY++)
- {
- destY = srcY;
- for (srcX = 0; srcX < ulSrcWidth; srcX++)
- {
- destX = srcX;
- /* copy a source pixel to a destination pixel */
- pulDestBuffer[destY * ulDestWidth + destX] = pulSrcBuffer[srcY * ulSrcWidth + srcX];
- }
- }
- }
- else if (ulRequiredRotation == 270)
- {
- /* Perform 270 degree rotation */
- assert(ulDestWidth == ulSrcHeight);
- assert(ulSrcWidth == ulDestHeight);
- destX = ulDestWidth - 1;
- for (srcY = 0; srcY < ulSrcHeight; srcY++)
- {
- // get destination x co-ordinate
- assert(destX >= 0);
- for (srcX = 0; srcX < ulSrcWidth; srcX++)
- {
- /* get destination y co-ordinate */
- destY = srcX;
- assert(destY < ((LONG) ulDestHeight));
- /* copy a source pixel to a destination pixel */
- pulDestBuffer[destY * ulDestWidth + destX] = pulSrcBuffer[srcY * ulSrcWidth + srcX];
- }
- destX--;
- }
- }
- else if (ulRequiredRotation == 180)
- {
- assert(ulDestHeight == ulSrcHeight);
- assert(ulDestWidth == ulSrcWidth);
- destY = ulDestHeight - 1;
- for (srcY = 0; srcY < ulSrcHeight; srcY++)
- {
- destX = ulDestWidth - 1;
- assert(destY >= 0);
- for (srcX = 0; srcX < ulSrcWidth; srcX++)
- {
- assert(destY >= 0);
- /* copy a source pixel to a destination pixel */
- pulDestBuffer[destY * ulDestWidth + destX] = pulSrcBuffer[srcY * ulSrcWidth + srcX];
- destX--;
- }
- destY--;
- }
- }
- else if (ulRequiredRotation == 90)
- {
- /* Perform 90 degree rotation */
- assert(ulDestWidth == ulSrcHeight);
- assert(ulSrcWidth == ulDestHeight);
- for (srcY = 0; srcY < ulSrcHeight; srcY++)
- {
- /* get destination x co-ordinate */
- destX = srcY;
- destY = ulDestHeight - 1;
- assert(destX < (LONG) ulDestWidth);
- for (srcX = 0; srcX < ulSrcWidth; srcX++)
- {
- /* get destination y co-ordinate */
- assert(destY >= 0);
- /* copy source pixel to destination pixel */
- pulDestBuffer[destY * ulDestWidth + destX] = pulSrcBuffer[srcY * ulSrcWidth + srcX];
- destY--;
- }
- }
- }
- #if (CHECK_MEM_COPY_SPEED == 1)
- ////////////////////////////////////////////////////////////////////////////////
- DWORD dwEnd = GetTickCount();
- DWORD timetaken = dwEnd - dwStart;
- TCHAR outstring[100];
- wsprintf(outstring, TEXT("DUALDISPDEMO: Loop time: %dn"), timetaken);
- TEXTOUT(outstring);
- ////////////////////////////////////////////////////////////////////////////////
- #endif
- }
- else if (dwWaitObjRetVal == WAIT_OBJECT_0)
- {
- /* hEvent_StopDesktopTransfer event object signalled - therefore stop transfer */
- TEXTOUT(TEXT("DUALDISPDEMO: RotateToBuffer: Exiting desktop transfer.n"));
- return nDDRetVal;
- }
- else if (dwWaitObjRetVal == WAIT_FAILED)
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- else
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- }
- return nDDRetVal;
- }
- /* Restore optimization */
- #ifdef OSV_PPC
- #ifdef NDEBUG
- #pragma optimize("", on)
- #endif
- #endif
- /* Turn off optimization for 'Desktop to XScale copy routine' (PocketPC, release builds) to prevent underrun. */
- #ifdef OSV_PPC
- #ifdef NDEBUG
- #pragma optimize("", off)
- #endif
- #endif
- /***********************************************************************************
- Function Name : RotateAndDoubleToBuffer
- Inputs : pulSrcBuffer
- ulDestWidth
- ulDestHeight
- destRotation
- ulSrcWidth
- ulSrcHeight
- Outputs : DestBuffer
- Returns : Error code
- Description : Copy the source buffer to the destination buffer. Perform the
- required rotation. Do pixel and line doubling.
- ************************************************************************************/
- LONG RotateAndDoubleToBuffer(USHORT* pulDestBuffer, USHORT* pulSrcBuffer,
- ULONG ulDestWidth, ULONG ulDestHeight, ULONG ulRequiredRotation,
- ULONG ulSrcWidth, ULONG ulSrcHeight, ULONG ulSrcStride)
- {
- ULONG nDDRetVal = DUALDISPSUCCESS;
- DWORD dwDelayInMilliseconds = DESKTOPTOXSCALEDELAY;
- DWORD dwWaitObjRetVal = 0;
- LONG srcX, srcY, destY;
- LONG destX;
- BOOL bIsDirty = FALSE;
- /* ulStride indicates the physical dimensions of the surface - irrespective of the intended viewing angle.
- Note: a 'portrait' image is described by the driver as having ('height' > 'width') and a landscape image is
- described as having ('width' > 'height'). Thus the driver describes the 'logical view'. However, in order to
- copy from the frame buffer, the 'logical view' must be converted to the 'physical view'. */
- if (ulSrcStride != (ulSrcWidth * 2))
- {
- /* Swap width and height in order to obtain a physical description of the frame buffer. */
- ULONG ulTemp = ulSrcWidth;
- ulSrcWidth = ulSrcHeight;
- ulSrcHeight = ulTemp;
- }
- /* Verify frame buffer addresses */
- if ((pulDestBuffer == NULL) || (pulSrcBuffer == NULL))
- {
- TEXTOUT(TEXT("DUALDISPDEMO: RotateAndDoubleToBuffer: Error - frame buffer address invalid.n"));
- return DUALDISPERROR;
- }
- for(;;)
- {
- static ULONG nConsecutiveScreenUpdates = 0;
- dwWaitObjRetVal = WaitForSingleObject(hEvent_StopDesktopTransfer, dwDelayInMilliseconds);
- /* See if Marathon frame buffer has changed since it was last copied to the
- XScale display surface. */
- DE_CheckForScreenUpdate(hdcMarathon, bIsDirty);
- /* Adjust the rate of screen update checks. NOTE: only use this function if GSB cannot
- cope with bandwidth requirements of DesktopToXScaleTransfer. */
- // AdjustRefreshRate(bIsDirty, nConsecutiveScreenUpdates, dwDelayInMilliseconds);
- /* If bIsDirty is TRUE, then an attempt should be made to update the screen by
- executing the 'if-else' statement below (which processes dwWaitObjRetVal). If
- dwWaitObjRetVal does NOT equal WAIT_TIMEOUT, then the 'if-else' statement below
- MUST be executed to catch WAIT_FAILED and WAIT_OBJECT_0. */
- if ((bIsDirty == FALSE) && (dwWaitObjRetVal == WAIT_TIMEOUT))
- {
- continue;
- }
- if (dwWaitObjRetVal == WAIT_TIMEOUT)
- {
- /* Copy one frame from desktop surface to XScale frame buffer. */
- #if (CHECK_MEM_COPY_SPEED == 1)
- //////////////////////// Monitor copy loop speed //////////////////////////////
- DWORD dwStart = GetTickCount();
- ///////////////////////////////////////////////////////////////////////////////
- #endif
- if (ulRequiredRotation == 0)
- {
- assert(ulDestHeight == (2 * ulSrcHeight));
- assert(ulDestWidth == (2 * ulSrcWidth));
- USHORT* pSrcBuffer = pulSrcBuffer;
- for (srcY = 0; srcY < (LONG) ulSrcHeight; srcY++)
- {
- destY = srcY * 2;
- /* Copy a line from the source buffer. */
- for (srcX = 0; srcX < (LONG) ulSrcWidth; srcX++)
- {
- usTempBuffer[srcX] = pSrcBuffer[srcX];
- }
- pSrcBuffer += ulSrcWidth;
- for (srcX = 0; srcX < (LONG) ulSrcWidth; srcX++)
- {
- destX = srcX * 2;
- /* Write the horizontal part of image */
- pulDestBuffer[destY * ulDestWidth + destX] = usTempBuffer[srcX];
- pulDestBuffer[destY * ulDestWidth + destX + 1] = usTempBuffer[srcX];
- pulDestBuffer[(destY+1) * ulDestWidth + destX] = usTempBuffer[srcX];
- pulDestBuffer[(destY+1) * ulDestWidth + destX + 1] = usTempBuffer[srcX];
- }
- }
- }
- else if (ulRequiredRotation == 270)
- {
- USHORT* pSrcBuffer = pulSrcBuffer;
- /* Copy a frame from source buffer */
- for (srcX = 0; srcX < (LONG) (ulSrcWidth * ulSrcHeight); srcX++)
- {
- usTempBuffer[srcX] = pSrcBuffer[srcX];
- }
-
- srcX = 0;
- for (destY = 0; destY < (LONG) ulDestHeight; destY+=2)
- {
- srcY = ulSrcHeight - 1;
-
- srcX = destY / 2;
-
- assert(((srcX < (LONG) ulSrcWidth) && (srcX >= 0)));
- for (destX = 0 ; destX < (LONG) ulDestWidth; destX+=2)
- {
- assert(((srcY < (LONG) ulSrcHeight) && (srcY >= 0)));
- // copy a source pixel to a destination pixel
- pulDestBuffer[destY * ulDestWidth + destX] = usTempBuffer[srcY * ulSrcWidth + srcX];
- // pixel double: copy the same pixel to column 'destX - 1'
- pulDestBuffer[destY * ulDestWidth + destX + 1] = usTempBuffer[srcY * ulSrcWidth + srcX];
- // line double: in the y direction
- pulDestBuffer[(destY+1) * ulDestWidth + destX] = usTempBuffer[srcY * ulSrcWidth + srcX];
- // line and pixel double: copy the same pixel to column 'destx - 1'
- pulDestBuffer[(destY+1) * ulDestWidth + destX + 1] = usTempBuffer[srcY * ulSrcWidth + srcX];
- srcY--;
- }
- }
- }
- else if (ulRequiredRotation == 180)
- {
- destY = ulDestHeight - 1;
- assert(ulDestHeight == (2 * ulSrcHeight));
- assert(ulDestWidth == (2 * ulSrcWidth));
- USHORT* pSrcBuffer = pulSrcBuffer;
- for (srcY = 0; srcY < (LONG) ulSrcHeight; srcY++)
- {
- destX = ulDestWidth - 1;
- assert(destY > 0);
- /* Copy a line from the source buffer. */
- for (srcX = 0; srcX < (LONG) ulSrcWidth; srcX++)
- {
- usTempBuffer[srcX] = pSrcBuffer[srcX];
- }
- pSrcBuffer += ulSrcWidth;
- for (srcX = 0; srcX < (LONG) ulSrcWidth; srcX++)
- {
- assert(destX > 0);
- /* Write the horizontal part of image */
- pulDestBuffer[destY * ulDestWidth + destX] = usTempBuffer[srcX];
- pulDestBuffer[destY * ulDestWidth + destX - 1] = usTempBuffer[srcX];
- pulDestBuffer[(destY-1) * ulDestWidth + destX] = usTempBuffer[srcX];
- pulDestBuffer[(destY-1) * ulDestWidth + destX - 1] = usTempBuffer[srcX];
- destX -= 2;
- }
- destY -= 2;
- }
- }
- else if (ulRequiredRotation == 90) // no ... use the correction angle
- {
- USHORT* pSrcBuffer = pulSrcBuffer;
- /* Copy a frame from source buffer */
- for (srcX = 0; srcX < (LONG) (ulSrcWidth * ulSrcHeight); srcX++)
- {
- usTempBuffer[srcX] = pSrcBuffer[srcX];
- }
-
- srcX = ulSrcWidth - 1;
-
- for (destY = 0; destY < (LONG) ulDestHeight; destY+=2)
- {
- for (destX = 0 ; destX < (LONG) ulDestWidth; destX+=2)
- {
- assert(srcX >= 0);
- srcY = destX / 2;
- assert(((srcY >= 0) && (srcY < (LONG) ulSrcHeight)));
- // copy a source pixel to a destination pixel
- pulDestBuffer[destY * ulDestWidth + destX] = usTempBuffer[srcY * ulSrcWidth + srcX];
- // pixel double: copy the same pixel to column 'destX - 1'
- pulDestBuffer[destY * ulDestWidth + destX + 1] = usTempBuffer[srcY * ulSrcWidth + srcX];
- // line double: in the y direction
- pulDestBuffer[(destY+1) * ulDestWidth + destX] = usTempBuffer[srcY * ulSrcWidth + srcX];
- // line and pixel double: copy the same pixel to column 'destx - 1'
- pulDestBuffer[(destY+1) * ulDestWidth + destX + 1] = usTempBuffer[srcY * ulSrcWidth + srcX];
- }
- srcX--;
- }
- }
- #if (CHECK_MEM_COPY_SPEED == 1)
- ////////////////////////////////////////////////////////////////////////////////
- DWORD dwEnd = GetTickCount();
- DWORD timetaken = dwEnd - dwStart;
- TCHAR outstring[100];
- wsprintf(outstring, TEXT("DUALDISPDEMO: Loop time: %dn"), timetaken);
- TEXTOUT(outstring);
- ////////////////////////////////////////////////////////////////////////////////
- #endif
- }
- else if (dwWaitObjRetVal == WAIT_OBJECT_0)
- {
- /* hEvent_StopDesktopTransfer event object signalled - therefore stop transfer */
- TEXTOUT(TEXT("DUALDISPDEMO: RotateAndDoubleToBuffer: Exiting desktop transfer.n"));
- return nDDRetVal;
- }
- else if (dwWaitObjRetVal == WAIT_FAILED)
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- else
- {
- assert(0);
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- }
- return nDDRetVal;
- }
- /* Restore optimization */
- #ifdef OSV_PPC
- #ifdef NDEBUG
- #pragma optimize("", on)
- #endif
- #endif
- /***********************************************************************************
- Function Name : AdjustRefreshRate
- Inputs : bIsDirty
- Inputs/Outputs : nConsecutiveScreenUpdates
- Outputs dwDelayInMilliseconds
- Returns : Error code
- Description : Monitors the frequency of updates to the XScale surface. Note:
- the XScale frame buffer is only updated when a change to the
- Marathon surface is detected by DE_CheckForScreenUpdate.
- If it detects that the rate of screen updates is increasing,
- AdjustRefreshRate reduces the rate of 'screen-update checks',
- thus limiting bandwidth consumption. As soon as a reduction in
- screen-updates is detected, the rate of 'screen-update checks' is
- restored to its default value, allowing the display to be more
- responsive.
- Note: The refresh rate is best controlled by the define
- DESKTOPTOXSCALEDELAY. AdjustRefreshRate is an experimental
- function - and is not presently called in dualdispdemo.
- ************************************************************************************/
- void AdjustRefreshRate(BOOL bIsDirty,
- ULONG& nConsecutiveScreenUpdates,
- DWORD& dwDelayInMilliseconds)
- {
- if (bIsDirty == FALSE)
- {
- /* Marathon frame buffer has not changed, therefore restore the rate of
- screen update checks to its default. */
- dwDelayInMilliseconds = DESKTOPTOXSCALEDELAY;
- nConsecutiveScreenUpdates = 0;
- }
- else
- {
- /* Marathon frame buffer has changed, therefore reduce the rate of screen
- update checks accordingly - in order to preserve GSB bandwidth. */
-
- switch (nConsecutiveScreenUpdates)
- {
- case 0:
- case 1:
- case 2:
- /* 0 to 2 consecutive screen updates: retain refresh rate. */
- dwDelayInMilliseconds = 250;
- TEXTOUT(TEXT("DUALDISPDEMO: UpdateXScaleFB: 250 millisecondsn"));
- break;
-
- case 3:
- case 4:
- /* 3 to 4 consecutive updates: reduce refresh rate. */
- dwDelayInMilliseconds = 500;
- TEXTOUT(TEXT("DUALDISPDEMO: UpdateXScaleFB: 500 millisecondsn"));
- break;
- default:
- /* 5 or more consecutive updates: further reduce refresh rate. */
- dwDelayInMilliseconds = 1000;
- TEXTOUT(TEXT("DUALDISPDEMO: UpdateXScaleFB: 1000 millisecondsn"));
- break;
- }
- nConsecutiveScreenUpdates++;
- }
- }
- /***********************************************************************************
- Function Name : GetSecondarySurfaceInfo
- Inputs :
- Outputs : s2700GSecondadrySurfInfo
- Returns :
- Description : Get secondary surface information from Marathon. This will
- include the frame buffer address which can be written to
- directly if desired.
- ************************************************************************************/
- LONG GetSecondarySurfaceInfo(DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo)
- {
- ULONG nDDRetVal = DUALDISPSUCCESS;
- // Get secondary surface info
- nDDRetVal |= DE_GetMarathonSurfaceInfo(s2700GSecondadrySurfInfo, DCFG_SECONDARYSURFACE, hdcMarathon);
- /* s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulPhysAddress can now be used
- to access the secondary surface directly. */
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : WriteToSecSurfFrameBuffer
- Inputs : s2700GSecondadrySurfInfo
- Outputs :
- Returns : error code
- Description : Writes directly to the secondary surface frame buffer
- ************************************************************************************/
- LONG WriteToSecSurfFrameBuffer(DISPCFG_GET_SURFACE_INFO& s2700GSecondadrySurfInfo)
- {
- ULONG nDDRetVal = DUALDISPSUCCESS;
- USHORT nColour = 0xF0F0;
- ULONG nNumLines = 0;
- ULONG nWidth, nHeight;
- nWidth = s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulWidth;
- nHeight = s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulHeight;
- /* Write directly to the frame buffer */
- USHORT* fbuffer = (USHORT*) s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulPhysAddress;
- for (ULONG line = 0; line < nHeight; line++)
- {
- for (ULONG pixel = 0; pixel < nWidth; pixel++)
- {
- fbuffer[line * nWidth + pixel] = nColour;
- }
- if (nNumLines == 10)
- {
- nColour ^= 0xFFFF; // invert colour
- nNumLines = 0;
- }
- nNumLines++;
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : WinMain
- Inputs : hInstance
- hPrevInstance
- lpCmdLine
- nCmdShow
- Outputs :
- Returns : msg.wParam
- Description : WinMain processes command line options to determine the desired
- Dual Display Mode. The specified mode is implemented
- by one or more threads. After creating the threads, WinMain
- creates a DialogBox (in the form of a single button). When
- the button is pressed, the threads are terminated, all open
- handles are closed and the default mode of operation is
- restored; the application will now exit.
- ************************************************************************************/
- int WINAPI WinMain( HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- SELECT_DUAL_DISP_CONFIG SelectDualDispConfig = eModeInvalid;
- char ArgBuffer[1024];
- char* argv[512];
- ULONG ulArgc;
- #ifdef LOGGING_TO_FILE
- /* Open output stream for logfile */
- gpStream = _wfopen(TEXT("\hard disk\dualdisplog.txt"), TEXT("w"));
- if (gpStream == NULL)
- {
- nDDRetVal |= DUALDISPERROR;
- return nDDRetVal;
- }
- #endif
- classRefreshDisplay.Init(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
- /* Initialize contents of sDisplayConfig and sMarathonSurfaceInfo to zero. */
- memset((void*) &sDisplayConfig, 0, sizeof(DISPCFG_DISPLAY_SYSTEM));
- memset((void*) &sDesktopSurfaceInfo, 0, sizeof(DISPCFG_GET_SURFACE_INFO));
- memset((void*) &s2700GSecondadrySurfInfo, 0, sizeof(DISPCFG_GET_SURFACE_INFO));
- GetCommandLineArgs(lpCmdLine, ulArgc, argv, ArgBuffer);
- /* Get the required dual display configuration. */
- nDDRetVal |= ProcessOptions(ulArgc, argv, SelectDualDispConfig);
- if ((nDDRetVal != DUALDISPSUCCESS) || (SelectDualDispConfig == eModeInvalid))
- {
- TEXTOUT(TEXT("DUALDISPDEMO: Error occured processing command linen"));
- /* An invalid mode has been requested - display command line options. */
- MessageBox(NULL,
- TEXT("Command line options: --default | --mirror | --mirrorcompatible | --gdi | --framebuffer | --extdesktop | --intsecsurf | --extsecsurf | --video | --test | --quicktest"),
- TEXT("Dual Display"), MB_OK);
- return nDDRetVal;
- }
- /* Get driver HDCs */
- nDDRetVal |= DualDisplaySetup(sDesktopSurfaceInfo);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: WinMain: DualDispSetup failed.n"));
- return nDDRetVal;
- }
- classRefreshDisplay.SetSize(sDesktopSurfaceInfo.sPhysSurfaceInfo.ulWidth,
- sDesktopSurfaceInfo.sPhysSurfaceInfo.ulHeight);
- /* Configure a Dual Display mode */
- switch (SelectDualDispConfig)
- {
- case eDefaultDisplay:
- /* Set default display mode and exit. */
- RestoreDefaultDisplayMode();
- return nDDRetVal;
- case eMirrorModeIncompatible:
- /* Display desktop on both internal and external screens. External display
- will be accelerated by marathon. Internal display will be copied from Marathon
- surface to XScale surface. */
- TEXTOUT(TEXT("DUALDISPDEMO: WinMain: Mirror Mode Selected.n"));
- nDDRetVal |= Config_MirrorModeIncompatible(sDisplayConfig, sDesktopSurfaceInfo, sXScaleSurfaceInfo, hdcXScale);
- break;
- case eVideoMode:
- /* Display the desktop on both internal and external screens. The external screen should
- display the desktop in landscape mode - even if the desktop surface has been rendered in
- portrait mode. This allows video to be played on the external screen in landscape mode. */
- nDDRetVal |= Config_VideoMode(sDisplayConfig, sDesktopSurfaceInfo, sXScaleSurfaceInfo, hdcXScale);
- break;
- case eMirrorModeCompatible:
- /* Display desktop on (compatible) internal and external screens by configuring the LCD SWITCH
- to mirror PDP to both panels. */
- TEXTOUT(TEXT("DUALDISPDEMO: WinMain: Mirror Mode (for compatible panels) Selected.n"));
- nDDRetVal |= Config_MirrorModeCompatible(sDisplayConfig);
- break;
- case eCustomGDIApplication:
-
- /* Display desktop on internal screen. Display a custom GDI application on the
- external screen. */
- TEXTOUT(TEXT("DUALDISPDEMO: WinMain: Custom GDI Mode Selected"));
- nDDRetVal |= Config_CustomGDIApplication(sDisplayConfig, sDesktopSurfaceInfo,
- s2700GSecondadrySurfInfo, sXScaleSurfaceInfo, hdcXScale);
- break;
- case eCustomFBApplication:
-
- /* Display Desktop on internal screen. Also perform a direct write to secondary
- surface frame buffer displayed on external screen.*/
- nDDRetVal |= Config_CustomFBApplication(sDisplayConfig, sDesktopSurfaceInfo,
- s2700GSecondadrySurfInfo, sXScaleSurfaceInfo, hdcXScale);
- break;
- case eInternalDispOnlySecSurf:
- /* Display random GDI rectangles for 20 seconds. Then write directly to secondary
- surface frame buffer before exiting - using internal screen. Finally, return from
- WinMain, because further user-interaction is not required. */
- nDDRetVal |= Config_InternalDispOnlySecSurf(sDisplayConfig, s2700GSecondadrySurfInfo);
- RestoreDefaultDisplayMode();
- return nDDRetVal;
- case eExternalDispOnlySecSurf:
- /* Display random GDI rectangles for 20 seconds. Then write directly to secondary
- surface frame buffer before exiting - using external screen. Finally, return from
- WinMain, because further user-interaction is not required. */
- nDDRetVal |= Config_ExternalDispOnlySecSurf(sDisplayConfig, s2700GSecondadrySurfInfo);
- RestoreDefaultDisplayMode();
- return nDDRetVal;
- case eExternalDispOnlyDesktop:
- /* Display desktop on the external screen only. */
- nDDRetVal |= Config_ExternalDispOnlyDesktop(sDisplayConfig);
- break;
- case eSlowTestMode:
- {
- /* Test all dual display configurations - allow time for each display to be
- visually inspected. */
- BOOL bQuickTest = FALSE;
- nDDRetVal |= Config_TestDualDisplay(sDisplayConfig,
- sDesktopSurfaceInfo,
- sXScaleSurfaceInfo,
- hdcXScale,
- bQuickTest);
- return nDDRetVal;
- }
- case eQuickTestMode:
- {
- /* Test all dual display configurations - do not allow time for visual inspection. */
- BOOL bQuickTest = TRUE;
- nDDRetVal |= Config_TestDualDisplay(sDisplayConfig,
- sDesktopSurfaceInfo,
- sXScaleSurfaceInfo,
- hdcXScale,
- bQuickTest);
- return nDDRetVal;
- }
- default:
- /* An invalid mode has been requested - display command line options. */
- MessageBox(NULL,
- TEXT("Command line options: --default | --mirror | --mirrorcompatible | --gdi | --framebuffer | --extdesktop | --intsecsurf | --extsecsurf | --video | --test | --quicktest"),
- TEXT("Dual Display"), MB_OK);
- return nDDRetVal;
- }
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- /* Dual display failure - restore the default settings */
- TEXTOUT(TEXT("DUALDISPDEMO: WinMain: dual display error. Attempting to restore default configuration.n"));
- nDDRetVal = DUALDISPSUCCESS;
- RestoreDefaultDisplayMode();
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- /* Failed to restore default settings */
- TEXTOUT(TEXT("DUALDISPDEMO: WinMain: dual display error: Attempt to restore default configuration has failed.n"));
- }
- return 0;
- }
- /* Create a dialog box. It will consist of just one button, which is used
- to close down the application. The default display mode will be restored before
- the application exits. */
- static TCHAR szAppName[] = TEXT ("DualDisp") ;
- HWND hwnd ;
- WNDCLASS wndclass ;
- MSG msg;
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
- wndclass.lpfnWndProc = (WNDPROC) WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = DLGWINDOWEXTRA ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = NULL;
- wndclass.hCursor = 0 ;
- wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH) ;
- wndclass.lpszMenuName = 0 ;
- wndclass.lpszClassName = szAppName ;
- RegisterClass(&wndclass);
- hwnd = CreateDialog (hInstance, szAppName, 0, NULL) ;
- ShowWindow (hwnd, nCmdShow) ;
- while (GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
- MessageBox(NULL, TEXT("Exiting dual display mode"), TEXT("Dual Display"), MB_OK);
- TEXTOUT(TEXT("DUALDISPDEMO: Exiting WinMainn"));
- if (gpStream)
- {
- fclose(gpStream);
- }
- return msg.wParam ;
- }
- /***********************************************************************************
- Function Name : WndProc
- Inputs : hwnd
- message
- wParam
- lParam
- Outputs :
- Returns :
- Description : Main window procedure - for a Dialog. Note: a Dialog has
- been registered as a WNDCLASS.
- ************************************************************************************/
- LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case IDC_EXITMODE:
- {
- RestoreDefaultDisplayMode();
- DestroyWindow(hwnd);
- return 0;
- }
- }
- }
- return 0;
- case WM_CLOSE:
- RestoreDefaultDisplayMode();
- DestroyWindow(hwnd);
- return 0;
- case WM_DESTROY:
- PostQuitMessage (0) ;
- return 0 ;
- }
- return DefWindowProc (hwnd, message, wParam, lParam);
- }
- /***********************************************************************************
- Function Name : CloseAllThreads
- Inputs :
- Outputs :
- Returns :
- Description : Shuts down the application's threads.
- ************************************************************************************/
- void CloseAllThreads()
- {
- if (hThread_DesktopTransfer)
- {
- /* Shut down 'Desktop to XScale Transfer' thread */
- StopDesktopToXScaleTransfer();
- hThread_DesktopTransfer = NULL;
- }
- if (hThread_GDIRectangles)
- {
- /* Shut down GDIRectangles thread */
- StopGDIRectangles();
- hThread_GDIRectangles = NULL;
- }
- }
- /***********************************************************************************
- Function Name : CloseAllHDCs
- Inputs :
- Outputs :
- Returns :
- Description : Close any open HDCs.
- ************************************************************************************/
- void CloseAllHDCs()
- {
- if (hdcMarathon)
- {
- ReleaseDC(NULL, hdcMarathon);
- hdcMarathon = NULL;
- }
- if (hdcXScale)
- {
- DeleteDC(hdcXScale);
- hdcXScale = NULL;
- }
- if (hdcMem)
- {
- DeleteDC(hdcMem);
- hdcMem = NULL;
- }
- }
- /***********************************************************************************
- Function Name : RestoreDefaultDisplayMode
- Inputs :
- Outputs :
- Returns :
- Description : Shuts down any the application's threads and closes HDCs.
- ************************************************************************************/
- LONG RestoreDefaultDisplayMode()
- {
- BOOL bRetVal;
- LONG nDDRetVal = DUALDISPSUCCESS;
- TEXTOUT(TEXT("DUALDISPDEMO: RestoreDefaultDisplayMode: Restoring dual display default configuration.n"));
- /* Close down GDIRectangles and DesktopTransfer threads. */
- CloseAllThreads();
- /* Blank the desktop surface forcing it to be refreshed. */
- classRefreshDisplay.MaskDesktop();
- nDDRetVal |= Config_DefaultDisplay(sDisplayConfig);
- /* Free virtual memory to which desktop surface has been mapped. */
- if (sDesktopSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: RestoreDefaultDisplayMode: Deallocating virtual memory for Desktop surface.n"));
- bRetVal = VirtualFree((LPVOID) sDesktopSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress, 0, MEM_RELEASE);
- assert(bRetVal != 0);
- sDesktopSurfaceInfo.sPhysSurfaceInfo.ulPhysAddress = 0;
- }
- /* Free virtual memory to which secondary surface has been mapped */
- if (s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulPhysAddress)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: RestoreDefaultDisplayMode: Deallocating virtual memory for Secondary surface.n"));
- bRetVal = VirtualFree((LPVOID) s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulPhysAddress, 0, MEM_RELEASE);
- assert(bRetVal != 0);
- s2700GSecondadrySurfInfo.sPhysSurfaceInfo.ulPhysAddress = 0;
- }
- /* Free virtual memory to which XScale Frame Buffer has been mapped. */
- if (sXScaleSurfaceInfo.ulPhysAddress)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: RestoreDefaultDisplayMode: Deallocating virtual memory for XScale Frame Buffer.n"));
- bRetVal = VirtualFree((LPVOID) sXScaleSurfaceInfo.ulPageAddress, 0, MEM_RELEASE);
- assert(bRetVal != 0);
- sXScaleSurfaceInfo.ulPageAddress = 0;
- sXScaleSurfaceInfo.ulPhysAddress = 0;
- }
- /* Display the desktop */
- classRefreshDisplay.Close();
- /* If the secondary surface still exists (e.g. in case Config_FBApplication), then
- delete it. Should be called before CloseAllHDCs. */
- DestroySecondarySurface();
- /* Free the dual display interface Should be called before CloseAllHDCs. */
- DE_ReleaseDualDisplay(hdcMarathon);
-
- /* Delete any remaining HDCs */
- CloseAllHDCs();
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: RestoreDefaultDisplayMode: Error.n"));
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : RefreshDisplay::Init
- Inputs : hInstance
- hPrevInstance
- szCmdLine
- iCmdShow
- Outputs :
- Returns : void
- Description : Initializes the class variables to the WinMain parameters.
- This function should only be called by WinMain.
- ************************************************************************************/
- void RefreshDisplay::Init(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR szCmdLine,
- int iCmdShow)
- {
- /* Get a copy of WinMain parameters */
- m_hInstance = hInstance;
- m_hPrevInstance = hPrevInstance;
- m_szCmdLine = szCmdLine;
- m_iCmdShow = iCmdShow;
- m_hwnd = NULL;
- }
- /***********************************************************************************
- Function Name : RefreshDisplay::Refresh
- Inputs :
- Outputs :
- Returns :
- Description : Hides the desktop by displaying a blank window. This allows a
- smooth transition to mirror mode.
- ************************************************************************************/
- void RefreshDisplay::MaskDesktop()
- {
- static TCHAR szAppName[] = TEXT ("RedrawDesktop") ;
- RECT rclRect;
- if (m_hwnd == NULL)
- {
- WNDCLASS wndclass ;
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = WndProcRefreshDisplay ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = m_hInstance ;
- wndclass.hIcon = NULL;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH) ;
- wndclass.lpszMenuName = NULL ;
- wndclass.lpszClassName = szAppName ;
- RegisterClass (&wndclass);
- m_hwnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_NOANIMATION,
- szAppName, // window class name
- NULL, // window caption
- WS_VISIBLE, // window style
- 0, // initial x position
- 0, // initial y position
- m_nScreenWidth, // initial x size
- m_nScreenHeight, // initial y size
- NULL, // parent window handle
- NULL, // window menu handle
- m_hInstance, // program instance handle
- NULL) ; // creation parameters
- }
- if (m_hwnd)
- {
- rclRect.left = 0;
- rclRect.top = 0;
- rclRect.right = m_nScreenWidth;
- rclRect.bottom = m_nScreenHeight;
- InvalidateRect(m_hwnd, &rclRect, TRUE);
- #ifdef OSV_PPC
- /* This is a fix for 'Upper Taskbar' corruption bug on PocketPC */
- SetForegroundWindow(m_hwnd);
- SHFullScreen(m_hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
- MoveWindow(m_hwnd,
- rclRect.left,
- rclRect.top,
- rclRect.right,
- rclRect.bottom,
- TRUE);
- #endif
- ShowWindow(m_hwnd, m_iCmdShow);
- UpdateWindow (m_hwnd);
- }
- }
- /***********************************************************************************
- Function Name : RefreshDisplay::RevealDesktop
- Inputs :
- Outputs :
- Returns :
- Description : Displays the desktop by hiding the 'MaskDesktop' window. This
- causes the desktop to be refreshed.
- ************************************************************************************/
- void RefreshDisplay::RevealDesktop()
- {
- if (m_hwnd)
- {
- ShowWindow (m_hwnd, SW_HIDE);
- UpdateWindow (m_hwnd);
- }
- }
- /***********************************************************************************
- Function Name : RefreshDisplay::Close
- Inputs :
- Outputs :
- Returns :
- Description : Destroys the 'MaskDesktop' window.
- ************************************************************************************/
- void RefreshDisplay::Close()
- {
- if (m_hwnd)
- {
- DestroyWindow (m_hwnd);
- m_hwnd = NULL;
- }
- }
- /***********************************************************************************
- Function Name : WndProcRefreshDisplay
- Inputs :
- Outputs :
- Returns :
- Description : Window Procedure for window created by
- RefreshDisplay::MaskDesktop.
- ************************************************************************************/
- LRESULT CALLBACK WndProcRefreshDisplay (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- HDC hdc ;
- PAINTSTRUCT ps ;
-
- switch (message)
- {
- case WM_PAINT:
- hdc = BeginPaint (hwnd, &ps) ;
- EndPaint (hwnd, &ps) ;
- return 0 ;
-
- case WM_DESTROY:
- PostQuitMessage (0) ;
- return 0 ;
- }
- return DefWindowProc (hwnd, message, wParam, lParam) ;
- }
- /***********************************************************************************
- Function Name : DualDisplaySetup
- Inputs :
- Input/Output : sDesktopSurfaceInfo
- Returns :
- Description : Dual display initialization.
- ************************************************************************************/
- LONG DualDisplaySetup(DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo)
- {
- LONG nDDRetVal = DUALDISPSUCCESS;
- hdcMarathon = GetDC(NULL);
- /* Load XScale as a secondary display driver */
- hdcXScale = CreateDC(TEXT("ddi.dll"), NULL, NULL, NULL);
- /* get default display settings */
- nDDRetVal = DE_GetMarathonSurfaceInfo(sDesktopSurfaceInfo, DCFG_DESKTOP, hdcMarathon);
- if (nDDRetVal != DUALDISPSUCCESS)
- {
- TEXTOUT(TEXT("DUALDISPDEMO: DualDisplaySetup: Error could not get default settingsn"));
- return nDDRetVal;
- }
- /* Preserve a copy of the initial desktop rotation angle */
- lInitialDesktopRotation = sDesktopSurfaceInfo.sPhysSurfaceInfo.lPhysicalRotation;
- if(!DE_AcquireDualDisplay(hdcMarathon))
- {
- nDDRetVal |= DUALDISPERROR;
- TEXTOUT(TEXT("DUALDISPDEMO: DualDisplaySetup: Failed to Acquire the DualDisplayInterfacen"));
-
- classRefreshDisplay.Close();
- /* Delete any remaining HDCs */
- CloseAllHDCs();
- return nDDRetVal;
- }
- return nDDRetVal;
- }
- /***********************************************************************************
- Function Name : DualDisplayTestSetup
- Input/Output : sDesktopSurfaceInfo
- Outputs : bTestSetupSuccess
- Returns :
- Description : Dual display test initialization.
- ************************************************************************************/
- void DualDisplayTestSetup(DISPCFG_GET_SURFACE_INFO& sDesktopSurfaceInfo, BOOL& bTestSetupSuccess)
- {
- /* Restore the default display mode */
- RestoreDefaultDisplayMode();
- LONG nRetVal = DualDisplaySetup(sDesktopSurfaceInfo);
- if (nRetVal != DUALDISPSUCCESS)
- {
- bTestSetupSuccess = FALSE;
- }
- /* If (nRetVal == DUALDISPSUCCESS) no action is required. bTestSetupSuccess should NOT
- be overwritten with TRUE.*/
- }