os/graphics/windowing/windowserver/test/t_integ/src/t_testsurfacerasterizer.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 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 /**
    17  @file
    18  @test
    19  @internalComponent
    20 */
    21 
    22 #include <e32debug.h>
    23 #include <hal.h>
    24 #include <limits.h>	//UINT_MAX
    25 
    26 #include "t_testsurfacerasterizer.h"
    27 
    28 EXPORT_C CTestSurfaceRasterizer* CTestSurfaceRasterizer::NewL(const TSurfaceId& aSurfaceId, TInt aSurfaceScreenNumber, RSurfaceManager* aSurfaceManager)
    29 	{
    30 	RDebug::Print(_L("Creating CTestSurfaceRasterizer class\n"));
    31     CTestSurfaceRasterizer* self = new (ELeave) CTestSurfaceRasterizer();
    32     CleanupStack::PushL(self);
    33     TInt ret = self->ConstructL(aSurfaceId, aSurfaceScreenNumber, aSurfaceManager);
    34     CleanupStack::Pop(); // self;
    35 
    36  	if(ret)
    37  		{
    38 	 	return self;
    39 		}
    40 	else
    41 		{
    42 		return 0;
    43 		}
    44 	}
    45 
    46 TBool CTestSurfaceRasterizer::ConstructL(const TSurfaceId& aSurfaceId, TInt aSurfaceScreenNumber, RSurfaceManager* aSurfaceManager)
    47 	{
    48 	RDebug::Print(_L("Constructing CTestSurfaceRasterizer\n"));
    49 
    50 	iSurfaceId = aSurfaceId;
    51 
    52 	iSurfaceScreenNumber  = aSurfaceScreenNumber;
    53 
    54 	iSurfaceManager = aSurfaceManager;
    55 
    56 	TInt err = iSurfaceManager->MapSurface(iSurfaceId, iChunk);
    57 
    58 	if(err)
    59 		{
    60 		RDebug::Print(_L("Error mapping to surface\n"));
    61 	 	User::Exit(0);
    62 		}
    63 
    64 	iInfoBuf.FillZ();
    65 
    66 	iSurfaceManager->SurfaceInfo(iSurfaceId, iInfoBuf);
    67 
    68 	return ETrue;
    69 	}
    70 
    71 EXPORT_C CTestSurfaceRasterizer::CTestSurfaceRasterizer()
    72 	{
    73 	}
    74 
    75 CTestSurfaceRasterizer::~CTestSurfaceRasterizer()
    76 	{
    77 	iChunk.Close();
    78 	}
    79 
    80 EXPORT_C void CTestSurfaceRasterizer::DrawRect(TUint32* aBuffer, SurfaceDetails& aSurfDetails)
    81 	{
    82 	//Send the fullscreen bitmap to the test rasterizer
    83 
    84 	RSurfaceManager::TSurfaceInfoV01& info = iInfoBuf();
    85 
    86 	aSurfDetails.aSurfaceId = iSurfaceId;
    87 	aSurfDetails.aSurfaceSize = info.iSize;
    88 	aSurfDetails.aBufferNumber = iSurfaceCurrentBuffer;
    89 
    90 
    91 	TInt offsetToCurrentBuffer;
    92 	TInt err = iSurfaceManager->GetBufferOffset(iSurfaceId, iSurfaceCurrentBuffer, offsetToCurrentBuffer);
    93 	if(err != KErrNone)
    94 		{
    95 		RDebug::Print(_L("Could not open buffer number\n"));
    96 		return;
    97 		}
    98 	TUint32* surfaceBufferPtr = reinterpret_cast<TUint32*>(iChunk.Base() + offsetToCurrentBuffer);
    99 
   100 	TInt noOfBytes =  (info.iStride * info.iSize.iHeight);
   101 	Mem::Move(surfaceBufferPtr, aBuffer, noOfBytes);
   102 
   103 	iSurfaceCurrentBuffer++;
   104 	if(iSurfaceCurrentBuffer == info.iBuffers)
   105 		{
   106 		iSurfaceCurrentBuffer = 0;
   107 		}
   108 	}
   109 
   110  EXPORT_C void CTestSurfaceRasterizer::PerfTestL(TInt aFrameNumber)
   111  	{
   112  	//Send the fullscreen bitmap to the test rasterizer
   113  	RChunk aChunk;
   114  	RSurfaceManager aManager;
   115  	User::LeaveIfError(aManager.Open());
   116 
   117  	TInt err = aManager.OpenSurface(iSurfaceId);
   118   	if(err!=KErrNone)
   119  		{
   120  		RDebug::Print(_L("Error opening a surface\n"));
   121  		User::Exit(0);
   122  		}
   123 
   124  	err = aManager.MapSurface(iSurfaceId, aChunk);
   125  	if(err!=KErrNone)
   126  		{
   127  		RDebug::Print(_L("Error mapping to surface\n"));
   128  		User::Exit(0);
   129  		}
   130 
   131  	RSurfaceManager::TInfoBuf InfoBuf;
   132  	RSurfaceManager::TSurfaceInfoV01& info = InfoBuf();
   133  	InfoBuf.FillZ();
   134 
   135  	aManager.SurfaceInfo(iSurfaceId, InfoBuf);
   136 
   137  	TInt noOfPixels =  (info.iSize.iWidth * info.iSize.iHeight);
   138 
   139  	TInt offsetToCurrentBuffer;
   140 	err = iSurfaceManager->GetBufferOffset(iSurfaceId, iSurfaceCurrentBuffer,offsetToCurrentBuffer);
   141 	if(err != KErrNone)
   142 		{
   143 		RDebug::Print(_L("Could not open buffer number\n"));
   144 		User::Exit(0);
   145 		}
   146 	TUint32* surfaceBufferPtr = reinterpret_cast<TUint32*>(aChunk.Base() + offsetToCurrentBuffer);
   147 
   148 	if(aFrameNumber < info.iBuffers)
   149 		{
   150 		TInt sector = aFrameNumber % info.iBuffers;
   151 		TInt offset = (noOfPixels * sector)/info.iBuffers;
   152 		Mem::Fill((surfaceBufferPtr + offset), noOfPixels, TChar(0xFF));
   153 		}
   154 
   155  	//Submit update
   156 	TRect rc[1] =
   157 			{
   158 			TRect(0, 0, info.iSize.iWidth, info.iSize.iHeight)
   159 			};
   160 
   161 	RRegion region(1, rc);
   162 	RSurfaceUpdateSession aSurfaceUpdateSession;
   163 
   164 	err = aSurfaceUpdateSession.Connect();
   165 	if (err!=KErrNone)
   166 		{
   167 		RDebug::Print(_L("error in connecting surface update session\n"));
   168 	 	User::Exit(0);
   169 		}
   170 
   171 	TInt ret = aSurfaceUpdateSession.SubmitUpdate(KAllScreens, iSurfaceId, iSurfaceCurrentBuffer, &region);
   172 
   173 	RDebug::Print(_L("Frame %d done\n"), aFrameNumber);
   174 
   175 	if(ret != KErrNone)
   176 		{
   177 		RDebug::Print(_L("Error submitting update request\n"));
   178 		}
   179 
   180 	iSurfaceCurrentBuffer++;
   181 	if(iSurfaceCurrentBuffer == info.iBuffers)
   182 		{
   183 		iSurfaceCurrentBuffer = 0;
   184 		}
   185 
   186  	aChunk.Close();
   187 
   188  	err = aManager.CloseSurface(iSurfaceId);
   189  	if(err)
   190  		{
   191  		RDebug::Print(_L("Error closing the surface\n"));
   192  		}
   193  	aManager.Close();
   194 	}