svgtopt/gfx2d/inc/Gfx2dGcOpenVG.h
changeset 0 d46562c3d99d
child 17 db5c883ad1c5
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     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 header file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef GFX2DGCOPENVG_H
       
    20 #define GFX2DGCOPENVG_H
       
    21 
       
    22 #include "Gfx2dGcInterface.h"
       
    23 #include "GfxRendererInfoP.h"
       
    24 #include "VGRenderer.h"
       
    25 #include <SVGRendererId.h>
       
    26 #include "VGSurface.h"
       
    27 #include <VG/openvg.h>
       
    28 
       
    29 const TUint8 KMediaAnimationVisible =  2;
       
    30   
       
    31 /**
       
    32  * This class provides the interface create a graphics context.
       
    33  *
       
    34  *  @lib Gfx2D.lib
       
    35  *  @since 1.0
       
    36  */
       
    37 class CGfx2dGcOpenVG : public CGfx2dGc
       
    38     {
       
    39     public:
       
    40 
       
    41         /**
       
    42          * Two-phase constructor.
       
    43          *
       
    44          * @since 1.0
       
    45          * @param
       
    46          * @return
       
    47          */
       
    48          static CGfx2dGcOpenVG* NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider, TBool aIsMain = ETrue );
       
    49 
       
    50          static CGfx2dGcOpenVG* NewL( const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType,TBool aIsMain = ETrue );
       
    51          void                 GetFontScaled( TFloatFixPt aHeight, const TDesC& aTypefaceName, CFont*& aFont, TFontSpec& aFontSpec );
       
    52 
       
    53         /**
       
    54          * Destructor
       
    55          */
       
    56          virtual                ~CGfx2dGcOpenVG();
       
    57 
       
    58 				 
       
    59         /**
       
    60          * Draw the given shape.
       
    61          *
       
    62          * @since 1.0
       
    63          * @param aShape : shape to draw.
       
    64          * @return
       
    65          */
       
    66          void                   DrawL( MGfxShape* aShape );
       
    67 
       
    68         /**
       
    69          * Draw the given string starting at the given context coordinate,
       
    70          * and stylized by the given parameters.
       
    71          *
       
    72          * @since 1.0
       
    73          * @param aDesc : string to draw
       
    74          * @param aX : x coordinate
       
    75          * @param aTextAnchor : text anchor
       
    76          * @param aTextDecoration : text decoration
       
    77          * @param aFamilies : font family names
       
    78          * @param aWordSpacing : spacing description for each word
       
    79          * @param aLetterSpacing : spacing description for each letter
       
    80          * @param aArrayRotate : angle of rotation
       
    81          * @param aArrayX : array of x coordinates
       
    82          * @param aArrayY : array of x coordinates
       
    83          * @return
       
    84          */
       
    85          void                   DrawStringL( const TDesC& aDesc,
       
    86                                                      TFloatFixPt aX,
       
    87                                                      TFloatFixPt aY,
       
    88                                                      TInt8 aTextAnchor,
       
    89                                                      TInt8 aTextDecoration,
       
    90                                                      CDesCArrayFlat* aFamilies,
       
    91                                                      TReal aWordSpacing,
       
    92                                                      TReal aLetterSpacing,
       
    93                                                      CArrayFix<TReal32>* aArrayRotate,
       
    94                                                      CArrayFix<TFloatFixPt>* aArrayX,
       
    95                                                      CArrayFix<TFloatFixPt>* aArrayY,
       
    96                                                      TSize& aBoundingBoxResult,
       
    97 						     CFont*& aFont,
       
    98 						     TFontSpec& aFontSpec);
       
    99 
       
   100         /**
       
   101          * Draw the given bitmap at the given top-left coordinates.
       
   102          *
       
   103          * @since 1.0
       
   104          * @param aDesc : bitmap image to draw
       
   105          * @param aX : x coordinate
       
   106          * @param aY : y coordinate
       
   107          * @return
       
   108          */
       
   109          void                   DrawImage( CFbsBitmap* aImage,
       
   110                                                    const TGfxRectangle2D& aImageRect,
       
   111                                                    TBool aHasAlpha = EFalse );
       
   112 
       
   113         /**
       
   114          * Clear the whole graphics context.
       
   115          *
       
   116          * @since 1.0
       
   117          * @param
       
   118          * @return
       
   119          */
       
   120          void                   Clear(TUint32 aRGBA8888Color);
       
   121 
       
   122         /**
       
   123          * Get the foreground color setting.
       
   124          *
       
   125          * @since 1.0
       
   126          * @param
       
   127          * @return foreground color.
       
   128          */
       
   129          TGfxColor              ForegroundColor();
       
   130 
       
   131         /**
       
   132          * Get the paint setting.
       
   133          *
       
   134          * @since 1.0
       
   135          * @param
       
   136          * @return paint.
       
   137          */
       
   138          MGfxPaint*             Paint();
       
   139 
       
   140         /**
       
   141          * Get the rendering hints setting.
       
   142          *
       
   143          * @since 1.0
       
   144          * @param
       
   145          * @return rendering hints.
       
   146          */
       
   147          TGfxRenderingHints*    RenderingHints();
       
   148 
       
   149         /**
       
   150          * Get the stroke setting.
       
   151          *
       
   152          * @since 1.0
       
   153          * @param
       
   154          * @return stroke.
       
   155          */
       
   156          TGfxStroke             Stroke();
       
   157 
       
   158         /**
       
   159          * Get the boundary setting.
       
   160          *
       
   161          * @since 1.0
       
   162          * @param
       
   163          * @return boundary.
       
   164          */
       
   165          TSize                  DeviceBounds();
       
   166         /**
       
   167          * Get the font setting.
       
   168          *
       
   169          * @since 1.0
       
   170          * @param
       
   171          * @return font.
       
   172          */
       
   173 
       
   174          CFont*                 Font();
       
   175 
       
   176 
       
   177         /**
       
   178          * Set the foreground color.
       
   179          *
       
   180          * @since 1.0
       
   181          * @param aColor : foreground color
       
   182          * @return
       
   183          */
       
   184          void                   SetForegroundColor( const TGfxColor& aColor );
       
   185 
       
   186         /**
       
   187          * Set the background color.
       
   188          *
       
   189          * @since 1.0
       
   190          * @param aColor : background color
       
   191          * @return
       
   192          */
       
   193          void                   SetBackgroundColor( const TGfxColor& aColor );
       
   194 
       
   195          
       
   196         /**
       
   197          * Set the stroke-width.
       
   198          *
       
   199          * @since 3.2
       
   200          * @param aWidth : stroke-width
       
   201          * @return none.
       
   202          */
       
   203          void SetStrokeWidth( const TFloatFixPt& aWidth );
       
   204          
       
   205          
       
   206         /**
       
   207          * Set the paint info.
       
   208          *
       
   209          * @since 1.0
       
   210          * @param aPaint : paint info
       
   211          * @return
       
   212          */
       
   213          void                   SetPaint( MGfxPaint* aPaint );
       
   214 
       
   215         /**
       
   216          * Set the stroke info.
       
   217          *
       
   218          * @since 1.0
       
   219          * @param aStroke : stroke info
       
   220          * @return
       
   221          */
       
   222          void                   SetStroke( TGfxStroke aStroke );
       
   223 
       
   224         /**
       
   225          * Set the rendering hints.
       
   226          *
       
   227          * @since 1.0
       
   228          * @param aRenderingHints : rendering hints
       
   229          * @return
       
   230          */
       
   231          void                   SetRenderingHints( const TGfxRenderingHints& aRenderingHints );
       
   232 
       
   233         /**
       
   234          * Set the transform info.
       
   235          *
       
   236          * @since 1.0
       
   237          * @param aTransform : transform info
       
   238          * @return
       
   239          */
       
   240          void                   SetTransform( const TGfxAffineTransform& aTransform );
       
   241 
       
   242         /**
       
   243          * Set the clipping info.
       
   244          *
       
   245          * @since 1.0
       
   246          * @param aClip : clipping rectangle
       
   247          * @return
       
   248          */
       
   249          void                   SetClip( const TGfxRectangle2D& aClip );
       
   250 
       
   251         /**
       
   252          * Set the font.
       
   253          *
       
   254          * @since 1.0
       
   255          * @param aFont : font
       
   256          * @return
       
   257          */
       
   258 
       
   259          void                   SetFont( const CFont* aFont );
       
   260 
       
   261         /**
       
   262          * Set the dash array info.
       
   263          *
       
   264          * @since 1.0
       
   265          * @param aArray : array of points
       
   266          * @param aOffset : offset point
       
   267          * @return
       
   268          */
       
   269          void                   SetDashArrayL( CArrayFix<TFloatFixPt>* aArray);
       
   270 		 void					SetDashOffset( TFloatFixPt aDashOffset ) ;
       
   271         /**
       
   272          * Set the font size.
       
   273          *
       
   274          * @since 1.0
       
   275          * @param aFontSize : font size
       
   276          * @return
       
   277          */
       
   278          void                   SetFontSize( const TFloatFixPt aFontSize );
       
   279 
       
   280         /**
       
   281          * Set the winding rule.
       
   282          *
       
   283          * @since 1.0
       
   284          * @param aRule : winding rule
       
   285          * @return
       
   286          */
       
   287          void                   SetWindingRule( TGfxWindingRule aRule );
       
   288 
       
   289         /**
       
   290          * Set the font weight.
       
   291          *
       
   292          * @since 1.0
       
   293          * @param aFontWeight : font weight value
       
   294          * @return
       
   295          */
       
   296          void                   SetFontWeight( const TInt32 aFontWeight );
       
   297 
       
   298         /**
       
   299          * Set the font style.
       
   300          *
       
   301          * @since 1.0
       
   302          * @param aFontStyle : font style
       
   303          * @return
       
   304          */
       
   305          void                   SetFontStyle( const TInt32 aFontStyle );
       
   306 
       
   307         /**
       
   308          * Set the font family.
       
   309          *
       
   310          * @since 1.0
       
   311          * @param aFamilies : font family names
       
   312          * @return
       
   313          */
       
   314          void                   SetFontFamily( CDesCArrayFlat* aFamilies );
       
   315 
       
   316         /**
       
   317          * Set the text anchor
       
   318          *
       
   319          * @since 1.0
       
   320          * @param aTextAnchor : text anchor value
       
   321          * @return
       
   322          */
       
   323          void                   SetTextanchor( const TInt32 aTextAnchor );
       
   324 
       
   325         /**
       
   326          * Set the text decoration
       
   327          *
       
   328          * @since 1.0
       
   329          * @param aTextDecoration : text decoration value
       
   330          * @return
       
   331          */
       
   332          void                   SetTextDecoration( const TInt32 aTextDecoration );
       
   333 
       
   334         /**
       
   335          * Set the anti-alias mode
       
   336          *
       
   337          * @since 1.0
       
   338          * @param aTextDecoration : anti-alias mode value
       
   339          * @return
       
   340          */
       
   341          void                   SetAntialiasingMode( const TInt32 aAntialiasingEnable );
       
   342 
       
   343         /**
       
   344          * This method copies the internal RGBA8888 framebuffer to CfbsBitmap that
       
   345          * is specified in constructor. The CfbsBitmap could be 4k color (RGB0444),
       
   346          * 64k color (RGB565), or 16M color (RGB888).
       
   347          *
       
   348          * @since
       
   349          * @param
       
   350          * @return
       
   351          */
       
   352          void UpdateFramebufferL( CFbsBitmap* aBitmap, CFbsBitmap* aMask );
       
   353 
       
   354          void UpdateFramebufferL( CFbsBitmap* aBitmap, CFbsBitmap* aMask,TSize BitmapSize,TDisplayMode aBitmapDspMode,TDisplayMode aMaskDspMode );
       
   355         /**
       
   356          * Blend aFrameBuffer with background buffer using the opacity value
       
   357          *
       
   358          * @since 1.0
       
   359          * @param aFrameBuffer: Buffer to be blended with background
       
   360          *        aOpacity: opacity value (0<=aOpacity<=1.0)
       
   361          * @return
       
   362          */
       
   363           void BlendWithBackground(TUint32* aFrameBuffer, TReal32 aOpacity);
       
   364 
       
   365          /**
       
   366           * Generate mask
       
   367           *
       
   368           * @since
       
   369           * @param aMask: pointer to the mask
       
   370           * @return
       
   371           */
       
   372 		 void GenerateMask(CFbsBitmap* aMask);
       
   373 
       
   374 		  /**
       
   375          * Set the fill opacity value
       
   376         *
       
   377          * @since 1.0
       
   378          * @param aFillOpacity : opacity value (0<=aFillOpacity<=1.0)
       
   379          * @return
       
   380          */
       
   381          void                   SetFillOpacity(TFloatFixPt aFillOpacity);
       
   382 
       
   383         /**
       
   384          * Set the stroke opacity value
       
   385          *
       
   386          * @since 1.0
       
   387          * @param aStrokeOpacity : opacity value (0<=aStrokeOpacity<=1.0)
       
   388          * @return
       
   389          */
       
   390          void                   SetStrokeOpacity(TFloatFixPt aStrokeOpacity);
       
   391 
       
   392         /**
       
   393          * Set the flag to do or ignore dithering.
       
   394          *
       
   395          * @since 1.0
       
   396          * @param aDoDithering : TRUE or False
       
   397          * @return
       
   398          */
       
   399          void                   SetDoDithering( TBool aDoDithering );
       
   400 
       
   401         /**
       
   402          * Request to change the buffer size.
       
   403          *
       
   404          * @since 1.0
       
   405          * @param aSize : size of new buffer
       
   406          * @return
       
   407          */
       
   408          void                   ChangeBufferSizeL( const TSize aBufferSize );
       
   409 
       
   410          // Group opacity methods
       
   411          void                   BindToImageL();
       
   412          void                   UnbindFromImageL( TReal32 aOpacity );
       
   413 
       
   414          void                   BindToMediaImageL(TInt aWidth, TInt aHeigth);
       
   415          void                   UnbindFromMediaImageL(const TGfxAffineTransform& aAffineTransform,TReal32 aOpacity,TInt aWidth, TInt aHeight, TInt aDraw );
       
   416          void                   SetClipMediaElement( TSize aSize );
       
   417          void                   GetMatrix(TReal32 * m);
       
   418          void SetBitmapHeader(const TDesC* aHeaderData);
       
   419 		 /**
       
   420          * Get the NVG-TLV data 
       
   421          *
       
   422          * @since 1.0
       
   423          * @return : pointer to the NVG-TLV data
       
   424          */
       
   425          const TPtrC8 TLVEncodedData() const;
       
   426   private:
       
   427 
       
   428         /**
       
   429          * Constructor
       
   430          */
       
   431                                         CGfx2dGcOpenVG( TBool aIsMainContext );
       
   432         /**
       
   433 
       
   434         /**
       
   435          * Constructor
       
   436          */
       
   437                                         CGfx2dGcOpenVG();
       
   438 
       
   439         /**
       
   440          * Two-phase constructor
       
   441          */
       
   442         void                            ConstructL(const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider);
       
   443 
       
   444         /**
       
   445 
       
   446         * Constructor NGA with the renderer selector parameter
       
   447 
       
   448         */
       
   449 
       
   450         void                            ConstructL(const TSize aBufferSize, TFontSpec& aFontSpec, CSvgBitmapFontProvider* aSvgBitmapFontProvider,SVGRendererId aRendererType);
       
   451 
       
   452         /**
       
   453          * Perform the drawing operations of the given shape.
       
   454          *
       
   455          * @since 1.0
       
   456          * @param aShape : shape to draw
       
   457          * @return
       
   458          */
       
   459         void                            DoDrawL( MGfxShape* aShape );
       
   460 
       
   461 		void 							PseudoDoDrawL( MGfxShape* aShape );
       
   462 
       
   463         /**
       
   464          * Destroy the OpenVG context and delete the 32-bit intermediate color buffer
       
   465          *
       
   466          * @since 1.0
       
   467          * @return
       
   468          */
       
   469         void DestroyContext();
       
   470         /**
       
   471          * Converts OpenVG Errors into Symbian error codes
       
   472          *
       
   473          * @since 
       
   474          * @return TInt
       
   475          */
       
   476         TInt OpenVGErrorToSymbianError( TInt aError );
       
   477 
       
   478 		void ApplyTransform( TGfxAffineTransform& aAffineTransform );
       
   479 		void ApplyTransformMediaElement(const TGfxAffineTransform& aAffineTransform,TSize& aSize );
       
   480 
       
   481 		VGbitfield SetFillStroke(VGPaint aFillPaint, VGPaint aStrokePaint, TGfxRectangle2D& bBox);
       
   482 
       
   483         VGImage CreateVGImage( void* aBuffer, TSize aSize, TDisplayMode aDisplayMode, TBool aPreMultiplied = ETrue );
       
   484 
       
   485         // This is for work-around for OpenVG to simulate multiple contexts
       
   486         void SetupContextL();
       
   487         void Flush();
       
   488         /**
       
   489          * Sets the Paint,Stroke and Path handle back to VG_INVALID_HANDLE
       
   490          *
       
   491          * @since 
       
   492          * @return void
       
   493          */
       
   494         void ResetContextHandle();
       
   495 		//To find the bounding box for system text..
       
   496 		TGfxRectangle2D GetBBoxForSystemText( const TDesC& aText, 
       
   497                                      TFloatFixPt aX,
       
   498                                      TFloatFixPt aY );
       
   499                                      
       
   500 		TGfxRectangle2D GetTRect(TGfxPoint2D lTransTopLeftCorner,
       
   501 												TGfxPoint2D lTransTopRightCorner,
       
   502 												TGfxPoint2D lTransBottomLeftCorner,
       
   503 												TGfxPoint2D lTransBottomRightCorner);                                     
       
   504 
       
   505         // Method to handle cleanup (turning off settings, such as dasharray) for efficiency.
       
   506         void PostDraw();
       
   507 
       
   508     private:
       
   509         // 32-bit buffer for OpenVG to draw to
       
   510         // Color conversion/copy to Symbian bitmap is needed as final step
       
   511         TSize                           iColorBufferSize;
       
   512 
       
   513         TGfxRectangle2D                 iClip;
       
   514         MGfxPaint*                      iFillColor;
       
   515         TFloatFixPt						iFillOpacity;
       
   516       	TFloatFixPt                     iScale;
       
   517         TGfxStroke                      iStroke;
       
   518         TGfxAffineTransform             iTransform;
       
   519         TGfxColor                       iStrokeColor;
       
   520         TFloatFixPt						iStrokeOpacity;
       
   521         TGfxColor                       iBackgroundColor;
       
   522         CFont*                          iFont;
       
   523         CArrayFix<VGfloat>*             iDashArray;
       
   524         TFloatFixPt                     iDashOffset;
       
   525         TFloatFixPt                     iFontSize;
       
   526         TInt32                          iFontWeight;
       
   527         TInt32                          iFontStyle;
       
   528         CDesCArrayFlat*                 iFamilies;
       
   529         TInt32                          iTextAnchor;
       
   530         TInt32                          iTextDecoration;
       
   531         TGfxRendererInfoP               iRenderInfo;
       
   532         
       
   533         // Flag used for using CFbsBitmap::DataAddress() instead of allocating
       
   534         // TInt32 array to draw shapes.
       
   535         TFontSpec                       iFontSpec;
       
   536         //OpenVG stuff
       
   537 
       
   538         TDisplayMode    iDisplayMode;
       
   539         TBool iGraphicsContextCreated;
       
   540         TBool iIsMainContext;
       
   541 
       
   542         VGPaint							iFillPaint;
       
   543         VGPaint							iStrokePaint;
       
   544         VGPath                          iPath;
       
   545 
       
   546         RArray<VGImage>                 iGroupOpacityImages;
       
   547         RPointerArray<TUint32>          iGroupOpacityBuffers;
       
   548 
       
   549         VGubyte*                        iPathSegmentTypes;
       
   550         TInt                            iPathSegmentTypeCount;
       
   551         TGfxRectangle2D                 iClipMain;
       
   552         TSize                           iColorBufferSizeMain;
       
   553         TInt32                          iRenderQuality;
       
   554 
       
   555         CVGRenderer *     iVgRenderer;
       
   556 
       
   557         CVGSurface  *     iVgSurface;
       
   558 
       
   559         SVGRendererId    iCurrentRendererType;
       
   560     };
       
   561 
       
   562 #endif      // GFX2DGCOPENVG_H