os/graphics/graphicsdeviceinterface/bitgdi/tbit/tmultiplescreens.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <hal.h>
    17 #include <graphics/gdi/gdiconsts.h>
    18 #include "tmultiplescreens.h"
    19 
    20 CTMultipleScreens::CTMultipleScreens(CTestStep* aStep):
    21 	CTGraphicsBase(aStep),
    22 	iScrDev(NULL),
    23 	iGc(NULL)
    24 	{
    25 	}
    26 
    27 CTMultipleScreens::~CTMultipleScreens()
    28 	{
    29 	DestroyFont();
    30 	DeleteGraphicsContext();
    31 	DeleteScreenDevice();
    32 	}
    33 
    34 void CTMultipleScreens::ConstructL()
    35 	{
    36 	}
    37 
    38 void CTMultipleScreens::RunTestCaseL(TInt aCurTestCase)
    39 	{
    40 	((CTMultipleScreensStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    41 	_LIT(KTest1,"SubTest %d: Create multiple screens");
    42 	switch(aCurTestCase)
    43 		{
    44 	case 1:
    45 		((CTMultipleScreensStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0072"));
    46 		INFO_PRINTF2(KTest1,aCurTestCase);
    47 		CreateScreenDeviceL();
    48 		break;
    49 	case 2:
    50 		((CTMultipleScreensStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    51 		((CTMultipleScreensStep*)iStep)->CloseTMSGraphicsStep();
    52 		TestComplete();
    53 		break;
    54 		}
    55 	((CTMultipleScreensStep*)iStep)->RecordTestResultL();
    56 	}
    57 
    58 
    59 /**
    60   @SYMTestCaseID GRAPHICS-BITGDI-0072
    61  
    62   @SYMDEF             
    63 
    64   @SYMTestCaseDesc Multiple screen test
    65    
    66   @SYMTestPriority High
    67 
    68   @SYMTestStatus Implemented
    69 
    70   @SYMTestActions creates some screens in different modes then writes some rotated text to them and test.
    71  
    72   @SYMTestExpectedResults Test should perform graphics operations succesfully. 
    73 */	
    74 void CTMultipleScreens::CreateScreenDeviceL()
    75 	{
    76 	TDisplayMode testMode[] =  {EColor4K, EColor64K, EColor16M, EColor16MU, EColor256, EColor16MA, EColor16MAP};//tested display modes
    77 	for(TInt ii=0;ii<TInt(sizeof(testMode)/sizeof(testMode[0]));ii++)
    78 		{
    79 		TInt screenCnt = 0;
    80 		TEST(HAL::Get(0, HALData::EDisplayNumberOfScreens, screenCnt) == KErrNone);
    81 		for(TInt screenNo=0;screenNo<screenCnt;++screenNo)
    82 			{
    83 			TInt err = CreateScrDevAndContext(screenNo, testMode[ii]);
    84 			if(err == KErrNone)
    85 				{
    86 				DoRotateMoveTextL();
    87 				}
    88 			DeleteGraphicsContext();
    89 			DeleteScreenDevice();
    90 			}
    91 		}
    92 	}
    93 
    94 void CTMultipleScreens::DoRotateMoveTextL()
    95 	{
    96 	__ASSERT_ALWAYS(iScrDev, User::Invariant());
    97 	__ASSERT_ALWAYS(iGc, User::Invariant());
    98 	
    99 	CreateFontL();
   100 
   101 	const CFbsBitGc::TGraphicsOrientation KOrientation[] = 
   102 		{
   103 		CFbsBitGc::EGraphicsOrientationNormal,
   104 		CFbsBitGc::EGraphicsOrientationRotated90,
   105 		CFbsBitGc::EGraphicsOrientationRotated180,
   106 		CFbsBitGc::EGraphicsOrientationRotated270
   107 		};
   108 
   109 	for(TInt ii=0;ii<TInt(sizeof(KOrientation)/sizeof(KOrientation[0]));++ii)
   110 		{
   111 		if(!iGc->SetOrientation(KOrientation[ii]))
   112 			{
   113 			continue;
   114 			}
   115 		_LIT(KRotation,"===EOrientation%S===");
   116 		INFO_PRINTF2(KRotation,&RotationName(KOrientation[ii]));
   117 
   118 		TSize size = iScrDev->SizeInPixels();
   119 		RDebug::Print(_L("Size: %d, %d\r\n"), size.iWidth, size.iHeight);
   120 		for(TInt x=-40;x<(size.iWidth+30);x+=27)
   121 			{
   122 			for(TInt y=-40;y<(size.iHeight+30);y+=23)
   123 				{
   124 				iGc->Clear();
   125 				iGc->SetPenStyle(CGraphicsContext::ESolidPen);
   126 				iGc->SetPenColor(TRgb(0x00, 0x00, 0x00));
   127 				iGc->SetPenSize(TSize(1, 1));
   128 				
   129 				iGc->DrawText(_L("Test text"), TPoint(x, y));
   130 				
   131 				iScrDev->Update();
   132 				}
   133 			}
   134 		}
   135 	iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);
   136 	DestroyFont();
   137 	}
   138 
   139 
   140 TInt CTMultipleScreens::CreateScrDevAndContext(TInt aScreenNo, TDisplayMode aDisplayMode)
   141 	{
   142 	DeleteGraphicsContext();
   143 	DeleteScreenDevice();
   144 	TRAPD(err, iScrDev = CFbsScreenDevice::NewL(aScreenNo, aDisplayMode));
   145 	if ( !iScrDev )
   146 		{
   147 		TESTE( err == KErrNotSupported, err );
   148 		return err;
   149 		}
   150 	TEST(err == KErrNone);
   151 	TEST(iScrDev->ScreenNo() == aScreenNo);
   152 	err = iScrDev->CreateContext((CGraphicsContext*&)iGc);
   153 	if ( !iGc )
   154 		{
   155 		return err;
   156 		}
   157 	TEST(err == KErrNone);
   158 	iGc->SetUserDisplayMode(aDisplayMode);
   159 	iScrDev->ChangeScreenDevice(NULL);
   160 	iScrDev->SetAutoUpdate(EFalse);
   161 	return err;
   162 	}
   163 
   164 TInt CTMultipleScreens::CreateScrDevAndContext(TDisplayMode aDisplayMode)
   165 	{
   166 	return CreateScrDevAndContext(KDefaultScreenNo,aDisplayMode);
   167 	}
   168 
   169 void CTMultipleScreens::DeleteScreenDevice()
   170 	{
   171 	delete iScrDev;
   172 	iScrDev = NULL;
   173 	}
   174 
   175 void CTMultipleScreens::DeleteGraphicsContext()
   176 	{
   177 	delete iGc;
   178 	iGc = NULL;
   179 	}
   180 
   181 void CTMultipleScreens::CreateFontL()
   182 	{
   183 	CFbsFont* font = NULL;
   184 	TFontSpec fs(_L("Swiss"), 12);
   185 	User::LeaveIfError(iScrDev->GetNearestFontToDesignHeightInPixels(font, fs));
   186 	iGc->UseFont(font);
   187 	}
   188 
   189 void CTMultipleScreens::DestroyFont()
   190 	{
   191 	if(iGc)
   192 		{
   193 		iGc->DiscardFont();
   194 		}
   195 	}
   196 
   197 
   198 //
   199 
   200 
   201 //--------------
   202 __CONSTRUCT_STEP__(MultipleScreens)
   203 
   204 void CTMultipleScreensStep::TestSetupL()
   205 	{
   206 	}
   207 	
   208 void CTMultipleScreensStep::TestClose()
   209 	{
   210 	}