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

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

Issue 577593003: Revert of removing GrDrawEffect (Closed) Base URL: https://skia.googlesource.com/skia.git@gp3
Patch Set: Created 6 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 | « src/core/SkXfermode.cpp ('k') | src/effects/SkArithmeticMode.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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 GrCoordTransform fImageCoordTransform; 111 GrCoordTransform fImageCoordTransform;
112 GrTextureAccess fImageTextureAccess; 112 GrTextureAccess fImageTextureAccess;
113 GrCoordTransform fMaskCoordTransform; 113 GrCoordTransform fMaskCoordTransform;
114 GrTextureAccess fMaskTextureAccess; 114 GrTextureAccess fMaskTextureAccess;
115 115
116 typedef GrEffect INHERITED; 116 typedef GrEffect INHERITED;
117 }; 117 };
118 118
119 class GrGLAlphaThresholdEffect : public GrGLEffect { 119 class GrGLAlphaThresholdEffect : public GrGLEffect {
120 public: 120 public:
121 GrGLAlphaThresholdEffect(const GrBackendEffectFactory&, const GrEffect&); 121 GrGLAlphaThresholdEffect(const GrBackendEffectFactory&, const GrDrawEffect&) ;
122 122
123 virtual void emitCode(GrGLProgramBuilder*, 123 virtual void emitCode(GrGLProgramBuilder*,
124 const GrEffect&, 124 const GrDrawEffect&,
125 const GrEffectKey&, 125 const GrEffectKey&,
126 const char* outputColor, 126 const char* outputColor,
127 const char* inputColor, 127 const char* inputColor,
128 const TransformedCoordsArray&, 128 const TransformedCoordsArray&,
129 const TextureSamplerArray&) SK_OVERRIDE; 129 const TextureSamplerArray&) SK_OVERRIDE;
130 130
131 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER RIDE; 131 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE;
132 132
133 private: 133 private:
134 134
135 GrGLProgramDataManager::UniformHandle fInnerThresholdVar; 135 GrGLProgramDataManager::UniformHandle fInnerThresholdVar;
136 GrGLProgramDataManager::UniformHandle fOuterThresholdVar; 136 GrGLProgramDataManager::UniformHandle fOuterThresholdVar;
137 137
138 typedef GrGLEffect INHERITED; 138 typedef GrGLEffect INHERITED;
139 }; 139 };
140 140
141 GrGLAlphaThresholdEffect::GrGLAlphaThresholdEffect(const GrBackendEffectFactory& factory, 141 GrGLAlphaThresholdEffect::GrGLAlphaThresholdEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
142 const GrEffect&)
143 : INHERITED(factory) { 142 : INHERITED(factory) {
144 } 143 }
145 144
146 void GrGLAlphaThresholdEffect::emitCode(GrGLProgramBuilder* builder, 145 void GrGLAlphaThresholdEffect::emitCode(GrGLProgramBuilder* builder,
147 const GrEffect&, 146 const GrDrawEffect&,
148 const GrEffectKey& key, 147 const GrEffectKey& key,
149 const char* outputColor, 148 const char* outputColor,
150 const char* inputColor, 149 const char* inputColor,
151 const TransformedCoordsArray& coords, 150 const TransformedCoordsArray& coords,
152 const TextureSamplerArray& samplers) { 151 const TextureSamplerArray& samplers) {
153 fInnerThresholdVar = builder->addUniform( 152 fInnerThresholdVar = builder->addUniform(
154 GrGLProgramBuilder::kFragment_Visibility, 153 GrGLProgramBuilder::kFragment_Visibility,
155 kFloat_GrSLType, "inner_threshold"); 154 kFloat_GrSLType, "inner_threshold");
156 fOuterThresholdVar = builder->addUniform( 155 fOuterThresholdVar = builder->addUniform(
157 GrGLProgramBuilder::kFragment_Visibility, 156 GrGLProgramBuilder::kFragment_Visibility,
(...skipping 29 matching lines...) Expand all
187 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a );\n" 186 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a );\n"
188 "\t\t\tcolor.rgb *= scale;\n" 187 "\t\t\tcolor.rgb *= scale;\n"
189 "\t\t\tcolor.a = inner_thresh;\n" 188 "\t\t\tcolor.a = inner_thresh;\n"
190 "\t\t}\n"); 189 "\t\t}\n");
191 190
192 fsBuilder->codeAppendf("%s = %s;\n", outputColor, 191 fsBuilder->codeAppendf("%s = %s;\n", outputColor,
193 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("color")).c_st r()); 192 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("color")).c_st r());
194 } 193 }
195 194
196 void GrGLAlphaThresholdEffect::setData(const GrGLProgramDataManager& pdman, 195 void GrGLAlphaThresholdEffect::setData(const GrGLProgramDataManager& pdman,
197 const GrEffect& effect) { 196 const GrDrawEffect& drawEffect) {
198 const AlphaThresholdEffect& alpha_threshold = effect.cast<AlphaThresholdEffe ct>(); 197 const AlphaThresholdEffect& alpha_threshold =
198 drawEffect.castEffect<AlphaThresholdEffect>();
199 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); 199 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold());
200 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); 200 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold());
201 } 201 }
202 202
203 ///////////////////////////////////////////////////////////////////// 203 /////////////////////////////////////////////////////////////////////
204 204
205 GR_DEFINE_EFFECT_TEST(AlphaThresholdEffect); 205 GR_DEFINE_EFFECT_TEST(AlphaThresholdEffect);
206 206
207 GrEffect* AlphaThresholdEffect::TestCreate(SkRandom* random, 207 GrEffect* AlphaThresholdEffect::TestCreate(SkRandom* random,
208 GrContext* context, 208 GrContext* context,
209 const GrDrawTargetCaps&, 209 const GrDrawTargetCaps&,
210 GrTexture** textures) { 210 GrTexture** textures) {
211 GrTexture* bmpTex = textures[GrEffectUnitTest::kSkiaPMTextureIdx]; 211 GrTexture* bmpTex = textures[GrEffectUnitTest::kSkiaPMTextureIdx];
212 GrTexture* maskTex = textures[GrEffectUnitTest::kAlphaTextureIdx]; 212 GrTexture* maskTex = textures[GrEffectUnitTest::kAlphaTextureIdx];
213 float inner_thresh = random->nextUScalar1(); 213 float inner_thresh = random->nextUScalar1();
214 float outer_thresh = random->nextUScalar1(); 214 float outer_thresh = random->nextUScalar1();
215 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr esh); 215 return AlphaThresholdEffect::Create(bmpTex, maskTex, inner_thresh, outer_thr esh);
216 } 216 }
217 217
218 /////////////////////////////////////////////////////////////////////////////// 218 ///////////////////////////////////////////////////////////////////////////////
219 219
220 const GrBackendEffectFactory& AlphaThresholdEffect::getFactory() const { 220 const GrBackendEffectFactory& AlphaThresholdEffect::getFactory() const {
221 return GrTBackendEffectFactory<AlphaThresholdEffect>::getInstance(); 221 return GrTBackendEffectFactory<AlphaThresholdEffect>::getInstance();
222 } 222 }
223 223
224 bool AlphaThresholdEffect::onIsEqual(const GrEffect& sBase) const { 224 bool AlphaThresholdEffect::onIsEqual(const GrEffect& sBase) const {
225 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>(); 225 const AlphaThresholdEffect& s = CastEffect<AlphaThresholdEffect>(sBase);
226 return (this->texture(0) == s.texture(0) && 226 return (this->texture(0) == s.texture(0) &&
227 this->fInnerThreshold == s.fInnerThreshold && 227 this->fInnerThreshold == s.fInnerThreshold &&
228 this->fOuterThreshold == s.fOuterThreshold); 228 this->fOuterThreshold == s.fOuterThreshold);
229 } 229 }
230 230
231 void AlphaThresholdEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { 231 void AlphaThresholdEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
232 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color ) && 232 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color ) &&
233 GrPixelConfigIsOpaque(this->texture(0)->config())) { 233 GrPixelConfigIsOpaque(this->texture(0)->config())) {
234 *validFlags = kA_GrColorComponentFlag; 234 *validFlags = kA_GrColorComponentFlag;
235 } else { 235 } else {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 (U8CPU)(SkColorGetG(source) * scale), 377 (U8CPU)(SkColorGetG(source) * scale),
378 (U8CPU)(SkColorGetB(source) * scale)); 378 (U8CPU)(SkColorGetB(source) * scale));
379 } 379 }
380 } 380 }
381 dptr[y * dst->width() + x] = output_color; 381 dptr[y * dst->width() + x] = output_color;
382 } 382 }
383 } 383 }
384 384
385 return true; 385 return true;
386 } 386 }
OLDNEW
« no previous file with comments | « src/core/SkXfermode.cpp ('k') | src/effects/SkArithmeticMode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698