svgt_plat/nvg_api/inc/nvg.h
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef NVG_H
       
    19 #define NVG_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <VG/openvg.h>
       
    23 #include <VG/vgu.h>
       
    24 
       
    25 #include <fbs.h>
       
    26 
       
    27 class TDereferencer;
       
    28 class MNVGIcon;
       
    29 class CNvgFitToViewBoxImpl;
       
    30 class MVGImageBinder;
       
    31 class TNVGEngineInternal;
       
    32 
       
    33 enum TNvgAlignStatusType
       
    34     {
       
    35     ENvgPreserveAspectRatio_None,
       
    36     ENvgPreserveAspectRatio_XminYmin,
       
    37     ENvgPreserveAspectRatio_XmidYmin,
       
    38     ENvgPreserveAspectRatio_XmaxYmin,
       
    39     ENvgPreserveAspectRatio_XminYmid,
       
    40     ENvgPreserveAspectRatio_XmidYmid,
       
    41     ENvgPreserveAspectRatio_XmaxYmid,
       
    42     ENvgPreserveAspectRatio_XminYmax,
       
    43     ENvgPreserveAspectRatio_XmidYmax,
       
    44     ENvgPreserveAspectRatio_XmaxYmax
       
    45     };
       
    46 
       
    47 enum TNvgMeetOrSliceType
       
    48     {
       
    49     ENvgMeet,
       
    50     ENvgSlice
       
    51     };
       
    52 
       
    53 enum TNvgBitEncoding
       
    54     {
       
    55     EEightBitEncoding = 1,
       
    56     ESixteenBitEncoding ,
       
    57     EThirtyTwoBitEncoding,
       
    58     EFloatEncoding
       
    59     };
       
    60 
       
    61 class CNvgEngine :  public CBase
       
    62     {
       
    63 public :    
       
    64     /**
       
    65      * @brief  constructor
       
    66      * @version
       
    67      * @param   None
       
    68      * @return  None
       
    69      */
       
    70     IMPORT_C static CNvgEngine* NewL();
       
    71     
       
    72     /**
       
    73      * @berief Destructor
       
    74      */
       
    75     IMPORT_C ~CNvgEngine();
       
    76     
       
    77     /**
       
    78      * @brief  Set the angle for rotation of the NVG graphic
       
    79      * @version
       
    80      * @param    aAngle counter-clockwise rotation by a given angle (expressed in degrees)
       
    81      *              aX, aY  point around which the rotation must take place
       
    82      * @return  None
       
    83      */
       
    84     IMPORT_C void Rotate(TReal32 aAngle, TReal32 aX, TReal32 aY) __SOFTFP;
       
    85 	
       
    86 	/**
       
    87      * @brief  Gets the viewbox width and height from the NVG bytedata
       
    88      * @version
       
    89      * @param   aBuf NVG byte data of the file
       
    90      * @return  None
       
    91      */
       
    92     IMPORT_C TSize ContentDimensions(const TDesC8& aBuf);
       
    93 	
       
    94 	/**
       
    95      * @brief  Render NVG onto the bitmap
       
    96      * @version
       
    97      * @param    aBuf  byte data of NVG file
       
    98      *           aSize Size in pixels of the target
       
    99      *           aDstBitmap Target bitmap
       
   100      *           aMask Target mask
       
   101      * @return  None
       
   102      */
       
   103     IMPORT_C TInt DrawNvg(const TDesC8& aBuf, const TSize& aSize, CFbsBitmap* aDstBitmap, CFbsBitmap* aMask );
       
   104    
       
   105     /**
       
   106      * @brief   Creates NVGIcon, openVG objects are cached
       
   107      * @param   aBuf  byte data of NVG file
       
   108      *          aSize Size in pixels of the target
       
   109      * @return  NVG icon object on success, 0 on failure
       
   110      */
       
   111     IMPORT_C MNVGIcon * CreateNVGIcon(const TDesC8& aBuf, const TSize& aSize);
       
   112     
       
   113 	/**
       
   114      * @brief  Set the preserve aspect ratio for the NVG file
       
   115      * @version
       
   116      * @param  
       
   117      * @return  None
       
   118      */
       
   119     IMPORT_C void SetPreserveAspectRatio( TNvgAlignStatusType aPreserveAspectSetting, TNvgMeetOrSliceType aSmilFitSetting );
       
   120 
       
   121 	/**
       
   122      * @brief  Reset the OpenVG handles in NVG Engine
       
   123      * @version
       
   124      * @param  
       
   125      * @return  None
       
   126      */
       
   127     IMPORT_C void ResetNvgState();
       
   128     
       
   129 	/**
       
   130      * @brief  Sets the BackGround Colour for the target
       
   131      * @version
       
   132      * @param  aRGBA8888Color colour in 32 bit RGBA format
       
   133      * @return  None
       
   134      */
       
   135     IMPORT_C void SetBackgroundColor( TUint32 aRGBA8888Color );
       
   136     
       
   137     /**
       
   138      * @fn      SetVGImageBinder
       
   139      * @brief   Sets the callback for binding image to surface, nvgengine doesn't owns the implementation
       
   140      * @param   aImageBinder    an implementation for MVGImageBinder, ownership is with the caller
       
   141      */
       
   142     void SetVGImageBinder(MVGImageBinder * aImageBinder)
       
   143         {
       
   144         iVGImageBinder = aImageBinder;
       
   145         }
       
   146     
       
   147     /**
       
   148      * @fn      OpenVGErrorToSymbianError
       
   149      * @brief   Converts OpenVg errors to symbian error type
       
   150      */
       
   151     static TInt OpenVGErrorToSymbianError( TInt aError );
       
   152 
       
   153 private :
       
   154     
       
   155     /**
       
   156      * Checks whether the given matrix is identity
       
   157      */
       
   158     TBool IsIdentity(VGfloat array[]);
       
   159     
       
   160     /**
       
   161      * Draws the nvg icon
       
   162      */
       
   163     void DoDrawNVGL(const TDesC8& aBuf, const TSize& aSize, CFbsBitmap* aDstBitmap, CFbsBitmap* aMask);
       
   164     
       
   165     /**
       
   166      * Draws the nvg-tlv icon
       
   167      */
       
   168     TInt DrawTLVL(const TDesC8& aBuf, const TSize& aTargetSize, CFbsBitmap* aDstBitmap, CFbsBitmap* aMask);
       
   169     
       
   170     /**
       
   171      * Draws the nvg-cs icon
       
   172      */
       
   173     TInt DrawCommandSectionL(TDereferencer * aIconData, const TSize& aTargetSize, CFbsBitmap* aDstBitmap, CFbsBitmap* aMask);
       
   174     
       
   175 	/**
       
   176      * Constructor
       
   177      */
       
   178     CNvgEngine();
       
   179     
       
   180     /**
       
   181      * Constructor
       
   182      */
       
   183     void ConstructL();
       
   184 	
       
   185 	/**
       
   186      * SetPaint gradient or solid in OpenVG
       
   187      */
       
   188     TInt SetFillPaintL(TDereferencer * aIconData);
       
   189 	
       
   190 	/**
       
   191      * SetColor in OpenVG
       
   192      */
       
   193     TInt SetColorRampL(TDereferencer * aIconData);
       
   194 	
       
   195 	/**
       
   196      * Call vgDrawPath in OpenVG
       
   197      */
       
   198     void DrawPathL(TDereferencer * aIconData);
       
   199     
       
   200     /**
       
   201      * call SetTranslate in OpenVG
       
   202      */
       
   203     void SetTransformL(TDereferencer * aIconData, TUint32 &transVal,const VGfloat* aCurrentMatrix);
       
   204     
       
   205     /**
       
   206      * Set stroke color in Openvg
       
   207      */
       
   208     void SetStrokePaintL(TDereferencer * aIconData);
       
   209 
       
   210     /**
       
   211      * Sets the stroke Width
       
   212      */
       
   213     void SetStrokeWidth(const TUint8* aBuf);
       
   214     
       
   215     /**
       
   216      * Sets the miter limit
       
   217      */
       
   218      void SetStrokeMiterLimit(const TUint8* aBuf);
       
   219      
       
   220 
       
   221 	/**
       
   222      * Generate Mask for modes not supported by custom binding API
       
   223      */
       
   224     void GenerateMask(CFbsBitmap* aMask);
       
   225    
       
   226    
       
   227     /**
       
   228      * To clear the background of the target
       
   229      */
       
   230     void ClearBackground();
       
   231        
       
   232     /**
       
   233      * Stores the callres matrix mode and matricies
       
   234      */
       
   235     void UpdateClientMatrices();
       
   236     
       
   237     /**
       
   238      * Restores the callres matrix mode and matricies
       
   239      */
       
   240     void RestoreClientMatrices();
       
   241     
       
   242     /**
       
   243      * Point transforms according to the given matrix
       
   244      */
       
   245     TPoint GetTranslatedPoint(VGfloat aTRMatrix[9], TPoint aPoint);
       
   246 
       
   247     /**
       
   248      * Gives the minimum of the given arguments
       
   249      */
       
   250     VGfloat MinVal4(VGfloat x1, VGfloat x2, VGfloat x3, VGfloat x4 );
       
   251 
       
   252     /**
       
   253      * Gives the maximum of the given arguments
       
   254      */
       
   255     VGfloat MaxVal4(VGfloat x1, VGfloat x2, VGfloat x3, VGfloat x4 );
       
   256     
       
   257     /**
       
   258      * Initializes the OpenVg handles
       
   259      */
       
   260     TInt InitializeGC();
       
   261     
       
   262     /**
       
   263      * Create the path handle
       
   264      */
       
   265     TInt CreatePathHandle(TInt16 aPathDataType, TReal32 aScale, TReal32 aBias);
       
   266 
       
   267     /**
       
   268      * Applies the rotation
       
   269      */
       
   270     void ApplyRotation();
       
   271 
       
   272     /**
       
   273      * Applies the scissoring
       
   274      */
       
   275     void ApplyScissoring(VGfloat aMatrix[], const TSize& aTargetSize);
       
   276     
       
   277     /**
       
   278      * Applies viewbox to viewport transformation
       
   279      */
       
   280     void ApplyViewboxToViewPortTransformationL(const TSize& aTargetSize, TReal32 aViewboxX, TReal32 aViewboxY,
       
   281                                             TReal32 aViewboxW, TReal32 aViewboxH);
       
   282 
       
   283     /**
       
   284      * Executes the nvg-cs commands
       
   285      */
       
   286     void ExecuteNVGCSCommandLoopL(TUint16 aCommandCount, TDereferencer * aIconData, TDereferencer * aOffsetVector,
       
   287                                               TDereferencer * aCommandSection, TInt aNVGVersion);
       
   288 
       
   289 private :
       
   290         
       
   291     CFbsBitmap*         iDstBimtap;             //! Target Bitmap onto which the drawing will be rendered
       
   292     TSize               iCurrentBufferSize;     //! Width and height of the target bitmap
       
   293 	
       
   294 	VGPath     iPath;          //! The path elements are appended to this path	
       
   295 	VGPaint    iPaintFill;     //! Paint handle for fill
       
   296 	VGPaint    iPaintStroke;   //! Paint handle for stroke
       
   297 	
       
   298     VGPaint    iGradPaintFill;
       
   299     VGPaint    iGradPaintStroke;        
       
   300     VGPaint    iUserStrokePaint;
       
   301     TUint32    iUserStrokePaintColor;
       
   302 
       
   303 	TInt   iFillAlpha;       //! For fill alpha value	
       
   304 	TInt   iStrokeAlpha;     //! Set alpha value for stroke
       
   305 			
       
   306 	VGboolean idoFill;       //! Flags for fill
       
   307 	VGboolean idoStroke;     //! Flags for stroke
       
   308 	
       
   309 	VGfloat * iColorRamps;                     //! This member variable is not used just kept for BC
       
   310 	CNvgFitToViewBoxImpl * iFitToViewBoxImpl;  //! This member variable is not used just kept for BC
       
   311 	
       
   312 	VGfloat iRotateAngle;   //! Rotation angle in degrees	
       
   313 	TBool iRotateApplied;   //! Is rotation angle specified
       
   314 	
       
   315 	/*
       
   316 	 * caller's matrix mode and matricies, must be restored after operation
       
   317 	 */
       
   318     VGint               iMatrixMode;
       
   319     TReal32             iImageMatrix[9];
       
   320     TReal32             iPathMatrix[9];
       
   321     TReal32             iFillPaintMatrix[9];
       
   322     TReal32             iStrokePaintMatrix[9];
       
   323     
       
   324     TInt16              iLastPathDataType;
       
   325 		
       
   326 	TNvgAlignStatusType iPreserveAspectSetting;    //! Aspect Ratio setting
       
   327     TNvgMeetOrSliceType iSmilFitSetting;           //! SMIL Fit setting
       
   328     
       
   329     TUint32     iBackgroundColor;
       
   330     
       
   331 	TReal32 iCentreX;      //! Rotate center x-coordinate
       
   332 	TReal32 iCentreY;      //! Rotate center y-coordinate
       
   333 	
       
   334     MVGImageBinder *    iVGImageBinder;     //! image binder
       
   335 
       
   336     /**
       
   337      * This class is added to maintain BC.
       
   338      * If you want to add new member variable you can add in this class, without breaking BC.
       
   339      * It is better to add members which are depend on macro's in this class.
       
   340      */
       
   341     TNVGEngineInternal  *iInternal;         
       
   342     
       
   343 #ifdef    OPENVG_OBJECT_CACHING
       
   344     VGPath CreatePath();
       
   345 #endif
       
   346 };
       
   347 
       
   348 #endif