diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/effects/SkGaussianEdgeShader.cpp | 95 | ||||
-rw-r--r-- | src/effects/SkGaussianEdgeShader.h | 27 | ||||
-rw-r--r-- | src/ports/SkGlobalInitialization_default.cpp | 2 |
3 files changed, 124 insertions, 0 deletions
diff --git a/src/effects/SkGaussianEdgeShader.cpp b/src/effects/SkGaussianEdgeShader.cpp new file mode 100644 index 0000000000..c710b949d3 --- /dev/null +++ b/src/effects/SkGaussianEdgeShader.cpp @@ -0,0 +1,95 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkGaussianEdgeShader.h" +#include "SkReadBuffer.h" +#include "SkWriteBuffer.h" + +class SkArenaAlloc; + + /** \class SkGaussianEdgeShaderImpl + This subclass of shader applies a Gaussian to shadow edge + + If the primitive supports an implicit distance to the edge, the radius of the blur is specified + by r & g values of the color in 14.2 fixed point. For spot shadows, we increase the stroke width + to set the shadow against the shape. This pad is specified by b, also in 6.2 fixed point. + + When not using implicit distance, then b in the input color represents the input to the + blur function. + */ +class SkGaussianEdgeShaderImpl : public SkShaderBase { +public: + SkGaussianEdgeShaderImpl() {} + + bool isOpaque() const override; + +#if SK_SUPPORT_GPU + sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override; +#endif + + SK_TO_STRING_OVERRIDE() + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkGaussianEdgeShaderImpl) + +protected: + void flatten(SkWriteBuffer&) const override; + Context* onMakeContext(const ContextRec& rec, SkArenaAlloc* storage) const override { + return nullptr; + } +private: + friend class SkGaussianEdgeShader; + + typedef SkShaderBase INHERITED; +}; + +//////////////////////////////////////////////////////////////////////////// + +#if SK_SUPPORT_GPU + +#include "effects/GrBlurredEdgeFragmentProcessor.h" + +//////////////////////////////////////////////////////////////////////////// + +sk_sp<GrFragmentProcessor> SkGaussianEdgeShaderImpl::asFragmentProcessor(const AsFPArgs&) const { + return GrBlurredEdgeFP::Make(GrBlurredEdgeFP::kGaussian_Mode); +} + +#endif + +//////////////////////////////////////////////////////////////////////////// + +bool SkGaussianEdgeShaderImpl::isOpaque() const { + return false; +} + +//////////////////////////////////////////////////////////////////////////// + +#ifndef SK_IGNORE_TO_STRING +void SkGaussianEdgeShaderImpl::toString(SkString* str) const { + str->appendf("GaussianEdgeShader: ()"); +} +#endif + +sk_sp<SkFlattenable> SkGaussianEdgeShaderImpl::CreateProc(SkReadBuffer& buf) { + return sk_make_sp<SkGaussianEdgeShaderImpl>(); +} + +void SkGaussianEdgeShaderImpl::flatten(SkWriteBuffer& buf) const { +} + +/////////////////////////////////////////////////////////////////////////////// + +sk_sp<SkShader> SkGaussianEdgeShader::Make() { + return sk_make_sp<SkGaussianEdgeShaderImpl>(); +} + +/////////////////////////////////////////////////////////////////////////////// + +SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) +SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) +SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END + +/////////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/SkGaussianEdgeShader.h b/src/effects/SkGaussianEdgeShader.h new file mode 100644 index 0000000000..f0554dd0a7 --- /dev/null +++ b/src/effects/SkGaussianEdgeShader.h @@ -0,0 +1,27 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkGaussianEdgeShader_DEFINED +#define SkGaussianEdgeShader_DEFINED + +#include "SkShaderBase.h" + +class SK_API SkGaussianEdgeShader { +public: + /** Returns a shader that applies a Gaussian blur depending on distance to the edge + * Currently this is only useable with Circle and RRect shapes on the GPU backend. + * Raster will draw nothing. + */ + static sk_sp<SkShader> Make(); + + SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() + +private: + SkGaussianEdgeShader(); // can't be instantiated +}; + +#endif diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp index de9b61ae9c..8052417ca8 100644 --- a/src/ports/SkGlobalInitialization_default.cpp +++ b/src/ports/SkGlobalInitialization_default.cpp @@ -22,6 +22,7 @@ #include "SkDisplacementMapEffect.h" #include "SkDropShadowImageFilter.h" #include "../../src/effects/SkEmbossMaskFilter.h" +#include "../../src/effects/SkGaussianEdgeShader.h" #include "SkGradientShader.h" #include "SkHighContrastFilter.h" #include "SkImageSource.h" @@ -91,6 +92,7 @@ void SkFlattenable::PrivateInitializer::InitEffects() { SkGradientShader::InitializeFlattenables(); SkLightingShader::InitializeFlattenables(); SkNormalSource::InitializeFlattenables(); + SkGaussianEdgeShader::InitializeFlattenables(); // PathEffect SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArcToPathEffect) |