Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: include/core/SkPicture.h

Issue 214953003: split SkPictureRecorder out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT (again) Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2007 The Android Open Source Project 3 * Copyright 2007 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkPicture_DEFINED 10 #ifndef SkPicture_DEFINED
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 after a frame or two of tiled rendering (and complex pictures that 153 after a frame or two of tiled rendering (and complex pictures that
154 induce the worst record times will generally get the largest 154 induce the worst record times will generally get the largest
155 speedups at playback time). 155 speedups at playback time).
156 156
157 Note: Currently this is not serializable, the bounding data will be 157 Note: Currently this is not serializable, the bounding data will be
158 discarded if you serialize into a stream and then deserialize. 158 discarded if you serialize into a stream and then deserialize.
159 */ 159 */
160 kOptimizeForClippedPlayback_RecordingFlag = 0x02, 160 kOptimizeForClippedPlayback_RecordingFlag = 0x02,
161 }; 161 };
162 162
163 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD
164 private:
165 friend class SkPictureRecorder;
166 friend class SkImage_Picture;
167 friend class SkSurface_Picture;
168 #endif
169
163 /** Returns the canvas that records the drawing commands. 170 /** Returns the canvas that records the drawing commands.
164 @param width the base width for the picture, as if the recording 171 @param width the base width for the picture, as if the recording
165 canvas' bitmap had this width. 172 canvas' bitmap had this width.
166 @param height the base width for the picture, as if the recording 173 @param height the base width for the picture, as if the recording
167 canvas' bitmap had this height. 174 canvas' bitmap had this height.
168 @param recordFlags optional flags that control recording. 175 @param recordFlags optional flags that control recording.
169 @return the picture canvas. 176 @return the picture canvas.
170 */ 177 */
171 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0); 178 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0);
172 179
173 /** Returns the recording canvas if one is active, or NULL if recording is 180 /** Returns the recording canvas if one is active, or NULL if recording is
174 not active. This does not alter the refcnt on the canvas (if present). 181 not active. This does not alter the refcnt on the canvas (if present).
175 */ 182 */
176 SkCanvas* getRecordingCanvas() const; 183 SkCanvas* getRecordingCanvas() const;
177 /** Signal that the caller is done recording. This invalidates the canvas 184 /** Signal that the caller is done recording. This invalidates the canvas
178 returned by beginRecording/getRecordingCanvas, and prepares the picture 185 returned by beginRecording/getRecordingCanvas, and prepares the picture
179 for drawing. Note: this happens implicitly the first time the picture 186 for drawing. Note: this happens implicitly the first time the picture
180 is drawn. 187 is drawn.
181 */ 188 */
182 void endRecording(); 189 void endRecording();
183 190
191 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD
192 public:
193 #endif
194
184 /** Replays the drawing commands on the specified canvas. This internally 195 /** Replays the drawing commands on the specified canvas. This internally
185 calls endRecording() if that has not already been called. 196 calls endRecording() if that has not already been called.
186 @param canvas the canvas receiving the drawing commands. 197 @param canvas the canvas receiving the drawing commands.
187 */ 198 */
188 void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL); 199 void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL);
189 200
190 /** Return the width of the picture's recording canvas. This 201 /** Return the width of the picture's recording canvas. This
191 value reflects what was passed to setSize(), and does not necessarily 202 value reflects what was passed to setSize(), and does not necessarily
192 reflect the bounds of what has been recorded into the picture. 203 reflect the bounds of what has been recorded into the picture.
193 @return the width of the picture's recording canvas 204 @return the width of the picture's recording canvas
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 * to the same level it was before the drawPicture call was made. 392 * to the same level it was before the drawPicture call was made.
382 */ 393 */
383 class SK_API SkDrawPictureCallback { 394 class SK_API SkDrawPictureCallback {
384 public: 395 public:
385 SkDrawPictureCallback() {} 396 SkDrawPictureCallback() {}
386 virtual ~SkDrawPictureCallback() {} 397 virtual ~SkDrawPictureCallback() {}
387 398
388 virtual bool abortDrawing() = 0; 399 virtual bool abortDrawing() = 0;
389 }; 400 };
390 401
402 class SkPictureFactory : public SkRefCnt {
403 public:
404 /**
405 * Allocate a new SkPicture. Return NULL on failure.
406 */
407 virtual SkPicture* create(int width, int height) = 0;
408 };
409
410 class SK_API SkPictureRecorder : SkNoncopyable {
411 public:
412 SkPictureRecorder(SkPictureFactory* factory = NULL) {
413 fFactory.reset(factory);
414 if (NULL != fFactory.get()) {
415 fFactory.get()->ref();
416 }
417 }
418
419 /** Returns the canvas that records the drawing commands.
420 @param width the base width for the picture, as if the recording
421 canvas' bitmap had this width.
422 @param height the base width for the picture, as if the recording
423 canvas' bitmap had this height.
424 @param recordFlags optional flags that control recording.
425 @return the canvas.
426 */
427 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) {
428 if (NULL != fFactory) {
429 fPicture.reset(fFactory->create(width, height));
430 } else {
431 fPicture.reset(SkNEW(SkPicture));
432 }
433
434 return fPicture->beginRecording(width, height, recordFlags);
435 }
436
437 /** Returns the recording canvas if one is active, or NULL if recording is
438 not active. This does not alter the refcnt on the canvas (if present).
439 */
440 SkCanvas* getRecordingCanvas() {
441 if (NULL != fPicture.get()) {
442 return fPicture->getRecordingCanvas();
443 }
444 return NULL;
445 }
446
447 /** Signal that the caller is done recording. This invalidates the canvas
448 returned by beginRecording/getRecordingCanvas, and returns the
449 created SkPicture. Note that the returned picture has its creation
450 ref which the caller must take ownership of.
451 */
452 SkPicture* endRecording() {
453 if (NULL != fPicture.get()) {
454 fPicture->endRecording();
455 return fPicture.detach();
456 }
457 return NULL;
458 }
459
460 /** Enable/disable all the picture recording optimizations (i.e.,
461 those in SkPictureRecord). It is mainly intended for testing the
462 existing optimizations (i.e., to actually have the pattern
463 appear in an .skp we have to disable the optimization). Call right
464 after 'beginRecording'.
465 */
466 void internalOnly_EnableOpts(bool enableOpts) {
467 if (NULL != fPicture.get()) {
468 fPicture->internalOnly_EnableOpts(enableOpts);
469 }
470 }
471
472 private:
473 SkAutoTUnref<SkPictureFactory> fFactory;
474 SkAutoTUnref<SkPicture> fPicture;
475
476 typedef SkNoncopyable INHERITED;
477 };
478
391 #endif 479 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698