sl@0
|
1 |
// Copyright (c) 2008-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 |
#include "rendertarget.h"
|
sl@0
|
17 |
#include <graphics/directgdidriver.h>
|
sl@0
|
18 |
#include <graphics/sgutils.h>
|
sl@0
|
19 |
#include "panic.h"
|
sl@0
|
20 |
#include <bitdraworigin.h>
|
sl@0
|
21 |
#include <bitdrawinterfaceid.h>
|
sl@0
|
22 |
#include "utils.h"
|
sl@0
|
23 |
#if defined(__WINS__) && defined(_DEBUG)
|
sl@0
|
24 |
#include "osbwin.h"
|
sl@0
|
25 |
#endif
|
sl@0
|
26 |
|
sl@0
|
27 |
RWsOffScreenImageTarget::RWsOffScreenImageTarget()
|
sl@0
|
28 |
{
|
sl@0
|
29 |
}
|
sl@0
|
30 |
|
sl@0
|
31 |
void RWsOffScreenImageTarget::OpenL(TUint32 aUsage, TSgCpuAccess aCpuAccess, TUidPixelFormat aPixelFormat, const TSize& aSize, TInt aScreenNumber)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
CDirectGdiDriver* theDGdiDriver = CDirectGdiDriver::Static();
|
sl@0
|
34 |
if(!theDGdiDriver)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
User::Leave(KErrNotReady);
|
sl@0
|
37 |
}
|
sl@0
|
38 |
iImageInfos[CRenderTarget::ENormalAspectRatio].iUsage = aUsage;
|
sl@0
|
39 |
iImageInfos[CRenderTarget::ENormalAspectRatio].iPixelFormat = aPixelFormat;
|
sl@0
|
40 |
iImageInfos[CRenderTarget::ENormalAspectRatio].iSizeInPixels = aSize;
|
sl@0
|
41 |
iImageInfos[CRenderTarget::ENormalAspectRatio].iCpuAccess = aCpuAccess;
|
sl@0
|
42 |
iImageInfos[CRenderTarget::ENormalAspectRatio].iScreenId = aScreenNumber;
|
sl@0
|
43 |
|
sl@0
|
44 |
iImageInfos[CRenderTarget::EInvertedAspectRatio] = iImageInfos[CRenderTarget::ENormalAspectRatio];
|
sl@0
|
45 |
iImageInfos[CRenderTarget::EInvertedAspectRatio].iSizeInPixels.SetSize(aSize.iHeight, aSize.iWidth);
|
sl@0
|
46 |
|
sl@0
|
47 |
const TInt KImageCount = 1;
|
sl@0
|
48 |
User::LeaveIfError(RSgImageCollection::Create(iImageInfos, KImageCount, iImageCollections, CRenderTarget::EAspectRatioCount));
|
sl@0
|
49 |
|
sl@0
|
50 |
for(TInt ii = 0; ii < CRenderTarget::EAspectRatioCount; ii++)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
User::LeaveIfError(iImageCollections[ii].GetInfo(iImageInfos[ii])); //should be the same as requested, this is just belt and braces
|
sl@0
|
53 |
User::LeaveIfError(iImageCollections[ii].OpenImage(0, iImages[ii]));
|
sl@0
|
54 |
iImageTargets[ii] = RDirectGdiImageTarget(*theDGdiDriver);
|
sl@0
|
55 |
User::LeaveIfError(iImageTargets[ii].Create(iImages[ii]));
|
sl@0
|
56 |
}
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
void RWsOffScreenImageTarget::Close()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
for(TInt ii = 0; ii < CRenderTarget::EAspectRatioCount; ii++)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
iImageTargets[ii].Close();
|
sl@0
|
64 |
iImages[ii].Close();
|
sl@0
|
65 |
iImageCollections[ii].Close();
|
sl@0
|
66 |
}
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
/**
|
sl@0
|
70 |
Create and construct render target. The function creates RSgImage and target associated with it.
|
sl@0
|
71 |
DirectGc wrapper will also be created at this stage.
|
sl@0
|
72 |
*/
|
sl@0
|
73 |
CRenderTarget* CRenderTarget::NewL(MWsIniFile* aIniFile, TUint32 aUsage, TSgCpuAccess aCpuAccess, TDisplayMode aDisplayMode, const TSize& aSize, TInt aScreenNumber)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
CRenderTarget* self=new(ELeave) CRenderTarget();
|
sl@0
|
76 |
CleanupStack::PushL(self);
|
sl@0
|
77 |
self->ConstructL(aIniFile, aUsage, aCpuAccess, aDisplayMode, aSize, aScreenNumber);
|
sl@0
|
78 |
CleanupStack::Pop(self);
|
sl@0
|
79 |
return self;
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
inline CRenderTarget::CRenderTarget()
|
sl@0
|
83 |
: iCurrentAspectRatio(ENormalAspectRatio)
|
sl@0
|
84 |
{}
|
sl@0
|
85 |
|
sl@0
|
86 |
CRenderTarget::~CRenderTarget()
|
sl@0
|
87 |
{
|
sl@0
|
88 |
delete iDirectGdiGcWrapper;
|
sl@0
|
89 |
iTarget.Close();
|
sl@0
|
90 |
#if defined(__WINS__) && defined(_DEBUG)
|
sl@0
|
91 |
delete iOsbWin;
|
sl@0
|
92 |
#endif
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
/**
|
sl@0
|
96 |
Construct render target. The function creates RSgImage and target associated with it.
|
sl@0
|
97 |
DirectGc wrapper will also be created at this stage.
|
sl@0
|
98 |
*/
|
sl@0
|
99 |
#if defined(__WINS__) && defined(_DEBUG)
|
sl@0
|
100 |
void CRenderTarget::ConstructL(MWsIniFile* aIniFile, TUint32 aUsage, TSgCpuAccess aCpuAccess, TDisplayMode aDisplayMode, const TSize& aSize, TInt aScreenNumber)
|
sl@0
|
101 |
#else
|
sl@0
|
102 |
void CRenderTarget::ConstructL(MWsIniFile* /*aIniFile*/, TUint32 aUsage, TSgCpuAccess aCpuAccess, TDisplayMode aDisplayMode, const TSize& aSize, TInt aScreenNumber)
|
sl@0
|
103 |
#endif
|
sl@0
|
104 |
{
|
sl@0
|
105 |
CDirectGdiDriver* theDGdiDriver = CDirectGdiDriver::Static();
|
sl@0
|
106 |
if(!theDGdiDriver)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
User::Leave(KErrNotReady);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
iTarget.OpenL(aUsage, aCpuAccess, SgUtils::DisplayModeToPixelFormat(aDisplayMode), aSize, aScreenNumber);
|
sl@0
|
111 |
iDirectGdiGcWrapper = CDirectGdiGcWrapper::NewL();
|
sl@0
|
112 |
User::LeaveIfError(iDirectGdiGcWrapper->DirectGdiGc().Activate(iTarget.iImageTargets[iCurrentAspectRatio]));
|
sl@0
|
113 |
|
sl@0
|
114 |
#if defined(__WINS__) && defined(_DEBUG)
|
sl@0
|
115 |
_LIT(KDebugOsb, "DEBUGOSB");
|
sl@0
|
116 |
if(aIniFile->FindVar(aScreenNumber, KDebugOsb))
|
sl@0
|
117 |
{
|
sl@0
|
118 |
_LIT(KDebugOsbTitleFormatBackBuffer, "Screen %d, back buffer ");
|
sl@0
|
119 |
_LIT(KDebugOsbTitleFormatScreen, "Screen %d, display buffer");
|
sl@0
|
120 |
TBuf<32> title;
|
sl@0
|
121 |
title.Format(((aUsage & ESgUsageScreenSource) ? KDebugOsbTitleFormatScreen : KDebugOsbTitleFormatBackBuffer), aScreenNumber);
|
sl@0
|
122 |
iOsbWin = CDebugOsbWin::NewL(title, aSize);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
#endif
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
TAny* CRenderTarget::ResolveObjectInterface(TUint aTypeId)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
switch(aTypeId)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
case MWsUiBuffer::EWsObjectInterfaceId:
|
sl@0
|
132 |
return static_cast<MWsUiBuffer*>(this);
|
sl@0
|
133 |
}
|
sl@0
|
134 |
return DirectGdiGc()->ResolveObjectInterface(aTypeId);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
TInt CRenderTarget::MapReadWrite(TAny*& aDataAddress, TInt& aDataStride)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
CDirectGdiDriver* driver = CDirectGdiDriver::Static();
|
sl@0
|
140 |
if(driver)
|
sl@0
|
141 |
driver->Finish();
|
sl@0
|
142 |
return Image().MapReadWrite(aDataAddress, aDataStride);
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
TInt CRenderTarget::MapWriteOnly(TAny*& aDataAddress, TInt& aDataStride)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
CDirectGdiDriver* driver = CDirectGdiDriver::Static();
|
sl@0
|
148 |
if(driver)
|
sl@0
|
149 |
driver->Finish();
|
sl@0
|
150 |
return Image().MapWriteOnly(aDataAddress, aDataStride);
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
TInt CRenderTarget::MapReadOnly(const TAny*& aDataAddress, TInt& aDataStride) const
|
sl@0
|
154 |
{
|
sl@0
|
155 |
CDirectGdiDriver* driver = CDirectGdiDriver::Static();
|
sl@0
|
156 |
if(driver)
|
sl@0
|
157 |
driver->Finish();
|
sl@0
|
158 |
return Image().MapReadOnly(aDataAddress, aDataStride);
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
TInt CRenderTarget::Unmap()
|
sl@0
|
162 |
{
|
sl@0
|
163 |
return Image().Unmap();
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
TInt CRenderTarget::Unmap() const
|
sl@0
|
167 |
{
|
sl@0
|
168 |
return Image().Unmap();
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
TUidPixelFormat CRenderTarget::PixelFormat() const
|
sl@0
|
172 |
{
|
sl@0
|
173 |
return ImageInfo().iPixelFormat;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
TSize CRenderTarget::SizeInPixels() const
|
sl@0
|
177 |
{
|
sl@0
|
178 |
return ImageInfo().iSizeInPixels;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
TDisplayMode CRenderTarget::DisplayMode() const
|
sl@0
|
182 |
{
|
sl@0
|
183 |
return SgUtils::PixelFormatToDisplayMode(PixelFormat());
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
const TSurfaceId& CRenderTarget::SurfaceId() const
|
sl@0
|
187 |
{
|
sl@0
|
188 |
return ImageCollection().SurfaceId();
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
const TSgDrawableId& CRenderTarget::ImageId(TAspectRatio aAspectRatio) const
|
sl@0
|
192 |
{
|
sl@0
|
193 |
return iTarget.iImages[aAspectRatio].Id();
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
void CRenderTarget::SetAspectRatio(TAspectRatio aAspectRatio)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
STD_ASSERT_DEBUG(aAspectRatio == ENormalAspectRatio || aAspectRatio == EInvertedAspectRatio, EPluginPanicTemp);
|
sl@0
|
199 |
if(aAspectRatio != iCurrentAspectRatio)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
iCurrentAspectRatio = aAspectRatio;
|
sl@0
|
202 |
iDirectGdiGcWrapper->Reset();
|
sl@0
|
203 |
}
|
sl@0
|
204 |
iDirectGdiGcWrapper->DirectGdiGc().Activate(iTarget.iImageTargets[iCurrentAspectRatio]);
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
TInt CRenderTarget::SetDrawDeviceOffset(TPoint& aOrigin)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
//set the offset on both wrappers
|
sl@0
|
210 |
MDrawDeviceOrigin* originInterface=NULL;
|
sl@0
|
211 |
TInt result= iDirectGdiGcWrapper->DirectGdiGc().GetInterface(TUid::Uid(KDrawDeviceOriginInterfaceID),reinterpret_cast<TAny*&>(originInterface));
|
sl@0
|
212 |
if (result>=KErrNone && originInterface!=NULL)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
result=originInterface->Set(aOrigin);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
if (result>=KErrNone)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
iOffset=aOrigin;
|
sl@0
|
220 |
iDirectGdiGcWrapper->DirectGdiGc().Activate(iTarget.iImageTargets[iCurrentAspectRatio]);
|
sl@0
|
221 |
}
|
sl@0
|
222 |
return result;
|
sl@0
|
223 |
}
|
sl@0
|
224 |
|
sl@0
|
225 |
TInt CRenderTarget::AllocNewTarget(RWsOffScreenImageTarget& aNewTarget, const TSize& aNewSize)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
TRAPD(err,
|
sl@0
|
228 |
aNewTarget.OpenL(
|
sl@0
|
229 |
iTarget.iImageInfos[CRenderTarget::ENormalAspectRatio].iUsage,
|
sl@0
|
230 |
iTarget.iImageInfos[CRenderTarget::ENormalAspectRatio].iCpuAccess,
|
sl@0
|
231 |
iTarget.iImageInfos[CRenderTarget::ENormalAspectRatio].iPixelFormat,
|
sl@0
|
232 |
aNewSize,
|
sl@0
|
233 |
iTarget.iImageInfos[CRenderTarget::ENormalAspectRatio].iScreenId))
|
sl@0
|
234 |
return err;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
void CRenderTarget::SwitchTarget(RWsOffScreenImageTarget& aNewTarget)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
iTarget.Close();
|
sl@0
|
240 |
iTarget = aNewTarget;
|
sl@0
|
241 |
iDirectGdiGcWrapper->DirectGdiGc().Activate(iTarget.iImageTargets[iCurrentAspectRatio]);
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
void CRenderTarget::GetPixel(TRgb& aColor, const TPoint& aPixel) const
|
sl@0
|
245 |
{
|
sl@0
|
246 |
const TAny* dataAddress = NULL;
|
sl@0
|
247 |
TInt dataStride;
|
sl@0
|
248 |
const TInt err = MapReadOnly(dataAddress, dataStride);
|
sl@0
|
249 |
if(!err)
|
sl@0
|
250 |
{
|
sl@0
|
251 |
const TUidPixelFormat pixelFormat = PixelFormat();
|
sl@0
|
252 |
const TInt bpp = SgUtils::MinDataStride(1, pixelFormat);
|
sl@0
|
253 |
const TUint32 offset = aPixel.iY * dataStride / bpp + aPixel.iX;
|
sl@0
|
254 |
switch(pixelFormat)
|
sl@0
|
255 |
{
|
sl@0
|
256 |
case EUidPixelFormatARGB_8888_PRE:
|
sl@0
|
257 |
case EUidPixelFormatARGB_8888:
|
sl@0
|
258 |
{
|
sl@0
|
259 |
const TInt32* dataAddress1 = static_cast<const TInt32*>(dataAddress) + offset;
|
sl@0
|
260 |
const TInt32 colValue = *dataAddress1;
|
sl@0
|
261 |
aColor.SetInternal(colValue);
|
sl@0
|
262 |
}
|
sl@0
|
263 |
break;
|
sl@0
|
264 |
case EUidPixelFormatRGB_565:
|
sl@0
|
265 |
{
|
sl@0
|
266 |
const TInt16* dataAddress1 = static_cast<const TInt16*>(dataAddress) + offset;
|
sl@0
|
267 |
const TInt16 colValue = *dataAddress1;
|
sl@0
|
268 |
aColor = TRgb::Color64K((TInt)colValue);
|
sl@0
|
269 |
}
|
sl@0
|
270 |
break;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
Unmap();
|
sl@0
|
273 |
}
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
void CRenderTarget::GetScanLine(TDes8& aScanLine, const TPoint& aStartPixel, TInt aPixelLength, TDisplayMode aDispMode) const
|
sl@0
|
277 |
{
|
sl@0
|
278 |
TRect rectSrc(aStartPixel, TSize(aPixelLength, 1));
|
sl@0
|
279 |
const TRect rectClientArea(SizeInPixels());
|
sl@0
|
280 |
rectSrc.Intersection(rectClientArea);
|
sl@0
|
281 |
if(rectSrc.IsEmpty())
|
sl@0
|
282 |
return;
|
sl@0
|
283 |
const TUidPixelFormat pixelFormatSource = PixelFormat();
|
sl@0
|
284 |
const TUidPixelFormat pixelFormatDest = SgUtils::DisplayModeToPixelFormat(aDispMode);
|
sl@0
|
285 |
if((pixelFormatSource == EUidPixelFormatUnknown) || (pixelFormatDest == EUidPixelFormatUnknown))
|
sl@0
|
286 |
return;
|
sl@0
|
287 |
|
sl@0
|
288 |
aPixelLength = rectSrc.Width();
|
sl@0
|
289 |
const TInt dataStrideDest = SgUtils::MinDataStride(aPixelLength, pixelFormatDest);
|
sl@0
|
290 |
if(dataStrideDest <= 0)
|
sl@0
|
291 |
return;
|
sl@0
|
292 |
const TAny* dataAddressSource = NULL;
|
sl@0
|
293 |
TInt dataStrideSource;
|
sl@0
|
294 |
const TInt err = MapReadOnly(dataAddressSource, dataStrideSource);
|
sl@0
|
295 |
if(!err)
|
sl@0
|
296 |
{
|
sl@0
|
297 |
aScanLine.SetLength(dataStrideDest);
|
sl@0
|
298 |
SgUtils::TransferPixels(const_cast<TUint8*>(aScanLine.Ptr()), dataStrideDest, pixelFormatDest,
|
sl@0
|
299 |
dataAddressSource, dataStrideSource, pixelFormatSource, rectSrc);
|
sl@0
|
300 |
Unmap();
|
sl@0
|
301 |
}
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|
sl@0
|
304 |
TBool CRenderTarget::RectCompare(const TRect& aRect1, const TRect& aRect2) const
|
sl@0
|
305 |
{
|
sl@0
|
306 |
const TAny* startDataAddress = NULL;
|
sl@0
|
307 |
TInt dataStride;
|
sl@0
|
308 |
|
sl@0
|
309 |
const TRect clientRect(SizeInPixels());
|
sl@0
|
310 |
TRect rect1 = aRect1;
|
sl@0
|
311 |
TRect rect2 = aRect2;
|
sl@0
|
312 |
|
sl@0
|
313 |
rect1.Intersection(clientRect);
|
sl@0
|
314 |
rect2.Intersection(clientRect);
|
sl@0
|
315 |
if(rect1.IsEmpty() || rect2.IsEmpty() || (rect1 != aRect1) || (rect2 != aRect2) ||
|
sl@0
|
316 |
(rect1.Width() != rect2.Width()) || (rect1.Height() != rect2.Height()))
|
sl@0
|
317 |
return EFalse;
|
sl@0
|
318 |
|
sl@0
|
319 |
TUidPixelFormat pixelFormat = PixelFormat();
|
sl@0
|
320 |
if(pixelFormat == EUidPixelFormatUnknown)
|
sl@0
|
321 |
return EFalse;
|
sl@0
|
322 |
|
sl@0
|
323 |
TInt bpp = SgUtils::MinDataStride(1, pixelFormat);
|
sl@0
|
324 |
if(bpp == 0)
|
sl@0
|
325 |
return EFalse;
|
sl@0
|
326 |
|
sl@0
|
327 |
TInt err = MapReadOnly(startDataAddress, dataStride);
|
sl@0
|
328 |
if(err != KErrNone)
|
sl@0
|
329 |
return EFalse;
|
sl@0
|
330 |
TBool res = ETrue;
|
sl@0
|
331 |
TPoint startPoint1 = rect1.iTl;
|
sl@0
|
332 |
TPoint startPoint2 = rect2.iTl;
|
sl@0
|
333 |
const TInt length1 = SgUtils::MinDataStride(rect1.Width(), pixelFormat);
|
sl@0
|
334 |
const TInt length2 = SgUtils::MinDataStride(rect2.Width(), pixelFormat);
|
sl@0
|
335 |
|
sl@0
|
336 |
for(; (startPoint1.iY < rect1.iBr.iY) && (startPoint2.iY < rect2.iBr.iY); startPoint1.iY++, startPoint2.iY++)
|
sl@0
|
337 |
{
|
sl@0
|
338 |
const TUint8* dataAddress1 = DataAddress(startDataAddress, startPoint1, dataStride, bpp);
|
sl@0
|
339 |
const TUint8* dataAddress2 = DataAddress(startDataAddress, startPoint2, dataStride, bpp);
|
sl@0
|
340 |
|
sl@0
|
341 |
if(Mem::Compare(dataAddress1, length1, dataAddress2, length2) != 0)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
res = EFalse;
|
sl@0
|
344 |
break;
|
sl@0
|
345 |
}
|
sl@0
|
346 |
}
|
sl@0
|
347 |
Unmap();
|
sl@0
|
348 |
|
sl@0
|
349 |
return res;
|
sl@0
|
350 |
}
|
sl@0
|
351 |
|
sl@0
|
352 |
void CRenderTarget::CopyToBitmapL(CFbsBitmap* aBitmap, const TRect& aRect) const
|
sl@0
|
353 |
{
|
sl@0
|
354 |
const TUidPixelFormat pixelFormatDest = SgUtils::DisplayModeToPixelFormat(aBitmap->DisplayMode());
|
sl@0
|
355 |
const TUidPixelFormat pixelFormatSrc = PixelFormat();
|
sl@0
|
356 |
if((pixelFormatSrc == EUidPixelFormatUnknown) || (pixelFormatDest == EUidPixelFormatUnknown))
|
sl@0
|
357 |
User::LeaveIfError(KErrNotSupported);
|
sl@0
|
358 |
|
sl@0
|
359 |
aBitmap->BeginDataAccess();
|
sl@0
|
360 |
const TSize sizeDest = aBitmap->SizeInPixels();
|
sl@0
|
361 |
TRect rectSrc = aRect;
|
sl@0
|
362 |
rectSrc.Intersection(TRect(SizeInPixels()));
|
sl@0
|
363 |
if(rectSrc.IsEmpty())
|
sl@0
|
364 |
return;
|
sl@0
|
365 |
if(rectSrc.Height() > sizeDest.iHeight)
|
sl@0
|
366 |
{
|
sl@0
|
367 |
rectSrc.SetHeight(sizeDest.iHeight);
|
sl@0
|
368 |
}
|
sl@0
|
369 |
if(rectSrc.Width() > sizeDest.iWidth)
|
sl@0
|
370 |
{
|
sl@0
|
371 |
rectSrc.SetWidth(sizeDest.iWidth);
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
const TAny* dataAddressSrc = NULL;
|
sl@0
|
375 |
TInt dataStrideSrc;
|
sl@0
|
376 |
User::LeaveIfError(MapReadOnly(dataAddressSrc, dataStrideSrc));
|
sl@0
|
377 |
|
sl@0
|
378 |
SgUtils::TransferPixels(aBitmap->DataAddress(), aBitmap->DataStride(), pixelFormatDest,
|
sl@0
|
379 |
dataAddressSrc, dataStrideSrc, pixelFormatSrc, rectSrc);
|
sl@0
|
380 |
|
sl@0
|
381 |
aBitmap->EndDataAccess();
|
sl@0
|
382 |
Unmap();
|
sl@0
|
383 |
}
|
sl@0
|
384 |
|
sl@0
|
385 |
/*
|
sl@0
|
386 |
Helper function to obtain the address of the buffer
|
sl@0
|
387 |
*/
|
sl@0
|
388 |
const TUint8* CRenderTarget::DataAddress(const TAny* aStartDataAddress, const TPoint& aStartPoint, TInt aDataStride, TInt aBpp) const
|
sl@0
|
389 |
{
|
sl@0
|
390 |
const TInt offset = aStartPoint.iX * aBpp + aStartPoint.iY * aDataStride;
|
sl@0
|
391 |
const TUint8* dataAddress = static_cast<TUint8*>(const_cast<TAny*> (aStartDataAddress));
|
sl@0
|
392 |
|
sl@0
|
393 |
return(dataAddress + offset);
|
sl@0
|
394 |
}
|
sl@0
|
395 |
|
sl@0
|
396 |
#if defined(__WINS__) && defined(_DEBUG)
|
sl@0
|
397 |
void CRenderTarget::UpdateDebugWin()
|
sl@0
|
398 |
{
|
sl@0
|
399 |
if (iOsbWin)
|
sl@0
|
400 |
{
|
sl@0
|
401 |
const TAny* dataAddress = NULL;
|
sl@0
|
402 |
TInt dataStride;
|
sl@0
|
403 |
const TInt err = MapReadOnly(dataAddress, dataStride);
|
sl@0
|
404 |
if(!err)
|
sl@0
|
405 |
{
|
sl@0
|
406 |
const TUint32* dataAddress1 = static_cast<const TUint32*>(dataAddress);
|
sl@0
|
407 |
iOsbWin->Refresh(SizeInPixels(), DisplayMode(), dataAddress1);
|
sl@0
|
408 |
Unmap();
|
sl@0
|
409 |
}
|
sl@0
|
410 |
}
|
sl@0
|
411 |
}
|
sl@0
|
412 |
#endif
|