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

Side by Side Diff: src/gpu/effects/GrConvexPolyEffect.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 | « src/gpu/effects/GrConvexPolyEffect.h ('k') | src/gpu/effects/GrConvolutionEffect.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 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/GrGLFragmentProcessor.h" 11 #include "gl/GrGLFragmentProcessor.h"
12 #include "gl/builders/GrGLProgramBuilder.h" 12 #include "gl/builders/GrGLProgramBuilder.h"
13 13
14 ////////////////////////////////////////////////////////////////////////////// 14 //////////////////////////////////////////////////////////////////////////////
15 class AARectEffect : public GrFragmentProcessor { 15 class AARectEffect : public GrFragmentProcessor {
16 public: 16 public:
17 const SkRect& getRect() const { return fRect; } 17 const SkRect& getRect() const { return fRect; }
18 18
19 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec t& rect) { 19 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec t& rect) {
20 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); 20 return SkNEW_ARGS(AARectEffect, (edgeType, rect));
21 } 21 }
22 22
23 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } 23 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; }
24 24
25 const char* name() const override { return "AARect"; } 25 const char* name() const override { return "AARect"; }
26 26
27 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 27 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
28 28
29 GrGLFragmentProcessor* createGLInstance() const override;
30
31 private: 29 private:
32 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) 30 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect)
33 : fRect(rect), fEdgeType(edgeType) { 31 : fRect(rect), fEdgeType(edgeType) {
34 this->initClassID<AARectEffect>(); 32 this->initClassID<AARectEffect>();
35 this->setWillReadFragmentPosition(); 33 this->setWillReadFragmentPosition();
36 } 34 }
37 35
36 GrGLFragmentProcessor* onCreateGLInstance() const override;
37
38 bool onIsEqual(const GrFragmentProcessor& other) const override { 38 bool onIsEqual(const GrFragmentProcessor& other) const override {
39 const AARectEffect& aare = other.cast<AARectEffect>(); 39 const AARectEffect& aare = other.cast<AARectEffect>();
40 return fRect == aare.fRect; 40 return fRect == aare.fRect;
41 } 41 }
42 42
43 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 43 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
44 if (fRect.isEmpty()) { 44 if (fRect.isEmpty()) {
45 // An empty rect will have no coverage anywhere. 45 // An empty rect will have no coverage anywhere.
46 inout->mulByKnownSingleComponent(0); 46 inout->mulByKnownSingleComponent(0);
47 } else { 47 } else {
(...skipping 30 matching lines...) Expand all
78 ////////////////////////////////////////////////////////////////////////////// 78 //////////////////////////////////////////////////////////////////////////////
79 79
80 class GLAARectEffect : public GrGLFragmentProcessor { 80 class GLAARectEffect : public GrGLFragmentProcessor {
81 public: 81 public:
82 GLAARectEffect(const GrProcessor&); 82 GLAARectEffect(const GrProcessor&);
83 83
84 virtual void emitCode(EmitArgs&) override; 84 virtual void emitCode(EmitArgs&) override;
85 85
86 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 86 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
87 87
88 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 88 protected:
89 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
89 90
90 private: 91 private:
91 GrGLProgramDataManager::UniformHandle fRectUniform; 92 GrGLProgramDataManager::UniformHandle fRectUniform;
92 SkRect fPrevRect; 93 SkRect fPrevRect;
93 typedef GrGLFragmentProcessor INHERITED; 94 typedef GrGLFragmentProcessor INHERITED;
94 }; 95 };
95 96
96 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { 97 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) {
97 fPrevRect.fLeft = SK_ScalarNaN; 98 fPrevRect.fLeft = SK_ScalarNaN;
98 } 99 }
(...skipping 30 matching lines...) Expand all
129 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos); 130 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos);
130 } 131 }
131 132
132 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) { 133 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) {
133 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n"); 134 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n");
134 } 135 }
135 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor, 136 fsBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor,
136 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 137 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str());
137 } 138 }
138 139
139 void GLAARectEffect::setData(const GrGLProgramDataManager& pdman, const GrProces sor& processor) { 140 void GLAARectEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProc essor& processor) {
140 const AARectEffect& aare = processor.cast<AARectEffect>(); 141 const AARectEffect& aare = processor.cast<AARectEffect>();
141 const SkRect& rect = aare.getRect(); 142 const SkRect& rect = aare.getRect();
142 if (rect != fPrevRect) { 143 if (rect != fPrevRect) {
143 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, 144 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f,
144 rect.fRight - 0.5f, rect.fBottom - 0.5f); 145 rect.fRight - 0.5f, rect.fBottom - 0.5f);
145 fPrevRect = rect; 146 fPrevRect = rect;
146 } 147 }
147 } 148 }
148 149
149 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, 150 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&,
150 GrProcessorKeyBuilder* b) { 151 GrProcessorKeyBuilder* b) {
151 const AARectEffect& aare = processor.cast<AARectEffect>(); 152 const AARectEffect& aare = processor.cast<AARectEffect>();
152 b->add32(aare.getEdgeType()); 153 b->add32(aare.getEdgeType());
153 } 154 }
154 155
155 void AARectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui lder* b) const { 156 void AARectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui lder* b) const {
156 GLAARectEffect::GenKey(*this, caps, b); 157 GLAARectEffect::GenKey(*this, caps, b);
157 } 158 }
158 159
159 GrGLFragmentProcessor* AARectEffect::createGLInstance() const { 160 GrGLFragmentProcessor* AARectEffect::onCreateGLInstance() const {
160 return SkNEW_ARGS(GLAARectEffect, (*this)); 161 return SkNEW_ARGS(GLAARectEffect, (*this));
161 } 162 }
162 163
163 ////////////////////////////////////////////////////////////////////////////// 164 //////////////////////////////////////////////////////////////////////////////
164 165
165 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { 166 class GrGLConvexPolyEffect : public GrGLFragmentProcessor {
166 public: 167 public:
167 GrGLConvexPolyEffect(const GrProcessor&); 168 GrGLConvexPolyEffect(const GrProcessor&);
168 169
169 virtual void emitCode(EmitArgs&) override; 170 virtual void emitCode(EmitArgs&) override;
170 171
171 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 172 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
172 173
173 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 174 protected:
175 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
174 176
175 private: 177 private:
176 GrGLProgramDataManager::UniformHandle fEdgeUniform; 178 GrGLProgramDataManager::UniformHandle fEdgeUniform;
177 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges]; 179 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges];
178 typedef GrGLFragmentProcessor INHERITED; 180 typedef GrGLFragmentProcessor INHERITED;
179 }; 181 };
180 182
181 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { 183 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) {
182 fPrevEdges[0] = SK_ScalarNaN; 184 fPrevEdges[0] = SK_ScalarNaN;
183 } 185 }
(...skipping 28 matching lines...) Expand all
212 fsBuilder->codeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n "); 214 fsBuilder->codeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n ");
213 } 215 }
214 216
215 if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) { 217 if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) {
216 fsBuilder->codeAppend("\talpha = 1.0 - alpha;\n"); 218 fsBuilder->codeAppend("\talpha = 1.0 - alpha;\n");
217 } 219 }
218 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor, 220 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,
219 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str()); 221 (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha") ).c_str());
220 } 222 }
221 223
222 void GrGLConvexPolyEffect::setData(const GrGLProgramDataManager& pdman, const Gr Processor& effect) { 224 void GrGLConvexPolyEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& effect) {
223 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); 225 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>();
224 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); 226 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar);
225 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { 227 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) {
226 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); 228 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges());
227 memcpy(fPrevEdges, cpe.getEdges(), byteSize); 229 memcpy(fPrevEdges, cpe.getEdges(), byteSize);
228 } 230 }
229 } 231 }
230 232
231 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps &, 233 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps &,
232 GrProcessorKeyBuilder* b) { 234 GrProcessorKeyBuilder* b) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 302
301 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons t { 303 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons t {
302 inout->mulByUnknownSingleComponent(); 304 inout->mulByUnknownSingleComponent();
303 } 305 }
304 306
305 void GrConvexPolyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 307 void GrConvexPolyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
306 GrProcessorKeyBuilder* b) const { 308 GrProcessorKeyBuilder* b) const {
307 GrGLConvexPolyEffect::GenKey(*this, caps, b); 309 GrGLConvexPolyEffect::GenKey(*this, caps, b);
308 } 310 }
309 311
310 GrGLFragmentProcessor* GrConvexPolyEffect::createGLInstance() const { 312 GrGLFragmentProcessor* GrConvexPolyEffect::onCreateGLInstance() const {
311 return SkNEW_ARGS(GrGLConvexPolyEffect, (*this)); 313 return SkNEW_ARGS(GrGLConvexPolyEffect, (*this));
312 } 314 }
313 315
314 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons t SkScalar edges[]) 316 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons t SkScalar edges[])
315 : fEdgeType(edgeType) 317 : fEdgeType(edgeType)
316 , fEdgeCount(n) { 318 , fEdgeCount(n) {
317 this->initClassID<GrConvexPolyEffect>(); 319 this->initClassID<GrConvexPolyEffect>();
318 // Factory function should have already ensured this. 320 // Factory function should have already ensured this.
319 SkASSERT(n <= kMaxEdges); 321 SkASSERT(n <= kMaxEdges);
320 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); 322 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar));
(...skipping 24 matching lines...) Expand all
345 } 347 }
346 348
347 GrFragmentProcessor* fp; 349 GrFragmentProcessor* fp;
348 do { 350 do {
349 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 351 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
350 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); 352 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt));
351 fp = GrConvexPolyEffect::Create(edgeType, count, edges); 353 fp = GrConvexPolyEffect::Create(edgeType, count, edges);
352 } while (NULL == fp); 354 } while (NULL == fp);
353 return fp; 355 return fp;
354 } 356 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConvexPolyEffect.h ('k') | src/gpu/effects/GrConvolutionEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698