vjiaoblack 2016-08-23 07:50:52 -07:00 committed by Commit bot
parent bb51f4a3a7
commit a97a1ab571
8 changed files with 62 additions and 46 deletions

View File

@ -60,6 +60,7 @@
'<(skia_src_path)/core/SkBlitter_PM4f.cpp',
'<(skia_src_path)/core/SkBlitter_RGB16.cpp',
'<(skia_src_path)/core/SkBlitter_Sprite.cpp',
'<(skia_src_path)/core/SkBlurImageFilter.cpp',
'<(skia_src_path)/core/SkBuffer.cpp',
'<(skia_src_path)/core/SkCachedData.cpp',
'<(skia_src_path)/core/SkCanvas.cpp',
@ -139,6 +140,8 @@
'<(skia_src_path)/core/SkGlyphCache.cpp',
'<(skia_src_path)/core/SkGlyphCache.h',
'<(skia_src_path)/core/SkGlyphCache_Globals.h',
'<(skia_src_path)/core/SkGpuBlurUtils.h',
'<(skia_src_path)/core/SkGpuBlurUtils.cpp',
'<(skia_src_path)/core/SkGraphics.cpp',
'<(skia_src_path)/core/SkHalf.cpp',
'<(skia_src_path)/core/SkHalf.h',

View File

@ -26,7 +26,6 @@
'<(skia_src_path)/effects/SkBlurDrawLooper.cpp',
'<(skia_src_path)/effects/SkBlurMask.cpp',
'<(skia_src_path)/effects/SkBlurMask.h',
'<(skia_src_path)/effects/SkBlurImageFilter.cpp',
'<(skia_src_path)/effects/SkBlurMaskFilter.cpp',
'<(skia_src_path)/effects/SkColorCubeFilter.cpp',
'<(skia_src_path)/effects/SkColorFilterImageFilter.cpp',
@ -45,8 +44,6 @@
'<(skia_src_path)/effects/SkImageSource.cpp',
'<(skia_src_path)/effects/SkGammaColorFilter.cpp',
'<(skia_src_path)/effects/SkGaussianEdgeShader.cpp',
'<(skia_src_path)/effects/SkGpuBlurUtils.h',
'<(skia_src_path)/effects/SkGpuBlurUtils.cpp',
'<(skia_src_path)/effects/SkLayerDrawLooper.cpp',
'<(skia_src_path)/effects/SkLayerRasterizer.cpp',
'<(skia_src_path)/effects/SkLightingImageFilter.cpp',

View File

@ -152,6 +152,10 @@ public:
return this->isColorFilterNode(filterPtr);
}
static sk_sp<SkImageFilter> MakeBlur(SkScalar sigmaX, SkScalar sigmaY,
sk_sp<SkImageFilter> input,
const CropRect* cropRect = nullptr);
/**
* Returns true (and optionally returns a ref'd filter) if this imagefilter can be completely
* replaced by the returned colorfilter. i.e. the two effects will affect drawing in the
@ -229,6 +233,7 @@ public:
SK_TO_STRING_PUREVIRT()
SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
protected:
class Common {

View File

@ -9,40 +9,14 @@
#define SkBlurImageFilter_DEFINED
#include "SkImageFilter.h"
#include "SkSize.h"
class SK_API SkBlurImageFilter : public SkImageFilter {
class SK_API SkBlurImageFilter {
public:
static sk_sp<SkImageFilter> Make(SkScalar sigmaX, SkScalar sigmaY,
sk_sp<SkImageFilter> input,
const CropRect* cropRect = nullptr);
SkRect computeFastBounds(const SkRect&) const override;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurImageFilter)
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
static SkImageFilter* Create(SkScalar sigmaX, SkScalar sigmaY, SkImageFilter* input = nullptr,
const CropRect* cropRect = nullptr) {
return Make(sigmaX, sigmaY, sk_ref_sp<SkImageFilter>(input), cropRect).release();
const SkImageFilter::CropRect* cropRect = nullptr) {
return SkImageFilter::MakeBlur(sigmaX, sigmaY, input, cropRect);
}
#endif
protected:
void flatten(SkWriteBuffer&) const override;
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
SkIPoint* offset) const override;
SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override;
private:
SkBlurImageFilter(SkScalar sigmaX,
SkScalar sigmaY,
sk_sp<SkImageFilter> input,
const CropRect* cropRect);
SkSize fSigma;
typedef SkImageFilter INHERITED;
};
#endif

View File

@ -5,8 +5,6 @@
* found in the LICENSE file.
*/
#include "SkBlurImageFilter.h"
#include "SkAutoPixmapStorage.h"
#include "SkColorPriv.h"
#include "SkGpuBlurUtils.h"
@ -20,13 +18,52 @@
#include "SkGr.h"
#endif
sk_sp<SkImageFilter> SkBlurImageFilter::Make(SkScalar sigmaX, SkScalar sigmaY,
class SkBlurImageFilterImpl : public SkImageFilter {
public:
SkBlurImageFilterImpl(SkScalar sigmaX,
SkScalar sigmaY,
sk_sp<SkImageFilter> input,
const CropRect* cropRect);
SkRect computeFastBounds(const SkRect&) const override;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurImageFilterImpl)
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
static SkImageFilter* Create(SkScalar sigmaX, SkScalar sigmaY, SkImageFilter* input = nullptr,
const CropRect* cropRect = nullptr) {
return SkImageFilter::MakeBlur(sigmaX, sigmaY, sk_ref_sp<SkImageFilter>(input),
cropRect).release();
}
#endif
protected:
void flatten(SkWriteBuffer&) const override;
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
SkIPoint* offset) const override;
SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override;
private:
SkSize fSigma;
typedef SkImageFilter INHERITED;
friend class SkImageFilter;
};
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurImageFilterImpl)
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
///////////////////////////////////////////////////////////////////////////////
sk_sp<SkImageFilter> SkImageFilter::MakeBlur(SkScalar sigmaX, SkScalar sigmaY,
sk_sp<SkImageFilter> input,
const CropRect* cropRect) {
if (0 == sigmaX && 0 == sigmaY && !cropRect) {
return input;
}
return sk_sp<SkImageFilter>(new SkBlurImageFilter(sigmaX, sigmaY, input, cropRect));
return sk_sp<SkImageFilter>(new SkBlurImageFilterImpl(sigmaX, sigmaY, input, cropRect));
}
// This rather arbitrary-looking value results in a maximum box blur kernel size
@ -44,7 +81,7 @@ static SkVector map_sigma(const SkSize& localSigma, const SkMatrix& ctm) {
return sigma;
}
SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX,
SkBlurImageFilterImpl::SkBlurImageFilterImpl(SkScalar sigmaX,
SkScalar sigmaY,
sk_sp<SkImageFilter> input,
const CropRect* cropRect)
@ -52,14 +89,14 @@ SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX,
, fSigma(SkSize::Make(sigmaX, sigmaY)) {
}
sk_sp<SkFlattenable> SkBlurImageFilter::CreateProc(SkReadBuffer& buffer) {
sk_sp<SkFlattenable> SkBlurImageFilterImpl::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
SkScalar sigmaX = buffer.readScalar();
SkScalar sigmaY = buffer.readScalar();
return Make(sigmaX, sigmaY, common.getInput(0), &common.cropRect());
return SkImageFilter::MakeBlur(sigmaX, sigmaY, common.getInput(0), &common.cropRect());
}
void SkBlurImageFilter::flatten(SkWriteBuffer& buffer) const {
void SkBlurImageFilterImpl::flatten(SkWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.writeScalar(fSigma.fWidth);
buffer.writeScalar(fSigma.fHeight);
@ -80,7 +117,7 @@ static void get_box3_params(SkScalar s, int *kernelSize, int* kernelSize3, int *
}
}
sk_sp<SkSpecialImage> SkBlurImageFilter::onFilterImage(SkSpecialImage* source,
sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* source,
const Context& ctx,
SkIPoint* offset) const {
SkIPoint inputOffset = SkIPoint::Make(0, 0);
@ -231,14 +268,14 @@ sk_sp<SkSpecialImage> SkBlurImageFilter::onFilterImage(SkSpecialImage* source,
}
SkRect SkBlurImageFilter::computeFastBounds(const SkRect& src) const {
SkRect SkBlurImageFilterImpl::computeFastBounds(const SkRect& src) const {
SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src) : src;
bounds.outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)),
SkScalarMul(fSigma.height(), SkIntToScalar(3)));
return bounds;
}
SkIRect SkBlurImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatrix& ctm,
SkIRect SkBlurImageFilterImpl::onFilterNodeBounds(const SkIRect& src, const SkMatrix& ctm,
MapDirection) const {
SkVector sigma = map_sigma(fSigma, ctm);
return src.makeOutset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))),
@ -246,8 +283,8 @@ SkIRect SkBlurImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatrix
}
#ifndef SK_IGNORE_TO_STRING
void SkBlurImageFilter::toString(SkString* str) const {
str->appendf("SkBlurImageFilter: (");
void SkBlurImageFilterImpl::toString(SkString* str) const {
str->appendf("SkBlurImageFilterImpl: (");
str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight);
if (this->getInput(0)) {

View File

@ -102,7 +102,7 @@ void SkFlattenable::PrivateInitializer::InitEffects() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSumPathEffect)
// ImageFilter
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurImageFilter)
SkImageFilter::InitializeFlattenables();
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDilateImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDisplacementMapEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDropShadowImageFilter)