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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 SkImage* newImageSnapshot(); | 147 SkImage* newImageSnapshot(); |
148 void setSurface(SkSurface* surface); | 148 void setSurface(SkSurface* surface); |
149 bool isFreshFrame(); | 149 bool isFreshFrame(); |
150 bool hasPendingCommands(); | 150 bool hasPendingCommands(); |
151 size_t storageAllocatedForRecording() const; | 151 size_t storageAllocatedForRecording() const; |
152 size_t freeMemoryIfPossible(size_t bytesToFree); | 152 size_t freeMemoryIfPossible(size_t bytesToFree); |
153 void flushPendingCommands(PlaybackMode); | 153 void flushPendingCommands(PlaybackMode); |
154 void skipPendingCommands(); | 154 void skipPendingCommands(); |
155 void setMaxRecordingStorage(size_t); | 155 void setMaxRecordingStorage(size_t); |
156 void recordedDrawCommand(); | 156 void recordedDrawCommand(); |
| 157 void setIsDrawingToLayer(bool value) {fIsDrawingToLayer = value;} |
157 | 158 |
158 virtual SkImageInfo imageInfo() const SK_OVERRIDE; | 159 virtual SkImageInfo imageInfo() const SK_OVERRIDE; |
159 | 160 |
160 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; | 161 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; |
161 | 162 |
162 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRID
E; | 163 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRID
E; |
163 | 164 |
164 virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_
OVERRIDE; | 165 virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_
OVERRIDE; |
165 | 166 |
166 protected: | 167 protected: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 void prepareForImmediatePixelWrite(); | 250 void prepareForImmediatePixelWrite(); |
250 | 251 |
251 DeferredPipeController fPipeController; | 252 DeferredPipeController fPipeController; |
252 SkGPipeWriter fPipeWriter; | 253 SkGPipeWriter fPipeWriter; |
253 SkCanvas* fImmediateCanvas; | 254 SkCanvas* fImmediateCanvas; |
254 SkCanvas* fRecordingCanvas; | 255 SkCanvas* fRecordingCanvas; |
255 SkSurface* fSurface; | 256 SkSurface* fSurface; |
256 SkDeferredCanvas::NotificationClient* fNotificationClient; | 257 SkDeferredCanvas::NotificationClient* fNotificationClient; |
257 bool fFreshFrame; | 258 bool fFreshFrame; |
258 bool fCanDiscardCanvasContents; | 259 bool fCanDiscardCanvasContents; |
| 260 bool fIsDrawingToLayer; |
259 size_t fMaxRecordingStorageBytes; | 261 size_t fMaxRecordingStorageBytes; |
260 size_t fPreviousStorageAllocated; | 262 size_t fPreviousStorageAllocated; |
261 }; | 263 }; |
262 | 264 |
263 SkDeferredDevice::SkDeferredDevice(SkSurface* surface) { | 265 SkDeferredDevice::SkDeferredDevice(SkSurface* surface) { |
264 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; | 266 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; |
265 fNotificationClient = NULL; | 267 fNotificationClient = NULL; |
266 fImmediateCanvas = NULL; | 268 fImmediateCanvas = NULL; |
267 fSurface = NULL; | 269 fSurface = NULL; |
268 this->setSurface(surface); | 270 this->setSurface(surface); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0, | 303 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0, |
302 immediateDevice()->width(), immediateDevice()->height()); | 304 immediateDevice()->width(), immediateDevice()->height()); |
303 } | 305 } |
304 | 306 |
305 void SkDeferredDevice::setNotificationClient( | 307 void SkDeferredDevice::setNotificationClient( |
306 SkDeferredCanvas::NotificationClient* notificationClient) { | 308 SkDeferredCanvas::NotificationClient* notificationClient) { |
307 fNotificationClient = notificationClient; | 309 fNotificationClient = notificationClient; |
308 } | 310 } |
309 | 311 |
310 void SkDeferredDevice::skipPendingCommands() { | 312 void SkDeferredDevice::skipPendingCommands() { |
311 if (!fRecordingCanvas->isDrawingToLayer()) { | 313 if (!fIsDrawingToLayer) { |
312 fCanDiscardCanvasContents = true; | 314 fCanDiscardCanvasContents = true; |
313 if (fPipeController.hasPendingCommands()) { | 315 if (fPipeController.hasPendingCommands()) { |
314 fFreshFrame = true; | 316 fFreshFrame = true; |
315 flushPendingCommands(kSilent_PlaybackMode); | 317 flushPendingCommands(kSilent_PlaybackMode); |
316 } | 318 } |
317 } | 319 } |
318 } | 320 } |
319 | 321 |
320 bool SkDeferredDevice::isFreshFrame() { | 322 bool SkDeferredDevice::isFreshFrame() { |
321 bool ret = fFreshFrame; | 323 bool ret = fFreshFrame; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 517 |
516 SkDeferredCanvas::SkDeferredCanvas(SkDeferredDevice* device) : SkCanvas (device)
{ | 518 SkDeferredCanvas::SkDeferredCanvas(SkDeferredDevice* device) : SkCanvas (device)
{ |
517 this->init(); | 519 this->init(); |
518 } | 520 } |
519 | 521 |
520 void SkDeferredCanvas::init() { | 522 void SkDeferredCanvas::init() { |
521 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; | 523 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; |
522 fDeferredDrawing = true; // On by default | 524 fDeferredDrawing = true; // On by default |
523 fCachedCanvasSize.setEmpty(); | 525 fCachedCanvasSize.setEmpty(); |
524 fCachedCanvasSizeDirty = true; | 526 fCachedCanvasSizeDirty = true; |
| 527 fSaveLevel = 0; |
525 } | 528 } |
526 | 529 |
527 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { | 530 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { |
528 this->validate(); | 531 this->validate(); |
529 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage); | 532 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage); |
530 } | 533 } |
531 | 534 |
532 size_t SkDeferredCanvas::storageAllocatedForRecording() const { | 535 size_t SkDeferredCanvas::storageAllocatedForRecording() const { |
533 return this->getDeferredDevice()->storageAllocatedForRecording(); | 536 return this->getDeferredDevice()->storageAllocatedForRecording(); |
534 } | 537 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) { | 669 transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) { |
667 return false; | 670 return false; |
668 } | 671 } |
669 } | 672 } |
670 | 673 |
671 return this->getClipStack()->quickContains(SkRect::MakeXYWH(0, 0, | 674 return this->getClipStack()->quickContains(SkRect::MakeXYWH(0, 0, |
672 SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight))); | 675 SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight))); |
673 } | 676 } |
674 | 677 |
675 void SkDeferredCanvas::willSave() { | 678 void SkDeferredCanvas::willSave() { |
| 679 fSaveLevel++; |
676 this->drawingCanvas()->save(); | 680 this->drawingCanvas()->save(); |
677 this->recordedDrawCommand(); | 681 this->recordedDrawCommand(); |
678 this->INHERITED::willSave(); | 682 this->INHERITED::willSave(); |
679 } | 683 } |
680 | 684 |
681 SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds
, | 685 SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds
, |
682 const SkPaint* paint
, SaveFlags flags) { | 686 const SkPaint* paint
, SaveFlags flags) { |
| 687 fSaveLevel++; |
| 688 fSaveLayerStack.push(fSaveLevel); |
| 689 this->getDeferredDevice()->setIsDrawingToLayer(true); |
683 this->drawingCanvas()->saveLayer(bounds, paint, flags); | 690 this->drawingCanvas()->saveLayer(bounds, paint, flags); |
684 this->recordedDrawCommand(); | 691 this->recordedDrawCommand(); |
685 this->INHERITED::willSaveLayer(bounds, paint, flags); | 692 this->INHERITED::willSaveLayer(bounds, paint, flags); |
686 // No need for a full layer. | 693 // No need for a full layer. |
687 return kNoLayer_SaveLayerStrategy; | 694 return kNoLayer_SaveLayerStrategy; |
688 } | 695 } |
689 | 696 |
690 void SkDeferredCanvas::willRestore() { | 697 void SkDeferredCanvas::willRestore() { |
| 698 SkASSERT(fSaveLayerStack.isEmpty() || fSaveLayerStack.top() <= fSaveLevel); |
| 699 if (!fSaveLayerStack.isEmpty() && fSaveLayerStack.top() == fSaveLevel) { |
| 700 fSaveLayerStack.pop(); |
| 701 if (fSaveLayerStack.isEmpty()) |
| 702 { |
| 703 this->getDeferredDevice()->setIsDrawingToLayer(false); |
| 704 } |
| 705 } |
691 this->drawingCanvas()->restore(); | 706 this->drawingCanvas()->restore(); |
692 this->recordedDrawCommand(); | 707 this->recordedDrawCommand(); |
693 this->INHERITED::willRestore(); | 708 this->INHERITED::willRestore(); |
694 } | 709 } |
695 | 710 |
696 bool SkDeferredCanvas::isDrawingToLayer() const { | |
697 return this->drawingCanvas()->isDrawingToLayer(); | |
698 } | |
699 | |
700 void SkDeferredCanvas::didConcat(const SkMatrix& matrix) { | 711 void SkDeferredCanvas::didConcat(const SkMatrix& matrix) { |
701 this->drawingCanvas()->concat(matrix); | 712 this->drawingCanvas()->concat(matrix); |
702 this->recordedDrawCommand(); | 713 this->recordedDrawCommand(); |
703 this->INHERITED::didConcat(matrix); | 714 this->INHERITED::didConcat(matrix); |
704 } | 715 } |
705 | 716 |
706 void SkDeferredCanvas::didSetMatrix(const SkMatrix& matrix) { | 717 void SkDeferredCanvas::didSetMatrix(const SkMatrix& matrix) { |
707 this->drawingCanvas()->setMatrix(matrix); | 718 this->drawingCanvas()->setMatrix(matrix); |
708 this->recordedDrawCommand(); | 719 this->recordedDrawCommand(); |
709 this->INHERITED::didSetMatrix(matrix); | 720 this->INHERITED::didSetMatrix(matrix); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { | 932 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { |
922 this->drawingCanvas()->setDrawFilter(filter); | 933 this->drawingCanvas()->setDrawFilter(filter); |
923 this->INHERITED::setDrawFilter(filter); | 934 this->INHERITED::setDrawFilter(filter); |
924 this->recordedDrawCommand(); | 935 this->recordedDrawCommand(); |
925 return filter; | 936 return filter; |
926 } | 937 } |
927 | 938 |
928 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { | 939 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { |
929 return this->drawingCanvas(); | 940 return this->drawingCanvas(); |
930 } | 941 } |
OLD | NEW |