Sat, 03 Jan 2015 20:18:00 +0100
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 | * Copyright 2011 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef SkPictureRecord_DEFINED |
michael@0 | 9 | #define SkPictureRecord_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkCanvas.h" |
michael@0 | 12 | #include "SkFlattenable.h" |
michael@0 | 13 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
michael@0 | 14 | #include "SkMatrixClipStateMgr.h" |
michael@0 | 15 | #endif |
michael@0 | 16 | #include "SkPathHeap.h" |
michael@0 | 17 | #include "SkPicture.h" |
michael@0 | 18 | #include "SkPictureFlat.h" |
michael@0 | 19 | #include "SkTemplates.h" |
michael@0 | 20 | #include "SkWriter32.h" |
michael@0 | 21 | |
michael@0 | 22 | class SkBBoxHierarchy; |
michael@0 | 23 | class SkOffsetTable; |
michael@0 | 24 | class SkPictureStateTree; |
michael@0 | 25 | |
michael@0 | 26 | // These macros help with packing and unpacking a single byte value and |
michael@0 | 27 | // a 3 byte value into/out of a uint32_t |
michael@0 | 28 | #define MASK_24 0x00FFFFFF |
michael@0 | 29 | #define UNPACK_8_24(combined, small, large) \ |
michael@0 | 30 | small = (combined >> 24) & 0xFF; \ |
michael@0 | 31 | large = combined & MASK_24; |
michael@0 | 32 | #define PACK_8_24(small, large) ((small << 24) | large) |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | class SkPictureRecord : public SkCanvas { |
michael@0 | 36 | public: |
michael@0 | 37 | SkPictureRecord(const SkISize& dimensions, uint32_t recordFlags); |
michael@0 | 38 | virtual ~SkPictureRecord(); |
michael@0 | 39 | |
michael@0 | 40 | virtual void clear(SkColor) SK_OVERRIDE; |
michael@0 | 41 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 42 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
michael@0 | 43 | const SkPaint&) SK_OVERRIDE; |
michael@0 | 44 | virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; |
michael@0 | 45 | virtual void drawRect(const SkRect&, const SkPaint&) SK_OVERRIDE; |
michael@0 | 46 | virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; |
michael@0 | 47 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
michael@0 | 48 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
michael@0 | 49 | const SkPaint*) SK_OVERRIDE; |
michael@0 | 50 | virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
michael@0 | 51 | const SkRect& dst, const SkPaint* paint, |
michael@0 | 52 | DrawBitmapRectFlags flags) SK_OVERRIDE; |
michael@0 | 53 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
michael@0 | 54 | const SkPaint*) SK_OVERRIDE; |
michael@0 | 55 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
michael@0 | 56 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
michael@0 | 57 | virtual void drawSprite(const SkBitmap&, int left, int top, |
michael@0 | 58 | const SkPaint*) SK_OVERRIDE; |
michael@0 | 59 | virtual void drawText(const void* text, size_t byteLength, SkScalar x, |
michael@0 | 60 | SkScalar y, const SkPaint&) SK_OVERRIDE; |
michael@0 | 61 | virtual void drawPosText(const void* text, size_t byteLength, |
michael@0 | 62 | const SkPoint pos[], const SkPaint&) SK_OVERRIDE; |
michael@0 | 63 | virtual void drawPosTextH(const void* text, size_t byteLength, |
michael@0 | 64 | const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE; |
michael@0 | 65 | virtual void drawTextOnPath(const void* text, size_t byteLength, |
michael@0 | 66 | const SkPath& path, const SkMatrix* matrix, |
michael@0 | 67 | const SkPaint&) SK_OVERRIDE; |
michael@0 | 68 | virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
michael@0 | 69 | virtual void drawVertices(VertexMode, int vertexCount, |
michael@0 | 70 | const SkPoint vertices[], const SkPoint texs[], |
michael@0 | 71 | const SkColor colors[], SkXfermode*, |
michael@0 | 72 | const uint16_t indices[], int indexCount, |
michael@0 | 73 | const SkPaint&) SK_OVERRIDE; |
michael@0 | 74 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
michael@0 | 75 | virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
michael@0 | 76 | virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
michael@0 | 77 | virtual void endCommentGroup() SK_OVERRIDE; |
michael@0 | 78 | virtual bool isDrawingToLayer() const SK_OVERRIDE; |
michael@0 | 79 | |
michael@0 | 80 | void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&, |
michael@0 | 81 | SkScalar minY, SkScalar maxY); |
michael@0 | 82 | |
michael@0 | 83 | const SkTDArray<SkPicture* >& getPictureRefs() const { |
michael@0 | 84 | return fPictureRefs; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | void setFlags(uint32_t recordFlags) { |
michael@0 | 88 | fRecordFlags = recordFlags; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | const SkWriter32& writeStream() const { |
michael@0 | 92 | return fWriter; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | void beginRecording(); |
michael@0 | 96 | void endRecording(); |
michael@0 | 97 | |
michael@0 | 98 | void internalOnly_EnableOpts(bool optsEnabled) { |
michael@0 | 99 | fOptsEnabled = optsEnabled; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | private: |
michael@0 | 103 | void handleOptimization(int opt); |
michael@0 | 104 | int recordRestoreOffsetPlaceholder(SkRegion::Op); |
michael@0 | 105 | void fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset); |
michael@0 | 106 | |
michael@0 | 107 | #ifndef SK_COLLAPSE_MATRIX_CLIP_STATE |
michael@0 | 108 | SkTDArray<int32_t> fRestoreOffsetStack; |
michael@0 | 109 | int fFirstSavedLayerIndex; |
michael@0 | 110 | enum { |
michael@0 | 111 | kNoSavedLayerIndex = -1 |
michael@0 | 112 | }; |
michael@0 | 113 | #endif |
michael@0 | 114 | |
michael@0 | 115 | SkTDArray<uint32_t> fCullOffsetStack; |
michael@0 | 116 | |
michael@0 | 117 | /* |
michael@0 | 118 | * Write the 'drawType' operation and chunk size to the skp. 'size' |
michael@0 | 119 | * can potentially be increased if the chunk size needs its own storage |
michael@0 | 120 | * location (i.e., it overflows 24 bits). |
michael@0 | 121 | * Returns the start offset of the chunk. This is the location at which |
michael@0 | 122 | * the opcode & size are stored. |
michael@0 | 123 | * TODO: since we are handing the size into here we could call reserve |
michael@0 | 124 | * and then return a pointer to the memory storage. This could decrease |
michael@0 | 125 | * allocation overhead but could lead to more wasted space (the tail |
michael@0 | 126 | * end of blocks could go unused). Possibly add a second addDraw that |
michael@0 | 127 | * operates in this manner. |
michael@0 | 128 | */ |
michael@0 | 129 | size_t addDraw(DrawType drawType, uint32_t* size) { |
michael@0 | 130 | size_t offset = fWriter.bytesWritten(); |
michael@0 | 131 | |
michael@0 | 132 | this->predrawNotify(); |
michael@0 | 133 | |
michael@0 | 134 | #ifdef SK_DEBUG_TRACE |
michael@0 | 135 | SkDebugf("add %s\n", DrawTypeToString(drawType)); |
michael@0 | 136 | #endif |
michael@0 | 137 | |
michael@0 | 138 | SkASSERT(0 != *size); |
michael@0 | 139 | SkASSERT(((uint8_t) drawType) == drawType); |
michael@0 | 140 | |
michael@0 | 141 | if (0 != (*size & ~MASK_24) || *size == MASK_24) { |
michael@0 | 142 | fWriter.writeInt(PACK_8_24(drawType, MASK_24)); |
michael@0 | 143 | *size += 1; |
michael@0 | 144 | fWriter.writeInt(*size); |
michael@0 | 145 | } else { |
michael@0 | 146 | fWriter.writeInt(PACK_8_24(drawType, *size)); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | return offset; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | void addInt(int value) { |
michael@0 | 153 | fWriter.writeInt(value); |
michael@0 | 154 | } |
michael@0 | 155 | void addScalar(SkScalar scalar) { |
michael@0 | 156 | fWriter.writeScalar(scalar); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | // The command at 'offset' in the skp uses the specified bitmap |
michael@0 | 160 | void trackBitmapUse(int bitmapID, size_t offset); |
michael@0 | 161 | int addBitmap(const SkBitmap& bitmap); |
michael@0 | 162 | void addMatrix(const SkMatrix& matrix); |
michael@0 | 163 | const SkFlatData* addPaint(const SkPaint& paint) { return this->addPaintPtr(&paint); } |
michael@0 | 164 | const SkFlatData* addPaintPtr(const SkPaint* paint); |
michael@0 | 165 | void addFlatPaint(const SkFlatData* flatPaint); |
michael@0 | 166 | void addPath(const SkPath& path); |
michael@0 | 167 | void addPicture(SkPicture& picture); |
michael@0 | 168 | void addPoint(const SkPoint& point); |
michael@0 | 169 | void addPoints(const SkPoint pts[], int count); |
michael@0 | 170 | void addRect(const SkRect& rect); |
michael@0 | 171 | void addRectPtr(const SkRect* rect); |
michael@0 | 172 | void addIRect(const SkIRect& rect); |
michael@0 | 173 | void addIRectPtr(const SkIRect* rect); |
michael@0 | 174 | void addRRect(const SkRRect&); |
michael@0 | 175 | void addRegion(const SkRegion& region); |
michael@0 | 176 | void addText(const void* text, size_t byteLength); |
michael@0 | 177 | |
michael@0 | 178 | int find(const SkBitmap& bitmap); |
michael@0 | 179 | |
michael@0 | 180 | #ifdef SK_DEBUG_DUMP |
michael@0 | 181 | public: |
michael@0 | 182 | void dumpMatrices(); |
michael@0 | 183 | void dumpPaints(); |
michael@0 | 184 | #endif |
michael@0 | 185 | |
michael@0 | 186 | #ifdef SK_DEBUG_SIZE |
michael@0 | 187 | public: |
michael@0 | 188 | size_t size() const; |
michael@0 | 189 | int bitmaps(size_t* size) const; |
michael@0 | 190 | int matrices(size_t* size) const; |
michael@0 | 191 | int paints(size_t* size) const; |
michael@0 | 192 | int paths(size_t* size) const; |
michael@0 | 193 | int regions(size_t* size) const; |
michael@0 | 194 | size_t streamlen() const; |
michael@0 | 195 | |
michael@0 | 196 | size_t fPointBytes, fRectBytes, fTextBytes; |
michael@0 | 197 | int fPointWrites, fRectWrites, fTextWrites; |
michael@0 | 198 | #endif |
michael@0 | 199 | |
michael@0 | 200 | #ifdef SK_DEBUG_VALIDATE |
michael@0 | 201 | public: |
michael@0 | 202 | void validate(size_t initialOffset, uint32_t size) const; |
michael@0 | 203 | private: |
michael@0 | 204 | void validateBitmaps() const; |
michael@0 | 205 | void validateMatrices() const; |
michael@0 | 206 | void validatePaints() const; |
michael@0 | 207 | void validatePaths() const; |
michael@0 | 208 | void validateRegions() const; |
michael@0 | 209 | #else |
michael@0 | 210 | public: |
michael@0 | 211 | void validate(size_t initialOffset, uint32_t size) const { |
michael@0 | 212 | SkASSERT(fWriter.bytesWritten() == initialOffset + size); |
michael@0 | 213 | } |
michael@0 | 214 | #endif |
michael@0 | 215 | |
michael@0 | 216 | protected: |
michael@0 | 217 | virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; |
michael@0 | 218 | const void* onPeekPixels(SkImageInfo*, size_t*) SK_OVERRIDE { |
michael@0 | 219 | return NULL; |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | virtual void willSave(SaveFlags) SK_OVERRIDE; |
michael@0 | 223 | virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; |
michael@0 | 224 | virtual void willRestore() SK_OVERRIDE; |
michael@0 | 225 | |
michael@0 | 226 | virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE; |
michael@0 | 227 | virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE; |
michael@0 | 228 | virtual void didRotate(SkScalar) SK_OVERRIDE; |
michael@0 | 229 | virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE; |
michael@0 | 230 | virtual void didConcat(const SkMatrix&) SK_OVERRIDE; |
michael@0 | 231 | virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; |
michael@0 | 232 | |
michael@0 | 233 | virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; |
michael@0 | 234 | virtual void onPushCull(const SkRect&) SK_OVERRIDE; |
michael@0 | 235 | virtual void onPopCull() SK_OVERRIDE; |
michael@0 | 236 | |
michael@0 | 237 | virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
michael@0 | 238 | virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
michael@0 | 239 | virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
michael@0 | 240 | virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; |
michael@0 | 241 | |
michael@0 | 242 | // Return fontmetrics.fTop,fBottom in topbot[0,1], after they have been |
michael@0 | 243 | // tweaked by paint.computeFastBounds(). |
michael@0 | 244 | static void ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]); |
michael@0 | 245 | |
michael@0 | 246 | // Make sure that flat has fTopBot written. |
michael@0 | 247 | static void WriteTopBot(const SkPaint& paint, const SkFlatData& flat) { |
michael@0 | 248 | if (!flat.isTopBotWritten()) { |
michael@0 | 249 | ComputeFontMetricsTopBottom(paint, flat.writableTopBot()); |
michael@0 | 250 | SkASSERT(flat.isTopBotWritten()); |
michael@0 | 251 | } |
michael@0 | 252 | } |
michael@0 | 253 | // Will return a cached version when possible. |
michael@0 | 254 | const SkFlatData* getFlatPaintData(const SkPaint& paint); |
michael@0 | 255 | /** |
michael@0 | 256 | * SkBBoxRecord::drawPosTextH gets a flat paint and uses it, |
michael@0 | 257 | * then it calls this, using the extra parameter, to avoid duplication. |
michael@0 | 258 | */ |
michael@0 | 259 | void drawPosTextHImpl(const void* text, size_t byteLength, |
michael@0 | 260 | const SkScalar xpos[], SkScalar constY, |
michael@0 | 261 | const SkPaint& paint, const SkFlatData* flatPaintData); |
michael@0 | 262 | |
michael@0 | 263 | int addPathToHeap(const SkPath& path); // does not write to ops stream |
michael@0 | 264 | |
michael@0 | 265 | // These entry points allow the writing of matrices, clips, saves & |
michael@0 | 266 | // restores to be deferred (e.g., if the MC state is being collapsed and |
michael@0 | 267 | // only written out as needed). |
michael@0 | 268 | void recordConcat(const SkMatrix& matrix); |
michael@0 | 269 | int recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA); |
michael@0 | 270 | int recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA); |
michael@0 | 271 | int recordClipPath(int pathID, SkRegion::Op op, bool doAA); |
michael@0 | 272 | int recordClipRegion(const SkRegion& region, SkRegion::Op op); |
michael@0 | 273 | void recordSave(SaveFlags flags); |
michael@0 | 274 | void recordSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); |
michael@0 | 275 | void recordRestore(bool fillInSkips = true); |
michael@0 | 276 | |
michael@0 | 277 | // These are set to NULL in our constructor, but may be changed by |
michael@0 | 278 | // subclasses, in which case they will be SkSafeUnref'd in our destructor. |
michael@0 | 279 | SkBBoxHierarchy* fBoundingHierarchy; |
michael@0 | 280 | SkPictureStateTree* fStateTree; |
michael@0 | 281 | |
michael@0 | 282 | // Allocated in the constructor and managed by this class. |
michael@0 | 283 | SkBitmapHeap* fBitmapHeap; |
michael@0 | 284 | |
michael@0 | 285 | private: |
michael@0 | 286 | friend class MatrixClipState; // for access to *Impl methods |
michael@0 | 287 | friend class SkMatrixClipStateMgr; // for access to *Impl methods |
michael@0 | 288 | |
michael@0 | 289 | SkChunkFlatController fFlattenableHeap; |
michael@0 | 290 | |
michael@0 | 291 | SkPaintDictionary fPaints; |
michael@0 | 292 | |
michael@0 | 293 | SkPathHeap* fPathHeap; // reference counted |
michael@0 | 294 | SkWriter32 fWriter; |
michael@0 | 295 | |
michael@0 | 296 | // we ref each item in these arrays |
michael@0 | 297 | SkTDArray<SkPicture*> fPictureRefs; |
michael@0 | 298 | |
michael@0 | 299 | uint32_t fRecordFlags; |
michael@0 | 300 | bool fOptsEnabled; |
michael@0 | 301 | int fInitialSaveCount; |
michael@0 | 302 | |
michael@0 | 303 | SkAutoTUnref<SkOffsetTable> fBitmapUseOffsets; |
michael@0 | 304 | |
michael@0 | 305 | friend class SkPicturePlayback; |
michael@0 | 306 | friend class SkPictureTester; // for unit testing |
michael@0 | 307 | |
michael@0 | 308 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
michael@0 | 309 | SkMatrixClipStateMgr fMCMgr; |
michael@0 | 310 | #endif |
michael@0 | 311 | |
michael@0 | 312 | typedef SkCanvas INHERITED; |
michael@0 | 313 | }; |
michael@0 | 314 | |
michael@0 | 315 | #endif |