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

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

Issue 2316593003: Add GM/slide to simulate Android-style reveal clip (Closed)
Patch Set: Make the default color be _opaque_ black Created 4 years, 3 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/GMSampleView.cpp ('k') | src/gpu/glsl/GrGLSLProgramBuilder.cpp » ('j') | 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"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 // enable output of distance information for shape 61 // enable output of distance information for shape
62 fUsesDistanceVectorField = true; 62 fUsesDistanceVectorField = true;
63 } 63 }
64 64
65 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor { 65 class GLSLGaussianEdgeFP : public GrGLSLFragmentProcessor {
66 public: 66 public:
67 GLSLGaussianEdgeFP() {} 67 GLSLGaussianEdgeFP() {}
68 68
69 void emitCode(EmitArgs& args) override { 69 void emitCode(EmitArgs& args) override {
70
71 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 70 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
72 71
73 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor); 72 if (!args.fGpImplementsDistanceVector) {
74 fragBuilder->codeAppend("float radius = color.g*64.0;"); 73 fragBuilder->codeAppendf("// GP does not implement fsDistanceVec tor - "
75 fragBuilder->codeAppend("float pad = color.b*64.0;"); 74 " returning black in \n");
75 fragBuilder->codeAppendf("%s = vec4(0, 0, 0, 1);", args.fOutputC olor);
76 } else {
77 fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor);
78 fragBuilder->codeAppend("float radius = color.g*64.0;");
79 fragBuilder->codeAppend("float pad = color.b*64.0;");
76 80
77 fragBuilder->codeAppendf("float factor = 1.0 - clamp((%s.z - pad)/ra dius, 0.0, 1.0);", 81 fragBuilder->codeAppendf("float factor = 1.0 - clamp((%s.z - pad )/radius, 0.0, 1.0);",
egdaniel 2016/09/08 14:31:09 100 chars
robertphillips 2016/09/08 14:34:50 Done.
78 fragBuilder->distanceVectorName()); 82 fragBuilder->distanceVectorName());
79 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01 8;"); 83 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.018;");
80 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color.r);" , args.fOutputColor); 84 fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color. r);",
85 args.fOutputColor);
86 }
81 } 87 }
82 88
83 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 89 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
84 GrProcessorKeyBuilder* b) { 90 GrProcessorKeyBuilder* b) {
85 // only one shader generated currently 91 // only one shader generated currently
86 b->add32(0x0); 92 b->add32(0x0);
87 } 93 }
88 94
89 protected: 95 protected:
90 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {} 96 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {}
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 void SkGaussianEdgeShaderImpl::toString(SkString* str) const { 132 void SkGaussianEdgeShaderImpl::toString(SkString* str) const {
127 str->appendf("GaussianEdgeShader: ()"); 133 str->appendf("GaussianEdgeShader: ()");
128 } 134 }
129 #endif 135 #endif
130 136
131 sk_sp<SkFlattenable> SkGaussianEdgeShaderImpl::CreateProc(SkReadBuffer& buf) { 137 sk_sp<SkFlattenable> SkGaussianEdgeShaderImpl::CreateProc(SkReadBuffer& buf) {
132 return sk_make_sp<SkGaussianEdgeShaderImpl>(); 138 return sk_make_sp<SkGaussianEdgeShaderImpl>();
133 } 139 }
134 140
135 void SkGaussianEdgeShaderImpl::flatten(SkWriteBuffer& buf) const { 141 void SkGaussianEdgeShaderImpl::flatten(SkWriteBuffer& buf) const {
136 this->INHERITED::flatten(buf);
137 } 142 }
138 143
139 /////////////////////////////////////////////////////////////////////////////// 144 ///////////////////////////////////////////////////////////////////////////////
140 145
141 sk_sp<SkShader> SkGaussianEdgeShader::Make() { 146 sk_sp<SkShader> SkGaussianEdgeShader::Make() {
142 return sk_make_sp<SkGaussianEdgeShaderImpl>(); 147 return sk_make_sp<SkGaussianEdgeShaderImpl>();
143 } 148 }
144 149
145 /////////////////////////////////////////////////////////////////////////////// 150 ///////////////////////////////////////////////////////////////////////////////
146 151
147 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader) 152 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGaussianEdgeShader)
148 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl) 153 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGaussianEdgeShaderImpl)
149 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 154 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
150 155
151 /////////////////////////////////////////////////////////////////////////////// 156 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « samplecode/GMSampleView.cpp ('k') | src/gpu/glsl/GrGLSLProgramBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698