uiacceltk/hitchcock/coretoolkit/rendervg10/inc/HuiVg10Gc.h
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-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:   Defines CHuiVg10Gc, an OpenVG 1.0 version of the HUITK
       
    15 *                graphics context.
       
    16 *
       
    17 */
       
    18 
       
    19  
       
    20 
       
    21 #ifndef __HUIVG10GC_H__
       
    22 #define __HUIVG10GC_H__
       
    23 
       
    24 
       
    25 #include <e32def.h>
       
    26 #include <VG/openvg.h>
       
    27 #include <VG/vgu.h>
       
    28 #include <e32cmn.h>
       
    29 
       
    30 #include "uiacceltk/HuiGc.h"
       
    31 #include "uiacceltk/HuiRealPoint.h"
       
    32 #include "uiacceltk/HuiRealSize.h"
       
    33 #include "uiacceltk/HuiRealRect.h"
       
    34 #include "uiacceltk/HuiSegmentedTexture.h"
       
    35 #include "HuiMatrixStack.h"
       
    36 
       
    37 /* Forward declarations. */
       
    38 #ifdef __NVG
       
    39 class MNVGIcon;
       
    40 class CNvgEngine;
       
    41 #endif
       
    42 
       
    43 /**
       
    44  * CHuiVg10Gc implements an OpenVG 1.0 version of the HUITK
       
    45  * graphics context.
       
    46  */
       
    47 NONSHARABLE_CLASS(CHuiVg10Gc) : public CHuiGc
       
    48     {
       
    49     friend class CHuiVg10CurvePath;
       
    50 
       
    51 public:
       
    52 
       
    53     /* Constructors and destructor. */
       
    54 
       
    55     /**
       
    56      * Constructs a new graphics context.
       
    57      */
       
    58     static CHuiVg10Gc* NewL();
       
    59 
       
    60     /**
       
    61      * Constructs a new graphics context and leaves it on the cleanup stack.
       
    62      */
       
    63     static CHuiVg10Gc* NewLC();
       
    64 
       
    65     /**
       
    66      * Destructor.
       
    67      */
       
    68     virtual ~CHuiVg10Gc();
       
    69 
       
    70 
       
    71     /* Methods. */
       
    72     
       
    73     virtual void Push(THuiGcMatrix aStack);
       
    74 
       
    75     virtual void Pop(THuiGcMatrix aStack);
       
    76 
       
    77     virtual void Multiply(THuiGcMatrix aStack, TReal32 aMatrix[16]);
       
    78 
       
    79     virtual void LoadIdentity(THuiGcMatrix aStack);
       
    80 
       
    81     virtual void Translate(THuiGcMatrix aStack,
       
    82                            TReal32 aX, TReal32 aY, TReal32 aZ) __SOFTFP;
       
    83 
       
    84     virtual void Scale(THuiGcMatrix aStack,
       
    85                        TReal32 aX, TReal32 aY, TReal32 aZ) __SOFTFP;
       
    86 
       
    87     virtual void Rotate(THuiGcMatrix aStack, TReal32 aAngle,
       
    88                          TReal32 aX, TReal32 aY, TReal32 aZ) __SOFTFP;
       
    89 
       
    90     virtual void Shear(THuiGcMatrix aStack,
       
    91                        TReal32 aX, TReal32 aY, TReal32 aZ) __SOFTFP;
       
    92     
       
    93     virtual void InitState();
       
    94 
       
    95     /**
       
    96      * Selects the default data arrays.
       
    97      */
       
    98     void RestoreState() const;
       
    99 
       
   100     /**
       
   101      * Restores OpenVg state according to flags set up in the render plugin
       
   102      */
       
   103     void RestoreFlaggedState() const;
       
   104     
       
   105     
       
   106     /**
       
   107      * Updates the projection matrix without changing any settings.
       
   108      */
       
   109     void UpdateProjection();
       
   110 
       
   111     /**
       
   112      * Returns the number of available texture units.
       
   113      *
       
   114      * @return  Number of units (at least 1).
       
   115      */
       
   116     TInt TextureUnits() const;
       
   117 
       
   118     /**
       
   119      * Sets the number of active texture units.
       
   120      *
       
   121      * @param aTextureUnitCount  Number of units to activate (e.g., 2 => 0,1)
       
   122      */
       
   123     void SetTextureUnits(TInt aTextureUnitCount);
       
   124 
       
   125     /**
       
   126      * Enable a feature.
       
   127      */
       
   128     void Enable(TFeature aFeature, TBool aDoEnable = ETrue);
       
   129 
       
   130     /**
       
   131      * Changes the blending mode.
       
   132      */
       
   133     void SetBlendMode(TBlendMode aBlendMode);
       
   134 
       
   135     /**
       
   136      * Changes the texture mode.
       
   137      *
       
   138      * @param aTextureMode  Texturing mode.
       
   139      * @param aParam        Parameter for the texturing.
       
   140      */
       
   141     void SetTextureMode(TTextureMode aTextureMode, TReal32 aParam = 0) __SOFTFP;
       
   142 
       
   143     /**
       
   144      * Sets the strength of dimming fog. In order to have effect, enable the
       
   145      * Fog feature.
       
   146      *
       
   147      * @param aColor   Color of dimming.
       
   148      * @param aAmount  Amout of dimming (0...1).
       
   149      */
       
   150     void SetDimmingFog(const TRgb& aColor, TReal32 aAmount) __SOFTFP;
       
   151 
       
   152     /**
       
   153      * Clear using the current pen color.
       
   154      */
       
   155     void Clear();
       
   156 
       
   157     /**
       
   158      * Clear the depth buffer.
       
   159      */
       
   160     void ClearDepth();
       
   161 
       
   162     /**
       
   163      * Clear both color and depth buffer
       
   164      */
       
   165     void ClearColorAndDepth();
       
   166 
       
   167 	/**
       
   168 	 * Do initialization of new frame.
       
   169 	 * Called by CHuiDisplay when starting to render new frame.
       
   170 	 * Graphics context can do renderer specific state initializations here.
       
   171 	 */
       
   172 	void InitNewFrame();
       
   173 
       
   174     /**
       
   175      * Apply a clipping rectangle to the current clipping region.
       
   176      *
       
   177      * @param aClipRect  Clipping rectangle.
       
   178      */
       
   179     virtual void Clip(const TRect& aClipRect);
       
   180 
       
   181     /**
       
   182      * Apply a clipping region to the current clipping region.
       
   183      *
       
   184      * @param aRegion  Clipping region.
       
   185      */
       
   186     virtual void Clip(const TRegion& aRegion);
       
   187 
       
   188     /**
       
   189      * Replace the current clipping rectangle.
       
   190      *
       
   191      * @param aClipRect  Clipping rectangle in display coordinates.
       
   192      */
       
   193     virtual void SetClip(const TRect& aClipRect);
       
   194     
       
   195     /**
       
   196      * Replace the current clipping region.
       
   197      *
       
   198      * @param aRegion  List of Clipping rectangles.
       
   199      */
       
   200     virtual void SetClipRegion(const TRegion& aRegion);
       
   201     
       
   202     /**
       
   203      * Cancel an applied clipping rectangle or region.
       
   204      */
       
   205     virtual void CancelClipping();
       
   206 
       
   207     /**
       
   208      * Draws a single line of text using the current pen color, font, and
       
   209      * alignment mode.
       
   210      *
       
   211      * @param aTextMesh  Text string.
       
   212      * @param aBounds    Bounding box for the text.
       
   213      * @param aShadow    Darkness of text shadow.
       
   214      */
       
   215     void DrawText(const CHuiTextMesh& aTextMesh,
       
   216                   const THuiRealRect& aBounds,
       
   217                   TReal32 aShadow = 0) __SOFTFP;
       
   218 
       
   219     /**
       
   220      * Draws a rectangle with the current graphics context parameters.
       
   221      *
       
   222      * @param aRect  Rectangle to draw.
       
   223      */
       
   224     void DrawRect(const TRect& aRect);
       
   225 
       
   226     /**
       
   227      * Draws a solid line of uniform thickness with the current graphics context parameters.
       
   228      *
       
   229      * @param aStart     Start of line.
       
   230      * @param aEnd       End of line.     
       
   231      * @param aThickness Thickness of line in pixels.
       
   232      */
       
   233     void DrawLine(const TPoint& aStart, const TPoint& aEnd, const TInt aThickness);
       
   234 
       
   235     /**
       
   236      * Draws a solid or unfilled round rectangle.
       
   237      *
       
   238      * @param aDestinationRect     Start of line.
       
   239      * @param aSize       	Arc size. 
       
   240 	 * @param aDrawMode		THuiFillMode 
       
   241      * @param aThickness 	Thickness of border line in pixels.
       
   242      */
       
   243     void DrawRoundRect(const TRect& aDestinationRect, const THuiRealSize& aSize, THuiFillMode aDrawMode, const TInt aThickness);
       
   244 
       
   245     /**
       
   246      * Draws a stretched image.
       
   247      *
       
   248      * @param aMode        Stretch mode: horizontal or vertical.
       
   249      * @param aImage       Image.
       
   250      * @param aRect        Rectangle to fill.
       
   251      * @param aStartWidth
       
   252      * @param aEndWidth
       
   253      */
       
   254     void DrawStretchImage(TStretchMode aMode,
       
   255                           const THuiImage& aImage, const THuiRealRect& aRect,
       
   256                           TInt aStartWidth, TInt aEndWidth);
       
   257 
       
   258     /**
       
   259      * Draws edges with a color or using a texture.
       
   260      *
       
   261      * @param aOuterRect         The outer edge of the borders.
       
   262      * @param aLeftBorderWidth   The visible width of the left border, 
       
   263      * 							 the width is assumed to be pixel units 
       
   264      * 							 inside from the respective edge 
       
   265      * 							 border. Use 0.0 for no left border.
       
   266      * @param aRightBorderWidth  The visible width of the right border, 
       
   267      * 							 the width is assumed to be pixel units 
       
   268      * 							 inside from the respective edge 
       
   269      * 							 border. Use 0.0 for no right border.
       
   270      * @param aTopBorderWidth    The visible height of the top border, 
       
   271      * 							 the height is assumed to be pixel units 
       
   272      * 							 inside from the respective edge 
       
   273      * 							 border. Use 0.0 for no border.
       
   274      * @param aBottomBorderWidth The visible height of the bottom border, 
       
   275      * 							 the height is assumed to be pixel units 
       
   276      * 							 inside from the respective edge 
       
   277      * 							 border. Use 0.0 for no border.
       
   278      * @param aBorderMode		 Border drawing mode, defines how the
       
   279      * 							 image is streched to the borders.
       
   280      * 							 aImage needs to be 
       
   281      * 							 defined in order to this modes to be
       
   282      * 					         effective.
       
   283      * 
       
   284      * @param aImage			 The image to be used to draw borders,
       
   285      * 							 according to the border drawing mode.
       
   286      * 							 If left NULL will use the current pen 
       
   287      * 							 color to draw single-color borders.
       
   288      */
       
   289     void DrawBorders(const TRect& aOuterRect, 
       
   290                      TReal32 aLeftBorderWidth,
       
   291                      TReal32 aRightBorderWidth, 
       
   292                      TReal32 aTopBorderHeight,
       
   293                      TReal32 aBottomBorderHeight, 
       
   294                      TBorderMode aBorderMode,
       
   295                      const THuiImage* aImage) __SOFTFP;
       
   296 
       
   297     /**
       
   298      * Draws a path from the beginning to aPos.
       
   299      *
       
   300      * @param aPath      Weighted path.
       
   301      * @param aOrigin    Offset.
       
   302      * @param aStartPos  Start position on the path.
       
   303      * @param aEndPos    End position on the path.
       
   304      * @param aAlphaFunction  Function for determining alpha values.
       
   305      * @param aWidthFunction  Function for determining line thickness.
       
   306      */
       
   307     void DrawPath(const CHuiCurvePath& aPath,
       
   308                   const TPoint& aOrigin,
       
   309                   TReal32 aStartPos,
       
   310                   TReal32 aEndPos,
       
   311                   MHuiMappingFunction* aAlphaFunction = 0,
       
   312                   MHuiMappingFunction* aWidthFunction = 0) __SOFTFP;
       
   313 
       
   314     void DrawMesh(const CHuiMesh& aMesh, const THuiImage* aImage = 0,
       
   315                   const THuiImage* aSecondaryImage = 0,
       
   316                   TReal32 aSecondaryAlpha = 0.0) __SOFTFP;
       
   317 
       
   318     void DrawArc(const TPoint& aOrigin, const TSize& aRadius,
       
   319                  TReal32 aStart, TReal32 aEnd, TInt aAnglePerSegment,
       
   320                  TReal32 aWidth, const THuiImage& aImage,
       
   321                  TReal32 (*aAlphaFunc)(TReal32)=0, TBool aAbsoluteAngleParm=EFalse) __SOFTFP;
       
   322 
       
   323     void DrawGradient(TGradientType aType, const TRect& aRect,
       
   324                       const TRgb& aStartColor, const TRgb& aEndColor,
       
   325                       TReal32 aStartOpacity = 1.0,
       
   326                       TReal32 aEndOpacity = 1.0,
       
   327                       const THuiRealRect* aTexCoords = 0) __SOFTFP;
       
   328                       
       
   329     void DrawPolygon(RArray<THuiRealPoint>& aPoints);                      
       
   330 
       
   331     void DrawEllipse(const TRect& aRect, THuiFillMode aDrawMode, const TInt aThickness);                      
       
   332     
       
   333     /**
       
   334      * Sets a depth offset. The depth offset is used when drawing overlaid
       
   335      * surfaces with the same Z coordinates. Normally the depth offset is
       
   336      * always zero.
       
   337      *
       
   338      * @param aOffset  Offset units.
       
   339      */
       
   340     void SetDepthOffset(TInt aOffset);
       
   341 
       
   342     /**
       
   343      * Makes a screen capture of the graphics context's current content.
       
   344      * The data is returned in an array of raw pixel data of size:
       
   345      * aSize.Width() * aSize.Height() * 4.
       
   346      *
       
   347      * @return  Rgba8888 raw bitmap data of the screen's contents.
       
   348      *          Caller must pop and destroy the returned buffer.
       
   349      */
       
   350     TUint8* CaptureLC(TSize& aSize) const;
       
   351 
       
   352     /**
       
   353      * Transforms a dirty rectangle. Implementing this method in
       
   354      * inherited classes is optional (if e.g. dirty rects aren't supported)
       
   355      *
       
   356      * @param aRect  Rectangle to transform.
       
   357      */
       
   358     void TransformDirtyRect(THuiRealRect& aRect);
       
   359 
       
   360     /*
       
   361      * Implemented.
       
   362      */
       
   363     virtual void UpdateColor(TReal32 aAlphaFactor = 1.0f) __SOFTFP;
       
   364     
       
   365 public: // new
       
   366 
       
   367     /**
       
   368      * Sets the rule by which a polygon should be filled
       
   369      * Fill rule is useful while filling self-intersecting polygons.
       
   370      *
       
   371      * @param aFillMode Polygon filling mode, which will be mapped to
       
   372      *  openVg Fill_Rule.
       
   373      */
       
   374 
       
   375     void SetFillRule( THuiFillMode aFillMode );
       
   376 
       
   377     /*
       
   378      * Ownership is not transferred.
       
   379      */
       
   380     void SetPaintPattern(CHuiTexture* aTexture, const TPoint& aTextureOrigin);
       
   381     
       
   382     void DrawArc(const TRect& aRect, THuiFillMode aDrawMode, const TInt aThickness, TReal32 aStart, TReal32 aEnd, TBool aIsPie);
       
   383 
       
   384 protected:
       
   385 
       
   386     /* Constructors. */
       
   387 
       
   388     /**
       
   389      * Constructor.
       
   390      */
       
   391     CHuiVg10Gc();
       
   392 
       
   393     /**
       
   394      * Second-phase constructor.
       
   395      */
       
   396     void ConstructL();
       
   397 
       
   398 
       
   399     /* Methods. */
       
   400 
       
   401     /**
       
   402      * Draw the image.
       
   403      *
       
   404      * @param aImage    Image to draw.
       
   405      * @param aTopLeft  Coordinates of the top left corner.
       
   406      * @param aSize     Size of the image.
       
   407      */
       
   408     void DoDrawImage(const THuiImage& aImage, const THuiRealPoint& aTopLeft,
       
   409                      const THuiRealSize& aSize);
       
   410 
       
   411     /**
       
   412      * Draws two images simultaneously. Requires at least two texture units.
       
   413      *
       
   414      * Segment count must match and sizes must match if using multiple segments.
       
   415      * Otherwise nothing is drawn.
       
   416      *
       
   417      * @param aImage    Image to draw.
       
   418      * @param aImage2   Secondary image to draw.
       
   419      * @param aTopLeft  Coordinates for the top left corner.
       
   420      * @param aSize     Size of the image.
       
   421      */
       
   422     void DoDrawImages(const THuiImage& aImage,
       
   423                       const THuiImage& aImage2,
       
   424                       const THuiRealPoint& aTopLeft,
       
   425                       const THuiRealSize& aSize);
       
   426 
       
   427     CHuiMatrixStack* MatrixStack(THuiGcMatrix aMatrix);
       
   428 
       
   429     void SetQuality(THuiQuality aQuality);
       
   430     
       
   431 private:
       
   432     /** 
       
   433      *  Synchronize a specific OpenVG matrix with the main matrix.
       
   434      */
       
   435     void UpdateMatrix(VGMatrixMode aMatrix);
       
   436     
       
   437     /**
       
   438      *  Makes sure the latest transformation matrix is used for client-side calculation.
       
   439      */
       
   440     void UpdateClientMatrix();
       
   441 
       
   442     /**
       
   443      *  Draw a cropped and possibly scaled portion of an image onto the screen.
       
   444      * 
       
   445      *  @param aTexture     Texture to draw
       
   446      *  @param aSourceRect  Source rectangle
       
   447      *  @param aDestRect    Destination rectangle
       
   448      */
       
   449     void DrawCroppedTexture(const MHuiSegmentedTexture& aTexture, 
       
   450                             const THuiRealRect& aSourceRect, 
       
   451                             const THuiRealRect& aDestRect);
       
   452 
       
   453     /**
       
   454      *  Draw a possibly cropped or scaled portion of an image onto the screen.
       
   455      * 
       
   456      *  @param aTexture     Texture to draw
       
   457      *  @param aSourceRect  Source rectangle
       
   458      *  @param aDestRect    Destination rectangle
       
   459      */
       
   460     void DrawTexture(const MHuiSegmentedTexture& aTexture, 
       
   461                      const THuiRealRect& aSourceRect, 
       
   462                      const THuiRealRect& aDestRect);
       
   463 
       
   464 
       
   465     /**
       
   466      * DrawBorders implementation for EBorderImage
       
   467      * border drawing mode.
       
   468      * @see CHuiGc::DrawBorders()
       
   469      */
       
   470     void DrawBorderImages(const TRect& aOuterRect, 
       
   471                           TReal32 aBorderWidth,
       
   472                           TReal32 aBorderHeight, 
       
   473                           THuiRealPoint aOffset,
       
   474                           const THuiImage* aImage);
       
   475 
       
   476 
       
   477     /**
       
   478      * DrawBorders implementation for EBorderFixedCorners
       
   479      * border drawing mode.
       
   480      * @see CHuiGc::DrawBorders()
       
   481      */
       
   482     void DrawBorderFixedCorners(const TRect& aOuterRect, 
       
   483                                 TReal32 aLeftBorderWidth,
       
   484                                 TReal32 aRightBorderWidth, 
       
   485                                 TReal32 aTopBorderHeight,
       
   486                                 TReal32 aBottomBorderHeight, 
       
   487                                 const THuiImage* aImage);
       
   488     
       
   489     
       
   490     void CreateVgObjectsL();
       
   491     
       
   492 	
       
   493 #ifdef __NVG
       
   494     /**
       
   495      * Draws the icon from NVG data using the NVGDecoder. Does the parsing of the icon header as well
       
   496      * 
       
   497      * @param aNVGData              Extended bitmap data in NVG buffer format to be drawn
       
   498      * @param aIconCmds             Extended bitmap data in VG Object Cached format to be drawn
       
   499      * @param aImageSize            Size of the image
       
   500      * @param aIgnoreAspectRatio    Ignore aspect ratio defined in the icon's header
       
   501      */
       
   502     void DrawNVG(HBufC8* aNVGData, MNVGIcon* aIconCmds, const TSize& aImageSize, TBool aIgnoreAspectRatio);
       
   503 #endif
       
   504     
       
   505     void UsePaintPattern();
       
   506     void DiscardPaintPattern();
       
   507     
       
   508 private:
       
   509     /** Matrix characteristics */
       
   510     enum TMatrixFlags
       
   511         {
       
   512         EMatrixFlagsRotation = 0x1,
       
   513         };
       
   514 
       
   515     /** Model view matrix stack */
       
   516     CHuiMatrixStack* iMatrixStack;
       
   517 
       
   518     typedef RArray<TUint> RMatrixFlagsStack;
       
   519     
       
   520     /** Stack for storing additional information about the matrices */
       
   521     RMatrixFlagsStack iMatrixFlagsStack;
       
   522     
       
   523     /** Flags for the current matrix */
       
   524     TUint iMatrixFlags;
       
   525     
       
   526     /** Rendering state */
       
   527 	TBool iStateScissorTest;
       
   528 	TRect iScissorRect;
       
   529 	
       
   530     /** A path for drawing dynamic shapes */
       
   531 	VGPath iPath;
       
   532     
       
   533 	/** A path for drawing rectangles */
       
   534 	VGPath iRectPath;
       
   535 	
       
   536 	/** A path for drawing round rectangles */
       
   537 	VGPath iRoundRectPath;
       
   538 
       
   539     /** A path for drawing cropped images */
       
   540     VGPath iImagePath;
       
   541     
       
   542     /** A path for drawing borders */
       
   543     VGPath iBorderPath;
       
   544     
       
   545     /** A path for drawing lines */
       
   546     VGPath iLinePath;
       
   547 
       
   548     /** A path for drawing arcs */
       
   549     VGPath iArcPath;
       
   550 
       
   551     /** A path for drawing ellipses */
       
   552     VGPath iEllipsePath;
       
   553     
       
   554     /** Default fill and stroke paint */
       
   555 	VGPaint iPaint;
       
   556 
       
   557     /** Gradient fill paint */
       
   558     VGPaint iGradientPaint;
       
   559     
       
   560     /** The current blend mode */
       
   561     VGBlendMode iBlendMode;
       
   562     
       
   563 #ifdef __NVG
       
   564     CNvgEngine* iNvgEngine;
       
   565 #endif
       
   566         
       
   567     TBool iVgObjectsCreated;
       
   568     
       
   569     /** Private temp region for general purpose, used to avoid excessive allocations of RRegion heap objects */
       
   570     mutable RRegionBuf<KHuiGcClipRegionGranularity> iTempRegion;
       
   571 
       
   572     /** Image pattern for paint, NOT owned */
       
   573     VGImage iPaintPattern;
       
   574     TPoint iPaintPatternOrigin;
       
   575     };
       
   576 
       
   577 #endif  // __HUIVG10GC_H__