svgtopt/gfx2d/src/GfxGc/Gfx2dGcOpenVG.cpp
branchRCL_3
changeset 17 db5c883ad1c5
parent 12 b52e29b42806
child 18 1902ade171ab
equal deleted inserted replaced
14:9be6eed35a80 17:db5c883ad1c5
    46 #include <VG/vgu.h>
    46 #include <VG/vgu.h>
    47 #include <vg/vgcontext.h>
    47 #include <vg/vgcontext.h>
    48 // OpenVG API Binding Symbian specific
    48 // OpenVG API Binding Symbian specific
    49 #include <vg/vgcontext_symbian.h>
    49 #include <vg/vgcontext_symbian.h>
    50 
    50 
       
    51 #include <svgtbitmap.h>
    51 // For allocating path segment type array
    52 // For allocating path segment type array
    52 // Found 130 to be max size at bootup
    53 // Found 130 to be max size at bootup
    53 const TInt KPathSegmentTypeInitialSize = 130;
    54 const TInt KPathSegmentTypeInitialSize = 130;
    54 const TInt KPathSegmentTypeMaxSize = 1000;
    55 const TInt KPathSegmentTypeMaxSize = 1000;
    55 
    56 
    59                                 //SvgTextElementImpl.cpp file
    60                                 //SvgTextElementImpl.cpp file
    60 
    61 
    61 // --------------------------------------------------------------------------
    62 // --------------------------------------------------------------------------
    62 // CGfx2dGcOpenVG::CGfx2dGcOpenVG() : iScale( 1 ),
    63 // CGfx2dGcOpenVG::CGfx2dGcOpenVG() : iScale( 1 ),
    63 // ---------------------------------------------------------------------------
    64 // ---------------------------------------------------------------------------
    64 CGfx2dGcOpenVG::CGfx2dGcOpenVG( TBool /* aIsMainContext */ ) :
    65 CGfx2dGcOpenVG::CGfx2dGcOpenVG( TBool aRenderOption ) :
       
    66                         iRenderOption(aRenderOption),
       
    67                         iGraphicsContextCreated( EFalse ),
    65                         iFillOpacity( 1 ),
    68                         iFillOpacity( 1 ),
    66                         iScale( 1 ),
    69                         iScale( 1 ),
    67                         iStrokeColor( 0 ),
    70                         iStrokeColor( 0 ),
    68                         iStrokeOpacity( 1 ),
    71                         iStrokeOpacity( 1 ),
    69                         iBackgroundColor( 0xffffff ),
    72                         iBackgroundColor( 0xffffff ),
    70                        iFontSize( 10 ),
    73                         iFontSize( 10 ),
    71                        iFontWeight( -1 ),
    74                         iFontWeight( -1 ),
    72                        iFontStyle( -1 ),
    75                         iFontStyle( -1 ),
    73                        iFamilies( NULL ),
    76                         iFamilies( NULL ),
    74                        iTextAnchor( EGfxTextAnchorNone ),
    77                         iTextAnchor( EGfxTextAnchorNone ),
    75                        iTextDecoration( EGfxTextDecorationNone ),
    78                         iTextDecoration( EGfxTextDecorationNone ),
    76                        iGraphicsContextCreated( EFalse ),
    79                         iRenderQuality(VG_RENDERING_QUALITY_BETTER),
    77                        iRenderQuality(VG_RENDERING_QUALITY_BETTER),
       
    78 		       						iCurrentRendererType(ESVGRendererSW)
    80 		       						iCurrentRendererType(ESVGRendererSW)
    79                        
    81                        
    80     {
    82     {
    81     }
    83     }
    82 //
    84 //
    84 // Create a new instance.
    86 // Create a new instance.
    85 // ==========================================================================
    87 // ==========================================================================
    86 // --------------------------------------------------------------------------
    88 // --------------------------------------------------------------------------
    87 // CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec )
    89 // CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec )
    88 // ---------------------------------------------------------------------------
    90 // ---------------------------------------------------------------------------
    89  CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider, TBool aIsMainContext )
    91  CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider, TBool aRenderOption )
    90     {
    92     {
    91     CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aIsMainContext );
    93     CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aRenderOption );
    92     CleanupStack::PushL( self );
    94     CleanupStack::PushL( self );
    93     self->ConstructL( aBufferSize, aFontSpec, aSvgBitmapFontProvider);
    95     self->ConstructL( aBufferSize, aFontSpec, aSvgBitmapFontProvider);
    94     CleanupStack::Pop();
    96     CleanupStack::Pop();
    95     return self;
    97     return self;
    96     }
    98     }
   121     iPathSegmentTypeCount = KPathSegmentTypeInitialSize;
   123     iPathSegmentTypeCount = KPathSegmentTypeInitialSize;
   122     iPathSegmentTypes = new (ELeave) VGubyte[KPathSegmentTypeInitialSize];
   124     iPathSegmentTypes = new (ELeave) VGubyte[KPathSegmentTypeInitialSize];
   123 
   125 
   124     iDashArray = new ( ELeave ) CArrayFixFlat<VGfloat>( 32 );
   126     iDashArray = new ( ELeave ) CArrayFixFlat<VGfloat>( 32 );
   125     
   127     
   126     iVgRenderer  = CVGRenderer::NewL(ESVGRendererSW, 0);
   128     iVgRenderer  = CVGRenderer::NewL(ESVGRendererSW, iRenderOption);
   127     iVgSurface   = iVgRenderer->GetCurrentSurface();
   129     iVgSurface   = iVgRenderer->GetCurrentSurface();
   128     ChangeBufferSizeL( aBufferSize );
   130     ChangeBufferSizeL( aBufferSize );
   129     }
   131     }
   130 //NGA
   132 //NGA
   131 // --------------------------------------------------------------------------
   133 // --------------------------------------------------------------------------
   132 // CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec )
   134 // CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( CFbsBitmap* aFrameBuffer, TFontSpec& aFontSpec )
   133 // ---------------------------------------------------------------------------
   135 // ---------------------------------------------------------------------------
   134  CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType,TBool aIsMainContext )
   136  CGfx2dGcOpenVG* CGfx2dGcOpenVG::NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType,TBool aRenderOption )
   135     {
   137     {
   136     CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aIsMainContext );
   138     CGfx2dGcOpenVG* self = new( ELeave ) CGfx2dGcOpenVG( aRenderOption );
   137     CleanupStack::PushL( self );
   139     CleanupStack::PushL( self );
   138     self->ConstructL( aBufferSize, aFontSpec, aSvgBitmapFontProvider,aRendererType);
   140     self->ConstructL( aBufferSize, aFontSpec, aSvgBitmapFontProvider,aRendererType);
   139     CleanupStack::Pop();
   141     CleanupStack::Pop();
   140     return self;
   142     return self;
   141     }
   143     }
   159     iPathSegmentTypeCount = KPathSegmentTypeInitialSize;
   161     iPathSegmentTypeCount = KPathSegmentTypeInitialSize;
   160     iPathSegmentTypes = new (ELeave) VGubyte[KPathSegmentTypeInitialSize];
   162     iPathSegmentTypes = new (ELeave) VGubyte[KPathSegmentTypeInitialSize];
   161 
   163 
   162     iDashArray = new ( ELeave ) CArrayFixFlat<VGfloat>( 32 );
   164     iDashArray = new ( ELeave ) CArrayFixFlat<VGfloat>( 32 );
   163     iCurrentRendererType = aRendererType;
   165     iCurrentRendererType = aRendererType;
   164     iVgRenderer = CVGRenderer::NewL(aRendererType, 0);
   166     iVgRenderer = CVGRenderer::NewL(aRendererType, iRenderOption);
   165     iVgSurface   = iVgRenderer->GetCurrentSurface();
   167     iVgSurface   = iVgRenderer->GetCurrentSurface();
   166     
   168     
   167     iVgSurface->InitializeSurface( aBufferSize, VGI_COLORSPACE_SRGB );
   169     iVgSurface->InitializeSurface( aBufferSize, VGI_COLORSPACE_SRGB );
   168     iVgSurface->CreateSurface(EColor16MA, 0, 0);
   170     iVgSurface->CreateSurface(EColor16MA, 0, 0);
   169 
   171 
  2323 
  2325 
  2324     // Set back the original filter-masks
  2326     // Set back the original filter-masks
  2325     iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, KOriginalFilterMasks );
  2327     iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, KOriginalFilterMasks );
  2326     }
  2328     }
  2327 
  2329 
       
  2330  void CGfx2dGcOpenVG::GenerateMask(CSvgtBitmap* aMask)
       
  2331      {
       
  2332      if ( !aMask || aMask->SizeInPixels() != iColorBufferSize )
       
  2333          {
       
  2334          return;
       
  2335          }
       
  2336 
       
  2337      const TDisplayMode KMaskDisplayMode = aMask->DisplayMode();
       
  2338 
       
  2339      if ( KMaskDisplayMode != EGray256 && KMaskDisplayMode != EGray2 )
       
  2340          {
       
  2341          return;
       
  2342          }
       
  2343 
       
  2344      const TInt KOriginalFilterMasks = iVgRenderer->vgGeti( VG_FILTER_CHANNEL_MASK );//
       
  2345      const TInt KStride = CFbsBitmap::ScanLineLength( iColorBufferSize.iWidth, KMaskDisplayMode );
       
  2346 
       
  2347      // Change to get alpha values from OpenVG
       
  2348      iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, VG_ALPHA );
       
  2349 
       
  2350      VGImageFormat format = ( KMaskDisplayMode == EGray256 ) ? VG_A_8 : VG_BW_1;
       
  2351 
       
  2352      // Get data address of last line and move upwards (negative stride)
       
  2353      // OpenVG uses Cartesian coordinate system and Symbian uses Screen coordinate system.
       
  2354 
       
  2355      iVgRenderer->vgReadPixels( aMask->BitmapBuffer(), -KStride, format, 0, 0,
       
  2356                    iColorBufferSize.iWidth, iColorBufferSize.iHeight );
       
  2357      // Set back the original filter-masks
       
  2358      iVgRenderer->vgSeti( VG_FILTER_CHANNEL_MASK, KOriginalFilterMasks );
       
  2359      }
  2328 
  2360 
  2329 // ==========================================================================
  2361 // ==========================================================================
  2330 //  This function calls the low level function to set fill opacity value
  2362 //  This function calls the low level function to set fill opacity value
  2331 // ==========================================================================
  2363 // ==========================================================================
  2332 
  2364 
  2985 
  3017 
  2986 const TPtrC8 CGfx2dGcOpenVG::TLVEncodedData() const
  3018 const TPtrC8 CGfx2dGcOpenVG::TLVEncodedData() const
  2987     {
  3019     {
  2988     return(iVgRenderer->TLVEncodedData());
  3020     return(iVgRenderer->TLVEncodedData());
  2989     }
  3021     }
       
  3022 
       
  3023 //--------------------------------------------------------------------------------
       
  3024 // M2G: UpdateFramebufferL() is overloaded to enable rendering on target buffer.
       
  3025 //--------------------------------------------------------------------------------
       
  3026 void CGfx2dGcOpenVG::UpdateFramebufferL( CSvgtBitmap* aBitmap, CSvgtBitmap* aMask )
       
  3027     {
       
  3028     if ( !aBitmap || aBitmap->SizeInPixels() != iColorBufferSize )
       
  3029         {
       
  3030         return;
       
  3031         }
       
  3032 
       
  3033     const TDisplayMode KBitmapDisplayMode = aBitmap->DisplayMode();
       
  3034     // This check just before VGISymbianCopyToBitmap avoid putting lot
       
  3035     // many similar error checks in the code. If there is any problem 
       
  3036     // during OpenVG call we simply leave without drawing any thing.  
       
  3037          VGErrorCode vgret = (VGErrorCode)iVgRenderer->vgGetError();                    
       
  3038         
       
  3039     if(vgret != VG_NO_ERROR )
       
  3040     {
       
  3041         User::LeaveIfError(OpenVGErrorToSymbianError(vgret));
       
  3042     }
       
  3043 
       
  3044     // EGray2 is not support in VGISymbianCopyToBitmap API
       
  3045     if ( KBitmapDisplayMode == EGray2 )
       
  3046         {
       
  3047         const TInt KStride = aBitmap->Stride();
       
  3048 
       
  3049         iVgRenderer->vgReadPixels( aBitmap->BitmapBuffer(), -KStride, VG_BW_1, 0, 0,
       
  3050                       iColorBufferSize.iWidth, iColorBufferSize.iHeight );
       
  3051         }
       
  3052     // All other color modes
       
  3053     else
       
  3054         {
       
  3055         // No Mask -- to be generated in GenerateMask
       
  3056         TInt error=KErrNone;
       
  3057         
       
  3058         //In cases, where the mask/aMaskBitmap != NULL, the hint should be defined as VGI_SKIP_TRANSPARENT_PIXELS.
       
  3059         //In all other cases, i.e., when mask/aMaskBitmap == NULL, the definition should be VGI_COPY_TRANSPARENT_PIXELS
       
  3060         error = iVgSurface->CopyBitmap(ENone,ENone, aBitmap, aMask, iColorBufferSize);
       
  3061         
       
  3062         if ( error != KErrNone )
       
  3063             {
       
  3064             #ifdef _DEBUG
       
  3065                 RDebug::Printf("VGICopyToTarget failed: error code: %d", error );
       
  3066                 RDebug::Printf(" - Color mode: %d", aBitmap->DisplayMode() );
       
  3067                 RDebug::Printf(" - Bitmap size: %dx%d", iColorBufferSize.iWidth, iColorBufferSize.iHeight );
       
  3068             #endif
       
  3069             User::LeaveIfError(error);
       
  3070             }
       
  3071         }
       
  3072     }
       
  3073 
       
  3074 //--------------------------------------------------------------------------------
       
  3075 // M2G: UpdateFramebufferL() is overloaded to enable rendering on target buffer.
       
  3076 //--------------------------------------------------------------------------------
       
  3077 void CGfx2dGcOpenVG::UpdateFramebufferL( CSvgtBitmap* aBitmap, CSvgtBitmap* aMask,TSize /*BitmapSize*/,TDisplayMode aBitmapDspMode,TDisplayMode aMaskDspMode )
       
  3078     {
       
  3079     if ( !aBitmap)
       
  3080         {
       
  3081         return;
       
  3082         }
       
  3083 
       
  3084     const TDisplayMode KBitmapDisplayMode = aBitmap->DisplayMode();
       
  3085     // This check just before VGISymbianCopyToBitmap avoid putting lot
       
  3086     // many similar error checks in the code. If there is any problem 
       
  3087     // during OpenVG call we simply leave without drawing any thing.  
       
  3088          VGErrorCode vgret = (VGErrorCode)iVgRenderer->vgGetError();                    
       
  3089                  
       
  3090     if(vgret != VG_NO_ERROR )
       
  3091     {
       
  3092         User::LeaveIfError(OpenVGErrorToSymbianError(vgret));
       
  3093     }
       
  3094 
       
  3095     // EGray2 is not support in VGISymbianCopyToBitmap API
       
  3096     if ( KBitmapDisplayMode == EGray2 )
       
  3097         {
       
  3098         const TInt KStride = aBitmap->Stride();
       
  3099 
       
  3100         iVgRenderer->vgReadPixels( aBitmap->BitmapBuffer(), -KStride, VG_BW_1, 0, 0,
       
  3101                       iColorBufferSize.iWidth, iColorBufferSize.iHeight );
       
  3102 
       
  3103         }
       
  3104     // All other color modes
       
  3105     else
       
  3106         {
       
  3107         // No Mask -- to be generated in GenerateMask
       
  3108         TInt error=KErrNone;
       
  3109         
       
  3110         //In cases, where the mask/aMaskBitmap != NULL, the hint should be defined as VGI_SKIP_TRANSPARENT_PIXELS.
       
  3111         //In all other cases, i.e., when mask/aMaskBitmap == NULL, the definition should be VGI_COPY_TRANSPARENT_PIXELS
       
  3112         
       
  3113         error = iVgSurface->CopyBitmap(aBitmapDspMode, aMaskDspMode, aBitmap, aMask, iColorBufferSize);
       
  3114         
       
  3115         if ( error != KErrNone )
       
  3116             {
       
  3117             #ifdef _DEBUG
       
  3118                 RDebug::Printf("VGICopyToTarget failed: error code: %d", error );
       
  3119                 RDebug::Printf(" - Color mode: %d", aBitmap->DisplayMode() );
       
  3120                 RDebug::Printf(" - Bitmap size: %dx%d", iColorBufferSize.iWidth, iColorBufferSize.iHeight );
       
  3121             #endif
       
  3122             User::LeaveIfError(error);
       
  3123             }
       
  3124         }
       
  3125     
       
  3126     }