Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 1 | #Topic Picture |
| 2 | #Alias Pictures ## |
| 3 | #Alias Picture_Reference ## |
| 4 | |
| 5 | #Class SkPicture |
| 6 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 7 | #Code |
| 8 | #Populate |
| 9 | ## |
| 10 | |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 11 | Picture records drawing commands made to Canvas. The command stream may be |
| 12 | played in whole or in part at a later time. |
| 13 | |
| 14 | Picture is an abstract class. Picture may be generated by Picture_Recorder |
| 15 | or Drawable, or from Picture previously saved to Data or Stream. |
| 16 | |
| 17 | Picture may contain any Canvas drawing command, as well as one or more |
| 18 | Canvas_Matrix or Canvas_Clip. Picture has a cull Rect, which is used as |
| 19 | a bounding box hint. To limit Picture bounds, use Canvas_Clip when |
| 20 | recording or drawing Picture. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 21 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 22 | # ------------------------------------------------------------------------------ |
| 23 | |
| 24 | #Class AbortCallback |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 25 | #Line # utility to stop picture playback ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 26 | |
| 27 | #Code |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 28 | class AbortCallback { |
| 29 | public: |
| 30 | AbortCallback() {} |
| 31 | virtual ~AbortCallback() {} |
| 32 | virtual bool abort() = 0; |
| 33 | }; |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 34 | ## |
| 35 | |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 36 | AbortCallback is an abstract class. An implementation of AbortCallback may |
| 37 | passed as a parameter to SkPicture::playback, to stop it before all drawing |
| 38 | commands have been processed. |
| 39 | |
| 40 | If AbortCallback::abort returns true, SkPicture::playback is interrupted. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 41 | |
| 42 | # ------------------------------------------------------------------------------ |
| 43 | |
| 44 | #Method AbortCallback() |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 45 | #In Constructors |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 46 | #Line # defines default constructor ## |
| 47 | Has no effect. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 48 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 49 | #Return abstract class cannot be instantiated ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 50 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 51 | #NoExample |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 52 | ## |
| 53 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 54 | #SeeAlso playback |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 55 | |
| 56 | #Method ## |
| 57 | |
| 58 | # ------------------------------------------------------------------------------ |
| 59 | |
| 60 | #Method virtual ~AbortCallback() |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 61 | #In Constructors |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 62 | #Line # defines default destructor ## |
| 63 | Has no effect. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 64 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 65 | #NoExample |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 66 | ## |
| 67 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 68 | #SeeAlso playback |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 69 | |
| 70 | #Method ## |
| 71 | |
| 72 | # ------------------------------------------------------------------------------ |
| 73 | |
| 74 | #Method virtual bool abort() = 0 |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 75 | #In Utility |
| 76 | #Line # aborts playback by callback ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 77 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 78 | Stops Picture playback when some condition is met. A subclass of |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 79 | AbortCallback provides an override for abort() that can stop SkPicture::playback. |
| 80 | |
| 81 | The part of Picture drawn when aborted is undefined. Picture instantiations are |
| 82 | free to stop drawing at different points during playback. |
| 83 | |
| 84 | If the abort happens inside one or more calls to SkCanvas::save(), stack |
| 85 | of Canvas_Matrix and Canvas_Clip values is restored to its state before |
| 86 | SkPicture::playback was called. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 87 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 88 | #Return true to stop playback ## |
| 89 | |
| 90 | #NoExample |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 91 | ## |
| 92 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 93 | #SeeAlso playback |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 94 | |
| 95 | #Method ## |
| 96 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 97 | #Example |
| 98 | #Description |
| 99 | JustOneDraw allows the black rectangle to draw but stops playback before the |
| 100 | white rectangle appears. |
| 101 | ## |
| 102 | #Function |
| 103 | class JustOneDraw : public SkPicture::AbortCallback { |
| 104 | public: |
| 105 | bool abort() override { return fCalls++ > 0; } |
| 106 | private: |
| 107 | int fCalls = 0; |
| 108 | }; |
| 109 | ## |
| 110 | |
| 111 | void draw(SkCanvas* canvas) { |
| 112 | SkPictureRecorder recorder; |
| 113 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); |
| 114 | SkPaint paint; |
| 115 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); |
| 116 | paint.setColor(SK_ColorWHITE); |
| 117 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); |
| 118 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
| 119 | JustOneDraw callback; |
| 120 | picture->playback(canvas, &callback); |
| 121 | } |
| 122 | |
| 123 | ## |
| 124 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 125 | #Class AbortCallback ## |
| 126 | |
| 127 | # ------------------------------------------------------------------------------ |
| 128 | |
| 129 | #Method static sk_sp<SkPicture> MakeFromStream(SkStream* stream, |
| 130 | const SkDeserialProcs* procs = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 131 | #In Constructors |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 132 | #Line # constructs Picture from stream ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 133 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 134 | Recreates Picture that was serialized into a stream. Returns constructed Picture |
| 135 | if successful; otherwise, returns nullptr. Fails if data does not permit |
| 136 | constructing valid Picture. |
| 137 | |
| 138 | procs.fPictureProc permits supplying a custom function to decode Picture. |
| 139 | If procs.fPictureProc is nullptr, default decoding is used. procs.fPictureCtx |
| 140 | may be used to provide user context to procs.fPictureProc; procs.fPictureProc |
| 141 | is called with a pointer to data, data byte length, and user context. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 142 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 143 | #Param stream container for serial data ## |
| 144 | #Param procs custom serial data decoders; may be nullptr ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 145 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 146 | #Return Picture constructed from stream data ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 147 | |
| 148 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 149 | SkPictureRecorder recorder;
|
| 150 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 151 | SkPaint paint;
|
| 152 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 153 | paint.setColor(SK_ColorWHITE);
|
| 154 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 155 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 156 | SkDynamicMemoryWStream writableStream;
|
| 157 | picture->serialize(&writableStream);
|
| 158 | std::unique_ptr<SkStreamAsset> readableStream = writableStream.detachAsStream();
|
| 159 | sk_sp<SkPicture> copy = SkPicture::MakeFromStream(readableStream.get());
|
| 160 | copy->playback(canvas); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 161 | ## |
| 162 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 163 | #SeeAlso MakeFromData SkPictureRecorder |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 164 | |
| 165 | #Method ## |
| 166 | |
| 167 | # ------------------------------------------------------------------------------ |
| 168 | |
| 169 | #Method static sk_sp<SkPicture> MakeFromData(const SkData* data, |
| 170 | const SkDeserialProcs* procs = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 171 | #In Constructors |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 172 | #Line # constructs Picture from data ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 173 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 174 | Recreates Picture that was serialized into data. Returns constructed Picture |
| 175 | if successful; otherwise, returns nullptr. Fails if data does not permit |
| 176 | constructing valid Picture. |
| 177 | |
| 178 | procs.fPictureProc permits supplying a custom function to decode Picture. |
| 179 | If procs.fPictureProc is nullptr, default decoding is used. procs.fPictureCtx |
| 180 | may be used to provide user context to procs.fPictureProc; procs.fPictureProc |
| 181 | is called with a pointer to data, data byte length, and user context. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 182 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 183 | #Param data container for serial data ## |
| 184 | #Param procs custom serial data decoders; may be nullptr ## |
| 185 | |
| 186 | #Return Picture constructed from data ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 187 | |
| 188 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 189 | SkPictureRecorder recorder;
|
| 190 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 191 | SkPaint paint;
|
| 192 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 193 | paint.setColor(SK_ColorWHITE);
|
| 194 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 195 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 196 | SkDynamicMemoryWStream writableStream;
|
| 197 | picture->serialize(&writableStream);
|
| 198 | sk_sp<SkData> readableData = writableStream.detachAsData();
|
| 199 | sk_sp<SkPicture> copy = SkPicture::MakeFromData(readableData.get());
|
| 200 | copy->playback(canvas); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 201 | ## |
| 202 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 203 | #SeeAlso MakeFromStream SkPictureRecorder |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 204 | |
| 205 | #Method ## |
| 206 | |
| 207 | # ------------------------------------------------------------------------------ |
| 208 | |
| 209 | #Method static sk_sp<SkPicture> MakeFromData(const void* data, size_t size, |
| 210 | const SkDeserialProcs* procs = nullptr) |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 211 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 212 | #Param data pointer to serial data ## |
| 213 | #Param size size of data ## |
| 214 | #Param procs custom serial data decoders; may be nullptr ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 215 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 216 | Recreates Picture that was serialized into data. Returns constructed Picture |
| 217 | if successful; otherwise, returns nullptr. Fails if size is smaller than |
| 218 | required data length, or if data does not permit constructing valid Picture. |
| 219 | |
| 220 | procs.fPictureProc permits supplying a custom function to decode Picture. |
| 221 | If procs.fPictureProc is nullptr, default decoding is used. procs.fPictureCtx |
| 222 | may be used to provide user context to procs.fPictureProc; procs.fPictureProc |
| 223 | is called with a pointer to data, data byte length, and user context. |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 224 | |
| 225 | #Return Picture constructed from data ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 226 | |
| 227 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 228 | SkPictureRecorder recorder;
|
| 229 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 230 | SkPaint paint;
|
| 231 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 232 | paint.setColor(SK_ColorWHITE);
|
| 233 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 234 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 235 | SkDynamicMemoryWStream writableStream;
|
| 236 | picture->serialize(&writableStream);
|
| 237 | sk_sp<SkData> readableData = writableStream.detachAsData();
|
| 238 | sk_sp<SkPicture> copy = SkPicture::MakeFromData(readableData->data(), readableData->size());
|
| 239 | copy->playback(canvas); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 240 | ## |
| 241 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 242 | #SeeAlso MakeFromStream SkPictureRecorder |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 243 | |
| 244 | #Method ## |
| 245 | |
| 246 | # ------------------------------------------------------------------------------ |
| 247 | |
| 248 | #Method virtual void playback(SkCanvas* canvas, AbortCallback* callback = nullptr) const = 0 |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 249 | #In Action |
| 250 | #Line # replays drawing commands on canvas ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 251 | |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 252 | Replays the drawing commands on the specified canvas. In the case that the |
| 253 | commands are recorded, each command in the Picture is sent separately to canvas. |
| 254 | |
| 255 | To add a single command to draw Picture to recording canvas, call |
| 256 | SkCanvas::drawPicture instead. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 257 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 258 | #Param canvas receiver of drawing commands ## |
| 259 | #Param callback allows interruption of playback ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 260 | |
| 261 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 262 | SkPictureRecorder recorder;
|
| 263 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 264 | SkPaint paint;
|
| 265 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 266 | paint.setColor(SK_ColorWHITE);
|
| 267 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 268 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 269 | picture->playback(canvas); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 270 | ## |
| 271 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 272 | #SeeAlso SkCanvas::drawPicture |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 273 | |
| 274 | #Method ## |
| 275 | |
| 276 | # ------------------------------------------------------------------------------ |
| 277 | |
| 278 | #Method virtual SkRect cullRect() const = 0 |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 279 | #In Property |
| 280 | #Line # returns bounds used to record Picture ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 281 | |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 282 | Returns cull Rect for this picture, passed in when Picture was created. |
| 283 | Returned Rect does not specify clipping Rect for Picture; cull is hint |
| 284 | of Picture bounds. |
| 285 | |
| 286 | Picture is free to discard recorded drawing commands that fall outside |
| 287 | cull. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 288 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 289 | #Return bounds passed when Picture was created ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 290 | |
| 291 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 292 | #Description |
| 293 | Picture recorded bounds are smaller than contents; contents outside recorded |
| 294 | bounds may be drawn, and are drawn in this example. |
| 295 | ## |
| 296 | SkPictureRecorder recorder;
|
| 297 | SkCanvas* pictureCanvas = recorder.beginRecording({64, 64, 192, 192});
|
| 298 | SkPaint paint;
|
| 299 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 300 | paint.setColor(SK_ColorWHITE);
|
| 301 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 302 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 303 | picture->playback(canvas);
|
| 304 | paint.setBlendMode(SkBlendMode::kModulate);
|
| 305 | paint.setColor(0x40404040);
|
| 306 | canvas->drawRect(picture->cullRect(), paint); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 307 | ## |
| 308 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 309 | #SeeAlso SkCanvas::clipRect |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 310 | |
| 311 | #Method ## |
| 312 | |
| 313 | # ------------------------------------------------------------------------------ |
| 314 | |
| 315 | #Method uint32_t uniqueID() const |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 316 | #In Property |
| 317 | #Line # returns identifier for Picture ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 318 | |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 319 | Returns a non-zero value unique among Pictures in Skia process. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 320 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 321 | #Return identifier for Picture ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 322 | |
| 323 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 324 | SkPictureRecorder recorder;
|
| 325 | recorder.beginRecording({0, 0, 0, 0});
|
| 326 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 327 | SkDebugf("empty picture id = %d\n", picture->uniqueID());
|
| 328 | sk_sp<SkPicture> placeholder = SkPicture::MakePlaceholder({0, 0, 0, 0});
|
| 329 | SkDebugf("placeholder id = %d\n", placeholder->uniqueID()); |
| 330 | #StdOut |
| 331 | empty picture id = 1
|
| 332 | placeholder id = 2 |
| 333 | ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 334 | ## |
| 335 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 336 | #SeeAlso SkRefCnt |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 337 | |
| 338 | #Method ## |
| 339 | |
| 340 | # ------------------------------------------------------------------------------ |
| 341 | |
| 342 | #Method sk_sp<SkData> serialize(const SkSerialProcs* procs = nullptr) const |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 343 | #In Utility |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 344 | #Line # writes Picture to Data ## |
| 345 | Returns storage containing Data describing Picture, using optional custom |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 346 | encoders. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 347 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 348 | procs.fPictureProc permits supplying a custom function to encode Picture. |
| 349 | If procs.fPictureProc is nullptr, default encoding is used. procs.fPictureCtx |
| 350 | may be used to provide user context to procs.fPictureProc; procs.fPictureProc |
| 351 | is called with a pointer to Picture and user context. |
| 352 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 353 | #Param procs custom serial data encoders; may be nullptr ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 354 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 355 | #Return storage containing serialized Picture ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 356 | |
| 357 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 358 | SkPictureRecorder recorder;
|
| 359 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 360 | SkPaint paint;
|
| 361 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 362 | paint.setColor(SK_ColorWHITE);
|
| 363 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 364 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 365 | sk_sp<SkData> readableData = picture->serialize();
|
| 366 | sk_sp<SkPicture> copy = SkPicture::MakeFromData(readableData->data(), readableData->size());
|
| 367 | copy->playback(canvas); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 368 | ## |
| 369 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 370 | #SeeAlso MakeFromData SkData SkSerialProcs |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 371 | |
| 372 | #Method ## |
| 373 | |
| 374 | # ------------------------------------------------------------------------------ |
| 375 | |
| 376 | #Method void serialize(SkWStream* stream, const SkSerialProcs* procs = nullptr) const |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 377 | Writes picture to stream, using optional custom encoders. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 378 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 379 | procs.fPictureProc permits supplying a custom function to encode Picture. |
| 380 | If procs.fPictureProc is nullptr, default encoding is used. procs.fPictureCtx |
| 381 | may be used to provide user context to procs.fPictureProc; procs.fPictureProc |
| 382 | is called with a pointer to Picture and user context. |
| 383 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 384 | #Param stream writable serial data stream ## |
| 385 | #Param procs custom serial data encoders; may be nullptr ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 386 | |
| 387 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 388 | SkPictureRecorder recorder;
|
| 389 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 390 | SkPaint paint;
|
| 391 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 392 | paint.setColor(SK_ColorWHITE);
|
| 393 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 394 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 395 | SkDynamicMemoryWStream writableStream;
|
| 396 | picture->serialize(&writableStream);
|
| 397 | sk_sp<SkData> readableData = writableStream.detachAsData();
|
| 398 | sk_sp<SkPicture> copy = SkPicture::MakeFromData(readableData->data(), readableData->size());
|
| 399 | copy->playback(canvas); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 400 | ## |
| 401 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 402 | #SeeAlso MakeFromStream SkWStream SkSerialProcs |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 403 | |
| 404 | #Method ## |
| 405 | |
| 406 | # ------------------------------------------------------------------------------ |
| 407 | |
| 408 | #Method static sk_sp<SkPicture> MakePlaceholder(SkRect cull) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame^] | 409 | #In Constructors |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 410 | #Line # constructs placeholder with unique identifier ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 411 | |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 412 | Returns a placeholder SkPicture. Result does not draw, and contains only |
| 413 | cull Rect, a hint of its bounds. Result is immutable; it cannot be changed |
| 414 | later. Result identifier is unique. |
| 415 | |
| 416 | Returned placeholder can be intercepted during playback to insert other |
| 417 | commands into Canvas draw stream. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 418 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 419 | #Param cull placeholder dimensions |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 420 | ## |
| 421 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 422 | #Return placeholder with unique identifier ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 423 | |
| 424 | #Example |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 425 | #Function |
| 426 | class MyCanvas : public SkCanvas { |
| 427 | public: |
| 428 | MyCanvas(SkCanvas* c) : canvas(c) {} |
| 429 | void onDrawPicture(const SkPicture* picture, const SkMatrix* ,
|
| 430 | const SkPaint* ) override {
|
| 431 | const SkRect rect = picture->cullRect(); |
| 432 | SkPaint redPaint; |
| 433 | redPaint.setColor(SK_ColorRED); |
| 434 | canvas->drawRect(rect, redPaint); |
| 435 | } |
| 436 | |
| 437 | SkCanvas* canvas;
|
| 438 | }; |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 439 | ## |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 440 | SkPictureRecorder recorder;
|
| 441 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 442 | sk_sp<SkPicture> placeholder = SkPicture::MakePlaceholder({10, 40, 80, 110});
|
| 443 | pictureCanvas->drawPicture(placeholder);
|
| 444 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 445 | MyCanvas myCanvas(canvas);
|
| 446 | myCanvas.drawPicture(picture);
|
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 447 | ## |
| 448 | |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 449 | #SeeAlso MakeFromStream MakeFromData uniqueID |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 450 | |
| 451 | #Method ## |
| 452 | |
| 453 | # ------------------------------------------------------------------------------ |
| 454 | |
| 455 | #Method virtual int approximateOpCount() const = 0 |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 456 | #In Property |
| 457 | #Line # returns approximate operation count ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 458 | |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 459 | Returns the approximate number of operations in Picture. Returned value |
| 460 | may be greater or less than the number of SkCanvas calls |
| 461 | recorded: some calls may be recorded as more than one operation, other |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 462 | calls may be optimized away. |
| 463 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 464 | #Return approximate operation count ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 465 | |
| 466 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 467 | SkPictureRecorder recorder;
|
| 468 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 469 | SkPaint paint;
|
| 470 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 471 | paint.setColor(SK_ColorWHITE);
|
| 472 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 473 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 474 | picture->playback(canvas); |
| 475 | std::string opCount = "approximate op count: " + std::to_string(picture->approximateOpCount()); |
| 476 | canvas->drawString(opCount.c_str(), 50, 220, SkPaint()); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 477 | ## |
| 478 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 479 | #SeeAlso approximateBytesUsed |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 480 | |
| 481 | #Method ## |
| 482 | |
| 483 | # ------------------------------------------------------------------------------ |
| 484 | |
| 485 | #Method virtual size_t approximateBytesUsed() const = 0 |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 486 | #In Property |
| 487 | #Line # returns approximate size ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 488 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 489 | Returns the approximate byte size of Picture. Does not include large objects |
Cary Clark | f960398 | 2018-07-17 08:20:27 -0400 | [diff] [blame] | 490 | referenced by Picture. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 491 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 492 | #Return approximate size ## |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 493 | |
| 494 | #Example |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 495 | SkPictureRecorder recorder;
|
| 496 | SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
|
| 497 | SkPaint paint;
|
| 498 | pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
|
| 499 | paint.setColor(SK_ColorWHITE);
|
| 500 | pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
|
| 501 | sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
| 502 | picture->playback(canvas); |
| 503 | std::string opCount = "approximate bytes used: " + std::to_string(picture->approximateBytesUsed()); |
| 504 | canvas->drawString(opCount.c_str(), 20, 220, SkPaint()); |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 505 | ## |
| 506 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 507 | #SeeAlso approximateOpCount |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 508 | |
| 509 | #Method ## |
| 510 | |
| 511 | #Class SkPicture ## |
| 512 | |
| 513 | #Topic Picture ## |