diff options
author | Florin Malita <fmalita@chromium.org> | 2014-06-30 10:13:28 -0400 |
---|---|---|
committer | Florin Malita <fmalita@chromium.org> | 2014-06-30 10:13:28 -0400 |
commit | 5f6102d07982043542343ff0a6c67b1319ac9fc7 (patch) | |
tree | 934909d391ec4f68bcb9c27a327f540c292ca8b3 | |
parent | fdecca84400688c5a683da32ec11f6282e9a6b14 (diff) |
SaveFlags be-gone
Remove the deprecated save(SaveFlags), willSave(SaveFlags) and all
traces of kMatrix_SaveFlags/kClip_SaveFlag.
BUG=skia:2297
R=mtklein@google.com, reed@google.com, robertphillips@google.com
Review URL: https://codereview.chromium.org/340403003
36 files changed, 92 insertions, 376 deletions
diff --git a/gm/canvasstate.cpp b/gm/canvasstate.cpp deleted file mode 100644 index b61ee720d5..0000000000 --- a/gm/canvasstate.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "gm.h" -#include "SkCanvas.h" -#include "SkPaint.h" -#include "SkPath.h" -#include "SkRect.h" - -namespace skiagm { - -/* - * This GM exercises the flags to SkCanvas::save(). The canvas' save() and - * restore actions can be limited to only a portion of the canvas' state through - * the use of flags when calling save. - */ -class CanvasStateGM : public GM { - SkSize fSize; - enum { - WIDTH = 150, - HEIGHT = 150, - }; - - SkPaint fFillPaint; - SkPaint fStrokePaint; - - SkPath fPath; - - SkRect fOutlineRect; - SkRect fFillRect; - - -public: - CanvasStateGM() { - fSize.set(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)); - - fFillPaint.setColor(SK_ColorRED); - fFillPaint.setStyle(SkPaint::kFill_Style); - - fStrokePaint.setColor(SK_ColorBLUE); - fStrokePaint.setStyle(SkPaint::kStroke_Style); - fStrokePaint.setStrokeWidth(1); - - fPath.moveTo(25, 25); - fPath.lineTo(125, 25); - fPath.lineTo(75, 125); - fPath.close(); - - fOutlineRect = SkRect::MakeXYWH(1, 1, WIDTH-2, HEIGHT-2); - fFillRect = SkRect::MakeXYWH(10, 10, WIDTH-20, HEIGHT-20); - } - -protected: - virtual SkString onShortName() SK_OVERRIDE { - return SkString("canvas-state"); - } - - virtual SkISize onISize() SK_OVERRIDE { - return SkISize::Make(WIDTH*3, HEIGHT*4); - } - - virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { - - SkCanvas::SaveFlags flags[] = { SkCanvas::kMatrix_SaveFlag, - SkCanvas::kClip_SaveFlag, - SkCanvas::kMatrixClip_SaveFlag }; - - // columns -- flags - // rows -- permutations of setting the clip and matrix - for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(flags)); ++i) { - for (int j = 0; j < 2; ++j) { - for (int k = 0; k < 2; ++k) { - this->drawTestPattern(i, (2*j)+k, canvas, flags[i], - SkToBool(j), SkToBool(k)); - } - } - } - } - - - virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipPicture_Flag; } - -private: - void drawTestPattern(int x, int y, SkCanvas* canvas, - SkCanvas::SaveFlags flags, bool doClip, bool doScale) { - canvas->save(); - canvas->translate(SkIntToScalar(x*WIDTH), SkIntToScalar(y*HEIGHT)); - - canvas->drawRect(fOutlineRect, fStrokePaint); - canvas->save(flags); - if(doClip) { - canvas->clipPath(fPath); - } - if (doScale) { - canvas->scale(SkDoubleToScalar(0.5), SkDoubleToScalar(0.5)); - } - canvas->restore(); - canvas->drawRect(fFillRect, fFillPaint); - - canvas->restore(); - } - - typedef GM INHERITED; -}; - -////////////////////////////////////////////////////////////////////////////// - -class CanvasLayerStateGM : public GM { -public: - CanvasLayerStateGM() { - fBluePaint.setColor(SK_ColorBLUE); - fBluePaint.setStyle(SkPaint::kFill_Style); - - fRect = SkRect::MakeXYWH(SPACER, SPACER, WIDTH-(2*SPACER), (HEIGHT-(2*SPACER)) / 7); - } - -protected: - virtual SkString onShortName() SK_OVERRIDE { - return SkString("canvas-layer-state"); - } - - virtual SkISize onISize() SK_OVERRIDE { - return SkISize::Make(WIDTH, HEIGHT); - } - - virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { - - // clear the canvas to red - canvas->drawColor(SK_ColorRED); - -#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG - // both rects should appear - drawTestPattern(canvas, 255, SkCanvas::kARGB_NoClipLayer_SaveFlag); - - canvas->translate(0, 2*(fRect.height() + 10)); - - // only the top rect should appear - drawTestPattern(canvas, 255, SkCanvas::kARGB_ClipLayer_SaveFlag); - - canvas->translate(0, 2*(fRect.height() + 10)); - - // only the bottom rect should appear - drawTestPattern(canvas, 0, SkCanvas::kARGB_NoClipLayer_SaveFlag); -#endif - } - - virtual uint32_t onGetFlags() const SK_OVERRIDE { return kSkipGPU_Flag; } - -private: - // draw a rect within the layer's bounds and again outside the layer's bounds - void drawTestPattern(SkCanvas* canvas, U8CPU layerAlpha, SkCanvas::SaveFlags flags) { - canvas->saveLayerAlpha(&fRect, layerAlpha, flags); - canvas->drawRect(fRect, fBluePaint); - canvas->translate(0, fRect.height() + 10); - canvas->drawRect(fRect, fBluePaint); - canvas->restore(); - } - - enum { - WIDTH = 400, - HEIGHT = 400, - SPACER = 10, - }; - - SkPaint fBluePaint; - SkRect fRect; - - typedef GM INHERITED; -}; - -////////////////////////////////////////////////////////////////////////////// - -DEF_GM( return SkNEW(CanvasStateGM); ) -DEF_GM( return SkNEW(CanvasLayerStateGM); ) - -} // end namespace diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index 433035ea9a..6bf46a393c 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -36,7 +36,6 @@ '../gm/blurquickreject.cpp', '../gm/blurrect.cpp', '../gm/blurroundrect.cpp', - '../gm/canvasstate.cpp', '../gm/circles.cpp', '../gm/circularclips.cpp', '../gm/clippedbitmapshaders.cpp', diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 8640d729b0..7a4ddd935f 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -293,9 +293,9 @@ public: enum SaveFlags { /** save the matrix state, restoring it on restore() */ - kMatrix_SaveFlag = 0x01, + // [deprecated] kMatrix_SaveFlag = 0x01, /** save the clip state, restoring it on restore() */ - kClip_SaveFlag = 0x02, + // [deprecated] kClip_SaveFlag = 0x02, /** the layer needs to support per-pixel alpha */ kHasAlphaLayer_SaveFlag = 0x04, /** the layer needs to support 8-bits per color component */ @@ -308,7 +308,7 @@ public: kClipToLayer_SaveFlag = 0x10, // helper masks for common choices - kMatrixClip_SaveFlag = 0x03, + // [deprecated] kMatrixClip_SaveFlag = 0x03, #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG kARGB_NoClipLayer_SaveFlag = 0x0F, #endif @@ -326,22 +326,6 @@ public: */ int save(); - /** DEPRECATED - use save() instead. - - This behaves the same as save(), but it allows fine-grained control of - which state bits to be saved (and subsequently restored). - - @param flags The flags govern what portion of the Matrix/Clip/drawFilter - state the save (and matching restore) effect. For example, - if only kMatrix is specified, then only the matrix state - will be pushed and popped. Likewise for the clip if kClip - is specified. However, the drawFilter is always affected - by calls to save/restore. - @return The value to pass to restoreToCount() to balance this save() - */ - SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") - int save(SaveFlags flags); - /** This behaves the same as save(), but in addition it allocates an offscreen bitmap. All drawing calls are directed there, and only when the balancing call to restore() is made is that offscreen transfered to @@ -1191,9 +1175,6 @@ protected: kNoLayer_SaveLayerStrategy }; - // Transitional, pending external clients cleanup. - virtual void willSave(SaveFlags) { this->willSave(); } - virtual void willSave() {} virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) { return kFullLayer_SaveLayerStrategy; @@ -1324,7 +1305,7 @@ private: void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); // shared by save() and saveLayer() - int internalSave(SaveFlags flags); + int internalSave(); void internalRestore(); static void DrawRect(const SkDraw& draw, const SkPaint& paint, const SkRect& r, SkScalar textSize); diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index 1f1378c415..b4644fc2c8 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -238,13 +238,14 @@ protected: // V26: Removed boolean from SkColorShader for inheriting color from SkPaint. // V27: Remove SkUnitMapper from gradients (and skia). // V28: No longer call bitmap::flatten inside SkWriteBuffer::writeBitmap. + // V29: Removed SaveFlags parameter from save(). // Note: If the picture version needs to be increased then please follow the // steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw // Only SKPs within the min/current picture version range (inclusive) can be read. static const uint32_t MIN_PICTURE_VERSION = 19; - static const uint32_t CURRENT_PICTURE_VERSION = 28; + static const uint32_t CURRENT_PICTURE_VERSION = 29; mutable uint32_t fUniqueID; diff --git a/include/utils/SkDeferredCanvas.h b/include/utils/SkDeferredCanvas.h index 31ebce48b3..5abff742b7 100644 --- a/include/utils/SkDeferredCanvas.h +++ b/include/utils/SkDeferredCanvas.h @@ -170,7 +170,7 @@ public: virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE; protected: - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; diff --git a/include/utils/SkDumpCanvas.h b/include/utils/SkDumpCanvas.h index 0aa55463b4..91d698fa38 100644 --- a/include/utils/SkDumpCanvas.h +++ b/include/utils/SkDumpCanvas.h @@ -101,7 +101,7 @@ public: virtual void endCommentGroup() SK_OVERRIDE; protected: - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; diff --git a/include/utils/SkLuaCanvas.h b/include/utils/SkLuaCanvas.h index 6bef8686a3..5d8a973458 100644 --- a/include/utils/SkLuaCanvas.h +++ b/include/utils/SkLuaCanvas.h @@ -44,7 +44,7 @@ public: virtual void drawData(const void* data, size_t length) SK_OVERRIDE; protected: - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; diff --git a/include/utils/SkNWayCanvas.h b/include/utils/SkNWayCanvas.h index bd1935539e..aabf27436c 100644 --- a/include/utils/SkNWayCanvas.h +++ b/include/utils/SkNWayCanvas.h @@ -59,7 +59,7 @@ public: protected: SkTDArray<SkCanvas*> fList; - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; diff --git a/include/utils/SkProxyCanvas.h b/include/utils/SkProxyCanvas.h index 32f103cd26..6055db9bed 100644 --- a/include/utils/SkProxyCanvas.h +++ b/include/utils/SkProxyCanvas.h @@ -55,11 +55,8 @@ public: virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE; - // Transitional, to facilitate migrating subclasses to the new willSave API. - using SkCanvas::willSave; - protected: - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; diff --git a/src/core/SkBBoxHierarchyRecord.cpp b/src/core/SkBBoxHierarchyRecord.cpp index 96e6cdf102..1868e65325 100644 --- a/src/core/SkBBoxHierarchyRecord.cpp +++ b/src/core/SkBBoxHierarchyRecord.cpp @@ -26,9 +26,9 @@ void SkBBoxHierarchyRecord::handleBBox(const SkRect& bounds) { fBoundingHierarchy->insert(draw, r, true); } -void SkBBoxHierarchyRecord::willSave(SaveFlags flags) { +void SkBBoxHierarchyRecord::willSave() { fStateTree->appendSave(); - this->INHERITED::willSave(flags); + this->INHERITED::willSave(); } SkCanvas::SaveLayerStrategy SkBBoxHierarchyRecord::willSaveLayer(const SkRect* bounds, diff --git a/src/core/SkBBoxHierarchyRecord.h b/src/core/SkBBoxHierarchyRecord.h index ba7d514bc5..7db82d8369 100644 --- a/src/core/SkBBoxHierarchyRecord.h +++ b/src/core/SkBBoxHierarchyRecord.h @@ -28,7 +28,7 @@ public: virtual bool shouldRewind(void* data) SK_OVERRIDE; protected: - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 2fb5c95124..c35f284432 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -189,7 +189,6 @@ private: */ class SkCanvas::MCRec { public: - int fFlags; SkMatrix* fMatrix; // points to either fMatrixStorage or prev MCRec SkRasterClip* fRasterClip; // points to either fRegionStorage or prev MCRec SkDrawFilter* fFilter; // the current filter (or null) @@ -203,21 +202,13 @@ public: */ DeviceCM* fTopLayer; - MCRec(const MCRec* prev, int flags) : fFlags(flags) { + MCRec(const MCRec* prev) { if (NULL != prev) { - if (flags & SkCanvas::kMatrix_SaveFlag) { - fMatrixStorage = *prev->fMatrix; - fMatrix = &fMatrixStorage; - } else { - fMatrix = prev->fMatrix; - } + fMatrixStorage = *prev->fMatrix; + fMatrix = &fMatrixStorage; - if (flags & SkCanvas::kClip_SaveFlag) { - fRasterClipStorage = *prev->fRasterClip; - fRasterClip = &fRasterClipStorage; - } else { - fRasterClip = prev->fRasterClip; - } + fRasterClipStorage = *prev->fRasterClip; + fRasterClip = &fRasterClipStorage; fFilter = prev->fFilter; SkSafeRef(fFilter); @@ -449,7 +440,7 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device) { fMetaData = NULL; fMCRec = (MCRec*)fMCStack.push_back(); - new (fMCRec) MCRec(NULL, 0); + new (fMCRec) MCRec(NULL); fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL)); fMCRec->fTopLayer = fMCRec->fLayer; @@ -786,30 +777,21 @@ void SkCanvas::updateDeviceCMCache() { /////////////////////////////////////////////////////////////////////////////// -int SkCanvas::internalSave(SaveFlags flags) { +int SkCanvas::internalSave() { int saveCount = this->getSaveCount(); // record this before the actual save MCRec* newTop = (MCRec*)fMCStack.push_back(); - new (newTop) MCRec(fMCRec, flags); // balanced in restore() - + new (newTop) MCRec(fMCRec); // balanced in restore() fMCRec = newTop; - if (SkCanvas::kClip_SaveFlag & flags) { - fClipStack.save(); - } + fClipStack.save(); return saveCount; } int SkCanvas::save() { - this->willSave(kMatrixClip_SaveFlag); - return this->internalSave(kMatrixClip_SaveFlag); -} - -int SkCanvas::save(SaveFlags flags) { - this->willSave(flags); - // call shared impl - return this->internalSave(flags); + this->willSave(); + return this->internalSave(); } static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { @@ -889,7 +871,7 @@ int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save // do this before we create the layer. We don't call the public save() since // that would invoke a possibly overridden virtual - int count = this->internalSave(flags); + int count = this->internalSave(); fDeviceCMDirty = true; @@ -974,9 +956,7 @@ void SkCanvas::internalRestore() { fDeviceCMDirty = true; fCachedLocalClipBoundsDirty = true; - if (SkCanvas::kClip_SaveFlag & fMCRec->fFlags) { - fClipStack.restore(); - } + fClipStack.restore(); // reserve our layer (if any) DeviceCM* layer = fMCRec->fLayer; // may be null diff --git a/src/core/SkMatrixClipStateMgr.cpp b/src/core/SkMatrixClipStateMgr.cpp index 1fc7fe8321..680cc364d2 100644 --- a/src/core/SkMatrixClipStateMgr.cpp +++ b/src/core/SkMatrixClipStateMgr.cpp @@ -110,7 +110,7 @@ SkMatrixClipStateMgr::SkMatrixClipStateMgr() fMatrixDict.append()->reset(); fCurMCState = (MatrixClipState*)fMatrixClipStack.push_back(); - new (fCurMCState) MatrixClipState(NULL, 0); // balanced in restore() + new (fCurMCState) MatrixClipState(NULL); // balanced in restore() #ifdef SK_DEBUG fActualDepth = 0; @@ -126,9 +126,9 @@ SkMatrixClipStateMgr::~SkMatrixClipStateMgr() { } -int SkMatrixClipStateMgr::MCStackPush(SkCanvas::SaveFlags flags) { +int SkMatrixClipStateMgr::MCStackPush() { MatrixClipState* newTop = (MatrixClipState*)fMatrixClipStack.push_back(); - new (newTop) MatrixClipState(fCurMCState, flags); // balanced in restore() + new (newTop) MatrixClipState(fCurMCState); // balanced in restore() fCurMCState = newTop; SkDEBUGCODE(this->validate();) @@ -136,10 +136,10 @@ int SkMatrixClipStateMgr::MCStackPush(SkCanvas::SaveFlags flags) { return fMatrixClipStack.count(); } -int SkMatrixClipStateMgr::save(SkCanvas::SaveFlags flags) { +int SkMatrixClipStateMgr::save() { SkDEBUGCODE(this->validate();) - return this->MCStackPush(flags); + return this->MCStackPush(); } int SkMatrixClipStateMgr::saveLayer(const SkRect* bounds, const SkPaint* paint, @@ -154,7 +154,7 @@ int SkMatrixClipStateMgr::saveLayer(const SkRect* bounds, const SkPaint* paint, // out the MC state SkDEBUGCODE(bool saved =) this->call(kOther_CallType); - int result = this->MCStackPush(flags); + int result = this->MCStackPush(); ++fCurMCState->fLayerID; fCurMCState->fIsSaveLayer = true; @@ -172,7 +172,7 @@ int SkMatrixClipStateMgr::saveLayer(const SkRect* bounds, const SkPaint* paint, // restore fSkipOffsets = SkNEW(SkTDArray<int>); - fPicRecord->recordSaveLayer(bounds, paint, flags | SkCanvas::kMatrixClip_SaveFlag); + fPicRecord->recordSaveLayer(bounds, paint, flags); #ifdef SK_DEBUG fActualDepth++; #endif @@ -289,7 +289,7 @@ bool SkMatrixClipStateMgr::call(CallType callType) { SkASSERT(!fCurMCState->fHasOpen); SkASSERT(0 == fSkipOffsets->count()); fCurMCState->fHasOpen = true; - fPicRecord->recordSave(SkCanvas::kMatrixClip_SaveFlag); + fPicRecord->recordSave(); #ifdef SK_DEBUG fActualDepth++; SkASSERT(fActualDepth == fCurMCState->fExpectedDepth); diff --git a/src/core/SkMatrixClipStateMgr.h b/src/core/SkMatrixClipStateMgr.h index 016baa008a..9a80b0154e 100644 --- a/src/core/SkMatrixClipStateMgr.h +++ b/src/core/SkMatrixClipStateMgr.h @@ -181,7 +181,7 @@ public: typedef SkNoncopyable INHERITED; }; - MatrixClipState(MatrixClipState* prev, int flags) + MatrixClipState(MatrixClipState* prev) : fPrev(prev) { fHasOpen = false; @@ -202,19 +202,11 @@ public: else { fLayerID = prev->fLayerID; - if (flags & SkCanvas::kMatrix_SaveFlag) { - fMatrixInfoStorage = *prev->fMatrixInfo; - fMatrixInfo = &fMatrixInfoStorage; - } else { - fMatrixInfo = prev->fMatrixInfo; - } + fMatrixInfoStorage = *prev->fMatrixInfo; + fMatrixInfo = &fMatrixInfoStorage; - if (flags & SkCanvas::kClip_SaveFlag) { - // We don't copy the ClipOps of the previous clip states - fClipInfo = &fClipInfoStorage; - } else { - fClipInfo = prev->fClipInfo; - } + // We don't copy the ClipOps of the previous clip states + fClipInfo = &fClipInfoStorage; // Initially a new save/saveLayer represents the same MC state // as its predecessor. @@ -275,7 +267,7 @@ public: // this duplicates effort. int getSaveCount() const { return fMatrixClipStack.count(); } - int save(SkCanvas::SaveFlags flags); + int save(); int saveLayer(const SkRect* bounds, const SkPaint* paint, SkCanvas::SaveFlags flags); @@ -372,7 +364,7 @@ protected: SkDEBUGCODE(void validate();) - int MCStackPush(SkCanvas::SaveFlags flags); + int MCStackPush(); void addClipOffset(size_t offset) { SkASSERT(NULL != fSkipOffsets); diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 148237a5a8..35e66bb7eb 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -1307,7 +1307,12 @@ void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) canvas.rotate(reader.readScalar()); break; case SAVE: - canvas.save((SkCanvas::SaveFlags) reader.readInt()); + // SKPs with version < 29 also store a SaveFlags param. + if (size > 4) { + SkASSERT(8 == size); + reader.readInt(); + } + canvas.save(); break; case SAVE_LAYER: { const SkRect* boundsPtr = this->getRectPtr(reader); diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 16856d639d..566cb196ba 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -32,7 +32,7 @@ enum { // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, etc. static int const kUInt32Size = 4; -static const uint32_t kSaveSize = 2 * kUInt32Size; +static const uint32_t kSaveSize = kUInt32Size; static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect); @@ -151,25 +151,24 @@ static inline size_t getPaintOffset(DrawType op, size_t opSize) { return gPaintOffsets[op] * sizeof(uint32_t) + overflow; } -void SkPictureRecord::willSave(SaveFlags flags) { +void SkPictureRecord::willSave() { #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE - fMCMgr.save(flags); + fMCMgr.save(); #else // record the offset to us, making it non-positive to distinguish a save // from a clip entry. fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); - this->recordSave(flags); + this->recordSave(); #endif - this->INHERITED::willSave(flags); + this->INHERITED::willSave(); } -void SkPictureRecord::recordSave(SaveFlags flags) { - // op + flags +void SkPictureRecord::recordSave() { + // op only size_t size = kSaveSize; size_t initialOffset = this->addDraw(SAVE, &size); - this->addInt(flags); this->validate(initialOffset, size); } @@ -517,15 +516,6 @@ static bool collapse_save_clip_restore(SkWriter32* writer, int32_t offset, SkASSERT(SAVE == op); SkASSERT(kSaveSize == opSize); - // get the save flag (last 4-bytes of the space allocated for the opSize) - SkCanvas::SaveFlags saveFlags = (SkCanvas::SaveFlags) writer->readTAt<uint32_t>(offset + 4); - if (SkCanvas::kMatrixClip_SaveFlag != saveFlags) { - // This function's optimization is only correct for kMatrixClip style saves. - // TODO: set checkMatrix & checkClip booleans here and then check for the - // offending operations in the following loop. - return false; - } - // Walk forward until we get back to either a draw-verb (abort) or we hit // our restore (success). int32_t saveOffset = offset; diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 7e5c5c6410..417dde6e82 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -233,7 +233,7 @@ protected: return NULL; } - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; @@ -293,7 +293,7 @@ protected: size_t recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA); size_t recordClipPath(int pathID, SkRegion::Op op, bool doAA); size_t recordClipRegion(const SkRegion& region, SkRegion::Op op); - void recordSave(SaveFlags flags); + void recordSave(); void recordSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); void recordRestore(bool fillInSkips = true); diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp index e4c49e4f49..db149100c5 100644 --- a/src/core/SkRecordDraw.cpp +++ b/src/core/SkRecordDraw.cpp @@ -36,7 +36,7 @@ template <> void Draw::draw(const NoOp&) {} #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; } DRAW(Restore, restore()); -DRAW(Save, save(r.flags)); +DRAW(Save, save()); DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); DRAW(PopCull, popCull()); DRAW(PushCull, pushCull(r.rect)); diff --git a/src/core/SkRecordOpts.cpp b/src/core/SkRecordOpts.cpp index 75f7c62605..cb429cf76c 100644 --- a/src/core/SkRecordOpts.cpp +++ b/src/core/SkRecordOpts.cpp @@ -84,11 +84,6 @@ struct SaveNoDrawsRestoreNooper { Pattern; bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned end) { - // If restore doesn't revert both matrix and clip, this isn't safe to noop away. - if (pattern->first<Save>()->flags != SkCanvas::kMatrixClip_SaveFlag) { - return false; - } - // The entire span between Save and Restore (inclusively) does nothing. for (unsigned i = begin; i < end; i++) { record->replace<NoOp>(i); diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp index 8581257c4a..4c02a35c9f 100644 --- a/src/core/SkRecorder.cpp +++ b/src/core/SkRecorder.cpp @@ -206,9 +206,9 @@ void SkRecorder::drawVertices(VertexMode vmode, indexCount); } -void SkRecorder::willSave(SkCanvas::SaveFlags flags) { - APPEND(Save, flags); - INHERITED(willSave, flags); +void SkRecorder::willSave() { + APPEND(Save); + INHERITED(willSave); } SkCanvas::SaveLayerStrategy SkRecorder::willSaveLayer(const SkRect* bounds, diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h index 3e2932d42e..0eb11d7af8 100644 --- a/src/core/SkRecorder.h +++ b/src/core/SkRecorder.h @@ -62,7 +62,7 @@ public: int indexCount, const SkPaint& paint) SK_OVERRIDE; - void willSave(SkCanvas::SaveFlags) SK_OVERRIDE; + void willSave() SK_OVERRIDE; SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) SK_OVERRIDE; void willRestore() SK_OVERRIDE; diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h index 581ae21e05..02cfc64032 100644 --- a/src/core/SkRecords.h +++ b/src/core/SkRecords.h @@ -183,7 +183,7 @@ private: RECORD0(NoOp); RECORD0(Restore); -RECORD1(Save, SkCanvas::SaveFlags, flags); +RECORD0(Save); RECORD3(SaveLayer, Optional<SkRect>, bounds, Optional<SkPaint>, paint, SkCanvas::SaveFlags, flags); RECORD1(PushCull, SkRect, rect); diff --git a/src/pipe/SkGPipeRead.cpp b/src/pipe/SkGPipeRead.cpp index 41c417f92e..9047e8293f 100644 --- a/src/pipe/SkGPipeRead.cpp +++ b/src/pipe/SkGPipeRead.cpp @@ -317,7 +317,7 @@ static void translate_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, static void save_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, SkGPipeState* state) { - canvas->save((SkCanvas::SaveFlags)DrawOp_unpackData(op32)); + canvas->save(); } static void saveLayer_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp index a3c38646bb..6711eb0664 100644 --- a/src/pipe/SkGPipeWrite.cpp +++ b/src/pipe/SkGPipeWrite.cpp @@ -266,7 +266,7 @@ public: bool shuttleBitmap(const SkBitmap&, int32_t slot); protected: - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; @@ -515,13 +515,13 @@ uint32_t SkGPipeCanvas::getTypefaceID(SkTypeface* face) { #define NOTIFY_SETUP(canvas) \ AutoPipeNotify apn(canvas) -void SkGPipeCanvas::willSave(SaveFlags flags) { +void SkGPipeCanvas::willSave() { NOTIFY_SETUP(this); if (this->needOpBytes()) { - this->writeOp(kSave_DrawOp, 0, flags); + this->writeOp(kSave_DrawOp); } - this->INHERITED::willSave(flags); + this->INHERITED::willSave(); } SkCanvas::SaveLayerStrategy SkGPipeCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp index 641974b1ed..299e7caeea 100644 --- a/src/utils/SkDeferredCanvas.cpp +++ b/src/utils/SkDeferredCanvas.cpp @@ -678,10 +678,10 @@ bool SkDeferredCanvas::isFullFrame(const SkRect* rect, SkIntToScalar(canvasSize.fWidth), SkIntToScalar(canvasSize.fHeight))); } -void SkDeferredCanvas::willSave(SaveFlags flags) { - this->drawingCanvas()->save(flags); +void SkDeferredCanvas::willSave() { + this->drawingCanvas()->save(); this->recordedDrawCommand(); - this->INHERITED::willSave(flags); + this->INHERITED::willSave(); } SkCanvas::SaveLayerStrategy SkDeferredCanvas::willSaveLayer(const SkRect* bounds, diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp index 4dfed395e0..b12928fbbb 100644 --- a/src/utils/SkDumpCanvas.cpp +++ b/src/utils/SkDumpCanvas.cpp @@ -192,9 +192,9 @@ void SkDumpCanvas::dump(Verb verb, const SkPaint* paint, /////////////////////////////////////////////////////////////////////////////// -void SkDumpCanvas::willSave(SaveFlags flags) { - this->dump(kSave_Verb, NULL, "save(0x%X)", flags); - this->INHERITED::willSave(flags); +void SkDumpCanvas::willSave() { + this->dump(kSave_Verb, NULL, "save()"); + this->INHERITED::willSave(); } SkCanvas::SaveLayerStrategy SkDumpCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, diff --git a/src/utils/SkLuaCanvas.cpp b/src/utils/SkLuaCanvas.cpp index d9c5dc1d76..b0b912827f 100644 --- a/src/utils/SkLuaCanvas.cpp +++ b/src/utils/SkLuaCanvas.cpp @@ -81,9 +81,9 @@ SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[]) SkLuaCanvas::~SkLuaCanvas() {} -void SkLuaCanvas::willSave(SaveFlags flags) { +void SkLuaCanvas::willSave() { AUTO_LUA("save"); - this->INHERITED::willSave(flags); + this->INHERITED::willSave(); } SkCanvas::SaveLayerStrategy SkLuaCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp index 505c05cbf1..11e4a65349 100644 --- a/src/utils/SkNWayCanvas.cpp +++ b/src/utils/SkNWayCanvas.cpp @@ -57,13 +57,13 @@ private: SkCanvas* fCanvas; }; -void SkNWayCanvas::willSave(SaveFlags flags) { +void SkNWayCanvas::willSave() { Iter iter(fList); while (iter.next()) { - iter->save(flags); + iter->save(); } - this->INHERITED::willSave(flags); + this->INHERITED::willSave(); } SkCanvas::SaveLayerStrategy SkNWayCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, diff --git a/src/utils/SkProxyCanvas.cpp b/src/utils/SkProxyCanvas.cpp index 5cb54698f6..3aa459cdfa 100644 --- a/src/utils/SkProxyCanvas.cpp +++ b/src/utils/SkProxyCanvas.cpp @@ -21,9 +21,9 @@ void SkProxyCanvas::setProxy(SkCanvas* proxy) { ///////////////////////////////// Overrides /////////// -void SkProxyCanvas::willSave(SaveFlags flags) { - fProxy->save(flags); - this->INHERITED::willSave(flags); +void SkProxyCanvas::willSave() { + fProxy->save(); + this->INHERITED::willSave(); } SkCanvas::SaveLayerStrategy SkProxyCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp index 8f6dc1b7a2..277e86d84d 100644 --- a/src/utils/debugger/SkDebugCanvas.cpp +++ b/src/utils/debugger/SkDebugCanvas.cpp @@ -590,9 +590,9 @@ void SkDebugCanvas::willRestore() { this->INHERITED::willRestore(); } -void SkDebugCanvas::willSave(SaveFlags flags) { - this->addDrawCommand(new SkSaveCommand(flags)); - this->INHERITED::willSave(flags); +void SkDebugCanvas::willSave() { + this->addDrawCommand(new SkSaveCommand()); + this->INHERITED::willSave(); } SkCanvas::SaveLayerStrategy SkDebugCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h index f15b397251..a3902d2a4e 100644 --- a/src/utils/debugger/SkDebugCanvas.h +++ b/src/utils/debugger/SkDebugCanvas.h @@ -231,7 +231,7 @@ public: } protected: - virtual void willSave(SaveFlags) SK_OVERRIDE; + virtual void willSave() SK_OVERRIDE; virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; virtual void willRestore() SK_OVERRIDE; diff --git a/src/utils/debugger/SkDrawCommand.cpp b/src/utils/debugger/SkDrawCommand.cpp index 7c73cec786..c50fa2d3f5 100644 --- a/src/utils/debugger/SkDrawCommand.cpp +++ b/src/utils/debugger/SkDrawCommand.cpp @@ -840,14 +840,12 @@ void SkRotateCommand::execute(SkCanvas* canvas) { canvas->rotate(fDegrees); } -SkSaveCommand::SkSaveCommand(SkCanvas::SaveFlags flags) +SkSaveCommand::SkSaveCommand() : INHERITED(SAVE) { - fFlags = flags; - fInfo.push(SkObjectParser::SaveFlagsToString(flags)); } void SkSaveCommand::execute(SkCanvas* canvas) { - canvas->save(fFlags); + canvas->save(); } void SkSaveCommand::trackSaveState(int* state) { diff --git a/src/utils/debugger/SkDrawCommand.h b/src/utils/debugger/SkDrawCommand.h index a0bfb2ddca..f4569931a1 100644 --- a/src/utils/debugger/SkDrawCommand.h +++ b/src/utils/debugger/SkDrawCommand.h @@ -522,13 +522,11 @@ private: class SkSaveCommand : public SkDrawCommand { public: - SkSaveCommand(SkCanvas::SaveFlags flags); + SkSaveCommand(); virtual void execute(SkCanvas* canvas) SK_OVERRIDE; virtual void trackSaveState(int* state) SK_OVERRIDE; virtual Action action() const SK_OVERRIDE { return kPushLayer_Action; } private: - SkCanvas::SaveFlags fFlags; - typedef SkDrawCommand INHERITED; }; diff --git a/src/utils/debugger/SkObjectParser.cpp b/src/utils/debugger/SkObjectParser.cpp index b932036a89..a9bad40f71 100644 --- a/src/utils/debugger/SkObjectParser.cpp +++ b/src/utils/debugger/SkObjectParser.cpp @@ -300,12 +300,6 @@ SkString* SkObjectParser::RegionToString(const SkRegion& region) { SkString* SkObjectParser::SaveFlagsToString(SkCanvas::SaveFlags flags) { SkString* mFlags = new SkString("SkCanvas::SaveFlags: "); - if (flags & SkCanvas::kMatrix_SaveFlag) { - mFlags->append("kMatrix_SaveFlag "); - } - if (flags & SkCanvas::kClip_SaveFlag) { - mFlags->append("kClip_SaveFlag "); - } if (flags & SkCanvas::kHasAlphaLayer_SaveFlag) { mFlags->append("kHasAlphaLayer_SaveFlag "); } diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index ae686762ba..217cf0349e 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -367,45 +367,11 @@ SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); /////////////////////////////////////////////////////////////////////////////// // Complex test steps -// Save/restore calls cannot be in isolated simple test steps because the test -// cases that use SkPicture require that save and restore calls be balanced. -static void SaveMatrixStep(SkCanvas* canvas, - skiatest::Reporter* reporter, - CanvasTestStep* testStep) { - int saveCount = canvas->getSaveCount(); - canvas->save(SkCanvas::kMatrix_SaveFlag); - canvas->clipRegion(kTestRegion); - canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); - canvas->restore(); - REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, - testStep->assertMessage()); - REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), - testStep->assertMessage()); -// REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() == kTestRegion, testStep->assertMessage()); -} -TEST_STEP(SaveMatrix, SaveMatrixStep); - -static void SaveClipStep(SkCanvas* canvas, - skiatest::Reporter* reporter, - CanvasTestStep* testStep) { - int saveCount = canvas->getSaveCount(); - canvas->save(SkCanvas::kClip_SaveFlag); - canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); - canvas->clipRegion(kTestRegion); - canvas->restore(); - REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, - testStep->assertMessage()); - REPORTER_ASSERT_MESSAGE(reporter, !canvas->getTotalMatrix().isIdentity(), - testStep->assertMessage()); -// REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, testStep->assertMessage()); -} -TEST_STEP(SaveClip, SaveClipStep); - static void SaveMatrixClipStep(SkCanvas* canvas, skiatest::Reporter* reporter, CanvasTestStep* testStep) { int saveCount = canvas->getSaveCount(); - canvas->save(SkCanvas::kMatrixClip_SaveFlag); + canvas->save(); canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); canvas->clipRegion(kTestRegion); canvas->restore(); diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index e62a68ba9a..8f0fb20c75 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -933,9 +933,9 @@ public: return this->INHERITED::willSaveLayer(bounds, paint, flags); } - virtual void willSave(SaveFlags flags) SK_OVERRIDE { + virtual void willSave() SK_OVERRIDE { ++fSaveCount; - this->INHERITED::willSave(flags); + this->INHERITED::willSave(); } virtual void willRestore() SK_OVERRIDE { |