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

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

Issue 1490283004: Create GLSLUniformHandler class for gpu backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up public api of uniformhandler Created 5 years 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 | « src/effects/GrCircleBlurFragmentProcessor.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 "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "GrCoordTransform.h" 52 #include "GrCoordTransform.h"
53 #include "GrFragmentProcessor.h" 53 #include "GrFragmentProcessor.h"
54 #include "GrInvariantOutput.h" 54 #include "GrInvariantOutput.h"
55 #include "GrTextureAccess.h" 55 #include "GrTextureAccess.h"
56 #include "effects/GrPorterDuffXferProcessor.h" 56 #include "effects/GrPorterDuffXferProcessor.h"
57 57
58 #include "SkGr.h" 58 #include "SkGr.h"
59 59
60 #include "glsl/GrGLSLFragmentProcessor.h" 60 #include "glsl/GrGLSLFragmentProcessor.h"
61 #include "glsl/GrGLSLFragmentShaderBuilder.h" 61 #include "glsl/GrGLSLFragmentShaderBuilder.h"
62 #include "glsl/GrGLSLProgramBuilder.h"
63 #include "glsl/GrGLSLProgramDataManager.h" 62 #include "glsl/GrGLSLProgramDataManager.h"
63 #include "glsl/GrGLSLUniformHandler.h"
64 64
65 class AlphaThresholdEffect : public GrFragmentProcessor { 65 class AlphaThresholdEffect : public GrFragmentProcessor {
66 66
67 public: 67 public:
68 static GrFragmentProcessor* Create(GrTexture* texture, 68 static GrFragmentProcessor* Create(GrTexture* texture,
69 GrTexture* maskTexture, 69 GrTexture* maskTexture,
70 float innerThreshold, 70 float innerThreshold,
71 float outerThreshold) { 71 float outerThreshold) {
72 return new AlphaThresholdEffect(texture, maskTexture, innerThreshold, ou terThreshold); 72 return new AlphaThresholdEffect(texture, maskTexture, innerThreshold, ou terThreshold);
73 } 73 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 private: 133 private:
134 134
135 GrGLSLProgramDataManager::UniformHandle fInnerThresholdVar; 135 GrGLSLProgramDataManager::UniformHandle fInnerThresholdVar;
136 GrGLSLProgramDataManager::UniformHandle fOuterThresholdVar; 136 GrGLSLProgramDataManager::UniformHandle fOuterThresholdVar;
137 137
138 typedef GrGLSLFragmentProcessor INHERITED; 138 typedef GrGLSLFragmentProcessor INHERITED;
139 }; 139 };
140 140
141 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) { 141 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) {
142 fInnerThresholdVar = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme nt_Visibility, 142 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
143 kFloat_GrSLType, kDefault_GrS LPrecision, 143 fInnerThresholdVar = uniformHandler->addUniform(GrGLSLUniformHandler::kFragm ent_Visibility,
144 "inner_threshold"); 144 kFloat_GrSLType, kDefault_Gr SLPrecision,
145 fOuterThresholdVar = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme nt_Visibility, 145 "inner_threshold");
146 kFloat_GrSLType, kDefault_GrS LPrecision, 146 fOuterThresholdVar = uniformHandler->addUniform(GrGLSLUniformHandler::kFragm ent_Visibility,
147 "outer_threshold"); 147 kFloat_GrSLType, kDefault_Gr SLPrecision,
148 "outer_threshold");
148 149
149 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 150 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
150 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0); 151 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
151 SkString maskCoords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); 152 SkString maskCoords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1);
152 153
153 fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str()); 154 fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
154 fragBuilder->codeAppendf("\t\tvec2 mask_coord = %s;\n", maskCoords2D.c_str() ); 155 fragBuilder->codeAppendf("\t\tvec2 mask_coord = %s;\n", maskCoords2D.c_str() );
155 fragBuilder->codeAppend("\t\tvec4 input_color = "); 156 fragBuilder->codeAppend("\t\tvec4 input_color = ");
156 fragBuilder->appendTextureLookup(args.fSamplers[0], "coord"); 157 fragBuilder->appendTextureLookup(args.fSamplers[0], "coord");
157 fragBuilder->codeAppend(";\n"); 158 fragBuilder->codeAppend(";\n");
158 fragBuilder->codeAppend("\t\tvec4 mask_color = "); 159 fragBuilder->codeAppend("\t\tvec4 mask_color = ");
159 fragBuilder->appendTextureLookup(args.fSamplers[1], "mask_coord"); 160 fragBuilder->appendTextureLookup(args.fSamplers[1], "mask_coord");
160 fragBuilder->codeAppend(";\n"); 161 fragBuilder->codeAppend(";\n");
161 162
162 fragBuilder->codeAppendf("\t\tfloat inner_thresh = %s;\n", 163 fragBuilder->codeAppendf("\t\tfloat inner_thresh = %s;\n",
163 args.fBuilder->getUniformCStr(fInnerThresholdVar)); 164 uniformHandler->getUniformCStr(fInnerThresholdVar)) ;
164 fragBuilder->codeAppendf("\t\tfloat outer_thresh = %s;\n", 165 fragBuilder->codeAppendf("\t\tfloat outer_thresh = %s;\n",
165 args.fBuilder->getUniformCStr(fOuterThresholdVar)); 166 uniformHandler->getUniformCStr(fOuterThresholdVar)) ;
166 fragBuilder->codeAppend("\t\tfloat mask = mask_color.a;\n"); 167 fragBuilder->codeAppend("\t\tfloat mask = mask_color.a;\n");
167 168
168 fragBuilder->codeAppend("vec4 color = input_color;\n"); 169 fragBuilder->codeAppend("vec4 color = input_color;\n");
169 fragBuilder->codeAppend("\t\tif (mask < 0.5) {\n" 170 fragBuilder->codeAppend("\t\tif (mask < 0.5) {\n"
170 "\t\t\tif (color.a > outer_thresh) {\n" 171 "\t\t\tif (color.a > outer_thresh) {\n"
171 "\t\t\t\tfloat scale = outer_thresh / color.a;\n" 172 "\t\t\t\tfloat scale = outer_thresh / color.a;\n"
172 "\t\t\t\tcolor.rgb *= scale;\n" 173 "\t\t\t\tcolor.rgb *= scale;\n"
173 "\t\t\t\tcolor.a = outer_thresh;\n" 174 "\t\t\t\tcolor.a = outer_thresh;\n"
174 "\t\t\t}\n" 175 "\t\t\t}\n"
175 "\t\t} else if (color.a < inner_thresh) {\n" 176 "\t\t} else if (color.a < inner_thresh) {\n"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 371 }
371 372
372 #ifndef SK_IGNORE_TO_STRING 373 #ifndef SK_IGNORE_TO_STRING
373 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { 374 void SkAlphaThresholdFilterImpl::toString(SkString* str) const {
374 str->appendf("SkAlphaThresholdImageFilter: ("); 375 str->appendf("SkAlphaThresholdImageFilter: (");
375 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); 376 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold);
376 str->append(")"); 377 str->append(")");
377 } 378 }
378 #endif 379 #endif
379 380
OLDNEW
« no previous file with comments | « src/effects/GrCircleBlurFragmentProcessor.cpp ('k') | src/effects/SkArithmeticMode_gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698