Home | History | Annotate | Download | only in pipe
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 
     11 #ifndef SkGPipePriv_DEFINED
     12 #define SkGPipePriv_DEFINED
     13 
     14 #include "SkTypes.h"
     15 
     16 #define UNIMPLEMENTED
     17 
     18 // these must be contiguous, 0...N-1
     19 enum PaintFlats {
     20     kColorFilter_PaintFlat,
     21     kDrawLooper_PaintFlat,
     22     kMaskFilter_PaintFlat,
     23     kPathEffect_PaintFlat,
     24     kRasterizer_PaintFlat,
     25     kShader_PaintFlat,
     26     kXfermode_PaintFlat,
     27 
     28     kLast_PaintFlat = kXfermode_PaintFlat
     29 };
     30 #define kCount_PaintFlats   (kLast_PaintFlat + 1)
     31 
     32 enum DrawOps {
     33     kSkip_DrawOp,   // skip an addition N bytes (N == data)
     34 
     35     // these match Canvas apis
     36     kClipPath_DrawOp,
     37     kClipRegion_DrawOp,
     38     kClipRect_DrawOp,
     39     kConcat_DrawOp,
     40     kDrawBitmap_DrawOp,
     41     kDrawBitmapMatrix_DrawOp,
     42     kDrawBitmapRect_DrawOp,
     43     kDrawClear_DrawOp,
     44     kDrawData_DrawOp,
     45     kDrawPaint_DrawOp,
     46     kDrawPath_DrawOp,
     47     kDrawPicture_DrawOp,
     48     kDrawPoints_DrawOp,
     49     kDrawPosText_DrawOp,
     50     kDrawPosTextH_DrawOp,
     51     kDrawRect_DrawOp,
     52     kDrawSprite_DrawOp,
     53     kDrawText_DrawOp,
     54     kDrawTextOnPath_DrawOp,
     55     kDrawVertices_DrawOp,
     56     kRestore_DrawOp,
     57     kRotate_DrawOp,
     58     kSave_DrawOp,
     59     kSaveLayer_DrawOp,
     60     kScale_DrawOp,
     61     kSetMatrix_DrawOp,
     62     kSkew_DrawOp,
     63     kTranslate_DrawOp,
     64 
     65     kPaintOp_DrawOp,
     66 
     67     kDef_Typeface_DrawOp,
     68     kDef_Flattenable_DrawOp,
     69 
     70     // these are signals to playback, not drawing verbs
     71     kDone_DrawOp,
     72 };
     73 
     74 /**
     75  *  DrawOp packs into a 32bit int as follows
     76  *
     77  *  DrawOp:8 - Flags:4 - Data:20
     78  *
     79  *  Flags and Data are called out separately, so we can reuse Data between
     80  *  different Ops that might have different Flags. e.g. Data might be a Paint
     81  *  index for both drawRect (no flags) and saveLayer (does have flags).
     82  *
     83  *  All Ops that take a SkPaint use their Data field to store the index to
     84  *  the paint (previously defined with kPaintOp_DrawOp).
     85  */
     86 
     87 #define DRAWOPS_OP_BITS     8
     88 #define DRAWOPS_FLAG_BITS   4
     89 #define DRAWOPS_DATA_BITS   20
     90 
     91 #define DRAWOPS_OP_MASK     ((1 << DRAWOPS_OP_BITS) - 1)
     92 #define DRAWOPS_FLAG_MASK   ((1 << DRAWOPS_FLAG_BITS) - 1)
     93 #define DRAWOPS_DATA_MASK   ((1 << DRAWOPS_DATA_BITS) - 1)
     94 
     95 static unsigned DrawOp_unpackOp(uint32_t op32) {
     96     return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS));
     97 }
     98 
     99 static unsigned DrawOp_unpackFlags(uint32_t op32) {
    100     return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK;
    101 }
    102 
    103 static unsigned DrawOp_unpackData(uint32_t op32) {
    104     return op32 & DRAWOPS_DATA_MASK;
    105 }
    106 
    107 static uint32_t DrawOp_packOpFlagData(DrawOps op, unsigned flags, unsigned data) {
    108     SkASSERT(0 == (op & ~DRAWOPS_OP_MASK));
    109     SkASSERT(0 == (flags & ~DRAWOPS_FLAG_MASK));
    110     SkASSERT(0 == (data & ~DRAWOPS_DATA_MASK));
    111 
    112     return (op << (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)) |
    113            (flags << DRAWOPS_DATA_BITS) |
    114             data;
    115 }
    116 
    117 /** DrawOp specific flag bits
    118  */
    119 
    120 enum {
    121     kSaveLayer_HasBounds_DrawOpFlag = 1 << 0,
    122     kSaveLayer_HasPaint_DrawOpFlag = 1 << 1,
    123 };
    124 enum {
    125     kClear_HasColor_DrawOpFlag  = 1 << 0
    126 };
    127 enum {
    128     kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0
    129 };
    130 enum {
    131     kDrawVertices_HasTexs_DrawOpFlag     = 1 << 0,
    132     kDrawVertices_HasColors_DrawOpFlag   = 1 << 1,
    133     kDrawVertices_HasIndices_DrawOpFlag  = 1 << 2,
    134 };
    135 
    136 ///////////////////////////////////////////////////////////////////////////////
    137 
    138 enum PaintOps {
    139     kReset_PaintOp,     // no arg
    140 
    141     kFlags_PaintOp,     // arg inline
    142     kColor_PaintOp,     // arg 32
    143     kStyle_PaintOp,     // arg inline
    144     kJoin_PaintOp,      // arg inline
    145     kCap_PaintOp,       // arg inline
    146     kWidth_PaintOp,     // arg scalar
    147     kMiter_PaintOp,// arg scalar
    148 
    149     kEncoding_PaintOp,  // arg inline - text
    150     kHinting_PaintOp,   // arg inline - text
    151     kAlign_PaintOp,     // arg inline - text
    152     kTextSize_PaintOp,  // arg scalar - text
    153     kTextScaleX_PaintOp,// arg scalar - text
    154     kTextSkewX_PaintOp, // arg scalar - text
    155     kTypeface_PaintOp,  // arg inline (index) - text
    156 
    157     kFlatIndex_PaintOp, // flags=paintflat, data=index
    158 };
    159 
    160 #define PAINTOPS_OP_BITS     8
    161 #define PAINTOPS_FLAG_BITS   4
    162 #define PAINTOPS_DATA_BITS   20
    163 
    164 #define PAINTOPS_OP_MASK     ((1 << PAINTOPS_OP_BITS) - 1)
    165 #define PAINTOPS_FLAG_MASK   ((1 << PAINTOPS_FLAG_BITS) - 1)
    166 #define PAINTOPS_DATA_MASK   ((1 << PAINTOPS_DATA_BITS) - 1)
    167 
    168 static unsigned PaintOp_unpackOp(uint32_t op32) {
    169     return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS));
    170 }
    171 
    172 static unsigned PaintOp_unpackFlags(uint32_t op32) {
    173     return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK;
    174 }
    175 
    176 static unsigned PaintOp_unpackData(uint32_t op32) {
    177     return op32 & PAINTOPS_DATA_MASK;
    178 }
    179 
    180 static uint32_t PaintOp_packOp(PaintOps op) {
    181     SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
    182 
    183     return op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS);
    184 }
    185 
    186 static uint32_t PaintOp_packOpData(PaintOps op, unsigned data) {
    187     SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
    188     SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
    189 
    190     return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | data;
    191 }
    192 
    193 static uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsigned data) {
    194     SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
    195     SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK));
    196     SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
    197 
    198     return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) |
    199     (flags << PAINTOPS_DATA_BITS) |
    200     data;
    201 }
    202 
    203 #endif
    204