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

Unified Diff: src/core/SkCanvas.cpp

Issue 798593003: Revert of Defer saves() until they're needed (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkCanvas.h ('k') | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkCanvas.cpp
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 294562ad92356d78e716ee44cd0c32aa66ea0956..083a8ed7e8a8cea5ccb505b1d6a3537a8ed95fd7 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -170,6 +170,8 @@
*/
class SkCanvas::MCRec {
public:
+ SkRasterClip fRasterClip;
+ SkMatrix fMatrix;
SkDrawFilter* fFilter; // the current filter (or null)
DeviceCM* fLayer;
/* If there are any layers in the stack, this points to the top-most
@@ -178,26 +180,22 @@
reference counted, since the real owner is either our fLayer field,
or a previous one in a lower level.)
*/
- DeviceCM* fTopLayer;
- SkRasterClip fRasterClip;
- SkMatrix fMatrix;
- int fDeferredSaveCount;
+ DeviceCM* fTopLayer;
MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) {
+ fMatrix.reset();
fFilter = NULL;
fLayer = NULL;
fTopLayer = NULL;
- fMatrix.reset();
- fDeferredSaveCount = 0;
// don't bother initializing fNext
inc_rec();
}
- MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatrix) {
+ MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip) {
+ fMatrix = prev.fMatrix;
fFilter = SkSafeRef(prev.fFilter);
fLayer = NULL;
fTopLayer = prev.fTopLayer;
- fDeferredSaveCount = 0;
// don't bother initializing fNext
inc_rec();
@@ -415,7 +413,6 @@
fAllowSoftClip = true;
fAllowSimplifyClip = false;
fDeviceCMDirty = true;
- fSaveCount = 1;
fSaveLayerCount = 0;
fCullCount = 0;
fMetaData = NULL;
@@ -788,54 +785,21 @@
///////////////////////////////////////////////////////////////////////////////
-void SkCanvas::checkForDeferredSave() {
- if (fMCRec->fDeferredSaveCount > 0) {
- fMCRec->fDeferredSaveCount -= 1;
- this->doSave();
- }
-}
-
int SkCanvas::getSaveCount() const {
-#ifdef SK_DEBUG
- int count = 0;
- SkDeque::Iter iter(fMCStack, SkDeque::Iter::kFront_IterStart);
- for (;;) {
- const MCRec* rec = (const MCRec*)iter.next();
- if (!rec) {
- break;
- }
- count += 1 + rec->fDeferredSaveCount;
- }
- SkASSERT(count == fSaveCount);
-#endif
- return fSaveCount;
+ return fMCStack.count();
}
int SkCanvas::save() {
- fSaveCount += 1;
- fMCRec->fDeferredSaveCount += 1;
- return this->getSaveCount() - 1; // return our prev value
-}
-
-void SkCanvas::doSave() {
this->willSave();
- this->internalSave();
+ return this->internalSave();
}
void SkCanvas::restore() {
- if (fMCRec->fDeferredSaveCount > 0) {
- SkASSERT(fSaveCount > 1);
- fSaveCount -= 1;
- fMCRec->fDeferredSaveCount -= 1;
- } else {
- // check for underflow
- if (fMCStack.count() > 1) {
- this->willRestore();
- SkASSERT(fSaveCount > 1);
- fSaveCount -= 1;
- this->internalRestore();
- this->didRestore();
- }
+ // check for underflow
+ if (fMCStack.count() > 1) {
+ this->willRestore();
+ this->internalRestore();
+ this->didRestore();
}
}
@@ -851,12 +815,16 @@
}
}
-void SkCanvas::internalSave() {
+int SkCanvas::internalSave() {
+ int saveCount = this->getSaveCount(); // record this before the actual save
+
MCRec* newTop = (MCRec*)fMCStack.push_back();
new (newTop) MCRec(*fMCRec); // balanced in restore()
fMCRec = newTop;
fClipStack.save();
+
+ return saveCount;
}
static bool bounds_affects_clip(SkCanvas::SaveFlags flags) {
@@ -913,19 +881,16 @@
int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) {
SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag);
- fSaveCount += 1;
- this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, false, strategy);
- return this->getSaveCount() - 1;
-}
-
-int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags) {
+ return this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, false, strategy);
+}
+
+int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags) {
SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags);
- fSaveCount += 1;
- this->internalSaveLayer(bounds, paint, flags, false, strategy);
- return this->getSaveCount() - 1;
-}
-
-void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags,
+ return this->internalSaveLayer(bounds, paint, flags, false, strategy);
+}
+
+int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags,
bool justForImageFilter, SaveLayerStrategy strategy) {
#ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
flags |= kClipToLayer_SaveFlag;
@@ -933,19 +898,19 @@
// do this before we create the layer. We don't call the public save() since
// that would invoke a possibly overridden virtual
- this->internalSave();
+ int count = this->internalSave();
fDeviceCMDirty = true;
SkIRect ir;
if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter() : NULL)) {
- return;
+ return count;
}
// FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about
// the clipRectBounds() call above?
if (kNoLayer_SaveLayerStrategy == strategy) {
- return;
+ return count;
}
// Kill the imagefilter if our device doesn't allow it
@@ -954,7 +919,7 @@
if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) {
if (justForImageFilter) {
// early exit if the layer was just for the imageFilter
- return;
+ return count;
}
SkPaint* p = lazyP.set(*paint);
p->setImageFilter(NULL);
@@ -969,7 +934,7 @@
SkBaseDevice* device = this->getTopDevice();
if (NULL == device) {
SkDebugf("Unable to find device for layer.");
- return;
+ return count;
}
SkBaseDevice::Usage usage = SkBaseDevice::kSaveLayer_Usage;
@@ -980,7 +945,7 @@
fProps.pixelGeometry()));
if (NULL == device) {
SkDebugf("Unable to create device for layer.");
- return;
+ return count;
}
device->setOrigin(ir.fLeft, ir.fTop);
@@ -993,6 +958,7 @@
fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
fSaveLayerCount += 1;
+ return count;
}
int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
@@ -1149,7 +1115,6 @@
#endif
void SkCanvas::pushCull(const SkRect& cullRect) {
- this->checkForDeferredSave();
++fCullCount;
this->onPushCull(cullRect);
@@ -1321,7 +1286,6 @@
return;
}
- this->checkForDeferredSave();
fDeviceCMDirty = true;
fCachedLocalClipBoundsDirty = true;
fMCRec->fMatrix.preConcat(matrix);
@@ -1330,7 +1294,6 @@
}
void SkCanvas::setMatrix(const SkMatrix& matrix) {
- this->checkForDeferredSave();
fDeviceCMDirty = true;
fCachedLocalClipBoundsDirty = true;
fMCRec->fMatrix = matrix;
@@ -1347,7 +1310,6 @@
//////////////////////////////////////////////////////////////////////////////
void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
- this->checkForDeferredSave();
ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
this->onClipRect(rect, op, edgeStyle);
}
@@ -1405,7 +1367,6 @@
}
void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
- this->checkForDeferredSave();
ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
if (rrect.isRect()) {
this->onClipRect(rrect.getBounds(), op, edgeStyle);
@@ -1441,7 +1402,6 @@
}
void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
- this->checkForDeferredSave();
ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
SkRect r;
if (!path.isInverseFillType() && path.isRect(&r)) {
@@ -1524,7 +1484,6 @@
}
void SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) {
- this->checkForDeferredSave();
this->onClipRegion(rgn, op);
}
« no previous file with comments | « include/core/SkCanvas.h ('k') | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698