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: src/utils/SkDeferredCanvas.cpp

Issue 803913005: Remove SkCanvas::isDrawingToLayer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: init fix 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);
269 this->init(); 273 this->init();
270 } 274 }
271 275
272 void SkDeferredDevice::setSurface(SkSurface* surface) { 276 void SkDeferredDevice::setSurface(SkSurface* surface) {
273 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas()); 277 SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas());
274 SkRefCnt_SafeAssign(fSurface, surface); 278 SkRefCnt_SafeAssign(fSurface, surface);
275 fPipeController.setPlaybackCanvas(fImmediateCanvas); 279 fPipeController.setPlaybackCanvas(fImmediateCanvas);
276 } 280 }
277 281
278 void SkDeferredDevice::init() { 282 void SkDeferredDevice::init() {
279 fRecordingCanvas = NULL; 283 fRecordingCanvas = NULL;
280 fFreshFrame = true; 284 fFreshFrame = true;
285 fIsDrawingToLayer = false;
281 fCanDiscardCanvasContents = false; 286 fCanDiscardCanvasContents = false;
282 fPreviousStorageAllocated = 0; 287 fPreviousStorageAllocated = 0;
283 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes; 288 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
284 fNotificationClient = NULL; 289 fNotificationClient = NULL;
285 this->beginRecording(); 290 this->beginRecording();
286 } 291 }
287 292
288 SkDeferredDevice::~SkDeferredDevice() { 293 SkDeferredDevice::~SkDeferredDevice() {
289 this->flushPendingCommands(kSilent_PlaybackMode); 294 this->flushPendingCommands(kSilent_PlaybackMode);
290 SkSafeUnref(fImmediateCanvas); 295 SkSafeUnref(fImmediateCanvas);
(...skipping 10 matching lines...) Expand all
301 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0, 306 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0,
302 immediateDevice()->width(), immediateDevice()->height()); 307 immediateDevice()->width(), immediateDevice()->height());
303 } 308 }
304 309
305 void SkDeferredDevice::setNotificationClient( 310 void SkDeferredDevice::setNotificationClient(
306 SkDeferredCanvas::NotificationClient* notificationClient) { 311 SkDeferredCanvas::NotificationClient* notificationClient) {
307 fNotificationClient = notificationClient; 312 fNotificationClient = notificationClient;
308 } 313 }
309 314
310 void SkDeferredDevice::skipPendingCommands() { 315 void SkDeferredDevice::skipPendingCommands() {
311 if (!fRecordingCanvas->isDrawingToLayer()) { 316 if (!fIsDrawingToLayer) {
312 fCanDiscardCanvasContents = true; 317 fCanDiscardCanvasContents = true;
313 if (fPipeController.hasPendingCommands()) { 318 if (fPipeController.hasPendingCommands()) {
314 fFreshFrame = true; 319 fFreshFrame = true;
315 flushPendingCommands(kSilent_PlaybackMode); 320 flushPendingCommands(kSilent_PlaybackMode);
316 } 321 }
317 } 322 }
318 } 323 }
319 324
320 bool SkDeferredDevice::isFreshFrame() { 325 bool SkDeferredDevice::isFreshFrame() {
321 bool ret = fFreshFrame; 326 bool ret = fFreshFrame;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 520
516 SkDeferredCanvas::SkDeferredCanvas(SkDeferredDevice* device) : SkCanvas (device) { 521 SkDeferredCanvas::SkDeferredCanvas(SkDeferredDevice* device) : SkCanvas (device) {
517 this->init(); 522 this->init();
518 } 523 }
519 524
520 void SkDeferredCanvas::init() { 525 void SkDeferredCanvas::init() {
521 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold; 526 fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold;
522 fDeferredDrawing = true; // On by default 527 fDeferredDrawing = true; // On by default
523 fCachedCanvasSize.setEmpty(); 528 fCachedCanvasSize.setEmpty();
524 fCachedCanvasSizeDirty = true; 529 fCachedCanvasSizeDirty = true;
530 fSaveLevel = 0;
531 fFirstSaveLayerIndex = kNoSaveLayerIndex;
525 } 532 }
526 533
527 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) { 534 void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) {
528 this->validate(); 535 this->validate();
529 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage); 536 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage);
530 } 537 }
531 538
532 size_t SkDeferredCanvas::storageAllocatedForRecording() const { 539 size_t SkDeferredCanvas::storageAllocatedForRecording() const {
533 return this->getDeferredDevice()->storageAllocatedForRecording(); 540 return this->getDeferredDevice()->storageAllocatedForRecording();
534 } 541 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) { 673 transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) {
667 return false; 674 return false;
668 } 675 }
669 } 676 }
670 677
671 return this->getClipStack()->quickContains(SkRect::MakeXYWH(0, 0, 678 return this->getClipStack()->quickContains(SkRect::MakeXYWH(0, 0,
672 SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight))); 679 SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight)));
673 } 680 }
674 681
675 void SkDeferredCanvas::willSave() { 682 void SkDeferredCanvas::willSave() {
683 fSaveLevel++;
676 this->drawingCanvas()->save(); 684 this->drawingCanvas()->save();
677 this->recordedDrawCommand(); 685 this->recordedDrawCommand();
678 this->INHERITED::willSave(); 686 this->INHERITED::willSave();
679 } 687 }
680 688
681 SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds , 689 SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds ,
682 const SkPaint* paint , SaveFlags flags) { 690 const SkPaint* paint , SaveFlags flags) {
691 fSaveLevel++;
692 if (fFirstSaveLayerIndex == kNoSaveLayerIndex) {
693 fFirstSaveLayerIndex = fSaveLevel;
694 this->getDeferredDevice()->setIsDrawingToLayer(true);
695 }
683 this->drawingCanvas()->saveLayer(bounds, paint, flags); 696 this->drawingCanvas()->saveLayer(bounds, paint, flags);
684 this->recordedDrawCommand(); 697 this->recordedDrawCommand();
685 this->INHERITED::willSaveLayer(bounds, paint, flags); 698 this->INHERITED::willSaveLayer(bounds, paint, flags);
686 // No need for a full layer. 699 // No need for a full layer.
687 return kNoLayer_SaveLayerStrategy; 700 return kNoLayer_SaveLayerStrategy;
688 } 701 }
689 702
690 void SkDeferredCanvas::willRestore() { 703 void SkDeferredCanvas::willRestore() {
704 SkASSERT(fFirstSaveLayerIndex == kNoSaveLayerIndex || fFirstSaveLayerIndex < = fSaveLevel);
705 if (fFirstSaveLayerIndex == fSaveLevel) {
706 fFirstSaveLayerIndex = kNoSaveLayerIndex;
707 this->getDeferredDevice()->setIsDrawingToLayer(false);
708 }
709 fSaveLevel--;
691 this->drawingCanvas()->restore(); 710 this->drawingCanvas()->restore();
692 this->recordedDrawCommand(); 711 this->recordedDrawCommand();
693 this->INHERITED::willRestore(); 712 this->INHERITED::willRestore();
694 } 713 }
695 714
696 bool SkDeferredCanvas::isDrawingToLayer() const {
697 return this->drawingCanvas()->isDrawingToLayer();
698 }
699
700 void SkDeferredCanvas::didConcat(const SkMatrix& matrix) { 715 void SkDeferredCanvas::didConcat(const SkMatrix& matrix) {
701 this->drawingCanvas()->concat(matrix); 716 this->drawingCanvas()->concat(matrix);
702 this->recordedDrawCommand(); 717 this->recordedDrawCommand();
703 this->INHERITED::didConcat(matrix); 718 this->INHERITED::didConcat(matrix);
704 } 719 }
705 720
706 void SkDeferredCanvas::didSetMatrix(const SkMatrix& matrix) { 721 void SkDeferredCanvas::didSetMatrix(const SkMatrix& matrix) {
707 this->drawingCanvas()->setMatrix(matrix); 722 this->drawingCanvas()->setMatrix(matrix);
708 this->recordedDrawCommand(); 723 this->recordedDrawCommand();
709 this->INHERITED::didSetMatrix(matrix); 724 this->INHERITED::didSetMatrix(matrix);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) { 936 SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
922 this->drawingCanvas()->setDrawFilter(filter); 937 this->drawingCanvas()->setDrawFilter(filter);
923 this->INHERITED::setDrawFilter(filter); 938 this->INHERITED::setDrawFilter(filter);
924 this->recordedDrawCommand(); 939 this->recordedDrawCommand();
925 return filter; 940 return filter;
926 } 941 }
927 942
928 SkCanvas* SkDeferredCanvas::canvasForDrawIter() { 943 SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
929 return this->drawingCanvas(); 944 return this->drawingCanvas();
930 } 945 }
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