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 | /* |
michael@0 | 3 | * Copyright 2007 The Android Open Source Project |
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 | #ifndef SkPicture_DEFINED |
michael@0 | 11 | #define SkPicture_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkBitmap.h" |
michael@0 | 14 | #include "SkImageDecoder.h" |
michael@0 | 15 | #include "SkRefCnt.h" |
michael@0 | 16 | |
michael@0 | 17 | class SkBBoxHierarchy; |
michael@0 | 18 | class SkCanvas; |
michael@0 | 19 | class SkDrawPictureCallback; |
michael@0 | 20 | class SkData; |
michael@0 | 21 | class SkPicturePlayback; |
michael@0 | 22 | class SkPictureRecord; |
michael@0 | 23 | class SkStream; |
michael@0 | 24 | class SkWStream; |
michael@0 | 25 | |
michael@0 | 26 | struct SkPictInfo; |
michael@0 | 27 | |
michael@0 | 28 | /** \class SkPicture |
michael@0 | 29 | |
michael@0 | 30 | The SkPicture class records the drawing commands made to a canvas, to |
michael@0 | 31 | be played back at a later time. |
michael@0 | 32 | */ |
michael@0 | 33 | class SK_API SkPicture : public SkRefCnt { |
michael@0 | 34 | public: |
michael@0 | 35 | SK_DECLARE_INST_COUNT(SkPicture) |
michael@0 | 36 | |
michael@0 | 37 | // AccelData provides a base class for device-specific acceleration |
michael@0 | 38 | // data. It is added to the picture via a call to a device's optimize |
michael@0 | 39 | // method. |
michael@0 | 40 | class AccelData : public SkRefCnt { |
michael@0 | 41 | public: |
michael@0 | 42 | typedef uint8_t Domain; |
michael@0 | 43 | typedef uint32_t Key; |
michael@0 | 44 | |
michael@0 | 45 | AccelData(Key key) : fKey(key) { } |
michael@0 | 46 | |
michael@0 | 47 | const Key& getKey() const { return fKey; } |
michael@0 | 48 | |
michael@0 | 49 | // This entry point allows user's to get a unique domain prefix |
michael@0 | 50 | // for their keys |
michael@0 | 51 | static Domain GenerateDomain(); |
michael@0 | 52 | private: |
michael@0 | 53 | Key fKey; |
michael@0 | 54 | |
michael@0 | 55 | typedef SkRefCnt INHERITED; |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | /** The constructor prepares the picture to record. |
michael@0 | 59 | @param width the width of the virtual device the picture records. |
michael@0 | 60 | @param height the height of the virtual device the picture records. |
michael@0 | 61 | */ |
michael@0 | 62 | SkPicture(); |
michael@0 | 63 | /** Make a copy of the contents of src. If src records more drawing after |
michael@0 | 64 | this call, those elements will not appear in this picture. |
michael@0 | 65 | */ |
michael@0 | 66 | SkPicture(const SkPicture& src); |
michael@0 | 67 | |
michael@0 | 68 | /** PRIVATE / EXPERIMENTAL -- do not call */ |
michael@0 | 69 | void EXPERIMENTAL_addAccelData(const AccelData* data) { |
michael@0 | 70 | SkRefCnt_SafeAssign(fAccelData, data); |
michael@0 | 71 | } |
michael@0 | 72 | /** PRIVATE / EXPERIMENTAL -- do not call */ |
michael@0 | 73 | const AccelData* EXPERIMENTAL_getAccelData(AccelData::Key key) const { |
michael@0 | 74 | if (NULL != fAccelData && fAccelData->getKey() == key) { |
michael@0 | 75 | return fAccelData; |
michael@0 | 76 | } |
michael@0 | 77 | return NULL; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Function signature defining a function that sets up an SkBitmap from encoded data. On |
michael@0 | 82 | * success, the SkBitmap should have its Config, width, height, rowBytes and pixelref set. |
michael@0 | 83 | * If the installed pixelref has decoded the data into pixels, then the src buffer need not be |
michael@0 | 84 | * copied. If the pixelref defers the actual decode until its lockPixels() is called, then it |
michael@0 | 85 | * must make a copy of the src buffer. |
michael@0 | 86 | * @param src Encoded data. |
michael@0 | 87 | * @param length Size of the encoded data, in bytes. |
michael@0 | 88 | * @param dst SkBitmap to install the pixel ref on. |
michael@0 | 89 | * @param bool Whether or not a pixel ref was successfully installed. |
michael@0 | 90 | */ |
michael@0 | 91 | typedef bool (*InstallPixelRefProc)(const void* src, size_t length, SkBitmap* dst); |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * Recreate a picture that was serialized into a stream. |
michael@0 | 95 | * @param SkStream Serialized picture data. |
michael@0 | 96 | * @param proc Function pointer for installing pixelrefs on SkBitmaps representing the |
michael@0 | 97 | * encoded bitmap data from the stream. |
michael@0 | 98 | * @return A new SkPicture representing the serialized data, or NULL if the stream is |
michael@0 | 99 | * invalid. |
michael@0 | 100 | */ |
michael@0 | 101 | static SkPicture* CreateFromStream(SkStream*, |
michael@0 | 102 | InstallPixelRefProc proc = &SkImageDecoder::DecodeMemory); |
michael@0 | 103 | |
michael@0 | 104 | /** |
michael@0 | 105 | * Recreate a picture that was serialized into a buffer. If the creation requires bitmap |
michael@0 | 106 | * decoding, the decoder must be set on the SkReadBuffer parameter by calling |
michael@0 | 107 | * SkReadBuffer::setBitmapDecoder() before calling SkPicture::CreateFromBuffer(). |
michael@0 | 108 | * @param SkReadBuffer Serialized picture data. |
michael@0 | 109 | * @return A new SkPicture representing the serialized data, or NULL if the buffer is |
michael@0 | 110 | * invalid. |
michael@0 | 111 | */ |
michael@0 | 112 | static SkPicture* CreateFromBuffer(SkReadBuffer&); |
michael@0 | 113 | |
michael@0 | 114 | virtual ~SkPicture(); |
michael@0 | 115 | |
michael@0 | 116 | /** |
michael@0 | 117 | * Swap the contents of the two pictures. Guaranteed to succeed. |
michael@0 | 118 | */ |
michael@0 | 119 | void swap(SkPicture& other); |
michael@0 | 120 | |
michael@0 | 121 | /** |
michael@0 | 122 | * Creates a thread-safe clone of the picture that is ready for playback. |
michael@0 | 123 | */ |
michael@0 | 124 | SkPicture* clone() const; |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * Creates multiple thread-safe clones of this picture that are ready for |
michael@0 | 128 | * playback. The resulting clones are stored in the provided array of |
michael@0 | 129 | * SkPictures. |
michael@0 | 130 | */ |
michael@0 | 131 | void clone(SkPicture* pictures, int count) const; |
michael@0 | 132 | |
michael@0 | 133 | enum RecordingFlags { |
michael@0 | 134 | /* This flag specifies that when clipPath() is called, the path will |
michael@0 | 135 | be faithfully recorded, but the recording canvas' current clip will |
michael@0 | 136 | only see the path's bounds. This speeds up the recording process |
michael@0 | 137 | without compromising the fidelity of the playback. The only side- |
michael@0 | 138 | effect for recording is that calling getTotalClip() or related |
michael@0 | 139 | clip-query calls will reflect the path's bounds, not the actual |
michael@0 | 140 | path. |
michael@0 | 141 | */ |
michael@0 | 142 | kUsePathBoundsForClip_RecordingFlag = 0x01, |
michael@0 | 143 | /* This flag causes the picture to compute bounding boxes and build |
michael@0 | 144 | up a spatial hierarchy (currently an R-Tree), plus a tree of Canvas' |
michael@0 | 145 | usually stack-based clip/etc state. This requires an increase in |
michael@0 | 146 | recording time (often ~2x; likely more for very complex pictures), |
michael@0 | 147 | but allows us to perform much faster culling at playback time, and |
michael@0 | 148 | completely avoid some unnecessary clips and other operations. This |
michael@0 | 149 | is ideal for tiled rendering, or any other situation where you're |
michael@0 | 150 | drawing a fraction of a large scene into a smaller viewport. |
michael@0 | 151 | |
michael@0 | 152 | In most cases the record cost is offset by the playback improvement |
michael@0 | 153 | after a frame or two of tiled rendering (and complex pictures that |
michael@0 | 154 | induce the worst record times will generally get the largest |
michael@0 | 155 | speedups at playback time). |
michael@0 | 156 | |
michael@0 | 157 | Note: Currently this is not serializable, the bounding data will be |
michael@0 | 158 | discarded if you serialize into a stream and then deserialize. |
michael@0 | 159 | */ |
michael@0 | 160 | kOptimizeForClippedPlayback_RecordingFlag = 0x02, |
michael@0 | 161 | }; |
michael@0 | 162 | |
michael@0 | 163 | /** Returns the canvas that records the drawing commands. |
michael@0 | 164 | @param width the base width for the picture, as if the recording |
michael@0 | 165 | canvas' bitmap had this width. |
michael@0 | 166 | @param height the base width for the picture, as if the recording |
michael@0 | 167 | canvas' bitmap had this height. |
michael@0 | 168 | @param recordFlags optional flags that control recording. |
michael@0 | 169 | @return the picture canvas. |
michael@0 | 170 | */ |
michael@0 | 171 | SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0); |
michael@0 | 172 | |
michael@0 | 173 | /** Returns the recording canvas if one is active, or NULL if recording is |
michael@0 | 174 | not active. This does not alter the refcnt on the canvas (if present). |
michael@0 | 175 | */ |
michael@0 | 176 | SkCanvas* getRecordingCanvas() const; |
michael@0 | 177 | /** Signal that the caller is done recording. This invalidates the canvas |
michael@0 | 178 | returned by beginRecording/getRecordingCanvas, and prepares the picture |
michael@0 | 179 | for drawing. Note: this happens implicitly the first time the picture |
michael@0 | 180 | is drawn. |
michael@0 | 181 | */ |
michael@0 | 182 | void endRecording(); |
michael@0 | 183 | |
michael@0 | 184 | /** Replays the drawing commands on the specified canvas. This internally |
michael@0 | 185 | calls endRecording() if that has not already been called. |
michael@0 | 186 | @param canvas the canvas receiving the drawing commands. |
michael@0 | 187 | */ |
michael@0 | 188 | void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL); |
michael@0 | 189 | |
michael@0 | 190 | /** Return the width of the picture's recording canvas. This |
michael@0 | 191 | value reflects what was passed to setSize(), and does not necessarily |
michael@0 | 192 | reflect the bounds of what has been recorded into the picture. |
michael@0 | 193 | @return the width of the picture's recording canvas |
michael@0 | 194 | */ |
michael@0 | 195 | int width() const { return fWidth; } |
michael@0 | 196 | |
michael@0 | 197 | /** Return the height of the picture's recording canvas. This |
michael@0 | 198 | value reflects what was passed to setSize(), and does not necessarily |
michael@0 | 199 | reflect the bounds of what has been recorded into the picture. |
michael@0 | 200 | @return the height of the picture's recording canvas |
michael@0 | 201 | */ |
michael@0 | 202 | int height() const { return fHeight; } |
michael@0 | 203 | |
michael@0 | 204 | /** |
michael@0 | 205 | * Function to encode an SkBitmap to an SkData. A function with this |
michael@0 | 206 | * signature can be passed to serialize() and SkWriteBuffer. |
michael@0 | 207 | * Returning NULL will tell the SkWriteBuffer to use |
michael@0 | 208 | * SkBitmap::flatten() to store the bitmap. |
michael@0 | 209 | * |
michael@0 | 210 | * @param pixelRefOffset DEPRECATED -- caller assumes it will return 0. |
michael@0 | 211 | * @return SkData If non-NULL, holds encoded data representing the passed |
michael@0 | 212 | * in bitmap. The caller is responsible for calling unref(). |
michael@0 | 213 | */ |
michael@0 | 214 | typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm); |
michael@0 | 215 | |
michael@0 | 216 | /** |
michael@0 | 217 | * Serialize to a stream. If non NULL, encoder will be used to encode |
michael@0 | 218 | * any bitmaps in the picture. |
michael@0 | 219 | * encoder will never be called with a NULL pixelRefOffset. |
michael@0 | 220 | */ |
michael@0 | 221 | void serialize(SkWStream*, EncodeBitmap encoder = NULL) const; |
michael@0 | 222 | |
michael@0 | 223 | /** |
michael@0 | 224 | * Serialize to a buffer. |
michael@0 | 225 | */ |
michael@0 | 226 | void flatten(SkWriteBuffer&) const; |
michael@0 | 227 | |
michael@0 | 228 | /** |
michael@0 | 229 | * Returns true if any bitmaps may be produced when this SkPicture |
michael@0 | 230 | * is replayed. |
michael@0 | 231 | * Returns false if called while still recording. |
michael@0 | 232 | */ |
michael@0 | 233 | bool willPlayBackBitmaps() const; |
michael@0 | 234 | |
michael@0 | 235 | #ifdef SK_BUILD_FOR_ANDROID |
michael@0 | 236 | /** Signals that the caller is prematurely done replaying the drawing |
michael@0 | 237 | commands. This can be called from a canvas virtual while the picture |
michael@0 | 238 | is drawing. Has no effect if the picture is not drawing. |
michael@0 | 239 | @deprecated preserving for legacy purposes |
michael@0 | 240 | */ |
michael@0 | 241 | void abortPlayback(); |
michael@0 | 242 | #endif |
michael@0 | 243 | |
michael@0 | 244 | /** Return true if the SkStream/Buffer represents a serialized picture, and |
michael@0 | 245 | fills out SkPictInfo. After this function returns, the data source is not |
michael@0 | 246 | rewound so it will have to be manually reset before passing to |
michael@0 | 247 | CreateFromStream or CreateFromBuffer. Note, CreateFromStream and |
michael@0 | 248 | CreateFromBuffer perform this check internally so these entry points are |
michael@0 | 249 | intended for stand alone tools. |
michael@0 | 250 | If false is returned, SkPictInfo is unmodified. |
michael@0 | 251 | */ |
michael@0 | 252 | static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*); |
michael@0 | 253 | static bool InternalOnly_BufferIsSKP(SkReadBuffer&, SkPictInfo*); |
michael@0 | 254 | |
michael@0 | 255 | /** Enable/disable all the picture recording optimizations (i.e., |
michael@0 | 256 | those in SkPictureRecord). It is mainly intended for testing the |
michael@0 | 257 | existing optimizations (i.e., to actually have the pattern |
michael@0 | 258 | appear in an .skp we have to disable the optimization). Call right |
michael@0 | 259 | after 'beginRecording'. |
michael@0 | 260 | */ |
michael@0 | 261 | void internalOnly_EnableOpts(bool enableOpts); |
michael@0 | 262 | |
michael@0 | 263 | protected: |
michael@0 | 264 | // V2 : adds SkPixelRef's generation ID. |
michael@0 | 265 | // V3 : PictInfo tag at beginning, and EOF tag at the end |
michael@0 | 266 | // V4 : move SkPictInfo to be the header |
michael@0 | 267 | // V5 : don't read/write FunctionPtr on cross-process (we can detect that) |
michael@0 | 268 | // V6 : added serialization of SkPath's bounds (and packed its flags tighter) |
michael@0 | 269 | // V7 : changed drawBitmapRect(IRect) to drawBitmapRectToRect(Rect) |
michael@0 | 270 | // V8 : Add an option for encoding bitmaps |
michael@0 | 271 | // V9 : Allow the reader and writer of an SKP disagree on whether to support |
michael@0 | 272 | // SK_SUPPORT_HINTING_SCALE_FACTOR |
michael@0 | 273 | // V10: add drawRRect, drawOval, clipRRect |
michael@0 | 274 | // V11: modify how readBitmap and writeBitmap store their info. |
michael@0 | 275 | // V12: add conics to SkPath, use new SkPathRef flattening |
michael@0 | 276 | // V13: add flag to drawBitmapRectToRect |
michael@0 | 277 | // parameterize blurs by sigma rather than radius |
michael@0 | 278 | // V14: Add flags word to PathRef serialization |
michael@0 | 279 | // V15: Remove A1 bitmpa config (and renumber remaining configs) |
michael@0 | 280 | // V16: Move SkPath's isOval flag to SkPathRef |
michael@0 | 281 | // V17: SkPixelRef now writes SkImageInfo |
michael@0 | 282 | // V18: SkBitmap now records x,y for its pixelref origin, instead of offset. |
michael@0 | 283 | // V19: encode matrices and regions into the ops stream |
michael@0 | 284 | // V20: added bool to SkPictureImageFilter's serialization (to allow SkPicture serialization) |
michael@0 | 285 | // V21: add pushCull, popCull |
michael@0 | 286 | // V22: SK_PICT_FACTORY_TAG's size is now the chunk size in bytes |
michael@0 | 287 | |
michael@0 | 288 | // Note: If the picture version needs to be increased then please follow the |
michael@0 | 289 | // steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw |
michael@0 | 290 | |
michael@0 | 291 | // Only SKPs within the min/current picture version range (inclusive) can be read. |
michael@0 | 292 | static const uint32_t MIN_PICTURE_VERSION = 19; |
michael@0 | 293 | static const uint32_t CURRENT_PICTURE_VERSION = 22; |
michael@0 | 294 | |
michael@0 | 295 | // fPlayback, fRecord, fWidth & fHeight are protected to allow derived classes to |
michael@0 | 296 | // install their own SkPicturePlayback-derived players,SkPictureRecord-derived |
michael@0 | 297 | // recorders and set the picture size |
michael@0 | 298 | SkPicturePlayback* fPlayback; |
michael@0 | 299 | SkPictureRecord* fRecord; |
michael@0 | 300 | int fWidth, fHeight; |
michael@0 | 301 | const AccelData* fAccelData; |
michael@0 | 302 | |
michael@0 | 303 | // Create a new SkPicture from an existing SkPicturePlayback. Ref count of |
michael@0 | 304 | // playback is unchanged. |
michael@0 | 305 | SkPicture(SkPicturePlayback*, int width, int height); |
michael@0 | 306 | |
michael@0 | 307 | // For testing. Derived classes may instantiate an alternate |
michael@0 | 308 | // SkBBoxHierarchy implementation |
michael@0 | 309 | virtual SkBBoxHierarchy* createBBoxHierarchy() const; |
michael@0 | 310 | private: |
michael@0 | 311 | void createHeader(SkPictInfo* info) const; |
michael@0 | 312 | static bool IsValidPictInfo(const SkPictInfo& info); |
michael@0 | 313 | |
michael@0 | 314 | friend class SkFlatPicture; |
michael@0 | 315 | friend class SkPicturePlayback; |
michael@0 | 316 | |
michael@0 | 317 | typedef SkRefCnt INHERITED; |
michael@0 | 318 | }; |
michael@0 | 319 | |
michael@0 | 320 | /** |
michael@0 | 321 | * Subclasses of this can be passed to canvas.drawPicture. During the drawing |
michael@0 | 322 | * of the picture, this callback will periodically be invoked. If its |
michael@0 | 323 | * abortDrawing() returns true, then picture playback will be interrupted. |
michael@0 | 324 | * |
michael@0 | 325 | * The resulting drawing is undefined, as there is no guarantee how often the |
michael@0 | 326 | * callback will be invoked. If the abort happens inside some level of nested |
michael@0 | 327 | * calls to save(), restore will automatically be called to return the state |
michael@0 | 328 | * to the same level it was before the drawPicture call was made. |
michael@0 | 329 | */ |
michael@0 | 330 | class SK_API SkDrawPictureCallback { |
michael@0 | 331 | public: |
michael@0 | 332 | SkDrawPictureCallback() {} |
michael@0 | 333 | virtual ~SkDrawPictureCallback() {} |
michael@0 | 334 | |
michael@0 | 335 | virtual bool abortDrawing() = 0; |
michael@0 | 336 | }; |
michael@0 | 337 | |
michael@0 | 338 | #endif |