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

Side by Side Diff: src/utils/SkDeferredCanvas.cpp

Issue 803913005: Remove SkCanvas::isDrawingToLayer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: moar moar cleanup Created 6 years 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
« no previous file with comments | « src/pipe/SkGPipeWrite.cpp ('k') | tests/CanvasTest.cpp » ('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 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
11 #include "SkBitmapDevice.h" 11 #include "SkBitmapDevice.h"
12 #include "SkChunkAlloc.h" 12 #include "SkChunkAlloc.h"
13 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
14 #include "SkDrawFilter.h" 14 #include "SkDrawFilter.h"
15 #include "SkGPipe.h" 15 #include "SkGPipe.h"
16 #include "SkPaint.h" 16 #include "SkPaint.h"
17 #include "SkPaintPriv.h" 17 #include "SkPaintPriv.h"
18 #include "SkRRect.h" 18 #include "SkRRect.h"
19 #include "SkShader.h" 19 #include "SkShader.h"
20 #include "SkSurface.h" 20 #include "SkSurface.h"
21 21
22 enum { 22 enum {
23 // Deferred canvas will auto-flush when recording reaches this limit 23 // Deferred canvas will auto-flush when recording reaches this limit
24 kDefaultMaxRecordingStorageBytes = 64*1024*1024, 24 kDefaultMaxRecordingStorageBytes = 64*1024*1024,
25 kDeferredCanvasBitmapSizeThreshold = ~0U, // Disables this feature 25 kDeferredCanvasBitmapSizeThreshold = ~0U, // Disables this feature
26
27 kNoSaveLayerIndex = -1,
26 }; 28 };
27 29
28 enum PlaybackMode { 30 enum PlaybackMode {
29 kNormal_PlaybackMode, 31 kNormal_PlaybackMode,
30 kSilent_PlaybackMode, 32 kSilent_PlaybackMode,
31 }; 33 };
32 34
33 static bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint , 35 static bool should_draw_immediately(const SkBitmap* bitmap, const SkPaint* paint ,
34 size_t bitmapSizeThreshold) { 36 size_t bitmapSizeThreshold) {
35 if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) || 37 if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) ||
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 SkImage* newImageSnapshot(); 149 SkImage* newImageSnapshot();
148 void setSurface(SkSurface* surface); 150 void setSurface(SkSurface* surface);
149 bool isFreshFrame(); 151 bool isFreshFrame();
150 bool hasPendingCommands(); 152 bool hasPendingCommands();
151 size_t storageAllocatedForRecording() const; 153 size_t storageAllocatedForRecording() const;
152 size_t freeMemoryIfPossible(size_t bytesToFree); 154 size_t freeMemoryIfPossible(size_t bytesToFree);
153 void flushPendingCommands(PlaybackMode); 155 void flushPendingCommands(PlaybackMode);
154 void skipPendingCommands(); 156 void skipPendingCommands();
155 void setMaxRecordingStorage(size_t); 157 void setMaxRecordingStorage(size_t);
156 void recordedDrawCommand(); 158 void recordedDrawCommand();
159 void setIsDrawingToLayer(bool value) {fIsDrawingToLayer = value;}
157 160
158 virtual SkImageInfo imageInfo() const SK_OVERRIDE; 161 virtual SkImageInfo imageInfo() const SK_OVERRIDE;
159 162
160 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE; 163 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE;
161 164
162 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRID E; 165 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRID E;
163 166
164 virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_ OVERRIDE; 167 virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_ OVERRIDE;
165 168
166 protected: 169 protected:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 void prepareForImmediatePixelWrite(); 252 void prepareForImmediatePixelWrite();
250 253
251 DeferredPipeController fPipeController; 254 DeferredPipeController fPipeController;
252 SkGPipeWriter fPipeWriter; 255 SkGPipeWriter fPipeWriter;
253 SkCanvas* fImmediateCanvas; 256 SkCanvas* fImmediateCanvas;
254 SkCanvas* fRecordingCanvas; 257 SkCanvas* fRecordingCanvas;
255 SkSurface* fSurface; 258 SkSurface* fSurface;
256 SkDeferredCanvas::NotificationClient* fNotificationClient; 259 SkDeferredCanvas::NotificationClient* fNotificationClient;
257 bool fFreshFrame; 260 bool fFreshFrame;
258 bool fCanDiscardCanvasContents; 261 bool fCanDiscardCanvasContents;
262 bool fIsDrawingToLayer;
259 size_t fMaxRecordingStorageBytes; 263 size_t fMaxRecordingStorageBytes;
260 size_t fPreviousStorageAllocated; 264 size_t fPreviousStorageAllocated;
261 }; 265 };
262 266
263 SkDeferredDevice::SkDeferredDevice(SkSurface* surface) { 267 SkDeferredDevice::SkDeferredDevice(SkSurface* surface) {
264 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; 268 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
265 fNotificationClient = NULL; 269 fNotificationClient = NULL;
266 fImmediateCanvas = NULL; 270 fImmediateCanvas = NULL;
267 fSurface = NULL; 271 fSurface = NULL;
268 this->setSurface(surface); 272 this->setSurface(surface);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0, 305 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0,
302 immediateDevice()->width(), immediateDevice()->height()); 306 immediateDevice()->width(), immediateDevice()->height());
303 } 307 }
304 308
305 void SkDeferredDevice::setNotificationClient( 309 void SkDeferredDevice::setNotificationClient(
306 SkDeferredCanvas::NotificationClient* notificationClient) { 310 SkDeferredCanvas::NotificationClient* notificationClient) {
307 fNotificationClient = notificationClient; 311 fNotificationClient = notificationClient;
308 } 312 }
309 313
310 void SkDeferredDevice::skipPendingCommands() { 314 void SkDeferredDevice::skipPendingCommands() {
311 if (!fRecordingCanvas->isDrawingToLayer()) { 315 if (!fIsDrawingToLayer) {
312 fCanDiscardCanvasContents = true; 316 fCanDiscardCanvasContents = true;
313 if (fPipeController.hasPendingCommands()) { 317 if (fPipeController.hasPendingCommands()) {
314 fFreshFrame = true; 318 fFreshFrame = true;
315 flushPendingCommands(kSilent_PlaybackMode); 319 flushPendingCommands(kSilent_PlaybackMode);
316 } 320 }
317 } 321 }
318 } 322 }
319 323
320 bool SkDeferredDevice::isFreshFrame() { 324 bool SkDeferredDevice::isFreshFrame() {
321 bool ret = fFreshFrame; 325 bool ret = fFreshFrame;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 519
516 SkDeferredCanvas::SkDeferredCanvas(SkDeferredDevice* device) : SkCanvas (device) { 520 SkDeferredCanvas::SkDeferredCanvas(SkDeferredDevice* device) : SkCanvas (device) {
517 this->init(); 521 this->init();
518 } 522 }
519 523
520 void SkDeferredCanvas::init() { 524 void SkDeferredCanvas::init() {
521 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; 525 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold;
522 fDeferredDrawing = true; // On by default 526 fDeferredDrawing = true; // On by default
523 fCachedCanvasSize.setEmpty(); 527 fCachedCanvasSize.setEmpty();
524 fCachedCanvasSizeDirty = true; 528 fCachedCanvasSizeDirty = true;
529 fSaveLevel = 0;
530 fFirstSaveLayerIndex = kNoSaveLayerIndex;
525 } 531 }
526 532
527 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { 533 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) {
528 this->validate(); 534 this->validate();
529 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage); 535 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage);
530 } 536 }
531 537
532 size_t SkDeferredCanvas::storageAllocatedForRecording() const { 538 size_t SkDeferredCanvas::storageAllocatedForRecording() const {
533 return this->getDeferredDevice()->storageAllocatedForRecording(); 539 return this->getDeferredDevice()->storageAllocatedForRecording();
534 } 540 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) { 672 transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) {
667 return false; 673 return false;
668 } 674 }
669 } 675 }
670 676
671 return this->getClipStack()->quickContains(SkRect::MakeXYWH(0, 0, 677 return this->getClipStack()->quickContains(SkRect::MakeXYWH(0, 0,
672 SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight))); 678 SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight)));
673 } 679 }
674 680
675 void SkDeferredCanvas::willSave() { 681 void SkDeferredCanvas::willSave() {
682 fSaveLevel++;
676 this->drawingCanvas()->save(); 683 this->drawingCanvas()->save();
677 this->recordedDrawCommand(); 684 this->recordedDrawCommand();
678 this->INHERITED::willSave(); 685 this->INHERITED::willSave();
679 } 686 }
680 687
681 SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds , 688 SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds ,
682 const SkPaint* paint , SaveFlags flags) { 689 const SkPaint* paint , SaveFlags flags) {
690 fSaveLevel++;
691 if (fFirstSaveLayerIndex == kNoSaveLayerIndex) {
mtklein 2014/12/15 19:05:25 It was neat to learn this doesn't need a stack, hu
692 fFirstSaveLayerIndex = fSaveLevel;
693 this->getDeferredDevice()->setIsDrawingToLayer(true);
694 }
683 this->drawingCanvas()->saveLayer(bounds, paint, flags); 695 this->drawingCanvas()->saveLayer(bounds, paint, flags);
684 this->recordedDrawCommand(); 696 this->recordedDrawCommand();
685 this->INHERITED::willSaveLayer(bounds, paint, flags); 697 this->INHERITED::willSaveLayer(bounds, paint, flags);
686 // No need for a full layer. 698 // No need for a full layer.
687 return kNoLayer_SaveLayerStrategy; 699 return kNoLayer_SaveLayerStrategy;
688 } 700 }
689 701
690 void SkDeferredCanvas::willRestore() { 702 void SkDeferredCanvas::willRestore() {
703 SkASSERT(fFirstSaveLayerIndex == kNoSaveLayerIndex || fFirstSaveLayerIndex < = fSaveLevel);
704 if (fFirstSaveLayerIndex == fSaveLevel) {
705 fFirstSaveLayerIndex = kNoSaveLayerIndex;
706 this->getDeferredDevice()->setIsDrawingToLayer(false);
707 }
708 fSaveLevel--;
691 this->drawingCanvas()->restore(); 709 this->drawingCanvas()->restore();
692 this->recordedDrawCommand(); 710 this->recordedDrawCommand();
693 this->INHERITED::willRestore(); 711 this->INHERITED::willRestore();
694 } 712 }
695 713
696 bool SkDeferredCanvas::isDrawingToLayer() const {
697 return this->drawingCanvas()->isDrawingToLayer();
698 }
699
700 void SkDeferredCanvas::didConcat(const SkMatrix& matrix) { 714 void SkDeferredCanvas::didConcat(const SkMatrix& matrix) {
701 this->drawingCanvas()->concat(matrix); 715 this->drawingCanvas()->concat(matrix);
702 this->recordedDrawCommand(); 716 this->recordedDrawCommand();
703 this->INHERITED::didConcat(matrix); 717 this->INHERITED::didConcat(matrix);
704 } 718 }
705 719
706 void SkDeferredCanvas::didSetMatrix(const SkMatrix& matrix) { 720 void SkDeferredCanvas::didSetMatrix(const SkMatrix& matrix) {
707 this->drawingCanvas()->setMatrix(matrix); 721 this->drawingCanvas()->setMatrix(matrix);
708 this->recordedDrawCommand(); 722 this->recordedDrawCommand();
709 this->INHERITED::didSetMatrix(matrix); 723 this->INHERITED::didSetMatrix(matrix);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { 935 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
922 this->drawingCanvas()->setDrawFilter(filter); 936 this->drawingCanvas()->setDrawFilter(filter);
923 this->INHERITED::setDrawFilter(filter); 937 this->INHERITED::setDrawFilter(filter);
924 this->recordedDrawCommand(); 938 this->recordedDrawCommand();
925 return filter; 939 return filter;
926 } 940 }
927 941
928 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { 942 SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
929 return this->drawingCanvas(); 943 return this->drawingCanvas();
930 } 944 }
OLDNEW
« no previous file with comments | « src/pipe/SkGPipeWrite.cpp ('k') | tests/CanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698