epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2007 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkPicture_DEFINED |
| 11 | #define SkPicture_DEFINED |
| 12 | |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 13 | #include "SkBitmap.h" |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 14 | #include "SkDrawPictureCallback.h" |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 15 | #include "SkImageDecoder.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkRefCnt.h" |
| 17 | |
commit-bot@chromium.org | eb9547c | 2014-03-19 21:24:25 +0000 | [diff] [blame] | 18 | #if SK_SUPPORT_GPU |
| 19 | class GrContext; |
| 20 | #endif |
| 21 | |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 22 | class SkBBHFactory; |
junov@chromium.org | 35ac048 | 2012-11-01 17:10:32 +0000 | [diff] [blame] | 23 | class SkBBoxHierarchy; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | class SkCanvas; |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 25 | class SkData; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | class SkPicturePlayback; |
| 27 | class SkPictureRecord; |
| 28 | class SkStream; |
| 29 | class SkWStream; |
| 30 | |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 31 | struct SkPictInfo; |
| 32 | |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 33 | class SkRecord; |
| 34 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | /** \class SkPicture |
| 36 | |
| 37 | The SkPicture class records the drawing commands made to a canvas, to |
| 38 | be played back at a later time. |
| 39 | */ |
reed@google.com | 1a32d4a | 2011-04-25 20:02:38 +0000 | [diff] [blame] | 40 | class SK_API SkPicture : public SkRefCnt { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | public: |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 42 | SK_DECLARE_INST_COUNT(SkPicture) |
| 43 | |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 44 | // AccelData provides a base class for device-specific acceleration |
skia.committer@gmail.com | eb849e5 | 2014-03-17 03:02:17 +0000 | [diff] [blame] | 45 | // data. It is added to the picture via a call to a device's optimize |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 46 | // method. |
| 47 | class AccelData : public SkRefCnt { |
| 48 | public: |
| 49 | typedef uint8_t Domain; |
| 50 | typedef uint32_t Key; |
| 51 | |
| 52 | AccelData(Key key) : fKey(key) { } |
| 53 | |
| 54 | const Key& getKey() const { return fKey; } |
| 55 | |
| 56 | // This entry point allows user's to get a unique domain prefix |
| 57 | // for their keys |
| 58 | static Domain GenerateDomain(); |
| 59 | private: |
| 60 | Key fKey; |
| 61 | |
| 62 | typedef SkRefCnt INHERITED; |
| 63 | }; |
| 64 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | SkPicture(); |
| 66 | /** Make a copy of the contents of src. If src records more drawing after |
| 67 | this call, those elements will not appear in this picture. |
| 68 | */ |
| 69 | SkPicture(const SkPicture& src); |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 70 | |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 71 | /** PRIVATE / EXPERIMENTAL -- do not call */ |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 72 | void EXPERIMENTAL_addAccelData(const AccelData*) const; |
| 73 | |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 74 | /** PRIVATE / EXPERIMENTAL -- do not call */ |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 75 | const AccelData* EXPERIMENTAL_getAccelData(AccelData::Key) const; |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 76 | |
reed@google.com | 34342f6 | 2012-06-25 14:36:28 +0000 | [diff] [blame] | 77 | /** |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 78 | * Function signature defining a function that sets up an SkBitmap from encoded data. On |
| 79 | * success, the SkBitmap should have its Config, width, height, rowBytes and pixelref set. |
| 80 | * If the installed pixelref has decoded the data into pixels, then the src buffer need not be |
| 81 | * copied. If the pixelref defers the actual decode until its lockPixels() is called, then it |
| 82 | * must make a copy of the src buffer. |
| 83 | * @param src Encoded data. |
| 84 | * @param length Size of the encoded data, in bytes. |
| 85 | * @param dst SkBitmap to install the pixel ref on. |
| 86 | * @param bool Whether or not a pixel ref was successfully installed. |
| 87 | */ |
| 88 | typedef bool (*InstallPixelRefProc)(const void* src, size_t length, SkBitmap* dst); |
| 89 | |
| 90 | /** |
| 91 | * Recreate a picture that was serialized into a stream. |
| 92 | * @param SkStream Serialized picture data. |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 93 | * @param proc Function pointer for installing pixelrefs on SkBitmaps representing the |
| 94 | * encoded bitmap data from the stream. |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 95 | * @return A new SkPicture representing the serialized data, or NULL if the stream is |
| 96 | * invalid. |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 97 | */ |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 98 | static SkPicture* CreateFromStream(SkStream*, |
| 99 | InstallPixelRefProc proc = &SkImageDecoder::DecodeMemory); |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 100 | |
commit-bot@chromium.org | 5e0995e | 2014-02-07 12:20:04 +0000 | [diff] [blame] | 101 | /** |
| 102 | * Recreate a picture that was serialized into a buffer. If the creation requires bitmap |
| 103 | * decoding, the decoder must be set on the SkReadBuffer parameter by calling |
| 104 | * SkReadBuffer::setBitmapDecoder() before calling SkPicture::CreateFromBuffer(). |
| 105 | * @param SkReadBuffer Serialized picture data. |
| 106 | * @return A new SkPicture representing the serialized data, or NULL if the buffer is |
| 107 | * invalid. |
| 108 | */ |
| 109 | static SkPicture* CreateFromBuffer(SkReadBuffer&); |
| 110 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | virtual ~SkPicture(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 112 | |
mtklein | d3e474e | 2014-06-27 12:34:44 -0700 | [diff] [blame] | 113 | #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 114 | /** |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 115 | * Creates a thread-safe clone of the picture that is ready for playback. |
| 116 | */ |
| 117 | SkPicture* clone() const; |
| 118 | |
| 119 | /** |
| 120 | * Creates multiple thread-safe clones of this picture that are ready for |
| 121 | * playback. The resulting clones are stored in the provided array of |
| 122 | * SkPictures. |
| 123 | */ |
| 124 | void clone(SkPicture* pictures, int count) const; |
mtklein | d3e474e | 2014-06-27 12:34:44 -0700 | [diff] [blame] | 125 | #endif |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 126 | |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 127 | /** Replays the drawing commands on the specified canvas. |
reed@google.com | 74babdf | 2013-05-20 17:02:41 +0000 | [diff] [blame] | 128 | @param canvas the canvas receiving the drawing commands. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 129 | */ |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 130 | void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL) const; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 131 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 132 | /** Return the width of the picture's recording canvas. This |
| 133 | value reflects what was passed to setSize(), and does not necessarily |
| 134 | reflect the bounds of what has been recorded into the picture. |
| 135 | @return the width of the picture's recording canvas |
| 136 | */ |
| 137 | int width() const { return fWidth; } |
| 138 | |
| 139 | /** Return the height of the picture's recording canvas. This |
| 140 | value reflects what was passed to setSize(), and does not necessarily |
| 141 | reflect the bounds of what has been recorded into the picture. |
| 142 | @return the height of the picture's recording canvas |
| 143 | */ |
| 144 | int height() const { return fHeight; } |
| 145 | |
skia.committer@gmail.com | a915772 | 2014-04-03 03:04:26 +0000 | [diff] [blame] | 146 | /** Return a non-zero, unique value representing the picture. This call is |
| 147 | only valid when not recording. Between a beginRecording/endRecording |
commit-bot@chromium.org | 2b4e370 | 2014-04-07 18:26:22 +0000 | [diff] [blame] | 148 | pair it will just return 0 (the invalid ID). Each beginRecording/ |
robertphillips@google.com | d550088 | 2014-04-02 23:51:13 +0000 | [diff] [blame] | 149 | endRecording pair will cause a different generation ID to be returned. |
| 150 | */ |
commit-bot@chromium.org | 2b4e370 | 2014-04-07 18:26:22 +0000 | [diff] [blame] | 151 | uint32_t uniqueID() const; |
robertphillips@google.com | d550088 | 2014-04-02 23:51:13 +0000 | [diff] [blame] | 152 | |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 153 | /** |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 154 | * Function to encode an SkBitmap to an SkData. A function with this |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 155 | * signature can be passed to serialize() and SkWriteBuffer. |
| 156 | * Returning NULL will tell the SkWriteBuffer to use |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 157 | * SkBitmap::flatten() to store the bitmap. |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 158 | * |
| 159 | * @param pixelRefOffset DEPRECATED -- caller assumes it will return 0. |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 160 | * @return SkData If non-NULL, holds encoded data representing the passed |
| 161 | * in bitmap. The caller is responsible for calling unref(). |
scroggo@google.com | 32ef131 | 2013-02-22 22:04:19 +0000 | [diff] [blame] | 162 | */ |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 163 | typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm); |
scroggo@google.com | 32ef131 | 2013-02-22 22:04:19 +0000 | [diff] [blame] | 164 | |
| 165 | /** |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 166 | * Serialize to a stream. If non NULL, encoder will be used to encode |
| 167 | * any bitmaps in the picture. |
scroggo@google.com | 1b1bcc3 | 2013-05-21 20:31:23 +0000 | [diff] [blame] | 168 | * encoder will never be called with a NULL pixelRefOffset. |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 169 | */ |
scroggo@google.com | 32ef131 | 2013-02-22 22:04:19 +0000 | [diff] [blame] | 170 | void serialize(SkWStream*, EncodeBitmap encoder = NULL) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 171 | |
tomhudson@google.com | 381010e | 2013-10-24 11:12:47 +0000 | [diff] [blame] | 172 | /** |
commit-bot@chromium.org | 5e0995e | 2014-02-07 12:20:04 +0000 | [diff] [blame] | 173 | * Serialize to a buffer. |
| 174 | */ |
| 175 | void flatten(SkWriteBuffer&) const; |
| 176 | |
| 177 | /** |
tomhudson@google.com | 381010e | 2013-10-24 11:12:47 +0000 | [diff] [blame] | 178 | * Returns true if any bitmaps may be produced when this SkPicture |
| 179 | * is replayed. |
| 180 | * Returns false if called while still recording. |
| 181 | */ |
| 182 | bool willPlayBackBitmaps() const; |
| 183 | |
djsollen@google.com | d9b0f48 | 2013-02-01 16:18:09 +0000 | [diff] [blame] | 184 | #ifdef SK_BUILD_FOR_ANDROID |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 185 | /** Signals that the caller is prematurely done replaying the drawing |
| 186 | commands. This can be called from a canvas virtual while the picture |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 187 | is drawing. Has no effect if the picture is not drawing. |
djsollen@google.com | d9b0f48 | 2013-02-01 16:18:09 +0000 | [diff] [blame] | 188 | @deprecated preserving for legacy purposes |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 189 | */ |
| 190 | void abortPlayback(); |
djsollen@google.com | d9b0f48 | 2013-02-01 16:18:09 +0000 | [diff] [blame] | 191 | #endif |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 192 | |
commit-bot@chromium.org | 6f4fb0f | 2014-03-03 19:18:39 +0000 | [diff] [blame] | 193 | /** Return true if the SkStream/Buffer represents a serialized picture, and |
| 194 | fills out SkPictInfo. After this function returns, the data source is not |
skia.committer@gmail.com | ade9a34 | 2014-03-04 03:02:32 +0000 | [diff] [blame] | 195 | rewound so it will have to be manually reset before passing to |
commit-bot@chromium.org | 6f4fb0f | 2014-03-03 19:18:39 +0000 | [diff] [blame] | 196 | CreateFromStream or CreateFromBuffer. Note, CreateFromStream and |
| 197 | CreateFromBuffer perform this check internally so these entry points are |
| 198 | intended for stand alone tools. |
| 199 | If false is returned, SkPictInfo is unmodified. |
| 200 | */ |
| 201 | static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*); |
| 202 | static bool InternalOnly_BufferIsSKP(SkReadBuffer&, SkPictInfo*); |
| 203 | |
commit-bot@chromium.org | eb9547c | 2014-03-19 21:24:25 +0000 | [diff] [blame] | 204 | /** Return true if the picture is suitable for rendering on the GPU. |
| 205 | */ |
| 206 | |
| 207 | #if SK_SUPPORT_GPU |
commit-bot@chromium.org | a1ff26a | 2014-05-30 21:52:52 +0000 | [diff] [blame] | 208 | bool suitableForGpuRasterization(GrContext*, const char ** = NULL) const; |
commit-bot@chromium.org | eb9547c | 2014-03-19 21:24:25 +0000 | [diff] [blame] | 209 | #endif |
| 210 | |
scroggo@google.com | 2983ddd | 2013-05-07 14:45:40 +0000 | [diff] [blame] | 211 | protected: |
robertphillips@google.com | 9a5b570 | 2012-11-13 20:41:18 +0000 | [diff] [blame] | 212 | // V2 : adds SkPixelRef's generation ID. |
| 213 | // V3 : PictInfo tag at beginning, and EOF tag at the end |
| 214 | // V4 : move SkPictInfo to be the header |
| 215 | // V5 : don't read/write FunctionPtr on cross-process (we can detect that) |
| 216 | // V6 : added serialization of SkPath's bounds (and packed its flags tighter) |
| 217 | // V7 : changed drawBitmapRect(IRect) to drawBitmapRectToRect(Rect) |
| 218 | // V8 : Add an option for encoding bitmaps |
| 219 | // V9 : Allow the reader and writer of an SKP disagree on whether to support |
| 220 | // SK_SUPPORT_HINTING_SCALE_FACTOR |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 221 | // V10: add drawRRect, drawOval, clipRRect |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 222 | // V11: modify how readBitmap and writeBitmap store their info. |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 223 | // V12: add conics to SkPath, use new SkPathRef flattening |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 224 | // V13: add flag to drawBitmapRectToRect |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 225 | // parameterize blurs by sigma rather than radius |
robertphillips@google.com | ca0c838 | 2013-09-26 12:18:23 +0000 | [diff] [blame] | 226 | // V14: Add flags word to PathRef serialization |
robertphillips@google.com | d550088 | 2014-04-02 23:51:13 +0000 | [diff] [blame] | 227 | // V15: Remove A1 bitmap config (and renumber remaining configs) |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame] | 228 | // V16: Move SkPath's isOval flag to SkPathRef |
reed@google.com | e132f50 | 2013-12-13 19:58:46 +0000 | [diff] [blame] | 229 | // V17: SkPixelRef now writes SkImageInfo |
reed@google.com | 672588b | 2014-01-08 15:42:01 +0000 | [diff] [blame] | 230 | // V18: SkBitmap now records x,y for its pixelref origin, instead of offset. |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 231 | // V19: encode matrices and regions into the ops stream |
commit-bot@chromium.org | 5e0995e | 2014-02-07 12:20:04 +0000 | [diff] [blame] | 232 | // V20: added bool to SkPictureImageFilter's serialization (to allow SkPicture serialization) |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 233 | // V21: add pushCull, popCull |
commit-bot@chromium.org | dcb8e54 | 2014-03-05 18:25:20 +0000 | [diff] [blame] | 234 | // V22: SK_PICT_FACTORY_TAG's size is now the chunk size in bytes |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 235 | // V23: SkPaint::FilterLevel became a real enum |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 236 | // V24: SkTwoPointConicalGradient now has fFlipped flag for gradient flipping |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 237 | // V25: SkDashPathEffect now only writes phase and interval array when flattening |
commit-bot@chromium.org | 76a3b2a | 2014-04-24 16:54:46 +0000 | [diff] [blame] | 238 | // V26: Removed boolean from SkColorShader for inheriting color from SkPaint. |
commit-bot@chromium.org | 83f23d8 | 2014-05-22 12:27:41 +0000 | [diff] [blame] | 239 | // V27: Remove SkUnitMapper from gradients (and skia). |
commit-bot@chromium.org | 968edca | 2014-05-23 13:21:55 +0000 | [diff] [blame] | 240 | // V28: No longer call bitmap::flatten inside SkWriteBuffer::writeBitmap. |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame^] | 241 | // V29: Removed SaveFlags parameter from save(). |
commit-bot@chromium.org | d281c92 | 2014-02-18 22:08:16 +0000 | [diff] [blame] | 242 | |
| 243 | // Note: If the picture version needs to be increased then please follow the |
| 244 | // steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw |
commit-bot@chromium.org | e8d9614 | 2014-02-25 02:16:10 +0000 | [diff] [blame] | 245 | |
| 246 | // Only SKPs within the min/current picture version range (inclusive) can be read. |
| 247 | static const uint32_t MIN_PICTURE_VERSION = 19; |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame^] | 248 | static const uint32_t CURRENT_PICTURE_VERSION = 29; |
robertphillips@google.com | 9a5b570 | 2012-11-13 20:41:18 +0000 | [diff] [blame] | 249 | |
commit-bot@chromium.org | 2b4e370 | 2014-04-07 18:26:22 +0000 | [diff] [blame] | 250 | mutable uint32_t fUniqueID; |
robertphillips@google.com | d550088 | 2014-04-02 23:51:13 +0000 | [diff] [blame] | 251 | |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 252 | // fPlayback, fWidth & fHeight are protected to allow derived classes to |
skia.committer@gmail.com | fbb0ed9 | 2012-11-13 21:46:06 +0000 | [diff] [blame] | 253 | // install their own SkPicturePlayback-derived players,SkPictureRecord-derived |
robertphillips@google.com | 9a5b570 | 2012-11-13 20:41:18 +0000 | [diff] [blame] | 254 | // recorders and set the picture size |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 255 | SkAutoTDelete<SkPicturePlayback> fPlayback; |
commit-bot@chromium.org | 145d1c0 | 2014-03-16 19:46:36 +0000 | [diff] [blame] | 256 | int fWidth, fHeight; |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 257 | mutable SkAutoTUnref<const AccelData> fAccelData; |
robertphillips@google.com | 63f1127 | 2012-10-24 19:30:41 +0000 | [diff] [blame] | 258 | |
commit-bot@chromium.org | 2b4e370 | 2014-04-07 18:26:22 +0000 | [diff] [blame] | 259 | void needsNewGenID() { fUniqueID = SK_InvalidGenID; } |
robertphillips@google.com | d550088 | 2014-04-02 23:51:13 +0000 | [diff] [blame] | 260 | |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 261 | // Create a new SkPicture from an existing SkPicturePlayback. Ref count of |
| 262 | // playback is unchanged. |
| 263 | SkPicture(SkPicturePlayback*, int width, int height); |
| 264 | |
robertphillips | e26e65e | 2014-06-12 05:51:22 -0700 | [diff] [blame] | 265 | SkPicture(int width, int height, const SkPictureRecord& record, bool deepCopyOps); |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 266 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 267 | private: |
commit-bot@chromium.org | 8f831f2 | 2014-04-23 22:35:42 +0000 | [diff] [blame] | 268 | static void WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size); |
| 269 | static void WriteTagSize(SkWStream* stream, uint32_t tag, size_t size); |
| 270 | |
commit-bot@chromium.org | 70512af | 2014-03-18 17:45:32 +0000 | [diff] [blame] | 271 | // An OperationList encapsulates a set of operation offsets into the picture byte |
| 272 | // stream along with the CTMs needed for those operation. |
commit-bot@chromium.org | e3beb6b | 2014-04-07 19:34:38 +0000 | [diff] [blame] | 273 | class OperationList : ::SkNoncopyable { |
commit-bot@chromium.org | 70512af | 2014-03-18 17:45:32 +0000 | [diff] [blame] | 274 | public: |
| 275 | virtual ~OperationList() {} |
| 276 | |
| 277 | // If valid returns false then there is no optimization data |
| 278 | // present. All the draw operations need to be issued. |
| 279 | virtual bool valid() const { return false; } |
| 280 | |
| 281 | // The following three entry points should only be accessed if |
| 282 | // 'valid' returns true. |
| 283 | virtual int numOps() const { SkASSERT(false); return 0; }; |
| 284 | // The offset in the picture of the operation to execute. |
| 285 | virtual uint32_t offset(int index) const { SkASSERT(false); return 0; }; |
| 286 | // The CTM that must be installed for the operation to behave correctly |
| 287 | virtual const SkMatrix& matrix(int index) const { SkASSERT(false); return SkMatrix::I(); } |
| 288 | |
| 289 | static const OperationList& InvalidList(); |
commit-bot@chromium.org | 70512af | 2014-03-18 17:45:32 +0000 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | /** PRIVATE / EXPERIMENTAL -- do not call |
| 293 | Return the operations required to render the content inside 'queryRect'. |
| 294 | */ |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 295 | const OperationList& EXPERIMENTAL_getActiveOps(const SkIRect& queryRect) const; |
commit-bot@chromium.org | 70512af | 2014-03-18 17:45:32 +0000 | [diff] [blame] | 296 | |
commit-bot@chromium.org | 75cf29b | 2014-03-24 19:40:49 +0000 | [diff] [blame] | 297 | /** PRIVATE / EXPERIMENTAL -- do not call |
| 298 | Return the ID of the operation currently being executed when playing |
| 299 | back. 0 indicates no call is active. |
| 300 | */ |
| 301 | size_t EXPERIMENTAL_curOpID() const; |
| 302 | |
commit-bot@chromium.org | 9e5f85e | 2014-03-12 14:46:41 +0000 | [diff] [blame] | 303 | void createHeader(SkPictInfo* info) const; |
| 304 | static bool IsValidPictInfo(const SkPictInfo& info); |
commit-bot@chromium.org | 5e0995e | 2014-02-07 12:20:04 +0000 | [diff] [blame] | 305 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 306 | friend class SkFlatPicture; |
| 307 | friend class SkPicturePlayback; |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 308 | friend class SkPictureRecorder; // just for SkPicture-based constructor |
commit-bot@chromium.org | 70512af | 2014-03-18 17:45:32 +0000 | [diff] [blame] | 309 | friend class SkGpuDevice; |
robertphillips@google.com | beb1af2 | 2014-05-07 21:31:09 +0000 | [diff] [blame] | 310 | friend class GrGatherCanvas; |
commit-bot@chromium.org | 75cf29b | 2014-03-24 19:40:49 +0000 | [diff] [blame] | 311 | friend class GrGatherDevice; |
| 312 | friend class SkDebugCanvas; |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 313 | |
| 314 | typedef SkRefCnt INHERITED; |
Mike Klein | 744fb73 | 2014-06-23 15:13:26 -0400 | [diff] [blame] | 315 | |
| 316 | SkPicture(int width, int height, SkRecord*); // Takes ownership. |
| 317 | SkAutoTDelete<SkRecord> fRecord; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 318 | }; |
| 319 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 320 | #endif |