Add default ctor to SkMask

The minimal fix here seems to be handling BoxBlur's return value in SkBlurMaskFilter.cpp::GrRRectBlurEffect::Create. We seem to do enough special handling of the fImage field though that always initialializing it may not be a bad idea.

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

Review URL: https://codereview.chromium.org/1539553002
This commit is contained in:
robertphillips 2015-12-17 11:33:12 -08:00 committed by Commit bot
parent 1250944aaa
commit e80eb928ba
15 changed files with 48 additions and 57 deletions

View File

@ -63,7 +63,7 @@ protected:
preBenchSetup(r); preBenchSetup(r);
for (int i = 0; i < loops; i++) { for (int i = 0; i < loops; i++) {
makeBlurryRect(r); this->makeBlurryRect(r);
} }
} }
@ -90,8 +90,10 @@ class BlurRectDirectBench: public BlurRectBench {
protected: protected:
void makeBlurryRect(const SkRect& r) override { void makeBlurryRect(const SkRect& r) override {
SkMask mask; SkMask mask;
SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()), if (!SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()),
&mask, r, kNormal_SkBlurStyle); &mask, r, kNormal_SkBlurStyle)) {
return;
}
SkMask::FreeImage(mask.fImage); SkMask::FreeImage(mask.fImage);
} }
private: private:
@ -101,9 +103,7 @@ private:
class BlurRectSeparableBench: public BlurRectBench { class BlurRectSeparableBench: public BlurRectBench {
public: public:
BlurRectSeparableBench(SkScalar rad) : INHERITED(rad) { BlurRectSeparableBench(SkScalar rad) : INHERITED(rad) { }
fSrcMask.fImage = nullptr;
}
~BlurRectSeparableBench() { ~BlurRectSeparableBench() {
SkMask::FreeImage(fSrcMask.fImage); SkMask::FreeImage(fSrcMask.fImage);
@ -144,9 +144,10 @@ protected:
void makeBlurryRect(const SkRect&) override { void makeBlurryRect(const SkRect&) override {
SkMask mask; SkMask mask;
mask.fImage = nullptr; if (!SkBlurMask::BoxBlur(&mask, fSrcMask, SkBlurMask::ConvertRadiusToSigma(this->radius()),
SkBlurMask::BoxBlur(&mask, fSrcMask, SkBlurMask::ConvertRadiusToSigma(this->radius()), kNormal_SkBlurStyle, kHigh_SkBlurQuality)) {
kNormal_SkBlurStyle, kHigh_SkBlurQuality); return;
}
SkMask::FreeImage(mask.fImage); SkMask::FreeImage(mask.fImage);
} }
private: private:
@ -171,9 +172,10 @@ protected:
void makeBlurryRect(const SkRect&) override { void makeBlurryRect(const SkRect&) override {
SkMask mask; SkMask mask;
mask.fImage = nullptr; if (!SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radius()),
SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radius()), &mask, fSrcMask, kNormal_SkBlurStyle)) {
&mask, fSrcMask, kNormal_SkBlurStyle); return;
}
SkMask::FreeImage(mask.fImage); SkMask::FreeImage(mask.fImage);
} }
private: private:

View File

@ -199,7 +199,10 @@ DEF_SIMPLE_GM(blurrect_gallery, canvas, 1200, 1024) {
SkBlurStyle style = styles[k]; SkBlurStyle style = styles[k];
SkMask mask; SkMask mask;
SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(radius), &mask, r, style); if (!SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(radius),
&mask, r, style)) {
continue;
}
SkAutoMaskFreeImage amfi(mask.fImage); SkAutoMaskFreeImage amfi(mask.fImage);

View File

@ -17,6 +17,8 @@
the 3-channel 3D format. These are passed to SkMaskFilter objects. the 3-channel 3D format. These are passed to SkMaskFilter objects.
*/ */
struct SkMask { struct SkMask {
SkMask() : fImage(nullptr) {}
enum Format { enum Format {
kBW_Format, //!< 1bit per pixel mask (e.g. monochrome) kBW_Format, //!< 1bit per pixel mask (e.g. monochrome)
kA8_Format, //!< 8bits per pixel mask (e.g. antialiasing) kA8_Format, //!< 8bits per pixel mask (e.g. antialiasing)

View File

@ -184,9 +184,7 @@ protected:
class NinePatch : ::SkNoncopyable { class NinePatch : ::SkNoncopyable {
public: public:
NinePatch() : fCache(NULL) { NinePatch() : fCache(nullptr) { }
fMask.fImage = NULL;
}
~NinePatch(); ~NinePatch();
SkMask fMask; // fBounds must have [0,0] in its top-left SkMask fMask; // fBounds must have [0,0] in its top-left

View File

@ -29,8 +29,8 @@ public:
// This method is not exported to java. // This method is not exported to java.
SkMask::Format getFormat() const override; SkMask::Format getFormat() const override;
// This method is not exported to java. // This method is not exported to java.
virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
SkIPoint* margin) const override; SkIPoint* margin) const override;
SK_TO_STRING_OVERRIDE() SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmbossMaskFilter) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmbossMaskFilter)

View File

@ -2165,7 +2165,6 @@ void SkAAClipBlitter::blitMask(const SkMask& origMask, const SkIRect& clip) {
// if we're BW, we need to upscale to A8 (ugh) // if we're BW, we need to upscale to A8 (ugh)
SkMask grayMask; SkMask grayMask;
grayMask.fImage = nullptr;
if (SkMask::kBW_Format == origMask.fFormat) { if (SkMask::kBW_Format == origMask.fFormat) {
grayMask.fFormat = SkMask::kA8_Format; grayMask.fFormat = SkMask::kA8_Format;
grayMask.fBounds = origMask.fBounds; grayMask.fBounds = origMask.fBounds;

View File

@ -1033,7 +1033,6 @@ bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint,
// compute our (larger?) dst bounds if we have a filter // compute our (larger?) dst bounds if we have a filter
if (filter) { if (filter) {
identity.reset(); identity.reset();
srcM.fImage = nullptr;
if (!filter->filterMask(&dstM, srcM, identity, nullptr)) { if (!filter->filterMask(&dstM, srcM, identity, nullptr)) {
goto NO_FILTER_CASE; goto NO_FILTER_CASE;
} }

View File

@ -908,10 +908,8 @@ void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const {
SkMask dstM; SkMask dstM;
if (paint.getMaskFilter() && if (paint.getMaskFilter() &&
paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, nullptr)) { paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, nullptr)) {
mask = &dstM; mask = &dstM;
} else {
dstM.fImage = nullptr;
} }
SkAutoMaskFreeImage ami(dstM.fImage); SkAutoMaskFreeImage ami(dstM.fImage);
@ -2013,7 +2011,6 @@ static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds,
srcM.fBounds = *bounds; srcM.fBounds = *bounds;
srcM.fFormat = SkMask::kA8_Format; srcM.fFormat = SkMask::kA8_Format;
srcM.fImage = nullptr;
if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) {
return false; return false;
} }

View File

@ -349,7 +349,6 @@ bool SkMaskFilter::filterMaskGPU(GrTexture* src,
void SkMaskFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { void SkMaskFilter::computeFastBounds(const SkRect& src, SkRect* dst) const {
SkMask srcM, dstM; SkMask srcM, dstM;
srcM.fImage = nullptr;
srcM.fBounds = src.roundOut(); srcM.fBounds = src.roundOut();
srcM.fRowBytes = 0; srcM.fRowBytes = 0;
srcM.fFormat = SkMask::kA8_Format; srcM.fFormat = SkMask::kA8_Format;

View File

@ -23,7 +23,6 @@ bool SkRasterizer::rasterize(const SkPath& fillPath, const SkMatrix& matrix,
srcM.fFormat = SkMask::kA8_Format; srcM.fFormat = SkMask::kA8_Format;
srcM.fBounds.set(0, 0, 1, 1); srcM.fBounds.set(0, 0, 1, 1);
srcM.fImage = nullptr;
if (!filter->filterMask(&dstM, srcM, matrix, &margin)) { if (!filter->filterMask(&dstM, srcM, matrix, &margin)) {
return false; return false;
} }

View File

@ -1628,12 +1628,8 @@ void SkXPSDevice::drawPath(const SkDraw& d,
//[Mask -> Mask] //[Mask -> Mask]
SkMask filteredMask; SkMask filteredMask;
if (filter && if (filter && filter->filterMask(&filteredMask, *mask, *d.fMatrix, nullptr)) {
filter->filterMask(&filteredMask, *mask, *d.fMatrix, nullptr)) {
mask = &filteredMask; mask = &filteredMask;
} else {
filteredMask.fImage = nullptr;
} }
SkAutoMaskFreeImage filteredAmi(filteredMask.fImage); SkAutoMaskFreeImage filteredAmi(filteredMask.fImage);
@ -1675,13 +1671,8 @@ void SkXPSDevice::drawPath(const SkDraw& d,
//[Mask -> Mask] //[Mask -> Mask]
SkMask filteredMask; SkMask filteredMask;
if (filter->filterMask(&filteredMask, if (filter->filterMask(&filteredMask, rasteredMask, matrix, nullptr)) {
rasteredMask,
matrix,
nullptr)) {
mask = &filteredMask; mask = &filteredMask;
} else {
filteredMask.fImage = nullptr;
} }
SkAutoMaskFreeImage filteredAmi(filteredMask.fImage); SkAutoMaskFreeImage filteredAmi(filteredMask.fImage);

View File

@ -15,14 +15,14 @@
class SkBlurMask { class SkBlurMask {
public: public:
static bool BlurRect(SkScalar sigma, SkMask *dst, const SkRect &src, SkBlurStyle, static bool SK_WARN_UNUSED_RESULT BlurRect(SkScalar sigma, SkMask *dst, const SkRect &src,
SkIPoint *margin = nullptr, SkBlurStyle, SkIPoint *margin = nullptr,
SkMask::CreateMode createMode = SkMask::CreateMode createMode =
SkMask::kComputeBoundsAndRenderImage_CreateMode); SkMask::kComputeBoundsAndRenderImage_CreateMode);
static bool BlurRRect(SkScalar sigma, SkMask *dst, const SkRRect &src, SkBlurStyle, static bool SK_WARN_UNUSED_RESULT BlurRRect(SkScalar sigma, SkMask *dst, const SkRRect &src,
SkIPoint *margin = nullptr, SkBlurStyle, SkIPoint *margin = nullptr,
SkMask::CreateMode createMode = SkMask::CreateMode createMode =
SkMask::kComputeBoundsAndRenderImage_CreateMode); SkMask::kComputeBoundsAndRenderImage_CreateMode);
// forceQuality will prevent BoxBlur from falling back to the low quality approach when sigma // forceQuality will prevent BoxBlur from falling back to the low quality approach when sigma
// is very small -- this can be used predict the margin bump ahead of time without completely // is very small -- this can be used predict the margin bump ahead of time without completely
@ -30,14 +30,16 @@ public:
// but also being able to predict precisely at what pixels the blurred profile of e.g. a // but also being able to predict precisely at what pixels the blurred profile of e.g. a
// rectangle will lie. // rectangle will lie.
static bool BoxBlur(SkMask* dst, const SkMask& src, static bool SK_WARN_UNUSED_RESULT BoxBlur(SkMask* dst, const SkMask& src,
SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, SkScalar sigma, SkBlurStyle style, SkBlurQuality,
SkIPoint* margin = nullptr, bool force_quality=false); SkIPoint* margin = nullptr,
bool forceQuality = false);
// the "ground truth" blur does a gaussian convolution; it's slow // the "ground truth" blur does a gaussian convolution; it's slow
// but useful for comparison purposes. // but useful for comparison purposes.
static bool BlurGroundTruth(SkScalar sigma, SkMask* dst, const SkMask& src, SkBlurStyle, static bool SK_WARN_UNUSED_RESULT BlurGroundTruth(SkScalar sigma, SkMask* dst,
SkIPoint* margin = nullptr); const SkMask& src,
SkBlurStyle, SkIPoint* margin = nullptr);
// If radius > 0, return the corresponding sigma, else return 0 // If radius > 0, return the corresponding sigma, else return 0
static SkScalar ConvertRadiusToSigma(SkScalar radius); static SkScalar ConvertRadiusToSigma(SkScalar radius);

View File

@ -353,7 +353,6 @@ SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& ma
SkIPoint margin; SkIPoint margin;
SkMask srcM, dstM; SkMask srcM, dstM;
srcM.fBounds = rrect.rect().roundOut(); srcM.fBounds = rrect.rect().roundOut();
srcM.fImage = nullptr;
srcM.fFormat = SkMask::kA8_Format; srcM.fFormat = SkMask::kA8_Format;
srcM.fRowBytes = 0; srcM.fRowBytes = 0;
@ -473,7 +472,6 @@ SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count,
SkIPoint margin; SkIPoint margin;
SkMask srcM, dstM; SkMask srcM, dstM;
srcM.fBounds = rects[0].roundOut(); srcM.fBounds = rects[0].roundOut();
srcM.fImage = nullptr;
srcM.fFormat = SkMask::kA8_Format; srcM.fFormat = SkMask::kA8_Format;
srcM.fRowBytes = 0; srcM.fRowBytes = 0;
@ -989,8 +987,10 @@ const GrFragmentProcessor* GrRRectBlurEffect::Create(GrTextureProvider* texProvi
SkMask::kJustRenderImage_CreateMode, SkPaint::kFill_Style); SkMask::kJustRenderImage_CreateMode, SkPaint::kFill_Style);
SkMask blurredMask; SkMask blurredMask;
SkBlurMask::BoxBlur(&blurredMask, mask, sigma, kNormal_SkBlurStyle, kHigh_SkBlurQuality, if (!SkBlurMask::BoxBlur(&blurredMask, mask, sigma, kNormal_SkBlurStyle,
nullptr, true); kHigh_SkBlurQuality, nullptr, true)) {
return nullptr;
}
unsigned int texSide = smallRectSide + 2*blurRadius; unsigned int texSide = smallRectSide + 2*blurRadius;
GrSurfaceDesc texDesc; GrSurfaceDesc texDesc;

View File

@ -228,7 +228,6 @@ static void test_empty(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, clip1 == clip0); REPORTER_ASSERT(reporter, clip1 == clip0);
SkMask mask; SkMask mask;
mask.fImage = nullptr;
clip0.copyToMask(&mask); clip0.copyToMask(&mask);
REPORTER_ASSERT(reporter, nullptr == mask.fImage); REPORTER_ASSERT(reporter, nullptr == mask.fImage);
REPORTER_ASSERT(reporter, mask.fBounds.isEmpty()); REPORTER_ASSERT(reporter, mask.fBounds.isEmpty());

View File

@ -170,8 +170,9 @@ static void ground_truth_2d(int width, int height,
memset(src.fImage, 0xff, src.computeTotalImageSize()); memset(src.fImage, 0xff, src.computeTotalImageSize());
dst.fImage = nullptr; if (!SkBlurMask::BlurGroundTruth(sigma, &dst, src, kNormal_SkBlurStyle)) {
SkBlurMask::BlurGroundTruth(sigma, &dst, src, kNormal_SkBlurStyle); return;
}
int midX = dst.fBounds.centerX(); int midX = dst.fBounds.centerX();
int midY = dst.fBounds.centerY(); int midY = dst.fBounds.centerY();