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