gfx/skia/trunk/src/pipe/SkGPipePriv.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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  */
    11 #ifndef SkGPipePriv_DEFINED
    12 #define SkGPipePriv_DEFINED
    14 #include "SkTypes.h"
    16 #define UNIMPLEMENTED
    18 // these must be contiguous, 0...N-1
    19 enum PaintFlats {
    20     kColorFilter_PaintFlat,
    21     kDrawLooper_PaintFlat,
    22     kImageFilter_PaintFlat,
    23     kMaskFilter_PaintFlat,
    24     kPathEffect_PaintFlat,
    25     kRasterizer_PaintFlat,
    26     kShader_PaintFlat,
    27     kXfermode_PaintFlat,
    29     kLast_PaintFlat = kXfermode_PaintFlat
    30 };
    31 #define kCount_PaintFlats   (kLast_PaintFlat + 1)
    33 enum DrawOps {
    34     kSkip_DrawOp,   // skip an addition N bytes (N == data)
    36     // these match Canvas apis
    37     kClipPath_DrawOp,
    38     kClipRegion_DrawOp,
    39     kClipRect_DrawOp,
    40     kClipRRect_DrawOp,
    41     kConcat_DrawOp,
    42     kDrawBitmap_DrawOp,
    43     kDrawBitmapMatrix_DrawOp,
    44     kDrawBitmapNine_DrawOp,
    45     kDrawBitmapRectToRect_DrawOp,
    46     kDrawClear_DrawOp,
    47     kDrawData_DrawOp,
    48     kDrawDRRect_DrawOp,
    49     kDrawOval_DrawOp,
    50     kDrawPaint_DrawOp,
    51     kDrawPath_DrawOp,
    52     kDrawPicture_DrawOp,
    53     kDrawPoints_DrawOp,
    54     kDrawPosText_DrawOp,
    55     kDrawPosTextH_DrawOp,
    56     kDrawRect_DrawOp,
    57     kDrawRRect_DrawOp,
    58     kDrawSprite_DrawOp,
    59     kDrawText_DrawOp,
    60     kDrawTextOnPath_DrawOp,
    61     kDrawVertices_DrawOp,
    62     kRestore_DrawOp,
    63     kRotate_DrawOp,
    64     kSave_DrawOp,
    65     kSaveLayer_DrawOp,
    66     kScale_DrawOp,
    67     kSetMatrix_DrawOp,
    68     kSkew_DrawOp,
    69     kTranslate_DrawOp,
    71     kPaintOp_DrawOp,
    72     kSetTypeface_DrawOp,
    73     kSetAnnotation_DrawOp,
    75     kDef_Typeface_DrawOp,
    76     kDef_Flattenable_DrawOp,
    77     kDef_Bitmap_DrawOp,
    78     kDef_Factory_DrawOp,
    80     // these are signals to playback, not drawing verbs
    81     kReportFlags_DrawOp,
    82     kShareBitmapHeap_DrawOp,
    83     kDone_DrawOp,
    84 };
    86 /**
    87  *  DrawOp packs into a 32bit int as follows
    88  *
    89  *  DrawOp:8 - Flags:4 - Data:20
    90  *
    91  *  Flags and Data are called out separately, so we can reuse Data between
    92  *  different Ops that might have different Flags. e.g. Data might be a Paint
    93  *  index for both drawRect (no flags) and saveLayer (does have flags).
    94  *
    95  *  All Ops that take a SkPaint use their Data field to store the index to
    96  *  the paint (previously defined with kPaintOp_DrawOp).
    97  */
    99 #define DRAWOPS_OP_BITS     8
   100 #define DRAWOPS_FLAG_BITS   4
   101 #define DRAWOPS_DATA_BITS   20
   103 #define DRAWOPS_OP_MASK     ((1 << DRAWOPS_OP_BITS) - 1)
   104 #define DRAWOPS_FLAG_MASK   ((1 << DRAWOPS_FLAG_BITS) - 1)
   105 #define DRAWOPS_DATA_MASK   ((1 << DRAWOPS_DATA_BITS) - 1)
   107 static inline unsigned DrawOp_unpackOp(uint32_t op32) {
   108     return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS));
   109 }
   111 static inline unsigned DrawOp_unpackFlags(uint32_t op32) {
   112     return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK;
   113 }
   115 static inline unsigned DrawOp_unpackData(uint32_t op32) {
   116     return op32 & DRAWOPS_DATA_MASK;
   117 }
   119 static inline uint32_t DrawOp_packOpFlagData(DrawOps op, unsigned flags, unsigned data) {
   120     SkASSERT(0 == (op & ~DRAWOPS_OP_MASK));
   121     SkASSERT(0 == (flags & ~DRAWOPS_FLAG_MASK));
   122     SkASSERT(0 == (data & ~DRAWOPS_DATA_MASK));
   124     return (op << (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)) |
   125            (flags << DRAWOPS_DATA_BITS) |
   126             data;
   127 }
   129 /** DrawOp specific flag bits
   130  */
   132 enum {
   133     kSaveLayer_HasBounds_DrawOpFlag = 1 << 0,
   134     kSaveLayer_HasPaint_DrawOpFlag = 1 << 1,
   135 };
   136 enum {
   137     kClear_HasColor_DrawOpFlag  = 1 << 0
   138 };
   139 enum {
   140     kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0
   141 };
   142 enum {
   143     kDrawVertices_HasTexs_DrawOpFlag     = 1 << 0,
   144     kDrawVertices_HasColors_DrawOpFlag   = 1 << 1,
   145     kDrawVertices_HasIndices_DrawOpFlag  = 1 << 2,
   146     kDrawVertices_HasXfermode_DrawOpFlag = 1 << 3,
   147 };
   148 enum {
   149     kDrawBitmap_HasPaint_DrawOpFlag   = 1 << 0,
   150     // Specific to drawBitmapRect, but needs to be different from HasPaint,
   151     // which is used for all drawBitmap calls, so include it here.
   152     kDrawBitmap_HasSrcRect_DrawOpFlag = 1 << 1,
   153     // SkCanvas::DrawBitmapRectFlags::kBleed_DrawBitmapRectFlag is
   154     // converted into and out of this flag to save space
   155     kDrawBitmap_Bleed_DrawOpFlag      = 1 << 2,
   156 };
   157 enum {
   158     kClip_HasAntiAlias_DrawOpFlag = 1 << 0,
   159 };
   160 ///////////////////////////////////////////////////////////////////////////////
   162 class BitmapInfo : SkNoncopyable {
   163 public:
   164     BitmapInfo(SkBitmap* bitmap, uint32_t genID, int toBeDrawnCount)
   165         : fBitmap(bitmap)
   166         , fGenID(genID)
   167         , fBytesAllocated(0)
   168         , fMoreRecentlyUsed(NULL)
   169         , fLessRecentlyUsed(NULL)
   170         , fToBeDrawnCount(toBeDrawnCount)
   171     {}
   173     ~BitmapInfo() {
   174         SkASSERT(0 == fToBeDrawnCount);
   175         SkDELETE(fBitmap);
   176     }
   178     void addDraws(int drawsToAdd) {
   179         if (0 == fToBeDrawnCount) {
   180             // The readers will only ever decrement the count, so once the
   181             // count is zero, the writer will be the only one modifying it,
   182             // so it does not need to be an atomic operation.
   183             fToBeDrawnCount = drawsToAdd;
   184         } else {
   185             sk_atomic_add(&fToBeDrawnCount, drawsToAdd);
   186         }
   187     }
   189     void decDraws() {
   190         sk_atomic_dec(&fToBeDrawnCount);
   191     }
   193     int drawCount() const {
   194         return fToBeDrawnCount;
   195     }
   197     SkBitmap* fBitmap;
   198     // Store the generation ID of the original bitmap, since copying does
   199     // not copy this field, so fBitmap's generation ID will not be useful
   200     // for comparing.
   201     // FIXME: Is it reasonable to make copying a bitmap/pixelref copy the
   202     // generation ID?
   203     uint32_t fGenID;
   204     // Keep track of the bytes allocated for this bitmap. When replacing the
   205     // bitmap or removing this BitmapInfo we know how much memory has been
   206     // reclaimed.
   207     size_t fBytesAllocated;
   208     // TODO: Generalize the LRU caching mechanism
   209     BitmapInfo* fMoreRecentlyUsed;
   210     BitmapInfo* fLessRecentlyUsed;
   211 private:
   212     int      fToBeDrawnCount;
   213 };
   215 static inline bool shouldFlattenBitmaps(uint32_t flags) {
   216     return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag
   217             && !(flags & SkGPipeWriter::kSharedAddressSpace_Flag));
   218 }
   220 ///////////////////////////////////////////////////////////////////////////////
   222 enum PaintOps {
   223     kReset_PaintOp,     // no arg
   225     kFlags_PaintOp,     // arg inline
   226     kColor_PaintOp,     // arg 32
   227     kStyle_PaintOp,     // arg inline
   228     kJoin_PaintOp,      // arg inline
   229     kCap_PaintOp,       // arg inline
   230     kWidth_PaintOp,     // arg scalar
   231     kMiter_PaintOp,     // arg scalar
   233     kEncoding_PaintOp,  // arg inline - text
   234     kHinting_PaintOp,   // arg inline - text
   235     kAlign_PaintOp,     // arg inline - text
   236     kTextSize_PaintOp,  // arg scalar - text
   237     kTextScaleX_PaintOp,// arg scalar - text
   238     kTextSkewX_PaintOp, // arg scalar - text
   239     kTypeface_PaintOp,  // arg inline (index) - text
   241     kFlatIndex_PaintOp, // flags=paintflat, data=index
   242 };
   244 #define PAINTOPS_OP_BITS     8
   245 #define PAINTOPS_FLAG_BITS   4
   246 #define PAINTOPS_DATA_BITS   20
   248 #define PAINTOPS_OP_MASK     ((1 << PAINTOPS_OP_BITS) - 1)
   249 #define PAINTOPS_FLAG_MASK   ((1 << PAINTOPS_FLAG_BITS) - 1)
   250 #define PAINTOPS_DATA_MASK   ((1 << PAINTOPS_DATA_BITS) - 1)
   252 static inline unsigned PaintOp_unpackOp(uint32_t op32) {
   253     return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS));
   254 }
   256 static inline unsigned PaintOp_unpackFlags(uint32_t op32) {
   257     return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK;
   258 }
   260 static inline unsigned PaintOp_unpackData(uint32_t op32) {
   261     return op32 & PAINTOPS_DATA_MASK;
   262 }
   264 static inline uint32_t PaintOp_packOp(PaintOps op) {
   265     SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
   267     return op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS);
   268 }
   270 static inline uint32_t PaintOp_packOpData(PaintOps op, unsigned data) {
   271     SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
   272     SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
   274     return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | data;
   275 }
   277 static inline uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsigned data) {
   278     SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
   279     SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK));
   280     SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
   282     return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) |
   283     (flags << PAINTOPS_DATA_BITS) |
   284     data;
   285 }
   287 #endif

mercurial