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

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

Issue 2249973003: Add alternative ambient shadow method to Android shadow sample (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix some overlong lines 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
OLDNEW
(Empty)
1 /*
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
12 /** \class SkGaussianEdgeShaderImpl
13 This subclass of shader applies a Gaussian to shadow edge
14 */
15 class SkGaussianEdgeShaderImpl : public SkShader {
16 public:
robertphillips 2016/08/16 17:56:07 Ditch comment ?
jvanverth1 2016/08/16 19:14:11 Done.
17 /** Create a new lighting shader that uses the provided normal map and
18 lights to light the diffuse bitmap.
19 @param diffuseShader the shader that provides the diffuse colors
20 */
21 SkGaussianEdgeShaderImpl() {}
22
23 bool isOpaque() const override;
24
25 #if SK_SUPPORT_GPU
26 sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const overri de;
27 #endif
28
29 SK_TO_STRING_OVERRIDE()
30 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkGaussianEdgeShader Impl)
31
32 protected:
33 void flatten(SkWriteBuffer&) const override;
34
35 private:
36 friend class SkGaussianEdgeShader;
37
38 typedef SkShader INHERITED;
39 };
40
41 ////////////////////////////////////////////////////////////////////////////
42
43 #if SK_SUPPORT_GPU
44
45 #include "GrCoordTransform.h"
46 #include "GrFragmentProcessor.h"
47 #include "GrInvariantOutput.h"
48 #include "glsl/GrGLSLFragmentProcessor.h"
49 #include "glsl/GrGLSLFragmentShaderBuilder.h"
50 #include "glsl/GrGLSLProgramDataManager.h"
51 #include "glsl/GrGLSLUniformHandler.h"
52 #include "SkGr.h"
53 #include "SkGrPriv.h"
54
55 class GaussianEdgeFP : public GrFragmentProcessor {
56 public:
57 GaussianEdgeFP() {
58 this->initClassID<GaussianEdgeFP>();
59
robertphillips 2016/08/16 17:56:07 delete ?
jvanverth1 2016/08/16 19:14:11 No, it's needed.
60 fUsesDistanceVectorField = true;
61 }
62
63 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor {
64 public:
65 GLSLGaussianEdgeFP() {}
66
67 void emitCode(EmitArgs& args) override {
68
69 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
70
71 fragBuilder->codeAppendf("vec4 output = %s;", args.fInputColor);
72 // outside the outer edge
73 fragBuilder->codeAppendf("if (%s.z <= 0) {", fragBuilder->distanceVe ctorName());
74 fragBuilder->codeAppend("output *= 0.0;");
75 // inside the stroke
76 fragBuilder->codeAppendf("} else if (%s.w > 0) {", fragBuilder->dist anceVectorName());
77 fragBuilder->codeAppendf("float factor = %s.w/(%s.z + %s.w);",
78 fragBuilder->distanceVectorName(),
79 fragBuilder->distanceVectorName(),
80 fragBuilder->distanceVectorName());
81 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01 8;");
82 fragBuilder->codeAppend("output *= factor;");
83 fragBuilder->codeAppend("}");
84 fragBuilder->codeAppendf("%s = output;", args.fOutputColor);
85 }
86
87 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
88 GrProcessorKeyBuilder* b) {
robertphillips 2016/08/16 17:56:07 kill dead code ?
jvanverth1 2016/08/16 19:14:11 Done.
89 // const GaussianEdgeFP& GaussianEdgeFP = proc.cast<Gauss ianEdgeFP>();
90 // only one shader generated currently
91 b->add32(0x0);
92 }
93
94 protected:
95 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {}
96 };
97
98 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {
99 GLSLGaussianEdgeFP::GenKey(*this, caps, b);
100 }
101
102 const char* name() const override { return "GaussianEdgeFP"; }
103
104 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
105 inout->mulByUnknownFourComponents();
106 }
107
108 private:
109 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLGaussianEdgeFP; }
110
111 bool onIsEqual(const GrFragmentProcessor& proc) const override { return true ; }
112 };
113
114 ////////////////////////////////////////////////////////////////////////////
115
116 sk_sp<GrFragmentProcessor> SkGaussianEdgeShaderImpl::asFragmentProcessor(const A sFPArgs& args) const {
117 return sk_make_sp<GaussianEdgeFP>();
118 }
119
120 #endif
121
robertphillips 2016/08/16 17:56:07 Does raster crash ?
jvanverth1 2016/08/16 19:14:11 Nope, just draws nothing. Added to comment.
122 ////////////////////////////////////////////////////////////////////////////
123
124 bool SkGaussianEdgeShaderImpl::isOpaque() const {
125 return false;
126 }
127
128 ////////////////////////////////////////////////////////////////////////////
129
130 #ifndef SK_IGNORE_TO_STRING
131 void SkGaussianEdgeShaderImpl::toString(SkString* str) const {
132 str->appendf("GaussianEdgeShader: ()");
133 }
134 #endif
135
136 sk_sp<SkFlattenable> SkGaussianEdgeShaderImpl::CreateProc(SkReadBuffer& buf) {
137 return sk_make_sp<SkGaussianEdgeShaderImpl>();
138 }
139
140 void SkGaussianEdgeShaderImpl::flatten(SkWriteBuffer& buf) const {
141 this->INHERITED::flatten(buf);
142 }
143
144 ///////////////////////////////////////////////////////////////////////////////
145
146 sk_sp<SkShader> SkGaussianEdgeShader::Make() {
147 return sk_make_sp<SkGaussianEdgeShaderImpl>();
148 }
149
150 ///////////////////////////////////////////////////////////////////////////////
151
152 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader)
153 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl)
154 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
155
156 ///////////////////////////////////////////////////////////////////////////////
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698