refactor where we wrap clipshaders, in prep for gpu backend

Change-Id: I6040d1fb67911bbfdefd5f1ff968e7d11323763d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276281
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-03-10 19:50:25 -04:00 committed by Skia Commit-Bot
parent f97c018947
commit c2fe5ee2b3
6 changed files with 15 additions and 17 deletions

View File

@ -757,8 +757,8 @@ void SkBitmapDevice::onClipPath(const SkPath& path, SkClipOp op, bool aa) {
fRCStack.clipPath(this->localToDevice(), path, op, aa);
}
void SkBitmapDevice::onClipShader(sk_sp<SkShader> sh, SkClipOp op) {
fRCStack.clipShader(this->localToDevice(), std::move(sh), op);
void SkBitmapDevice::onClipShader(sk_sp<SkShader> sh) {
fRCStack.clipShader(std::move(sh));
}
void SkBitmapDevice::onClipRegion(const SkRegion& rgn, SkClipOp op) {

View File

@ -125,7 +125,7 @@ protected:
void onClipRect(const SkRect& rect, SkClipOp, bool aa) override;
void onClipRRect(const SkRRect& rrect, SkClipOp, bool aa) override;
void onClipPath(const SkPath& path, SkClipOp, bool aa) override;
void onClipShader(sk_sp<SkShader>, SkClipOp) override;
void onClipShader(sk_sp<SkShader>) override;
void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
void onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) override;
bool onClipIsAA() const override;

View File

@ -15,6 +15,7 @@
#include "include/core/SkShader.h"
#include "include/core/SkSurfaceProps.h"
#include "include/private/SkNoncopyable.h"
#include "src/shaders/SkShaderBase.h"
class SkBitmap;
struct SkDrawShadowRec;
@ -152,7 +153,11 @@ public:
this->onClipPath(path, op, aa);
}
void clipShader(sk_sp<SkShader> sh, SkClipOp op) {
this->onClipShader(std::move(sh), op);
sh = as_SB(sh)->makeWithCTM(this->localToDevice());
if (op == SkClipOp::kDifference) {
sh = as_SB(sh)->makeInvertAlpha();
}
this->onClipShader(std::move(sh));
}
void clipRegion(const SkRegion& region, SkClipOp op) {
this->onClipRegion(region, op);
@ -188,7 +193,7 @@ protected:
virtual void onClipRect(const SkRect& rect, SkClipOp, bool aa) {}
virtual void onClipRRect(const SkRRect& rrect, SkClipOp, bool aa) {}
virtual void onClipPath(const SkPath& path, SkClipOp, bool aa) {}
virtual void onClipShader(sk_sp<SkShader>, SkClipOp) {}
virtual void onClipShader(sk_sp<SkShader>) {}
virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp) {}
virtual void onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) {}
virtual bool onClipIsAA() const = 0;

View File

@ -347,20 +347,13 @@ bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) {
return this->updateCacheAndReturnNonEmpty();
}
bool SkRasterClip::op(sk_sp<SkShader> sh, const SkMatrix& ctm, SkRegion::Op op) {
bool SkRasterClip::op(sk_sp<SkShader> sh) {
AUTO_RASTERCLIP_VALIDATE(*this);
sh = as_SB(sh)->makeWithCTM(ctm);
if (!fShader) {
if (op != SkRegion::kIntersect_Op) {
sh = as_SB(sh)->makeInvertAlpha();
}
fShader = sh;
} else {
SkBlendMode mode = (op == SkRegion::kIntersect_Op) ?
SkBlendMode::kSrcIn :
SkBlendMode::kSrcOut;
fShader = SkShaders::Blend(mode, sh, fShader);
fShader = SkShaders::Blend(SkBlendMode::kSrcIn, sh, fShader);
}
return !this->isEmpty();
}

View File

@ -98,7 +98,7 @@ public:
bool op(const SkRect&, const SkMatrix& matrix, const SkIRect&, SkRegion::Op, bool doAA);
bool op(const SkRRect&, const SkMatrix& matrix, const SkIRect&, SkRegion::Op, bool doAA);
bool op(const SkPath&, const SkMatrix& matrix, const SkIRect&, SkRegion::Op, bool doAA);
bool op(sk_sp<SkShader>, const SkMatrix&, SkRegion::Op);
bool op(sk_sp<SkShader>);
void translate(int dx, int dy, SkRasterClip* dst) const;
void translate(int dx, int dy) {

View File

@ -117,8 +117,8 @@ public:
this->validate();
}
void clipShader(const SkMatrix& ctm, sk_sp<SkShader> sh, SkClipOp op) {
this->writable_rc().op(std::move(sh), ctm, (SkRegion::Op)op);
void clipShader(sk_sp<SkShader> sh) {
this->writable_rc().op(std::move(sh));
this->validate();
}