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.

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

mercurial