Home | History | Annotate | Download | only in vega
      1 /**************************************************************************
      2  *
      3  * Copyright 2009 VMware, Inc.  All Rights Reserved.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a
      6  * copy of this software and associated documentation files (the
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sub license, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * The above copyright notice and this permission notice (including the
     14  * next paragraph) shall be included in all copies or substantial portions
     15  * of the Software.
     16  *
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     20  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
     21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     24  *
     25  **************************************************************************/
     26 
     27 #ifndef PATH_UTILS_H
     28 #define PATH_UTILS_H
     29 
     30 #include "VG/openvg.h"
     31 
     32 #define SEGMENT_COMMAND(command) /* Extract segment type */     \
     33     ((command) & 0x1e)
     34 #define SEGMENT_ABS_REL(command) /* Extract absolute/relative bit */ \
     35     ((command) & 0x1)
     36 
     37 static INLINE VGint size_for_datatype(VGPathDatatype datatype)
     38 {
     39    switch(datatype) {
     40    case VG_PATH_DATATYPE_S_8:
     41       return 1;
     42    case VG_PATH_DATATYPE_S_16:
     43       return 2;
     44    case VG_PATH_DATATYPE_S_32:
     45       return 4;
     46    case VG_PATH_DATATYPE_F:
     47       return 4;
     48    default:
     49       assert(!"unknown datatype");
     50    }
     51    return 0;
     52 }
     53 
     54 static INLINE VGint num_elements_for_segments(const VGubyte *segments,
     55                                               VGint num_segments)
     56 {
     57    VGint i;
     58    VGint count = 0;
     59 
     60    for (i = 0; i < num_segments; ++i) {
     61       VGubyte segment = segments[i];
     62       VGint command = SEGMENT_COMMAND(segment);
     63       switch(command) {
     64       case VG_CLOSE_PATH:
     65          break;
     66       case VG_MOVE_TO:
     67          count += 2;
     68          break;
     69       case VG_LINE_TO:
     70          count += 2;
     71          break;
     72       case VG_HLINE_TO:
     73          count += 1;
     74          break;
     75       case VG_VLINE_TO:
     76          count += 1;
     77          break;
     78       case VG_QUAD_TO:
     79          count += 4;
     80          break;
     81       case VG_CUBIC_TO:
     82          count += 6;
     83          break;
     84       case VG_SQUAD_TO:
     85          count += 2;
     86          break;
     87       case VG_SCUBIC_TO:
     88          count += 4;
     89          break;
     90       case VG_SCCWARC_TO:
     91          count += 5;
     92          break;
     93       case VG_SCWARC_TO:
     94          count += 5;
     95          break;
     96       case VG_LCCWARC_TO:
     97          count += 5;
     98          break;
     99       case VG_LCWARC_TO:
    100          count += 5;
    101          break;
    102       default:
    103          assert(!"Unknown segment!");
    104       }
    105    }
    106    return count;
    107 }
    108 
    109 #endif
    110