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

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

Issue 238273012: Staged removal of SkPicture-derived classes (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: have SkPicture only friend SkPictureRecorder once 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
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | include/core/SkRTreePicture.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #define SkPicture_DEFINED 11 #define SkPicture_DEFINED
12 12
13 #include "SkBitmap.h" 13 #include "SkBitmap.h"
14 #include "SkImageDecoder.h" 14 #include "SkImageDecoder.h"
15 #include "SkRefCnt.h" 15 #include "SkRefCnt.h"
16 16
17 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
18 class GrContext; 18 class GrContext;
19 #endif 19 #endif
20 20
21 class SkBBHFactory;
21 class SkBBoxHierarchy; 22 class SkBBoxHierarchy;
22 class SkCanvas; 23 class SkCanvas;
23 class SkDrawPictureCallback; 24 class SkDrawPictureCallback;
24 class SkData; 25 class SkData;
25 class SkPicturePlayback; 26 class SkPicturePlayback;
26 class SkPictureRecord; 27 class SkPictureRecord;
27 class SkStream; 28 class SkStream;
28 class SkWStream; 29 class SkWStream;
29 30
30 struct SkPictInfo; 31 struct SkPictInfo;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 discarded if you serialize into a stream and then deserialize. 168 discarded if you serialize into a stream and then deserialize.
168 */ 169 */
169 kOptimizeForClippedPlayback_RecordingFlag = 0x02, 170 kOptimizeForClippedPlayback_RecordingFlag = 0x02,
170 }; 171 };
171 #ifndef SK_SUPPORT_DEPRECATED_RECORD_FLAGS 172 #ifndef SK_SUPPORT_DEPRECATED_RECORD_FLAGS
172 public: 173 public:
173 #endif 174 #endif
174 175
175 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD 176 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD
176 private: 177 private:
177 friend class SkPictureRecorder;
178 friend class SkImage_Picture;
179 friend class SkSurface_Picture;
180 #endif 178 #endif
181 179
180 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES
181
182 /** Returns the canvas that records the drawing commands. 182 /** Returns the canvas that records the drawing commands.
183 @param width the base width for the picture, as if the recording 183 @param width the base width for the picture, as if the recording
184 canvas' bitmap had this width. 184 canvas' bitmap had this width.
185 @param height the base width for the picture, as if the recording 185 @param height the base width for the picture, as if the recording
186 canvas' bitmap had this height. 186 canvas' bitmap had this height.
187 @param recordFlags optional flags that control recording. 187 @param recordFlags optional flags that control recording.
188 @return the picture canvas. 188 @return the picture canvas.
189 */ 189 */
190 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0); 190 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0);
191 #endif
191 192
192 /** Returns the recording canvas if one is active, or NULL if recording is 193 /** Returns the recording canvas if one is active, or NULL if recording is
193 not active. This does not alter the refcnt on the canvas (if present). 194 not active. This does not alter the refcnt on the canvas (if present).
194 */ 195 */
195 SkCanvas* getRecordingCanvas() const; 196 SkCanvas* getRecordingCanvas() const;
196 /** Signal that the caller is done recording. This invalidates the canvas 197 /** Signal that the caller is done recording. This invalidates the canvas
197 returned by beginRecording/getRecordingCanvas, and prepares the picture 198 returned by beginRecording/getRecordingCanvas, and prepares the picture
198 for drawing. Note: this happens implicitly the first time the picture 199 for drawing. Note: this happens implicitly the first time the picture
199 is drawn. 200 is drawn.
200 */ 201 */
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 SkPictureRecord* fRecord; 340 SkPictureRecord* fRecord;
340 int fWidth, fHeight; 341 int fWidth, fHeight;
341 const AccelData* fAccelData; 342 const AccelData* fAccelData;
342 343
343 void needsNewGenID() { fUniqueID = SK_InvalidGenID; } 344 void needsNewGenID() { fUniqueID = SK_InvalidGenID; }
344 345
345 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of 346 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of
346 // playback is unchanged. 347 // playback is unchanged.
347 SkPicture(SkPicturePlayback*, int width, int height); 348 SkPicture(SkPicturePlayback*, int width, int height);
348 349
350 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES
349 // For testing. Derived classes may instantiate an alternate 351 // For testing. Derived classes may instantiate an alternate
350 // SkBBoxHierarchy implementation 352 // SkBBoxHierarchy implementation
351 virtual SkBBoxHierarchy* createBBoxHierarchy() const; 353 virtual SkBBoxHierarchy* createBBoxHierarchy() const;
354 #endif
355
356 SkCanvas* beginRecording(int width, int height, SkBBHFactory* factory, uint3 2_t recordFlags);
352 357
353 private: 358 private:
354 // An OperationList encapsulates a set of operation offsets into the picture byte 359 // An OperationList encapsulates a set of operation offsets into the picture byte
355 // stream along with the CTMs needed for those operation. 360 // stream along with the CTMs needed for those operation.
356 class OperationList : ::SkNoncopyable { 361 class OperationList : ::SkNoncopyable {
357 public: 362 public:
358 virtual ~OperationList() {} 363 virtual ~OperationList() {}
359 364
360 // If valid returns false then there is no optimization data 365 // If valid returns false then there is no optimization data
361 // present. All the draw operations need to be issued. 366 // present. All the draw operations need to be issued.
(...skipping 19 matching lines...) Expand all
381 Return the ID of the operation currently being executed when playing 386 Return the ID of the operation currently being executed when playing
382 back. 0 indicates no call is active. 387 back. 0 indicates no call is active.
383 */ 388 */
384 size_t EXPERIMENTAL_curOpID() const; 389 size_t EXPERIMENTAL_curOpID() const;
385 390
386 void createHeader(SkPictInfo* info) const; 391 void createHeader(SkPictInfo* info) const;
387 static bool IsValidPictInfo(const SkPictInfo& info); 392 static bool IsValidPictInfo(const SkPictInfo& info);
388 393
389 friend class SkFlatPicture; 394 friend class SkFlatPicture;
390 friend class SkPicturePlayback; 395 friend class SkPicturePlayback;
396 friend class SkPictureRecorder;
391 friend class SkGpuDevice; 397 friend class SkGpuDevice;
392 friend class GrGatherDevice; 398 friend class GrGatherDevice;
393 friend class SkDebugCanvas; 399 friend class SkDebugCanvas;
394 400
395 typedef SkRefCnt INHERITED; 401 typedef SkRefCnt INHERITED;
396 }; 402 };
397 403
398 /** 404 /**
399 * Subclasses of this can be passed to canvas.drawPicture. During the drawing 405 * Subclasses of this can be passed to canvas.drawPicture. During the drawing
400 * of the picture, this callback will periodically be invoked. If its 406 * of the picture, this callback will periodically be invoked. If its
401 * abortDrawing() returns true, then picture playback will be interrupted. 407 * abortDrawing() returns true, then picture playback will be interrupted.
402 * 408 *
403 * The resulting drawing is undefined, as there is no guarantee how often the 409 * The resulting drawing is undefined, as there is no guarantee how often the
404 * callback will be invoked. If the abort happens inside some level of nested 410 * callback will be invoked. If the abort happens inside some level of nested
405 * calls to save(), restore will automatically be called to return the state 411 * calls to save(), restore will automatically be called to return the state
406 * to the same level it was before the drawPicture call was made. 412 * to the same level it was before the drawPicture call was made.
407 */ 413 */
408 class SK_API SkDrawPictureCallback { 414 class SK_API SkDrawPictureCallback {
409 public: 415 public:
410 SkDrawPictureCallback() {} 416 SkDrawPictureCallback() {}
411 virtual ~SkDrawPictureCallback() {} 417 virtual ~SkDrawPictureCallback() {}
412 418
413 virtual bool abortDrawing() = 0; 419 virtual bool abortDrawing() = 0;
414 }; 420 };
415 421
422 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES
423
416 class SkPictureFactory : public SkRefCnt { 424 class SkPictureFactory : public SkRefCnt {
417 public: 425 public:
418 /** 426 /**
419 * Allocate a new SkPicture. Return NULL on failure. 427 * Allocate a new SkPicture. Return NULL on failure.
420 */ 428 */
421 virtual SkPicture* create(int width, int height) = 0; 429 virtual SkPicture* create(int width, int height) = 0;
422 430
423 private: 431 private:
424 typedef SkRefCnt INHERITED; 432 typedef SkRefCnt INHERITED;
425 }; 433 };
426 434
435 #endif
436
437 class SkBBHFactory {
438 public:
439 /**
440 * Allocate a new SkBBoxHierarchy. Return NULL on failure.
441 */
442 virtual SkBBoxHierarchy* operator()(int width, int height) const = 0;
443 virtual ~SkBBHFactory() {};
444 };
445
427 class SK_API SkPictureRecorder : SkNoncopyable { 446 class SK_API SkPictureRecorder : SkNoncopyable {
428 public: 447 public:
448 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES
449
429 SkPictureRecorder(SkPictureFactory* factory = NULL) { 450 SkPictureRecorder(SkPictureFactory* factory = NULL) {
430 fFactory.reset(factory); 451 fFactory.reset(factory);
431 if (NULL != fFactory.get()) { 452 if (NULL != fFactory.get()) {
432 fFactory.get()->ref(); 453 fFactory.get()->ref();
433 } 454 }
434 } 455 }
435 456
436 /** Returns the canvas that records the drawing commands. 457 /** Returns the canvas that records the drawing commands.
437 @param width the base width for the picture, as if the recording 458 @param width the base width for the picture, as if the recording
438 canvas' bitmap had this width. 459 canvas' bitmap had this width.
439 @param height the base width for the picture, as if the recording 460 @param height the base width for the picture, as if the recording
440 canvas' bitmap had this height. 461 canvas' bitmap had this height.
441 @param recordFlags optional flags that control recording. 462 @param recordFlags optional flags that control recording.
442 @return the canvas. 463 @return the canvas.
443 */ 464 */
444 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) { 465 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) {
445 if (NULL != fFactory) { 466 if (NULL != fFactory) {
446 fPicture.reset(fFactory->create(width, height)); 467 fPicture.reset(fFactory->create(width, height));
447 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; 468 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag;
448 } else { 469 } else {
449 fPicture.reset(SkNEW(SkPicture)); 470 fPicture.reset(SkNEW(SkPicture));
450 } 471 }
451 472
452 return fPicture->beginRecording(width, height, recordFlags); 473 return fPicture->beginRecording(width, height, recordFlags);
453 } 474 }
475 #endif
476
477 /** Returns the canvas that records the drawing commands.
478 @param width the base width for the picture, as if the recording
479 canvas' bitmap had this width.
480 @param height the base width for the picture, as if the recording
481 canvas' bitmap had this height.
482 @param bbhFactory factory to create desired acceleration structure
483 @param recordFlags optional flags that control recording.
484 @return the canvas.
485 */
486 // TODO: allow default parameters once the other beginRecoding entry point i s gone
487 SkCanvas* beginRecording(int width, int height,
488 SkBBHFactory* bbhFactory /* = NULL */,
489 uint32_t recordFlags /* = 0 */) {
490 fPicture.reset(SkNEW(SkPicture));
491 return fPicture->beginRecording(width, height, bbhFactory, recordFlags);
492 }
454 493
455 /** Returns the recording canvas if one is active, or NULL if recording is 494 /** Returns the recording canvas if one is active, or NULL if recording is
456 not active. This does not alter the refcnt on the canvas (if present). 495 not active. This does not alter the refcnt on the canvas (if present).
457 */ 496 */
458 SkCanvas* getRecordingCanvas() { 497 SkCanvas* getRecordingCanvas() {
459 if (NULL != fPicture.get()) { 498 if (NULL != fPicture.get()) {
460 return fPicture->getRecordingCanvas(); 499 return fPicture->getRecordingCanvas();
461 } 500 }
462 return NULL; 501 return NULL;
463 } 502 }
(...skipping 17 matching lines...) Expand all
481 appear in an .skp we have to disable the optimization). Call right 520 appear in an .skp we have to disable the optimization). Call right
482 after 'beginRecording'. 521 after 'beginRecording'.
483 */ 522 */
484 void internalOnly_EnableOpts(bool enableOpts) { 523 void internalOnly_EnableOpts(bool enableOpts) {
485 if (NULL != fPicture.get()) { 524 if (NULL != fPicture.get()) {
486 fPicture->internalOnly_EnableOpts(enableOpts); 525 fPicture->internalOnly_EnableOpts(enableOpts);
487 } 526 }
488 } 527 }
489 528
490 private: 529 private:
491 SkAutoTUnref<SkPictureFactory> fFactory; 530 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES
492 SkAutoTUnref<SkPicture> fPicture; 531 SkAutoTUnref<SkPictureFactory> fFactory;
532 #endif
533
534 SkAutoTUnref<SkPicture> fPicture;
493 535
494 typedef SkNoncopyable INHERITED; 536 typedef SkNoncopyable INHERITED;
495 }; 537 };
496 538
497 #endif 539 #endif
OLDNEW
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | include/core/SkRTreePicture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698