blob: 7bbbb79117c3af3fb1ccb74d449dfc854172cffd [file] [log] [blame]
jvanverth6c177a12016-08-17 07:59:41 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkGaussianEdgeShader.h"
9#include "SkReadBuffer.h"
10#include "SkWriteBuffer.h"
11
Herb Derby83e939b2017-02-07 14:25:11 -050012class SkArenaAlloc;
13
jvanverth6c177a12016-08-17 07:59:41 -070014 /** \class SkGaussianEdgeShaderImpl
15 This subclass of shader applies a Gaussian to shadow edge
jvanverthd7315f912016-08-17 10:06:18 -070016
Jim Van Verth91af7272017-01-27 14:15:54 -050017 If the primitive supports an implicit distance to the edge, the radius of the blur is specified
18 by r & g values of the color in 14.2 fixed point. For spot shadows, we increase the stroke width
19 to set the shadow against the shape. This pad is specified by b, also in 6.2 fixed point.
jvanverthd99858a2016-09-12 07:51:04 -070020
Jim Van Verth91af7272017-01-27 14:15:54 -050021 When not using implicit distance, then b in the input color represents the input to the
22 blur function.
jvanverth6c177a12016-08-17 07:59:41 -070023 */
24class SkGaussianEdgeShaderImpl : public SkShader {
25public:
jvanvertha8370b22016-09-16 09:13:15 -070026 SkGaussianEdgeShaderImpl() {}
jvanverth6c177a12016-08-17 07:59:41 -070027
28 bool isOpaque() const override;
29
30#if SK_SUPPORT_GPU
31 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
32#endif
33
34 SK_TO_STRING_OVERRIDE()
35 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkGaussianEdgeShaderImpl)
36
37protected:
38 void flatten(SkWriteBuffer&) const override;
Herb Derby83e939b2017-02-07 14:25:11 -050039 Context* onMakeContext(const ContextRec& rec, SkArenaAlloc* storage) const override {
40 return nullptr;
41 }
jvanverth6c177a12016-08-17 07:59:41 -070042private:
43 friend class SkGaussianEdgeShader;
44
45 typedef SkShader INHERITED;
46};
47
48////////////////////////////////////////////////////////////////////////////
49
50#if SK_SUPPORT_GPU
51
Jim Van Verth91af7272017-01-27 14:15:54 -050052#include "effects/GrBlurredEdgeFragmentProcessor.h"
jvanverth6c177a12016-08-17 07:59:41 -070053
54////////////////////////////////////////////////////////////////////////////
55
jvanvertha8370b22016-09-16 09:13:15 -070056sk_sp<GrFragmentProcessor> SkGaussianEdgeShaderImpl::asFragmentProcessor(const AsFPArgs&) const {
Jim Van Verth91af7272017-01-27 14:15:54 -050057 return GrBlurredEdgeFP::Make(GrBlurredEdgeFP::kGaussian_Mode);
jvanverth6c177a12016-08-17 07:59:41 -070058}
59
60#endif
61
62////////////////////////////////////////////////////////////////////////////
63
64bool SkGaussianEdgeShaderImpl::isOpaque() const {
65 return false;
66}
67
68////////////////////////////////////////////////////////////////////////////
69
70#ifndef SK_IGNORE_TO_STRING
71void SkGaussianEdgeShaderImpl::toString(SkString* str) const {
72 str->appendf("GaussianEdgeShader: ()");
73}
74#endif
75
76sk_sp<SkFlattenable> SkGaussianEdgeShaderImpl::CreateProc(SkReadBuffer& buf) {
77 return sk_make_sp<SkGaussianEdgeShaderImpl>();
78}
79
80void SkGaussianEdgeShaderImpl::flatten(SkWriteBuffer& buf) const {
jvanverth6c177a12016-08-17 07:59:41 -070081}
82
83///////////////////////////////////////////////////////////////////////////////
84
jvanvertha8370b22016-09-16 09:13:15 -070085sk_sp<SkShader> SkGaussianEdgeShader::Make() {
86 return sk_make_sp<SkGaussianEdgeShaderImpl>();
jvanverth6c177a12016-08-17 07:59:41 -070087}
88
89///////////////////////////////////////////////////////////////////////////////
90
91SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader)
92SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl)
93SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
94
95///////////////////////////////////////////////////////////////////////////////