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 "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "SkPath.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 "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
14 | 14 |
15 ////////////////////////////////////////////////////////////////////////////// | 15 ////////////////////////////////////////////////////////////////////////////// |
16 class AARectEffect : public GrFragmentProcessor { | 16 class AARectEffect : public GrFragmentProcessor { |
17 public: | 17 public: |
18 const SkRect& getRect() const { return fRect; } | 18 const SkRect& getRect() const { return fRect; } |
19 | 19 |
20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { | 20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { |
21 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); | 21 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); |
22 } | 22 } |
23 | 23 |
24 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 24 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
25 | 25 |
26 virtual const char* name() const SK_OVERRIDE { return "AARect"; } | 26 const char* name() const SK_OVERRIDE { return "AARect"; } |
27 | 27 |
28 virtual void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) cons
t SK_OVERRIDE; | 28 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const SK_OVE
RRIDE; |
29 | 29 |
30 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; | 30 GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
31 | 31 |
32 private: | 32 private: |
33 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) | 33 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) |
34 : fRect(rect), fEdgeType(edgeType) { | 34 : fRect(rect), fEdgeType(edgeType) { |
35 this->initClassID<AARectEffect>(); | 35 this->initClassID<AARectEffect>(); |
36 this->setWillReadFragmentPosition(); | 36 this->setWillReadFragmentPosition(); |
37 } | 37 } |
38 | 38 |
39 virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { | 39 bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { |
40 const AARectEffect& aare = other.cast<AARectEffect>(); | 40 const AARectEffect& aare = other.cast<AARectEffect>(); |
41 return fRect == aare.fRect; | 41 return fRect == aare.fRect; |
42 } | 42 } |
43 | 43 |
44 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE { | 44 void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE { |
45 if (fRect.isEmpty()) { | 45 if (fRect.isEmpty()) { |
46 // An empty rect will have no coverage anywhere. | 46 // An empty rect will have no coverage anywhere. |
47 inout->mulByKnownSingleComponent(0); | 47 inout->mulByKnownSingleComponent(0); |
48 } else { | 48 } else { |
49 inout->mulByUnknownSingleComponent(); | 49 inout->mulByUnknownSingleComponent(); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 SkRect fRect; | 53 SkRect fRect; |
54 GrPrimitiveEdgeType fEdgeType; | 54 GrPrimitiveEdgeType fEdgeType; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 virtual void emitCode(GrGLFPBuilder* builder, | 88 virtual void emitCode(GrGLFPBuilder* builder, |
89 const GrFragmentProcessor& fp, | 89 const GrFragmentProcessor& fp, |
90 const char* outputColor, | 90 const char* outputColor, |
91 const char* inputColor, | 91 const char* inputColor, |
92 const TransformedCoordsArray&, | 92 const TransformedCoordsArray&, |
93 const TextureSamplerArray&) SK_OVERRIDE; | 93 const TextureSamplerArray&) SK_OVERRIDE; |
94 | 94 |
95 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 95 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
96 | 96 |
97 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 97 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE; |
98 | 98 |
99 private: | 99 private: |
100 GrGLProgramDataManager::UniformHandle fRectUniform; | 100 GrGLProgramDataManager::UniformHandle fRectUniform; |
101 SkRect fPrevRect; | 101 SkRect fPrevRect; |
102 typedef GrGLFragmentProcessor INHERITED; | 102 typedef GrGLFragmentProcessor INHERITED; |
103 }; | 103 }; |
104 | 104 |
105 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { | 105 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { |
106 fPrevRect.fLeft = SK_ScalarNaN; | 106 fPrevRect.fLeft = SK_ScalarNaN; |
107 } | 107 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 virtual void emitCode(GrGLFPBuilder* builder, | 183 virtual void emitCode(GrGLFPBuilder* builder, |
184 const GrFragmentProcessor& fp, | 184 const GrFragmentProcessor& fp, |
185 const char* outputColor, | 185 const char* outputColor, |
186 const char* inputColor, | 186 const char* inputColor, |
187 const TransformedCoordsArray&, | 187 const TransformedCoordsArray&, |
188 const TextureSamplerArray&) SK_OVERRIDE; | 188 const TextureSamplerArray&) SK_OVERRIDE; |
189 | 189 |
190 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 190 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
191 | 191 |
192 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 192 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE; |
193 | 193 |
194 private: | 194 private: |
195 GrGLProgramDataManager::UniformHandle fEdgeUniform; | 195 GrGLProgramDataManager::UniformHandle fEdgeUniform; |
196 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; | 196 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; |
197 typedef GrGLFragmentProcessor INHERITED; | 197 typedef GrGLFragmentProcessor INHERITED; |
198 }; | 198 }; |
199 | 199 |
200 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { | 200 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { |
201 fPrevEdges[0] = SK_ScalarNaN; | 201 fPrevEdges[0] = SK_ScalarNaN; |
202 } | 202 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 372 } |
373 | 373 |
374 GrFragmentProcessor* fp; | 374 GrFragmentProcessor* fp; |
375 do { | 375 do { |
376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); | 377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); |
378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
379 } while (NULL == fp); | 379 } while (NULL == fp); |
380 return fp; | 380 return fp; |
381 } | 381 } |
OLD | NEW |