|
1 /* |
|
2 * Copyright (c) 2002 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: Graphics Extension Library source file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "Gfx2dGcOpenVG.h" |
|
20 //#include "Gfx2dDevice.h" |
|
21 #include "GfxLine2D.h" |
|
22 #include "GfxStroke.h" |
|
23 #include "GfxGeneralPath.h" |
|
24 #include "GfxFlatteningPathIterator.h" |
|
25 #include "GfxColor.h" |
|
26 #include "GfxImageTransformer.h" |
|
27 //#include "hal.h" |
|
28 //#include "hal_data.h" |
|
29 |
|
30 #include "gdi.h" |
|
31 #include "biditext.h" |
|
32 |
|
33 #include "GfxFloatFixPt.h" |
|
34 #include "GfxShape.h" |
|
35 #include "GfxEllipse2D.h" |
|
36 #include "GfxRoundRectangle2D.h" |
|
37 //#include "svgBackendStd.h" |
|
38 //#include "gulutil.h" |
|
39 #include <AknFontAccess.h> |
|
40 //#include <AknUtils.h> |
|
41 //#include <featmgr.h> |
|
42 #include<e32cmn.h> |
|
43 #include<e32uid.h>//NGA |
|
44 #include <e32math.h> |
|
45 // OpenVG Includes |
|
46 #include <VG/vgu.h> |
|
47 #include <vg/vgcontext.h> |
|
48 // OpenVG API Binding Symbian specific |
|
49 #include <vg/vgcontext_symbian.h> |
|
50 |
|
51 // For allocating path segment type array |
|
52 // Found 130 to be max size at bootup |
|
53 const TInt KPathSegmentTypeInitialSize = 130; |
|
54 const TInt KPathSegmentTypeMaxSize = 1000; |
|
55 |
|
56 const TInt KRenderQualityLow = 1; |
|
57 const TInt KRenderQualityHigh = 2; |
|
58 _LIT( KDefaultFont, "serif" ); // Similar changes should be applied to \ |
|
59 //SvgTextElementImpl.cpp file |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // CGfx2dGcOpenVG::CGfx2dGcOpenVG() : iScale( 1 ), |
|
63 // --------------------------------------------------------------------------- |
|
64 CGfx2dGcOpenVG::CGfx2dGcOpenVG( TBool /* aIsMainContext */ ) : |
|
65 iFillOpacity( 1 ), |
|
66 iScale( 1 ), |
|
67 iStrokeColor( 0 ), |
|
68 iStrokeOpacity( 1 ), |
|
69 iBackgroundColor( 0xffffff ), |
|
70 iFontSize( 10 ), |
|
71 iFontWeight( -1 ), |
|
72 iFontStyle( -1 ), |
|
73 iFamilies( NULL ), |
|
74 iTextAnchor( EGfxTextAnchorNone ), |
|
75 iTextDecoration( EGfxTextDecorationNone ), |
|
76 iGraphicsContextCreated( EFalse ), |
|
77 iRenderQuality(VG_RENDERING_QUALITY_BETTER), |
|
78 iCurrentRendererType(ESVGRendererSW) |
|
79 |
|
80 { |
|
81 } |
|
82 // |
|
83 // ========================================================================== |
|
84 // Create a new instance. |
|
85 // ========================================================================== |
|
86 // -------------------------------------------------------------------------- |
|
87 // CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec ) |
|
88 // --------------------------------------------------------------------------- |
|
89 CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider, TBool aIsMainContext ) |
|
90 { |
|
91 CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aIsMainContext ); |
|
92 CleanupStack::PushL( self ); |
|
93 self->ConstructL( aBufferSize, aFontSpec, aSvgBitmapFontProvider); |
|
94 CleanupStack::Pop(); |
|
95 return self; |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // void CGfx2dGcOpenVG::ConstructL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec ) |
|
100 // --------------------------------------------------------------------------- |
|
101 void CGfx2dGcOpenVG::ConstructL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider ) |
|
102 { |
|
103 /* iApacAvailable = EFalse; |
|
104 FeatureManager::InitializeLibL(); |
|
105 iApacAvailable = ( AknLayoutUtils::Variant() == EApacVariant ); |
|
106 FeatureManager::UnInitializeLib();*/ |
|
107 |
|
108 |
|
109 iFontSpec = aFontSpec; |
|
110 |
|
111 if (iFontSpec.iTypeface.iName.Length() == 0) |
|
112 { |
|
113 //just for a safety check in case client didnt put it in |
|
114 iFontSpec = TFontSpec(KDefaultFont, 100); |
|
115 } |
|
116 |
|
117 |
|
118 iSvgBitmapFontProvider = aSvgBitmapFontProvider ; |
|
119 |
|
120 // Allocate path segment type array |
|
121 iPathSegmentTypeCount = KPathSegmentTypeInitialSize; |
|
122 iPathSegmentTypes = new (ELeave) VGubyte[KPathSegmentTypeInitialSize]; |
|
123 |
|
124 iDashArray = new ( ELeave ) CArrayFixFlat<VGfloat>( 32 ); |
|
125 |
|
126 iVgRenderer = CVGRenderer::NewL(ESVGRendererSW, 0); |
|
127 iVgSurface = iVgRenderer->GetCurrentSurface(); |
|
128 ChangeBufferSizeL( aBufferSize ); |
|
129 } |
|
130 //NGA |
|
131 // -------------------------------------------------------------------------- |
|
132 // CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec ) |
|
133 // --------------------------------------------------------------------------- |
|
134 CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType,TBool aIsMainContext ) |
|
135 { |
|
136 CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aIsMainContext ); |
|
137 CleanupStack::PushL( self ); |
|
138 self->ConstructL( aBufferSize, aFontSpec, aSvgBitmapFontProvider,aRendererType); |
|
139 CleanupStack::Pop(); |
|
140 return self; |
|
141 } |
|
142 //NGA |
|
143 // -------------------------------------------------------------------------- |
|
144 // void CGfx2dGcOpenVG::ConstructL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec ) |
|
145 // --------------------------------------------------------------------------- |
|
146 void CGfx2dGcOpenVG::ConstructL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType ) |
|
147 { |
|
148 |
|
149 iFontSpec = aFontSpec; |
|
150 |
|
151 if (iFontSpec.iTypeface.iName.Length() == 0) |
|
152 { |
|
153 //just for a safety check in case client didnt put it in |
|
154 iFontSpec = TFontSpec(KDefaultFont, 100); |
|
155 } |
|
156 iSvgBitmapFontProvider = aSvgBitmapFontProvider ; |
|
157 |
|
158 // Allocate path segment type array |
|
159 iPathSegmentTypeCount = KPathSegmentTypeInitialSize; |
|
160 iPathSegmentTypes = new (ELeave) VGubyte[KPathSegmentTypeInitialSize]; |
|
161 |
|
162 iDashArray = new ( ELeave ) CArrayFixFlat<VGfloat>( 32 ); |
|
163 iCurrentRendererType = aRendererType; |
|
164 iVgRenderer = CVGRenderer::NewL(aRendererType, 0); |
|
165 iVgSurface = iVgRenderer->GetCurrentSurface(); |
|
166 |
|
167 iVgSurface->InitializeSurface( aBufferSize, VGI_COLORSPACE_SRGB ); |
|
168 iVgSurface->CreateSurface(EColor16MA, 0, 0); |
|
169 |
|
170 ChangeBufferSizeL( aBufferSize ); |
|
171 |
|
172 } |
|
173 // ========================================================================== |
|
174 // Destructor. |
|
175 // ========================================================================== |
|
176 // -------------------------------------------------------------------------- |
|
177 // CGfx2dGcOpenVG::~CGfx2dGcOpenVG() |
|
178 // --------------------------------------------------------------------------- |
|
179 CGfx2dGcOpenVG::~CGfx2dGcOpenVG() |
|
180 { |
|
181 if ( iDashArray ) |
|
182 { |
|
183 delete iDashArray; |
|
184 iDashArray = NULL; |
|
185 } |
|
186 |
|
187 // This is no longer needed, the Font is owned by TextElement |
|
188 // now as each text element may have its own specific font |
|
189 // and keeping one copy at Gc level will not work. |
|
190 // Gc is just refering to the Font from Textelement, so |
|
191 // now need to free it here. |
|
192 // |
|
193 //if (iFont && iWsScreenDevice) |
|
194 // { |
|
195 // iWsScreenDevice->ReleaseFont(iFont); |
|
196 // iFont = NULL; |
|
197 // } |
|
198 |
|
199 |
|
200 DestroyContext(); |
|
201 |
|
202 iGroupOpacityImages.Close(); |
|
203 |
|
204 TInt bufferCount = iGroupOpacityBuffers.Count(); |
|
205 for ( TInt i = 0; i < bufferCount; i++ ) |
|
206 { |
|
207 delete [] iGroupOpacityBuffers[i]; |
|
208 } |
|
209 iGroupOpacityBuffers.Close(); |
|
210 |
|
211 if ( iPathSegmentTypes ) |
|
212 { |
|
213 delete [] iPathSegmentTypes; |
|
214 } |
|
215 delete iVgRenderer; |
|
216 |
|
217 } |
|
218 |
|
219 // private method |
|
220 void CGfx2dGcOpenVG::DestroyContext() |
|
221 { |
|
222 if ( iGraphicsContextCreated ) |
|
223 { |
|
224 // Destroy OpenVG context |
|
225 iVgSurface->TerminateSurface(); |
|
226 ResetContextHandle(); |
|
227 iFillOpacity = 1; |
|
228 iScale = 1; |
|
229 iStrokeOpacity = 1; |
|
230 } |
|
231 } |
|
232 |
|
233 // -------------------------------------------------------------------------- |
|
234 // void CGfx2dGcOpenVG::SetFrameBufferL( CFbsBitmap* aFrameBuffer ) |
|
235 // --------------------------------------------------------------------------- |
|
236 void CGfx2dGcOpenVG::ChangeBufferSizeL( const TSize aBufferSize ) |
|
237 { |
|
238 if ( aBufferSize.iWidth <= 0 || aBufferSize.iHeight <= 0 || aBufferSize == iColorBufferSize ) |
|
239 { |
|
240 return; |
|
241 } |
|
242 |
|
243 iColorBufferSize = aBufferSize; |
|
244 |
|
245 // First time: creating OpenVG context |
|
246 if( !iGraphicsContextCreated ) |
|
247 { |
|
248 // Create OpenVG context |
|
249 TInt err = iVgSurface->InitializeSurface( iColorBufferSize, VGI_COLORSPACE_SRGB ); |
|
250 if (!((err == KErrNone) || (err == KErrAlreadyExists))) |
|
251 { |
|
252 #ifdef _DEBUG |
|
253 RDebug::Printf("SVG can't initialize OpenVG Context %d", err); |
|
254 #endif //_DEBUG |
|
255 iGraphicsContextCreated = EFalse; |
|
256 User::Leave(err); |
|
257 } |
|
258 iGraphicsContextCreated = ETrue; |
|
259 // By default the Rendering quality is VG_RENDERING_QUALITY_BETTER |
|
260 iVgRenderer->vgSeti( VG_RENDERING_QUALITY, iRenderQuality ); |
|
261 } |
|
262 // Only need to update context with color-buffer info |
|
263 // when frame buffer size changes |
|
264 else |
|
265 { |
|
266 TInt err = iVgSurface->ResizeSurface( iColorBufferSize ); |
|
267 |
|
268 if( err != KErrNone ) |
|
269 { |
|
270 if(err == KErrNoMemory ) |
|
271 { |
|
272 #ifdef _DEBUG |
|
273 RDebug::Printf("OpenVG Context destroyed %d", err); |
|
274 #endif //_DEBUG |
|
275 // This indicates that OpenVG has destroyed the current context handle |
|
276 // and also the Path, StrokePaint and FillPaint handles are no more valid. |
|
277 // Thus reinitialize them to 0, so that they can be recreated. |
|
278 ResetContextHandle(); |
|
279 } |
|
280 |
|
281 #ifdef _DEBUG |
|
282 RDebug::Printf("SVG can't RESIZE OpenVG Context %d", err); |
|
283 #endif //_DEBUG |
|
284 User::Leave(err); |
|
285 } |
|
286 } |
|
287 |
|
288 iRenderInfo.SetDevice( 0, /*this parameter will be ignored */ |
|
289 iColorBufferSize.iWidth, |
|
290 iColorBufferSize.iHeight, |
|
291 0 /*this parameter will be ignored */); |
|
292 } |
|
293 |
|
294 // -------------------------------------------------------------------------- |
|
295 // TInt CGfx2dGcOpenVG::OpenVGErrorToSymbianError( int aError ) |
|
296 // --------------------------------------------------------------------------- |
|
297 TInt CGfx2dGcOpenVG::OpenVGErrorToSymbianError( TInt aError ) |
|
298 { |
|
299 TInt error = KErrNone; |
|
300 switch( aError ) |
|
301 { |
|
302 case VGI_OK: |
|
303 { |
|
304 error = KErrNone; |
|
305 break; |
|
306 } |
|
307 |
|
308 case VGU_OUT_OF_MEMORY_ERROR: |
|
309 case VG_OUT_OF_MEMORY_ERROR: |
|
310 case VGI_ERROR_OUT_OF_MEMORY: |
|
311 { |
|
312 error = KErrNoMemory; |
|
313 break; |
|
314 } |
|
315 |
|
316 case VG_ILLEGAL_ARGUMENT_ERROR: |
|
317 case VGI_ERROR_INVALID_ARGUMENTS: |
|
318 case VGU_ILLEGAL_ARGUMENT_ERROR: |
|
319 { |
|
320 error = KErrArgument; |
|
321 break; |
|
322 } |
|
323 |
|
324 case VGI_ERROR_ALREADY_EXISTS: |
|
325 { |
|
326 error = KErrAlreadyExists; |
|
327 break; |
|
328 } |
|
329 |
|
330 case VG_UNSUPPORTED_PATH_FORMAT_ERROR: |
|
331 case VGI_ERROR_COLORSPACE_NOT_SUPPORTED: |
|
332 case VG_UNSUPPORTED_IMAGE_FORMAT_ERROR: |
|
333 case VGI_ERROR_NOT_SUPPORTED: |
|
334 { |
|
335 error = KErrNotSupported; |
|
336 break; |
|
337 } |
|
338 |
|
339 case VGI_ERROR_ILLEGAL_IMAGE_HANDLE: |
|
340 { |
|
341 error = KErrBadHandle; |
|
342 break; |
|
343 } |
|
344 |
|
345 case VG_IMAGE_IN_USE_ERROR: |
|
346 case VGI_ERROR_IMAGE_IN_USE: |
|
347 { |
|
348 error = KErrInUse; |
|
349 break; |
|
350 } |
|
351 |
|
352 case VGI_ERROR_ILLEGAL_OPERATION: |
|
353 { |
|
354 error = KErrPermissionDenied; |
|
355 break; |
|
356 } |
|
357 |
|
358 case VG_BAD_HANDLE_ERROR: |
|
359 case VG_PATH_CAPABILITY_ERROR: |
|
360 case VGU_PATH_CAPABILITY_ERROR: |
|
361 case VGU_BAD_WARP_ERROR: |
|
362 case VGU_BAD_HANDLE_ERROR: |
|
363 { |
|
364 error = KErrUnknown; |
|
365 break; |
|
366 } |
|
367 |
|
368 default: |
|
369 { |
|
370 error = KErrUnknown; |
|
371 } |
|
372 } |
|
373 |
|
374 return error; |
|
375 } |
|
376 // -------------------------------------------------------------------------- |
|
377 // void CGfx2dGcOpenVG::DoDrawL( MGfxShape* aShape ) |
|
378 // --------------------------------------------------------------------------- |
|
379 void CGfx2dGcOpenVG::DoDrawL( MGfxShape* aShape ) |
|
380 { |
|
381 VGbitfield drawMode = 0x0; |
|
382 VGUErrorCode vguret; |
|
383 |
|
384 // Do not render if both stroke and fill are none |
|
385 if ( iStrokeColor.GetARGB() == KGfxColorNull && iFillColor == NULL ) |
|
386 return; |
|
387 |
|
388 iVgRenderer->vgSeti( VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE ); |
|
389 |
|
390 if ( !iPath ) |
|
391 { |
|
392 const float KScale = 1.0f / 65536.0f; |
|
393 iPath = iVgRenderer->vgCreatePath( VG_PATH_FORMAT_STANDARD, |
|
394 VG_PATH_DATATYPE_S_32, KScale, 0.0f, 0, 0, |
|
395 VG_PATH_CAPABILITY_APPEND_TO ); |
|
396 if ( iPath == VG_INVALID_HANDLE ) |
|
397 { |
|
398 VGErrorCode error = (VGErrorCode)iVgRenderer->vgGetError(); |
|
399 if (error == VG_OUT_OF_MEMORY_ERROR) |
|
400 { |
|
401 #ifdef _DEBUG |
|
402 RDebug::Printf("OOM: vgCreatePath"); |
|
403 #endif |
|
404 User::Leave(KErrNoMemory); |
|
405 } |
|
406 // handle other errors... |
|
407 #ifdef _DEBUG |
|
408 RDebug::Printf("SVG GFX2D Error: vgCreatePath"); |
|
409 #endif |
|
410 } |
|
411 } |
|
412 |
|
413 if (iFillColor) |
|
414 { |
|
415 if(!iFillPaint) |
|
416 { |
|
417 iFillPaint = iVgRenderer->vgCreatePaint(); |
|
418 if ( iFillPaint == VG_INVALID_HANDLE ) |
|
419 { |
|
420 VGErrorCode error = (VGErrorCode)iVgRenderer->vgGetError(); |
|
421 if (error == VG_OUT_OF_MEMORY_ERROR) |
|
422 { |
|
423 RDebug::Printf("SVG GFX2D Error OOMs: vgCreatePaint"); |
|
424 User::Leave(KErrNoMemory); |
|
425 } |
|
426 // handle other errors... |
|
427 #ifdef _DEBUG |
|
428 RDebug::Printf("SVG GFX2D Error: vgCreatePaint"); |
|
429 #endif |
|
430 } |
|
431 } |
|
432 } |
|
433 |
|
434 if(iStrokeColor.GetARGB() != KGfxColorNull) |
|
435 { |
|
436 if(!iStrokePaint) |
|
437 { |
|
438 iStrokePaint = iVgRenderer->vgCreatePaint(); |
|
439 if ( iStrokePaint == VG_INVALID_HANDLE ) |
|
440 { |
|
441 VGErrorCode error = (VGErrorCode)iVgRenderer->vgGetError(); |
|
442 if (error == VG_OUT_OF_MEMORY_ERROR) |
|
443 { |
|
444 RDebug::Printf("SVGT CGfx2dGcOpenVG::DoDrawL vgCreatePaint OOM"); |
|
445 User::Leave(KErrNoMemory); |
|
446 } |
|
447 #ifdef _DEBUG |
|
448 RDebug::Printf("SVGT CGfx2dGcOpenVG::DoDrawL vgCreatePaint failed %d", error); |
|
449 #endif |
|
450 } |
|
451 } |
|
452 } |
|
453 |
|
454 TGfxRectangle2D bbRect; |
|
455 TGfxAffineTransform identityMat; |
|
456 |
|
457 //vgClear( 0, 0, VG_MAXINT, VG_MAXINT ); |
|
458 switch(aShape->ShapeType()) |
|
459 { |
|
460 case MGfxShape::ERect: |
|
461 { |
|
462 TGfxRectangle2D* rect = (TGfxRectangle2D*)aShape; |
|
463 |
|
464 rect->GetBounds( identityMat, bbRect ); |
|
465 drawMode = SetFillStroke(iFillPaint, iStrokePaint, bbRect); |
|
466 |
|
467 vguret = (VGUErrorCode)iVgRenderer->vguRect( |
|
468 iPath, |
|
469 (VGfloat)rect->iX, |
|
470 (VGfloat)rect->iY, |
|
471 (VGfloat)rect->iWidth, |
|
472 (VGfloat)rect->iHeight ); |
|
473 |
|
474 if( vguret != KErrNone ) |
|
475 { |
|
476 User::LeaveIfError(OpenVGErrorToSymbianError(vguret)); |
|
477 } |
|
478 iVgRenderer->vgDrawPath( iPath, drawMode ); |
|
479 } |
|
480 break; |
|
481 |
|
482 case MGfxShape::ERoundRect: |
|
483 { |
|
484 float rx, ry; |
|
485 TGfxRoundRectangle2D* rect = (TGfxRoundRectangle2D*)aShape; |
|
486 |
|
487 TFloatFixPt tWidth = rect->iArcWidth; |
|
488 TFloatFixPt tHeight = rect->iArcHeight; |
|
489 |
|
490 tWidth.iValue <<= 1; |
|
491 tHeight.iValue <<= 1; |
|
492 |
|
493 rx = (VGfloat)tWidth; |
|
494 ry = (VGfloat)tHeight; |
|
495 |
|
496 //If a properly specified value is provided for ry but not for rx, |
|
497 // then the user agent must process the 'rect' element with the |
|
498 // effective value for rx as equal to ry. However clamp to 0. |
|
499 if ( rx <= 0 ) |
|
500 { |
|
501 rx = ry; |
|
502 } |
|
503 if ( ry <= 0) |
|
504 { |
|
505 ry = rx; |
|
506 } |
|
507 |
|
508 if(rx < 0) |
|
509 { |
|
510 rx = 0; |
|
511 } |
|
512 if(ry < 0) |
|
513 { |
|
514 ry = 0; |
|
515 } |
|
516 |
|
517 rect->GetBounds( identityMat, bbRect ); |
|
518 drawMode = SetFillStroke(iFillPaint, iStrokePaint, bbRect); |
|
519 |
|
520 // Rounded rectangle |
|
521 if ( rx == 0.0f && ry == 0.0f ) |
|
522 { |
|
523 vguret = (VGUErrorCode)iVgRenderer->vguRect(iPath, |
|
524 (VGfloat)rect->iX, (VGfloat)rect->iY, |
|
525 (VGfloat)rect->iWidth, (VGfloat)rect->iHeight ); |
|
526 } |
|
527 else |
|
528 { |
|
529 vguret = (VGUErrorCode)iVgRenderer->vguRoundRect( iPath, |
|
530 (VGfloat)rect->iX, (VGfloat)rect->iY, |
|
531 (VGfloat)rect->iWidth, (VGfloat)rect->iHeight, |
|
532 rx, ry ); |
|
533 } |
|
534 if( vguret != KErrNone ) |
|
535 { |
|
536 User::LeaveIfError(OpenVGErrorToSymbianError(vguret)); |
|
537 } |
|
538 iVgRenderer->vgDrawPath( iPath, drawMode ); |
|
539 } |
|
540 break; |
|
541 |
|
542 case MGfxShape::EEllipse: |
|
543 { |
|
544 TGfxEllipse2D* ellipse = (TGfxEllipse2D*)aShape; |
|
545 #ifdef SVG_FLOAT_BUILD |
|
546 TFloatFixPt rx = ellipse->iWidth * TFloatFixPt(.5f); |
|
547 TFloatFixPt ry = ellipse->iHeight * TFloatFixPt(.5f); |
|
548 #else |
|
549 TFloatFixPt rx = ellipse->iWidth >> 1; // rx = width / 2 |
|
550 TFloatFixPt ry = ellipse->iHeight >> 1; // ry = height / 2 |
|
551 #endif |
|
552 ellipse->GetBounds( identityMat, bbRect ); |
|
553 drawMode = SetFillStroke(iFillPaint, iStrokePaint, bbRect); |
|
554 |
|
555 // Element |
|
556 vguret = (VGUErrorCode)iVgRenderer->vguEllipse(iPath, |
|
557 (VGfloat)(ellipse->iX + rx), |
|
558 (VGfloat)(ellipse->iY + ry), |
|
559 (VGfloat)ellipse->iWidth, |
|
560 (VGfloat)ellipse->iHeight); |
|
561 if( vguret != KErrNone ) |
|
562 { |
|
563 User::LeaveIfError(OpenVGErrorToSymbianError(vguret)); |
|
564 } |
|
565 iVgRenderer->vgDrawPath(iPath,drawMode); |
|
566 } |
|
567 break; |
|
568 |
|
569 |
|
570 case MGfxShape::EPath: |
|
571 { |
|
572 CGfxGeneralPath* gPath = (CGfxGeneralPath*)aShape; |
|
573 RArray<TFloatFixPt>* coordArray = gPath->PointCoordsArrayAll(); |
|
574 if (coordArray->Count() > 0) |
|
575 { |
|
576 TFloatFixPt* coord = gPath->PointCoordsArray(); |
|
577 TUint8 count = gPath->Count(); |
|
578 RArray<TUint32>* type = gPath->PointTypeArray(); |
|
579 TInt typeCount = type->Count(); |
|
580 if(count && ( typeCount == count)) |
|
581 { |
|
582 iVgRenderer->vgAppendPathData(iPath, count,gPath->PathSegmentTypeArray(),coord); |
|
583 } |
|
584 else |
|
585 { |
|
586 //RArray<TUint32>* type = gPath->PointTypeArray(); |
|
587 //TInt typeCount = type->Count(); |
|
588 // this is a multi path |
|
589 // Using non-ELeave version and checking for NULL to avoid (ELeave) and TRAP |
|
590 if ( iPathSegmentTypeCount < typeCount ) |
|
591 { |
|
592 if ( iPathSegmentTypes ) |
|
593 { |
|
594 delete [] iPathSegmentTypes; |
|
595 iPathSegmentTypes = NULL; |
|
596 } |
|
597 iPathSegmentTypes = new VGubyte[typeCount]; |
|
598 iPathSegmentTypeCount = typeCount; |
|
599 } |
|
600 if ( !iPathSegmentTypes ) |
|
601 { |
|
602 break; |
|
603 } |
|
604 for (TInt i=0; i < typeCount; i++) |
|
605 { |
|
606 iPathSegmentTypes[i] = (TGfxSegType) (*type)[i]; |
|
607 } |
|
608 iVgRenderer->vgAppendPathData(iPath, typeCount, iPathSegmentTypes, coord); |
|
609 } |
|
610 gPath->GetBounds( identityMat, bbRect ); |
|
611 drawMode = SetFillStroke(iFillPaint, iStrokePaint, bbRect); |
|
612 iVgRenderer->vgDrawPath(iPath,drawMode); |
|
613 } |
|
614 } |
|
615 break; |
|
616 |
|
617 case MGfxShape::ELine: |
|
618 { |
|
619 TGfxLine2D* line = (TGfxLine2D*)aShape; |
|
620 |
|
621 // Force Stroke color... if not present |
|
622 if(iFillColor && iStrokeColor.GetARGB() == KGfxColorNull) |
|
623 { |
|
624 iStrokeColor = iFillColor->GetColor(); |
|
625 } |
|
626 |
|
627 line->GetBounds( identityMat, bbRect ); |
|
628 drawMode = SetFillStroke(iFillPaint, iStrokePaint, bbRect); |
|
629 |
|
630 vguret = (VGUErrorCode)iVgRenderer->vguLine( |
|
631 iPath, |
|
632 (VGfloat)line->iX1, |
|
633 (VGfloat)line->iY1, |
|
634 (VGfloat)line->iX2, |
|
635 (VGfloat)line->iY2); |
|
636 |
|
637 if( vguret != KErrNone ) |
|
638 { |
|
639 User::LeaveIfError(OpenVGErrorToSymbianError(vguret)); |
|
640 } |
|
641 |
|
642 iVgRenderer->vgDrawPath(iPath,drawMode); |
|
643 } |
|
644 break; |
|
645 } |
|
646 iVgRenderer->vgClearPath( iPath, VG_PATH_CAPABILITY_APPEND_TO ); |
|
647 |
|
648 // Delete path segment type array to avoid large memory to persist, |
|
649 // created by some content, but the larget size is not needed later. |
|
650 if ( iPathSegmentTypeCount > KPathSegmentTypeMaxSize ) |
|
651 { |
|
652 if ( iPathSegmentTypes ) |
|
653 { |
|
654 delete [] iPathSegmentTypes; |
|
655 iPathSegmentTypes = NULL; |
|
656 iPathSegmentTypeCount = 0; |
|
657 } |
|
658 } |
|
659 |
|
660 // Turn off any settings that are not needed by default |
|
661 PostDraw(); |
|
662 } |
|
663 |
|
664 void CGfx2dGcOpenVG::PostDraw() |
|
665 { |
|
666 if ( iDashArray && iDashArray->Count() > 0 ) |
|
667 { |
|
668 iVgRenderer->vgSetfv(VG_STROKE_DASH_PATTERN, 0, NULL); |
|
669 iDashArray->Reset(); |
|
670 } |
|
671 } |
|
672 |
|
673 // -------------------------------------------------------------------------- |
|
674 // VGbitfield CGfx2dGcOpenVG::SetFillStroke(VGPaint aFillPaint, VGPaint aStrokePaint, TGfxRectangle2D& bBox) |
|
675 // --------------------------------------------------------------------------- |
|
676 VGbitfield CGfx2dGcOpenVG::SetFillStroke(VGPaint aFillPaint, VGPaint aStrokePaint, TGfxRectangle2D& bBox) |
|
677 { |
|
678 VGbitfield returnVal = 0x0; |
|
679 |
|
680 // Fill Color |
|
681 if (iFillColor) |
|
682 { |
|
683 if( aFillPaint != VG_INVALID_HANDLE ) |
|
684 { |
|
685 iFillColor->SetFill(aFillPaint, bBox, iFillOpacity, iVgRenderer); |
|
686 returnVal |= VG_FILL_PATH; |
|
687 } |
|
688 } |
|
689 |
|
690 // |
|
691 // Color Correction for Symbian->OpenVG |
|
692 // Symbian argb |
|
693 // OpenVg rgba |
|
694 // |
|
695 // Stroke |
|
696 // |
|
697 if( iStrokeColor.GetARGB() != KGfxColorNull && iStrokeColor.GetARGB() != 0x1ffffff ) |
|
698 { |
|
699 iVgRenderer->vgSetf( VG_STROKE_LINE_WIDTH, (VGfloat)iStroke.StrokeWidth() ); |
|
700 |
|
701 //SET LINECAP INFORMATION |
|
702 SVGLineCap lineCap = (SVGLineCap)iStroke.StrokeCap(); |
|
703 |
|
704 if (lineCap == SVG_CAP_ROUND) |
|
705 { |
|
706 iVgRenderer->vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_ROUND); |
|
707 } |
|
708 else if ( lineCap == SVG_CAP_SQUARE ) |
|
709 { |
|
710 iVgRenderer->vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_SQUARE); |
|
711 } |
|
712 else |
|
713 { |
|
714 iVgRenderer->vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_BUTT); |
|
715 } |
|
716 |
|
717 //SET LINEJOIN INFORMATION |
|
718 SVGLineJoin linejoin = (SVGLineJoin)iStroke.StrokeJoin(); |
|
719 if (linejoin == SVG_JOIN_ROUND) |
|
720 { |
|
721 iVgRenderer->vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); |
|
722 } |
|
723 else if (linejoin == SVG_JOIN_BEVEL) |
|
724 { |
|
725 iVgRenderer->vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); |
|
726 } |
|
727 else |
|
728 { |
|
729 iVgRenderer->vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_MITER); |
|
730 } |
|
731 |
|
732 iVgRenderer->vgSetf( VG_STROKE_MITER_LIMIT, (VGfloat)iStroke.StrokeMiterLimit() ); |
|
733 if(aStrokePaint != VG_INVALID_HANDLE) |
|
734 { |
|
735 iVgRenderer->vgSetParameteri( aStrokePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR ); |
|
736 TUint32 opacity = (TInt)(iStrokeOpacity * TFloatFixPt(255.0f)); |
|
737 iVgRenderer->vgSetColor( aStrokePaint, iStrokeColor.GetARGB() << 8 | opacity ); |
|
738 iVgRenderer->vgSetPaint( aStrokePaint, VG_STROKE_PATH ); |
|
739 returnVal |= VG_STROKE_PATH; |
|
740 } |
|
741 } |
|
742 |
|
743 return returnVal; |
|
744 } |
|
745 |
|
746 // -------------------------------------------------------------------------- |
|
747 // void CGfx2dGcOpenVG::SetWindingRule( TGfxWindingRule aRule ) |
|
748 // --------------------------------------------------------------------------- |
|
749 void CGfx2dGcOpenVG::SetWindingRule( TGfxWindingRule aRule ) |
|
750 { |
|
751 if ( aRule == EGfxWindEvenOdd ) |
|
752 { |
|
753 iVgRenderer->vgSeti(VG_FILL_RULE, VG_EVEN_ODD); |
|
754 } |
|
755 else |
|
756 { |
|
757 iVgRenderer->vgSeti(VG_FILL_RULE, VG_NON_ZERO); |
|
758 } |
|
759 } |
|
760 |
|
761 // -------------------------------------------------------------------------- |
|
762 // void CGfx2dGcOpenVG::Draw( MGfxShape* aShape ) |
|
763 // --------------------------------------------------------------------------- |
|
764 void CGfx2dGcOpenVG::DrawL( MGfxShape* aShape ) |
|
765 { |
|
766 DoDrawL( aShape ); |
|
767 } |
|
768 |
|
769 |
|
770 |
|
771 // -------------------------------------------------------------------------- |
|
772 // TGfxColor CGfx2dGcOpenVG::ForegroundColor() |
|
773 // --------------------------------------------------------------------------- |
|
774 TGfxColor CGfx2dGcOpenVG::ForegroundColor() |
|
775 { |
|
776 return iStrokeColor; |
|
777 } |
|
778 |
|
779 |
|
780 // -------------------------------------------------------------------------- |
|
781 // MGfxPaint* CGfx2dGcOpenVG::Paint() |
|
782 // --------------------------------------------------------------------------- |
|
783 MGfxPaint* CGfx2dGcOpenVG::Paint() |
|
784 { |
|
785 return iFillColor; |
|
786 } |
|
787 |
|
788 // -------------------------------------------------------------------------- |
|
789 // TGfxRenderingHints* CGfx2dGcOpenVG::RenderingHints() |
|
790 // --------------------------------------------------------------------------- |
|
791 TGfxRenderingHints* CGfx2dGcOpenVG::RenderingHints() |
|
792 { |
|
793 //return &iRenderingHints; |
|
794 return NULL; |
|
795 } |
|
796 |
|
797 // -------------------------------------------------------------------------- |
|
798 // TGfxStroke CGfx2dGcOpenVG::Stroke() |
|
799 // --------------------------------------------------------------------------- |
|
800 TGfxStroke CGfx2dGcOpenVG::Stroke() |
|
801 { |
|
802 return iStroke; |
|
803 } |
|
804 |
|
805 |
|
806 |
|
807 // -------------------------------------------------------------------------- |
|
808 // void CGfx2dGcOpenVG::SetDashOffset( TFloatFixPt aDashOffset ) |
|
809 // --------------------------------------------------------------------------- |
|
810 void CGfx2dGcOpenVG::SetDashOffset( TFloatFixPt aDashOffset ) |
|
811 { |
|
812 iDashOffset = aDashOffset; |
|
813 iVgRenderer->vgSetf(VG_STROKE_DASH_PHASE, (VGfloat)iDashOffset); |
|
814 // svgSetStrokeDashOffset(iHyb2dContext, svgScalarFromFloat(iDashOffset)); |
|
815 } |
|
816 |
|
817 |
|
818 // -------------------------------------------------------------------------- |
|
819 // void CGfx2dGcOpenVG::SetForegroundColor( const TGfxColor& aColor ) |
|
820 // --------------------------------------------------------------------------- |
|
821 void CGfx2dGcOpenVG::SetForegroundColor( const TGfxColor& aColor ) |
|
822 { |
|
823 // Both GDI and Gfx2D need to keep color value... |
|
824 iStrokeColor = aColor; |
|
825 } |
|
826 // -------------------------------------------------------------------------- |
|
827 // void CGfx2dGcOpenVG::SetStrokeWidth( const TGfxStroke& aColor ) |
|
828 // --------------------------------------------------------------------------- |
|
829 void CGfx2dGcOpenVG::SetStrokeWidth( const TFloatFixPt& aWidth ) |
|
830 { |
|
831 // Both GDI and Gfx2D need to keep stroke-width value... |
|
832 iStroke.SetStrokeWidth(aWidth); |
|
833 |
|
834 } |
|
835 |
|
836 // -------------------------------------------------------------------------- |
|
837 // void CGfx2dGcOpenVG::SetBackgroundColor( const TGfxColor& aColor ) |
|
838 // --------------------------------------------------------------------------- |
|
839 void CGfx2dGcOpenVG::SetBackgroundColor( const TGfxColor& aColor ) |
|
840 { |
|
841 // Only Gfx2D need to keep background color value. |
|
842 iBackgroundColor = aColor; |
|
843 } |
|
844 |
|
845 // -------------------------------------------------------------------------- |
|
846 // void CGfx2dGcOpenVG::SetPaint( MGfxPaint* aPaint ) |
|
847 // --------------------------------------------------------------------------- |
|
848 void CGfx2dGcOpenVG::SetPaint( MGfxPaint* aPaint ) |
|
849 { |
|
850 iFillColor = aPaint; |
|
851 } |
|
852 |
|
853 // -------------------------------------------------------------------------- |
|
854 // void CGfx2dGcOpenVG::SetStroke( TGfxStroke aStroke ) |
|
855 // --------------------------------------------------------------------------- |
|
856 void CGfx2dGcOpenVG::SetStroke( TGfxStroke aStroke ) |
|
857 { |
|
858 iStroke = aStroke; |
|
859 iVgRenderer->vgSetf( VG_STROKE_LINE_WIDTH, (VGfloat)iStroke.StrokeWidth() ); |
|
860 |
|
861 //SET LINECAP INFORMATION |
|
862 SVGLineCap lineCap = (SVGLineCap)iStroke.StrokeCap(); |
|
863 |
|
864 if (lineCap == SVG_CAP_ROUND) |
|
865 { |
|
866 iVgRenderer->vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_ROUND); |
|
867 } |
|
868 else if ( lineCap == SVG_CAP_SQUARE ) |
|
869 { |
|
870 iVgRenderer->vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_SQUARE); |
|
871 } |
|
872 else |
|
873 { |
|
874 iVgRenderer->vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_BUTT); |
|
875 } |
|
876 |
|
877 //SET LINEJOIN INFORMATION |
|
878 SVGLineJoin linejoin = (SVGLineJoin)iStroke.StrokeJoin(); |
|
879 if (linejoin == SVG_JOIN_ROUND) |
|
880 { |
|
881 iVgRenderer->vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); |
|
882 } |
|
883 else if (linejoin == SVG_JOIN_BEVEL) |
|
884 { |
|
885 iVgRenderer->vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); |
|
886 } |
|
887 else |
|
888 { |
|
889 iVgRenderer->vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_MITER); |
|
890 } |
|
891 |
|
892 iVgRenderer->vgSetf( VG_STROKE_MITER_LIMIT, (VGfloat)iStroke.StrokeMiterLimit() ); |
|
893 |
|
894 } |
|
895 |
|
896 // -------------------------------------------------------------------------- |
|
897 // void CGfx2dGcOpenVG::SetRenderingHints( const TGfxRenderingHints& aRenderingHints ) |
|
898 // --------------------------------------------------------------------------- |
|
899 void CGfx2dGcOpenVG::SetRenderingHints( const TGfxRenderingHints& /*aRenderingHints*/ ) |
|
900 { |
|
901 //iRenderingHints = aRenderingHints; |
|
902 } |
|
903 |
|
904 // -------------------------------------------------------------------------- |
|
905 // void CGfx2dGcOpenVG::SetTransform( const TGfxAffineTransform& aTransform ) |
|
906 // --------------------------------------------------------------------------- |
|
907 void CGfx2dGcOpenVG::SetTransform( const TGfxAffineTransform& aTransform ) |
|
908 { |
|
909 iTransform = aTransform; |
|
910 |
|
911 // Calculate scale |
|
912 TGfxPoint2D ep( 1, 0 ), org( 2, 0 ); |
|
913 iTransform.Transform( &ep, & ep, 1 ); |
|
914 iTransform.Transform( &org, & org, 1 ); |
|
915 ep.iX -= org.iX; |
|
916 ep.iY -= org.iY; |
|
917 iScale = TFloatFixPt::Sqrt( ep.iX * ep.iX + ep.iY * ep.iY ); |
|
918 |
|
919 // activate Graphics 2D engine |
|
920 // set viewport coordinate system to map from canvas coordinates to pixels |
|
921 // in order to provide resolution independent results |
|
922 // SVGMatrix2x3 vmat; |
|
923 // svgMatrix2x3Set( &vmat, |
|
924 // iTransform.iM00.iValue, |
|
925 // iTransform.iM01.iValue, |
|
926 // iTransform.iM02.iValue, |
|
927 // iTransform.iM10.iValue, |
|
928 // iTransform.iM11.iValue, |
|
929 // iTransform.iM12.iValue |
|
930 // ); |
|
931 // svgSetViewportCoordinateSystem( iHyb2dContext, vmat.matrix ); |
|
932 ApplyTransform(iTransform); |
|
933 } |
|
934 |
|
935 // -------------------------------------------------------------------------- |
|
936 // void CGfx2dGcOpenVG::SetClip( const TGfxRectangle2D& aClip ) |
|
937 // --------------------------------------------------------------------------- |
|
938 void CGfx2dGcOpenVG::SetClip( const TGfxRectangle2D& aClip ) |
|
939 { |
|
940 iClip = aClip; |
|
941 TFloatFixPt newY = iColorBufferSize.iHeight - (TInt)aClip.iHeight - (TInt)aClip.iY; |
|
942 VGint clipRect[4] = |
|
943 { |
|
944 (TInt)aClip.iX, (TInt)newY, (TInt)aClip.iWidth, (TInt)aClip.iHeight |
|
945 }; |
|
946 |
|
947 // Set VG_SCISSORING to True |
|
948 iVgRenderer->vgSeti(VG_SCISSORING, VG_TRUE); |
|
949 |
|
950 // Set Clippling rectangle |
|
951 iVgRenderer->vgSetiv(VG_SCISSOR_RECTS, 4,(const TInt*) clipRect); |
|
952 } |
|
953 |
|
954 void CGfx2dGcOpenVG::SetClipMediaElement( TSize aSize ) |
|
955 { |
|
956 TFloatFixPt width = (TFloatFixPt)aSize.iWidth; |
|
957 TFloatFixPt height = (TFloatFixPt)aSize.iHeight; |
|
958 TFloatFixPt x = (TFloatFixPt)0; |
|
959 TFloatFixPt y = (TFloatFixPt)0; |
|
960 TGfxRectangle2D aClip(x,y,width,height); |
|
961 iClipMain = iClip; |
|
962 iClip = aClip; |
|
963 // TFloatFixPt newY = aSize.iHeight - (TInt)aClip.iHeight - (TInt)aClip.iY; |
|
964 VGint clipRect[4] = |
|
965 { |
|
966 (TInt)aClip.iX, (TInt)aClip.iY, (TInt)aClip.iWidth, (TInt)aClip.iHeight |
|
967 }; |
|
968 |
|
969 // Set VG_SCISSORING to True |
|
970 iVgRenderer->vgSeti(VG_SCISSORING, VG_TRUE); |
|
971 |
|
972 // Set Clippling rectangle |
|
973 iVgRenderer->vgSetiv(VG_SCISSOR_RECTS, 4, (const TInt*)clipRect); |
|
974 |
|
975 } |
|
976 // -------------------------------------------------------------------------- |
|
977 // void CGfx2dGcOpenVG::SetDashArrayL( CArrayFix<TFloatFixPt>* aArray ) |
|
978 // --------------------------------------------------------------------------- |
|
979 void CGfx2dGcOpenVG::SetDashArrayL( CArrayFix<TFloatFixPt>* aArray ) |
|
980 { |
|
981 if ( !aArray || !iDashArray ) |
|
982 { |
|
983 return; |
|
984 } |
|
985 |
|
986 TInt32 count = aArray->Count(); |
|
987 |
|
988 if ( count == 0 ) |
|
989 { |
|
990 return; |
|
991 } |
|
992 |
|
993 if ( iDashArray->Count() > 0 ) |
|
994 { |
|
995 iDashArray->Reset(); |
|
996 } |
|
997 |
|
998 for ( TInt32 i = 0; i < count; i++ ) |
|
999 { |
|
1000 iDashArray->AppendL( (VGfloat)aArray->At( i ) ); |
|
1001 } |
|
1002 |
|
1003 if ( count & 0x00000001 ) |
|
1004 { |
|
1005 //count was odd so we need to duplicate the current ones on the array |
|
1006 for (TInt32 i=0; i < count; i++) |
|
1007 { |
|
1008 iDashArray->AppendL( (VGfloat)aArray->At( i ) ); |
|
1009 } |
|
1010 } |
|
1011 |
|
1012 iVgRenderer->vgSetfv(VG_STROKE_DASH_PATTERN, iDashArray->Count(), (VGfloat*)&(*iDashArray)[0] ); |
|
1013 } |
|
1014 |
|
1015 // -------------------------------------------------------------------------- |
|
1016 // TSize CGfx2dGcOpenVG::DeviceBounds() |
|
1017 // --------------------------------------------------------------------------- |
|
1018 TSize CGfx2dGcOpenVG::DeviceBounds() |
|
1019 { |
|
1020 return iColorBufferSize; |
|
1021 } |
|
1022 |
|
1023 // -------------------------------------------------------------------------- |
|
1024 // void CGfx2dGcOpenVG::SetAntialiasingMode( const TInt32 /*aAntialiasingEnable*/) |
|
1025 // --------------------------------------------------------------------------- |
|
1026 void CGfx2dGcOpenVG::SetAntialiasingMode( const TInt32 aAntialiasingMode ) |
|
1027 { |
|
1028 |
|
1029 // JSR226 has two values for Render Quality |
|
1030 //-------------------------------------------------------------------------------- |
|
1031 // JSR226/M2G Values : TInt Value : OpenVG Constants |
|
1032 //-------------------------------------------------------------------------------- |
|
1033 // RENDERING_QUALITY_LOW : = 1 = : VG_RENDERING_QUALITY_NONANTIALIASED |
|
1034 // RENDERING_QUALITY_HIGH : = 2 = : VG_RENDERING_QUALITY_BETTER |
|
1035 //--------------------------------------------------------------------------------. |
|
1036 |
|
1037 if( aAntialiasingMode == KRenderQualityLow ) // RENDERING_QUALITY_LOW |
|
1038 { |
|
1039 iRenderQuality = VG_RENDERING_QUALITY_NONANTIALIASED ; |
|
1040 } |
|
1041 else if( aAntialiasingMode == KRenderQualityHigh ) // RENDERING_QUALITY_HIGH |
|
1042 { |
|
1043 iRenderQuality = VG_RENDERING_QUALITY_BETTER ; |
|
1044 } |
|
1045 |
|
1046 iVgRenderer->vgSeti(VG_RENDERING_QUALITY, iRenderQuality ); |
|
1047 |
|
1048 } |
|
1049 |
|
1050 // -------------------------------------------------------------------------- |
|
1051 // void CGfx2dGcOpenVG::SetFont( const CFont* aFont ) |
|
1052 // --------------------------------------------------------------------------- |
|
1053 void CGfx2dGcOpenVG::SetFont( const CFont* aFont ) |
|
1054 { |
|
1055 iFont = (CFont*)aFont; |
|
1056 } |
|
1057 // -------------------------------------------------------------------------- |
|
1058 // CFont* CGfx2dGcOpenVG::Font() |
|
1059 // --------------------------------------------------------------------------- |
|
1060 CFont* CGfx2dGcOpenVG::Font() |
|
1061 { |
|
1062 if (iFont == NULL) |
|
1063 { |
|
1064 iSvgBitmapFontProvider->GetNearestFontToDesignHeightInTwips( iFont, iFontSpec ); |
|
1065 |
|
1066 } |
|
1067 return iFont; |
|
1068 } |
|
1069 |
|
1070 // -------------------------------------------------------------------------- |
|
1071 // void CGfx2dGcOpenVG::GetSystemFontScaled(TFloatFixPt aHeight, |
|
1072 // const TDesC& aTypefaceName, |
|
1073 // CFont*& aFont, |
|
1074 // TFontSpec& aFontSpec ) |
|
1075 // --------------------------------------------------------------------------- |
|
1076 void CGfx2dGcOpenVG::GetFontScaled( TFloatFixPt /* aHeight */, |
|
1077 const TDesC& /* aTypefaceName */, |
|
1078 CFont*& /* aFont */, |
|
1079 TFontSpec& /* aFontSpec */ ) |
|
1080 { |
|
1081 } |
|
1082 |
|
1083 // -------------------------------------------------------------------------- |
|
1084 // void CGfx2dGcOpenVG::SetFontSize( const TFloatFixPt aFontSize ) |
|
1085 // --------------------------------------------------------------------------- |
|
1086 void CGfx2dGcOpenVG::SetFontSize( const TFloatFixPt aFontSize ) |
|
1087 { |
|
1088 iFontSize = aFontSize; |
|
1089 } |
|
1090 |
|
1091 // -------------------------------------------------------------------------- |
|
1092 // void CGfx2dGcOpenVG::SetFontWeight( const TInt32 aFontWeight ) |
|
1093 // --------------------------------------------------------------------------- |
|
1094 void CGfx2dGcOpenVG::SetFontWeight( const TInt32 aFontWeight ) |
|
1095 { |
|
1096 iFontWeight = aFontWeight; |
|
1097 } |
|
1098 |
|
1099 // -------------------------------------------------------------------------- |
|
1100 // void CGfx2dGcOpenVG::SetFontStyle( const TInt32 aFontStyle ) |
|
1101 // --------------------------------------------------------------------------- |
|
1102 void CGfx2dGcOpenVG::SetFontStyle( const TInt32 aFontStyle ) |
|
1103 { |
|
1104 iFontStyle = aFontStyle; |
|
1105 } |
|
1106 |
|
1107 // -------------------------------------------------------------------------- |
|
1108 // void CGfx2dGcOpenVG::SetFontFamily( CDesCArrayFlat* aFamilies ) |
|
1109 // --------------------------------------------------------------------------- |
|
1110 void CGfx2dGcOpenVG::SetFontFamily( CDesCArrayFlat* aFamilies ) |
|
1111 { |
|
1112 iFamilies = aFamilies; |
|
1113 } |
|
1114 |
|
1115 // -------------------------------------------------------------------------- |
|
1116 // void CGfx2dGcOpenVG::SetTextanchor( const TInt32 aTextAnchor ) |
|
1117 // --------------------------------------------------------------------------- |
|
1118 void CGfx2dGcOpenVG::SetTextanchor( const TInt32 aTextAnchor ) |
|
1119 { |
|
1120 iTextAnchor = (TGfxTextAnchor)aTextAnchor; |
|
1121 } |
|
1122 |
|
1123 // -------------------------------------------------------------------------- |
|
1124 // void CGfx2dGcOpenVG::SetTextDecoration( const TInt32 aTextDecoration ) |
|
1125 // --------------------------------------------------------------------------- |
|
1126 void CGfx2dGcOpenVG::SetTextDecoration( const TInt32 aTextDecoration ) |
|
1127 { |
|
1128 iTextDecoration = (TGfxTextDecoration)aTextDecoration; |
|
1129 } |
|
1130 // -------------------------------------------------------------------------- |
|
1131 // void CGfx2dGcOpenVG::GetBBoxForSystemText( TSvgFourPointRect& aFourPointBbox ) |
|
1132 // --------------------------------------------------------------------------- |
|
1133 TGfxRectangle2D CGfx2dGcOpenVG::GetBBoxForSystemText( const TDesC& aText, |
|
1134 TFloatFixPt aX, |
|
1135 TFloatFixPt aY ) |
|
1136 { |
|
1137 //bbox for bitmap fonts |
|
1138 TGfxRectangle2D lBbox; |
|
1139 TGfxPoint2D pt(aX,aY); |
|
1140 //iScale = GetCurrentScale(); |
|
1141 |
|
1142 //scaled already for bitmap text... |
|
1143 |
|
1144 TInt textAdvance = iFont->TextWidthInPixels( aText ); |
|
1145 TInt fontMaxHeight = iFont->FontMaxHeight(); |
|
1146 TFloatFixPt lascent = iFont->AscentInPixels(); |
|
1147 TFloatFixPt ldescent = TFloatFixPt(fontMaxHeight) - (TFloatFixPt)iFont->AscentInPixels(); |
|
1148 |
|
1149 |
|
1150 lBbox.iWidth = textAdvance; |
|
1151 lBbox.iHeight = fontMaxHeight; |
|
1152 |
|
1153 //need to work in the rotation factor somehow... |
|
1154 //without doing the scaling again |
|
1155 //at this point the bbox already scaled,translated but not rotated |
|
1156 |
|
1157 //should we create 1/scale factor or create with scale factor then get inverse |
|
1158 //iScale scaling factor from the graphics context |
|
1159 TReal32 linverseScale = 1.0/(TReal)iScale; |
|
1160 TGfxAffineTransform lInverseScaleMat = TGfxAffineTransform::GetScaleInstance(linverseScale, linverseScale); |
|
1161 |
|
1162 //this is with scale and rotation |
|
1163 TGfxPoint2D transformedPoint( pt.iX, pt.iY ); |
|
1164 |
|
1165 const TGfxAffineTransform& ctm = iTransform; |
|
1166 ctm.Transform(&pt, &transformedPoint, 1); |
|
1167 |
|
1168 //remove the double scaling effect that we would have |
|
1169 TGfxAffineTransform ctmWithoutScale = iTransform; |
|
1170 ctmWithoutScale.Concatenate(lInverseScaleMat); |
|
1171 |
|
1172 TGfxPoint2D scaledPoint( pt.iX * iScale, pt.iY * iScale ); |
|
1173 |
|
1174 //set up the initial box with just scale in it and not rotation. |
|
1175 // The base line is position at x,y co-ordinate of the text, but |
|
1176 // the bottom of bound box would be further below by amount ldescent. |
|
1177 TGfxPoint2D lTopLeftCorner(scaledPoint.iX, scaledPoint.iY + ldescent ); |
|
1178 TGfxPoint2D lTopRightCorner(scaledPoint.iX + lBbox.iWidth , scaledPoint.iY + ldescent ); |
|
1179 TGfxPoint2D lBottomLeftCorner(scaledPoint.iX, scaledPoint.iY - lascent); |
|
1180 TGfxPoint2D lBottomRightCorner(scaledPoint.iX + lBbox.iWidth, scaledPoint.iY - lascent ); |
|
1181 |
|
1182 TGfxPoint2D lTransTopLeftCorner; |
|
1183 TGfxPoint2D lTransBottomLeftCorner; |
|
1184 TGfxPoint2D lTransTopRightCorner; |
|
1185 TGfxPoint2D lTransBottomRightCorner; |
|
1186 |
|
1187 //applying current rotation transform without the scale. |
|
1188 ctmWithoutScale.Transform(&lTopLeftCorner, &lTransTopLeftCorner,1); |
|
1189 ctmWithoutScale.Transform(&lTopRightCorner, &lTransTopRightCorner,1); |
|
1190 ctmWithoutScale.Transform(&lBottomLeftCorner, &lTransBottomLeftCorner,1); |
|
1191 ctmWithoutScale.Transform(&lBottomRightCorner, &lTransBottomRightCorner,1); |
|
1192 |
|
1193 TFloatFixPt lXTranslation = transformedPoint.iX - lTransTopLeftCorner.iX; |
|
1194 //TFixPt lXTranslation = transformedPoint.iX - iPoint.iX; |
|
1195 |
|
1196 TFloatFixPt lYTranslation = transformedPoint.iY - lTransTopLeftCorner.iY; |
|
1197 //TFixPt lYTranslation = transformedPoint.iY - iPoint.iY; |
|
1198 |
|
1199 // X position is affected by anchor |
|
1200 switch( iTextAnchor ) |
|
1201 { |
|
1202 case EGfxTextAnchorMiddle: |
|
1203 lXTranslation = lXTranslation - ( lBbox.iWidth / TFloatFixPt( 2 ) ); |
|
1204 break; |
|
1205 case EGfxTextAnchorEnd: |
|
1206 lXTranslation = lXTranslation - lBbox.iWidth; |
|
1207 break; |
|
1208 default: |
|
1209 //do nothing |
|
1210 break; |
|
1211 } |
|
1212 |
|
1213 lTransTopLeftCorner.iX += lXTranslation; |
|
1214 lTransTopLeftCorner.iY += lYTranslation; |
|
1215 |
|
1216 lTransTopRightCorner.iX += lXTranslation; |
|
1217 lTransTopRightCorner.iY += lYTranslation; |
|
1218 |
|
1219 lTransBottomLeftCorner.iX += lXTranslation; |
|
1220 lTransBottomLeftCorner.iY += lYTranslation; |
|
1221 |
|
1222 lTransBottomRightCorner.iX += lXTranslation; |
|
1223 lTransBottomRightCorner.iY += lYTranslation; |
|
1224 |
|
1225 //at this point I have the exact path coordinates of the bbox |
|
1226 //aFourPointBbox.SetRectPoints(lTransTopLeftCorner, lTransTopRightCorner, lTransBottomLeftCorner, lTransBottomRightCorner); |
|
1227 return GetTRect(lTransTopLeftCorner, lTransTopRightCorner, lTransBottomLeftCorner, lTransBottomRightCorner); |
|
1228 } |
|
1229 |
|
1230 |
|
1231 TGfxRectangle2D CGfx2dGcOpenVG::GetTRect(TGfxPoint2D lTransTopLeftCorner,TGfxPoint2D lTransTopRightCorner,TGfxPoint2D lTransBottomLeftCorner,TGfxPoint2D lTransBottomRightCorner) |
|
1232 { |
|
1233 TFloatFixPt lMaxX = lTransTopLeftCorner.iX; |
|
1234 |
|
1235 if (lTransTopRightCorner.iX > lMaxX) |
|
1236 { |
|
1237 lMaxX = lTransTopRightCorner.iX; |
|
1238 } |
|
1239 if (lTransBottomLeftCorner.iX > lMaxX) |
|
1240 { |
|
1241 lMaxX = lTransBottomLeftCorner.iX; |
|
1242 } |
|
1243 if (lTransBottomRightCorner.iX > lMaxX) |
|
1244 { |
|
1245 lMaxX = lTransBottomRightCorner.iX; |
|
1246 } |
|
1247 |
|
1248 TFloatFixPt lMaxY = lTransTopLeftCorner.iY; |
|
1249 |
|
1250 if (lTransTopRightCorner.iY > lMaxY) |
|
1251 { |
|
1252 lMaxY = lTransTopRightCorner.iY; |
|
1253 } |
|
1254 if (lTransBottomLeftCorner.iY > lMaxY) |
|
1255 { |
|
1256 lMaxY = lTransBottomLeftCorner.iY; |
|
1257 } |
|
1258 if (lTransBottomRightCorner.iY > lMaxY) |
|
1259 { |
|
1260 lMaxY = lTransBottomRightCorner.iY; |
|
1261 } |
|
1262 |
|
1263 TFloatFixPt lMinX = lTransTopLeftCorner.iX; |
|
1264 |
|
1265 if (lTransTopRightCorner.iX < lMinX) |
|
1266 { |
|
1267 lMinX = lTransTopRightCorner.iX; |
|
1268 } |
|
1269 if (lTransBottomLeftCorner.iX < lMinX) |
|
1270 { |
|
1271 lMinX = lTransBottomLeftCorner.iX; |
|
1272 } |
|
1273 if (lTransBottomRightCorner.iX < lMinX) |
|
1274 { |
|
1275 lMinX = lTransBottomRightCorner.iX; |
|
1276 } |
|
1277 |
|
1278 TFloatFixPt lMinY = lTransTopLeftCorner.iY; |
|
1279 |
|
1280 if (lTransTopRightCorner.iY < lMinY) |
|
1281 { |
|
1282 lMinY = lTransTopRightCorner.iY; |
|
1283 } |
|
1284 if (lTransBottomLeftCorner.iY < lMinY) |
|
1285 { |
|
1286 lMinY = lTransBottomLeftCorner.iY; |
|
1287 } |
|
1288 if (lTransBottomRightCorner.iY < lMinY) |
|
1289 { |
|
1290 lMinY = lTransBottomRightCorner.iY; |
|
1291 } |
|
1292 TGfxRectangle2D aRect; |
|
1293 aRect.iX = lMinX; |
|
1294 aRect.iY = lMinY; |
|
1295 aRect.iWidth = lMaxX - lMinX; |
|
1296 aRect.iHeight = lMaxY - lMinY; |
|
1297 return aRect; |
|
1298 |
|
1299 } |
|
1300 |
|
1301 // Text Drawing |
|
1302 // -------------------------------------------------------------------------- |
|
1303 // void CGfx2dGcOpenVG::DrawStringL( const TDesC& aDesc, |
|
1304 // --------------------------------------------------------------------------- |
|
1305 void CGfx2dGcOpenVG::DrawStringL( const TDesC& aDesc, |
|
1306 TFloatFixPt aX, |
|
1307 TFloatFixPt aY, |
|
1308 TInt8 ,// aTextAnchor |
|
1309 TInt8 ,// aTextDecoration |
|
1310 CDesCArrayFlat*, // aFamilies, |
|
1311 TReal aWordSpacing, |
|
1312 TReal aLetterSpacing, |
|
1313 CArrayFix<TReal32>* aArrayRotate, |
|
1314 CArrayFix<TFloatFixPt>* aArrayX, |
|
1315 CArrayFix<TFloatFixPt>* aArrayY, |
|
1316 TSize& aBoundingBox, |
|
1317 CFont*& aFont, |
|
1318 TFontSpec& /* aFontSpec */ ) |
|
1319 { |
|
1320 |
|
1321 if ( iStrokeColor.GetARGB() == KGfxColorNull && |
|
1322 iFillColor == NULL ) |
|
1323 return; |
|
1324 |
|
1325 if(iFillOpacity == TFloatFixPt(0)) |
|
1326 return; |
|
1327 |
|
1328 if ( aDesc.Length() <= 0 ) |
|
1329 return; |
|
1330 |
|
1331 TPtrC outputText; |
|
1332 if ( *( aDesc.Right( 1 ).Ptr() ) < ' ' ) |
|
1333 outputText.Set( aDesc.Left( aDesc.Length() - 1 ) ); |
|
1334 else |
|
1335 outputText.Set( aDesc ); |
|
1336 |
|
1337 TBool rtl=EFalse; |
|
1338 if(TBidiText::TextDirectionality(outputText) == TBidiText::ERightToLeft) |
|
1339 { |
|
1340 rtl=ETrue; |
|
1341 } |
|
1342 |
|
1343 if ( aFont == NULL ) |
|
1344 { |
|
1345 return; |
|
1346 } |
|
1347 iFont = aFont; |
|
1348 |
|
1349 float aFloat = 0.5; |
|
1350 |
|
1351 //put in .50 for rounding issues 10.99 was going to 10 |
|
1352 // iFontSize has been initialised at the SetGCL time for the |
|
1353 // this specific text element in question. |
|
1354 TInt32 fontsize = (TInt32)( iScale * iFontSize + TFloatFixPt(aFloat) ); |
|
1355 |
|
1356 if ( fontsize == 0 ) |
|
1357 { |
|
1358 return; |
|
1359 } |
|
1360 |
|
1361 |
|
1362 CFont::TMeasureTextOutput myTextOutput; |
|
1363 |
|
1364 TInt textAdvance = iFont->TextWidthInPixels( outputText ); |
|
1365 if ( textAdvance == 0 ) |
|
1366 { |
|
1367 return; |
|
1368 } |
|
1369 TInt fontMaxHeight = iFont->FontMaxHeight() + 2; //Tweak factor needed |
|
1370 TInt fontMaxAscent = iFont->FontMaxAscent() + 1; //Tweak factor needed |
|
1371 TInt fontAscent = iFont->AscentInPixels(); |
|
1372 TInt fontDescent = iFont->DescentInPixels(); |
|
1373 TInt maxDescent = fontMaxHeight-fontMaxAscent; //iFont->FontMaxDescent(); |
|
1374 TInt fontHeightInPixels = iFont->HeightInPixels(); |
|
1375 //added to correct for text clipping that system font has |
|
1376 TInt fontTweakFactor = (TInt)(TFloatFixPt( 1.5f ) * iScale); |
|
1377 TInt fontHorizontalTweakFactor = (TInt)(TFloatFixPt( 5.0f ) * iScale); |
|
1378 TInt numSpaces = myTextOutput.iSpaces; |
|
1379 TInt numChars = myTextOutput.iChars; |
|
1380 TGfxRectangle2D tempRect( aX, |
|
1381 aY, |
|
1382 textAdvance, |
|
1383 fontMaxHeight ); |
|
1384 |
|
1385 /****************************************************************** |
|
1386 * Boundary Check to see if the Text to be drawn is within Bounds. * |
|
1387 ******************************************************************/ |
|
1388 |
|
1389 TGfxAffineTransform tMatrix; |
|
1390 tMatrix = iTransform; |
|
1391 TInt32 transx = tMatrix.TranslateX(); |
|
1392 TInt32 transy = tMatrix.TranslateY(); |
|
1393 TGfxRectangle2D aRect = GetBBoxForSystemText( outputText , aX , aY ); |
|
1394 |
|
1395 TInt32 rectmaxx = aRect.MaxX(); //+ (TFloatFixPt)transx; |
|
1396 TInt32 rectmaxy = aRect.MaxY();//- (TFloatFixPt)fontMaxAscent; //+ (TFloatFixPt)transy; |
|
1397 TInt32 rectminx = aRect.MinX(); //- (TFloatFixPt)transx; |
|
1398 TInt32 rectminy = aRect.MinY();// - (TFloatFixPt)fontMaxHeight;//- (TFloatFixPt)fontMaxAscent; //- (TFloatFixPt)transy; |
|
1399 TInt32 clipminx = iRenderInfo.iClipMinX;// + transx; |
|
1400 TInt32 clipmaxx = iRenderInfo.iClipMaxX;// + transx; |
|
1401 TInt32 clipmaxy = iRenderInfo.iClipMaxY;// + transy; |
|
1402 TInt32 clipminy = iRenderInfo.iClipMinY;// + transy; |
|
1403 |
|
1404 TInt advanceWidth = 0; |
|
1405 TInt advanceX = 0; |
|
1406 TInt excessSpace = 0; |
|
1407 TInt aMultipleXY = 0; |
|
1408 |
|
1409 //Checking for multiple XY values. |
|
1410 if ( aArrayX != NULL && aArrayY != NULL ) |
|
1411 { |
|
1412 if ( ( aArrayX->Count() > 1 ) || ( aArrayY->Count() > 1 ) ) |
|
1413 aMultipleXY = 1; |
|
1414 } |
|
1415 |
|
1416 // setting the boundbox for simple text with no xy and rotate |
|
1417 //this is set here because bound box should get always set as it is used in GetBBoxForSystemText in TextElement. |
|
1418 if ( ( aArrayRotate == NULL ) && |
|
1419 ( aMultipleXY == 0 ) && |
|
1420 ( aLetterSpacing == 0.0 ) && |
|
1421 ( aWordSpacing == 0.0 ) ) |
|
1422 { |
|
1423 aBoundingBox.iWidth = textAdvance; |
|
1424 aBoundingBox.iHeight = fontMaxHeight; |
|
1425 } |
|
1426 |
|
1427 if( rectmaxx < clipminx || rectmaxy < clipminy || |
|
1428 rectminx > clipmaxx || rectminy > clipmaxy ) |
|
1429 return; |
|
1430 |
|
1431 /**************************************************************************** |
|
1432 * Code to Draw Simple Text with only x, y and transform values and return.* |
|
1433 ****************************************************************************/ |
|
1434 |
|
1435 if ( ( aArrayRotate == NULL ) && |
|
1436 ( aMultipleXY == 0 ) && |
|
1437 ( aLetterSpacing == 0.0 ) && |
|
1438 ( aWordSpacing == 0.0 ) ) |
|
1439 { |
|
1440 CFbsBitmap* offScreenBitmap = new ( ELeave ) CFbsBitmap(); |
|
1441 |
|
1442 User::LeaveIfError( offScreenBitmap->Create( TSize( textAdvance, fontMaxHeight), EGray256 ) ); |
|
1443 // User::LeaveIfError( offScreenBitmap->Create( TSize( textAdvance + fontHorizontalTweakFactor, fontMaxHeight + fontTweakFactor ), EGray256 ) ); |
|
1444 CleanupStack::PushL( offScreenBitmap ); |
|
1445 |
|
1446 CGraphicsContext* bitmapContext = NULL; |
|
1447 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( offScreenBitmap ); |
|
1448 |
|
1449 CleanupStack::PushL( bitmapDevice ); |
|
1450 User::LeaveIfError( bitmapDevice->CreateContext( bitmapContext ) ); |
|
1451 CleanupStack::PushL( bitmapContext ); |
|
1452 |
|
1453 bitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
1454 bitmapContext->SetBrushColor( 0x000000 ); |
|
1455 bitmapContext->DrawRect( TRect( TPoint( 0, 0 ), offScreenBitmap->SizeInPixels() ) ); |
|
1456 bitmapContext->UseFont( iFont ); |
|
1457 bitmapContext->SetPenSize( TSize( 1, 1 ) ); |
|
1458 bitmapContext->SetPenColor( 0xFFFFFF ); |
|
1459 bitmapContext->SetPenStyle( CGraphicsContext::ESolidPen ); |
|
1460 bitmapContext->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
1461 |
|
1462 if (iTextAnchor == EGfxTextAnchorEnd) |
|
1463 { |
|
1464 aX -= TFloatFixPt(textAdvance) / iScale; |
|
1465 } |
|
1466 if (iTextAnchor == EGfxTextAnchorMiddle) |
|
1467 { |
|
1468 aX -= (TFloatFixPt(textAdvance) / iScale) / TFloatFixPt(2); |
|
1469 } |
|
1470 |
|
1471 // While drawing the text which has both arabic & normal left-to-right |
|
1472 // characters the DrawTextExtended should be used since there is no way |
|
1473 // to split the text according to the directionality. |
|
1474 |
|
1475 CGraphicsContext::TDrawTextExtendedParam param; |
|
1476 param.iParRightToLeft = rtl; |
|
1477 bitmapContext->DrawTextExtended(outputText, |
|
1478 TPoint( 0, fontMaxAscent ), param); |
|
1479 |
|
1480 VGint width = offScreenBitmap->SizeInPixels().iWidth; |
|
1481 VGint height = offScreenBitmap->SizeInPixels().iHeight; |
|
1482 |
|
1483 /* The bilinear causes the text to blur a bit, but rotated (& scaled) text will look better, of course */ |
|
1484 VGImage img = iVgRenderer->vgCreateImage( VG_A_8, width, height, VG_IMAGE_QUALITY_NONANTIALIASED ); |
|
1485 //VGImage img = vgCreateImage( VG_A_8, width, height, VG_IMAGE_QUALITY_BETTER ); |
|
1486 //VGImage img = vgCreateImage( VG_A_8, width, height, VG_IMAGE_QUALITY_FASTER ); |
|
1487 |
|
1488 VGPaint paint = iVgRenderer->vgCreatePaint(); |
|
1489 |
|
1490 if( img && paint ) |
|
1491 { |
|
1492 offScreenBitmap->LockHeap(); |
|
1493 |
|
1494 /* OpenVG images have their y-axis flipped, |
|
1495 that is why when calling vgImageSubData we pass the address of offScreenBitmap's last scanline, |
|
1496 and use a negated stride value */ |
|
1497 VGint stride = CFbsBitmap::ScanLineLength( width, EGray256 ); /* EGray256 == offScreenBitmap->DisplayMode() */ |
|
1498 VGbyte *lastScanline = ( (VGbyte*)offScreenBitmap->DataAddress() ) + ( height - 1 ) * stride; |
|
1499 |
|
1500 iVgRenderer->vgImageSubData( img, lastScanline, -stride, VG_A_8, 0, 0, width, height ); |
|
1501 |
|
1502 offScreenBitmap->UnlockHeap(); |
|
1503 |
|
1504 TGfxColor color( iFillColor ? iFillColor->GetColor() : iStrokeColor.GetColor() ); |
|
1505 VGuint argb = color.GetARGB() | ( 0xff000000 ); /* set alpha to 255 */ |
|
1506 VGfloat rgba_f[4]; |
|
1507 |
|
1508 int tr, tg, tb; |
|
1509 |
|
1510 tr = (argb >> 16) & 0xff; |
|
1511 tg = (argb >> 8 ) & 0xff; |
|
1512 tb = (argb ) & 0xff; |
|
1513 |
|
1514 rgba_f[0] = tr / 255.0f; |
|
1515 rgba_f[1] = tg / 255.0f; |
|
1516 rgba_f[2] = tb / 255.0f; |
|
1517 //rgba_f[3] = ( ( argb >> 24 ) & 0xff ) / 255.0f; |
|
1518 rgba_f[3] = 1.0f; /* was set to 255 */ |
|
1519 if( paint != VG_INVALID_HANDLE ) |
|
1520 { |
|
1521 iVgRenderer->vgSetParameteri( paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR ); |
|
1522 iVgRenderer->vgSetParameterfv( paint, VG_PAINT_COLOR, 4, rgba_f ); |
|
1523 iVgRenderer->vgSetPaint( paint, VG_FILL_PATH ); |
|
1524 } |
|
1525 |
|
1526 // Get the current blend mode (set back at end of operation) |
|
1527 const TInt KBlendModeValue = iVgRenderer->vgGeti( VG_BLEND_MODE ); |
|
1528 const TInt KImageModeValue = iVgRenderer->vgGeti( VG_IMAGE_MODE ); |
|
1529 |
|
1530 |
|
1531 iVgRenderer->vgSeti( VG_BLEND_MODE, VG_BLEND_SRC_OVER ); |
|
1532 iVgRenderer->vgSeti( VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY ); |
|
1533 VGfloat mat[9]; |
|
1534 |
|
1535 /* Retreive the Path transformation matrix */ |
|
1536 GetMatrix( mat ); |
|
1537 iVgRenderer->vgSeti( VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE ); |
|
1538 |
|
1539 |
|
1540 iVgRenderer->vgSeti( VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE ); |
|
1541 |
|
1542 /* Since the text rendering has to match AA done by ext, we'll round the transformation. |
|
1543 Seems like Symbian does not have a 32-bit float round... */ |
|
1544 |
|
1545 TReal tx = mat[6], ty = mat[7]; |
|
1546 Math::Round(tx, tx, 0); Math::Round(ty, ty, 0); |
|
1547 |
|
1548 mat[6] = (VGfloat)tx; |
|
1549 mat[7] = (VGfloat)ty; |
|
1550 |
|
1551 /* Load Path transformation matrix to Image transformation matrix */ |
|
1552 /*nga vgLoadMatrix( mat ); |
|
1553 |
|
1554 // TFloatFixPt aY1( aY * iScale ); |
|
1555 // aY -= ( iFont->AscentInPixels()); |
|
1556 //vgTranslate( (VGfloat)aX, (VGfloat)aY + fontTweakFactor); |
|
1557 vgTranslate( (VGfloat)aX, (VGfloat)aY ); |
|
1558 vgScale( 1.0f/(VGfloat)iScale, -1.0f/(VGfloat)iScale ); |
|
1559 vgTranslate( (VGfloat)0, -(VGfloat)maxDescent); |
|
1560 vgDrawImage( img ); |
|
1561 |
|
1562 vgSeti( VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE ); |
|
1563 vgLoadIdentity(); |
|
1564 |
|
1565 vgSeti( VG_IMAGE_MODE, KImageModeValue ); |
|
1566 vgSeti( VG_BLEND_MODE, KBlendModeValue );*/ |
|
1567 iVgRenderer->vgLoadMatrix( mat ); |
|
1568 iVgRenderer->vgTranslate( (VGfloat)aX, (VGfloat)aY ); |
|
1569 iVgRenderer->vgScale( 1.0f/(VGfloat)iScale, -1.0f/(VGfloat)iScale ); |
|
1570 iVgRenderer->vgTranslate( (VGfloat)0, -(VGfloat)maxDescent); |
|
1571 iVgRenderer->vgDrawImage( img ); |
|
1572 |
|
1573 iVgRenderer->vgSeti( VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE ); |
|
1574 iVgRenderer->vgLoadIdentity(); |
|
1575 |
|
1576 iVgRenderer->vgSeti( VG_IMAGE_MODE, KImageModeValue ); |
|
1577 iVgRenderer->vgSeti( VG_BLEND_MODE, KBlendModeValue ); |
|
1578 } |
|
1579 |
|
1580 if( img ) |
|
1581 { |
|
1582 iVgRenderer->vgDestroyImage( img ); |
|
1583 } |
|
1584 if( paint ) |
|
1585 { |
|
1586 iVgRenderer->vgDestroyPaint( paint ); |
|
1587 } |
|
1588 |
|
1589 bitmapContext->DiscardFont(); |
|
1590 |
|
1591 CleanupStack::PopAndDestroy( 3 ); |
|
1592 |
|
1593 if ( iTextDecoration == EGfxTextDecorationUnderLine ) |
|
1594 { |
|
1595 TGfxLine2D aLine( aX, |
|
1596 aY, |
|
1597 (aX + ( TFloatFixPt )textAdvance / iScale ), |
|
1598 aY); //+ ( TFloatFixPt )(2)); |
|
1599 DrawL( &aLine ); |
|
1600 } |
|
1601 else if ( iTextDecoration == EGfxTextDecorationOverLine ) |
|
1602 { |
|
1603 TGfxLine2D aLine( aX, |
|
1604 // aY - ( TFloatFixPt )fontMaxHeight / iScale, |
|
1605 aY, |
|
1606 (aX + ( TFloatFixPt )textAdvance / iScale ), |
|
1607 aY);// - ( TFloatFixPt )fontMaxHeight / iScale ); |
|
1608 DrawL( &aLine ); |
|
1609 } |
|
1610 else if ( iTextDecoration == EGfxTextDecorationLineThrough ) |
|
1611 { |
|
1612 TGfxLine2D aLine( aX , |
|
1613 aY - ( TFloatFixPt )( fontMaxHeight / 2 ) / iScale, |
|
1614 (aX + ( TFloatFixPt )textAdvance /iScale ), |
|
1615 aY - ( TFloatFixPt )( fontMaxHeight / 2 ) / iScale ); |
|
1616 DrawL( &aLine ); |
|
1617 } |
|
1618 |
|
1619 //----------------------------------------------------------------- |
|
1620 return; |
|
1621 } |
|
1622 |
|
1623 |
|
1624 //Check Word/Letter Spacing. |
|
1625 if ( aWordSpacing > 0.0 ) |
|
1626 excessSpace += ( TInt ) |
|
1627 ( aWordSpacing * ( TReal ) iScale ) * numSpaces; |
|
1628 if ( aLetterSpacing > 0.0 ) |
|
1629 excessSpace += ( TInt ) |
|
1630 ( aLetterSpacing * ( TReal ) iScale ) * numChars; |
|
1631 |
|
1632 textAdvance += excessSpace; |
|
1633 |
|
1634 /***************************************************************************** |
|
1635 * Drawing one glyph(character) at a time for multiple XY and rotation Values.* |
|
1636 ******************************************************************************/ |
|
1637 if (rtl) |
|
1638 { |
|
1639 TBidiText* biditext = TBidiText::NewL(outputText,1); |
|
1640 biditext->WrapText(textAdvance,*iFont,0,1); |
|
1641 outputText.Set(biditext->DisplayText()); |
|
1642 delete biditext; |
|
1643 biditext = NULL; |
|
1644 |
|
1645 } |
|
1646 TLex aOutputText( outputText ); |
|
1647 for ( TInt count = 0; count < outputText.Length() ; count++ ) |
|
1648 { |
|
1649 TPtrC outputChar; |
|
1650 TChar ch( aOutputText.Get() ); |
|
1651 outputChar.Set( &( outputText.operator[]( count ) ), 1 ); |
|
1652 |
|
1653 TInt charWidth = iFont->CharWidthInPixels( ch ); |
|
1654 |
|
1655 CFbsBitmap* offScreenBitmap = new ( ELeave ) CFbsBitmap(); |
|
1656 User::LeaveIfError( offScreenBitmap->Create( TSize( charWidth, |
|
1657 fontMaxHeight + fontTweakFactor ), |
|
1658 EColor16MU ) ); |
|
1659 CleanupStack::PushL( offScreenBitmap ); |
|
1660 |
|
1661 CGraphicsContext* bitmapContext = NULL; |
|
1662 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( offScreenBitmap ); |
|
1663 |
|
1664 CleanupStack::PushL( bitmapDevice ); |
|
1665 User::LeaveIfError( bitmapDevice->CreateContext( bitmapContext ) ); |
|
1666 CleanupStack::PushL( bitmapContext ); |
|
1667 |
|
1668 TBool isWhite = EFalse; |
|
1669 if ( iFillColor != NULL ) |
|
1670 { |
|
1671 if ( ( ( TGfxColor * ) iFillColor )->GetARGB() == 0xffffff ) |
|
1672 isWhite = ETrue; |
|
1673 } |
|
1674 else |
|
1675 { |
|
1676 if ( iStrokeColor.GetARGB() == 0xffffff ) |
|
1677 isWhite = ETrue; |
|
1678 } |
|
1679 if ( isWhite ) |
|
1680 { |
|
1681 // Fill with black if text color is white |
|
1682 TRect bmprect( 0, 0, charWidth, fontMaxHeight ); |
|
1683 bitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
1684 bitmapContext->SetBrushColor( 0x000000 ); |
|
1685 bitmapContext->SetPenColor( 0x000000 ); |
|
1686 bitmapContext->DrawRect( bmprect ); |
|
1687 } |
|
1688 |
|
1689 bitmapContext->UseFont( iFont ); |
|
1690 bitmapContext->SetPenSize( TSize( 1, 1 ) ); |
|
1691 if ( iFillColor != NULL ) |
|
1692 { |
|
1693 TGfxColor lColor(iFillColor->GetColor()); |
|
1694 bitmapContext->SetBrushColor( lColor.GetABGR() ); |
|
1695 bitmapContext->SetPenColor( lColor.GetABGR() ); |
|
1696 } |
|
1697 else |
|
1698 { |
|
1699 bitmapContext->SetBrushColor( iStrokeColor.GetABGR() ); |
|
1700 bitmapContext->SetPenColor( iStrokeColor.GetABGR() ); |
|
1701 } |
|
1702 |
|
1703 bitmapContext->SetPenStyle( CGraphicsContext::ESolidPen ); |
|
1704 bitmapContext->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
1705 |
|
1706 |
|
1707 if ( ( aArrayX != NULL ) && ( count < aArrayX->Count() ) ) |
|
1708 aX = aArrayX->At( count ); |
|
1709 |
|
1710 if ( ( aArrayY != NULL ) && ( count < aArrayY->Count() ) ) |
|
1711 aY = aArrayY->At( count ); |
|
1712 |
|
1713 TFloatFixPt aY1( aY * iScale ), aX1( aX * iScale ); |
|
1714 |
|
1715 TFloatFixPt ScaleAA; |
|
1716 TGfxAffineTransform tempMatrix; |
|
1717 tempMatrix = iTransform; |
|
1718 |
|
1719 ScaleAA = 1; |
|
1720 |
|
1721 #ifdef SVG_FLOAT_BUILD |
|
1722 tempMatrix.Scale( ( TFloatFixPt( 1 ) / ( iScale ) ), |
|
1723 ( TFloatFixPt( 1 ) / ( iScale ) )); |
|
1724 #else |
|
1725 tempMatrix.Scale( ( TFloatFixPt( 0x10000,ETrue ) / ( iScale ) ), |
|
1726 ( TFloatFixPt( 0x10000,ETrue ) / ( iScale ) )); |
|
1727 #endif |
|
1728 |
|
1729 |
|
1730 |
|
1731 if ( aMultipleXY == 1 ) |
|
1732 { |
|
1733 aX1 = aX1 + ( TFloatFixPt ) advanceX; |
|
1734 } |
|
1735 else |
|
1736 aX1 = aX1 + ( TFloatFixPt ) advanceWidth; |
|
1737 |
|
1738 aY1 -= ( iFont->AscentInPixels() ); |
|
1739 |
|
1740 if ( aMultipleXY == 0 ) |
|
1741 { |
|
1742 if ( iTextAnchor == EGfxTextAnchorMiddle ) |
|
1743 { |
|
1744 aX1 -= textAdvance / 2; |
|
1745 } |
|
1746 else if ( iTextAnchor == EGfxTextAnchorEnd ) |
|
1747 { |
|
1748 aX1 -= textAdvance; |
|
1749 } |
|
1750 } |
|
1751 |
|
1752 TGfxPoint2D p( aX1, aY1 ); |
|
1753 |
|
1754 TFloatFixPt trnsx, trnsy; |
|
1755 |
|
1756 trnsx = aX1 ; |
|
1757 trnsy = aY1 + ( TFloatFixPt ) ( (fontMaxHeight / 2) + fontDescent); |
|
1758 |
|
1759 //"rotate" Attribute Implementation |
|
1760 // If only one value is present, it is applied to all the glyphs |
|
1761 //otherwise, one-to-one mapping is taken. Any extra values are ignored! |
|
1762 if ( aArrayRotate != NULL ) |
|
1763 { |
|
1764 if(count < aArrayRotate->Count()) |
|
1765 { |
|
1766 TFloatFixPt KZero; |
|
1767 tempMatrix.Translate( trnsx, trnsy ); |
|
1768 TReal32 aAngle( ( TReal32 ) aArrayRotate->At( count ) ); |
|
1769 tempMatrix.Rotate( aAngle * 3.1415926f / 180.0f ); |
|
1770 TFloatFixPt negX( KZero - trnsx ); |
|
1771 TFloatFixPt negY( KZero - trnsy ); |
|
1772 tempMatrix.Translate( negX, negY ); |
|
1773 } |
|
1774 } |
|
1775 |
|
1776 TGfxImageTransformer imgtrns( &tempMatrix, iVgRenderer); |
|
1777 |
|
1778 |
|
1779 TRect clip(iClip.iX, iClip.iY, |
|
1780 iClip.iWidth + iClip.iX, iClip.iHeight + iClip.iY); |
|
1781 |
|
1782 p.iY -= fontTweakFactor; |
|
1783 imgtrns.ImageBlend( offScreenBitmap, |
|
1784 p, |
|
1785 iRenderInfo.iWidth, |
|
1786 iRenderInfo.iHeight, |
|
1787 clip, |
|
1788 ETrue); |
|
1789 |
|
1790 if (rtl) // IsRightToLeft(outputText) |
|
1791 { |
|
1792 CGraphicsContext::TDrawTextExtendedParam param; |
|
1793 param.iParRightToLeft = ETrue; |
|
1794 |
|
1795 bitmapContext->DrawTextExtended(outputText, |
|
1796 TPoint( 0, fontHeightInPixels - fontDescent + fontTweakFactor ), param); |
|
1797 } |
|
1798 else |
|
1799 { |
|
1800 bitmapContext->DrawText( outputChar, TPoint( 0, fontMaxAscent ) ); |
|
1801 // bitmapContext->DrawText( outputChar, TPoint( 0, fontHeightInPixels - fontDescent + fontTweakFactor )); |
|
1802 } |
|
1803 TGfxRectangle2D textRect(p.iX, p.iY, textAdvance, fontMaxHeight); |
|
1804 |
|
1805 imgtrns.ImageBlend( offScreenBitmap, |
|
1806 p, |
|
1807 iRenderInfo.iWidth, |
|
1808 iRenderInfo.iHeight, |
|
1809 clip); |
|
1810 |
|
1811 bitmapContext->DiscardFont(); |
|
1812 CleanupStack::PopAndDestroy( 3 ); |
|
1813 |
|
1814 if ( aMultipleXY == 0 ) |
|
1815 { |
|
1816 TInt aSpacing = 0; |
|
1817 if ( aLetterSpacing > 0.0 ) |
|
1818 { |
|
1819 if ( ch != 0x0020 ) |
|
1820 aSpacing += ( TInt ) |
|
1821 ( aLetterSpacing * ( TReal ) iScale ) ; |
|
1822 } |
|
1823 if ( aWordSpacing > 0.0 ) |
|
1824 { |
|
1825 if ( ch == 0x0020 ) |
|
1826 aSpacing += ( TInt ) ( aWordSpacing * ( TReal ) iScale ) ; |
|
1827 } |
|
1828 |
|
1829 if ( iStrokeColor.GetARGB() == KGfxColorNull ) |
|
1830 { |
|
1831 if ( iFillColor != NULL ) |
|
1832 this->iStrokeColor = TGfxColor( iFillColor->GetColor() ); |
|
1833 } |
|
1834 |
|
1835 if ( iTextDecoration == EGfxTextDecorationUnderLine ) |
|
1836 { |
|
1837 if ( iTextAnchor == EGfxTextAnchorMiddle ) |
|
1838 { |
|
1839 TGfxLine2D aLine( aX + (ScaleAA * |
|
1840 ( TFloatFixPt ) |
|
1841 ( advanceWidth - textAdvance / 2 ) / |
|
1842 iScale), |
|
1843 aY, |
|
1844 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1845 ( advanceWidth + charWidth + aSpacing - textAdvance / 2 ) / |
|
1846 iScale ) ) ), |
|
1847 aY ); |
|
1848 DrawL( &aLine ); |
|
1849 } |
|
1850 else if ( iTextAnchor == EGfxTextAnchorEnd ) |
|
1851 { |
|
1852 TGfxLine2D aLine( aX + (ScaleAA * |
|
1853 ( TFloatFixPt ) |
|
1854 ( advanceWidth - textAdvance ) / |
|
1855 iScale), |
|
1856 aY, |
|
1857 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1858 ( advanceWidth + charWidth + aSpacing - textAdvance ) / |
|
1859 iScale ) ) ), |
|
1860 aY ); |
|
1861 DrawL( &aLine ); |
|
1862 } |
|
1863 else //Start |
|
1864 { |
|
1865 TGfxLine2D aLine( aX + (ScaleAA * |
|
1866 ( TFloatFixPt ) |
|
1867 advanceWidth / |
|
1868 iScale), |
|
1869 aY, |
|
1870 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1871 ( advanceWidth + charWidth + aSpacing ) / |
|
1872 iScale ) ) ), |
|
1873 aY ); |
|
1874 DrawL( &aLine ); |
|
1875 } |
|
1876 } |
|
1877 if ( iTextDecoration == EGfxTextDecorationOverLine ) |
|
1878 { |
|
1879 if ( iTextAnchor == EGfxTextAnchorMiddle ) |
|
1880 { |
|
1881 TGfxLine2D aLine( aX + (ScaleAA * |
|
1882 ( TFloatFixPt ) |
|
1883 ( advanceWidth - textAdvance / 2 ) / |
|
1884 iScale), |
|
1885 aY - |
|
1886 ( TFloatFixPt ) |
|
1887 fontMaxHeight / |
|
1888 iScale, |
|
1889 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1890 ( advanceWidth + charWidth + aSpacing - textAdvance / 2 ) / |
|
1891 iScale ) ) ), |
|
1892 aY - |
|
1893 ( TFloatFixPt ) |
|
1894 fontMaxHeight / |
|
1895 iScale ); |
|
1896 DrawL( &aLine ); |
|
1897 } |
|
1898 else if ( iTextAnchor == EGfxTextAnchorEnd ) |
|
1899 { |
|
1900 TGfxLine2D aLine( aX + (ScaleAA * |
|
1901 ( TFloatFixPt ) |
|
1902 ( advanceWidth - textAdvance ) / |
|
1903 iScale), |
|
1904 aY - |
|
1905 ( TFloatFixPt ) |
|
1906 fontMaxHeight / |
|
1907 iScale, |
|
1908 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1909 ( advanceWidth + charWidth + aSpacing - textAdvance ) / |
|
1910 iScale ) ) ), |
|
1911 aY - |
|
1912 ( TFloatFixPt ) |
|
1913 fontMaxHeight / |
|
1914 iScale ); |
|
1915 DrawL( &aLine ); |
|
1916 } |
|
1917 else //Start |
|
1918 { |
|
1919 TGfxLine2D aLine( aX + (ScaleAA * |
|
1920 ( TFloatFixPt ) |
|
1921 advanceWidth / |
|
1922 iScale), |
|
1923 aY - |
|
1924 ( TFloatFixPt ) |
|
1925 fontMaxHeight / |
|
1926 iScale, |
|
1927 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1928 ( advanceWidth + charWidth + aSpacing ) / |
|
1929 iScale ) ) ), |
|
1930 aY - |
|
1931 ( TFloatFixPt ) |
|
1932 fontMaxHeight / |
|
1933 iScale ); |
|
1934 DrawL( &aLine ); |
|
1935 } |
|
1936 } |
|
1937 if ( iTextDecoration == EGfxTextDecorationLineThrough ) |
|
1938 { |
|
1939 if ( iTextAnchor == EGfxTextAnchorMiddle ) |
|
1940 { |
|
1941 TGfxLine2D aLine( aX + (ScaleAA * |
|
1942 ( TFloatFixPt ) |
|
1943 ( advanceWidth - (textAdvance >> 1) ) / |
|
1944 iScale), |
|
1945 aY - |
|
1946 ( TFloatFixPt ) |
|
1947 ( fontMaxHeight >> 1 ) / |
|
1948 iScale, |
|
1949 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1950 ( advanceWidth + charWidth + aSpacing - ( textAdvance >> 1 )) / |
|
1951 iScale ) ) ), |
|
1952 aY - |
|
1953 ( TFloatFixPt ) |
|
1954 ( fontMaxHeight >> 1 ) / |
|
1955 iScale ); |
|
1956 DrawL( &aLine ); |
|
1957 } |
|
1958 else if ( iTextAnchor == EGfxTextAnchorEnd ) |
|
1959 { |
|
1960 TGfxLine2D aLine( aX + (ScaleAA * |
|
1961 ( TFloatFixPt ) |
|
1962 ( advanceWidth - textAdvance ) / |
|
1963 iScale), |
|
1964 aY - |
|
1965 ( TFloatFixPt ) |
|
1966 ( fontMaxHeight >> 1 ) / |
|
1967 iScale, |
|
1968 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1969 ( advanceWidth + charWidth + aSpacing - textAdvance ) / |
|
1970 iScale ) ) ), |
|
1971 aY - |
|
1972 ( TFloatFixPt ) |
|
1973 ( fontMaxHeight >> 1 ) / |
|
1974 iScale ); |
|
1975 DrawL( &aLine ); |
|
1976 } |
|
1977 else //Start |
|
1978 { |
|
1979 TGfxLine2D aLine( aX + (ScaleAA * |
|
1980 ( TFloatFixPt ) |
|
1981 advanceWidth / |
|
1982 iScale), |
|
1983 aY - |
|
1984 ( TFloatFixPt ) |
|
1985 ( fontMaxHeight >> 1 ) / |
|
1986 iScale, |
|
1987 ( aX + (ScaleAA * ( ( TFloatFixPt ) |
|
1988 ( advanceWidth + charWidth + aSpacing ) / |
|
1989 iScale ) ) ), |
|
1990 aY - |
|
1991 ( TFloatFixPt ) |
|
1992 ( fontMaxHeight >> 1 ) / |
|
1993 iScale ); |
|
1994 DrawL( &aLine ); |
|
1995 } |
|
1996 } |
|
1997 advanceWidth += charWidth + aSpacing; |
|
1998 } |
|
1999 |
|
2000 if ( aMultipleXY == 1 ) |
|
2001 { |
|
2002 if ( count >= aArrayX->Count() - 1 ) |
|
2003 advanceX += charWidth; |
|
2004 } |
|
2005 } //end for(Drawing single glyph) |
|
2006 } |
|
2007 |
|
2008 // Raster image drawing |
|
2009 // -------------------------------------------------------------------------- |
|
2010 // void CGfx2dGcOpenVG::DrawImage( CFbsBitmap* aImage, |
|
2011 // --------------------------------------------------------------------------- |
|
2012 void CGfx2dGcOpenVG::DrawImage( CFbsBitmap* aImage, |
|
2013 const TGfxRectangle2D& aImageRect, |
|
2014 TBool aHasAlpha ) |
|
2015 { |
|
2016 if ( !aImage ) |
|
2017 return; |
|
2018 |
|
2019 TSize imageSize = aImage->SizeInPixels(); |
|
2020 |
|
2021 aImage->LockHeap(); |
|
2022 VGImage vgImage = CreateVGImage( aImage->DataAddress(), imageSize, aImage->DisplayMode(), EFalse ); |
|
2023 |
|
2024 aImage->UnlockHeap(); |
|
2025 |
|
2026 // Transform to flip drawing to be like screen drawing (from Cartesian) |
|
2027 TGfxAffineTransform flipTransform = TGfxAffineTransform::GetScaleInstance( 1.0f, -1.0f ); |
|
2028 |
|
2029 // Shift x=0 line to top of screen (buffer) |
|
2030 flipTransform.Translate( TFloatFixPt ( 0 ), TFloatFixPt ( -iColorBufferSize.iHeight ) ); |
|
2031 |
|
2032 // Application transformations from element |
|
2033 flipTransform.Concatenate( iTransform ); |
|
2034 |
|
2035 // Set the topleft corner of image to draw |
|
2036 flipTransform.Translate( aImageRect.iX, aImageRect.iY ); |
|
2037 |
|
2038 // Caller to DrawImage already check for image size zero |
|
2039 float scaleX = (VGfloat)( TFloatFixPt ( aImageRect.iWidth ) / TFloatFixPt ( imageSize.iWidth ) ); |
|
2040 float scaleY = (VGfloat)( TFloatFixPt ( aImageRect.iHeight ) / TFloatFixPt ( imageSize.iHeight ) ); |
|
2041 |
|
2042 // Scale to fit image to drawing area |
|
2043 flipTransform.Scale( scaleX, scaleY ); |
|
2044 |
|
2045 VGfloat matrix[] = { (VGfloat)flipTransform.iM00, (VGfloat)flipTransform.iM10, 0, |
|
2046 (VGfloat)flipTransform.iM01, (VGfloat)flipTransform.iM11, 0, |
|
2047 (VGfloat)flipTransform.iM02, (VGfloat)flipTransform.iM12, 1 }; |
|
2048 |
|
2049 iVgRenderer->vgSeti( VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE ); |
|
2050 iVgRenderer->vgLoadMatrix( matrix ); |
|
2051 |
|
2052 // Get current blend-mode |
|
2053 const TInt KBlendMode = iVgRenderer->vgGeti( VG_BLEND_MODE ); |
|
2054 |
|
2055 iVgRenderer->vgSeti( VG_BLEND_MODE, aHasAlpha ? VG_BLEND_SRC_OVER : VG_BLEND_SRC ); |
|
2056 |
|
2057 /* Disable bilinear filtering -> faster, but lower rendering quality */ |
|
2058 iVgRenderer->vgSeti( VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED ); |
|
2059 |
|
2060 iVgRenderer->vgDrawImage( vgImage ); |
|
2061 |
|
2062 iVgRenderer->vgSeti( VG_BLEND_MODE, KBlendMode ); |
|
2063 |
|
2064 iVgRenderer->vgDestroyImage( vgImage ); |
|
2065 } |
|
2066 |
|
2067 |
|
2068 // ========================================================================== |
|
2069 // Clear the whole graphics context with the background color |
|
2070 // ========================================================================== |
|
2071 // -------------------------------------------------------------------------- |
|
2072 // void CGfx2dGcOpenVG::Clear(TUint32 aRGBA8888Color) |
|
2073 // --------------------------------------------------------------------------- |
|
2074 void CGfx2dGcOpenVG::Clear(TUint32 aARGB ) |
|
2075 { |
|
2076 TUint32 rgba = ( aARGB << 8 ) | ( aARGB >> 24 ); |
|
2077 TInt32 r, g, b, a; |
|
2078 r = (TInt)((rgba & 0xFF000000) >> 24); |
|
2079 g = (TInt)((rgba & 0x00FF0000) >> 16); |
|
2080 b = (TInt)((rgba & 0x0000FF00) >> 8); |
|
2081 a = (TInt)( rgba & 0x000000FF); |
|
2082 |
|
2083 r += r >> 7; g += g >> 7; b += b >> 7; a += a >> 7; |
|
2084 |
|
2085 const TFloatFixPt KInverse255 = TFloatFixPt ( 1.0f/256.0f ); |
|
2086 const VGfloat clearColor[4] = { (VGfloat)(KInverse255 * TFloatFixPt (r)), |
|
2087 (VGfloat)(KInverse255 * TFloatFixPt (g)), |
|
2088 (VGfloat)(KInverse255 * TFloatFixPt (b)), |
|
2089 (VGfloat)(KInverse255 * TFloatFixPt (a)) }; |
|
2090 |
|
2091 iVgRenderer->vgSeti( VG_SCISSORING, VG_FALSE ); |
|
2092 iVgRenderer->vgSetfv( VG_CLEAR_COLOR, 4, clearColor ); |
|
2093 iVgRenderer->vgClear( 0, 0, iColorBufferSize.iWidth, iColorBufferSize.iHeight ); |
|
2094 iVgRenderer->vgSeti( VG_SCISSORING, VG_TRUE ); |
|
2095 } |
|
2096 |
|
2097 // ========================================================================== |
|
2098 // This method copies the internal RGBA8888 framebuffer to CfbsBitmap that |
|
2099 // is specified in constructor. The CfbsBitmap could be 4k color (RGB0444), |
|
2100 // 64k color (RGB565), or 16M color (RGB888). |
|
2101 // ========================================================================== |
|
2102 // -------------------------------------------------------------------------- |
|
2103 // void CGfx2dGcOpenVG::UpdateFramebufferL() |
|
2104 // -------------------------------------------------------------------------- |
|
2105 void CGfx2dGcOpenVG::UpdateFramebufferL( CFbsBitmap* aBitmap, CFbsBitmap* aMask) |
|
2106 { |
|
2107 if ( !aBitmap || aBitmap->SizeInPixels() != iColorBufferSize ) |
|
2108 { |
|
2109 return; |
|
2110 } |
|
2111 |
|
2112 const TDisplayMode KBitmapDisplayMode = aBitmap->DisplayMode(); |
|
2113 // This check just before VGISymbianCopyToBitmap avoid putting lot |
|
2114 // many similar error checks in the code. If there is any problem |
|
2115 // during OpenVG call we simply leave without drawing any thing. |
|
2116 VGErrorCode vgret = (VGErrorCode)iVgRenderer->vgGetError(); |
|
2117 |
|
2118 if(vgret != VG_NO_ERROR ) |
|
2119 { |
|
2120 User::LeaveIfError(OpenVGErrorToSymbianError(vgret)); |
|
2121 } |
|
2122 |
|
2123 // EGray2 is not support in VGISymbianCopyToBitmap API |
|
2124 if ( KBitmapDisplayMode == EGray2 ) |
|
2125 { |
|
2126 const TInt KStride = CFbsBitmap::ScanLineLength( iColorBufferSize.iWidth, KBitmapDisplayMode ); |
|
2127 |
|
2128 aBitmap->LockHeap(); |
|
2129 |
|
2130 // Get data address of last line and move upwards (negative stride) |
|
2131 // OpenVG uses Cartesian coordinate system and Symbian uses Screen coordinate system. |
|
2132 TUint* data = (TUint*)((TUint)aBitmap->DataAddress() + ( KStride * ( iColorBufferSize.iHeight - 1 ) ) ); |
|
2133 |
|
2134 iVgRenderer->vgReadPixels( data, -KStride, VG_BW_1, 0, 0, |
|
2135 iColorBufferSize.iWidth, iColorBufferSize.iHeight ); |
|
2136 |
|
2137 aBitmap->UnlockHeap(); |
|
2138 |
|
2139 if ( aMask ) |
|
2140 { |
|
2141 GenerateMask( aMask ); |
|
2142 } |
|
2143 } |
|
2144 // All other color modes |
|
2145 else |
|
2146 { |
|
2147 // No Mask -- to be generated in GenerateMask |
|
2148 TInt error=KErrNone; |
|
2149 |
|
2150 //In cases, where the mask/aMaskBitmap != NULL, the hint should be defined as VGI_SKIP_TRANSPARENT_PIXELS. |
|
2151 //In all other cases, i.e., when mask/aMaskBitmap == NULL, the definition should be VGI_COPY_TRANSPARENT_PIXELS |
|
2152 error = iVgSurface->CopyBitmap(ENone,ENone, aBitmap, aMask, iColorBufferSize); |
|
2153 |
|
2154 if ( error != KErrNone ) |
|
2155 { |
|
2156 #ifdef _DEBUG |
|
2157 RDebug::Printf("VGISymbianCopyToBitmap failed: error code: %d", error ); |
|
2158 RDebug::Printf(" - Color mode: %d", aBitmap->DisplayMode() ); |
|
2159 RDebug::Printf(" - Bitmap size: %dx%d", iColorBufferSize.iWidth, iColorBufferSize.iHeight ); |
|
2160 #endif |
|
2161 User::LeaveIfError(error); |
|
2162 } |
|
2163 |
|
2164 // VGISymbianCopyToBitmap only generates Gray256 mask |
|
2165 if ( aMask && aMask->DisplayMode() == EGray2 ) |
|
2166 { |
|
2167 GenerateMask( aMask ); |
|
2168 } |
|
2169 } |
|
2170 } |
|
2171 //NGA |
|
2172 // --------------------------------------------------------------------------------------------------------------------------------------- |
|
2173 //void UpdateFramebufferL( CFbsBitmap* aBitmap, CFbsBitmap* aMask,TSize BitmapSize,TDisplayMode aBitmapDspMode,TDisplayMode aMaskDspMode ) |
|
2174 // --------------------------------------------------------------------------------------------------------------------------------------- |
|
2175 |
|
2176 void CGfx2dGcOpenVG::UpdateFramebufferL( CFbsBitmap* aBitmap, CFbsBitmap* aMask,TSize /*BitmapSize*/,TDisplayMode aBitmapDspMode,TDisplayMode aMaskDspMode ) |
|
2177 { |
|
2178 if ( !aBitmap) |
|
2179 { |
|
2180 return; |
|
2181 } |
|
2182 |
|
2183 const TDisplayMode KBitmapDisplayMode = aBitmap->DisplayMode(); |
|
2184 // This check just before VGISymbianCopyToBitmap avoid putting lot |
|
2185 // many similar error checks in the code. If there is any problem |
|
2186 // during OpenVG call we simply leave without drawing any thing. |
|
2187 VGErrorCode vgret = (VGErrorCode)iVgRenderer->vgGetError(); |
|
2188 |
|
2189 if(vgret != VG_NO_ERROR ) |
|
2190 { |
|
2191 User::LeaveIfError(OpenVGErrorToSymbianError(vgret)); |
|
2192 } |
|
2193 |
|
2194 // EGray2 is not support in VGISymbianCopyToBitmap API |
|
2195 if ( KBitmapDisplayMode == EGray2 ) |
|
2196 { |
|
2197 const TInt KStride = CFbsBitmap::ScanLineLength( iColorBufferSize.iWidth, KBitmapDisplayMode ); |
|
2198 |
|
2199 aBitmap->LockHeap(); |
|
2200 |
|
2201 // Get data address of last line and move upwards (negative stride) |
|
2202 // OpenVG uses Cartesian coordinate system and Symbian uses Screen coordinate system. |
|
2203 TUint* data = (TUint*)((TUint)aBitmap->DataAddress() + ( KStride * ( iColorBufferSize.iHeight - 1 ) ) ); |
|
2204 |
|
2205 |
|
2206 iVgRenderer->vgReadPixels( data, -KStride, VG_BW_1, 0, 0, |
|
2207 iColorBufferSize.iWidth, iColorBufferSize.iHeight ); |
|
2208 |
|
2209 aBitmap->UnlockHeap(); |
|
2210 |
|
2211 if ( aMask ) |
|
2212 { |
|
2213 GenerateMask( aMask ); |
|
2214 } |
|
2215 } |
|
2216 // All other color modes |
|
2217 else |
|
2218 { |
|
2219 // No Mask -- to be generated in GenerateMask |
|
2220 TInt error=KErrNone; |
|
2221 |
|
2222 //In cases, where the mask/aMaskBitmap != NULL, the hint should be defined as VGI_SKIP_TRANSPARENT_PIXELS. |
|
2223 //In all other cases, i.e., when mask/aMaskBitmap == NULL, the definition should be VGI_COPY_TRANSPARENT_PIXELS |
|
2224 |
|
2225 error = iVgSurface->CopyBitmap(aBitmapDspMode, aMaskDspMode, aBitmap, aMask, iColorBufferSize); |
|
2226 |
|
2227 if ( error != KErrNone ) |
|
2228 { |
|
2229 #ifdef _DEBUG |
|
2230 RDebug::Printf("VGISymbianCopyToBitmap failed: error code: %d", error ); |
|
2231 RDebug::Printf(" - Color mode: %d", aBitmap->DisplayMode() ); |
|
2232 RDebug::Printf(" - Bitmap size: %dx%d", iColorBufferSize.iWidth, iColorBufferSize.iHeight ); |
|
2233 #endif |
|
2234 User::LeaveIfError(error); |
|
2235 } |
|
2236 |
|
2237 // VGISymbianCopyToBitmap only generates Gray256 mask |
|
2238 if ( aMask && aMask->DisplayMode() == EGray2 ) |
|
2239 { |
|
2240 GenerateMask( aMask ); |
|
2241 } |
|
2242 } |
|
2243 } |
|
2244 |
|
2245 // ==================================================================================== |
|
2246 // Blend bitmap with background according to group opacity |
|
2247 // This function gets called with the opacity framebuffer and the group opacity value |
|
2248 // The opacity buffer is initialized with the 0xAA55AA55 value. The pixels not matching |
|
2249 // the initialiazation value are the pixels that have to be blended with the background. |
|
2250 // ==================================================================================== |
|
2251 |
|
2252 // -------------------------------------------------------------------------- |
|
2253 // void CGfx2dGcVGR::BlendWithBackground(TUint32* aFrameBuffer, TReal32 aOpacity) |
|
2254 // --------------------------------------------------------------------------- |
|
2255 void CGfx2dGcOpenVG::BlendWithBackground(TUint32* /* aColorBuffer */, TReal32 /* aOpacity */) |
|
2256 { |
|
2257 /* |
|
2258 if ( !iColorBuffer || !aColorBuffer ) |
|
2259 { |
|
2260 return; |
|
2261 } |
|
2262 |
|
2263 TReal32 inverseAlpha = 1.0f - aOpacity; |
|
2264 const TInt KMax = iColorBufferSize.iWidth * iColorBufferSize.iHeight; |
|
2265 TUint32* dst = iColorBuffer; |
|
2266 TUint32* src = aColorBuffer; |
|
2267 |
|
2268 for ( TInt i = KMax - 1; i >= 0; i-- ) |
|
2269 { |
|
2270 TUint32 srcColor = src[i]; |
|
2271 TUint32 dstColor = dst[i]; |
|
2272 if ( srcColor != dstColor ) |
|
2273 { |
|
2274 dst[i] = ((((TUint)((srcColor >> 24 ) * aOpacity) + |
|
2275 (TUint)((dstColor >> 24 ) * inverseAlpha))) << 24) | // red |
|
2276 ((((TUint)((srcColor >> 16 & 0xff) * aOpacity) + |
|
2277 (TUint)((dstColor >> 16 & 0xff) * inverseAlpha))) << 16) | // green |
|
2278 ((((TUint)((srcColor >> 8 & 0xff) * aOpacity) + |
|
2279 (TUint)((dstColor >> 8 & 0xff) * inverseAlpha))) << 8 ) | // blue |
|
2280 (srcColor & 0x000000FF); // keep orignal alpha |
|
2281 } |
|
2282 } |
|
2283 */ |
|
2284 } |
|
2285 |
|
2286 // ========================================================================== |
|
2287 // Generate 8 bit gray or 1bit B/W mask from internal ARGB8888 frame buffer. |
|
2288 // ========================================================================== |
|
2289 // -------------------------------------------------------------------------- |
|
2290 // void CGfx2dGcOpenVG::GenerateMask(CFbsBitmap* aMask) |
|
2291 // --------------------------------------------------------------------------- |
|
2292 void CGfx2dGcOpenVG::GenerateMask(CFbsBitmap* aMask) |
|
2293 { |
|
2294 if ( !aMask || aMask->SizeInPixels() != iColorBufferSize ) |
|
2295 { |
|
2296 return; |
|
2297 } |
|
2298 |
|
2299 const TDisplayMode KMaskDisplayMode = aMask->DisplayMode(); |
|
2300 |
|
2301 if ( KMaskDisplayMode != EGray256 && KMaskDisplayMode != EGray2 ) |
|
2302 { |
|
2303 return; |
|
2304 } |
|
2305 |
|
2306 const TInt KOriginalFilterMasks = iVgRenderer->vgGeti( VG_FILTER_CHANNEL_MASK );// |
|
2307 const TInt KStride = CFbsBitmap::ScanLineLength( iColorBufferSize.iWidth, KMaskDisplayMode ); |
|
2308 |
|
2309 // Change to get alpha values from OpenVG |
|
2310 iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, VG_ALPHA ); |
|
2311 |
|
2312 VGImageFormat format = ( KMaskDisplayMode == EGray256 ) ? VG_A_8 : VG_BW_1; |
|
2313 |
|
2314 aMask->LockHeap(); |
|
2315 |
|
2316 // Get data address of last line and move upwards (negative stride) |
|
2317 // OpenVG uses Cartesian coordinate system and Symbian uses Screen coordinate system. |
|
2318 TUint* data = (TUint*)((TUint)aMask->DataAddress() + ( KStride * ( iColorBufferSize.iHeight - 1 ) ) ); |
|
2319 |
|
2320 iVgRenderer->vgReadPixels( data, -KStride, format, 0, 0, |
|
2321 iColorBufferSize.iWidth, iColorBufferSize.iHeight ); |
|
2322 aMask->UnlockHeap(); |
|
2323 |
|
2324 // Set back the original filter-masks |
|
2325 iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, KOriginalFilterMasks ); |
|
2326 } |
|
2327 |
|
2328 |
|
2329 // ========================================================================== |
|
2330 // This function calls the low level function to set fill opacity value |
|
2331 // ========================================================================== |
|
2332 |
|
2333 // -------------------------------------------------------------------------- |
|
2334 // void CGfx2dGcOpenVG::SetFillOpacity(TFloatFixPt aFillOpacity) |
|
2335 // --------------------------------------------------------------------------- |
|
2336 void CGfx2dGcOpenVG::SetFillOpacity(TFloatFixPt aFillOpacity) |
|
2337 { |
|
2338 iFillOpacity = aFillOpacity; |
|
2339 } |
|
2340 // ========================================================================== |
|
2341 // This function calls the low level function to set stroke opacity value |
|
2342 // ========================================================================== |
|
2343 |
|
2344 // -------------------------------------------------------------------------- |
|
2345 // void CGfx2dGcOpenVG::SetStrokeOpacity(TFloatFixPt aStrokeOpacity) |
|
2346 // --------------------------------------------------------------------------- |
|
2347 void CGfx2dGcOpenVG::SetStrokeOpacity(TFloatFixPt aStrokeOpacity) |
|
2348 { |
|
2349 iStrokeOpacity = aStrokeOpacity; |
|
2350 } |
|
2351 // ========================================================================== |
|
2352 // This function is called to set the dithering flag |
|
2353 // ========================================================================== |
|
2354 |
|
2355 // -------------------------------------------------------------------------- |
|
2356 // void CGfx2dGcOpenVG::SetDoDithering( TBool aDoDithering ) |
|
2357 // --------------------------------------------------------------------------- |
|
2358 void CGfx2dGcOpenVG::SetDoDithering( TBool /*aDoDithering*/ ) |
|
2359 { |
|
2360 } |
|
2361 |
|
2362 // -------------------------------------------------------------------------- |
|
2363 // void CGfx2dGcOpenVG::ApplyTransform |
|
2364 // --------------------------------------------------------------------------- |
|
2365 void CGfx2dGcOpenVG::ApplyTransform( TGfxAffineTransform& aAffineTransform ) |
|
2366 { |
|
2367 iVgRenderer->vgSeti( VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE ); |
|
2368 |
|
2369 TUint transformType = aAffineTransform.iTransType; |
|
2370 |
|
2371 // Only translation is applied |
|
2372 if ( transformType == KTransformTranslate ) |
|
2373 { |
|
2374 iVgRenderer->vgLoadIdentity(); |
|
2375 iVgRenderer->vgScale( 1.0f, -1.0f ); |
|
2376 iVgRenderer->vgTranslate( (VGfloat)aAffineTransform.iM02, |
|
2377 (VGfloat)(TFloatFixPt (-iColorBufferSize.iHeight) + aAffineTransform.iM12 ) ); |
|
2378 } |
|
2379 // General case: Rotate and/or scaling, translation |
|
2380 else |
|
2381 { |
|
2382 TGfxAffineTransform flipTransform = TGfxAffineTransform::GetScaleInstance( 1.0f, -1.0f ); |
|
2383 flipTransform.Translate( TFloatFixPt ( 0 ), TFloatFixPt ( -iColorBufferSize.iHeight ) ); |
|
2384 flipTransform.Concatenate( aAffineTransform ); |
|
2385 |
|
2386 VGfloat matrix[] = { (VGfloat)flipTransform.iM00, (VGfloat)flipTransform.iM10, 0, |
|
2387 (VGfloat)flipTransform.iM01, (VGfloat)flipTransform.iM11, 0, |
|
2388 (VGfloat)flipTransform.iM02, (VGfloat)flipTransform.iM12, 1 }; |
|
2389 iVgRenderer->vgLoadMatrix( matrix ); |
|
2390 } |
|
2391 } |
|
2392 void CGfx2dGcOpenVG::ApplyTransformMediaElement( const TGfxAffineTransform& aAffineTransform,TSize& /*aSize*/ ) |
|
2393 { |
|
2394 iVgRenderer->vgSeti( VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE ); |
|
2395 |
|
2396 // TUint transformType = aAffineTransform.iTransType; |
|
2397 |
|
2398 // Only translation is applied |
|
2399 /* if ( transformType == KTransformTranslate ) |
|
2400 { |
|
2401 vgLoadIdentity(); |
|
2402 vgScale( 1.0f, -1.0f ); |
|
2403 vgTranslate( (VGfloat)aAffineTransform.iM02, |
|
2404 (VGfloat)(TFloatFixPt (-iColorBufferSize.iHeight) + aAffineTransform.iM12 ) ); |
|
2405 } |
|
2406 // General case: Rotate and/or scaling, translation |
|
2407 else |
|
2408 { |
|
2409 TGfxAffineTransform flipTransform = TGfxAffineTransform::GetScaleInstance( 1.0f, -1.0f ); |
|
2410 flipTransform.Translate( TFloatFixPt ( 0 ), TFloatFixPt ( -iColorBufferSize.iHeight ) ); |
|
2411 flipTransform.Concatenate( aAffineTransform ); |
|
2412 |
|
2413 VGfloat matrix[] = { (VGfloat)flipTransform.iM00, (VGfloat)flipTransform.iM10, 0, |
|
2414 (VGfloat)flipTransform.iM01, (VGfloat)flipTransform.iM11, 0, |
|
2415 (VGfloat)flipTransform.iM02, (VGfloat)flipTransform.iM12, 1 }; |
|
2416 vgLoadMatrix( matrix ); |
|
2417 }*/ |
|
2418 TGfxAffineTransform flipTransform = TGfxAffineTransform::GetScaleInstance( 1.0f, -1.0f ); |
|
2419 flipTransform.Translate( TFloatFixPt ( 0 ), TFloatFixPt ( -iColorBufferSize.iHeight ) ); |
|
2420 //flipTransform.Concatenate( aAffineTransform ); |
|
2421 TGfxAffineTransform flipTransformTemp = aAffineTransform; |
|
2422 flipTransformTemp.Concatenate( flipTransform ); |
|
2423 flipTransform.Concatenate( flipTransformTemp ); |
|
2424 |
|
2425 |
|
2426 VGfloat matrix[] = { (VGfloat)flipTransform.iM00, (VGfloat)flipTransform.iM10, 0, |
|
2427 (VGfloat)flipTransform.iM01, (VGfloat)flipTransform.iM11, 0, |
|
2428 (VGfloat)flipTransform.iM02, (VGfloat)flipTransform.iM12, 1 }; |
|
2429 iVgRenderer->vgLoadMatrix( matrix ); |
|
2430 } |
|
2431 |
|
2432 VGImage CGfx2dGcOpenVG::CreateVGImage( void* aBuffer, TSize aSize, TDisplayMode aDisplayMode, TBool aPreMultiplied ) |
|
2433 { |
|
2434 VGImage vgImage = VGImage( -1 ); |
|
2435 |
|
2436 if ( aBuffer ) |
|
2437 { |
|
2438 VGint stride = CFbsBitmap::ScanLineLength( aSize.iWidth, aDisplayMode ); |
|
2439 |
|
2440 if ( aDisplayMode == EColor64K ) |
|
2441 { |
|
2442 vgImage = iVgRenderer->vgCreateImage( VG_sRGB_565, aSize.iWidth, aSize.iHeight, VG_IMAGE_QUALITY_FASTER ); |
|
2443 iVgRenderer->vgImageSubData( vgImage, aBuffer, stride, VG_sRGB_565, |
|
2444 0, 0, aSize.iWidth, aSize.iHeight ); |
|
2445 } |
|
2446 else if ( aDisplayMode == EColor16MU ) |
|
2447 { |
|
2448 VGImageFormat format = aPreMultiplied ? VG_sRGBA_8888_PRE :VG_sRGBA_8888; |
|
2449 vgImage = iVgRenderer->vgCreateImage( format, aSize.iWidth, aSize.iHeight, VG_IMAGE_QUALITY_FASTER ); |
|
2450 iVgRenderer->vgImageSubData( vgImage, aBuffer, stride, format, |
|
2451 0, 0, aSize.iWidth, aSize.iHeight ); |
|
2452 } |
|
2453 else |
|
2454 { |
|
2455 #ifdef _DEBUG |
|
2456 RDebug::Printf("SVGT CreateVGImage:: Color Mode not supported: %d ", aDisplayMode ); |
|
2457 #endif |
|
2458 } |
|
2459 } |
|
2460 |
|
2461 return vgImage; |
|
2462 } |
|
2463 |
|
2464 void CGfx2dGcOpenVG::BindToImageL() |
|
2465 { |
|
2466 TUint32* buffer = NULL; |
|
2467 buffer = new (ELeave) TUint32[ iColorBufferSize.iWidth * iColorBufferSize.iHeight ] ; |
|
2468 |
|
2469 iVgSurface->PrepareToBindClientBuffer(); |
|
2470 VGImage vgImage = CreateVGImage( buffer, iColorBufferSize, EColor16MU, ETrue ); |
|
2471 //Clear VGImage |
|
2472 VGfloat color[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; |
|
2473 iVgRenderer->vgSetfv(VG_CLEAR_COLOR, 4, color); |
|
2474 iVgRenderer->vgClearImage(vgImage,0,0,iColorBufferSize.iWidth,iColorBufferSize.iHeight); |
|
2475 //Clear VGImage |
|
2476 TInt error = iVgSurface->BindClientBuffer( vgImage ); |
|
2477 if ( error != KErrNone ) |
|
2478 { |
|
2479 #ifdef _DEBUG |
|
2480 RDebug::Printf("SVGT CGfx2dGcOpenVG::BindToImageL--VGISymbianBindToImageL failed: %d", error); |
|
2481 #endif |
|
2482 |
|
2483 iVgRenderer->vgDestroyImage(vgImage) ; |
|
2484 // Delete color-buffer to match count with vgImage |
|
2485 delete[] buffer; |
|
2486 |
|
2487 if( error == KErrNoMemory ) |
|
2488 { |
|
2489 // Need to reset values at our side as OpenVG calls VGISymbianTerminate. |
|
2490 ResetContextHandle(); |
|
2491 } |
|
2492 |
|
2493 User::Leave(error); |
|
2494 } |
|
2495 |
|
2496 iGroupOpacityBuffers.Append( buffer ); |
|
2497 iGroupOpacityImages.Append( vgImage ); |
|
2498 |
|
2499 iVgRenderer->vgLoadIdentity(); |
|
2500 } |
|
2501 |
|
2502 |
|
2503 void CGfx2dGcOpenVG::BindToMediaImageL(TInt aWidth, TInt aHeight) |
|
2504 { |
|
2505 TUint32* buffer = NULL; |
|
2506 buffer = new (ELeave) TUint32[ iColorBufferSize.iWidth * iColorBufferSize.iHeight ]; |
|
2507 |
|
2508 iVgSurface->PrepareToBindClientBuffer(); |
|
2509 VGImage vgImage = CreateVGImage( buffer, iColorBufferSize, EColor16MU, ETrue ); |
|
2510 VGfloat color[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; |
|
2511 iVgRenderer->vgSetfv(VG_CLEAR_COLOR, 4, color); |
|
2512 iVgRenderer->vgClearImage(vgImage,0,0,iColorBufferSize.iWidth,iColorBufferSize.iHeight); |
|
2513 //vgClearImage(vgImage,0,0,aWidth,aHeight); |
|
2514 TInt error = iVgSurface->BindClientBuffer( vgImage ); |
|
2515 if ( error != KErrNone ) |
|
2516 { |
|
2517 #ifdef _DEBUG |
|
2518 RDebug::Printf("SVGT CGfx2dGcOpenVG::BindToImage--VGISymbianBindToImage failed: %d", error); |
|
2519 #endif |
|
2520 |
|
2521 iVgRenderer->vgDestroyImage(vgImage) ; |
|
2522 // Delete color-buffer to match count with vgImage |
|
2523 delete[] buffer; |
|
2524 |
|
2525 if( error == KErrNoMemory ) |
|
2526 { |
|
2527 // Need to reset values at our side as OpenVG calls VGISymbianTerminate. |
|
2528 ResetContextHandle(); |
|
2529 } |
|
2530 |
|
2531 User::Leave(error); |
|
2532 } |
|
2533 |
|
2534 iGroupOpacityBuffers.Append( buffer ); |
|
2535 iGroupOpacityImages.Append( vgImage ); |
|
2536 iVgRenderer->vgLoadIdentity(); |
|
2537 |
|
2538 TGfxRectangle2D aClip(0,0,aWidth,aHeight); |
|
2539 iClipMain = iClip; |
|
2540 SetClip(aClip); |
|
2541 } |
|
2542 |
|
2543 void CGfx2dGcOpenVG::UnbindFromImageL( TReal32 aOpacity ) |
|
2544 { |
|
2545 if ( iGroupOpacityImages.Count() == 0 ) |
|
2546 { |
|
2547 return; |
|
2548 } |
|
2549 |
|
2550 TInt error = iVgSurface->UnBindClientBuffer(); |
|
2551 if ( error != KErrNone ) |
|
2552 { |
|
2553 #ifdef _DEBUG |
|
2554 RDebug::Printf("SVGT CGfx2dGcOpenVG::UnbindFromImage--VGISymbianUnBindImage failed: %d", error); |
|
2555 #endif |
|
2556 |
|
2557 if( error == KErrNoMemory ) |
|
2558 { |
|
2559 // Need to reset values at our side as OpenVG calls VGITerminate. |
|
2560 ResetContextHandle(); |
|
2561 } |
|
2562 User::LeaveIfError(error); |
|
2563 } |
|
2564 |
|
2565 // Need to bind to previous level image |
|
2566 // Else VGISymbianUnBindImage binds to non-image |
|
2567 if ( iGroupOpacityImages.Count() > 1 ) |
|
2568 { |
|
2569 iVgSurface->PrepareToBindClientBuffer(); |
|
2570 TInt error = iVgSurface->BindClientBuffer( iGroupOpacityImages[iGroupOpacityImages.Count()-2] ); |
|
2571 if ( error != KErrNone ) |
|
2572 { |
|
2573 #ifdef _DEBUG |
|
2574 RDebug::Printf("SVGT CGfx2dGcOpenVG::UnbindFromImage--VGISymbianBindToImage failed: %d", error); |
|
2575 #endif |
|
2576 |
|
2577 iVgSurface->UnBindClientBuffer(); |
|
2578 |
|
2579 // Remove and Destroy all the previous images and buffer |
|
2580 TInt iIndex = iGroupOpacityImages.Count()-1; |
|
2581 for( ;iIndex >= 0 ; iIndex-- ) |
|
2582 { |
|
2583 iVgRenderer->vgDestroyImage( iGroupOpacityImages[ iIndex ] ); |
|
2584 iGroupOpacityImages.Remove( iIndex ); |
|
2585 } |
|
2586 |
|
2587 iIndex = iGroupOpacityBuffers.Count()-1; |
|
2588 for( ;iIndex >= 0 ; iIndex-- ) |
|
2589 { |
|
2590 delete [] iGroupOpacityBuffers[ iIndex ]; |
|
2591 iGroupOpacityBuffers.Remove( iIndex ); |
|
2592 } |
|
2593 |
|
2594 if( error == KErrNoMemory ) |
|
2595 { |
|
2596 // Need to reset values at our side as OpenVG calls VGISymbianTerminate. |
|
2597 ResetContextHandle(); |
|
2598 } |
|
2599 |
|
2600 User::LeaveIfError(error); |
|
2601 } |
|
2602 } |
|
2603 |
|
2604 // Check if default fill paint needs to be created |
|
2605 if ( iFillPaint == VG_INVALID_HANDLE ) |
|
2606 { |
|
2607 iFillPaint = iVgRenderer->vgCreatePaint(); |
|
2608 } |
|
2609 |
|
2610 // Check if default stroke paint needs to be created |
|
2611 if ( iStrokePaint == VG_INVALID_HANDLE ) |
|
2612 { |
|
2613 iStrokePaint = iVgRenderer->vgCreatePaint(); |
|
2614 } |
|
2615 |
|
2616 VGfloat opaquePaint[] = { 1.0f, 1.0f, 1.0f, aOpacity }; |
|
2617 |
|
2618 // Create paint object |
|
2619 VGPaint paint = iVgRenderer->vgCreatePaint(); |
|
2620 |
|
2621 if ( paint != VG_INVALID_HANDLE ) |
|
2622 { |
|
2623 |
|
2624 // Set solid paint of opacity |
|
2625 iVgRenderer->vgSetParameteri( paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); |
|
2626 iVgRenderer->vgSetParameterfv( paint, VG_PAINT_COLOR, 4, opaquePaint); |
|
2627 iVgRenderer->vgSetPaint( paint, VG_FILL_PATH | VG_STROKE_PATH ); |
|
2628 |
|
2629 // Set image mode to multiply |
|
2630 iVgRenderer->vgSeti( VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY ); |
|
2631 |
|
2632 // Draw opacity image |
|
2633 iVgRenderer->vgSeti( VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE ); |
|
2634 iVgRenderer->vgLoadIdentity(); |
|
2635 iVgRenderer->vgDrawImage( iGroupOpacityImages[iGroupOpacityImages.Count()-1] ); |
|
2636 |
|
2637 // Reset the image draw mode |
|
2638 iVgRenderer->vgSeti( VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL ); |
|
2639 |
|
2640 // Restore the fill and paint |
|
2641 if ( iFillPaint != VG_INVALID_HANDLE ) |
|
2642 { |
|
2643 iVgRenderer->vgSetPaint( iFillPaint, VG_FILL_PATH ); |
|
2644 } |
|
2645 |
|
2646 if ( iStrokePaint != VG_INVALID_HANDLE ) |
|
2647 { |
|
2648 iVgRenderer->vgSetPaint( iStrokePaint, VG_STROKE_PATH ); |
|
2649 } |
|
2650 |
|
2651 iVgRenderer->vgDestroyPaint( paint ); |
|
2652 } |
|
2653 else |
|
2654 { |
|
2655 VGErrorCode error = (VGErrorCode)iVgRenderer->vgGetError(); |
|
2656 if (error == VG_OUT_OF_MEMORY_ERROR) |
|
2657 { |
|
2658 RDebug::Printf("SVGT CGfx2dGcOpenVG::UnbindFromImage vgCreatePaint OOM"); |
|
2659 // Remove and Destroy all the previous images and buffer |
|
2660 TInt iIndex = iGroupOpacityImages.Count()-1; |
|
2661 for( ;iIndex >= 0 ; iIndex-- ) |
|
2662 { |
|
2663 iVgRenderer->vgDestroyImage( iGroupOpacityImages[ iIndex ] ); |
|
2664 iGroupOpacityImages.Remove( iIndex ); |
|
2665 } |
|
2666 |
|
2667 iIndex = iGroupOpacityBuffers.Count()-1; |
|
2668 for( ;iIndex >= 0 ; iIndex-- ) |
|
2669 { |
|
2670 delete [] iGroupOpacityBuffers[ iIndex ]; |
|
2671 iGroupOpacityBuffers.Remove( iIndex ); |
|
2672 } |
|
2673 ResetContextHandle(); |
|
2674 User::Leave(KErrNoMemory); |
|
2675 } |
|
2676 #ifdef _DEBUG |
|
2677 RDebug::Printf("SVGT CGfx2dGcOpenVG::UnbindFromImage vgCreatePaint failed"); |
|
2678 #endif |
|
2679 } |
|
2680 |
|
2681 // Remove/Delete OpenVG Image object |
|
2682 TInt imageIndex = iGroupOpacityImages.Count() - 1; |
|
2683 if ( imageIndex >= 0 ) |
|
2684 { |
|
2685 iVgRenderer->vgDestroyImage( iGroupOpacityImages[ imageIndex ] ); |
|
2686 iGroupOpacityImages.Remove( imageIndex ); |
|
2687 } |
|
2688 |
|
2689 // Remove/Delete color-buffer |
|
2690 TInt bufferIndex = iGroupOpacityBuffers.Count() - 1; |
|
2691 if ( bufferIndex >= 0 ) |
|
2692 { |
|
2693 delete [] iGroupOpacityBuffers[ bufferIndex ]; |
|
2694 iGroupOpacityBuffers.Remove( bufferIndex ); |
|
2695 } |
|
2696 |
|
2697 } |
|
2698 |
|
2699 // -------------------------------------------------------------------------- |
|
2700 // void CGfx2dGcOpenVG::UnbindFromMediaImageL( |
|
2701 // const TGfxAffineTransform& aAffineTransform, |
|
2702 // TReal32 aOpacity, |
|
2703 // TInt aWidth, |
|
2704 // TInt aHeight ) |
|
2705 // --------------------------------------------------------------------------- |
|
2706 void CGfx2dGcOpenVG::UnbindFromMediaImageL( |
|
2707 const TGfxAffineTransform& aAffineTransform, |
|
2708 TReal32 aOpacity, |
|
2709 TInt aWidth, |
|
2710 TInt aHeight, TInt aDraw ) |
|
2711 { |
|
2712 if ( iGroupOpacityImages.Count() == 0 ) |
|
2713 { |
|
2714 return; |
|
2715 } |
|
2716 |
|
2717 TInt error = iVgSurface->UnBindClientBuffer(); |
|
2718 if ( error != KErrNone ) |
|
2719 { |
|
2720 #ifdef _DEBUG |
|
2721 RDebug::Printf( "SVGT CGfx2dGcOpenVG::UnbindFromMediaImage--VGISymbianUnBindImage failed: %d", error); |
|
2722 #endif |
|
2723 if( error == KErrNoMemory ) |
|
2724 { |
|
2725 // Need to reset values at our side as OpenVG calls |
|
2726 // VGITerminate. |
|
2727 ResetContextHandle(); |
|
2728 } |
|
2729 User::LeaveIfError(error); |
|
2730 } |
|
2731 |
|
2732 // Restore the clipping window back to main window |
|
2733 SetClip(iClipMain); |
|
2734 |
|
2735 // Need to bind to previous level image |
|
2736 // Else VGISymbianUnBindImage binds to non-image |
|
2737 if ( iGroupOpacityImages.Count() > 1 ) |
|
2738 { |
|
2739 iVgSurface->PrepareToBindClientBuffer(); |
|
2740 TInt error = iVgSurface->BindClientBuffer( iGroupOpacityImages[iGroupOpacityImages.Count()-2] ); |
|
2741 if ( error != KErrNone ) |
|
2742 { |
|
2743 #ifdef _DEBUG |
|
2744 RDebug::Printf("SVGT CGfx2dGcOpenVG::UnbindFromMediaImage--VGISymbianBindToImage failed: %d", error); |
|
2745 #endif |
|
2746 |
|
2747 iVgSurface->UnBindClientBuffer(); |
|
2748 |
|
2749 // Remove and Destroy all the previous images and buffer |
|
2750 TInt iIndex = iGroupOpacityImages.Count()-1; |
|
2751 for( ;iIndex >= 0 ; iIndex-- ) |
|
2752 { |
|
2753 iVgRenderer->vgDestroyImage( iGroupOpacityImages[ iIndex ] ); |
|
2754 iGroupOpacityImages.Remove( iIndex ); |
|
2755 } |
|
2756 |
|
2757 iIndex = iGroupOpacityBuffers.Count()-1; |
|
2758 for( ;iIndex >= 0 ; iIndex-- ) |
|
2759 { |
|
2760 delete [] iGroupOpacityBuffers[ iIndex ]; |
|
2761 iGroupOpacityBuffers.Remove( iIndex ); |
|
2762 } |
|
2763 |
|
2764 // Destroy the Previous two Opacity buffer |
|
2765 if( error == KErrNoMemory ) |
|
2766 { |
|
2767 // Need to reset values at our side as OpenVG calls VGISymbianTerminate. |
|
2768 ResetContextHandle(); |
|
2769 } |
|
2770 |
|
2771 User::LeaveIfError(error); |
|
2772 } |
|
2773 } |
|
2774 |
|
2775 // Create opaque paint |
|
2776 VGfloat opaquePaint[] = { 1.0f, 1.0f, 1.0f, aOpacity }; |
|
2777 |
|
2778 // Check if default fill paint needs to be created |
|
2779 if ( iFillPaint == VG_INVALID_HANDLE ) |
|
2780 { |
|
2781 iFillPaint = iVgRenderer->vgCreatePaint(); |
|
2782 } |
|
2783 |
|
2784 // Check if default stroke paint needs to be created |
|
2785 if ( iStrokePaint == VG_INVALID_HANDLE ) |
|
2786 { |
|
2787 iStrokePaint = iVgRenderer->vgCreatePaint(); |
|
2788 } |
|
2789 |
|
2790 // Create paint object |
|
2791 VGPaint paint = iVgRenderer->vgCreatePaint(); |
|
2792 |
|
2793 if ( paint != VG_INVALID_HANDLE ) |
|
2794 { |
|
2795 // Set solid paint of opacity |
|
2796 iVgRenderer->vgSetParameteri( paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); |
|
2797 iVgRenderer->vgSetParameterfv( paint, VG_PAINT_COLOR, 4, opaquePaint); |
|
2798 iVgRenderer->vgSetPaint( paint, VG_FILL_PATH | VG_STROKE_PATH ); |
|
2799 |
|
2800 // Set image mode to normal |
|
2801 iVgRenderer->vgSeti( VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL ); |
|
2802 |
|
2803 // Draw the animation element with transforms applied on the |
|
2804 // main colour buffer |
|
2805 TSize size(aWidth,aHeight); |
|
2806 ApplyTransformMediaElement(aAffineTransform,size); |
|
2807 |
|
2808 // Check so that animation element is drawn only when animation has started |
|
2809 if ( aDraw == KMediaAnimationVisible ) |
|
2810 { |
|
2811 iVgRenderer->vgDrawImage( iGroupOpacityImages[iGroupOpacityImages.Count()-1] ); |
|
2812 } |
|
2813 |
|
2814 |
|
2815 // Restore the fill and paint |
|
2816 if ( iFillPaint != VG_INVALID_HANDLE ) |
|
2817 { |
|
2818 iVgRenderer->vgSetPaint( iFillPaint, VG_FILL_PATH ); |
|
2819 } |
|
2820 |
|
2821 if ( iStrokePaint != VG_INVALID_HANDLE ) |
|
2822 { |
|
2823 iVgRenderer->vgSetPaint( iStrokePaint, VG_STROKE_PATH ); |
|
2824 } |
|
2825 |
|
2826 iVgRenderer->vgDestroyPaint( paint ); |
|
2827 } |
|
2828 else |
|
2829 { |
|
2830 VGErrorCode error = (VGErrorCode)iVgRenderer->vgGetError(); |
|
2831 if (error == VG_OUT_OF_MEMORY_ERROR) |
|
2832 { |
|
2833 RDebug::Printf("SVGT CGfx2dGcOpenVG::UnbindFromMediaImage vgCreatePaint OOM"); |
|
2834 // Remove and Destroy all the previous images and buffer |
|
2835 TInt iIndex = iGroupOpacityImages.Count()-1; |
|
2836 for( ;iIndex >= 0 ; iIndex-- ) |
|
2837 { |
|
2838 iVgRenderer->vgDestroyImage( iGroupOpacityImages[ iIndex ] ); |
|
2839 iGroupOpacityImages.Remove( iIndex ); |
|
2840 } |
|
2841 |
|
2842 iIndex = iGroupOpacityBuffers.Count()-1; |
|
2843 for( ;iIndex >= 0 ; iIndex-- ) |
|
2844 { |
|
2845 delete [] iGroupOpacityBuffers[ iIndex ]; |
|
2846 iGroupOpacityBuffers.Remove( iIndex ); |
|
2847 } |
|
2848 ResetContextHandle(); |
|
2849 User::Leave(KErrNoMemory); |
|
2850 } |
|
2851 #ifdef _DEBUG |
|
2852 RDebug::Printf("SVGT CGfx2dGcOpenVG::UnbindFromMediaImage vgCreatePaint failed"); |
|
2853 #endif |
|
2854 } |
|
2855 // Remove/Delete OpenVG Image object |
|
2856 TInt imageIndex = iGroupOpacityImages.Count() - 1; |
|
2857 if ( imageIndex >= 0 ) |
|
2858 { |
|
2859 iVgRenderer->vgDestroyImage( iGroupOpacityImages[ imageIndex ] ); |
|
2860 iGroupOpacityImages.Remove( imageIndex ); |
|
2861 } |
|
2862 |
|
2863 // Remove/Delete color-buffer |
|
2864 TInt bufferIndex = iGroupOpacityBuffers.Count() - 1; |
|
2865 if ( bufferIndex >= 0 ) |
|
2866 { |
|
2867 delete [] iGroupOpacityBuffers[ bufferIndex ]; |
|
2868 iGroupOpacityBuffers.Remove( bufferIndex ); |
|
2869 } |
|
2870 |
|
2871 } |
|
2872 // These are for work-around for OpenVG to simulate multiple contexts |
|
2873 void CGfx2dGcOpenVG::SetupContextL() |
|
2874 { |
|
2875 // Ensure OpenVG is initialized: could have been terminated by another Svg engine |
|
2876 // Returns immediately if already initialized |
|
2877 TInt err = iVgSurface->InitializeSurface( iColorBufferSize, VGI_COLORSPACE_SRGB );//NGA --- testing purpose//srikanth |
|
2878 if (!((err == KErrNone) || (err == KErrAlreadyExists))) |
|
2879 { |
|
2880 #ifdef _DEBUG |
|
2881 RDebug::Printf("SVG can't initialize OpenVG Context %d", err); |
|
2882 #endif |
|
2883 iGraphicsContextCreated = EFalse; |
|
2884 User::Leave(err); |
|
2885 } |
|
2886 |
|
2887 iGraphicsContextCreated = ETrue; |
|
2888 // Ensure context size is correct: could have been change by another Svg engine |
|
2889 // Returns immediately if size is the same |
|
2890 |
|
2891 err = iVgSurface->ResizeSurface( iColorBufferSize ); |
|
2892 |
|
2893 if( err != KErrNone ) |
|
2894 { |
|
2895 if(err == KErrNoMemory ) |
|
2896 { |
|
2897 #ifdef _DEBUG |
|
2898 RDebug::Printf("OpenVG Context destroyed %d", err); |
|
2899 #endif //_DEBUG |
|
2900 // This indicates that OpenVG has destroyed the current context handle |
|
2901 // and also the Path, StrokePaint and FillPaint handles are no more valid. |
|
2902 // Thus reinitialize them to 0, so that they can be recreated. |
|
2903 ResetContextHandle(); |
|
2904 } |
|
2905 |
|
2906 #ifdef _DEBUG |
|
2907 RDebug::Printf("SVG can't RESIZE OpenVG Context %d", err); |
|
2908 #endif //_DEBUG |
|
2909 User::Leave(err); |
|
2910 } |
|
2911 } |
|
2912 |
|
2913 void CGfx2dGcOpenVG::Flush() |
|
2914 { |
|
2915 if (iCurrentRendererType == ESVGRendererTLV) |
|
2916 { |
|
2917 iPath = VG_INVALID_HANDLE; |
|
2918 iFillPaint = VG_INVALID_HANDLE; |
|
2919 iStrokePaint = VG_INVALID_HANDLE; |
|
2920 } |
|
2921 |
|
2922 iVgRenderer->vgFlush(); |
|
2923 } |
|
2924 /** |
|
2925 * Sets the Paint,Stroke and Path handle back to VG_INVALID_HANDLE |
|
2926 * |
|
2927 * @since |
|
2928 * @return void |
|
2929 */ |
|
2930 void CGfx2dGcOpenVG::ResetContextHandle() |
|
2931 { |
|
2932 iPath = VG_INVALID_HANDLE; |
|
2933 iFillPaint = VG_INVALID_HANDLE; |
|
2934 iStrokePaint = VG_INVALID_HANDLE; |
|
2935 iGraphicsContextCreated = EFalse; |
|
2936 } |
|
2937 |
|
2938 void CGfx2dGcOpenVG::GetMatrix(TReal32 * m) |
|
2939 { |
|
2940 //Below is the replacement for vgGetMatrix |
|
2941 TGfxAffineTransform flipTransform; |
|
2942 if ( iTransform.iTransType == KTransformTranslate ) |
|
2943 { |
|
2944 |
|
2945 flipTransform = TGfxAffineTransform::GetScaleInstance( 1.0f, -1.0f );//get and identity matrix and scale the x,y axis to (1,-1) |
|
2946 flipTransform.Translate((VGfloat)iTransform.iM02, (VGfloat)(TFloatFixPt (-iColorBufferSize.iHeight) + iTransform.iM12 ) ); |
|
2947 |
|
2948 m[0] = (VGfloat)flipTransform.iM00; |
|
2949 m[1] = (VGfloat)flipTransform.iM10; |
|
2950 m[2] = 0; |
|
2951 m[3] = (VGfloat)flipTransform.iM01; |
|
2952 m[4] = (VGfloat)flipTransform.iM11; |
|
2953 m[5] = 0; |
|
2954 m[6] = (VGfloat)flipTransform.iM02; |
|
2955 m[7] = (VGfloat)flipTransform.iM12; |
|
2956 m[8] = 1; |
|
2957 |
|
2958 } |
|
2959 // General case: Rotate and/or scaling, translation |
|
2960 else |
|
2961 { |
|
2962 flipTransform = TGfxAffineTransform::GetScaleInstance( 1.0f, -1.0f ); |
|
2963 flipTransform.Translate( TFloatFixPt ( 0 ), TFloatFixPt ( -iColorBufferSize.iHeight ) ); |
|
2964 flipTransform.Concatenate( iTransform ); |
|
2965 |
|
2966 m[0] = (VGfloat)flipTransform.iM00; |
|
2967 m[1] = (VGfloat)flipTransform.iM10; |
|
2968 m[2] = 0; |
|
2969 m[3] = (VGfloat)flipTransform.iM01; |
|
2970 m[4] = (VGfloat)flipTransform.iM11; |
|
2971 m[5] = 0; |
|
2972 m[6] = (VGfloat)flipTransform.iM02; |
|
2973 m[7] = (VGfloat)flipTransform.iM12; |
|
2974 m[8] = 1; |
|
2975 |
|
2976 } |
|
2977 |
|
2978 } |
|
2979 |
|
2980 void CGfx2dGcOpenVG::SetBitmapHeader(const TDesC* aHeaderData) |
|
2981 { |
|
2982 iVgSurface->SetConfiguration(CVGSurface::BTIMAP_HEADER, aHeaderData); |
|
2983 } |
|
2984 |
|
2985 const TPtrC8 CGfx2dGcOpenVG::TLVEncodedData() const |
|
2986 { |
|
2987 return(iVgRenderer->TLVEncodedData()); |
|
2988 } |