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

Side by Side Diff: src/gpu/effects/GrConvexPolyEffect.cpp

Issue 1666773002: Clean up GrGLSLFragmentProcessor-derived classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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/gpu/effects/GrConfigConversionEffect.cpp ('k') | src/gpu/effects/GrConvolutionEffect.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 2014 Google Inc. 2 * Copyright 2014 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 "GrConvexPolyEffect.h" 8 #include "GrConvexPolyEffect.h"
9 #include "GrInvariantOutput.h" 9 #include "GrInvariantOutput.h"
10 #include "SkPathPriv.h" 10 #include "SkPathPriv.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 fp = AARectEffect::Create(edgeType, rect); 75 fp = AARectEffect::Create(edgeType, rect);
76 } while (nullptr == fp); 76 } while (nullptr == fp);
77 return fp; 77 return fp;
78 } 78 }
79 79
80 ////////////////////////////////////////////////////////////////////////////// 80 //////////////////////////////////////////////////////////////////////////////
81 81
82 class GLAARectEffect : public GrGLSLFragmentProcessor { 82 class GLAARectEffect : public GrGLSLFragmentProcessor {
83 public: 83 public:
84 GLAARectEffect(const GrProcessor&); 84 GLAARectEffect() {
85 fPrevRect.fLeft = SK_ScalarNaN;
86 }
85 87
86 virtual void emitCode(EmitArgs&) override; 88 void emitCode(EmitArgs&) override;
87 89
88 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 90 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
89 91
90 protected: 92 protected:
91 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ; 93 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
92 94
93 private: 95 private:
94 GrGLSLProgramDataManager::UniformHandle fRectUniform; 96 GrGLSLProgramDataManager::UniformHandle fRectUniform;
95 SkRect fPrevRect; 97 SkRect fPrevRect;
96 typedef GrGLSLFragmentProcessor INHERITED; 98 typedef GrGLSLFragmentProcessor INHERITED;
97 }; 99 };
98 100
99 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) {
100 fPrevRect.fLeft = SK_ScalarNaN;
101 }
102
103 void GLAARectEffect::emitCode(EmitArgs& args) { 101 void GLAARectEffect::emitCode(EmitArgs& args) {
104 const AARectEffect& aare = args.fFp.cast<AARectEffect>(); 102 const AARectEffect& aare = args.fFp.cast<AARectEffect>();
105 const char *rectName; 103 const char *rectName;
106 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5), 104 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5),
107 // respectively. 105 // respectively.
108 fRectUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragm ent_Visibility, 106 fRectUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragm ent_Visibility,
109 kVec4f_GrSLType, 107 kVec4f_GrSLType,
110 kDefault_GrSLPrecision, 108 kDefault_GrSLPrecision,
111 "rect", 109 "rect",
112 &rectName); 110 &rectName);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 GrProcessorKeyBuilder* b) { 152 GrProcessorKeyBuilder* b) {
155 const AARectEffect& aare = processor.cast<AARectEffect>(); 153 const AARectEffect& aare = processor.cast<AARectEffect>();
156 b->add32(aare.getEdgeType()); 154 b->add32(aare.getEdgeType());
157 } 155 }
158 156
159 void AARectEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyB uilder* b) const { 157 void AARectEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyB uilder* b) const {
160 GLAARectEffect::GenKey(*this, caps, b); 158 GLAARectEffect::GenKey(*this, caps, b);
161 } 159 }
162 160
163 GrGLSLFragmentProcessor* AARectEffect::onCreateGLSLInstance() const { 161 GrGLSLFragmentProcessor* AARectEffect::onCreateGLSLInstance() const {
164 return new GLAARectEffect(*this); 162 return new GLAARectEffect;
165 } 163 }
166 164
167 ////////////////////////////////////////////////////////////////////////////// 165 //////////////////////////////////////////////////////////////////////////////
168 166
169 class GrGLConvexPolyEffect : public GrGLSLFragmentProcessor { 167 class GrGLConvexPolyEffect : public GrGLSLFragmentProcessor {
170 public: 168 public:
171 GrGLConvexPolyEffect(const GrProcessor&); 169 GrGLConvexPolyEffect() {
170 fPrevEdges[0] = SK_ScalarNaN;
171 }
172 172
173 virtual void emitCode(EmitArgs&) override; 173 void emitCode(EmitArgs&) override;
174 174
175 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 175 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
176 176
177 protected: 177 protected:
178 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ; 178 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
179 179
180 private: 180 private:
181 GrGLSLProgramDataManager::UniformHandle fEdgeUniform; 181 GrGLSLProgramDataManager::UniformHandle fEdgeUniform;
182 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges]; 182 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges];
183 typedef GrGLSLFragmentProcessor INHERITED; 183 typedef GrGLSLFragmentProcessor INHERITED;
184 }; 184 };
185 185
186 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) {
187 fPrevEdges[0] = SK_ScalarNaN;
188 }
189
190 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { 186 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
191 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); 187 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
192 188
193 const char *edgeArrayName; 189 const char *edgeArrayName;
194 fEdgeUniform = args.fUniformHandler->addUniformArray(GrGLSLUniformHandler::k Fragment_Visibility, 190 fEdgeUniform = args.fUniformHandler->addUniformArray(GrGLSLUniformHandler::k Fragment_Visibility,
195 kVec3f_GrSLType, 191 kVec3f_GrSLType,
196 kDefault_GrSLPrecision, 192 kDefault_GrSLPrecision,
197 "edges", 193 "edges",
198 cpe.getEdgeCount(), 194 cpe.getEdgeCount(),
199 &edgeArrayName); 195 &edgeArrayName);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons t { 298 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons t {
303 inout->mulByUnknownSingleComponent(); 299 inout->mulByUnknownSingleComponent();
304 } 300 }
305 301
306 void GrConvexPolyEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, 302 void GrConvexPolyEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
307 GrProcessorKeyBuilder* b) const { 303 GrProcessorKeyBuilder* b) const {
308 GrGLConvexPolyEffect::GenKey(*this, caps, b); 304 GrGLConvexPolyEffect::GenKey(*this, caps, b);
309 } 305 }
310 306
311 GrGLSLFragmentProcessor* GrConvexPolyEffect::onCreateGLSLInstance() const { 307 GrGLSLFragmentProcessor* GrConvexPolyEffect::onCreateGLSLInstance() const {
312 return new GrGLConvexPolyEffect(*this); 308 return new GrGLConvexPolyEffect;
313 } 309 }
314 310
315 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons t SkScalar edges[]) 311 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons t SkScalar edges[])
316 : fEdgeType(edgeType) 312 : fEdgeType(edgeType)
317 , fEdgeCount(n) { 313 , fEdgeCount(n) {
318 this->initClassID<GrConvexPolyEffect>(); 314 this->initClassID<GrConvexPolyEffect>();
319 // Factory function should have already ensured this. 315 // Factory function should have already ensured this.
320 SkASSERT(n <= kMaxEdges); 316 SkASSERT(n <= kMaxEdges);
321 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); 317 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar));
322 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov ered in the AA case 318 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov ered in the AA case
(...skipping 23 matching lines...) Expand all
346 } 342 }
347 343
348 GrFragmentProcessor* fp; 344 GrFragmentProcessor* fp;
349 do { 345 do {
350 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 346 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
351 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); 347 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt));
352 fp = GrConvexPolyEffect::Create(edgeType, count, edges); 348 fp = GrConvexPolyEffect::Create(edgeType, count, edges);
353 } while (nullptr == fp); 349 } while (nullptr == fp);
354 return fp; 350 return fp;
355 } 351 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConfigConversionEffect.cpp ('k') | src/gpu/effects/GrConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698