66
|
1 |
/*
|
|
2 |
* Copyright (c) 2005 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 "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <lcdgdrv.h>
|
|
20 |
#include "lcdgdrvif.h"
|
|
21 |
#include "calctransform.h"
|
|
22 |
#include "lcdgdev.h"
|
|
23 |
|
|
24 |
CLcdGraphicsDeviceImpl::CLcdGraphicsDeviceImpl
|
|
25 |
(
|
|
26 |
CLcdGraphicsDriver& aDriver,
|
|
27 |
const TImageType& aTargetType,
|
|
28 |
CRenderFunctions* aRenderers,
|
|
29 |
const TColorMap& aColorMap,
|
|
30 |
const TDrawFunctions& aDrawFunctions
|
|
31 |
)
|
|
32 |
: iDriver(aDriver)
|
|
33 |
, iRenderers(aRenderers)
|
|
34 |
, iColorMap(aColorMap)
|
|
35 |
, iDrawFunctions(aDrawFunctions)
|
|
36 |
{
|
|
37 |
iRenderKey.iTargetType = aTargetType;
|
|
38 |
ASSERT(iDrawFunctions.iDisplayMode == aTargetType.iColorMode);
|
|
39 |
}
|
|
40 |
|
|
41 |
CLcdGraphicsDeviceImpl::~CLcdGraphicsDeviceImpl()
|
|
42 |
{
|
|
43 |
delete iRenderers;
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
TUint32 CLcdGraphicsDeviceImpl::DrawingCaps() const
|
|
48 |
{
|
|
49 |
const TInt renderCaps = (CLcdGraphicsDevice::ECapDrawRegion | CLcdGraphicsDevice::ECapCopyRegion);
|
|
50 |
return iDrawFunctions.iDrawCaps | renderCaps;
|
|
51 |
}
|
|
52 |
|
|
53 |
TUint32 CLcdGraphicsDeviceImpl::Quantize(TUint32 aRGB) const
|
|
54 |
{
|
|
55 |
return (*iColorMap.iQuantize)(aRGB);
|
|
56 |
}
|
|
57 |
|
|
58 |
/**
|
|
59 |
* Transforming biblt from aColorBitmap/aAlphaBitmap to target surface
|
|
60 |
* Composites source image over destination image (either alpha blending
|
|
61 |
* or masking as appropriate to <CODE>aSrcTransparency</CODE>).
|
|
62 |
*/
|
|
63 |
TInt CLcdGraphicsDeviceImpl::DrawRegion
|
|
64 |
(
|
|
65 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
66 |
const TRect& aDstRect,
|
|
67 |
const TAcceleratedBitmapInfo* aSrcColorBitmap,
|
|
68 |
const TAcceleratedBitmapInfo* aSrcAlphaBitmap,
|
|
69 |
TTransparency aSrcTransparency,
|
|
70 |
const TRect& aSrcRect,
|
|
71 |
TTransformType aSrcTransform,
|
|
72 |
const TRect& aClipRect
|
|
73 |
)
|
|
74 |
{
|
|
75 |
TInt err = KErrNotSupported;
|
|
76 |
|
|
77 |
TImageType sourceType;
|
|
78 |
sourceType.iColorMode = aSrcColorBitmap->iDisplayMode;
|
|
79 |
sourceType.iAlphaMode = aSrcAlphaBitmap ? aSrcAlphaBitmap->iDisplayMode : ENone;
|
|
80 |
sourceType.iTransparency = aSrcTransparency;
|
|
81 |
|
|
82 |
iRenderKey.iSourceType = TCompactImageType(sourceType);
|
|
83 |
iRenderKey.iTransform = (1<<aSrcTransform);
|
|
84 |
iRenderKey.iComposite = ECompositeSrcOver;
|
|
85 |
|
|
86 |
const TImageRenderer* renderer = iRenderers->Get(iRenderKey);
|
|
87 |
if (renderer)
|
|
88 |
{
|
|
89 |
TImageRenderFunction drawRegion = renderer->iFunction;
|
|
90 |
|
|
91 |
// calc source to target transform
|
|
92 |
TLcdTransform transform = CalcTransform(aDstRect, aSrcRect, aSrcTransform);
|
|
93 |
|
|
94 |
TRect dstRect(aDstRect);
|
|
95 |
TRect srcRect(aSrcRect);
|
|
96 |
TRect srcClipRect(aSrcColorBitmap->iSize);
|
|
97 |
TRect dstClipRect(aDstBitmap->iSize);
|
|
98 |
|
|
99 |
// clip cliprect to device rect
|
|
100 |
dstClipRect.Intersection(aClipRect);
|
|
101 |
|
|
102 |
// calculate source and target rects clipped to src and target bounds.
|
|
103 |
ClipTransformRect(dstRect, srcRect, dstClipRect, srcClipRect, transform);
|
|
104 |
|
|
105 |
dstRect.Intersection(dstClipRect);
|
|
106 |
|
|
107 |
if (!dstRect.IsEmpty())
|
|
108 |
{
|
|
109 |
// calc target to source transform.
|
|
110 |
transform = transform.Inverse();
|
|
111 |
|
|
112 |
ASSERT(CheckBounds(aDstBitmap->iSize, aSrcColorBitmap->iSize, dstRect, transform));
|
|
113 |
|
|
114 |
(*drawRegion)(aDstBitmap, NULL, dstRect, aSrcColorBitmap, aSrcAlphaBitmap, transform);
|
|
115 |
}
|
|
116 |
|
|
117 |
err = KErrNone;
|
|
118 |
}
|
|
119 |
|
|
120 |
return err;
|
|
121 |
}
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Transforming biblt from <CODE>aSrcColorBitmap,aSrcAlphaBitmap<CODE>
|
|
125 |
* to <CODE>aDstColorBitmap,aDstAlphaBitmap</CODE>.
|
|
126 |
* Copies source image pixels to destination image converting color
|
|
127 |
* and transparency pixels to the destination format. Supports translation
|
|
128 |
* and symmetry transformation of source image region, specified by
|
|
129 |
* <CODE>aSrcTransform</CODE>.
|
|
130 |
*/
|
|
131 |
TInt CLcdGraphicsDeviceImpl::CopyRegion
|
|
132 |
(
|
|
133 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
134 |
const TRect& aDstRect,
|
|
135 |
const TAcceleratedBitmapInfo* aSrcColorBitmap,
|
|
136 |
const TAcceleratedBitmapInfo* aSrcAlphaBitmap,
|
|
137 |
TTransparency aSrcTransparency,
|
|
138 |
const TRect& aSrcRect,
|
|
139 |
TTransformType aSrcTransform,
|
|
140 |
const TRect& aClipRect
|
|
141 |
)
|
|
142 |
{
|
|
143 |
TInt err = KErrNotSupported;
|
|
144 |
ASSERT(aDstBitmap->iAddress);
|
|
145 |
|
|
146 |
TImageType sourceType;
|
|
147 |
|
|
148 |
sourceType.iColorMode = aSrcColorBitmap->iDisplayMode;
|
|
149 |
sourceType.iAlphaMode = aSrcAlphaBitmap ? aSrcAlphaBitmap->iDisplayMode : ENone;
|
|
150 |
sourceType.iTransparency = aSrcTransparency;
|
|
151 |
|
|
152 |
iRenderKey.iSourceType = TCompactImageType(sourceType);
|
|
153 |
iRenderKey.iTransform = (1<<aSrcTransform);
|
|
154 |
iRenderKey.iComposite = ECompositeSrcCopy;
|
|
155 |
|
|
156 |
const TImageRenderer* renderer = iRenderers->Get(iRenderKey);
|
|
157 |
if (renderer)
|
|
158 |
{
|
|
159 |
TImageRenderFunction copyRegion = renderer->iFunction;
|
|
160 |
|
|
161 |
// calc source to target transform
|
|
162 |
TLcdTransform transform = CalcTransform(aDstRect, aSrcRect, aSrcTransform);
|
|
163 |
|
|
164 |
TRect dstRect(aDstRect);
|
|
165 |
TRect srcRect(aSrcRect);
|
|
166 |
TRect srcClipRect(aSrcColorBitmap->iSize);
|
|
167 |
TRect dstClipRect(aDstBitmap->iSize);
|
|
168 |
|
|
169 |
// clip cliprect to device rect
|
|
170 |
dstClipRect.Intersection(aClipRect);
|
|
171 |
|
|
172 |
// clip source and target rects
|
|
173 |
ClipTransformRect(dstRect, srcRect, dstClipRect, srcClipRect, transform);
|
|
174 |
|
|
175 |
// check src and dst rects still correspond
|
|
176 |
ASSERT(CheckTransform(dstRect, srcRect, transform));
|
|
177 |
|
|
178 |
dstRect.Intersection(dstClipRect);
|
|
179 |
|
|
180 |
if (!dstRect.IsEmpty())
|
|
181 |
{
|
|
182 |
// calc target to source transform.
|
|
183 |
transform = transform.Inverse();
|
|
184 |
|
|
185 |
// check source and dst rects lie within bounds
|
|
186 |
ASSERT(CheckBounds(aDstBitmap->iSize, aSrcColorBitmap->iSize, dstRect, transform));
|
|
187 |
|
|
188 |
(*copyRegion)(aDstBitmap, NULL, dstRect, aSrcColorBitmap, aSrcAlphaBitmap, transform);
|
|
189 |
}
|
|
190 |
|
|
191 |
err = KErrNone;
|
|
192 |
}
|
|
193 |
|
|
194 |
return err;
|
|
195 |
}
|
|
196 |
|
|
197 |
|
|
198 |
/*
|
|
199 |
* Draw line from aStart to aEnd including both end points and
|
|
200 |
* using line style TStrokeStyle.
|
|
201 |
*/
|
|
202 |
TInt CLcdGraphicsDeviceImpl::DrawLine
|
|
203 |
(
|
|
204 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
205 |
const TPoint& aStart,
|
|
206 |
const TPoint& aEnd,
|
|
207 |
TUint32 aRGB,
|
|
208 |
TStrokeStyle aStyle,
|
|
209 |
const TRect& aClipRect
|
|
210 |
)
|
|
211 |
{
|
|
212 |
TInt caps = ECapDrawLine;
|
|
213 |
if (aStyle == EStrokeDotted)
|
|
214 |
{
|
|
215 |
caps |= ECapStrokeDotted;
|
|
216 |
}
|
|
217 |
if ((iDrawFunctions.iDrawCaps & caps) != caps)
|
|
218 |
{
|
|
219 |
return KErrNotSupported;
|
|
220 |
}
|
|
221 |
ASSERT(iDrawFunctions.iDrawLine);
|
|
222 |
(*iDrawFunctions.iDrawLine)(aDstBitmap, aStart, aEnd, (*iColorMap.iForward)(aRGB), aStyle, aClipRect);
|
|
223 |
return KErrNone;
|
|
224 |
}
|
|
225 |
|
|
226 |
/**
|
|
227 |
* Draw outline of <CODE>aRect</CODE>
|
|
228 |
*/
|
|
229 |
TInt CLcdGraphicsDeviceImpl::DrawRect
|
|
230 |
(
|
|
231 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
232 |
const TRect& aRect,
|
|
233 |
TUint32 aRGB,
|
|
234 |
TStrokeStyle aStyle,
|
|
235 |
const TRect& aClipRect
|
|
236 |
)
|
|
237 |
{
|
|
238 |
TInt caps = ECapDrawRect;
|
|
239 |
if (aStyle == EStrokeDotted)
|
|
240 |
{
|
|
241 |
caps |= ECapStrokeDotted;
|
|
242 |
}
|
|
243 |
if ((iDrawFunctions.iDrawCaps & caps) != caps)
|
|
244 |
{
|
|
245 |
return KErrNotSupported;
|
|
246 |
}
|
|
247 |
ASSERT(iDrawFunctions.iDrawRect);
|
|
248 |
(*iDrawFunctions.iDrawRect)(aDstBitmap, aRect, (*iColorMap.iForward)(aRGB), aStyle, aClipRect);
|
|
249 |
return KErrNone;
|
|
250 |
}
|
|
251 |
|
|
252 |
/**
|
|
253 |
* Fill interior of <CODE>aRect</CODE> with color <CODE>aRGB</CODE>
|
|
254 |
*/
|
|
255 |
TInt CLcdGraphicsDeviceImpl::FillRect
|
|
256 |
(
|
|
257 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
258 |
const TRect& aRect,
|
|
259 |
TUint32 aRGB,
|
|
260 |
const TRect& aClipRect
|
|
261 |
)
|
|
262 |
{
|
|
263 |
if (!(iDrawFunctions.iDrawCaps & ECapFillRect))
|
|
264 |
{
|
|
265 |
return KErrNotSupported;
|
|
266 |
}
|
|
267 |
ASSERT(iDrawFunctions.iFillRect);
|
|
268 |
(*iDrawFunctions.iFillRect)(aDstBitmap, aRect, (*iColorMap.iForward)(aRGB), aClipRect);
|
|
269 |
return KErrNone;
|
|
270 |
}
|
|
271 |
|
|
272 |
/**
|
|
273 |
* Draw the arc of an ellipse bounded by aBoundingRect in device coordinates,
|
|
274 |
* starting the arc at aStartAngle from the ellipse horizontal axis and
|
|
275 |
* extending for aArcAngle degrees anticlockwise. Draw with color aRGB and
|
|
276 |
* clip to aClipRect in device coords.
|
|
277 |
*/
|
|
278 |
TInt CLcdGraphicsDeviceImpl::DrawArc
|
|
279 |
(
|
|
280 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
281 |
const TRect& aBoundingRect,
|
|
282 |
const TInt aStartAngle,
|
|
283 |
const TInt aArcAngle,
|
|
284 |
TUint32 aRGB,
|
|
285 |
TStrokeStyle aStyle,
|
|
286 |
const TRect& aClipRect
|
|
287 |
)
|
|
288 |
{
|
|
289 |
TInt caps = ECapDrawRect;
|
|
290 |
if (aStyle == EStrokeDotted)
|
|
291 |
{
|
|
292 |
caps |= ECapStrokeDotted;
|
|
293 |
}
|
|
294 |
if ((iDrawFunctions.iDrawCaps & caps) != caps)
|
|
295 |
{
|
|
296 |
return KErrNotSupported;
|
|
297 |
}
|
|
298 |
ASSERT(iDrawFunctions.iDrawArc);
|
|
299 |
(*iDrawFunctions.iDrawArc)(aDstBitmap, aBoundingRect, aStartAngle, aArcAngle, (*iColorMap.iForward)(aRGB), aStyle, aClipRect);
|
|
300 |
return KErrNone;
|
|
301 |
}
|
|
302 |
|
|
303 |
/**
|
|
304 |
* Fill the region bounded by an arc and the radii of its end points of an ellipse bounded
|
|
305 |
* by aBoundingRect in device coordinates. The first radius lies at aStartAngle from the
|
|
306 |
* ellipse horizontal axis and the second radies lies aArcAngle degrees anticlockwise
|
|
307 |
* from the first. Fill with color aRGB and clip to aClipRect in device coords.
|
|
308 |
*/
|
|
309 |
TInt CLcdGraphicsDeviceImpl::FillArc
|
|
310 |
(
|
|
311 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
312 |
const TRect& aBoundingRect,
|
|
313 |
const TInt aStartAngle,
|
|
314 |
const TInt aArcAngle,
|
|
315 |
TUint32 aRGB,
|
|
316 |
const TRect& aClipRect
|
|
317 |
)
|
|
318 |
{
|
|
319 |
if (!(iDrawFunctions.iDrawCaps & ECapFillArc))
|
|
320 |
{
|
|
321 |
return KErrNotSupported;
|
|
322 |
}
|
|
323 |
ASSERT(iDrawFunctions.iFillArc);
|
|
324 |
(*iDrawFunctions.iFillArc)(aDstBitmap, aBoundingRect, aStartAngle, aArcAngle, (*iColorMap.iForward)(aRGB), aClipRect);
|
|
325 |
return KErrNone;
|
|
326 |
}
|
|
327 |
|
|
328 |
/**
|
|
329 |
* Fill a triangle in device coordinates with color aRGB,
|
|
330 |
* clipping to aClipRect in device coordinates.
|
|
331 |
*/
|
|
332 |
TInt CLcdGraphicsDeviceImpl::FillTriangle
|
|
333 |
(
|
|
334 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
335 |
const TPoint aPoints[3],
|
|
336 |
TUint32 aRGB,
|
|
337 |
const TRect& aClipRect
|
|
338 |
)
|
|
339 |
{
|
|
340 |
if (!(iDrawFunctions.iDrawCaps & ECapFillTriangle))
|
|
341 |
{
|
|
342 |
return KErrNotSupported;
|
|
343 |
}
|
|
344 |
ASSERT(iDrawFunctions.iFillTriangle);
|
|
345 |
(*iDrawFunctions.iFillTriangle)(aDstBitmap, aPoints, (*iColorMap.iForward)(aRGB), aClipRect);
|
|
346 |
return KErrNone;
|
|
347 |
}
|
|
348 |
|
|
349 |
TInt CLcdGraphicsDeviceImpl::DrawText
|
|
350 |
(
|
|
351 |
const TAcceleratedBitmapInfo* /*aDstBitmap*/,
|
|
352 |
const TDesC& /*aText*/,
|
|
353 |
const TPoint& /*aPoint*/,
|
|
354 |
const CFont* /*aFont*/,
|
|
355 |
TUint32 /*aColor*/,
|
|
356 |
const TRect& /*aClipRect*/
|
|
357 |
)
|
|
358 |
{
|
|
359 |
return KErrNotSupported;
|
|
360 |
}
|
|
361 |
|
|
362 |
/**
|
|
363 |
* This function is used, when image is drawn and rendering
|
|
364 |
* target is framebuffer of CanavsGraphicsItem.
|
|
365 |
*/
|
|
366 |
TInt CLcdGraphicsDeviceImpl::DrawRegionForCanvasGraphicsItem
|
|
367 |
(
|
|
368 |
const TAcceleratedBitmapInfo* aDstBitmap,
|
|
369 |
const TRect& aDstRect,
|
|
370 |
const TAcceleratedBitmapInfo* aSrcColorBitmap,
|
|
371 |
const TAcceleratedBitmapInfo* /*aSrcAlphaBitmap*/,
|
|
372 |
TTransparency /*aSrcTransparency*/,
|
|
373 |
const TRect& aSrcRect,
|
|
374 |
TTransformType aSrcTransform,
|
|
375 |
const TRect& aClipRect,
|
|
376 |
const TCanvasGraphicsItemOperationsType& aOperation
|
|
377 |
)
|
|
378 |
{
|
|
379 |
TInt err = KErrNotSupported;
|
|
380 |
|
|
381 |
// calc source to target transform
|
|
382 |
TLcdTransform transform = CalcTransform(aDstRect, aSrcRect, aSrcTransform);
|
|
383 |
|
|
384 |
TRect dstRect(aDstRect);
|
|
385 |
TRect srcRect(aSrcRect);
|
|
386 |
TRect srcClipRect(aSrcColorBitmap->iSize);
|
|
387 |
TRect dstClipRect(aDstBitmap->iSize);
|
|
388 |
|
|
389 |
// clip cliprect to device rect
|
|
390 |
dstClipRect.Intersection(aClipRect);
|
|
391 |
|
|
392 |
// calculate source and target rects clipped to src and target bounds.
|
|
393 |
ClipTransformRect(dstRect, srcRect, dstClipRect, srcClipRect, transform);
|
|
394 |
|
|
395 |
dstRect.Intersection(dstClipRect);
|
|
396 |
|
|
397 |
if (!dstRect.IsEmpty())
|
|
398 |
{
|
|
399 |
// calc target to source transform.
|
|
400 |
transform = transform.Inverse();
|
|
401 |
|
|
402 |
ASSERT(CheckBounds(aDstBitmap->iSize, aSrcColorBitmap->iSize, dstRect, transform));
|
|
403 |
|
|
404 |
ASSERT(aDstBitmap->iDisplayMode == EColor16MA);
|
|
405 |
ASSERT(aSrcColorBitmap->iDisplayMode == EColor16MA);
|
|
406 |
|
|
407 |
DoBlit(aDstBitmap, dstRect, aSrcColorBitmap, transform, aOperation);
|
|
408 |
}
|
|
409 |
|
|
410 |
err = KErrNone;
|
|
411 |
|
|
412 |
return err;
|
|
413 |
}
|
|
414 |
|
|
415 |
// support for rendering image on CanavsGraphicsItem frame buffer
|
|
416 |
TInt CLcdGraphicsDeviceImpl::PixelPitch(const TAcceleratedBitmapInfo* aBitmap)
|
|
417 |
{
|
|
418 |
switch (aBitmap->iDisplayMode)
|
|
419 |
{
|
|
420 |
case EColor64K:
|
|
421 |
case EColor4K:
|
|
422 |
return 2;
|
|
423 |
case EColorARGB8888:
|
|
424 |
case EColor16MU:
|
|
425 |
return 4;
|
|
426 |
case EGray256:
|
|
427 |
return 1;
|
|
428 |
}
|
|
429 |
|
|
430 |
// Any other display mode is either invalid, or has a fractional number of
|
|
431 |
// bytes per pixel, and cannot be handled by this routine.
|
|
432 |
ASSERT(EFalse);
|
|
433 |
return 0; // Pacify the compiler
|
|
434 |
}
|
|
435 |
|
|
436 |
// support for rendering image on CanavsGraphicsItem frame buffer
|
|
437 |
void CLcdGraphicsDeviceImpl::DoBlit
|
|
438 |
(
|
|
439 |
const TAcceleratedBitmapInfo* aDstColorBitmap,
|
|
440 |
const TRect& aDstRect, // must be clipped to destination
|
|
441 |
const TAcceleratedBitmapInfo* aSrcColorBitmap,
|
|
442 |
const TLcdTransform& aTransform, // includes anchor
|
|
443 |
const TCanvasGraphicsItemOperationsType& aOperation
|
|
444 |
)
|
|
445 |
{
|
|
446 |
ASSERT(aDstColorBitmap != NULL);
|
|
447 |
ASSERT(aSrcColorBitmap != NULL);
|
|
448 |
|
|
449 |
TPoint srcPoint = aTransform(aDstRect.iTl);
|
|
450 |
|
|
451 |
TInt dudx = aTransform.iDuDx;
|
|
452 |
TInt dudy = aTransform.iDuDy;
|
|
453 |
TInt dvdx = aTransform.iDvDx;
|
|
454 |
TInt dvdy = aTransform.iDvDy;
|
|
455 |
|
|
456 |
//
|
|
457 |
// For each bitmap, calculate the starting address and byte offsets to the
|
|
458 |
// next address for one line down and one pixel right.
|
|
459 |
//
|
|
460 |
const TInt dstLinePitch = aDstColorBitmap->iLinePitch;
|
|
461 |
const TInt dstPixelPitch = PixelPitch(aDstColorBitmap);
|
|
462 |
TUint8* dstAddress = aDstColorBitmap->iAddress;
|
|
463 |
dstAddress += aDstRect.iTl.iY * dstLinePitch + aDstRect.iTl.iX * dstPixelPitch;
|
|
464 |
|
|
465 |
const TInt colorLinePitch = aSrcColorBitmap->iLinePitch;
|
|
466 |
const TInt colorPixelPitch = PixelPitch(aSrcColorBitmap);
|
|
467 |
TUint8* colorAddress = aSrcColorBitmap->iAddress;
|
|
468 |
colorAddress += srcPoint.iY * colorLinePitch + srcPoint.iX * colorPixelPitch;
|
|
469 |
|
|
470 |
// For the source bitmap, also calculate the pitch to the next address for
|
|
471 |
// one line down and one pixel right in the destination bitmap.
|
|
472 |
const TInt colorDstLinePitch = colorLinePitch * dvdy + colorPixelPitch * dudy;
|
|
473 |
const TInt colorDstPixelPitch = colorLinePitch * dvdx + colorPixelPitch * dudx;
|
|
474 |
|
|
475 |
//
|
|
476 |
// Iterate over destination pixels.
|
|
477 |
//
|
|
478 |
const TInt width = aDstRect.Width();
|
|
479 |
TInt h = aDstRect.Height();
|
|
480 |
while (h-- > 0)
|
|
481 |
{
|
|
482 |
switch (aOperation)
|
|
483 |
{
|
|
484 |
case ECanvasGraphicsItemImageRendering:
|
|
485 |
DoBlitLineForImage(dstAddress, width, colorAddress, colorDstPixelPitch);
|
|
486 |
break;
|
|
487 |
case ECanvasGraphicsItemRGBRendering:
|
|
488 |
DoBlitLineForRgb(dstAddress, width, colorAddress, colorDstPixelPitch);
|
|
489 |
break;
|
|
490 |
}
|
|
491 |
|
|
492 |
dstAddress += dstLinePitch;
|
|
493 |
colorAddress += colorDstLinePitch;
|
|
494 |
}
|
|
495 |
}
|
|
496 |
|
|
497 |
// support for rendering image on CanavsGraphicsItem frame buffer
|
|
498 |
void CLcdGraphicsDeviceImpl::DoBlitLineForImage
|
|
499 |
(
|
|
500 |
TUint8* aDstAddress,
|
|
501 |
TInt aWidth,
|
|
502 |
TUint8* aColorAddress,
|
|
503 |
TInt aColorPixelPitch
|
|
504 |
)
|
|
505 |
{
|
|
506 |
TUint32* dst = (TUint32*)(aDstAddress);
|
|
507 |
TUint32* end = dst + aWidth;
|
|
508 |
|
|
509 |
TUint8* colorAddr = aColorAddress;
|
|
510 |
|
|
511 |
while (dst < end)
|
|
512 |
{
|
|
513 |
TUint32 dstColor = *dst;
|
|
514 |
TUint32 srcColor = *(TUint32*)colorAddr;
|
|
515 |
|
|
516 |
TUint32 mask = (TUint32)(((TInt32)srcColor) >> 24); // Sign extend down.
|
|
517 |
|
|
518 |
#ifdef RD_JAVA_NGA_ENABLED
|
|
519 |
if (mask == (TUint32)-1)
|
|
520 |
{
|
|
521 |
// Note that the target is not always opaque anymore
|
|
522 |
dstColor = srcColor;
|
|
523 |
}
|
|
524 |
#else // !RD_JAVA_NGA_ENABLED
|
|
525 |
dstColor = (dstColor & ~mask) | (srcColor & mask);
|
|
526 |
#endif // RD_JAVA_NGA_ENABLED
|
|
527 |
|
|
528 |
*dst++ = dstColor;
|
|
529 |
colorAddr += aColorPixelPitch;
|
|
530 |
}
|
|
531 |
}
|
|
532 |
|
|
533 |
// support for rendering image on CanavsGraphicsItem frame buffer
|
|
534 |
void CLcdGraphicsDeviceImpl::DoBlitLineForRgb
|
|
535 |
(
|
|
536 |
TUint8* aDstAddress,
|
|
537 |
TInt aWidth,
|
|
538 |
TUint8* aColorAddress,
|
|
539 |
TInt aColorPixelPitch
|
|
540 |
)
|
|
541 |
{
|
|
542 |
TUint32* dstAddress = (TUint32*)(aDstAddress);
|
|
543 |
TUint32* end = dstAddress + aWidth;
|
|
544 |
|
|
545 |
TUint8* srcAddress = aColorAddress;
|
|
546 |
|
|
547 |
while (dstAddress < end)
|
|
548 |
{
|
|
549 |
const TUint32 src=*(TUint32*)srcAddress;
|
|
550 |
|
|
551 |
if (src >= 0xFF000000)
|
|
552 |
{
|
|
553 |
*(TUint32*)dstAddress = src;
|
|
554 |
}
|
|
555 |
else
|
|
556 |
{
|
|
557 |
const TUint32 srcAlpha = src >> 24;
|
|
558 |
|
|
559 |
if (srcAlpha)
|
|
560 |
{
|
|
561 |
TUint32 destA;
|
|
562 |
TUint32 destAG;
|
|
563 |
TUint32 destRB;
|
|
564 |
TUint32 destMultAlpha;
|
|
565 |
|
|
566 |
const TUint32 dst = *(TUint32*)dstAddress;
|
|
567 |
const TUint32 dstAlpha = dst >> 24;
|
|
568 |
|
|
569 |
destA = dstAlpha << 16;
|
|
570 |
destA = destA * (0x100 - srcAlpha);
|
|
571 |
destA += srcAlpha << 24;
|
|
572 |
destMultAlpha = (((0x100 - srcAlpha) * dstAlpha) >> 8) + 1;
|
|
573 |
|
|
574 |
const TUint32 srcPixel = *(TUint32*)srcAddress;
|
|
575 |
const TUint32 dstPixel = *(TUint32*)dstAddress;
|
|
576 |
|
|
577 |
destAG = (dstPixel & 0xFF00FF00) >> 8;
|
|
578 |
destAG = destAG * destMultAlpha;
|
|
579 |
TUint32 srcAG = (srcPixel & 0xFF00FF00) >> 8;
|
|
580 |
destAG &= 0xFF00FF00;
|
|
581 |
TUint32 alphaPlus1 = srcAlpha + 1;
|
|
582 |
destAG += srcAG * alphaPlus1;
|
|
583 |
|
|
584 |
destRB = dstPixel & 0x00FF00FF;
|
|
585 |
destRB = destRB * destMultAlpha;
|
|
586 |
destRB &= 0xFF00FF00;
|
|
587 |
TUint32 srcRB = (srcPixel & 0x00FF00FF);
|
|
588 |
destRB += srcRB * alphaPlus1;
|
|
589 |
destRB >>= 8;
|
|
590 |
|
|
591 |
*(TUint32*)dstAddress = (destAG & 0x0000FF00) |
|
|
592 |
(destRB & 0x00FF00FF) |
|
|
593 |
(destA & 0xFF000000);
|
|
594 |
}
|
|
595 |
}
|
|
596 |
|
|
597 |
dstAddress++;
|
|
598 |
srcAddress += aColorPixelPitch;
|
|
599 |
} // while( dstAddress < end )
|
|
600 |
}
|
|
601 |
|
|
602 |
CRenderFunctions::~CRenderFunctions()
|
|
603 |
{
|
|
604 |
iEntries.Reset();
|
|
605 |
iEntries.Close();
|
|
606 |
}
|
|
607 |
|
|
608 |
const TImageRenderer* CRenderFunctions::Get(const TRenderKey& aKey)
|
|
609 |
{
|
|
610 |
if (iLast && (iLast->iKey == aKey))
|
|
611 |
{
|
|
612 |
return &(iLast->iRenderer);
|
|
613 |
}
|
|
614 |
const TInt count = iEntries.Count();
|
|
615 |
for (TInt index=0; index<count; ++index)
|
|
616 |
{
|
|
617 |
const TRenderEntry& entry = iEntries[index];
|
|
618 |
if (entry.iKey.Match(aKey))
|
|
619 |
{
|
|
620 |
if (entry.iKey.iTransform == (1<<ETransNone))
|
|
621 |
{
|
|
622 |
// only cache no-trans variants.
|
|
623 |
iLast = &entry;
|
|
624 |
}
|
|
625 |
return &entry.iRenderer;
|
|
626 |
}
|
|
627 |
}
|
|
628 |
return NULL;
|
|
629 |
}
|
|
630 |
|
|
631 |
void CRenderFunctions::AppendL(const TImageRenderer& aRenderer)
|
|
632 |
{
|
|
633 |
TRenderEntry entry;
|
|
634 |
entry.iKey.iTargetType = aRenderer.iTargetType;
|
|
635 |
entry.iKey.iSourceType = aRenderer.iSourceType;
|
|
636 |
entry.iKey.iTransform = aRenderer.iTransformMask;
|
|
637 |
entry.iKey.iComposite = aRenderer.iCompositeRule;
|
|
638 |
entry.iRenderer = aRenderer;
|
|
639 |
iEntries.AppendL(entry);
|
|
640 |
}
|