OLD | NEW |
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 "gl/builders/GrGLProgramBuilder.h" | |
9 #include "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
10 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "SkPath.h" |
11 #include "gl/GrGLProcessor.h" | 11 #include "gl/GrGLProcessor.h" |
12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
13 #include "GrTBackendProcessorFactory.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
14 | |
15 #include "SkPath.h" | |
16 | 14 |
17 ////////////////////////////////////////////////////////////////////////////// | 15 ////////////////////////////////////////////////////////////////////////////// |
18 class GLAARectEffect; | |
19 | |
20 class AARectEffect : public GrFragmentProcessor { | 16 class AARectEffect : public GrFragmentProcessor { |
21 public: | 17 public: |
22 typedef GLAARectEffect GLProcessor; | |
23 | |
24 const SkRect& getRect() const { return fRect; } | 18 const SkRect& getRect() const { return fRect; } |
25 | 19 |
26 static const char* Name() { return "AARect"; } | |
27 | |
28 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { | 20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { |
29 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); | 21 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); |
30 } | 22 } |
31 | 23 |
32 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 24 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
33 | 25 |
34 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 26 virtual const char* name() const SK_OVERRIDE { return "AARect"; } |
| 27 |
| 28 virtual void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) cons
t SK_OVERRIDE; |
| 29 |
| 30 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
35 | 31 |
36 private: | 32 private: |
37 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) : fRect(rect)
, fEdgeType(edgeType) { | 33 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) |
| 34 : fRect(rect), fEdgeType(edgeType) { |
| 35 this->initClassID<AARectEffect>(); |
38 this->setWillReadFragmentPosition(); | 36 this->setWillReadFragmentPosition(); |
39 } | 37 } |
40 | 38 |
41 virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { | 39 virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { |
42 const AARectEffect& aare = other.cast<AARectEffect>(); | 40 const AARectEffect& aare = other.cast<AARectEffect>(); |
43 return fRect == aare.fRect; | 41 return fRect == aare.fRect; |
44 } | 42 } |
45 | 43 |
46 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE { | 44 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE { |
47 if (fRect.isEmpty()) { | 45 if (fRect.isEmpty()) { |
(...skipping 30 matching lines...) Expand all Loading... |
78 | 76 |
79 fp = AARectEffect::Create(edgeType, rect); | 77 fp = AARectEffect::Create(edgeType, rect); |
80 } while (NULL == fp); | 78 } while (NULL == fp); |
81 return fp; | 79 return fp; |
82 } | 80 } |
83 | 81 |
84 ////////////////////////////////////////////////////////////////////////////// | 82 ////////////////////////////////////////////////////////////////////////////// |
85 | 83 |
86 class GLAARectEffect : public GrGLFragmentProcessor { | 84 class GLAARectEffect : public GrGLFragmentProcessor { |
87 public: | 85 public: |
88 GLAARectEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 86 GLAARectEffect(const GrProcessor&); |
89 | 87 |
90 virtual void emitCode(GrGLFPBuilder* builder, | 88 virtual void emitCode(GrGLFPBuilder* builder, |
91 const GrFragmentProcessor& fp, | 89 const GrFragmentProcessor& fp, |
92 const char* outputColor, | 90 const char* outputColor, |
93 const char* inputColor, | 91 const char* inputColor, |
94 const TransformedCoordsArray&, | 92 const TransformedCoordsArray&, |
95 const TextureSamplerArray&) SK_OVERRIDE; | 93 const TextureSamplerArray&) SK_OVERRIDE; |
96 | 94 |
97 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 95 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
98 | 96 |
99 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 97 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
100 | 98 |
101 private: | 99 private: |
102 GrGLProgramDataManager::UniformHandle fRectUniform; | 100 GrGLProgramDataManager::UniformHandle fRectUniform; |
103 SkRect fPrevRect; | 101 SkRect fPrevRect; |
104 typedef GrGLFragmentProcessor INHERITED; | 102 typedef GrGLFragmentProcessor INHERITED; |
105 }; | 103 }; |
106 | 104 |
107 GLAARectEffect::GLAARectEffect(const GrBackendProcessorFactory& factory, | 105 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { |
108 const GrProcessor& effect) | |
109 : INHERITED (factory) { | |
110 fPrevRect.fLeft = SK_ScalarNaN; | 106 fPrevRect.fLeft = SK_ScalarNaN; |
111 } | 107 } |
112 | 108 |
113 void GLAARectEffect::emitCode(GrGLFPBuilder* builder, | 109 void GLAARectEffect::emitCode(GrGLFPBuilder* builder, |
114 const GrFragmentProcessor& fp, | 110 const GrFragmentProcessor& fp, |
115 const char* outputColor, | 111 const char* outputColor, |
116 const char* inputColor, | 112 const char* inputColor, |
117 const TransformedCoordsArray&, | 113 const TransformedCoordsArray&, |
118 const TextureSamplerArray& samplers) { | 114 const TextureSamplerArray& samplers) { |
119 const AARectEffect& aare = fp.cast<AARectEffect>(); | 115 const AARectEffect& aare = fp.cast<AARectEffect>(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 fPrevRect = rect; | 158 fPrevRect = rect; |
163 } | 159 } |
164 } | 160 } |
165 | 161 |
166 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, | 162 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, |
167 GrProcessorKeyBuilder* b) { | 163 GrProcessorKeyBuilder* b) { |
168 const AARectEffect& aare = processor.cast<AARectEffect>(); | 164 const AARectEffect& aare = processor.cast<AARectEffect>(); |
169 b->add32(aare.getEdgeType()); | 165 b->add32(aare.getEdgeType()); |
170 } | 166 } |
171 | 167 |
172 const GrBackendFragmentProcessorFactory& AARectEffect::getFactory() const { | 168 void AARectEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder
* b) const { |
173 return GrTBackendFragmentProcessorFactory<AARectEffect>::getInstance(); | 169 GLAARectEffect::GenKey(*this, caps, b); |
| 170 } |
| 171 |
| 172 GrGLFragmentProcessor* AARectEffect::createGLInstance() const { |
| 173 return SkNEW_ARGS(GLAARectEffect, (*this)); |
174 } | 174 } |
175 | 175 |
176 ////////////////////////////////////////////////////////////////////////////// | 176 ////////////////////////////////////////////////////////////////////////////// |
177 | 177 |
178 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { | 178 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { |
179 public: | 179 public: |
180 GrGLConvexPolyEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 180 GrGLConvexPolyEffect(const GrProcessor&); |
181 | 181 |
182 virtual void emitCode(GrGLFPBuilder* builder, | 182 virtual void emitCode(GrGLFPBuilder* builder, |
183 const GrFragmentProcessor& fp, | 183 const GrFragmentProcessor& fp, |
184 const char* outputColor, | 184 const char* outputColor, |
185 const char* inputColor, | 185 const char* inputColor, |
186 const TransformedCoordsArray&, | 186 const TransformedCoordsArray&, |
187 const TextureSamplerArray&) SK_OVERRIDE; | 187 const TextureSamplerArray&) SK_OVERRIDE; |
188 | 188 |
189 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 189 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
190 | 190 |
191 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 191 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
192 | 192 |
193 private: | 193 private: |
194 GrGLProgramDataManager::UniformHandle fEdgeUniform; | 194 GrGLProgramDataManager::UniformHandle fEdgeUniform; |
195 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; | 195 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; |
196 typedef GrGLFragmentProcessor INHERITED; | 196 typedef GrGLFragmentProcessor INHERITED; |
197 }; | 197 }; |
198 | 198 |
199 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrBackendProcessorFactory& fact
ory, | 199 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { |
200 const GrProcessor&) | |
201 : INHERITED (factory) { | |
202 fPrevEdges[0] = SK_ScalarNaN; | 200 fPrevEdges[0] = SK_ScalarNaN; |
203 } | 201 } |
204 | 202 |
205 void GrGLConvexPolyEffect::emitCode(GrGLFPBuilder* builder, | 203 void GrGLConvexPolyEffect::emitCode(GrGLFPBuilder* builder, |
206 const GrFragmentProcessor& fp, | 204 const GrFragmentProcessor& fp, |
207 const char* outputColor, | 205 const char* outputColor, |
208 const char* inputColor, | 206 const char* inputColor, |
209 const TransformedCoordsArray&, | 207 const TransformedCoordsArray&, |
210 const TextureSamplerArray& samplers) { | 208 const TextureSamplerArray& samplers) { |
211 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); | 209 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 317 } |
320 return AARectEffect::Create(edgeType, rect); | 318 return AARectEffect::Create(edgeType, rect); |
321 } | 319 } |
322 | 320 |
323 GrConvexPolyEffect::~GrConvexPolyEffect() {} | 321 GrConvexPolyEffect::~GrConvexPolyEffect() {} |
324 | 322 |
325 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { | 323 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { |
326 inout->mulByUnknownAlpha(); | 324 inout->mulByUnknownAlpha(); |
327 } | 325 } |
328 | 326 |
329 const GrBackendFragmentProcessorFactory& GrConvexPolyEffect::getFactory() const
{ | 327 void GrConvexPolyEffect::getGLProcessorKey(const GrGLCaps& caps, |
330 return GrTBackendFragmentProcessorFactory<GrConvexPolyEffect>::getInstance()
; | 328 GrProcessorKeyBuilder* b) const { |
| 329 GrGLConvexPolyEffect::GenKey(*this, caps, b); |
| 330 } |
| 331 |
| 332 GrGLFragmentProcessor* GrConvexPolyEffect::createGLInstance() const { |
| 333 return SkNEW_ARGS(GrGLConvexPolyEffect, (*this)); |
331 } | 334 } |
332 | 335 |
333 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons
t SkScalar edges[]) | 336 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons
t SkScalar edges[]) |
334 : fEdgeType(edgeType) | 337 : fEdgeType(edgeType) |
335 , fEdgeCount(n) { | 338 , fEdgeCount(n) { |
| 339 this->initClassID<GrConvexPolyEffect>(); |
336 // Factory function should have already ensured this. | 340 // Factory function should have already ensured this. |
337 SkASSERT(n <= kMaxEdges); | 341 SkASSERT(n <= kMaxEdges); |
338 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); | 342 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); |
339 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov
ered in the AA case | 343 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov
ered in the AA case |
340 // and 100% covered in the non-AA case. | 344 // and 100% covered in the non-AA case. |
341 for (int i = 0; i < n; ++i) { | 345 for (int i = 0; i < n; ++i) { |
342 fEdges[3 * i + 2] += SK_ScalarHalf; | 346 fEdges[3 * i + 2] += SK_ScalarHalf; |
343 } | 347 } |
344 this->setWillReadFragmentPosition(); | 348 this->setWillReadFragmentPosition(); |
345 } | 349 } |
(...skipping 20 matching lines...) Expand all Loading... |
366 } | 370 } |
367 | 371 |
368 GrFragmentProcessor* fp; | 372 GrFragmentProcessor* fp; |
369 do { | 373 do { |
370 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 374 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
371 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); | 375 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); |
372 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 376 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
373 } while (NULL == fp); | 377 } while (NULL == fp); |
374 return fp; | 378 return fp; |
375 } | 379 } |
OLD | NEW |