| 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 "GrTBackendProcessorFactory.h" | |
| 13 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
| 14 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
| 15 | 14 |
| 16 /* | 15 /* |
| 17 * 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 |
| 18 * 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 |
| 19 * local coords. | 18 * local coords. |
| 20 */ | 19 */ |
| 21 typedef GrDefaultGeoProcFactory Flag; | 20 typedef GrDefaultGeoProcFactory Flag; |
| 22 | 21 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 case Flag::kPosition_GPType: { | 54 case Flag::kPosition_GPType: { |
| 56 GR_CREATE_STATIC_PROCESSOR(gDefaultGeoProc, DefaultGeoProc, (gpT
ypeFlags)); | 55 GR_CREATE_STATIC_PROCESSOR(gDefaultGeoProc, DefaultGeoProc, (gpT
ypeFlags)); |
| 57 return SkRef(gDefaultGeoProc); | 56 return SkRef(gDefaultGeoProc); |
| 58 } | 57 } |
| 59 default: | 58 default: |
| 60 SkFAIL("Incomplete Switch"); | 59 SkFAIL("Incomplete Switch"); |
| 61 return NULL; | 60 return NULL; |
| 62 } | 61 } |
| 63 } | 62 } |
| 64 | 63 |
| 65 static const char* Name() { return "DefaultGeometryProcessor"; } | 64 virtual const char* name() const SK_OVERRIDE { return "DefaultGeometryProces
sor"; } |
| 66 | |
| 67 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR
IDE { | |
| 68 return GrTBackendGeometryProcessorFactory<DefaultGeoProc>::getInstance()
; | |
| 69 } | |
| 70 | 65 |
| 71 const GrAttribute* inPosition() const { return fInPosition; } | 66 const GrAttribute* inPosition() const { return fInPosition; } |
| 72 const GrAttribute* inColor() const { return fInColor; } | 67 const GrAttribute* inColor() const { return fInColor; } |
| 73 const GrAttribute* inLocalCoords() const { return fInLocalCoords; } | 68 const GrAttribute* inLocalCoords() const { return fInLocalCoords; } |
| 74 const GrAttribute* inCoverage() const { return fInCoverage; } | 69 const GrAttribute* inCoverage() const { return fInCoverage; } |
| 75 | 70 |
| 76 class GLProcessor : public GrGLGeometryProcessor { | 71 class GLProcessor : public GrGLGeometryProcessor { |
| 77 public: | 72 public: |
| 78 GLProcessor(const GrBackendProcessorFactory& factory, | 73 GLProcessor(const GrGeometryProcessor&, |
| 79 const GrGeometryProcessor&, | 74 const GrBatchTracker&) {} |
| 80 const GrBatchTracker&) | |
| 81 : INHERITED (factory) {} | |
| 82 | 75 |
| 83 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 76 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 84 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); | 77 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
| 85 GrGLVertexBuilder* vs = args.fPB->getVertexShaderBuilder(); | 78 GrGLVertexBuilder* vs = args.fPB->getVertexShaderBuilder(); |
| 86 | 79 |
| 87 vs->codeAppendf("%s = %s;", vs->positionCoords(), gp.inPosition()->f
Name); | 80 vs->codeAppendf("%s = %s;", vs->positionCoords(), gp.inPosition()->f
Name); |
| 88 | 81 |
| 89 // Setup pass through color | 82 // Setup pass through color |
| 90 if (gp.inColor()) { | 83 if (gp.inColor()) { |
| 91 args.fPB->addPassThroughAttribute(gp.inColor(), args.fOutputColo
r); | 84 args.fPB->addPassThroughAttribute(gp.inColor(), args.fOutputColo
r); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 120 } | 113 } |
| 121 | 114 |
| 122 virtual void setData(const GrGLProgramDataManager&, | 115 virtual void setData(const GrGLProgramDataManager&, |
| 123 const GrGeometryProcessor&, | 116 const GrGeometryProcessor&, |
| 124 const GrBatchTracker&) SK_OVERRIDE {} | 117 const GrBatchTracker&) SK_OVERRIDE {} |
| 125 | 118 |
| 126 private: | 119 private: |
| 127 typedef GrGLGeometryProcessor INHERITED; | 120 typedef GrGLGeometryProcessor INHERITED; |
| 128 }; | 121 }; |
| 129 | 122 |
| 123 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 124 const GrGLCaps& caps, |
| 125 GrProcessorKeyBuilder* b) const SK_OVERRIDE { |
| 126 GLProcessor::GenKey(*this, bt, caps, b); |
| 127 } |
| 128 |
| 129 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE { |
| 130 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
| 131 } |
| 132 |
| 133 virtual uint32_t classID() const { |
| 134 static uint32_t id = GenClassID(); |
| 135 return id; |
| 136 } |
| 137 |
| 130 private: | 138 private: |
| 131 DefaultGeoProc(uint32_t gpTypeFlags) | 139 DefaultGeoProc(uint32_t gpTypeFlags) |
| 132 : fInPosition(NULL) | 140 : fInPosition(NULL) |
| 133 , fInColor(NULL) | 141 , fInColor(NULL) |
| 134 , fInLocalCoords(NULL) | 142 , fInLocalCoords(NULL) |
| 135 , fInCoverage(NULL) | 143 , fInCoverage(NULL) |
| 136 , fFlags(gpTypeFlags) { | 144 , fFlags(gpTypeFlags) { |
| 137 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G
PType); | 145 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G
PType); |
| 138 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo
calCoord_GPType); | 146 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo
calCoord_GPType); |
| 139 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove
rage_GPType); | 147 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove
rage_GPType); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 if (random->nextBool()) { | 202 if (random->nextBool()) { |
| 195 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 203 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 196 } | 204 } |
| 197 | 205 |
| 198 return DefaultGeoProc::Create(flags); | 206 return DefaultGeoProc::Create(flags); |
| 199 } | 207 } |
| 200 | 208 |
| 201 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags)
{ | 209 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags)
{ |
| 202 return DefaultGeoProc::Create(gpTypeFlags); | 210 return DefaultGeoProc::Create(gpTypeFlags); |
| 203 } | 211 } |
| OLD | NEW |