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

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

Issue 1287023009: Added tree structure to GrGLFragmentProcessor, i.e. GL instances (Closed) Base URL: https://skia.googlesource.com/skia@cs3_isequal_nonrecursive
Patch Set: moved onSetData from public to protected, onCreateGLInstance from public to private in subclasses Created 5 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
« no previous file with comments | « include/gpu/effects/GrConstColorProcessor.h ('k') | src/effects/SkArithmeticMode_gpu.h » ('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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 outerThreshold)); 74 outerThreshold));
75 } 75 }
76 76
77 virtual ~AlphaThresholdEffect() {}; 77 virtual ~AlphaThresholdEffect() {};
78 78
79 const char* name() const override { return "Alpha Threshold"; } 79 const char* name() const override { return "Alpha Threshold"; }
80 80
81 float innerThreshold() const { return fInnerThreshold; } 81 float innerThreshold() const { return fInnerThreshold; }
82 float outerThreshold() const { return fOuterThreshold; } 82 float outerThreshold() const { return fOuterThreshold; }
83 83
84 GrGLFragmentProcessor* createGLInstance() const override;
85
86 private: 84 private:
87 AlphaThresholdEffect(GrProcessorDataManager*, 85 AlphaThresholdEffect(GrProcessorDataManager*,
88 GrTexture* texture, 86 GrTexture* texture,
89 GrTexture* maskTexture, 87 GrTexture* maskTexture,
90 float innerThreshold, 88 float innerThreshold,
91 float outerThreshold) 89 float outerThreshold)
92 : fInnerThreshold(innerThreshold) 90 : fInnerThreshold(innerThreshold)
93 , fOuterThreshold(outerThreshold) 91 , fOuterThreshold(outerThreshold)
94 , fImageCoordTransform(kLocal_GrCoordSet, 92 , fImageCoordTransform(kLocal_GrCoordSet,
95 GrCoordTransform::MakeDivByTextureWHMatrix(textur e), texture, 93 GrCoordTransform::MakeDivByTextureWHMatrix(textur e), texture,
96 GrTextureParams::kNone_FilterMode) 94 GrTextureParams::kNone_FilterMode)
97 , fImageTextureAccess(texture) 95 , fImageTextureAccess(texture)
98 , fMaskCoordTransform(kLocal_GrCoordSet, 96 , fMaskCoordTransform(kLocal_GrCoordSet,
99 GrCoordTransform::MakeDivByTextureWHMatrix(maskTex ture), maskTexture, 97 GrCoordTransform::MakeDivByTextureWHMatrix(maskTex ture), maskTexture,
100 GrTextureParams::kNone_FilterMode) 98 GrTextureParams::kNone_FilterMode)
101 , fMaskTextureAccess(maskTexture) { 99 , fMaskTextureAccess(maskTexture) {
102 this->initClassID<AlphaThresholdEffect>(); 100 this->initClassID<AlphaThresholdEffect>();
103 this->addCoordTransform(&fImageCoordTransform); 101 this->addCoordTransform(&fImageCoordTransform);
104 this->addTextureAccess(&fImageTextureAccess); 102 this->addTextureAccess(&fImageTextureAccess);
105 this->addCoordTransform(&fMaskCoordTransform); 103 this->addCoordTransform(&fMaskCoordTransform);
106 this->addTextureAccess(&fMaskTextureAccess); 104 this->addTextureAccess(&fMaskTextureAccess);
107 } 105 }
108 106
107 GrGLFragmentProcessor* onCreateGLInstance() const override;
108
109 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 109 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
110 110
111 bool onIsEqual(const GrFragmentProcessor&) const override; 111 bool onIsEqual(const GrFragmentProcessor&) const override;
112 112
113 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 113 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
114 114
115 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 115 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
116 116
117 float fInnerThreshold; 117 float fInnerThreshold;
118 float fOuterThreshold; 118 float fOuterThreshold;
119 GrCoordTransform fImageCoordTransform; 119 GrCoordTransform fImageCoordTransform;
120 GrTextureAccess fImageTextureAccess; 120 GrTextureAccess fImageTextureAccess;
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(EmitArgs&) override; 131 virtual void emitCode(EmitArgs&) override;
132 132
133 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 133 protected:
134 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
134 135
135 private: 136 private:
136 137
137 GrGLProgramDataManager::UniformHandle fInnerThresholdVar; 138 GrGLProgramDataManager::UniformHandle fInnerThresholdVar;
138 GrGLProgramDataManager::UniformHandle fOuterThresholdVar; 139 GrGLProgramDataManager::UniformHandle fOuterThresholdVar;
139 140
140 typedef GrGLFragmentProcessor INHERITED; 141 typedef GrGLFragmentProcessor INHERITED;
141 }; 142 };
142 143
143 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) { 144 void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 "\t\t} else if (color.a < inner_thresh) {\n" 180 "\t\t} else if (color.a < inner_thresh) {\n"
180 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a );\n" 181 "\t\t\tfloat scale = inner_thresh / max(0.001, color.a );\n"
181 "\t\t\tcolor.rgb *= scale;\n" 182 "\t\t\tcolor.rgb *= scale;\n"
182 "\t\t\tcolor.a = inner_thresh;\n" 183 "\t\t\tcolor.a = inner_thresh;\n"
183 "\t\t}\n"); 184 "\t\t}\n");
184 185
185 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, 186 fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor,
186 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color") ).c_str()); 187 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color") ).c_str());
187 } 188 }
188 189
189 void GrGLAlphaThresholdEffect::setData(const GrGLProgramDataManager& pdman, 190 void GrGLAlphaThresholdEffect::onSetData(const GrGLProgramDataManager& pdman,
190 const GrProcessor& proc) { 191 const GrProcessor& proc) {
191 const AlphaThresholdEffect& alpha_threshold = proc.cast<AlphaThresholdEffect >(); 192 const AlphaThresholdEffect& alpha_threshold = proc.cast<AlphaThresholdEffect >();
192 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); 193 pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold());
193 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold()); 194 pdman.set1f(fOuterThresholdVar, alpha_threshold.outerThreshold());
194 } 195 }
195 196
196 ///////////////////////////////////////////////////////////////////// 197 /////////////////////////////////////////////////////////////////////
197 198
198 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); 199 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect);
199 200
200 GrFragmentProcessor* AlphaThresholdEffect::TestCreate(GrProcessorTestData* d) { 201 GrFragmentProcessor* AlphaThresholdEffect::TestCreate(GrProcessorTestData* d) {
201 GrTexture* bmpTex = d->fTextures[GrProcessorUnitTest::kSkiaPMTextureIdx]; 202 GrTexture* bmpTex = d->fTextures[GrProcessorUnitTest::kSkiaPMTextureIdx];
202 GrTexture* maskTex = d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx]; 203 GrTexture* maskTex = d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx];
203 float innerThresh = d->fRandom->nextUScalar1(); 204 float innerThresh = d->fRandom->nextUScalar1();
204 float outerThresh = d->fRandom->nextUScalar1(); 205 float outerThresh = d->fRandom->nextUScalar1();
205 return AlphaThresholdEffect::Create(d->fProcDataManager, bmpTex, maskTex, in nerThresh, 206 return AlphaThresholdEffect::Create(d->fProcDataManager, bmpTex, maskTex, in nerThresh,
206 outerThresh); 207 outerThresh);
207 } 208 }
208 209
209 /////////////////////////////////////////////////////////////////////////////// 210 ///////////////////////////////////////////////////////////////////////////////
210 211
211 void AlphaThresholdEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 212 void AlphaThresholdEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
212 GrProcessorKeyBuilder* b) const { 213 GrProcessorKeyBuilder* b) const {
213 GrGLAlphaThresholdEffect::GenKey(*this, caps, b); 214 GrGLAlphaThresholdEffect::GenKey(*this, caps, b);
214 } 215 }
215 216
216 GrGLFragmentProcessor* AlphaThresholdEffect::createGLInstance() const { 217 GrGLFragmentProcessor* AlphaThresholdEffect::onCreateGLInstance() const {
217 return SkNEW_ARGS(GrGLAlphaThresholdEffect, (*this)); 218 return SkNEW_ARGS(GrGLAlphaThresholdEffect, (*this));
218 } 219 }
219 220
220 bool AlphaThresholdEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 221 bool AlphaThresholdEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
221 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>(); 222 const AlphaThresholdEffect& s = sBase.cast<AlphaThresholdEffect>();
222 return (this->fInnerThreshold == s.fInnerThreshold && 223 return (this->fInnerThreshold == s.fInnerThreshold &&
223 this->fOuterThreshold == s.fOuterThreshold); 224 this->fOuterThreshold == s.fOuterThreshold);
224 } 225 }
225 226
226 void AlphaThresholdEffect::onComputeInvariantOutput(GrInvariantOutput* inout) co nst { 227 void AlphaThresholdEffect::onComputeInvariantOutput(GrInvariantOutput* inout) co nst {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 375 }
375 376
376 #ifndef SK_IGNORE_TO_STRING 377 #ifndef SK_IGNORE_TO_STRING
377 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { 378 void SkAlphaThresholdFilterImpl::toString(SkString* str) const {
378 str->appendf("SkAlphaThresholdImageFilter: ("); 379 str->appendf("SkAlphaThresholdImageFilter: (");
379 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); 380 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold);
380 str->append(")"); 381 str->append(")");
381 } 382 }
382 #endif 383 #endif
383 384
OLDNEW
« no previous file with comments | « include/gpu/effects/GrConstColorProcessor.h ('k') | src/effects/SkArithmeticMode_gpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698