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 "GrDefaultGeoProcFactory.h" | 8 #include "GrDefaultGeoProcFactory.h" |
9 | 9 |
10 #include "GrDrawState.h" | 10 #include "GrDrawState.h" |
11 #include "GrInvariantOutput.h" | 11 #include "GrInvariantOutput.h" |
12 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
14 | 14 |
15 /* | 15 /* |
16 * The default Geometry Processor simply takes position and multiplies it by the
uniform view | 16 * The default Geometry Processor simply takes position and multiplies it by the
uniform view |
17 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per
vertex color or | 17 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per
vertex color or |
18 * local coords. | 18 * local coords. |
19 */ | 19 */ |
20 typedef GrDefaultGeoProcFactory Flag; | 20 typedef GrDefaultGeoProcFactory Flag; |
21 | 21 |
22 class DefaultGeoProc : public GrGeometryProcessor { | 22 class DefaultGeoProc : public GrGeometryProcessor { |
23 public: | 23 public: |
24 static GrGeometryProcessor* Create(uint32_t gpTypeFlags) { | 24 static GrGeometryProcessor* Create(GrColor color, uint8_t coverage, uint32_t
gpTypeFlags) { |
25 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags)); | 25 return SkNEW_ARGS(DefaultGeoProc, (color, coverage, gpTypeFlags)); |
26 } | 26 } |
27 | 27 |
28 virtual const char* name() const SK_OVERRIDE { return "DefaultGeometryProces
sor"; } | 28 virtual const char* name() const SK_OVERRIDE { return "DefaultGeometryProces
sor"; } |
29 | 29 |
30 const GrAttribute* inPosition() const { return fInPosition; } | 30 const GrAttribute* inPosition() const { return fInPosition; } |
31 const GrAttribute* inColor() const { return fInColor; } | 31 const GrAttribute* inColor() const { return fInColor; } |
32 const GrAttribute* inLocalCoords() const { return fInLocalCoords; } | 32 const GrAttribute* inLocalCoords() const { return fInLocalCoords; } |
33 const GrAttribute* inCoverage() const { return fInCoverage; } | 33 const GrAttribute* inCoverage() const { return fInCoverage; } |
34 | 34 |
35 class GLProcessor : public GrGLGeometryProcessor { | 35 class GLProcessor : public GrGLGeometryProcessor { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const GrGLCaps& caps, | 88 const GrGLCaps& caps, |
89 GrProcessorKeyBuilder* b) const SK_OVERRIDE { | 89 GrProcessorKeyBuilder* b) const SK_OVERRIDE { |
90 GLProcessor::GenKey(*this, bt, caps, b); | 90 GLProcessor::GenKey(*this, bt, caps, b); |
91 } | 91 } |
92 | 92 |
93 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE { | 93 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE { |
94 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 94 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
95 } | 95 } |
96 | 96 |
97 private: | 97 private: |
98 DefaultGeoProc(uint32_t gpTypeFlags) | 98 DefaultGeoProc(GrColor color, uint8_t coverage, uint32_t gpTypeFlags) |
99 : fInPosition(NULL) | 99 : INHERITED(color, coverage) |
| 100 , fInPosition(NULL) |
100 , fInColor(NULL) | 101 , fInColor(NULL) |
101 , fInLocalCoords(NULL) | 102 , fInLocalCoords(NULL) |
102 , fInCoverage(NULL) | 103 , fInCoverage(NULL) |
103 , fFlags(gpTypeFlags) { | 104 , fFlags(gpTypeFlags) { |
104 this->initClassID<DefaultGeoProc>(); | 105 this->initClassID<DefaultGeoProc>(); |
105 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G
PType); | 106 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G
PType); |
106 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo
calCoord_GPType); | 107 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo
calCoord_GPType); |
107 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove
rage_GPType); | 108 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove
rage_GPType); |
108 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_Gr
VertexAttribType)); | 109 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_Gr
VertexAttribType)); |
109 if (hasColor) { | 110 if (hasColor) { |
(...skipping 26 matching lines...) Expand all Loading... |
136 } | 137 } |
137 | 138 |
138 const GrAttribute* fInPosition; | 139 const GrAttribute* fInPosition; |
139 const GrAttribute* fInColor; | 140 const GrAttribute* fInColor; |
140 const GrAttribute* fInLocalCoords; | 141 const GrAttribute* fInLocalCoords; |
141 const GrAttribute* fInCoverage; | 142 const GrAttribute* fInCoverage; |
142 uint32_t fFlags; | 143 uint32_t fFlags; |
143 | 144 |
144 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 145 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
145 | 146 |
146 typedef GrFragmentProcessor INHERITED; | 147 typedef GrGeometryProcessor INHERITED; |
147 }; | 148 }; |
148 | 149 |
149 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); | 150 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
150 | 151 |
151 GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random, | 152 GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random, |
152 GrContext*, | 153 GrContext*, |
153 const GrDrawTargetCaps& caps, | 154 const GrDrawTargetCaps& caps, |
154 GrTexture*[]) { | 155 GrTexture*[]) { |
155 uint32_t flags = 0; | 156 uint32_t flags = 0; |
156 if (random->nextBool()) { | 157 if (random->nextBool()) { |
157 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 158 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
158 } | 159 } |
159 if (random->nextBool()) { | 160 if (random->nextBool()) { |
160 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; | 161 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; |
161 } | 162 } |
162 if (random->nextBool()) { | 163 if (random->nextBool()) { |
163 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 164 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
164 } | 165 } |
165 | 166 |
166 return DefaultGeoProc::Create(flags); | 167 return DefaultGeoProc::Create(GrRandomColor(random), GrRandomCoverage(random
), flags); |
167 } | 168 } |
168 | 169 |
169 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags)
{ | 170 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(GrColor color, uint32
_t gpTypeFlags, |
170 return DefaultGeoProc::Create(gpTypeFlags); | 171 uint8_t coverage) { |
| 172 return DefaultGeoProc::Create(color, coverage, gpTypeFlags); |
171 } | 173 } |
OLD | NEW |