diff options
author | Mike Reed <reed@google.com> | 2017-07-13 17:16:34 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-13 17:16:43 +0000 |
commit | 771ae9682f25ea23de32f85be0d3239ad5acec30 (patch) | |
tree | 164473ef2e010ff285eab04027b9739e6da5adc8 /src/core/SkMaskBlurFilter.h | |
parent | b4d6106345358df0e95845d7ac27e773e793057d (diff) |
Revert "Revert "Experimental blur code with 32 bit fix.""
This reverts commit 27b3d272a8fcce24813212f5816b177090111ec6.
Reason for revert: guard has landed in android
Original change's description:
> Revert "Experimental blur code with 32 bit fix."
>
> This reverts commit d4b2c537d058ad4cb890ba116d00aa86c3416c08.
>
> Reason for revert: speculative fix for android-roll
>
> java.lang.AssertionError: expected:<0> but was:<255>
> at org.junit.Assert.fail(Assert.java:88)
> at org.junit.Assert.failNotEquals(Assert.java:834)
> at org.junit.Assert.assertEquals(Assert.java:645)
> at org.junit.Assert.assertEquals(Assert.java:631)
> at android.graphics.cts.BlurMaskFilterTest.verifyColor(BlurMaskFilterTest.java:79)
> at android.graphics.cts.BlurMaskFilterTest.verifyQuadrants(BlurMaskFilterTest.java:72)
> at android.graphics.cts.BlurMaskFilterTest.testBlurMaskFilter(BlurMaskFilterTest.java:56)
>
> Original change's description:
> > Experimental blur code with 32 bit fix.
> >
> > This uses a new method of blurring that runs the three
> > passes of the box filter in a single pass. This implementation
> > currently only does 1x1 pixel at a time, but it should be simple
> > to expand to 4x4 pixels at a time.
> >
> > On the blur_10_normal_high_quality benchmark, the new is 7% faster
> > than the old code. For the blur_100.50_normal_high_quality
> > benchmark, the new code is 11% slower.
> >
> > Bug: skia:
> > Change-Id: I847270906b0ceac1dfbf43ab5446756689ef660f
> > Reviewed-on: https://skia-review.googlesource.com/22700
> > Reviewed-by: Mike Reed <reed@google.com>
> > Commit-Queue: Herb Derby <herb@google.com>
>
> TBR=herb@google.com,reed@google.com
>
> Change-Id: Ie84f6bf8872cae08c06d679f0c2f2e6c3d8a02a2
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/22880
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>
TBR=herb@google.com,reed@google.com
Change-Id: I393d1c05f83ccf98137201bc7b4e7d8e8b0e8742
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/23121
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core/SkMaskBlurFilter.h')
-rw-r--r-- | src/core/SkMaskBlurFilter.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/core/SkMaskBlurFilter.h b/src/core/SkMaskBlurFilter.h new file mode 100644 index 0000000000..9becadca39 --- /dev/null +++ b/src/core/SkMaskBlurFilter.h @@ -0,0 +1,67 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkBlurMaskFilter_DEFINED +#define SkBlurMaskFilter_DEFINED + +#include <algorithm> +#include <memory> + +#include "SkMask.h" +#include "SkTypes.h" + +// Implement a single channel Gaussian blur. The specifics for implementation are taken from: +// https://drafts.fxtf.org/filters/#feGaussianBlurElement +class SkMaskBlurFilter { +public: + // Given a filter specified by sigma, generate various quantities. + class FilterInfo { + public: + explicit FilterInfo(double sigma); + + // The final weight to divide by given a box size calculated from sigma accumulated for + // all three passes. For example, if the box size is 5, then the final weight for all + // three passes is 5^3 or 125. + uint64_t weight() const; + + // The distance between the first value of the dst and the first value of the src. + uint32_t borderSize() const; + + // The size of the box filter. + size_t diameter(uint8_t) const; + + // A factor used to simulate division using multiplication and shift. + uint64_t scaledWeight() const; + + private: + const uint32_t fFilterWindow; + const uint64_t fScaledWeight; + }; + + // Create an object suitable for filtering an SkMask using a filter with width sigmaW and + // height sigmaH. + SkMaskBlurFilter(double sigmaW, double sigmaH); + + // Given a src SkMask, generate dst SkMask returning the border width and height. + SkIPoint blur(const SkMask& src, SkMask* dst) const; + +private: + size_t bufferSize(uint8_t bufferPass) const; + + void blurOneScan(FilterInfo gen, + const uint8_t* src, size_t srcStride, const uint8_t* srcEnd, + uint8_t* dst, size_t dstStride, uint8_t* dstEnd) const; + + + const FilterInfo fInfoW, + fInfoH; + std::unique_ptr<uint32_t[]> fBuffer0, + fBuffer1, + fBuffer2; +}; + +#endif // SkBlurMaskFilter_DEFINED |