--- a/svgtopt/gfx2d/src/GfxGc/Gfx2dGcOpenVG.cpp Tue May 11 17:02:26 2010 +0300
+++ b/svgtopt/gfx2d/src/GfxGc/Gfx2dGcOpenVG.cpp Tue Aug 31 16:06:58 2010 +0300
@@ -48,6 +48,7 @@
// OpenVG API Binding Symbian specific
#include <vg/vgcontext_symbian.h>
+#include <svgtbitmap.h>
// For allocating path segment type array
// Found 130 to be max size at bootup
const TInt KPathSegmentTypeInitialSize = 130;
@@ -61,20 +62,21 @@
// --------------------------------------------------------------------------
// CGfx2dGcOpenVG::CGfx2dGcOpenVG() : iScale( 1 ),
// ---------------------------------------------------------------------------
-CGfx2dGcOpenVG::CGfx2dGcOpenVG( TBool /* aIsMainContext */ ) :
+CGfx2dGcOpenVG::CGfx2dGcOpenVG( TBool aRenderOption ) :
+ iRenderOption(aRenderOption),
+ iGraphicsContextCreated( EFalse ),
iFillOpacity( 1 ),
iScale( 1 ),
iStrokeColor( 0 ),
iStrokeOpacity( 1 ),
iBackgroundColor( 0xffffff ),
- iFontSize( 10 ),
- iFontWeight( -1 ),
- iFontStyle( -1 ),
- iFamilies( NULL ),
- iTextAnchor( EGfxTextAnchorNone ),
- iTextDecoration( EGfxTextDecorationNone ),
- iGraphicsContextCreated( EFalse ),
- iRenderQuality(VG_RENDERING_QUALITY_BETTER),
+ iFontSize( 10 ),
+ iFontWeight( -1 ),
+ iFontStyle( -1 ),
+ iFamilies( NULL ),
+ iTextAnchor( EGfxTextAnchorNone ),
+ iTextDecoration( EGfxTextDecorationNone ),
+ iRenderQuality(VG_RENDERING_QUALITY_BETTER),
iCurrentRendererType(ESVGRendererSW)
{
@@ -86,9 +88,9 @@
// --------------------------------------------------------------------------
// CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec )
// ---------------------------------------------------------------------------
- CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider, TBool aIsMainContext )
+ CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider, TBool aRenderOption )
{
- CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aIsMainContext );
+ CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aRenderOption );
CleanupStack::PushL( self );
self->ConstructL( aBufferSize, aFontSpec, aSvgBitmapFontProvider);
CleanupStack::Pop();
@@ -123,7 +125,7 @@
iDashArray = new ( ELeave ) CArrayFixFlat<VGfloat>( 32 );
- iVgRenderer = CVGRenderer::NewL(ESVGRendererSW, 0);
+ iVgRenderer = CVGRenderer::NewL(ESVGRendererSW, iRenderOption);
iVgSurface = iVgRenderer->GetCurrentSurface();
ChangeBufferSizeL( aBufferSize );
}
@@ -131,9 +133,9 @@
// --------------------------------------------------------------------------
// CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec )
// ---------------------------------------------------------------------------
- CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType,TBool aIsMainContext )
+ CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType,TBool aRenderOption )
{
- CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aIsMainContext );
+ CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aRenderOption );
CleanupStack::PushL( self );
self->ConstructL( aBufferSize, aFontSpec, aSvgBitmapFontProvider,aRendererType);
CleanupStack::Pop();
@@ -161,7 +163,7 @@
iDashArray = new ( ELeave ) CArrayFixFlat<VGfloat>( 32 );
iCurrentRendererType = aRendererType;
- iVgRenderer = CVGRenderer::NewL(aRendererType, 0);
+ iVgRenderer = CVGRenderer::NewL(aRendererType, iRenderOption);
iVgSurface = iVgRenderer->GetCurrentSurface();
iVgSurface->InitializeSurface( aBufferSize, VGI_COLORSPACE_SRGB );
@@ -2325,6 +2327,36 @@
iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, KOriginalFilterMasks );
}
+ void CGfx2dGcOpenVG::GenerateMask(CSvgtBitmap* aMask)
+ {
+ if ( !aMask || aMask->SizeInPixels() != iColorBufferSize )
+ {
+ return;
+ }
+
+ const TDisplayMode KMaskDisplayMode = aMask->DisplayMode();
+
+ if ( KMaskDisplayMode != EGray256 && KMaskDisplayMode != EGray2 )
+ {
+ return;
+ }
+
+ const TInt KOriginalFilterMasks = iVgRenderer->vgGeti( VG_FILTER_CHANNEL_MASK );//
+ const TInt KStride = CFbsBitmap::ScanLineLength( iColorBufferSize.iWidth, KMaskDisplayMode );
+
+ // Change to get alpha values from OpenVG
+ iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, VG_ALPHA );
+
+ VGImageFormat format = ( KMaskDisplayMode == EGray256 ) ? VG_A_8 : VG_BW_1;
+
+ // Get data address of last line and move upwards (negative stride)
+ // OpenVG uses Cartesian coordinate system and Symbian uses Screen coordinate system.
+
+ iVgRenderer->vgReadPixels( aMask->BitmapBuffer(), -KStride, format, 0, 0,
+ iColorBufferSize.iWidth, iColorBufferSize.iHeight );
+ // Set back the original filter-masks
+ iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, KOriginalFilterMasks );
+ }
// ==========================================================================
// This function calls the low level function to set fill opacity value
@@ -2987,3 +3019,108 @@
{
return(iVgRenderer->TLVEncodedData());
}
+
+//--------------------------------------------------------------------------------
+// M2G: UpdateFramebufferL() is overloaded to enable rendering on target buffer.
+//--------------------------------------------------------------------------------
+void CGfx2dGcOpenVG::UpdateFramebufferL( CSvgtBitmap* aBitmap, CSvgtBitmap* aMask )
+ {
+ if ( !aBitmap || aBitmap->SizeInPixels() != iColorBufferSize )
+ {
+ return;
+ }
+
+ const TDisplayMode KBitmapDisplayMode = aBitmap->DisplayMode();
+ // This check just before VGISymbianCopyToBitmap avoid putting lot
+ // many similar error checks in the code. If there is any problem
+ // during OpenVG call we simply leave without drawing any thing.
+ VGErrorCode vgret = (VGErrorCode)iVgRenderer->vgGetError();
+
+ if(vgret != VG_NO_ERROR )
+ {
+ User::LeaveIfError(OpenVGErrorToSymbianError(vgret));
+ }
+
+ // EGray2 is not support in VGISymbianCopyToBitmap API
+ if ( KBitmapDisplayMode == EGray2 )
+ {
+ const TInt KStride = aBitmap->Stride();
+
+ iVgRenderer->vgReadPixels( aBitmap->BitmapBuffer(), -KStride, VG_BW_1, 0, 0,
+ iColorBufferSize.iWidth, iColorBufferSize.iHeight );
+ }
+ // All other color modes
+ else
+ {
+ // No Mask -- to be generated in GenerateMask
+ TInt error=KErrNone;
+
+ //In cases, where the mask/aMaskBitmap != NULL, the hint should be defined as VGI_SKIP_TRANSPARENT_PIXELS.
+ //In all other cases, i.e., when mask/aMaskBitmap == NULL, the definition should be VGI_COPY_TRANSPARENT_PIXELS
+ error = iVgSurface->CopyBitmap(ENone,ENone, aBitmap, aMask, iColorBufferSize);
+
+ if ( error != KErrNone )
+ {
+ #ifdef _DEBUG
+ RDebug::Printf("VGICopyToTarget failed: error code: %d", error );
+ RDebug::Printf(" - Color mode: %d", aBitmap->DisplayMode() );
+ RDebug::Printf(" - Bitmap size: %dx%d", iColorBufferSize.iWidth, iColorBufferSize.iHeight );
+ #endif
+ User::LeaveIfError(error);
+ }
+ }
+ }
+
+//--------------------------------------------------------------------------------
+// M2G: UpdateFramebufferL() is overloaded to enable rendering on target buffer.
+//--------------------------------------------------------------------------------
+void CGfx2dGcOpenVG::UpdateFramebufferL( CSvgtBitmap* aBitmap, CSvgtBitmap* aMask,TSize /*BitmapSize*/,TDisplayMode aBitmapDspMode,TDisplayMode aMaskDspMode )
+ {
+ if ( !aBitmap)
+ {
+ return;
+ }
+
+ const TDisplayMode KBitmapDisplayMode = aBitmap->DisplayMode();
+ // This check just before VGISymbianCopyToBitmap avoid putting lot
+ // many similar error checks in the code. If there is any problem
+ // during OpenVG call we simply leave without drawing any thing.
+ VGErrorCode vgret = (VGErrorCode)iVgRenderer->vgGetError();
+
+ if(vgret != VG_NO_ERROR )
+ {
+ User::LeaveIfError(OpenVGErrorToSymbianError(vgret));
+ }
+
+ // EGray2 is not support in VGISymbianCopyToBitmap API
+ if ( KBitmapDisplayMode == EGray2 )
+ {
+ const TInt KStride = aBitmap->Stride();
+
+ iVgRenderer->vgReadPixels( aBitmap->BitmapBuffer(), -KStride, VG_BW_1, 0, 0,
+ iColorBufferSize.iWidth, iColorBufferSize.iHeight );
+
+ }
+ // All other color modes
+ else
+ {
+ // No Mask -- to be generated in GenerateMask
+ TInt error=KErrNone;
+
+ //In cases, where the mask/aMaskBitmap != NULL, the hint should be defined as VGI_SKIP_TRANSPARENT_PIXELS.
+ //In all other cases, i.e., when mask/aMaskBitmap == NULL, the definition should be VGI_COPY_TRANSPARENT_PIXELS
+
+ error = iVgSurface->CopyBitmap(aBitmapDspMode, aMaskDspMode, aBitmap, aMask, iColorBufferSize);
+
+ if ( error != KErrNone )
+ {
+ #ifdef _DEBUG
+ RDebug::Printf("VGICopyToTarget failed: error code: %d", error );
+ RDebug::Printf(" - Color mode: %d", aBitmap->DisplayMode() );
+ RDebug::Printf(" - Bitmap size: %dx%d", iColorBufferSize.iWidth, iColorBufferSize.iHeight );
+ #endif
+ User::LeaveIfError(error);
+ }
+ }
+
+ }