SkBlurDrawLooper: Start by deleting flags

Android is the only user of this looper.  They never pass any flags.

BUG=skia:

Change-Id: I87b02ef7bc0ed94bca82637d60adddf34575a3e6
Reviewed-on: https://skia-review.googlesource.com/10057
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Matt Sarett 2017-03-23 16:23:38 -04:00 committed by Skia Commit-Bot
parent 9827256c8a
commit f160ad4d76
6 changed files with 24 additions and 125 deletions

View File

@ -77,10 +77,7 @@ protected:
p.setAntiAlias(true);
p.setLooper(SkBlurDrawLooper::Make(SK_ColorBLUE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag));
SkIntToScalar(5), SkIntToScalar(10)));
fPaints.push_back(p);
}

View File

@ -93,10 +93,7 @@ protected:
p.setAntiAlias(true);
p.setLooper(SkBlurDrawLooper::Make(SK_ColorWHITE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag));
SkIntToScalar(5), SkIntToScalar(10)));
fPaints.push_back(p);
}

View File

@ -60,32 +60,19 @@ protected:
sk_sp<SkDrawLooper> shadowLoopers[] = {
SkBlurDrawLooper::Make(SK_ColorBLUE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag),
SkIntToScalar(5), SkIntToScalar(10)),
SkBlurDrawLooper::Make(SK_ColorBLUE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag),
SkIntToScalar(5), SkIntToScalar(10)),
SkBlurDrawLooper::Make(SK_ColorBLACK,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
SkIntToScalar(5),
SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag),
SkIntToScalar(10)),
SkBlurDrawLooper::Make(0x7FFF0000,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
SkIntToScalar(-5), SkIntToScalar(-10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag),
SkIntToScalar(-5), SkIntToScalar(-10)),
SkBlurDrawLooper::Make(SK_ColorBLACK, SkIntToScalar(0),
SkIntToScalar(5), SkIntToScalar(5),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag),
SkIntToScalar(5), SkIntToScalar(5)),
};
constexpr struct {

View File

@ -23,22 +23,8 @@ class SkColorFilter;
*/
class SK_API SkBlurDrawLooper : public SkDrawLooper {
public:
enum BlurFlags {
kNone_BlurFlag = 0x00,
/**
The blur layer's dx/dy/radius aren't affected by the canvas
transform.
*/
kIgnoreTransform_BlurFlag = 0x01,
kOverrideColor_BlurFlag = 0x02,
kHighQuality_BlurFlag = 0x04,
/** mask for all blur flags */
kAll_BlurFlag = 0x07
};
static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
uint32_t flags = kNone_BlurFlag) {
return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy, flags));
static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy) {
return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy));
}
SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc*) const override;
@ -47,8 +33,7 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
protected:
SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
uint32_t flags);
SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy);
void flatten(SkWriteBuffer&) const override;
@ -56,10 +41,8 @@ protected:
private:
sk_sp<SkMaskFilter> fBlur;
sk_sp<SkColorFilter> fColorFilter;
SkScalar fDx, fDy, fSigma;
SkColor fBlurColor;
uint32_t fBlurFlags;
enum State {
kBeforeEdge,
@ -78,7 +61,7 @@ private:
State fState;
};
void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags);
void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color);
void initEffects();
typedef SkDrawLooper INHERITED;

View File

@ -19,45 +19,25 @@
#include "SkStringUtils.h"
SkBlurDrawLooper::SkBlurDrawLooper(SkColor color, SkScalar sigma,
SkScalar dx, SkScalar dy, uint32_t flags) {
this->init(sigma, dx, dy, color, flags);
SkScalar dx, SkScalar dy) {
this->init(sigma, dx, dy, color);
}
// only call from constructor
void SkBlurDrawLooper::initEffects() {
SkASSERT(fBlurFlags <= kAll_BlurFlag);
if (fSigma > 0) {
uint32_t flags = fBlurFlags & kIgnoreTransform_BlurFlag ?
SkBlurMaskFilter::kIgnoreTransform_BlurFlag :
SkBlurMaskFilter::kNone_BlurFlag;
flags |= fBlurFlags & kHighQuality_BlurFlag ?
SkBlurMaskFilter::kHighQuality_BlurFlag :
SkBlurMaskFilter::kNone_BlurFlag;
fBlur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, fSigma, flags);
fBlur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, fSigma,
SkBlurMaskFilter::kNone_BlurFlag);
} else {
fBlur = nullptr;
}
if (fBlurFlags & kOverrideColor_BlurFlag) {
// Set alpha to 1 for the override since transparency will already
// be baked into the blurred mask.
SkColor opaqueColor = SkColorSetA(fBlurColor, 255);
//The SrcIn xfer mode will multiply 'color' by the incoming alpha
fColorFilter = SkColorFilter::MakeModeFilter(opaqueColor, SkBlendMode::kSrcIn);
} else {
fColorFilter = nullptr;
}
}
void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy,
SkColor color, uint32_t flags) {
void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color) {
fSigma = sigma;
fDx = dx;
fDy = dy;
fBlurColor = color;
fBlurFlags = flags;
this->initEffects();
}
@ -67,8 +47,7 @@ sk_sp<SkFlattenable> SkBlurDrawLooper::CreateProc(SkReadBuffer& buffer) {
const SkScalar sigma = buffer.readScalar();
const SkScalar dx = buffer.readScalar();
const SkScalar dy = buffer.readScalar();
const uint32_t flags = buffer.read32();
return Make(color, sigma, dx, dy, flags);
return Make(color, sigma, dx, dy);
}
void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
@ -76,11 +55,10 @@ void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
buffer.writeScalar(fSigma);
buffer.writeScalar(fDx);
buffer.writeScalar(fDy);
buffer.write32(fBlurFlags);
}
bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
if (fSigma <= 0 || (fBlurFlags & fBlurFlags & kIgnoreTransform_BlurFlag)) {
if (fSigma <= 0) {
return false;
}
@ -89,8 +67,7 @@ bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
rec->fColor = fBlurColor;
rec->fOffset.set(fDx, fDy);
rec->fStyle = kNormal_SkBlurStyle;
rec->fQuality = (fBlurFlags & kHighQuality_BlurFlag) ?
kHigh_SkBlurQuality : kLow_SkBlurQuality;
rec->fQuality = kLow_SkBlurQuality;
}
return true;
}
@ -126,15 +103,8 @@ bool SkBlurDrawLooper::BlurDrawLooperContext::next(SkCanvas* canvas,
paint->setColor(fLooper->fBlurColor);
#endif
paint->setMaskFilter(fLooper->fBlur);
paint->setColorFilter(fLooper->fColorFilter);
canvas->save();
if (fLooper->fBlurFlags & kIgnoreTransform_BlurFlag) {
SkMatrix transform(canvas->getTotalMatrix());
transform.postTranslate(fLooper->fDx, fLooper->fDy);
canvas->setMatrix(transform);
} else {
canvas->translate(fLooper->fDx, fLooper->fDy);
}
fState = kAfterEdge;
return true;
case kAfterEdge:
@ -160,19 +130,7 @@ void SkBlurDrawLooper::toString(SkString* str) const {
str->append(" color: ");
str->appendHex(fBlurColor);
str->append(" flags: (");
if (kNone_BlurFlag == fBlurFlags) {
str->append("None");
} else {
bool needsSeparator = false;
SkAddFlagToString(str, SkToBool(kIgnoreTransform_BlurFlag & fBlurFlags), "IgnoreTransform",
&needsSeparator);
SkAddFlagToString(str, SkToBool(kOverrideColor_BlurFlag & fBlurFlags), "OverrideColor",
&needsSeparator);
SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "HighQuality",
&needsSeparator);
}
str->append(")");
str->append(" flags: (None)");
// TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toString is added
// alternatively we could cache the radius in SkBlurDrawLooper and just add it here

View File

@ -383,24 +383,6 @@ static SkBlurQuality blurMaskFilterFlags_as_quality(uint32_t blurMaskFilterFlags
kHigh_SkBlurQuality : kLow_SkBlurQuality;
}
static uint32_t blurMaskFilterFlags_to_blurDrawLooperFlags(uint32_t bmf) {
const struct {
uint32_t fBlurMaskFilterFlag;
uint32_t fBlurDrawLooperFlag;
} pairs[] = {
{ SkBlurMaskFilter::kIgnoreTransform_BlurFlag, SkBlurDrawLooper::kIgnoreTransform_BlurFlag },
{ SkBlurMaskFilter::kHighQuality_BlurFlag, SkBlurDrawLooper::kHighQuality_BlurFlag },
};
uint32_t bdl = 0;
for (size_t i = 0; i < SK_ARRAY_COUNT(pairs); ++i) {
if (bmf & pairs[i].fBlurMaskFilterFlag) {
bdl |= pairs[i].fBlurDrawLooperFlag;
}
}
return bdl;
}
static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
SkBlurStyle style, uint32_t blurMaskFilterFlags) {
if (kNormal_SkBlurStyle != style) {
@ -410,13 +392,8 @@ static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
const SkColor color = 0xFF335577;
const SkScalar dx = 10;
const SkScalar dy = -5;
const SkBlurQuality quality = blurMaskFilterFlags_as_quality(blurMaskFilterFlags);
uint32_t flags = blurMaskFilterFlags_to_blurDrawLooperFlags(blurMaskFilterFlags);
sk_sp<SkDrawLooper> lp(SkBlurDrawLooper::Make(color, sigma, dx, dy, flags));
const bool expectSuccess = sigma > 0 &&
0 == (flags & SkBlurDrawLooper::kIgnoreTransform_BlurFlag);
sk_sp<SkDrawLooper> lp(SkBlurDrawLooper::Make(color, sigma, dx, dy));
const bool expectSuccess = sigma > 0;
if (nullptr == lp) {
REPORTER_ASSERT(reporter, sigma <= 0);
@ -430,7 +407,7 @@ static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
REPORTER_ASSERT(reporter, rec.fOffset.y() == dy);
REPORTER_ASSERT(reporter, rec.fColor == color);
REPORTER_ASSERT(reporter, rec.fStyle == style);
REPORTER_ASSERT(reporter, rec.fQuality == quality);
REPORTER_ASSERT(reporter, rec.fQuality == kLow_SkBlurQuality);
}
}
}