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