blob: 344550433d4ec774defbe5e4755f21bb0698e5bc [file] [log] [blame]
Cary Clark224c7002018-06-27 11:00:21 -04001#Topic Picture
2#Alias Pictures ##
3#Alias Picture_Reference ##
4
5#Class SkPicture
6
Cary Clarkf9603982018-07-17 08:20:27 -04007Picture records drawing commands made to Canvas. The command stream may be
8played in whole or in part at a later time.
9
10Picture is an abstract class. Picture may be generated by Picture_Recorder
11or Drawable, or from Picture previously saved to Data or Stream.
12
13Picture may contain any Canvas drawing command, as well as one or more
14Canvas_Matrix or Canvas_Clip. Picture has a cull Rect, which is used as
15a bounding box hint. To limit Picture bounds, use Canvas_Clip when
16recording or drawing Picture.
Cary Clark224c7002018-06-27 11:00:21 -040017
18#Subtopic Overview
19#Populate
20##
21
22#Subtopic Class
23#Populate
24##
25
26#Subtopic Member_Function
27#Populate
28##
29
30# ------------------------------------------------------------------------------
31
32#Class AbortCallback
Cary Clark80247e52018-07-11 16:18:41 -040033#Line # utility to stop picture playback ##
Cary Clark224c7002018-06-27 11:00:21 -040034
35#Code
Cary Clark80247e52018-07-11 16:18:41 -040036 class AbortCallback {
37 public:
38 AbortCallback() {}
39 virtual ~AbortCallback() {}
40 virtual bool abort() = 0;
41 };
Cary Clark224c7002018-06-27 11:00:21 -040042##
43
Cary Clarkf9603982018-07-17 08:20:27 -040044AbortCallback is an abstract class. An implementation of AbortCallback may
45passed as a parameter to SkPicture::playback, to stop it before all drawing
46commands have been processed.
47
48If AbortCallback::abort returns true, SkPicture::playback is interrupted.
Cary Clark224c7002018-06-27 11:00:21 -040049
50# ------------------------------------------------------------------------------
51
52#Method AbortCallback()
Cary Clark80247e52018-07-11 16:18:41 -040053#In Constructor
54#Line # defines default constructor ##
55Has no effect.
Cary Clark224c7002018-06-27 11:00:21 -040056
Cary Clark80247e52018-07-11 16:18:41 -040057#Return abstract class cannot be instantiated ##
Cary Clark224c7002018-06-27 11:00:21 -040058
Cary Clark80247e52018-07-11 16:18:41 -040059#NoExample
Cary Clark224c7002018-06-27 11:00:21 -040060##
61
Cary Clark80247e52018-07-11 16:18:41 -040062#SeeAlso playback
Cary Clark224c7002018-06-27 11:00:21 -040063
64#Method ##
65
66# ------------------------------------------------------------------------------
67
68#Method virtual ~AbortCallback()
69#In Constructor
Cary Clark80247e52018-07-11 16:18:41 -040070#Line # defines default destructor ##
71Has no effect.
Cary Clark224c7002018-06-27 11:00:21 -040072
Cary Clark80247e52018-07-11 16:18:41 -040073#NoExample
Cary Clark224c7002018-06-27 11:00:21 -040074##
75
Cary Clark80247e52018-07-11 16:18:41 -040076#SeeAlso playback
Cary Clark224c7002018-06-27 11:00:21 -040077
78#Method ##
79
80# ------------------------------------------------------------------------------
81
82#Method virtual bool abort() = 0
Cary Clark80247e52018-07-11 16:18:41 -040083#In Utility
84#Line # aborts playback by callback ##
Cary Clark224c7002018-06-27 11:00:21 -040085
Cary Clark80247e52018-07-11 16:18:41 -040086Stops Picture playback when some condition is met. A subclass of
Cary Clarkf9603982018-07-17 08:20:27 -040087AbortCallback provides an override for abort() that can stop SkPicture::playback.
88
89The part of Picture drawn when aborted is undefined. Picture instantiations are
90free to stop drawing at different points during playback.
91
92If the abort happens inside one or more calls to SkCanvas::save(), stack
93of Canvas_Matrix and Canvas_Clip values is restored to its state before
94SkPicture::playback was called.
Cary Clark224c7002018-06-27 11:00:21 -040095
Cary Clark80247e52018-07-11 16:18:41 -040096#Return true to stop playback ##
97
98#NoExample
Cary Clark224c7002018-06-27 11:00:21 -040099##
100
Cary Clark80247e52018-07-11 16:18:41 -0400101#SeeAlso playback
Cary Clark224c7002018-06-27 11:00:21 -0400102
103#Method ##
104
Cary Clark80247e52018-07-11 16:18:41 -0400105#Example
106#Description
107JustOneDraw allows the black rectangle to draw but stops playback before the
108white rectangle appears.
109##
110#Function
111class JustOneDraw : public SkPicture::AbortCallback {
112public:
113 bool abort() override { return fCalls++ > 0; }
114private:
115 int fCalls = 0;
116};
117##
118
119void draw(SkCanvas* canvas) {
120 SkPictureRecorder recorder;
121 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
122 SkPaint paint;
123 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
124 paint.setColor(SK_ColorWHITE);
125 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
126 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
127 JustOneDraw callback;
128 picture->playback(canvas, &callback);
129}
130
131##
132
Cary Clark224c7002018-06-27 11:00:21 -0400133#Class AbortCallback ##
134
135# ------------------------------------------------------------------------------
136
137#Method static sk_sp<SkPicture> MakeFromStream(SkStream* stream,
138 const SkDeserialProcs* procs = nullptr)
Cary Clark80247e52018-07-11 16:18:41 -0400139#In Constructor
140#Line # constructs Picture from stream ##
Cary Clark224c7002018-06-27 11:00:21 -0400141
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400142Recreates Picture that was serialized into a stream. Returns constructed Picture
143if successful; otherwise, returns nullptr. Fails if data does not permit
144constructing valid Picture.
145
146procs.fPictureProc permits supplying a custom function to decode Picture.
147If procs.fPictureProc is nullptr, default decoding is used. procs.fPictureCtx
148may be used to provide user context to procs.fPictureProc; procs.fPictureProc
149is called with a pointer to data, data byte length, and user context.
Cary Clark224c7002018-06-27 11:00:21 -0400150
Cary Clark80247e52018-07-11 16:18:41 -0400151#Param stream container for serial data ##
152#Param procs custom serial data decoders; may be nullptr ##
Cary Clark224c7002018-06-27 11:00:21 -0400153
Cary Clark80247e52018-07-11 16:18:41 -0400154#Return Picture constructed from stream data ##
Cary Clark224c7002018-06-27 11:00:21 -0400155
156#Example
Cary Clark80247e52018-07-11 16:18:41 -0400157 SkPictureRecorder recorder;
158 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
159 SkPaint paint;
160 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
161 paint.setColor(SK_ColorWHITE);
162 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
163 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
164 SkDynamicMemoryWStream writableStream;
165 picture->serialize(&writableStream);
166 std::unique_ptr<SkStreamAsset> readableStream = writableStream.detachAsStream();
167 sk_sp<SkPicture> copy = SkPicture::MakeFromStream(readableStream.get());
168 copy->playback(canvas);
Cary Clark224c7002018-06-27 11:00:21 -0400169##
170
Cary Clark80247e52018-07-11 16:18:41 -0400171#SeeAlso MakeFromData SkPictureRecorder
Cary Clark224c7002018-06-27 11:00:21 -0400172
173#Method ##
174
175# ------------------------------------------------------------------------------
176
177#Method static sk_sp<SkPicture> MakeFromData(const SkData* data,
178 const SkDeserialProcs* procs = nullptr)
Cary Clark80247e52018-07-11 16:18:41 -0400179#In Constructor
180#Line # constructs Picture from data ##
Cary Clark224c7002018-06-27 11:00:21 -0400181
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400182Recreates Picture that was serialized into data. Returns constructed Picture
183if successful; otherwise, returns nullptr. Fails if data does not permit
184constructing valid Picture.
185
186procs.fPictureProc permits supplying a custom function to decode Picture.
187If procs.fPictureProc is nullptr, default decoding is used. procs.fPictureCtx
188may be used to provide user context to procs.fPictureProc; procs.fPictureProc
189is called with a pointer to data, data byte length, and user context.
Cary Clark224c7002018-06-27 11:00:21 -0400190
Cary Clark80247e52018-07-11 16:18:41 -0400191#Param data container for serial data ##
192#Param procs custom serial data decoders; may be nullptr ##
193
194#Return Picture constructed from data ##
Cary Clark224c7002018-06-27 11:00:21 -0400195
196#Example
Cary Clark80247e52018-07-11 16:18:41 -0400197 SkPictureRecorder recorder;
198 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
199 SkPaint paint;
200 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
201 paint.setColor(SK_ColorWHITE);
202 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
203 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
204 SkDynamicMemoryWStream writableStream;
205 picture->serialize(&writableStream);
206 sk_sp<SkData> readableData = writableStream.detachAsData();
207 sk_sp<SkPicture> copy = SkPicture::MakeFromData(readableData.get());
208 copy->playback(canvas);
Cary Clark224c7002018-06-27 11:00:21 -0400209##
210
Cary Clark80247e52018-07-11 16:18:41 -0400211#SeeAlso MakeFromStream SkPictureRecorder
Cary Clark224c7002018-06-27 11:00:21 -0400212
213#Method ##
214
215# ------------------------------------------------------------------------------
216
217#Method static sk_sp<SkPicture> MakeFromData(const void* data, size_t size,
218 const SkDeserialProcs* procs = nullptr)
Cary Clark224c7002018-06-27 11:00:21 -0400219
Cary Clark80247e52018-07-11 16:18:41 -0400220#Param data pointer to serial data ##
221#Param size size of data ##
222#Param procs custom serial data decoders; may be nullptr ##
Cary Clark224c7002018-06-27 11:00:21 -0400223
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400224Recreates Picture that was serialized into data. Returns constructed Picture
225if successful; otherwise, returns nullptr. Fails if size is smaller than
226required data length, or if data does not permit constructing valid Picture.
227
228procs.fPictureProc permits supplying a custom function to decode Picture.
229If procs.fPictureProc is nullptr, default decoding is used. procs.fPictureCtx
230may be used to provide user context to procs.fPictureProc; procs.fPictureProc
231is called with a pointer to data, data byte length, and user context.
Cary Clark80247e52018-07-11 16:18:41 -0400232
233#Return Picture constructed from data ##
Cary Clark224c7002018-06-27 11:00:21 -0400234
235#Example
Cary Clark80247e52018-07-11 16:18:41 -0400236 SkPictureRecorder recorder;
237 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
238 SkPaint paint;
239 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
240 paint.setColor(SK_ColorWHITE);
241 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
242 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
243 SkDynamicMemoryWStream writableStream;
244 picture->serialize(&writableStream);
245 sk_sp<SkData> readableData = writableStream.detachAsData();
246 sk_sp<SkPicture> copy = SkPicture::MakeFromData(readableData->data(), readableData->size());
247 copy->playback(canvas);
Cary Clark224c7002018-06-27 11:00:21 -0400248##
249
Cary Clark80247e52018-07-11 16:18:41 -0400250#SeeAlso MakeFromStream SkPictureRecorder
Cary Clark224c7002018-06-27 11:00:21 -0400251
252#Method ##
253
254# ------------------------------------------------------------------------------
255
256#Method virtual void playback(SkCanvas* canvas, AbortCallback* callback = nullptr) const = 0
Cary Clark80247e52018-07-11 16:18:41 -0400257#In Action
258#Line # replays drawing commands on canvas ##
Cary Clark224c7002018-06-27 11:00:21 -0400259
Cary Clarkf9603982018-07-17 08:20:27 -0400260Replays the drawing commands on the specified canvas. In the case that the
261commands are recorded, each command in the Picture is sent separately to canvas.
262
263To add a single command to draw Picture to recording canvas, call
264SkCanvas::drawPicture instead.
Cary Clark224c7002018-06-27 11:00:21 -0400265
Cary Clark80247e52018-07-11 16:18:41 -0400266#Param canvas receiver of drawing commands ##
267#Param callback allows interruption of playback ##
Cary Clark224c7002018-06-27 11:00:21 -0400268
269#Example
Cary Clark80247e52018-07-11 16:18:41 -0400270 SkPictureRecorder recorder;
271 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
272 SkPaint paint;
273 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
274 paint.setColor(SK_ColorWHITE);
275 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
276 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
277 picture->playback(canvas);
Cary Clark224c7002018-06-27 11:00:21 -0400278##
279
Cary Clark80247e52018-07-11 16:18:41 -0400280#SeeAlso SkCanvas::drawPicture
Cary Clark224c7002018-06-27 11:00:21 -0400281
282#Method ##
283
284# ------------------------------------------------------------------------------
285
286#Method virtual SkRect cullRect() const = 0
Cary Clark80247e52018-07-11 16:18:41 -0400287#In Property
288#Line # returns bounds used to record Picture ##
Cary Clark224c7002018-06-27 11:00:21 -0400289
Cary Clarkf9603982018-07-17 08:20:27 -0400290Returns cull Rect for this picture, passed in when Picture was created.
291Returned Rect does not specify clipping Rect for Picture; cull is hint
292of Picture bounds.
293
294Picture is free to discard recorded drawing commands that fall outside
295cull.
Cary Clark224c7002018-06-27 11:00:21 -0400296
Cary Clark80247e52018-07-11 16:18:41 -0400297#Return bounds passed when Picture was created ##
Cary Clark224c7002018-06-27 11:00:21 -0400298
299#Example
Cary Clark80247e52018-07-11 16:18:41 -0400300#Description
301Picture recorded bounds are smaller than contents; contents outside recorded
302bounds may be drawn, and are drawn in this example.
303##
304 SkPictureRecorder recorder;
305 SkCanvas* pictureCanvas = recorder.beginRecording({64, 64, 192, 192});
306 SkPaint paint;
307 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
308 paint.setColor(SK_ColorWHITE);
309 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
310 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
311 picture->playback(canvas);
312 paint.setBlendMode(SkBlendMode::kModulate);
313 paint.setColor(0x40404040);
314 canvas->drawRect(picture->cullRect(), paint);
Cary Clark224c7002018-06-27 11:00:21 -0400315##
316
Cary Clark80247e52018-07-11 16:18:41 -0400317#SeeAlso SkCanvas::clipRect
Cary Clark224c7002018-06-27 11:00:21 -0400318
319#Method ##
320
321# ------------------------------------------------------------------------------
322
323#Method uint32_t uniqueID() const
Cary Clark80247e52018-07-11 16:18:41 -0400324#In Property
325#Line # returns identifier for Picture ##
Cary Clark224c7002018-06-27 11:00:21 -0400326
Cary Clarkf9603982018-07-17 08:20:27 -0400327Returns a non-zero value unique among Pictures in Skia process.
Cary Clark224c7002018-06-27 11:00:21 -0400328
Cary Clark80247e52018-07-11 16:18:41 -0400329#Return identifier for Picture ##
Cary Clark224c7002018-06-27 11:00:21 -0400330
331#Example
Cary Clark80247e52018-07-11 16:18:41 -0400332 SkPictureRecorder recorder;
333 recorder.beginRecording({0, 0, 0, 0});
334 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
335 SkDebugf("empty picture id = %d\n", picture->uniqueID());
336 sk_sp<SkPicture> placeholder = SkPicture::MakePlaceholder({0, 0, 0, 0});
337 SkDebugf("placeholder id = %d\n", placeholder->uniqueID());
338#StdOut
339empty picture id = 1
340placeholder id = 2
341##
Cary Clark224c7002018-06-27 11:00:21 -0400342##
343
Cary Clark80247e52018-07-11 16:18:41 -0400344#SeeAlso SkRefCnt
Cary Clark224c7002018-06-27 11:00:21 -0400345
346#Method ##
347
348# ------------------------------------------------------------------------------
349
350#Method sk_sp<SkData> serialize(const SkSerialProcs* procs = nullptr) const
Cary Clark80247e52018-07-11 16:18:41 -0400351#In Utility
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400352#Line # writes Picture to Data ##
353Returns storage containing Data describing Picture, using optional custom
Cary Clarkf9603982018-07-17 08:20:27 -0400354encoders.
Cary Clark224c7002018-06-27 11:00:21 -0400355
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400356procs.fPictureProc permits supplying a custom function to encode Picture.
357If procs.fPictureProc is nullptr, default encoding is used. procs.fPictureCtx
358may be used to provide user context to procs.fPictureProc; procs.fPictureProc
359is called with a pointer to Picture and user context.
360
Cary Clark80247e52018-07-11 16:18:41 -0400361#Param procs custom serial data encoders; may be nullptr ##
Cary Clark224c7002018-06-27 11:00:21 -0400362
Cary Clark80247e52018-07-11 16:18:41 -0400363#Return storage containing serialized Picture ##
Cary Clark224c7002018-06-27 11:00:21 -0400364
365#Example
Cary Clark80247e52018-07-11 16:18:41 -0400366 SkPictureRecorder recorder;
367 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
368 SkPaint paint;
369 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
370 paint.setColor(SK_ColorWHITE);
371 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
372 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
373 sk_sp<SkData> readableData = picture->serialize();
374 sk_sp<SkPicture> copy = SkPicture::MakeFromData(readableData->data(), readableData->size());
375 copy->playback(canvas);
Cary Clark224c7002018-06-27 11:00:21 -0400376##
377
Cary Clark80247e52018-07-11 16:18:41 -0400378#SeeAlso MakeFromData SkData SkSerialProcs
Cary Clark224c7002018-06-27 11:00:21 -0400379
380#Method ##
381
382# ------------------------------------------------------------------------------
383
384#Method void serialize(SkWStream* stream, const SkSerialProcs* procs = nullptr) const
Cary Clark80247e52018-07-11 16:18:41 -0400385Writes picture to stream, using optional custom encoders.
Cary Clark224c7002018-06-27 11:00:21 -0400386
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400387procs.fPictureProc permits supplying a custom function to encode Picture.
388If procs.fPictureProc is nullptr, default encoding is used. procs.fPictureCtx
389may be used to provide user context to procs.fPictureProc; procs.fPictureProc
390is called with a pointer to Picture and user context.
391
Cary Clark80247e52018-07-11 16:18:41 -0400392#Param stream writable serial data stream ##
393#Param procs custom serial data encoders; may be nullptr ##
Cary Clark224c7002018-06-27 11:00:21 -0400394
395#Example
Cary Clark80247e52018-07-11 16:18:41 -0400396 SkPictureRecorder recorder;
397 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
398 SkPaint paint;
399 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
400 paint.setColor(SK_ColorWHITE);
401 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
402 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
403 SkDynamicMemoryWStream writableStream;
404 picture->serialize(&writableStream);
405 sk_sp<SkData> readableData = writableStream.detachAsData();
406 sk_sp<SkPicture> copy = SkPicture::MakeFromData(readableData->data(), readableData->size());
407 copy->playback(canvas);
Cary Clark224c7002018-06-27 11:00:21 -0400408##
409
Cary Clark80247e52018-07-11 16:18:41 -0400410#SeeAlso MakeFromStream SkWStream SkSerialProcs
Cary Clark224c7002018-06-27 11:00:21 -0400411
412#Method ##
413
414# ------------------------------------------------------------------------------
415
416#Method static sk_sp<SkPicture> MakePlaceholder(SkRect cull)
Cary Clark80247e52018-07-11 16:18:41 -0400417#In Constructor
418#Line # constructs placeholder with unique identifier ##
Cary Clark224c7002018-06-27 11:00:21 -0400419
Cary Clarkf9603982018-07-17 08:20:27 -0400420Returns a placeholder SkPicture. Result does not draw, and contains only
421cull Rect, a hint of its bounds. Result is immutable; it cannot be changed
422later. Result identifier is unique.
423
424Returned placeholder can be intercepted during playback to insert other
425commands into Canvas draw stream.
Cary Clark224c7002018-06-27 11:00:21 -0400426
Cary Clark80247e52018-07-11 16:18:41 -0400427#Param cull placeholder dimensions
Cary Clark224c7002018-06-27 11:00:21 -0400428##
429
Cary Clark80247e52018-07-11 16:18:41 -0400430#Return placeholder with unique identifier ##
Cary Clark224c7002018-06-27 11:00:21 -0400431
432#Example
Cary Clarkf9603982018-07-17 08:20:27 -0400433#Function
434class MyCanvas : public SkCanvas {
435public:
436 MyCanvas(SkCanvas* c) : canvas(c) {}
437 void onDrawPicture(const SkPicture* picture, const SkMatrix* ,
438 const SkPaint* ) override {
439 const SkRect rect = picture->cullRect();
440 SkPaint redPaint;
441 redPaint.setColor(SK_ColorRED);
442 canvas->drawRect(rect, redPaint);
443 }
444
445 SkCanvas* canvas;
446};
Cary Clark80247e52018-07-11 16:18:41 -0400447##
Cary Clarkf9603982018-07-17 08:20:27 -0400448SkPictureRecorder recorder;
449SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
450sk_sp<SkPicture> placeholder = SkPicture::MakePlaceholder({10, 40, 80, 110});
451pictureCanvas->drawPicture(placeholder);
452sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
453MyCanvas myCanvas(canvas);
454myCanvas.drawPicture(picture);
Cary Clark224c7002018-06-27 11:00:21 -0400455##
456
Cary Clarkf9603982018-07-17 08:20:27 -0400457#SeeAlso MakeFromStream MakeFromData uniqueID
Cary Clark224c7002018-06-27 11:00:21 -0400458
459#Method ##
460
461# ------------------------------------------------------------------------------
462
463#Method virtual int approximateOpCount() const = 0
Cary Clark80247e52018-07-11 16:18:41 -0400464#In Property
465#Line # returns approximate operation count ##
Cary Clark224c7002018-06-27 11:00:21 -0400466
Cary Clarkf9603982018-07-17 08:20:27 -0400467Returns the approximate number of operations in Picture. Returned value
468may be greater or less than the number of SkCanvas calls
469recorded: some calls may be recorded as more than one operation, other
Cary Clark224c7002018-06-27 11:00:21 -0400470calls may be optimized away.
471
Cary Clark80247e52018-07-11 16:18:41 -0400472#Return approximate operation count ##
Cary Clark224c7002018-06-27 11:00:21 -0400473
474#Example
Cary Clark80247e52018-07-11 16:18:41 -0400475 SkPictureRecorder recorder;
476 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
477 SkPaint paint;
478 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
479 paint.setColor(SK_ColorWHITE);
480 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
481 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
482 picture->playback(canvas);
483 std::string opCount = "approximate op count: " + std::to_string(picture->approximateOpCount());
484 canvas->drawString(opCount.c_str(), 50, 220, SkPaint());
Cary Clark224c7002018-06-27 11:00:21 -0400485##
486
Cary Clark80247e52018-07-11 16:18:41 -0400487#SeeAlso approximateBytesUsed
Cary Clark224c7002018-06-27 11:00:21 -0400488
489#Method ##
490
491# ------------------------------------------------------------------------------
492
493#Method virtual size_t approximateBytesUsed() const = 0
Cary Clark80247e52018-07-11 16:18:41 -0400494#In Property
495#Line # returns approximate size ##
Cary Clark224c7002018-06-27 11:00:21 -0400496
Cary Clark80247e52018-07-11 16:18:41 -0400497Returns the approximate byte size of Picture. Does not include large objects
Cary Clarkf9603982018-07-17 08:20:27 -0400498referenced by Picture.
Cary Clark224c7002018-06-27 11:00:21 -0400499
Cary Clark80247e52018-07-11 16:18:41 -0400500#Return approximate size ##
Cary Clark224c7002018-06-27 11:00:21 -0400501
502#Example
Cary Clark80247e52018-07-11 16:18:41 -0400503 SkPictureRecorder recorder;
504 SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
505 SkPaint paint;
506 pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
507 paint.setColor(SK_ColorWHITE);
508 pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
509 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
510 picture->playback(canvas);
511 std::string opCount = "approximate bytes used: " + std::to_string(picture->approximateBytesUsed());
512 canvas->drawString(opCount.c_str(), 20, 220, SkPaint());
Cary Clark224c7002018-06-27 11:00:21 -0400513##
514
Cary Clark80247e52018-07-11 16:18:41 -0400515#SeeAlso approximateOpCount
Cary Clark224c7002018-06-27 11:00:21 -0400516
517#Method ##
518
519#Class SkPicture ##
520
521#Topic Picture ##