change signature for virtual related to saveLayer, passing SaveLayerRec

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1533953002

NOTREECHECKS=True

Review URL: https://codereview.chromium.org/1533953002
This commit is contained in:
reed 2015-12-18 07:09:18 -08:00 committed by Commit bot
parent f97aa74fea
commit 4960eeec4a
28 changed files with 207 additions and 151 deletions

View File

@ -391,6 +391,27 @@ public:
SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated")
int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags);
enum {
kIsOpaque_SaveLayerFlag = 1 << 0,
kPreserveLCDText_SaveLayerFlag = 1 << 1,
};
typedef uint32_t SaveLayerFlags;
struct SaveLayerRec {
SaveLayerRec() : fBounds(nullptr), fPaint(nullptr), fSaveLayerFlags(0) {}
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
: fBounds(bounds)
, fPaint(paint)
, fSaveLayerFlags(saveLayerFlags)
{}
const SkRect* fBounds; // optional
const SkPaint* fPaint; // optional
SaveLayerFlags fSaveLayerFlags;
};
int saveLayer(const SaveLayerRec&);
/** This call balances a previous call to save(), and is used to remove all
modifications to the matrix/clip/drawFilter state since the last save
call.
@ -1217,16 +1238,24 @@ protected:
// Subclass save/restore notifiers.
// Overriders should call the corresponding INHERITED method up the inheritance chain.
// willSaveLayer()'s return value may suppress full layer allocation.
// getSaveLayerStrategy()'s return value may suppress full layer allocation.
enum SaveLayerStrategy {
kFullLayer_SaveLayerStrategy,
kNoLayer_SaveLayerStrategy
kNoLayer_SaveLayerStrategy,
};
virtual void willSave() {}
#ifdef SK_SUPPORT_LEGACY_SAVELAYERPARAMS
virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) {
return kFullLayer_SaveLayerStrategy;
}
virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&);
#else
// Overriders should call the corresponding INHERITED method up the inheritance chain.
virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) {
return kFullLayer_SaveLayerStrategy;
}
#endif
virtual void willRestore() {}
virtual void didRestore() {}
virtual void didConcat(const SkMatrix&) {}
@ -1304,16 +1333,17 @@ protected:
// returns false if the entire rectangle is entirely clipped out
// If non-NULL, The imageFilter parameter will be used to expand the clip
// and offscreen bounds for any margin required by the filter DAG.
bool clipRectBounds(const SkRect* bounds, SaveFlags flags,
SkIRect* intersection,
bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersection,
const SkImageFilter* imageFilter = NULL);
private:
enum PrivateSaveFlags {
// These must not overlap the public flags.
kPreserveLCDText_PrivateSaveFlag = 1 << 5,
enum PrivateSaveLayerFlags {
kDontClipToLayer_PrivateSaveLayerFlag = 1 << 31,
};
static bool BoundsAffectsClip(SaveLayerFlags);
static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags);
enum ShaderOverrideOpacity {
kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
@ -1373,6 +1403,7 @@ private:
friend class SkNoSaveLayerCanvas; // InitFlags
friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>)
friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
enum InitFlags {
kDefault_InitFlags = 0,
@ -1404,7 +1435,7 @@ private:
const SkRect& dst, const SkPaint* paint,
SrcRectConstraint);
void internalDrawPaint(const SkPaint& paint);
void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, SaveLayerStrategy);
void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool isBitmapDevice);
// shared by save() and saveLayer()

View File

@ -197,7 +197,7 @@ RECORD(Save, 0);
RECORD(SaveLayer, 0,
Optional<SkRect> bounds;
Optional<SkPaint> paint;
SkCanvas::SaveFlags flags);
SkCanvas::SaveLayerFlags saveLayerFlags);
RECORD(SetMatrix, 0,
TypedMatrix matrix);

View File

@ -73,7 +73,7 @@ public:
protected:
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;

View File

@ -22,7 +22,7 @@ public:
protected:
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;

View File

@ -30,7 +30,7 @@ protected:
SkTDArray<SkCanvas*> fList;
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;

View File

@ -21,9 +21,8 @@ public:
{}
protected:
virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) override {
this->INHERITED::willSaveLayer(bounds, paint, flags);
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override {
(void)this->INHERITED::getSaveLayerStrategy(rec);
return kNoLayer_SaveLayerStrategy;
}

View File

@ -481,7 +481,7 @@ public:
// Make rawBounds include all paint outsets except for those due to image filters.
rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *rawBounds, &storage);
}
(void)canvas->internalSaveLayer(rawBounds, &tmp, SkCanvas::kARGB_ClipLayer_SaveFlag,
(void)canvas->internalSaveLayer(SkCanvas::SaveLayerRec(rawBounds, &tmp, 0),
SkCanvas::kFullLayer_SaveLayerStrategy);
fTempLayerForImageFilter = true;
// we remove the imagefilter/xfermode inside doNext()
@ -1053,15 +1053,15 @@ void SkCanvas::internalSave() {
fClipStack->save();
}
static bool bounds_affects_clip(SkCanvas::SaveFlags flags) {
bool SkCanvas::BoundsAffectsClip(SaveLayerFlags saveLayerFlags) {
#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0;
return !(saveLayerFlags & SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag);
#else
return true;
#endif
}
bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags,
bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveLayerFlags saveLayerFlags,
SkIRect* intersection, const SkImageFilter* imageFilter) {
SkIRect clipBounds;
if (!this->getClipDeviceBounds(&clipBounds)) {
@ -1098,7 +1098,7 @@ bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags,
r.roundOut(&ir);
// early exit if the layer's bounds are clipped out
if (!ir.intersect(clipBounds)) {
if (bounds_affects_clip(flags)) {
if (BoundsAffectsClip(saveLayerFlags)) {
fCachedLocalClipBoundsDirty = true;
fMCRec->fRasterClip.setEmpty();
}
@ -1109,7 +1109,7 @@ bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags,
}
SkASSERT(!ir.isEmpty());
if (bounds_affects_clip(flags)) {
if (BoundsAffectsClip(saveLayerFlags)) {
// Simplify the current clips since they will be applied properly during restore()
fCachedLocalClipBoundsDirty = true;
fClipStack->clipDevRect(ir, SkRegion::kReplace_Op);
@ -1122,29 +1122,53 @@ bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags,
return true;
}
int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) {
if (gIgnoreSaveLayerBounds) {
bounds = nullptr;
uint32_t SkCanvas::SaveFlagsToSaveLayerFlags(SaveFlags flags) {
uint32_t layerFlags = 0;
if (0 == (flags & kClipToLayer_SaveFlag)) {
layerFlags |= kDontClipToLayer_PrivateSaveLayerFlag;
}
SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag);
fSaveCount += 1;
this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, strategy);
return this->getSaveCount() - 1;
if (0 == (flags & kHasAlphaLayer_SaveFlag)) {
layerFlags |= kIsOpaque_SaveLayerFlag;
}
return layerFlags;
}
#ifdef SK_SUPPORT_LEGACY_SAVELAYERPARAMS
SkCanvas::SaveLayerStrategy SkCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
uint32_t flags = 0;
if (0 == (rec.fSaveLayerFlags & kDontClipToLayer_PrivateSaveLayerFlag)) {
flags |= kClipToLayer_SaveFlag;
}
if (0 == (rec.fSaveLayerFlags & kIsOpaque_SaveLayerFlag)) {
flags |= kHasAlphaLayer_SaveFlag;
}
return this->willSaveLayer(rec.fBounds, rec.fPaint, (SaveFlags)flags);
}
#endif
int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) {
return this->saveLayer(SaveLayerRec(bounds, paint, 0));
}
int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags) {
if (gIgnoreSaveLayerBounds) {
bounds = nullptr;
}
SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags);
fSaveCount += 1;
this->internalSaveLayer(bounds, paint, flags, strategy);
return this->getSaveCount() - 1;
return this->saveLayer(SaveLayerRec(bounds, paint, SaveFlagsToSaveLayerFlags(flags)));
}
int SkCanvas::saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) {
unsigned flags = kARGB_ClipLayer_SaveFlag | kPreserveLCDText_PrivateSaveFlag;
return this->saveLayer(bounds, paint, (SaveFlags)flags);
return this->saveLayer(SaveLayerRec(bounds, paint, kPreserveLCDText_SaveLayerFlag));
}
int SkCanvas::saveLayer(const SaveLayerRec& origRec) {
SaveLayerRec rec(origRec);
if (gIgnoreSaveLayerBounds) {
rec.fBounds = nullptr;
}
SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec);
fSaveCount += 1;
this->internalSaveLayer(rec, strategy);
return this->getSaveCount() - 1;
}
static void draw_filter_into_device(SkBaseDevice* src, SkImageFilter* filter, SkBaseDevice* dst) {
@ -1177,10 +1201,13 @@ static void draw_filter_into_device(SkBaseDevice* src, SkImageFilter* filter, Sk
c.drawBitmap(srcBM, 0, 0, &p);
}
void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags,
SaveLayerStrategy strategy) {
void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy strategy) {
const SkRect* bounds = rec.fBounds;
const SkPaint* paint = rec.fPaint;
SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags;
#ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
flags |= kClipToLayer_SaveFlag;
saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag;
#endif
// do this before we create the layer. We don't call the public save() since
@ -1190,7 +1217,7 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
fDeviceCMDirty = true;
SkIRect ir;
if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter() : nullptr)) {
if (!this->clipRectBounds(bounds, saveLayerFlags, &ir, paint ? paint->getImageFilter() : nullptr)) {
return;
}
@ -1200,7 +1227,7 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
return;
}
bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag);
bool isOpaque = SkToBool(saveLayerFlags & kIsOpaque_SaveLayerFlag);
SkPixelGeometry geo = fProps.pixelGeometry();
if (paint) {
// TODO: perhaps add a query to filters so we might preserve opaqueness...
@ -1221,7 +1248,7 @@ void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
bool forceSpriteOnRestore = false;
{
const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() ||
SkToBool(flags & kPreserveLCDText_PrivateSaveFlag);
(saveLayerFlags & kPreserveLCDText_SaveLayerFlag);
const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(info, usage, geo,
preserveLCDText, false);

View File

@ -51,7 +51,7 @@ enum DrawType {
RESTORE,
ROTATE,
SAVE,
SAVE_LAYER,
SAVE_LAYER_SAVEFLAGS_DEPRECATED,
SCALE,
SET_MATRIX,
SKEW,
@ -75,7 +75,9 @@ enum DrawType {
DRAW_IMAGE_NINE,
DRAW_IMAGE_RECT,
LAST_DRAWTYPE_ENUM = DRAW_IMAGE_RECT
SAVE_LAYER_SAVELAYERFLAGS,
LAST_DRAWTYPE_ENUM = SAVE_LAYER_SAVELAYERFLAGS,
};
// In the 'match' method, this constant will match any flavor of DRAW_BITMAP*

View File

@ -455,10 +455,17 @@ void SkPicturePlayback::handleOp(SkReader32* reader,
}
canvas->save();
break;
case SAVE_LAYER: {
case SAVE_LAYER_SAVEFLAGS_DEPRECATED: {
const SkRect* boundsPtr = get_rect_ptr(reader);
const SkPaint* paint = fPictureData->getPaint(reader);
canvas->saveLayer(boundsPtr, paint, (SkCanvas::SaveFlags) reader->readInt());
const SkCanvas::SaveFlags flags = (SkCanvas::SaveFlags)reader->readInt();
canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint,
SkCanvas::SaveFlagsToSaveLayerFlags(flags)));
} break;
case SAVE_LAYER_SAVELAYERFLAGS: {
const SkRect* boundsPtr = get_rect_ptr(reader);
const SkPaint* paint = fPictureData->getPaint(reader);
canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint, reader->readInt()));
} break;
case SCALE: {
SkScalar sx = reader->readScalar();

View File

@ -83,7 +83,7 @@ static inline size_t get_paint_offset(DrawType op, size_t opSize) {
0, // RESTORE - no paint
0, // ROTATE - no paint
0, // SAVE - no paint
0, // SAVE_LAYER - see below - this paint's location varies
0, // SAVE_LAYER_SAVEFLAGS_DEPRECATED - see below - this paint's location varies
0, // SCALE - no paint
0, // SET_MATRIX - no paint
0, // SKEW - no paint
@ -103,6 +103,7 @@ static inline size_t get_paint_offset(DrawType op, size_t opSize) {
1, // DRAW_ATLAS - right after op code
1, // DRAW_IMAGE_NINE - right after op code
1, // DRAW_IMAGE_RECT - right after op code
0, // SAVE_LAYER_SAVELAYERFLAGS - see below - this paint's location varies
};
static_assert(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, "need_to_be_in_sync");
@ -115,7 +116,8 @@ static inline size_t get_paint_offset(DrawType op, size_t opSize) {
overflow = sizeof(uint32_t);
}
if (SAVE_LAYER == op) {
SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != op);
if (SAVE_LAYER_SAVELAYERFLAGS == op) {
static const uint32_t kSaveLayerNoBoundsPaintOffset = 2 * kUInt32Size;
static const uint32_t kSaveLayerWithBoundsPaintOffset = 2 * kUInt32Size + sizeof(SkRect);
@ -151,14 +153,13 @@ void SkPictureRecord::recordSave() {
this->validate(initialOffset, size);
}
SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds,
const SkPaint* paint, SaveFlags flags) {
SkCanvas::SaveLayerStrategy SkPictureRecord::getSaveLayerStrategy(const SaveLayerRec& rec) {
// record the offset to us, making it non-positive to distinguish a save
// from a clip entry.
fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
this->recordSaveLayer(bounds, paint, flags);
this->recordSaveLayer(rec);
this->INHERITED::willSaveLayer(bounds, paint, flags);
(void)this->INHERITED::getSaveLayerStrategy(rec);
/* 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
clip starts out the size of the picture, which is often much larger
@ -167,25 +168,24 @@ SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds,
return kNoLayer_SaveLayerStrategy;
}
void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) {
void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) {
fContentInfo.onSaveLayer();
// op + bool for 'bounds'
size_t size = 2 * kUInt32Size;
if (bounds) {
size += sizeof(*bounds); // + rect
if (rec.fBounds) {
size += sizeof(*rec.fBounds); // + rect
}
// + paint index + flags
size += 2 * kUInt32Size;
SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size);
size_t initialOffset = this->addDraw(SAVE_LAYER, &size);
this->addRectPtr(bounds);
SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER, size) == fWriter.bytesWritten());
this->addPaintPtr(paint);
this->addInt(flags);
size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERFLAGS, &size);
this->addRectPtr(rec.fBounds);
SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER_SAVELAYERFLAGS, size) == fWriter.bytesWritten());
this->addPaintPtr(rec.fPaint);
this->addInt(rec.fSaveLayerFlags);
this->validate(initialOffset, size);
}
@ -321,7 +321,8 @@ void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t
// assert that the final offset value points to a save verb
uint32_t opSize;
DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize);
SkASSERT(SAVE == drawOp || SAVE_LAYER == drawOp);
SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != drawOp);
SkASSERT(SAVE == drawOp || SAVE_LAYER_SAVELAYERFLAGS == drawOp);
}
#endif
}

View File

@ -153,7 +153,7 @@ protected:
bool onPeekPixels(SkPixmap*) override { return false; }
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;
@ -218,7 +218,7 @@ protected:
size_t recordClipPath(int pathID, SkRegion::Op op, bool doAA);
size_t recordClipRegion(const SkRegion& region, SkRegion::Op op);
void recordSave();
void recordSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags);
void recordSaveLayer(const SaveLayerRec&);
void recordRestore(bool fillInSkips = true);
private:

View File

@ -78,7 +78,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());
DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags));
DRAW(SaveLayer, saveLayer(SkCanvas::SaveLayerRec(r.bounds, r.paint, r.saveLayerFlags)));
DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));
DRAW(Concat, concat(r.matrix));

View File

@ -336,10 +336,8 @@ void SkRecorder::willSave() {
APPEND(Save);
}
SkCanvas::SaveLayerStrategy SkRecorder::willSaveLayer(const SkRect* bounds,
const SkPaint* paint,
SkCanvas::SaveFlags flags) {
APPEND(SaveLayer, this->copy(bounds), this->copy(paint), flags);
SkCanvas::SaveLayerStrategy SkRecorder::getSaveLayerStrategy(const SaveLayerRec& rec) {
APPEND(SaveLayer, this->copy(rec.fBounds), this->copy(rec.fPaint), rec.fSaveLayerFlags);
return SkCanvas::kNoLayer_SaveLayerStrategy;
}

View File

@ -54,7 +54,7 @@ public:
void forgetRecord();
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override {}
void didRestore() override;

View File

@ -163,18 +163,17 @@ namespace SkRemote {
void willSave() override { fEncoder-> save(); }
void didRestore() override { fEncoder->restore(); }
SaveLayerStrategy willSaveLayer(const SkRect* bounds,
const SkPaint* paint,
SaveFlags flags) override {
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override {
SkPath path;
if (bounds) {
path.addRect(*bounds);
if (rec.fBounds) {
path.addRect(*rec.fBounds);
}
const SkPaint defaultPaint;
const SkPaint* paint = rec.fPaint;
if (!paint) {
paint = &defaultPaint;
}
fEncoder->saveLayer(this->id(path), this->commonIDs(*paint), flags);
fEncoder->saveLayer(this->id(path), this->commonIDs(*paint), rec.fSaveLayerFlags);
return kNoLayer_SaveLayerStrategy;
}
@ -500,11 +499,13 @@ namespace SkRemote {
void save() override { fCanvas->save(); }
void restore() override { fCanvas->restore(); }
void saveLayer(ID bounds, CommonIDs common, SkCanvas::SaveFlags flags) override {
void saveLayer(ID bounds, CommonIDs common, SkCanvas::SaveLayerFlags flags) override {
SkPaint paint;
this->applyCommon(common, &paint);
SkRect rect;
fCanvas->saveLayer(fPath.find(bounds).isRect(&rect) ? &rect : nullptr, &paint, flags);
fCanvas->saveLayer({ fPath.find(bounds).isRect(&rect) ? &rect : nullptr,
&paint, flags });
}
void setMatrix(ID matrix) override { fCanvas->setMatrix(fMatrix.find(matrix)); }
@ -684,7 +685,7 @@ namespace SkRemote {
void save() override { fWrapped-> save(); }
void restore() override { fWrapped->restore(); }
void saveLayer(ID bounds, CommonIDs common, SkCanvas::SaveFlags flags) override {
void saveLayer(ID bounds, CommonIDs common, SkCanvas::SaveLayerFlags flags) override {
fWrapped->saveLayer(bounds, common, flags);
}

View File

@ -91,7 +91,7 @@ namespace SkRemote {
virtual void save() = 0;
virtual void restore() = 0;
virtual void saveLayer(ID bounds, CommonIDs, SkCanvas::SaveFlags) = 0;
virtual void saveLayer(ID bounds, CommonIDs, uint32_t saveLayerFlags) = 0;
virtual void setMatrix(ID matrix) = 0;

View File

@ -335,7 +335,7 @@ static void save_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
static void saveLayer_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
unsigned flags = DrawOp_unpackFlags(op32);
SkCanvas::SaveFlags saveFlags = (SkCanvas::SaveFlags)DrawOp_unpackData(op32);
SkCanvas::SaveLayerFlags saveLayerFlags = DrawOp_unpackData(op32);
const SkRect* bounds = nullptr;
if (flags & kSaveLayer_HasBounds_DrawOpFlag) {
@ -345,7 +345,7 @@ static void saveLayer_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
if (flags & kSaveLayer_HasPaint_DrawOpFlag) {
paint = &state->paint();
}
canvas->saveLayer(bounds, paint, saveFlags);
canvas->saveLayer(SkCanvas::SaveLayerRec(bounds, paint, saveLayerFlags));
}
static void restore_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,

View File

@ -248,7 +248,7 @@ public:
protected:
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;
@ -542,29 +542,28 @@ void SkGPipeCanvas::willSave() {
this->INHERITED::willSave();
}
SkCanvas::SaveLayerStrategy SkGPipeCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags saveFlags) {
SkCanvas::SaveLayerStrategy SkGPipeCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
NOTIFY_SETUP(this);
size_t size = 0;
unsigned opFlags = 0;
if (bounds) {
if (rec.fBounds) {
opFlags |= kSaveLayer_HasBounds_DrawOpFlag;
size += sizeof(SkRect);
}
if (paint) {
if (rec.fPaint) {
opFlags |= kSaveLayer_HasPaint_DrawOpFlag;
this->writePaint(*paint);
this->writePaint(*rec.fPaint);
}
if (this->needOpBytes(size)) {
this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags);
if (bounds) {
fWriter.writeRect(*bounds);
this->writeOp(kSaveLayer_DrawOp, opFlags, rec.fSaveLayerFlags);
if (rec.fBounds) {
fWriter.writeRect(*rec.fBounds);
}
}
this->INHERITED::willSaveLayer(bounds, paint, saveFlags);
(void)this->INHERITED::getSaveLayerStrategy(rec);
// we don't create a layer
return kNoLayer_SaveLayerStrategy;
}

View File

@ -199,14 +199,14 @@ void SkDumpCanvas::willSave() {
this->INHERITED::willSave();
}
SkCanvas::SaveLayerStrategy SkDumpCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) {
SkCanvas::SaveLayerStrategy SkDumpCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
SkString str;
str.printf("saveLayer(0x%X)", flags);
if (bounds) {
str.printf("saveLayer(0x%X)", rec.fSaveLayerFlags);
if (rec.fBounds) {
str.append(" bounds");
toString(*bounds, &str);
toString(*rec.fBounds, &str);
}
const SkPaint* paint = rec.fPaint;
if (paint) {
if (paint->getAlpha() != 0xFF) {
str.appendf(" alpha:0x%02X", paint->getAlpha());
@ -216,7 +216,7 @@ SkCanvas::SaveLayerStrategy SkDumpCanvas::willSaveLayer(const SkRect* bounds, co
}
}
this->dump(kSave_Verb, paint, str.c_str());
return this->INHERITED::willSaveLayer(bounds, paint, flags);
return this->INHERITED::getSaveLayerStrategy(rec);
}
void SkDumpCanvas::willRestore() {

View File

@ -86,17 +86,16 @@ void SkLuaCanvas::willSave() {
this->INHERITED::willSave();
}
SkCanvas::SaveLayerStrategy SkLuaCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) {
SkCanvas::SaveLayerStrategy SkLuaCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
AUTO_LUA("saveLayer");
if (bounds) {
lua.pushRect(*bounds, "bounds");
if (rec.fBounds) {
lua.pushRect(*rec.fBounds, "bounds");
}
if (paint) {
lua.pushPaint(*paint, "paint");
if (rec.fPaint) {
lua.pushPaint(*rec.fPaint, "paint");
}
this->INHERITED::willSaveLayer(bounds, paint, flags);
(void)this->INHERITED::getSaveLayerStrategy(rec);
// No need for a layer.
return kNoLayer_SaveLayerStrategy;
}

View File

@ -66,14 +66,13 @@ void SkNWayCanvas::willSave() {
this->INHERITED::willSave();
}
SkCanvas::SaveLayerStrategy SkNWayCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) {
SkCanvas::SaveLayerStrategy SkNWayCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
Iter iter(fList);
while (iter.next()) {
iter->saveLayer(bounds, paint, flags);
iter->saveLayer(rec);
}
this->INHERITED::willSaveLayer(bounds, paint, flags);
this->INHERITED::getSaveLayerStrategy(rec);
// No need for a layer.
return kNoLayer_SaveLayerStrategy;
}

View File

@ -524,10 +524,9 @@ void SkDebugCanvas::willSave() {
this->INHERITED::willSave();
}
SkCanvas::SaveLayerStrategy SkDebugCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) {
this->addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags));
this->INHERITED::willSaveLayer(bounds, paint, flags);
SkCanvas::SaveLayerStrategy SkDebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
this->addDrawCommand(new SkSaveLayerCommand(rec));
(void)this->INHERITED::getSaveLayerStrategy(rec);
// No need for a full layer.
return kNoLayer_SaveLayerStrategy;
}

View File

@ -165,7 +165,7 @@ public:
protected:
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;

View File

@ -925,36 +925,35 @@ void SkSaveCommand::execute(SkCanvas* canvas) const {
canvas->save();
}
SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
SkCanvas::SaveFlags flags)
SkSaveLayerCommand::SkSaveLayerCommand(const SkCanvas::SaveLayerRec& rec)
: INHERITED(kSaveLayer_OpType) {
if (bounds) {
fBounds = *bounds;
if (rec.fBounds) {
fBounds = *rec.fBounds;
} else {
fBounds.setEmpty();
}
if (paint) {
fPaint = *paint;
if (rec.fPaint) {
fPaint = *rec.fPaint;
fPaintPtr = &fPaint;
} else {
fPaintPtr = nullptr;
}
fFlags = flags;
fSaveLayerFlags = rec.fSaveLayerFlags;
if (bounds) {
fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
if (rec.fBounds) {
fInfo.push(SkObjectParser::RectToString(*rec.fBounds, "Bounds: "));
}
if (paint) {
fInfo.push(SkObjectParser::PaintToString(*paint));
if (rec.fPaint) {
fInfo.push(SkObjectParser::PaintToString(*rec.fPaint));
}
fInfo.push(SkObjectParser::SaveFlagsToString(flags));
fInfo.push(SkObjectParser::SaveLayerFlagsToString(fSaveLayerFlags));
}
void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
canvas->saveLayer(fBounds.isEmpty() ? nullptr : &fBounds,
fPaintPtr,
fFlags);
canvas->saveLayer(SkCanvas::SaveLayerRec(fBounds.isEmpty() ? nullptr : &fBounds,
fPaintPtr,
fSaveLayerFlags));
}
void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {

View File

@ -551,8 +551,7 @@ private:
class SkSaveLayerCommand : public SkDrawCommand {
public:
SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint,
SkCanvas::SaveFlags flags);
SkSaveLayerCommand(const SkCanvas::SaveLayerRec&);
void execute(SkCanvas* canvas) const override;
void vizExecute(SkCanvas* canvas) const override;
Action action() const override{ return kPushLayer_Action; }
@ -562,12 +561,12 @@ public:
const SkPaint* paint() const { return fPaintPtr; }
private:
SkRect fBounds;
SkPaint fPaint;
SkPaint* fPaintPtr;
SkCanvas::SaveFlags fFlags;
SkRect fBounds;
SkPaint fPaint;
SkPaint* fPaintPtr;
uint32_t fSaveLayerFlags;
bool fActive;
bool fActive;
typedef SkDrawCommand INHERITED;
};

View File

@ -338,16 +338,13 @@ SkString* SkObjectParser::RegionToString(const SkRegion& region) {
return mRegion;
}
SkString* SkObjectParser::SaveFlagsToString(SkCanvas::SaveFlags flags) {
SkString* SkObjectParser::SaveLayerFlagsToString(SkCanvas::SaveLayerFlags saveLayerFlags) {
SkString* mFlags = new SkString("SkCanvas::SaveFlags: ");
if (flags & SkCanvas::kHasAlphaLayer_SaveFlag) {
mFlags->append("kHasAlphaLayer_SaveFlag ");
if (saveLayerFlags & SkCanvas::kIsOpaque_SaveLayerFlag) {
mFlags->append("kIsOpaque_SaveLayerFlag ");
}
if (flags & SkCanvas::kFullColorLayer_SaveFlag) {
mFlags->append("kFullColorLayer_SaveFlag ");
}
if (flags & SkCanvas::kClipToLayer_SaveFlag) {
mFlags->append("kClipToLayer_SaveFlag ");
if (saveLayerFlags & SkCanvas::kPreserveLCDText_SaveLayerFlag) {
mFlags->append("kPreserveLCDText_SaveLayerFlag ");
}
return mFlags;
}

View File

@ -110,10 +110,10 @@ public:
static SkString* RegionToString(const SkRegion& region);
/**
Returns a string representation of the SkCanvas::SaveFlags enum.
@param flags SkCanvas::SaveFlags enum
Returns a string representation of the SkCanvas::SaveLayerFlags enum.
@param flags SkCanvas::SaveLayerFlags enum
*/
static SkString* SaveFlagsToString(SkCanvas::SaveFlags flags);
static SkString* SaveLayerFlagsToString(uint32_t saveLayerFlags);
/**
Returns a string representation of an SkScalar with the text parameter

View File

@ -559,10 +559,9 @@ public:
, fRestoreCount(0){
}
virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) override {
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override {
++fSaveLayerCount;
return this->INHERITED::willSaveLayer(bounds, paint, flags);
return this->INHERITED::getSaveLayerStrategy(rec);
}
void willSave() override {