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

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: added guard 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 after a frame or two of tiled rendering (and complex pictures that 157 after a frame or two of tiled rendering (and complex pictures that
158 induce the worst record times will generally get the largest 158 induce the worst record times will generally get the largest
159 speedups at playback time). 159 speedups at playback time).
160 160
161 Note: Currently this is not serializable, the bounding data will be 161 Note: Currently this is not serializable, the bounding data will be
162 discarded if you serialize into a stream and then deserialize. 162 discarded if you serialize into a stream and then deserialize.
163 */ 163 */
164 kOptimizeForClippedPlayback_RecordingFlag = 0x02, 164 kOptimizeForClippedPlayback_RecordingFlag = 0x02,
165 }; 165 };
166 166
167 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD
168 private:
169 friend class SkPictureRecorder;
170 friend class SkImage_Picture;
171 friend class SkSurface_Picture;
172 #endif
173
167 /** Returns the canvas that records the drawing commands. 174 /** Returns the canvas that records the drawing commands.
168 @param width the base width for the picture, as if the recording 175 @param width the base width for the picture, as if the recording
169 canvas' bitmap had this width. 176 canvas' bitmap had this width.
170 @param height the base width for the picture, as if the recording 177 @param height the base width for the picture, as if the recording
171 canvas' bitmap had this height. 178 canvas' bitmap had this height.
172 @param recordFlags optional flags that control recording. 179 @param recordFlags optional flags that control recording.
173 @return the picture canvas. 180 @return the picture canvas.
174 */ 181 */
175 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0); 182 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0);
176 183
177 /** Returns the recording canvas if one is active, or NULL if recording is 184 /** Returns the recording canvas if one is active, or NULL if recording is
178 not active. This does not alter the refcnt on the canvas (if present). 185 not active. This does not alter the refcnt on the canvas (if present).
179 */ 186 */
180 SkCanvas* getRecordingCanvas() const; 187 SkCanvas* getRecordingCanvas() const;
181 /** Signal that the caller is done recording. This invalidates the canvas 188 /** Signal that the caller is done recording. This invalidates the canvas
182 returned by beginRecording/getRecordingCanvas, and prepares the picture 189 returned by beginRecording/getRecordingCanvas, and prepares the picture
183 for drawing. Note: this happens implicitly the first time the picture 190 for drawing. Note: this happens implicitly the first time the picture
184 is drawn. 191 is drawn.
185 */ 192 */
186 void endRecording(); 193 void endRecording();
187 194
195 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD
196 public:
197 #endif
198
188 /** Replays the drawing commands on the specified canvas. This internally 199 /** Replays the drawing commands on the specified canvas. This internally
189 calls endRecording() if that has not already been called. 200 calls endRecording() if that has not already been called.
190 @param canvas the canvas receiving the drawing commands. 201 @param canvas the canvas receiving the drawing commands.
191 */ 202 */
192 void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL); 203 void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL);
193 204
194 /** Return the width of the picture's recording canvas. This 205 /** Return the width of the picture's recording canvas. This
195 value reflects what was passed to setSize(), and does not necessarily 206 value reflects what was passed to setSize(), and does not necessarily
196 reflect the bounds of what has been recorded into the picture. 207 reflect the bounds of what has been recorded into the picture.
197 @return the width of the picture's recording canvas 208 @return the width of the picture's recording canvas
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 * to the same level it was before the drawPicture call was made. 388 * to the same level it was before the drawPicture call was made.
378 */ 389 */
379 class SK_API SkDrawPictureCallback { 390 class SK_API SkDrawPictureCallback {
380 public: 391 public:
381 SkDrawPictureCallback() {} 392 SkDrawPictureCallback() {}
382 virtual ~SkDrawPictureCallback() {} 393 virtual ~SkDrawPictureCallback() {}
383 394
384 virtual bool abortDrawing() = 0; 395 virtual bool abortDrawing() = 0;
385 }; 396 };
386 397
398 class SkPictureFactory : public SkRefCnt {
399 public:
400 /**
401 * Allocate a new SkPicture. Return NULL on failure.
402 */
403 virtual SkPicture* create(int width, int height) = 0;
mtklein 2014/04/07 15:18:12 If you keep factories, it might be less obtrusive
robertphillips 2014/04/07 16:26:56 The TileGrid ctor requires extra parameters.
mtklein 2014/04/07 16:29:43 OK then, pass as a functor?
404 };
405
406 class SK_API SkPictureRecorder : public SkNoncopyable {
mtklein 2014/04/07 15:18:12 For SkNoncopyable to work, it's got to be private
mtklein 2014/04/07 15:18:12 I'm still somewhat surprised that SkPictureRecorde
robertphillips 2014/04/07 16:26:56 If that's true we're doing it wrong all over the p
mtklein 2014/04/07 16:29:43 Gross.
407 public:
408 SkPictureRecorder(SkPictureFactory* factory = NULL) {
reed1 2014/04/07 14:49:57 icky icky factory. why is this here? Is it just fo
robertphillips 2014/04/07 15:05:37 Yes. Ultimately this should change to "SkAccelFact
409 fFactory.reset(factory);
410 if (NULL != fFactory.get()) {
411 fFactory.get()->ref();
412 }
413 }
414
415 /** Returns the canvas that records the drawing commands.
416 @param width the base width for the picture, as if the recording
417 canvas' bitmap had this width.
418 @param height the base width for the picture, as if the recording
419 canvas' bitmap had this height.
420 @param recordFlags optional flags that control recording.
421 @return the canvas.
422 */
423 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) {
mtklein 2014/04/07 15:18:12 Can we just pass in the SkPicture to record into?
424 if (NULL != fFactory) {
425 fPicture.reset(fFactory->create(width, height));
426 } else {
427 fPicture.reset(SkNEW(SkPicture));
428 }
429
430 return fPicture->beginRecording(width, height, recordFlags);
431 }
432
433 /** Returns the recording canvas if one is active, or NULL if recording is
434 not active. This does not alter the refcnt on the canvas (if present).
435 */
436 SkCanvas* getRecordingCanvas() {
437 if (NULL != fPicture.get()) {
438 return fPicture->getRecordingCanvas();
439 }
440 return NULL;
441 }
442
443 /** Signal that the caller is done recording. This invalidates the canvas
444 returned by beginRecording/getRecordingCanvas, and returns the
445 created SkPicture. Note that the returned picture has its creation
446 ref which the caller must take ownership of.
447 */
448 SkPicture* endRecording() {
449 if (NULL != fPicture.get()) {
450 fPicture->endRecording();
451 return fPicture.detach();
452 }
453 return NULL;
454 }
455
456 /** Enable/disable all the picture recording optimizations (i.e.,
457 those in SkPictureRecord). It is mainly intended for testing the
458 existing optimizations (i.e., to actually have the pattern
459 appear in an .skp we have to disable the optimization). Call right
460 after 'beginRecording'.
461 */
462 void internalOnly_EnableOpts(bool enableOpts) {
463 if (NULL != fPicture.get()) {
464 fPicture->internalOnly_EnableOpts(enableOpts);
465 }
466 }
467
468 private:
469 SkAutoTUnref<SkPictureFactory> fFactory;
470 SkAutoTUnref<SkPicture> fPicture;
471
472 typedef SkNoncopyable INHERITED;
473 };
474
387 #endif 475 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698