Revert of Revert "De-virtualize SkCanvas save/restore." (https://codereview.chromium.org/194923008/)

Reason for revert:
Re-landing after roll fix.

Original issue's description:
> Revert "De-virtualize SkCanvas save/restore."
>
> (To allow a roll fix into the tree).
>
> This reverts commit edf702204be42c945254191f9f9cd6585b3d189b.
>
> R=halcanary@google.com
>
> Committed: https://code.google.com/p/skia/source/detail?r=13748

R=halcanary@google.com, fmalita@chromium.org
TBR=fmalita@chromium.org, halcanary@google.com
NOTREECHECKS=true
NOTRY=true

Author: fmalita@google.com

Review URL: https://codereview.chromium.org/196323003

git-svn-id: http://skia.googlecode.com/svn/trunk@13754 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-03-11 23:47:35 +00:00
parent ab373bd459
commit 4fcd92d0bf
21 changed files with 177 additions and 147 deletions

View File

@ -26,13 +26,6 @@ public:
explicit SkNulCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap) {} explicit SkNulCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap) {}
virtual ~SkNulCanvas() {} virtual ~SkNulCanvas() {}
virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) SK_OVERRIDE {return 0;}
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags = kARGB_ClipLayer_SaveFlag) SK_OVERRIDE {return 0;}
int saveLayerAlpha(const SkRect* bounds, U8CPU alpha,
SaveFlags flags = kARGB_ClipLayer_SaveFlag) {return 0;}
virtual void restore() SK_OVERRIDE {}
int getSaveCount() const {return 0;}
virtual bool isDrawingToLayer() const SK_OVERRIDE {return false;} virtual bool isDrawingToLayer() const SK_OVERRIDE {return false;}
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE {return true;} virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE {return true;}
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE {return true;} virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE {return true;}
@ -106,6 +99,12 @@ protected:
virtual SkCanvas* canvasForDrawIter() {return NULL;} virtual SkCanvas* canvasForDrawIter() {return NULL;}
virtual SkBaseDevice* setDevice(SkBaseDevice* device) {return NULL;} virtual SkBaseDevice* setDevice(SkBaseDevice* device) {return NULL;}
virtual bool onSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags)
SK_OVERRIDE {
this->INHERITED::onSaveLayer(bounds, paint, flags);
return false;
}
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {} virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {}
virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {} virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {}
virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {} virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {}

View File

@ -358,7 +358,7 @@ public:
by calls to save/restore. by calls to save/restore.
@return The value to pass to restoreToCount() to balance this save() @return The value to pass to restoreToCount() to balance this save()
*/ */
virtual int save(SaveFlags flags = kMatrixClip_SaveFlag); int save(SaveFlags flags = kMatrixClip_SaveFlag);
/** This behaves the same as save(), but in addition it allocates an /** This behaves the same as save(), but in addition it allocates an
offscreen bitmap. All drawing calls are directed there, and only when offscreen bitmap. All drawing calls are directed there, and only when
@ -373,8 +373,8 @@ public:
@param flags LayerFlags @param flags LayerFlags
@return The value to pass to restoreToCount() to balance this save() @return The value to pass to restoreToCount() to balance this save()
*/ */
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags = kARGB_ClipLayer_SaveFlag); SaveFlags flags = kARGB_ClipLayer_SaveFlag);
/** This behaves the same as save(), but in addition it allocates an /** This behaves the same as save(), but in addition it allocates an
offscreen bitmap. All drawing calls are directed there, and only when offscreen bitmap. All drawing calls are directed there, and only when
@ -396,7 +396,7 @@ public:
call. call.
It is an error to call restore() more times than save() was called. It is an error to call restore() more times than save() was called.
*/ */
virtual void restore(); void restore();
/** Returns the number of matrix/clip states on the SkCanvas' private stack. /** Returns the number of matrix/clip states on the SkCanvas' private stack.
This will equal # save() calls - # restore() calls + 1. The save count on This will equal # save() calls - # restore() calls + 1. The save count on
@ -1178,6 +1178,14 @@ protected:
// default impl defers to its device // default impl defers to its device
virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes);
// Subclass save/restore notifiers. These are called *before* updating the canvas state.
// Overriders should call the corresponding INHERITED method up the inheritance chain.
// For onSaveLayer(), returning false suppresses full layer allocation (and forces
// the base impl to only perform a state save + bounds clip).
virtual void onSave(SaveFlags);
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags);
virtual void onRestore();
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
enum ClipEdgeStyle { enum ClipEdgeStyle {
@ -1277,7 +1285,7 @@ private:
const SkRect& dst, const SkPaint* paint); const SkRect& dst, const SkPaint* paint);
void internalDrawPaint(const SkPaint& paint); void internalDrawPaint(const SkPaint& paint);
int internalSaveLayer(const SkRect* bounds, const SkPaint* paint, int internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags, bool justForImageFilter); SaveFlags, bool justForImageFilter, bool skipLayer);
void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
// shared by save() and saveLayer() // shared by save() and saveLayer()

View File

@ -138,10 +138,6 @@ public:
void silentFlush(); void silentFlush();
// Overrides of the SkCanvas interface // Overrides of the SkCanvas interface
virtual int save(SaveFlags flags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool isDrawingToLayer() const SK_OVERRIDE; virtual bool isDrawingToLayer() const SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
@ -193,6 +189,10 @@ public:
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE; virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE;
protected: protected:
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, virtual void onDrawDRRect(const SkRRect&, const SkRRect&,
const SkPaint&) SK_OVERRIDE; const SkPaint&) SK_OVERRIDE;

View File

@ -74,11 +74,6 @@ public:
int getNestLevel() const { return fNestLevel; } int getNestLevel() const { return fNestLevel; }
virtual int save(SaveFlags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE; virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
@ -124,6 +119,10 @@ public:
virtual void endCommentGroup() SK_OVERRIDE; virtual void endCommentGroup() SK_OVERRIDE;
protected: protected:
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE; virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
virtual void onPopCull() SK_OVERRIDE; virtual void onPopCull() SK_OVERRIDE;

View File

@ -20,11 +20,6 @@ public:
SkLuaCanvas(int width, int height, lua_State*, const char function[]); SkLuaCanvas(int width, int height, lua_State*, const char function[]);
virtual ~SkLuaCanvas(); virtual ~SkLuaCanvas();
virtual int save(SaveFlags flags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE; virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
@ -67,6 +62,10 @@ public:
virtual void drawData(const void* data, size_t length) SK_OVERRIDE; virtual void drawData(const void* data, size_t length) SK_OVERRIDE;
protected: protected:
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;

View File

@ -23,10 +23,6 @@ public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// These are forwarded to the N canvases we're referencing // These are forwarded to the N canvases we're referencing
virtual int save(SaveFlags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint*,
SaveFlags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE; virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
@ -81,6 +77,10 @@ public:
protected: protected:
SkTDArray<SkCanvas*> fList; SkTDArray<SkCanvas*> fList;
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;

View File

@ -26,11 +26,6 @@ public:
SkCanvas* getProxy() const { return fProxy; } SkCanvas* getProxy() const { return fProxy; }
void setProxy(SkCanvas* proxy); void setProxy(SkCanvas* proxy);
virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags = kARGB_ClipLayer_SaveFlag) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE; virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
@ -80,6 +75,10 @@ public:
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE; virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE;
protected: protected:
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;

View File

@ -26,20 +26,20 @@ void SkBBoxHierarchyRecord::handleBBox(const SkRect& bounds) {
fBoundingHierarchy->insert(draw, r, true); fBoundingHierarchy->insert(draw, r, true);
} }
int SkBBoxHierarchyRecord::save(SaveFlags flags) { void SkBBoxHierarchyRecord::onSave(SaveFlags flags) {
fStateTree->appendSave(); fStateTree->appendSave();
return INHERITED::save(flags); this->INHERITED::onSave(flags);
} }
int SkBBoxHierarchyRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkBBoxHierarchyRecord::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
fStateTree->appendSaveLayer(this->writeStream().bytesWritten()); fStateTree->appendSaveLayer(this->writeStream().bytesWritten());
return INHERITED::saveLayer(bounds, paint, flags); return this->INHERITED::onSaveLayer(bounds, paint, flags);
} }
void SkBBoxHierarchyRecord::restore() { void SkBBoxHierarchyRecord::onRestore() {
fStateTree->appendRestore(); fStateTree->appendRestore();
INHERITED::restore(); this->INHERITED::onRestore();
} }
bool SkBBoxHierarchyRecord::translate(SkScalar dx, SkScalar dy) { bool SkBBoxHierarchyRecord::translate(SkScalar dx, SkScalar dy) {

View File

@ -23,11 +23,6 @@ public:
virtual void handleBBox(const SkRect& bounds) SK_OVERRIDE; virtual void handleBBox(const SkRect& bounds) SK_OVERRIDE;
virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags = kARGB_ClipLayer_SaveFlag) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE; virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
@ -39,6 +34,10 @@ public:
virtual bool shouldRewind(void* data) SK_OVERRIDE; virtual bool shouldRewind(void* data) SK_OVERRIDE;
protected: protected:
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;

View File

@ -348,7 +348,7 @@ public:
SkPaint tmp; SkPaint tmp;
tmp.setImageFilter(fOrigPaint.getImageFilter()); tmp.setImageFilter(fOrigPaint.getImageFilter());
(void)canvas->internalSaveLayer(bounds, &tmp, (void)canvas->internalSaveLayer(bounds, &tmp,
SkCanvas::kARGB_ClipLayer_SaveFlag, true); SkCanvas::kARGB_ClipLayer_SaveFlag, true, false);
// we'll clear the imageFilter for the actual draws in next(), so // we'll clear the imageFilter for the actual draws in next(), so
// it will only be applied during the restore(). // it will only be applied during the restore().
fDoClearImageFilter = true; fDoClearImageFilter = true;
@ -806,7 +806,12 @@ int SkCanvas::internalSave(SaveFlags flags) {
return saveCount; return saveCount;
} }
void SkCanvas::onSave(SaveFlags) {
// Do nothing. Subclasses may do something.
}
int SkCanvas::save(SaveFlags flags) { int SkCanvas::save(SaveFlags flags) {
this->onSave(flags);
// call shared impl // call shared impl
return this->internalSave(flags); return this->internalSave(flags);
} }
@ -863,9 +868,16 @@ bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags,
return true; return true;
} }
bool SkCanvas::onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) {
// Do nothing. Subclasses may do something.
return true;
}
int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
return this->internalSaveLayer(bounds, paint, flags, false); // Overriding classes may return false to signal that we don't need to create a layer.
bool skipLayer = !this->onSaveLayer(bounds, paint, flags);
return this->internalSaveLayer(bounds, paint, flags, false, skipLayer);
} }
static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas,
@ -875,7 +887,7 @@ static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas,
} }
int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags, bool justForImageFilter) { SaveFlags flags, bool justForImageFilter, bool skipLayer) {
#ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
flags = (SaveFlags)(flags | kClipToLayer_SaveFlag); flags = (SaveFlags)(flags | kClipToLayer_SaveFlag);
#endif #endif
@ -891,6 +903,11 @@ int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
return count; return count;
} }
// FIXME: do onSaveLayer() overriders returning false really care about the clipRectBounds()
// call above?
if (skipLayer)
return count;
// Kill the imagefilter if our device doesn't allow it // Kill the imagefilter if our device doesn't allow it
SkLazyPaint lazyP; SkLazyPaint lazyP;
if (paint && paint->getImageFilter()) { if (paint && paint->getImageFilter()) {
@ -943,9 +960,14 @@ int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha,
} }
} }
void SkCanvas::onRestore() {
// Do nothing. Subclasses may do something.
}
void SkCanvas::restore() { void SkCanvas::restore() {
// check for underflow // check for underflow
if (fMCStack.count() > 1) { if (fMCStack.count() > 1) {
this->onRestore();
this->internalRestore(); this->internalRestore();
} }
} }

View File

@ -146,7 +146,7 @@ static inline uint32_t getPaintOffset(DrawType op, uint32_t opSize) {
return gPaintOffsets[op] * sizeof(uint32_t) + overflow; return gPaintOffsets[op] * sizeof(uint32_t) + overflow;
} }
int SkPictureRecord::save(SaveFlags flags) { void SkPictureRecord::onSave(SaveFlags flags) {
#ifdef SK_COLLAPSE_MATRIX_CLIP_STATE #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
fMCMgr.save(flags); fMCMgr.save(flags);
@ -156,7 +156,8 @@ int SkPictureRecord::save(SaveFlags flags) {
fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
this->recordSave(flags); this->recordSave(flags);
#endif #endif
return this->INHERITED::save(flags);
this->INHERITED::onSave(flags);
} }
void SkPictureRecord::recordSave(SaveFlags flags) { void SkPictureRecord::recordSave(SaveFlags flags) {
@ -168,12 +169,11 @@ void SkPictureRecord::recordSave(SaveFlags flags) {
this->validate(initialOffset, size); this->validate(initialOffset, size);
} }
int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkPictureRecord::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
int count;
#ifdef SK_COLLAPSE_MATRIX_CLIP_STATE #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
count = fMCMgr.saveLayer(bounds, paint, flags); fMCMgr.saveLayer(bounds, paint, flags);
#else #else
// record the offset to us, making it non-positive to distinguish a save // record the offset to us, making it non-positive to distinguish a save
// from a clip entry. // from a clip entry.
@ -184,15 +184,13 @@ int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
} }
#endif #endif
/* Don't actually call INHERITED::saveLayer, because that will try to allocate this->INHERITED::onSaveLayer(bounds, paint, flags);
an offscreen device (potentially very big) which we don't actually need /* No need for a (potentially very big) layer which we don't actually need
at this time (and may not be able to afford since during record our at this time (and may not be able to afford since during record our
clip starts out the size of the picture, which is often much larger clip starts out the size of the picture, which is often much larger
than the size of the actual device we'll use during playback). than the size of the actual device we'll use during playback).
*/ */
count = this->INHERITED::save(flags); return false;
this->clipRectBounds(bounds, flags, NULL);
return count;
} }
void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint, void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint,
@ -605,7 +603,7 @@ static void apply_optimization_to_bbh(PictureRecordOptType opt, SkPictureStateTr
} }
} }
void SkPictureRecord::restore() { void SkPictureRecord::onRestore() {
// FIXME: SkDeferredCanvas needs to be refactored to respect // FIXME: SkDeferredCanvas needs to be refactored to respect
// save/restore balancing so that the following test can be // save/restore balancing so that the following test can be
// turned on permanently. // turned on permanently.
@ -653,7 +651,7 @@ void SkPictureRecord::restore() {
fRestoreOffsetStack.pop(); fRestoreOffsetStack.pop();
#endif #endif
return this->INHERITED::restore(); this->INHERITED::onRestore();
} }
void SkPictureRecord::recordRestore(bool fillInSkips) { void SkPictureRecord::recordRestore(bool fillInSkips) {

View File

@ -37,9 +37,6 @@ public:
SkPictureRecord(const SkISize& dimensions, uint32_t recordFlags); SkPictureRecord(const SkISize& dimensions, uint32_t recordFlags);
virtual ~SkPictureRecord(); virtual ~SkPictureRecord();
virtual int save(SaveFlags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE; virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
@ -227,6 +224,11 @@ protected:
const void* onPeekPixels(SkImageInfo*, size_t*) SK_OVERRIDE { const void* onPeekPixels(SkImageInfo*, size_t*) SK_OVERRIDE {
return NULL; return NULL;
} }
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onPushCull(const SkRect&) SK_OVERRIDE; virtual void onPushCull(const SkRect&) SK_OVERRIDE;
virtual void onPopCull() SK_OVERRIDE; virtual void onPopCull() SK_OVERRIDE;

View File

@ -229,10 +229,6 @@ public:
} }
// overrides from SkCanvas // overrides from SkCanvas
virtual int save(SaveFlags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint*,
SaveFlags) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool isDrawingToLayer() const SK_OVERRIDE; virtual bool isDrawingToLayer() const SK_OVERRIDE;
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
@ -287,6 +283,10 @@ public:
bool shuttleBitmap(const SkBitmap&, int32_t slot); bool shuttleBitmap(const SkBitmap&, int32_t slot);
protected: protected:
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
@ -514,16 +514,17 @@ uint32_t SkGPipeCanvas::getTypefaceID(SkTypeface* face) {
#define NOTIFY_SETUP(canvas) \ #define NOTIFY_SETUP(canvas) \
AutoPipeNotify apn(canvas) AutoPipeNotify apn(canvas)
int SkGPipeCanvas::save(SaveFlags flags) { void SkGPipeCanvas::onSave(SaveFlags flags) {
NOTIFY_SETUP(this); NOTIFY_SETUP(this);
if (this->needOpBytes()) { if (this->needOpBytes()) {
this->writeOp(kSave_DrawOp, 0, flags); this->writeOp(kSave_DrawOp, 0, flags);
} }
return this->INHERITED::save(flags);
this->INHERITED::onSave(flags);
} }
int SkGPipeCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkGPipeCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags saveFlags) { SaveFlags saveFlags) {
NOTIFY_SETUP(this); NOTIFY_SETUP(this);
size_t size = 0; size_t size = 0;
unsigned opFlags = 0; unsigned opFlags = 0;
@ -547,21 +548,23 @@ int SkGPipeCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
if (kNoSaveLayer == fFirstSaveLayerStackLevel){ if (kNoSaveLayer == fFirstSaveLayerStackLevel){
fFirstSaveLayerStackLevel = this->getSaveCount(); fFirstSaveLayerStackLevel = this->getSaveCount();
} }
// we just pass on the save, so we don't create a layer
return this->INHERITED::save(saveFlags); this->INHERITED::onSaveLayer(bounds, paint, saveFlags);
// we don't create a layer
return false;
} }
void SkGPipeCanvas::restore() { void SkGPipeCanvas::onRestore() {
NOTIFY_SETUP(this); NOTIFY_SETUP(this);
if (this->needOpBytes()) { if (this->needOpBytes()) {
this->writeOp(kRestore_DrawOp); this->writeOp(kRestore_DrawOp);
} }
this->INHERITED::restore(); if (this->getSaveCount() - 1 == fFirstSaveLayerStackLevel){
if (this->getSaveCount() == fFirstSaveLayerStackLevel){
fFirstSaveLayerStackLevel = kNoSaveLayer; fFirstSaveLayerStackLevel = kNoSaveLayer;
} }
this->INHERITED::onRestore();
} }
bool SkGPipeCanvas::isDrawingToLayer() const { bool SkGPipeCanvas::isDrawingToLayer() const {

View File

@ -739,28 +739,25 @@ bool SkDeferredCanvas::isFullFrame(const SkRect* rect,
SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight))); SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight)));
} }
int SkDeferredCanvas::save(SaveFlags flags) { void SkDeferredCanvas::onSave(SaveFlags flags) {
this->drawingCanvas()->save(flags); this->drawingCanvas()->save(flags);
int val = this->INHERITED::save(flags);
this->recordedDrawCommand(); this->recordedDrawCommand();
this->INHERITED::onSave(flags);
return val;
} }
int SkDeferredCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkDeferredCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
this->drawingCanvas()->saveLayer(bounds, paint, flags); this->drawingCanvas()->saveLayer(bounds, paint, flags);
int count = this->INHERITED::save(flags);
this->clipRectBounds(bounds, flags, NULL);
this->recordedDrawCommand(); this->recordedDrawCommand();
this->INHERITED::onSaveLayer(bounds, paint, flags);
return count; // No need for a full layer.
return false;
} }
void SkDeferredCanvas::restore() { void SkDeferredCanvas::onRestore() {
this->drawingCanvas()->restore(); this->drawingCanvas()->restore();
this->INHERITED::restore();
this->recordedDrawCommand(); this->recordedDrawCommand();
this->INHERITED::onRestore();
} }
bool SkDeferredCanvas::isDrawingToLayer() const { bool SkDeferredCanvas::isDrawingToLayer() const {

View File

@ -192,13 +192,13 @@ void SkDumpCanvas::dump(Verb verb, const SkPaint* paint,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
int SkDumpCanvas::save(SaveFlags flags) { void SkDumpCanvas::onSave(SaveFlags flags) {
this->dump(kSave_Verb, NULL, "save(0x%X)", flags); this->dump(kSave_Verb, NULL, "save(0x%X)", flags);
return this->INHERITED::save(flags); this->INHERITED::onSave(flags);
} }
int SkDumpCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkDumpCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
SkString str; SkString str;
str.printf("saveLayer(0x%X)", flags); str.printf("saveLayer(0x%X)", flags);
if (bounds) { if (bounds) {
@ -214,12 +214,12 @@ int SkDumpCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
} }
} }
this->dump(kSave_Verb, paint, str.c_str()); this->dump(kSave_Verb, paint, str.c_str());
return this->INHERITED::saveLayer(bounds, paint, flags); return this->INHERITED::onSaveLayer(bounds, paint, flags);
} }
void SkDumpCanvas::restore() { void SkDumpCanvas::onRestore() {
this->INHERITED::restore();
this->dump(kRestore_Verb, NULL, "restore"); this->dump(kRestore_Verb, NULL, "restore");
this->INHERITED::onRestore();
} }
bool SkDumpCanvas::translate(SkScalar dx, SkScalar dy) { bool SkDumpCanvas::translate(SkScalar dx, SkScalar dy) {

View File

@ -81,13 +81,13 @@ SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[])
SkLuaCanvas::~SkLuaCanvas() {} SkLuaCanvas::~SkLuaCanvas() {}
int SkLuaCanvas::save(SaveFlags flags) { void SkLuaCanvas::onSave(SaveFlags flags) {
AUTO_LUA("save"); AUTO_LUA("save");
return this->INHERITED::save(flags); this->INHERITED::onSave(flags);
} }
int SkLuaCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkLuaCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
AUTO_LUA("saveLayer"); AUTO_LUA("saveLayer");
if (bounds) { if (bounds) {
lua.pushRect(*bounds, "bounds"); lua.pushRect(*bounds, "bounds");
@ -95,12 +95,15 @@ int SkLuaCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
if (paint) { if (paint) {
lua.pushPaint(*paint, "paint"); lua.pushPaint(*paint, "paint");
} }
return this->INHERITED::save(flags);
this->INHERITED::onSaveLayer(bounds, paint, flags);
// No need for a layer.
return false;
} }
void SkLuaCanvas::restore() { void SkLuaCanvas::onRestore() {
AUTO_LUA("restore"); AUTO_LUA("restore");
this->INHERITED::restore(); this->INHERITED::onRestore();
} }
bool SkLuaCanvas::translate(SkScalar dx, SkScalar dy) { bool SkLuaCanvas::translate(SkScalar dx, SkScalar dy) {

View File

@ -57,29 +57,33 @@ private:
SkCanvas* fCanvas; SkCanvas* fCanvas;
}; };
int SkNWayCanvas::save(SaveFlags flags) { void SkNWayCanvas::onSave(SaveFlags flags) {
Iter iter(fList); Iter iter(fList);
while (iter.next()) { while (iter.next()) {
iter->save(flags); iter->save(flags);
} }
return this->INHERITED::save(flags);
this->INHERITED::onSave(flags);
} }
int SkNWayCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkNWayCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
Iter iter(fList); Iter iter(fList);
while (iter.next()) { while (iter.next()) {
iter->saveLayer(bounds, paint, flags); iter->saveLayer(bounds, paint, flags);
} }
return this->INHERITED::saveLayer(bounds, paint, flags);
this->INHERITED::onSaveLayer(bounds, paint, flags);
// No need for a layer.
return false;
} }
void SkNWayCanvas::restore() { void SkNWayCanvas::onRestore() {
Iter iter(fList); Iter iter(fList);
while (iter.next()) { while (iter.next()) {
iter->restore(); iter->restore();
} }
this->INHERITED::restore(); this->INHERITED::onRestore();
} }
bool SkNWayCanvas::translate(SkScalar dx, SkScalar dy) { bool SkNWayCanvas::translate(SkScalar dx, SkScalar dy) {

View File

@ -18,21 +18,13 @@ class SkNoSaveLayerCanvas : public SkCanvas {
public: public:
SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {} SkNoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {}
// turn saveLayer() into save() for speed, should not affect correctness. protected:
virtual int saveLayer(const SkRect* bounds, virtual bool onSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags)
const SkPaint* paint, SK_OVERRIDE {
SaveFlags flags) SK_OVERRIDE { this->INHERITED::onSaveLayer(bounds, paint, flags);
return false;
// Like SkPictureRecord, we don't want to create layers, but we do need
// to respect the save and (possibly) its rect-clip.
int count = this->INHERITED::save(flags);
if (NULL != bounds) {
this->INHERITED::clipRectBounds(bounds, flags, NULL);
}
return count;
} }
protected:
// disable aa for speed // disable aa for speed
virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE { virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle); this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle);

View File

@ -21,17 +21,22 @@ void SkProxyCanvas::setProxy(SkCanvas* proxy) {
///////////////////////////////// Overrides /////////// ///////////////////////////////// Overrides ///////////
int SkProxyCanvas::save(SaveFlags flags) { void SkProxyCanvas::onSave(SaveFlags flags) {
return fProxy->save(flags); fProxy->save(flags);
this->INHERITED::onSave(flags);
} }
int SkProxyCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkProxyCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
return fProxy->saveLayer(bounds, paint, flags); fProxy->saveLayer(bounds, paint, flags);
this->INHERITED::onSaveLayer(bounds, paint, flags);
// No need for a layer.
return false;
} }
void SkProxyCanvas::restore() { void SkProxyCanvas::onRestore() {
fProxy->restore(); fProxy->restore();
this->INHERITED::onRestore();
} }
bool SkProxyCanvas::translate(SkScalar dx, SkScalar dy) { bool SkProxyCanvas::translate(SkScalar dx, SkScalar dy) {

View File

@ -530,8 +530,9 @@ void SkDebugCanvas::onPopCull() {
this->addDrawCommand(new SkPopCullCommand()); this->addDrawCommand(new SkPopCullCommand());
} }
void SkDebugCanvas::restore() { void SkDebugCanvas::onRestore() {
addDrawCommand(new SkRestoreCommand()); this->addDrawCommand(new SkRestoreCommand());
this->INHERITED::onRestore();
} }
bool SkDebugCanvas::rotate(SkScalar degrees) { bool SkDebugCanvas::rotate(SkScalar degrees) {
@ -539,15 +540,17 @@ bool SkDebugCanvas::rotate(SkScalar degrees) {
return true; return true;
} }
int SkDebugCanvas::save(SaveFlags flags) { void SkDebugCanvas::onSave(SaveFlags flags) {
addDrawCommand(new SkSaveCommand(flags)); this->addDrawCommand(new SkSaveCommand(flags));
return true; this->INHERITED::onSave(flags);
} }
int SkDebugCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, bool SkDebugCanvas::onSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) { SaveFlags flags) {
addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags)); this->addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags));
return true; this->INHERITED::onSaveLayer(bounds, paint, flags);
// No need for a full layer.
return false;
} }
bool SkDebugCanvas::scale(SkScalar sx, SkScalar sy) { bool SkDebugCanvas::scale(SkScalar sx, SkScalar sy) {

View File

@ -206,14 +206,8 @@ public:
const uint16_t indices[], int indexCount, const uint16_t indices[], int indexCount,
const SkPaint&) SK_OVERRIDE; const SkPaint&) SK_OVERRIDE;
virtual void restore() SK_OVERRIDE;
virtual bool rotate(SkScalar degrees) SK_OVERRIDE; virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
virtual int save(SaveFlags) SK_OVERRIDE;
virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
@ -248,6 +242,10 @@ public:
} }
protected: protected:
virtual void onSave(SaveFlags) SK_OVERRIDE;
virtual bool onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
virtual void onRestore() SK_OVERRIDE;
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE; virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
virtual void onPopCull() SK_OVERRIDE; virtual void onPopCull() SK_OVERRIDE;