OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
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 #include "SkDeferredCanvas.h" | 9 #include "SkDeferredCanvas.h" |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 // Release all allocated blocks | 133 // Release all allocated blocks |
134 fAllocator.reset(); | 134 fAllocator.reset(); |
135 } | 135 } |
136 | 136 |
137 //----------------------------------------------------------------------------- | 137 //----------------------------------------------------------------------------- |
138 // DeferredDevice | 138 // DeferredDevice |
139 //----------------------------------------------------------------------------- | 139 //----------------------------------------------------------------------------- |
140 class DeferredDevice : public SkDevice { | 140 class DeferredDevice : public SkDevice { |
141 public: | 141 public: |
| 142 #ifdef SK_DEVELOPER |
142 explicit DeferredDevice(SkDevice* immediateDevice); | 143 explicit DeferredDevice(SkDevice* immediateDevice); |
| 144 #endif |
143 explicit DeferredDevice(SkSurface* surface); | 145 explicit DeferredDevice(SkSurface* surface); |
144 ~DeferredDevice(); | 146 ~DeferredDevice(); |
145 | 147 |
146 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio
nClient); | 148 void setNotificationClient(SkDeferredCanvas::NotificationClient* notificatio
nClient); |
147 SkCanvas* recordingCanvas(); | 149 SkCanvas* recordingCanvas(); |
148 SkCanvas* immediateCanvas() const {return fImmediateCanvas;} | 150 SkCanvas* immediateCanvas() const {return fImmediateCanvas;} |
149 SkDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();} | 151 SkDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();} |
150 SkImage* newImageSnapshot(); | 152 SkImage* newImageSnapshot(); |
151 void setSurface(SkSurface* surface); | 153 void setSurface(SkSurface* surface); |
152 bool isFreshFrame(); | 154 bool isFreshFrame(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 SkCanvas* fRecordingCanvas; | 250 SkCanvas* fRecordingCanvas; |
249 SkSurface* fSurface; | 251 SkSurface* fSurface; |
250 SkDeferredCanvas::NotificationClient* fNotificationClient; | 252 SkDeferredCanvas::NotificationClient* fNotificationClient; |
251 bool fFreshFrame; | 253 bool fFreshFrame; |
252 bool fCanDiscardCanvasContents; | 254 bool fCanDiscardCanvasContents; |
253 size_t fMaxRecordingStorageBytes; | 255 size_t fMaxRecordingStorageBytes; |
254 size_t fPreviousStorageAllocated; | 256 size_t fPreviousStorageAllocated; |
255 size_t fBitmapSizeThreshold; | 257 size_t fBitmapSizeThreshold; |
256 }; | 258 }; |
257 | 259 |
| 260 #ifdef SK_DEVELOPER |
258 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) | 261 DeferredDevice::DeferredDevice(SkDevice* immediateDevice) |
259 : SkDevice(SkBitmap::kNo_Config, | 262 : SkDevice(SkBitmap::kNo_Config, |
260 immediateDevice->width(), immediateDevice->height(), | 263 immediateDevice->width(), immediateDevice->height(), |
261 immediateDevice->isOpaque(), | 264 immediateDevice->isOpaque(), |
262 immediateDevice->getDeviceProperties()) { | 265 immediateDevice->getDeviceProperties()) { |
263 fSurface = NULL; | 266 fSurface = NULL; |
264 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); | 267 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice)); |
265 fPipeController.setPlaybackCanvas(fImmediateCanvas); | 268 fPipeController.setPlaybackCanvas(fImmediateCanvas); |
266 this->init(); | 269 this->init(); |
267 } | 270 } |
| 271 #endif |
268 | 272 |
269 DeferredDevice::DeferredDevice(SkSurface* surface) | 273 DeferredDevice::DeferredDevice(SkSurface* surface) |
270 : SkDevice(SkBitmap::kNo_Config, | 274 : SkDevice(SkBitmap::kNo_Config, |
271 surface->getCanvas()->getDevice()->width(), | 275 surface->getCanvas()->getDevice()->width(), |
272 surface->getCanvas()->getDevice()->height(), | 276 surface->getCanvas()->getDevice()->height(), |
273 surface->getCanvas()->getDevice()->isOpaque(), | 277 surface->getCanvas()->getDevice()->isOpaque(), |
274 surface->getCanvas()->getDevice()->getDeviceProperties()) { | 278 surface->getCanvas()->getDevice()->getDeviceProperties()) { |
275 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; | 279 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
276 fNotificationClient = NULL; | 280 fNotificationClient = NULL; |
277 fImmediateCanvas = NULL; | 281 fImmediateCanvas = NULL; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 canvas.setDeferredDrawing(false); | 524 canvas.setDeferredDrawing(false); |
521 fCanvas = &canvas; | 525 fCanvas = &canvas; |
522 } else { | 526 } else { |
523 fCanvas = NULL; | 527 fCanvas = NULL; |
524 } | 528 } |
525 } | 529 } |
526 | 530 |
527 SkDeferredCanvas* fCanvas; | 531 SkDeferredCanvas* fCanvas; |
528 }; | 532 }; |
529 | 533 |
| 534 #if !SK_DEFERRED_CANVAS_USES_FACTORIES |
530 SkDeferredCanvas::SkDeferredCanvas() { | 535 SkDeferredCanvas::SkDeferredCanvas() { |
531 this->init(); | 536 this->init(); |
532 } | 537 } |
533 | 538 |
534 SkDeferredCanvas::SkDeferredCanvas(SkDevice* device) { | 539 SkDeferredCanvas::SkDeferredCanvas(SkDevice* device) { |
535 this->init(); | 540 this->init(); |
536 this->setDevice(device); | 541 this->setDevice(device); |
537 } | 542 } |
538 | 543 |
539 SkDeferredCanvas::SkDeferredCanvas(SkSurface* surface) { | 544 SkDeferredCanvas::SkDeferredCanvas(SkSurface* surface) { |
540 this->init(); | 545 this->init(); |
541 this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (surface)))->unref(); | 546 this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (surface)))->unref(); |
542 } | 547 } |
| 548 #endif |
| 549 |
| 550 SkDeferredCanvas* SkDeferredCanvas::Create(SkSurface* surface) { |
| 551 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (surf
ace))); |
| 552 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); |
| 553 } |
| 554 |
| 555 #ifdef SK_DEVELOPER |
| 556 SkDeferredCanvas* SkDeferredCanvas::Create(SkDevice* device) { |
| 557 SkAutoTUnref<DeferredDevice> deferredDevice(SkNEW_ARGS(DeferredDevice, (devi
ce))); |
| 558 return SkNEW_ARGS(SkDeferredCanvas, (deferredDevice)); |
| 559 } |
| 560 #endif |
| 561 |
| 562 SkDeferredCanvas::SkDeferredCanvas(DeferredDevice* device) : SkCanvas (device) { |
| 563 this->init(); |
| 564 } |
543 | 565 |
544 void SkDeferredCanvas::init() { | 566 void SkDeferredCanvas::init() { |
545 fDeferredDrawing = true; // On by default | 567 fDeferredDrawing = true; // On by default |
546 } | 568 } |
547 | 569 |
548 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { | 570 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { |
549 this->validate(); | 571 this->validate(); |
550 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage); | 572 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage); |
551 } | 573 } |
552 | 574 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 void SkDeferredCanvas::silentFlush() { | 637 void SkDeferredCanvas::silentFlush() { |
616 if (fDeferredDrawing) { | 638 if (fDeferredDrawing) { |
617 this->getDeferredDevice()->flushPendingCommands(kSilent_PlaybackMode); | 639 this->getDeferredDevice()->flushPendingCommands(kSilent_PlaybackMode); |
618 } | 640 } |
619 } | 641 } |
620 | 642 |
621 SkDeferredCanvas::~SkDeferredCanvas() { | 643 SkDeferredCanvas::~SkDeferredCanvas() { |
622 } | 644 } |
623 | 645 |
624 SkDevice* SkDeferredCanvas::setDevice(SkDevice* device) { | 646 SkDevice* SkDeferredCanvas::setDevice(SkDevice* device) { |
| 647 #if SK_DEFERRED_CANVAS_USES_FACTORIES |
| 648 SkASSERT(0); // setDevice is deprecated |
| 649 #else |
625 this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (device)))->unref(); | 650 this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (device)))->unref(); |
| 651 #endif |
626 return device; | 652 return device; |
627 } | 653 } |
628 | 654 |
629 SkSurface* SkDeferredCanvas::setSurface(SkSurface* surface) { | 655 SkSurface* SkDeferredCanvas::setSurface(SkSurface* surface) { |
630 DeferredDevice* deferredDevice = this->getDeferredDevice(); | 656 DeferredDevice* deferredDevice = this->getDeferredDevice(); |
631 if (NULL != deferredDevice) { | 657 SkASSERT(NULL != deferredDevice); |
632 // By swapping the surface into the existing device, we preserve | 658 // By swapping the surface into the existing device, we preserve |
633 // all pending commands, which can help to seamlessly recover from | 659 // all pending commands, which can help to seamlessly recover from |
634 // a lost accelerated graphics context. | 660 // a lost accelerated graphics context. |
635 deferredDevice->setSurface(surface); | 661 deferredDevice->setSurface(surface); |
636 } else { | |
637 this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (surface)))->unref
(); | |
638 } | |
639 return surface; | 662 return surface; |
640 } | 663 } |
641 | 664 |
642 SkDeferredCanvas::NotificationClient* SkDeferredCanvas::setNotificationClient( | 665 SkDeferredCanvas::NotificationClient* SkDeferredCanvas::setNotificationClient( |
643 NotificationClient* notificationClient) { | 666 NotificationClient* notificationClient) { |
644 | 667 |
645 DeferredDevice* deferredDevice = this->getDeferredDevice(); | 668 DeferredDevice* deferredDevice = this->getDeferredDevice(); |
646 SkASSERT(deferredDevice); | 669 SkASSERT(deferredDevice); |
647 if (deferredDevice) { | 670 if (deferredDevice) { |
648 deferredDevice->setNotificationClient(notificationClient); | 671 deferredDevice->setNotificationClient(notificationClient); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { | 1010 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { |
988 this->drawingCanvas()->setDrawFilter(filter); | 1011 this->drawingCanvas()->setDrawFilter(filter); |
989 this->INHERITED::setDrawFilter(filter); | 1012 this->INHERITED::setDrawFilter(filter); |
990 this->recordedDrawCommand(); | 1013 this->recordedDrawCommand(); |
991 return filter; | 1014 return filter; |
992 } | 1015 } |
993 | 1016 |
994 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { | 1017 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { |
995 return this->drawingCanvas(); | 1018 return this->drawingCanvas(); |
996 } | 1019 } |
OLD | NEW |