SaveLayerRec::fClipMask -> raw pointer

Use raw pointers for optional clip mask plumbing, to match the backdrop
API.

Change-Id: I7eb0ee5896faf34cc05789ba0703f35a4ab6a4f2
Reviewed-on: https://skia-review.googlesource.com/14901
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2017-05-01 12:17:12 -04:00 committed by Skia Commit-Bot
parent 5664e65eb1
commit a6b72cb572
14 changed files with 26 additions and 23 deletions

View File

@ -210,8 +210,8 @@ DEF_SIMPLE_GM(savelayer_clipmask, canvas, 1200, 1200) {
rec.fPaint = &layerPaint;
for (const auto& maskMaker : kMaskMakers) {
maskMaker(kSize);
rec.fClipMask = maskMaker(kSize);
sk_sp<SkImage> mask = maskMaker(kSize);
rec.fClipMask = mask.get();
canvas->save();
for (const auto cfg : kConfigs) {

View File

@ -336,8 +336,10 @@ public:
, fBackdrop(backdrop)
, fSaveLayerFlags(saveLayerFlags)
{}
// EXPERIMENTAL: not ready for general use.
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
sk_sp<SkImage> clipMask, const SkMatrix* clipMatrix,
const SkImage* clipMask, const SkMatrix* clipMatrix,
SaveLayerFlags saveLayerFlags)
: fBounds(bounds)
, fPaint(paint)
@ -350,7 +352,7 @@ public:
const SkRect* fBounds = nullptr; // optional
const SkPaint* fPaint = nullptr; // optional
const SkImageFilter* fBackdrop = nullptr; // optional
sk_sp<SkImage> fClipMask; // optional
const SkImage* fClipMask = nullptr; // optional
const SkMatrix* fClipMatrix = nullptr; // optional -- only used with fClipMask
SaveLayerFlags fSaveLayerFlags = 0;
};

View File

@ -180,7 +180,7 @@ RECORD(SaveLayer, kHasPaint_Tag,
Optional<SkRect> bounds;
Optional<SkPaint> paint;
sk_sp<const SkImageFilter> backdrop;
sk_sp<SkImage> clipMask;
sk_sp<const SkImage> clipMask;
Optional<SkMatrix> clipMatrix;
SkCanvas::SaveLayerFlags saveLayerFlags);

View File

@ -257,12 +257,12 @@ struct DeviceCM {
SkMatrix fClipMatrix;
DeviceCM(sk_sp<SkBaseDevice> device, const SkPaint* paint, const SkMatrix& stashed,
sk_sp<SkImage> clipImage, const SkMatrix* clipMatrix)
const SkImage* clipImage, const SkMatrix* clipMatrix)
: fNext(nullptr)
, fDevice(std::move(device))
, fPaint(paint ? skstd::make_unique<SkPaint>(*paint) : nullptr)
, fStashedMatrix(stashed)
, fClipImage(std::move(clipImage))
, fClipImage(sk_ref_sp(const_cast<SkImage*>(clipImage)))
, fClipMatrix(clipMatrix ? *clipMatrix : SkMatrix::I())
{}

View File

@ -229,12 +229,12 @@ public:
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override {
sk_sp<SkImageFilter> backdrop = rec.fBackdrop ? fXformer->apply(rec.fBackdrop) : nullptr;
sk_sp<SkImage> clipMask = rec.fClipMask ? fXformer->apply(rec.fClipMask.get()) : nullptr;
sk_sp<SkImage> clipMask = rec.fClipMask ? fXformer->apply(rec.fClipMask) : nullptr;
fTarget->saveLayer({
rec.fBounds,
MaybePaint(rec.fPaint, fXformer.get()),
backdrop.get(),
std::move(clipMask),
clipMask.get(),
rec.fClipMatrix,
rec.fSaveLayerFlags,
});

View File

@ -91,23 +91,23 @@ namespace {
struct SaveLayer final : Op {
static const auto kType = Type::SaveLayer;
SaveLayer(const SkRect* bounds, const SkPaint* paint,
const SkImageFilter* backdrop, sk_sp<SkImage> clipMask,
const SkImageFilter* backdrop, const SkImage* clipMask,
const SkMatrix* clipMatrix, SkCanvas::SaveLayerFlags flags) {
if (bounds) { this->bounds = *bounds; }
if (paint) { this->paint = *paint; }
this->backdrop = sk_ref_sp(backdrop);
this->clipMask = std::move(clipMask);
this->clipMask = sk_ref_sp(clipMask);
this->clipMatrix = clipMatrix ? *clipMatrix : SkMatrix::I();
this->flags = flags;
}
SkRect bounds = kUnset;
SkPaint paint;
sk_sp<const SkImageFilter> backdrop;
sk_sp<SkImage> clipMask;
sk_sp<const SkImage> clipMask;
SkMatrix clipMatrix;
SkCanvas::SaveLayerFlags flags;
void draw(SkCanvas* c, const SkMatrix&) const {
c->saveLayer({ maybe_unset(bounds), &paint, backdrop.get(), clipMask,
c->saveLayer({ maybe_unset(bounds), &paint, backdrop.get(), clipMask.get(),
clipMatrix.isIdentity() ? nullptr : &clipMatrix, flags });
}
};
@ -550,9 +550,9 @@ void SkLiteDL::setDrawFilter(SkDrawFilter* df) {
void SkLiteDL:: save() { this->push <Save>(0); }
void SkLiteDL::restore() { this->push<Restore>(0); }
void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint,
const SkImageFilter* backdrop, sk_sp<SkImage> clipMask,
const SkImageFilter* backdrop, const SkImage* clipMask,
const SkMatrix* clipMatrix, SkCanvas::SaveLayerFlags flags) {
this->push<SaveLayer>(0, bounds, paint, backdrop, std::move(clipMask), clipMatrix, flags);
this->push<SaveLayer>(0, bounds, paint, backdrop, clipMask, clipMatrix, flags);
}
void SkLiteDL:: concat(const SkMatrix& matrix) { this->push <Concat>(0, matrix); }

View File

@ -29,7 +29,7 @@ public:
#endif
void save();
void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, sk_sp<SkImage>,
void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, const SkImage*,
const SkMatrix*, SkCanvas::SaveLayerFlags);
void restore();

View File

@ -744,7 +744,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
rec.fSaveLayerFlags = reader->readInt();
}
if (flatFlags & SAVELAYERREC_HAS_CLIPMASK) {
rec.fClipMask = sk_ref_sp(const_cast<SkImage*>(fPictureData->getImage(reader)));
rec.fClipMask = fPictureData->getImage(reader);
}
if (flatFlags & SAVELAYERREC_HAS_CLIPMATRIX) {
reader->readMatrix(&clipMatrix);

View File

@ -125,7 +125,7 @@ void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) {
this->addInt(rec.fSaveLayerFlags);
}
if (flatFlags & SAVELAYERREC_HAS_CLIPMASK) {
this->addImage(rec.fClipMask.get());
this->addImage(rec.fClipMask);
}
if (flatFlags & SAVELAYERREC_HAS_CLIPMATRIX) {
this->addMatrix(*rec.fClipMatrix);

View File

@ -77,7 +77,7 @@ DRAW(Save, save());
DRAW(SaveLayer, saveLayer(SkCanvas::SaveLayerRec(r.bounds,
r.paint,
r.backdrop.get(),
r.clipMask,
r.clipMask.get(),
r.clipMatrix,
r.saveLayerFlags)));
DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));

View File

@ -366,7 +366,7 @@ SkCanvas::SaveLayerStrategy SkRecorder::getSaveLayerStrategy(const SaveLayerRec&
APPEND(SaveLayer, this->copy(rec.fBounds)
, this->copy(rec.fPaint)
, sk_ref_sp(rec.fBackdrop)
, rec.fClipMask
, sk_ref_sp(rec.fClipMask)
, this->copy(rec.fClipMatrix)
, rec.fSaveLayerFlags);
return SkCanvas::kNoLayer_SaveLayerStrategy;

View File

@ -258,7 +258,7 @@ SkCanvas::SaveLayerStrategy SkPipeCanvas::getSaveLayerStrategy(const SaveLayerRe
writer.writeFlattenable(rec.fBackdrop);
}
if (rec.fClipMask) {
writer.writeImage(rec.fClipMask.get());
writer.writeImage(rec.fClipMask);
}
if (rec.fClipMatrix) {
writer.writeMatrix(*rec.fClipMatrix);

View File

@ -259,7 +259,7 @@ static void saveLayer_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanva
flags |= (1 << 31);//SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag;
}
canvas->saveLayer(SkCanvas::SaveLayerRec(bounds, paint, backdrop.get(), std::move(clipMask),
canvas->saveLayer(SkCanvas::SaveLayerRec(bounds, paint, backdrop.get(), clipMask.get(),
(extra & kHasClipMatrix_SaveLayerMask) ? &clipMatrix : nullptr, flags));
}

View File

@ -198,7 +198,8 @@ DEF_TEST(RecordOpts_NoopSaveLayerDrawRestore, r) {
// saveLayer w/ clip mask should also NOT go away
{
sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(10, 10));
recorder.saveLayer({ nullptr, nullptr, nullptr, surface->makeImageSnapshot(), nullptr, 0});
recorder.saveLayer({ nullptr, nullptr, nullptr, surface->makeImageSnapshot().get(),
nullptr, 0});
recorder.drawRect(draw, opaqueDrawPaint);
recorder.restore();
assert_savelayer_draw_restore(r, &record, 21, false);