Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: src/effects/SkGaussianEdgeShader.cpp

Issue 2256713002: Add alternative spot shadow to Android shadow sample (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments; fix scale Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samplecode/SampleAndroidShadows.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkGaussianEdgeShader.h" 8 #include "SkGaussianEdgeShader.h"
9 #include "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkWriteBuffer.h" 10 #include "SkWriteBuffer.h"
11 11
12 /** \class SkGaussianEdgeShaderImpl 12 /** \class SkGaussianEdgeShaderImpl
13 This subclass of shader applies a Gaussian to shadow edge 13 This subclass of shader applies a Gaussian to shadow edge
14
15 The radius of the Gaussian blur is specified by the g and b values of the color ,
16 where g is the integer component and b is the fractional component. The r value
17 represents the max final alpha.
14 */ 18 */
15 class SkGaussianEdgeShaderImpl : public SkShader { 19 class SkGaussianEdgeShaderImpl : public SkShader {
16 public: 20 public:
17 SkGaussianEdgeShaderImpl() {} 21 SkGaussianEdgeShaderImpl() {}
18 22
19 bool isOpaque() const override; 23 bool isOpaque() const override;
20 24
21 #if SK_SUPPORT_GPU 25 #if SK_SUPPORT_GPU
22 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const overri de; 26 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const overri de;
23 #endif 27 #endif
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 62 }
59 63
60 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { 64 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor {
61 public: 65 public:
62 GLSLGaussianEdgeFP() {} 66 GLSLGaussianEdgeFP() {}
63 67
64 void emitCode(EmitArgs& args) override { 68 void emitCode(EmitArgs& args) override {
65 69
66 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 70 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
67 71
68 fragBuilder->codeAppendf("vec4 output = %s;", args.fInputColor); 72 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor);
69 // outside the outer edge 73 fragBuilder->codeAppend("float radius = color.g*255.0 + color.b;");
70 fragBuilder->codeAppendf("if (%s.z <= 0) {", fragBuilder->distanceVe ctorName()); 74
71 fragBuilder->codeAppend("output *= 0.0;"); 75 fragBuilder->codeAppendf("float factor = 1.0 - clamp(%s.z/radius, 0. 0, 1.0);",
72 // inside the stroke
73 fragBuilder->codeAppendf("} else if (%s.w > 0) {", fragBuilder->dist anceVectorName());
74 fragBuilder->codeAppendf("float factor = %s.w/(%s.z + %s.w);",
75 fragBuilder->distanceVectorName(),
76 fragBuilder->distanceVectorName(),
77 fragBuilder->distanceVectorName()); 76 fragBuilder->distanceVectorName());
78 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01 8;"); 77 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01 8;");
79 fragBuilder->codeAppend("output *= factor;"); 78 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color.r);" , args.fOutputColor);
80 fragBuilder->codeAppend("}");
81 fragBuilder->codeAppendf("%s = output;", args.fOutputColor);
82 } 79 }
83 80
84 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 81 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
85 GrProcessorKeyBuilder* b) { 82 GrProcessorKeyBuilder* b) {
86 // only one shader generated currently 83 // only one shader generated currently
87 b->add32(0x0); 84 b->add32(0x0);
88 } 85 }
89 86
90 protected: 87 protected:
91 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {} 88 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return sk_make_sp<SkGaussianEdgeShaderImpl>(); 140 return sk_make_sp<SkGaussianEdgeShaderImpl>();
144 } 141 }
145 142
146 /////////////////////////////////////////////////////////////////////////////// 143 ///////////////////////////////////////////////////////////////////////////////
147 144
148 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) 145 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader)
149 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) 146 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl)
150 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 147 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
151 148
152 /////////////////////////////////////////////////////////////////////////////// 149 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « samplecode/SampleAndroidShadows.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698