svgtopt/nvgdecoder/inc/NVGUtil.h
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2003 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:  NVG Decoder header file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef NVGUTIL_H_
       
    20 #define NVGUTIL_H_
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 #ifndef NVG_DEBUG
       
    25     #define NVG_DEBUGP1(x1)
       
    26     #define NVG_DEBUGP2(x1, x2)
       
    27     #define NVG_DEBUGP3(x1, x2, x3)
       
    28     #define NVG_DEBUGP4(x1, x2, x3, x4)
       
    29     #define NVG_DEBUGP5(x1, x2, x3, x4, x5)
       
    30     #define NVG_DEBUGP6(x1, x2, x3, x4, x5, x6)
       
    31     #define NVG_DEBUGP7(x1, x2, x3, x4, x5, x6, x7)
       
    32     #define NVG_DEBUGP8(x1, x2, x3, x4, x5, x6, x7, x8)
       
    33     #define NVG_DEBUGP9(x1, x2, x3, x4, x5, x6, x7, x8, x9)
       
    34 
       
    35     #define NVG_DEBUGSTMT(x1)
       
    36 
       
    37     #define VGCREATEPAINT()     vgCreatePaint()
       
    38     #define VGDESTROYPAINT(h)   vgDestroyPaint(h)
       
    39     
       
    40     #define VGCREATEPATH(a1, a2, a3, a4, a5, a6, a7)  vgCreatePath(a1, a2, a3, a4, a5, a6, a7)
       
    41     #define VGDESTROYPATH(h)     vgDestroyPath(h)
       
    42     
       
    43     #define VGCREATEIMAGE(a1, a2, a3, a4) vgCreateImage(a1, a2, a3, a4)
       
    44     #define VGDESTROYIMAGE(h)     vgDestroyImage(h)
       
    45 
       
    46     #define DECLARE_HANDLECHECKER_GLOBAL()
       
    47     #define DECLARE_HANDLECHECKER()
       
    48     #define INIT_HANDLECHECKER()
       
    49     #define ASSERT_HANDLE_COUNT()
       
    50 
       
    51 #else
       
    52 #include <e32debug.h>
       
    53     #define NVG_DEBUGP1(x1)                                 RDebug::Printf(x1)
       
    54     #define NVG_DEBUGP2(x1, x2)                             RDebug::Printf(x1, x2)
       
    55     #define NVG_DEBUGP3(x1, x2, x3)                         RDebug::Printf(x1, x2, x3)
       
    56     #define NVG_DEBUGP4(x1, x2, x3, x4)                     RDebug::Printf(x1, x2, x3, x4)
       
    57     #define NVG_DEBUGP5(x1, x2, x3, x4, x5)                 RDebug::Printf(x1, x2, x3, x4, x5)
       
    58     #define NVG_DEBUGP6(x1, x2, x3, x4, x5, x6)             RDebug::Printf(x1, x2, x3, x4, x5, x6)
       
    59     #define NVG_DEBUGP7(x1, x2, x3, x4, x5, x6, x7)         RDebug::Printf(x1, x2, x3, x4, x5, x6, x7)
       
    60     #define NVG_DEBUGP8(x1, x2, x3, x4, x5, x6, x7, x8)     RDebug::Printf(x1, x2, x3, x4, x5, x6, x7, x8)
       
    61     #define NVG_DEBUGP9(x1, x2, x3, x4, x5, x6, x7, x8, x9) RDebug::Printf(x1, x2, x3, x4, x5, x6, x7, x8, x9)
       
    62 
       
    63     #define NVG_DEBUGSTMT(x1)                             do { x1; } while (0)
       
    64 
       
    65     struct THandleCounter
       
    66         {
       
    67         TInt    paintHC;
       
    68         TInt    pathHC;
       
    69         TInt    imageHC;
       
    70         THandleCounter() : paintHC(0), pathHC(0), imageHC(0) {}
       
    71         };
       
    72 
       
    73 inline void incrementPaintHandleCountL(THandleCounter * handleCounter)
       
    74     {
       
    75     if (handleCounter)
       
    76         handleCounter->paintHC++;
       
    77     }
       
    78 
       
    79 inline void decrementPaintHandleCountL(THandleCounter * handleCounter)
       
    80     {
       
    81     if (handleCounter)
       
    82         handleCounter->paintHC--;
       
    83     }
       
    84 
       
    85 inline void decrementImageHandleCountL(THandleCounter * handleCounter)
       
    86     {
       
    87     if (handleCounter)
       
    88         handleCounter->imageHC--;
       
    89     }
       
    90 
       
    91 inline void decrementPathHandleCountL(THandleCounter * handleCounter)
       
    92     {
       
    93     if (handleCounter)
       
    94         handleCounter->pathHC--;
       
    95     }
       
    96 
       
    97 inline void incrementPathHandleCountL(THandleCounter * handleCounter)
       
    98     {
       
    99     if (handleCounter)
       
   100         handleCounter->pathHC++;
       
   101     }
       
   102 
       
   103 inline void incrementImageHandleCountL(THandleCounter * handleCounter)
       
   104     {
       
   105     if (handleCounter)
       
   106         handleCounter->imageHC++;
       
   107     }
       
   108 
       
   109 inline void checkHandleCout(THandleCounter * handleCounter)
       
   110     {
       
   111     if (handleCounter)
       
   112         {
       
   113         if (handleCounter->paintHC != 0)
       
   114             {
       
   115             User::Panic(_L("Paint Handle Deallocation Not Matching"), 1);
       
   116             }
       
   117         
       
   118         if (handleCounter->pathHC != 0)
       
   119             {
       
   120             User::Panic(_L("Path Handle Deallocation Not Matching"), 1);
       
   121             }
       
   122         
       
   123         if (handleCounter->imageHC != 0)
       
   124             {
       
   125             User::Panic(_L("Image Handle Deallocation Not Matching"), 1);
       
   126             }
       
   127         }
       
   128     
       
   129         delete handleCounter;
       
   130         handleCounter = 0;
       
   131     }
       
   132 
       
   133 inline VGHandle vgCreatePaintWrapper(THandleCounter * handleCounter)
       
   134     {
       
   135     VGPaint pH = vgCreatePaint();
       
   136     if (pH)
       
   137         {
       
   138         incrementPaintHandleCountL(handleCounter);
       
   139         }
       
   140     return pH;
       
   141     }
       
   142                                     
       
   143 inline void vgDestroyPaintWrapper(THandleCounter * handleCounter, VGHandle h)
       
   144     {
       
   145     if (h)
       
   146         {
       
   147         vgDestroyPaint(h);
       
   148         decrementPaintHandleCountL(handleCounter);
       
   149         }
       
   150     }
       
   151     
       
   152     
       
   153 inline VGHandle vgCreatePathWrapper(THandleCounter * handleCounter, VGint a1,
       
   154         VGPathDatatype a2,
       
   155         VGfloat a3, VGfloat a4,
       
   156         VGint a5,
       
   157         VGint a6,
       
   158         VGbitfield a7)
       
   159     {
       
   160     VGPath pH = vgCreatePath(a1, a2, a3, a4, a5, a6, a7);
       
   161     if (pH) 
       
   162         {
       
   163         incrementPathHandleCountL(handleCounter);
       
   164         }
       
   165     return pH;
       
   166     }
       
   167    
       
   168 inline void vgDestroyPathWrapper(THandleCounter * handleCounter, VGHandle h)
       
   169     {
       
   170     if (h) 
       
   171         {
       
   172         vgDestroyPath(h);
       
   173         decrementPathHandleCountL(handleCounter);
       
   174         }
       
   175     }
       
   176     
       
   177 inline VGHandle vgCreateImageWrapper(THandleCounter * handleCounter, VGImageFormat a1,
       
   178         VGint a2, VGint a3,
       
   179         VGbitfield a4)
       
   180     {
       
   181     VGImage iH = vgCreateImage(a1, a2, a3, a4);
       
   182     if (iH) 
       
   183         {
       
   184         incrementImageHandleCountL(handleCounter);
       
   185         }
       
   186     return iH;
       
   187     }
       
   188 
       
   189 inline void vgDestroyImageWrapper(THandleCounter * handleCounter, VGHandle h)
       
   190     {
       
   191     if (h)
       
   192         {
       
   193         vgDestroyImage(h);
       
   194         decrementImageHandleCountL(handleCounter);
       
   195         }
       
   196     }
       
   197     
       
   198     
       
   199     #define DECLARE_HANDLECHECKER_GLOBAL()  THandleCounter * __handleCounter;
       
   200     #define DECLARE_HANDLECHECKER()  private:  THandleCounter * __handleCounter;
       
   201     #define INIT_HANDLECHECKER()  __handleCounter = new THandleCounter;
       
   202     #define ASSERT_HANDLE_COUNT() checkHandleCout(__handleCounter);
       
   203 
       
   204     #define VGCREATEPAINT()     (NVG_DEBUGP3("/*vgCreatePaint() %s:%d*/", __FILE__, __LINE__), vgCreatePaintWrapper(__handleCounter))
       
   205     #define VGDESTROYPAINT(h)   (NVG_DEBUGP3("/*vgDestroyPaint() %s:%d*/", __FILE__, __LINE__), vgDestroyPaintWrapper(__handleCounter, h))
       
   206     
       
   207     #define VGCREATEPATH(a1, a2, a3, a4, a5, a6, a7)  (NVG_DEBUGP3("/*vgCreatePath() %s:%d*/", __FILE__, __LINE__), vgCreatePathWrapper(__handleCounter, a1, a2, a3, a4, a5, a6, a7))
       
   208     #define VGDESTROYPATH(h)     (NVG_DEBUGP3("/*vgDestroyPath() %s:%d*/", __FILE__, __LINE__), vgDestroyPathWrapper(__handleCounter, h))
       
   209     
       
   210     #define VGCREATEIMAGE(a1, a2, a3, a4) (NVG_DEBUGP3("/*vgCreateImage() %s:%d*/", __FILE__, __LINE__), vgCreateImageWrapper(__handleCounter, a1, a2, a3, a4))
       
   211     #define VGDESTROYIMAGE(h)     (NVG_DEBUGP3("/*vgDestroyImage() %s:%d*/", __FILE__, __LINE__), vgDestroyImageWrapper(__handleCounter, h))
       
   212 
       
   213 #endif
       
   214 
       
   215 #ifdef OPENVG_OBJECT_CACHING
       
   216 
       
   217 // first one is for openVG object caching, the macro is used for testing purpose
       
   218 #define COND_COM_OC(obj, s1, s2)       if (obj) { s1; } else { s2; }
       
   219 
       
   220 // if object caching is enabled take the first one, which is for object caching,
       
   221 // else the second one
       
   222 #define COND_COM_OC_NOC(s1, s2)        s1
       
   223 
       
   224 // if object caching is enabled take the first one, which is for object caching
       
   225 // else don't do anything
       
   226 #define COND_COM_OC_OOC(s1)            s1
       
   227 
       
   228 #else
       
   229 
       
   230 // first one is for openVG object caching, the macro is used for testing purpose
       
   231 #define COND_COM_OC(obj, s1, s2)       s2
       
   232 
       
   233 // if object caching is enabled take the first one, which is for object caching,
       
   234 // else the second one
       
   235 #define COND_COM_OC_NOC(s1, s2)        s2
       
   236 
       
   237 // if object caching is enabled take the first one, which is for object caching
       
   238 // else don't do anything
       
   239 // if object caching is enabled take the first one, which is for object caching
       
   240 // else don't do anything
       
   241 #define COND_COM_OC_OOC(s1)
       
   242 
       
   243 // if object caching is enabled take the first one, which is for object caching
       
   244 // else don't do anything
       
   245 #endif
       
   246 
       
   247 GLDEF_C void CleanupArray( TAny * aObj );
       
   248 GLDEF_C void CleanupTFloatFixArray( TAny * aObj );
       
   249 
       
   250 /*
       
   251  * There is an Align4 function in symbian which does the alignement
       
   252  * this is just to check whether the given pointer is aligned or not
       
   253  */
       
   254 template <class T>
       
   255 inline TBool IsAligned4(T aValue)
       
   256     {return !((TUint32)aValue & (sizeof(TUint32) - 1));}
       
   257 
       
   258 /*
       
   259  * There is an Align2 function in symbian which does the alignement
       
   260  * this is just to check whether the given pointer is aligned or not
       
   261  */
       
   262 template <class T>
       
   263 inline TBool IsAligned2(T aValue)
       
   264     {return !((TUint16)aValue & (sizeof(TUint16) - 1));}
       
   265 
       
   266 #endif
       
   267