graphics/bitgdi/src/T_DataPolygonFiller.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 //
       
     2 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 // All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the License "Symbian Foundation License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 //
       
     9 // Initial Contributors:
       
    10 // Nokia Corporation - initial contribution.
       
    11 //
       
    12 // Contributors:
       
    13 //
       
    14 // Description:
       
    15 //
       
    16 
       
    17 #include "T_DataPolygonFiller.h"
       
    18 #include "T_GraphicsUtil.h"
       
    19 
       
    20 _LIT(KDataClassname,								"CPolygonFiller");
       
    21 
       
    22 ///	Fields
       
    23 _LIT(KFldScanLine,									"scanline");
       
    24 _LIT(KFldPointList,									"pointlist");
       
    25 _LIT(KFldFillRule,									"fillrule");
       
    26 _LIT(KFldUsage,										"usage");
       
    27 _LIT(KFldnumPoints,									"numpoints");
       
    28 _LIT(KFldExpectedScanLine,							"expectedscanline");
       
    29 _LIT(KFldExpectedStart,								"expectedstart");
       
    30 _LIT(KFldExpectedEnd,								"expectedend");
       
    31 _LIT(KFldExpectedExists,							"expectedexists");
       
    32 ///	Commands
       
    33 _LIT(KCmdnewL,										"new");
       
    34 _LIT(KCmdConstructL,								"Construct");
       
    35 _LIT(KCmdDestructorGeneral,							"~");
       
    36 _LIT(KCmdDestructor,								"~CPolygonFiller");
       
    37 _LIT(KCmdReset,										"Reset");
       
    38 _LIT(KCmdGetNextPixelRun,							"GetNextPixelRun");
       
    39 _LIT(KCmdGetNextPixelRunOnSpecifiedScanLine,		"GetNextPixelRunOnSpecifiedScanLine");
       
    40 
       
    41 //Log
       
    42 _LIT(KLogErrNum,									"Error=%d");
       
    43 _LIT(KLogInfoCmdnewL, 						    	"execute new CPolygonFiller()");
       
    44 _LIT(KLogMissingParameter, 							"Missing parameter '%S'");
       
    45 _LIT(KLogInfoCmdDestructor1, 						"execute ~CPolygonFiller()");
       
    46 _LIT(KLogInfoCmdConstruct1,							"execute Construct(TPoint*, TInt, TFillRule,TUsage)");
       
    47 _LIT(KLogInfoCmdConstruct2,							"execute Construct(CArrayFix<TPoint>*, TFillRule,TUsage)");
       
    48 _LIT(KLogInfoCmdReset,								"execute Reset()");
       
    49 _LIT(KLogInfoCmdGetNextPixelRun,					"execute GetNextPixelRun()");
       
    50 _LIT(KLogInfoCmdGetNextPixelRunOnSpecifiedScanLine,	"execute GetNextPixelRunOnSpecifiedScanLine()");
       
    51 _LIT(KLogInfoNotCheckThePosition,   			    "Won't check the position on the scan line in the test case");
       
    52 CT_DataPolygonFiller* CT_DataPolygonFiller::NewL()
       
    53 	{
       
    54 	CT_DataPolygonFiller*	ret = new (ELeave) CT_DataPolygonFiller();
       
    55 	CleanupStack::PushL(ret);
       
    56 	ret->ConstructL();
       
    57 	CleanupStack::Pop(ret);
       
    58 	return ret;
       
    59 	}
       
    60 
       
    61 CT_DataPolygonFiller::CT_DataPolygonFiller()
       
    62 :	iPolygonFiller(NULL)
       
    63 	{
       
    64 	}
       
    65 
       
    66 void CT_DataPolygonFiller::ConstructL()
       
    67 	{
       
    68 	iPointsArray=NULL;
       
    69 	iPoints=NULL;
       
    70 	}
       
    71 
       
    72 CT_DataPolygonFiller::~CT_DataPolygonFiller()
       
    73 	{
       
    74 	DestroyData();
       
    75 	
       
    76 	delete iPointsArray;
       
    77 	iPointsArray=NULL;
       
    78 	
       
    79 	delete[] iPoints;
       
    80 	iPoints=NULL;
       
    81 	}
       
    82 
       
    83 TAny* CT_DataPolygonFiller::GetObject()
       
    84 	{
       
    85 	return iPolygonFiller;
       
    86 	}
       
    87 
       
    88 void CT_DataPolygonFiller::SetObjectL(TAny* aAny)
       
    89 	{
       
    90 	DestroyData();
       
    91 	iPolygonFiller = static_cast<CPolygonFiller*> (aAny);
       
    92 	}
       
    93 
       
    94 void CT_DataPolygonFiller::DisownObjectL()
       
    95 	{
       
    96 	iPolygonFiller = NULL;
       
    97 	}
       
    98 
       
    99 void CT_DataPolygonFiller::DestroyData()
       
   100 	{
       
   101 	DoCmdDestructor();
       
   102 	}
       
   103 
       
   104 
       
   105 /**
       
   106 * Process a command read from the ini file
       
   107 *
       
   108 * @param aCommand			the command to process
       
   109 * @param aSection			the entry in the ini file requiring the command to be processed
       
   110 * @return ETrue if the command is processed
       
   111 */
       
   112 TBool CT_DataPolygonFiller::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt)
       
   113 	{
       
   114 	TBool	ret = ETrue;
       
   115 
       
   116 	if ( aCommand==KCmdDestructorGeneral || aCommand==KCmdDestructor )
       
   117 		{
       
   118 		DoCmdDestructor();
       
   119 		}
       
   120 	else if ( aCommand==KCmdnewL || aCommand==KDataClassname )
       
   121 		{
       
   122 		DoCmdnewL();
       
   123 		}
       
   124 	else if(aCommand==KCmdConstructL)
       
   125 		{
       
   126 		DoCmdConstructL(aSection);
       
   127 		}
       
   128 	else if ( aCommand==KCmdReset )
       
   129 		{
       
   130 		DoCmdReset();
       
   131 		}
       
   132 	else if ( aCommand==KCmdGetNextPixelRun )
       
   133 		{
       
   134 		DoCmdGetNextPixelRun(aSection);
       
   135 		}
       
   136 	else if ( aCommand==KCmdGetNextPixelRunOnSpecifiedScanLine )
       
   137 		{
       
   138 		DoCmdGetNextPixelRunOnSpecifiedScanLine(aSection);
       
   139 		}
       
   140 	else
       
   141 		{
       
   142 		ret=EFalse;
       
   143 		}
       
   144 	return ret;
       
   145 	}
       
   146 
       
   147 void CT_DataPolygonFiller::DoCmdnewL()
       
   148 	{ 
       
   149 	DestroyData();
       
   150 	TInt err = KErrNone;
       
   151 	INFO_PRINTF1(KLogInfoCmdnewL);
       
   152 	TRAP(err, iPolygonFiller = new (ELeave) CPolygonFiller());
       
   153 	if ( err!=KErrNone )
       
   154 		{
       
   155 		ERR_PRINTF2(KLogErrNum, err);
       
   156 		SetError(err);
       
   157 		}
       
   158 	}
       
   159 
       
   160 void CT_DataPolygonFiller::DoCmdConstructL(const TDesC& aSection)
       
   161 	{
       
   162 	TBool	dataOk=ETrue;
       
   163     TInt datNumPoints=0;
       
   164     TInt err=0;
       
   165     CGraphicsContext::TFillRule	datFillRule=CGraphicsContext::EAlternate;
       
   166     CPolygonFiller::TUsage datUsage=CPolygonFiller::EGetAllPixelRunsSequentially;
       
   167 
       
   168 	CT_GraphicsUtil::ReadFillRule(*this, aSection, KFldFillRule, datFillRule);
       
   169     CT_GraphicsUtil::ReadTUsage(*this,aSection,KFldUsage,datUsage);
       
   170 	
       
   171 //Use TPoint parameter to construct if the number of points in the list is assigned.
       
   172 	if (GetIntFromConfig(aSection, KFldnumPoints, datNumPoints))
       
   173 		{
       
   174 		iPoints=new (ELeave) TPoint[datNumPoints];
       
   175 		if ( !GetPointListFromConfig(aSection, KFldPointList, datNumPoints, iPoints))
       
   176 			{
       
   177 			ERR_PRINTF2(KLogMissingParameter, &KFldPointList());
       
   178 			SetBlockResult(EFail);
       
   179 			}
       
   180 		else
       
   181 			{
       
   182 			// Execute command and log parameters
       
   183 			INFO_PRINTF1(KLogInfoCmdConstruct1);
       
   184 			iPolygonFiller->Construct(iPoints, datNumPoints, datFillRule, datUsage);
       
   185 			}
       
   186 		}
       
   187 	else
       
   188 		{
       
   189 		iPointsArray=new (ELeave) CArrayFixFlat<TPoint>(1);
       
   190 		TBool	hasPointList=GetPointListFromConfigL(aSection, KFldPointList, *iPointsArray);
       
   191 				
       
   192 		if ( !hasPointList )
       
   193 			{
       
   194 			ERR_PRINTF2(KLogMissingParameter, &KFldPointList());
       
   195 			SetBlockResult(EFail);
       
   196 			}
       
   197 		else
       
   198 			{
       
   199 			// Execute command and log parameters
       
   200 			INFO_PRINTF1(KLogInfoCmdConstruct2);
       
   201 			iPolygonFiller->Construct(iPointsArray,datFillRule,datUsage);
       
   202 			}
       
   203 		}
       
   204 	}
       
   205 
       
   206 void CT_DataPolygonFiller::DoCmdDestructor()
       
   207 	{
       
   208 	INFO_PRINTF1(KLogInfoCmdDestructor1);
       
   209 	delete iPolygonFiller;
       
   210 	iPolygonFiller = NULL;
       
   211 	}
       
   212 
       
   213 void CT_DataPolygonFiller::DoCmdReset()
       
   214 	{
       
   215 	INFO_PRINTF1(KLogInfoCmdReset);
       
   216 	iPolygonFiller->Reset();
       
   217 	}
       
   218 
       
   219 void CT_DataPolygonFiller::DoCmdGetNextPixelRun(const TDesC& aSection)
       
   220 	{
       
   221 	TBool relExists,expectedExists;
       
   222 	TInt relScanLine,relStart,relEnd,expectedScanLine,expectedStart,expectedEnd;
       
   223 	INFO_PRINTF1(KLogInfoCmdGetNextPixelRun);
       
   224 	iPolygonFiller->GetNextPixelRun(relExists,relScanLine,relStart,relEnd);
       
   225 	//Verify the scanline is expected
       
   226 	if(!GetBoolFromConfig(aSection,KFldExpectedExists,expectedExists))
       
   227 		{
       
   228 		ERR_PRINTF2(KLogMissingParameter, &KFldExpectedExists);
       
   229 		SetBlockResult(EFail);
       
   230 		}
       
   231 	else if(relExists!=expectedExists)
       
   232     	{
       
   233     	ERR_PRINTF3(_L("The returned Exists value is not as expected, expected: %d, result: %d"), expectedExists , relExists);        
       
   234     	SetBlockResult(EFail);
       
   235     	}
       
   236 	if(!GetIntFromConfig(aSection,KFldExpectedScanLine,expectedScanLine))
       
   237 		{
       
   238 		ERR_PRINTF2(KLogMissingParameter, &KFldExpectedScanLine);
       
   239 		SetBlockResult(EFail);
       
   240 		}
       
   241 	else if(relScanLine!=expectedScanLine)
       
   242     	{
       
   243     	ERR_PRINTF3(_L("The returned Scanline value is not as expected, expected: %d, result: %d"), expectedScanLine , relScanLine);        
       
   244     	SetBlockResult(EFail);
       
   245     	}
       
   246     //Verify the start position on the scan line  
       
   247     if(!GetIntFromConfig(aSection,KFldExpectedStart,expectedStart))
       
   248     	{
       
   249     	INFO_PRINTF1(KLogInfoNotCheckThePosition);
       
   250 
       
   251     	}
       
   252     else if(relStart!=expectedStart)
       
   253     	{
       
   254     	ERR_PRINTF3(_L("The returned Start Position value is not as expected, expected: %d, result: %d"), expectedStart , relStart);        
       
   255     	SetBlockResult(EFail);
       
   256     	}
       
   257     //Verify the end position on the scan line
       
   258     if(!GetIntFromConfig(aSection,KFldExpectedEnd,expectedEnd))
       
   259     	{
       
   260     	INFO_PRINTF1(KLogInfoNotCheckThePosition);
       
   261 
       
   262 		}
       
   263     else if(relEnd!=expectedEnd)
       
   264     	{
       
   265     	ERR_PRINTF3(_L("The returned End Position value is not as expected, expected: %d, result: %d"), expectedEnd , relEnd);        
       
   266     	SetBlockResult(EFail);
       
   267     	} 
       
   268 	}
       
   269 
       
   270 void CT_DataPolygonFiller::DoCmdGetNextPixelRunOnSpecifiedScanLine(const TDesC& aSection)
       
   271 	{
       
   272 	TInt datScanLine=0;
       
   273 	TBool relExists,expectedExists;
       
   274 	TInt relStart,relEnd,expectedStart,expectedEnd;
       
   275 	
       
   276 	if (!GetIntFromConfig(aSection, KFldScanLine, datScanLine))
       
   277 		{
       
   278 		ERR_PRINTF2(KLogMissingParameter, &KFldScanLine);
       
   279 		SetBlockResult(EFail);
       
   280 		}
       
   281 	INFO_PRINTF1(KLogInfoCmdGetNextPixelRunOnSpecifiedScanLine);
       
   282     iPolygonFiller->GetNextPixelRunOnSpecifiedScanLine(relExists,datScanLine,relStart,relEnd);
       
   283 	if(!GetBoolFromConfig(aSection,KFldExpectedExists,expectedExists))
       
   284 		{
       
   285 		ERR_PRINTF2(KLogMissingParameter, &KFldExpectedExists);
       
   286 		SetBlockResult(EFail);
       
   287 		}
       
   288 	else if(relExists!=expectedExists)
       
   289     	{
       
   290     	ERR_PRINTF3(_L("The returned Exists value is not as expected, expected: %d, result: %d"), expectedExists , relExists);        
       
   291     	SetBlockResult(EFail);
       
   292     	}
       
   293     //Verify the start position on the scan line  
       
   294     if(!GetIntFromConfig(aSection,KFldExpectedStart,expectedStart))
       
   295     	{
       
   296     	INFO_PRINTF1(KLogInfoNotCheckThePosition);
       
   297 
       
   298     	}
       
   299     else if(relStart!=expectedStart)
       
   300 		{
       
   301     	ERR_PRINTF3(_L("The returned Start Position value is not as expected, expected: %d, result: %d"), expectedStart , relStart);        
       
   302     	SetBlockResult(EFail);
       
   303 		}
       
   304     //Verify the end position on the scan line
       
   305     if(!GetIntFromConfig(aSection,KFldExpectedEnd,expectedEnd))
       
   306     	{
       
   307     	INFO_PRINTF1(KLogInfoNotCheckThePosition);
       
   308 
       
   309     	}
       
   310     else if(relEnd!=expectedEnd)
       
   311     	{
       
   312     	ERR_PRINTF3(_L("The returned End Position value is not as expected, expected: %d, result: %d"), expectedEnd , relEnd);        
       
   313     	SetBlockResult(EFail);
       
   314     	} 
       
   315 	}
       
   316