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

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

Issue 1251173002: Added GrGLFragmentProcessor::EmitArgs struct for use with emitCode() (Closed) Base URL: https://skia.googlesource.com/skia@composeshader_gpu
Patch Set: Created 5 years, 5 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/SampleLighting.cpp ('k') | src/effects/SkArithmeticMode_gpu.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 2013 Google Inc. 2 * Copyright 2013 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 "SkAlphaThresholdFilter.h" 8 #include "SkAlphaThresholdFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 GrCoordTransform fMaskCoordTransform; 121 GrCoordTransform fMaskCoordTransform;
122 GrTextureAccess fMaskTextureAccess; 122 GrTextureAccess fMaskTextureAccess;
123 123
124 typedef GrFragmentProcessor INHERITED; 124 typedef GrFragmentProcessor INHERITED;
125 }; 125 };
126 126
127 class GrGLAlphaThresholdEffect : public GrGLFragmentProcessor { 127 class GrGLAlphaThresholdEffect : public GrGLFragmentProcessor {
128 public: 128 public:
129 GrGLAlphaThresholdEffect(const GrFragmentProcessor&) {} 129 GrGLAlphaThresholdEffect(const GrFragmentProcessor&) {}
130 130
131 virtual void emitCode(GrGLFPBuilder*, 131 virtual void emitCode(EmitArgs&) override;
132 const GrFragmentProcessor&,
133 const char* outputColor,
134 const char* inputColor,
135 const TransformedCoordsArray&,
136 const TextureSamplerArray&) override;
137 132
138 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 133 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
139 134
140 private: 135 private:
141 136
142 GrGLProgramDataManager::UniformHandle fInnerThresholdVar; 137 GrGLProgramDataManager::UniformHandle fInnerThresholdVar;
143 GrGLProgramDataManager::UniformHandle fOuterThresholdVar; 138 GrGLProgramDataManager::UniformHandle fOuterThresholdVar;
144 139
145 typedef GrGLFragmentProcessor INHERITED; 140 typedef GrGLFragmentProcessor INHERITED;
146 }; 141 };
147 142
148 void GrGLAlphaThresholdEffect::emitCode(GrGLFPBuilder* builder, 143 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) {
149 const GrFragmentProcessor&, 144 fInnerThresholdVar = args.fBuilder->addUniform(
150 const char* outputColor,
151 const char* inputColor,
152 const TransformedCoordsArray& coords,
153 const TextureSamplerArray& samplers) {
154 fInnerThresholdVar = builder->addUniform(
155 GrGLProgramBuilder::kFragment_Visibility, 145 GrGLProgramBuilder::kFragment_Visibility,
156 kFloat_GrSLType, kDefault_GrSLPrecision, 146 kFloat_GrSLType, kDefault_GrSLPrecision,
157 "inner_threshold"); 147 "inner_threshold");
158 fOuterThresholdVar = builder->addUniform( 148 fOuterThresholdVar = args.fBuilder->addUniform(
159 GrGLProgramBuilder::kFragment_Visibility, 149 GrGLProgramBuilder::kFragment_Visibility,
160 kFloat_GrSLType, kDefault_GrSLPrecision, 150 kFloat_GrSLType, kDefault_GrSLPrecision,
161 "outer_threshold"); 151 "outer_threshold");
162 152
163 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 153 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
164 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); 154 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
165 SkString maskCoords2D = fsBuilder->ensureFSCoords2D(coords, 1); 155 SkString maskCoords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 1);
166 156
167 fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); 157 fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
168 fsBuilder->codeAppendf("\t\tvec2 mask_coord = %s;\n", maskCoords2D.c_str()); 158 fsBuilder->codeAppendf("\t\tvec2 mask_coord = %s;\n", maskCoords2D.c_str());
169 fsBuilder->codeAppend("\t\tvec4 input_color = "); 159 fsBuilder->codeAppend("\t\tvec4 input_color = ");
170 fsBuilder->appendTextureLookup(samplers[0], "coord"); 160 fsBuilder->appendTextureLookup(args.fSamplers[0], "coord");
171 fsBuilder->codeAppend(";\n"); 161 fsBuilder->codeAppend(";\n");
172 fsBuilder->codeAppend("\t\tvec4 mask_color = "); 162 fsBuilder->codeAppend("\t\tvec4 mask_color = ");
173 fsBuilder->appendTextureLookup(samplers[1], "mask_coord"); 163 fsBuilder->appendTextureLookup(args.fSamplers[1], "mask_coord");
174 fsBuilder->codeAppend(";\n"); 164 fsBuilder->codeAppend(";\n");
175 165
176 fsBuilder->codeAppendf("\t\tfloat inner_thresh = %s;\n", 166 fsBuilder->codeAppendf("\t\tfloat inner_thresh = %s;\n",
177 builder->getUniformCStr(fInnerThresholdVar)); 167 args.fBuilder->getUniformCStr(fInnerThresholdVar));
178 fsBuilder->codeAppendf("\t\tfloat outer_thresh = %s;\n", 168 fsBuilder->codeAppendf("\t\tfloat outer_thresh = %s;\n",
179 builder->getUniformCStr(fOuterThresholdVar)); 169 args.fBuilder->getUniformCStr(fOuterThresholdVar));
180 fsBuilder->codeAppend("\t\tfloat mask = mask_color.a;\n"); 170 fsBuilder->codeAppend("\t\tfloat mask = mask_color.a;\n");
181 171
182 fsBuilder->codeAppend("vec4 color = input_color;\n"); 172 fsBuilder->codeAppend("vec4 color = input_color;\n");
183 fsBuilder->codeAppend("\t\tif (mask < 0.5) {\n" 173 fsBuilder->codeAppend("\t\tif (mask < 0.5) {\n"
184 "\t\t\tif (color.a > outer_thresh) {\n" 174 "\t\t\tif (color.a > outer_thresh) {\n"
185 "\t\t\t\tfloat scale = outer_thresh / color.a;\n" 175 "\t\t\t\tfloat scale = outer_thresh / color.a;\n"
186 "\t\t\t\tcolor.rgb *= scale;\n" 176 "\t\t\t\tcolor.rgb *= scale;\n"
187 "\t\t\t\tcolor.a = outer_thresh;\n" 177 "\t\t\t\tcolor.a = outer_thresh;\n"
188 "\t\t\t}\n" 178 "\t\t\t}\n"
189 "\t\t} else if (color.a < inner_thresh) {\n" 179 "\t\t} else if (color.a < inner_thresh) {\n"
190 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a );\n" 180 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a );\n"
191 "\t\t\tcolor.rgb *= scale;\n" 181 "\t\t\tcolor.rgb *= scale;\n"
192 "\t\t\tcolor.a = inner_thresh;\n" 182 "\t\t\tcolor.a = inner_thresh;\n"
193 "\t\t}\n"); 183 "\t\t}\n");
194 184
195 fsBuilder->codeAppendf("%s = %s;\n", outputColor, 185 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor,
196 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("color")).c_st r()); 186 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color") ).c_str());
197 } 187 }
198 188
199 void GrGLAlphaThresholdEffect::setData(const GrGLProgramDataManager& pdman, 189 void GrGLAlphaThresholdEffect::setData(const GrGLProgramDataManager& pdman,
200 const GrProcessor& proc) { 190 const GrProcessor& proc) {
201 const AlphaThresholdEffect& alpha_threshold = proc.cast<AlphaThresholdEffect >(); 191 const AlphaThresholdEffect& alpha_threshold = proc.cast<AlphaThresholdEffect >();
202 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); 192 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold());
203 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); 193 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold());
204 } 194 }
205 195
206 ///////////////////////////////////////////////////////////////////// 196 /////////////////////////////////////////////////////////////////////
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 374 }
385 375
386 #ifndef SK_IGNORE_TO_STRING 376 #ifndef SK_IGNORE_TO_STRING
387 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { 377 void SkAlphaThresholdFilterImpl::toString(SkString* str) const {
388 str->appendf("SkAlphaThresholdImageFilter: ("); 378 str->appendf("SkAlphaThresholdImageFilter: (");
389 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); 379 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold);
390 str->append(")"); 380 str->append(")");
391 } 381 }
392 #endif 382 #endif
393 383
OLDNEW
« no previous file with comments | « samplecode/SampleLighting.cpp ('k') | src/effects/SkArithmeticMode_gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698