Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 * to the same level it was before the drawPicture call was made. | 377 * to the same level it was before the drawPicture call was made. |
| 378 */ | 378 */ |
| 379 class SK_API SkDrawPictureCallback { | 379 class SK_API SkDrawPictureCallback { |
| 380 public: | 380 public: |
| 381 SkDrawPictureCallback() {} | 381 SkDrawPictureCallback() {} |
| 382 virtual ~SkDrawPictureCallback() {} | 382 virtual ~SkDrawPictureCallback() {} |
| 383 | 383 |
| 384 virtual bool abortDrawing() = 0; | 384 virtual bool abortDrawing() = 0; |
| 385 }; | 385 }; |
| 386 | 386 |
| 387 class SkPictureFactory : public SkRefCnt { | |
| 388 public: | |
| 389 /** | |
| 390 * Allocate a new SkPicture. Return NULL on failure. | |
| 391 */ | |
| 392 virtual SkPicture* create(int width, int height) = 0; | |
| 393 }; | |
| 394 | |
| 395 class SK_API SkPictureRecorder : public SkRefCnt { | |
|
mtklein
2014/03/27 21:09:11
What's this extra level of indirection get us? I'
| |
| 396 public: | |
| 397 SK_DECLARE_INST_COUNT(SkPictureRecorder) | |
| 398 | |
| 399 SkPictureRecorder(SkPictureFactory* factory = NULL) { | |
| 400 fFactory.reset(factory); | |
| 401 if (NULL != fFactory.get()) { | |
| 402 fFactory.get()->ref(); | |
| 403 } | |
| 404 } | |
| 405 | |
| 406 /** Returns the canvas that records the drawing commands. | |
| 407 @param width the base width for the picture, as if the recording | |
| 408 canvas' bitmap had this width. | |
| 409 @param height the base width for the picture, as if the recording | |
| 410 canvas' bitmap had this height. | |
| 411 @param recordFlags optional flags that control recording. | |
| 412 @return the canvas. | |
| 413 */ | |
| 414 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) { | |
| 415 if (NULL != fFactory) { | |
| 416 fPicture.reset(fFactory->create(width, height)); | |
| 417 } else { | |
| 418 fPicture.reset(SkNEW(SkPicture)); | |
| 419 } | |
| 420 | |
| 421 return fPicture->beginRecording(width, height, recordFlags); | |
| 422 } | |
| 423 | |
| 424 /** Returns the recording canvas if one is active, or NULL if recording is | |
| 425 not active. This does not alter the refcnt on the canvas (if present). | |
| 426 */ | |
| 427 SkCanvas* getRecordingCanvas() { | |
| 428 if (NULL != fPicture.get()) { | |
| 429 return fPicture->getRecordingCanvas(); | |
| 430 } | |
| 431 return NULL; | |
| 432 } | |
| 433 | |
| 434 /** Signal that the caller is done recording. This invalidates the canvas | |
| 435 returned by beginRecording/getRecordingCanvas, and returns the | |
| 436 created SkPicture. Note that the returned picture has its creation | |
| 437 ref which the caller must take ownership of. | |
| 438 */ | |
| 439 SkPicture* endRecording() { | |
| 440 if (NULL != fPicture.get()) { | |
| 441 fPicture->endRecording(); | |
| 442 return fPicture.detach(); | |
| 443 } | |
| 444 return NULL; | |
| 445 } | |
| 446 | |
| 447 /** Enable/disable all the picture recording optimizations (i.e., | |
| 448 those in SkPictureRecord). It is mainly intended for testing the | |
| 449 existing optimizations (i.e., to actually have the pattern | |
| 450 appear in an .skp we have to disable the optimization). Call right | |
| 451 after 'beginRecording'. | |
| 452 */ | |
| 453 void internalOnly_EnableOpts(bool enableOpts) { | |
| 454 if (NULL != fPicture.get()) { | |
| 455 fPicture->internalOnly_EnableOpts(enableOpts); | |
| 456 } | |
| 457 } | |
| 458 | |
| 459 private: | |
| 460 SkAutoTUnref<SkPictureFactory> fFactory; | |
| 461 SkAutoTUnref<SkPicture> fPicture; | |
| 462 | |
| 463 typedef SkRefCnt INHERITED; | |
| 464 }; | |
| 465 | |
| 387 #endif | 466 #endif |
| OLD | NEW |