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

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

Issue 1428543003: Create GLSL base class for ProgramDataManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add space Created 5 years, 1 month 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/GrConstColorProcessor.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"
11 #include "gl/GrGLContext.h" 11 #include "gl/GrGLContext.h"
12 #include "gl/GrGLFragmentProcessor.h" 12 #include "gl/GrGLFragmentProcessor.h"
13 #include "gl/builders/GrGLProgramBuilder.h" 13 #include "gl/builders/GrGLProgramBuilder.h"
14 #include "glsl/GrGLSLProgramDataManager.h"
14 15
15 ////////////////////////////////////////////////////////////////////////////// 16 //////////////////////////////////////////////////////////////////////////////
16 class AARectEffect : public GrFragmentProcessor { 17 class AARectEffect : public GrFragmentProcessor {
17 public: 18 public:
18 const SkRect& getRect() const { return fRect; } 19 const SkRect& getRect() const { return fRect; }
19 20
20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec t& rect) { 21 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec t& rect) {
21 return new AARectEffect(edgeType, rect); 22 return new AARectEffect(edgeType, rect);
22 } 23 }
23 24
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 81
81 class GLAARectEffect : public GrGLFragmentProcessor { 82 class GLAARectEffect : public GrGLFragmentProcessor {
82 public: 83 public:
83 GLAARectEffect(const GrProcessor&); 84 GLAARectEffect(const GrProcessor&);
84 85
85 virtual void emitCode(EmitArgs&) override; 86 virtual void emitCode(EmitArgs&) override;
86 87
87 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 88 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
88 89
89 protected: 90 protected:
90 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 91 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
91 92
92 private: 93 private:
93 GrGLProgramDataManager::UniformHandle fRectUniform; 94 GrGLSLProgramDataManager::UniformHandle fRectUniform;
94 SkRect fPrevRect; 95 SkRect fPrevRect;
95 typedef GrGLFragmentProcessor INHERITED; 96 typedef GrGLFragmentProcessor INHERITED;
96 }; 97 };
97 98
98 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { 99 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) {
99 fPrevRect.fLeft = SK_ScalarNaN; 100 fPrevRect.fLeft = SK_ScalarNaN;
100 } 101 }
101 102
102 void GLAARectEffect::emitCode(EmitArgs& args) { 103 void GLAARectEffect::emitCode(EmitArgs& args) {
103 const AARectEffect& aare = args.fFp.cast<AARectEffect>(); 104 const AARectEffect& aare = args.fFp.cast<AARectEffect>();
(...skipping 27 matching lines...) Expand all
131 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos); 132 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos);
132 } 133 }
133 134
134 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) { 135 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) {
135 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n"); 136 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n");
136 } 137 }
137 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, 138 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor,
138 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 139 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str());
139 } 140 }
140 141
141 void GLAARectEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProc essor& processor) { 142 void GLAARectEffect::onSetData(const GrGLSLProgramDataManager& pdman,
143 const GrProcessor& processor) {
142 const AARectEffect& aare = processor.cast<AARectEffect>(); 144 const AARectEffect& aare = processor.cast<AARectEffect>();
143 const SkRect& rect = aare.getRect(); 145 const SkRect& rect = aare.getRect();
144 if (rect != fPrevRect) { 146 if (rect != fPrevRect) {
145 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, 147 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f,
146 rect.fRight - 0.5f, rect.fBottom - 0.5f); 148 rect.fRight - 0.5f, rect.fBottom - 0.5f);
147 fPrevRect = rect; 149 fPrevRect = rect;
148 } 150 }
149 } 151 }
150 152
151 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, 153 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&,
(...skipping 14 matching lines...) Expand all
166 168
167 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { 169 class GrGLConvexPolyEffect : public GrGLFragmentProcessor {
168 public: 170 public:
169 GrGLConvexPolyEffect(const GrProcessor&); 171 GrGLConvexPolyEffect(const GrProcessor&);
170 172
171 virtual void emitCode(EmitArgs&) override; 173 virtual void emitCode(EmitArgs&) override;
172 174
173 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 175 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
174 176
175 protected: 177 protected:
176 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 178 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
177 179
178 private: 180 private:
179 GrGLProgramDataManager::UniformHandle fEdgeUniform; 181 GrGLSLProgramDataManager::UniformHandle fEdgeUniform;
180 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges]; 182 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges];
181 typedef GrGLFragmentProcessor INHERITED; 183 typedef GrGLFragmentProcessor INHERITED;
182 }; 184 };
183 185
184 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { 186 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) {
185 fPrevEdges[0] = SK_ScalarNaN; 187 fPrevEdges[0] = SK_ScalarNaN;
186 } 188 }
187 189
188 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { 190 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
189 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); 191 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
(...skipping 25 matching lines...) Expand all
215 fsBuilder->codeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n "); 217 fsBuilder->codeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n ");
216 } 218 }
217 219
218 if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) { 220 if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) {
219 fsBuilder->codeAppend("\talpha = 1.0 - alpha;\n"); 221 fsBuilder->codeAppend("\talpha = 1.0 - alpha;\n");
220 } 222 }
221 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor, 223 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,
222 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 224 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str());
223 } 225 }
224 226
225 void GrGLConvexPolyEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& effect) { 227 void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman,
228 const GrProcessor& effect) {
226 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); 229 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>();
227 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); 230 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar);
228 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { 231 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) {
229 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); 232 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges());
230 memcpy(fPrevEdges, cpe.getEdges(), byteSize); 233 memcpy(fPrevEdges, cpe.getEdges(), byteSize);
231 } 234 }
232 } 235 }
233 236
234 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps &, 237 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps &,
235 GrProcessorKeyBuilder* b) { 238 GrProcessorKeyBuilder* b) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 351 }
349 352
350 GrFragmentProcessor* fp; 353 GrFragmentProcessor* fp;
351 do { 354 do {
352 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 355 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
353 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); 356 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt));
354 fp = GrConvexPolyEffect::Create(edgeType, count, edges); 357 fp = GrConvexPolyEffect::Create(edgeType, count, edges);
355 } while (nullptr == fp); 358 } while (nullptr == fp);
356 return fp; 359 return fp;
357 } 360 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConstColorProcessor.cpp ('k') | src/gpu/effects/GrConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698