| 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 "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 bool hasVertexColor() const { return SkToBool(fInColor); } | 48 bool hasVertexColor() const { return SkToBool(fInColor); } |
| 49 const SkMatrix& viewMatrix() const { return fViewMatrix; } | 49 const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 50 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 50 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
| 51 bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; } | 51 bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; } |
| 52 uint8_t coverage() const { return fCoverage; } | 52 uint8_t coverage() const { return fCoverage; } |
| 53 bool coverageWillBeIgnored() const { return fCoverageWillBeIgnored; } | 53 bool coverageWillBeIgnored() const { return fCoverageWillBeIgnored; } |
| 54 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } | 54 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } |
| 55 | 55 |
| 56 class GLProcessor : public GrGLGeometryProcessor { | 56 class GLProcessor : public GrGLGeometryProcessor { |
| 57 public: | 57 public: |
| 58 GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&) | 58 GLProcessor() |
| 59 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f
Coverage(0xff) {} | 59 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f
Coverage(0xff) {} |
| 60 | 60 |
| 61 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 61 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 62 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); | 62 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
| 63 GrGLGPBuilder* pb = args.fPB; | 63 GrGLGPBuilder* pb = args.fPB; |
| 64 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 64 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
| 65 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); | 65 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); |
| 66 | 66 |
| 67 // emit attributes | 67 // emit attributes |
| 68 vsBuilder->emitAttributes(gp); | 68 vsBuilder->emitAttributes(gp); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 kFloat_GrSLType, | 108 kFloat_GrSLType, |
| 109 kDefault_GrSLPrecision, | 109 kDefault_GrSLPrecision, |
| 110 "Coverage", | 110 "Coverage", |
| 111 &fragCoverage); | 111 &fragCoverage); |
| 112 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, frag
Coverage); | 112 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, frag
Coverage); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 static inline void GenKey(const GrGeometryProcessor& gp, | 117 static inline void GenKey(const GrGeometryProcessor& gp, |
| 118 const GrBatchTracker& bt, | |
| 119 const GrGLSLCaps&, | 118 const GrGLSLCaps&, |
| 120 GrProcessorKeyBuilder* b) { | 119 GrProcessorKeyBuilder* b) { |
| 121 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); | 120 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
| 122 uint32_t key = def.fFlags; | 121 uint32_t key = def.fFlags; |
| 123 key |= def.colorIgnored() << 8; | 122 key |= def.colorIgnored() << 8; |
| 124 key |= def.coverageWillBeIgnored() << 9; | 123 key |= def.coverageWillBeIgnored() << 9; |
| 125 key |= def.hasVertexColor() << 10; | 124 key |= def.hasVertexColor() << 10; |
| 126 key |= def.hasVertexCoverage() << 11; | 125 key |= def.hasVertexCoverage() << 11; |
| 127 key |= def.coverage() == 0xff ? 0x1 << 12 : 0; | 126 key |= def.coverage() == 0xff ? 0x1 << 12 : 0; |
| 128 key |= def.localCoordsWillBeRead() && def.localMatrix().hasPerspecti
ve() ? 0x1 << 24 : | 127 key |= def.localCoordsWillBeRead() && def.localMatrix().hasPerspecti
ve() ? 0x1 << 24 : |
| 129
0x0; | 128
0x0; |
| 130 key |= ComputePosKey(def.viewMatrix()) << 25; | 129 key |= ComputePosKey(def.viewMatrix()) << 25; |
| 131 b->add32(key); | 130 b->add32(key); |
| 132 } | 131 } |
| 133 | 132 |
| 134 virtual void setData(const GrGLProgramDataManager& pdman, | 133 void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProce
ssor& gp) override { |
| 135 const GrPrimitiveProcessor& gp, | |
| 136 const GrBatchTracker& bt) override { | |
| 137 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); | 134 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
| 138 | 135 |
| 139 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.
viewMatrix())) { | 136 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.
viewMatrix())) { |
| 140 fViewMatrix = dgp.viewMatrix(); | 137 fViewMatrix = dgp.viewMatrix(); |
| 141 GrGLfloat viewMatrix[3 * 3]; | 138 GrGLfloat viewMatrix[3 * 3]; |
| 142 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 139 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 143 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 140 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 144 } | 141 } |
| 145 | 142 |
| 146 if (dgp.color() != fColor && !dgp.hasVertexColor()) { | 143 if (dgp.color() != fColor && !dgp.hasVertexColor()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 168 SkMatrix fViewMatrix; | 165 SkMatrix fViewMatrix; |
| 169 GrColor fColor; | 166 GrColor fColor; |
| 170 uint8_t fCoverage; | 167 uint8_t fCoverage; |
| 171 UniformHandle fViewMatrixUniform; | 168 UniformHandle fViewMatrixUniform; |
| 172 UniformHandle fColorUniform; | 169 UniformHandle fColorUniform; |
| 173 UniformHandle fCoverageUniform; | 170 UniformHandle fCoverageUniform; |
| 174 | 171 |
| 175 typedef GrGLGeometryProcessor INHERITED; | 172 typedef GrGLGeometryProcessor INHERITED; |
| 176 }; | 173 }; |
| 177 | 174 |
| 178 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 175 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con
st override { |
| 179 const GrGLSLCaps& caps, | 176 GLProcessor::GenKey(*this, caps, b); |
| 180 GrProcessorKeyBuilder* b) const override { | |
| 181 GLProcessor::GenKey(*this, bt, caps, b); | |
| 182 } | 177 } |
| 183 | 178 |
| 184 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 179 GrGLPrimitiveProcessor* createGLInstance(const GrGLSLCaps&) const override { |
| 185 const GrGLSLCaps&) const ov
erride { | 180 return new GLProcessor(); |
| 186 return new GLProcessor(*this, bt); | |
| 187 } | 181 } |
| 188 | 182 |
| 189 private: | 183 private: |
| 190 DefaultGeoProc(uint32_t gpTypeFlags, | 184 DefaultGeoProc(uint32_t gpTypeFlags, |
| 191 GrColor color, | 185 GrColor color, |
| 192 const SkMatrix& viewMatrix, | 186 const SkMatrix& viewMatrix, |
| 193 const SkMatrix& localMatrix, | 187 const SkMatrix& localMatrix, |
| 194 uint8_t coverage, | 188 uint8_t coverage, |
| 195 bool localCoordsWillBeRead, | 189 bool localCoordsWillBeRead, |
| 196 bool coverageWillBeIgnored) | 190 bool coverageWillBeIgnored) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 308 } |
| 315 | 309 |
| 316 if (localCoords.hasLocalMatrix()) { | 310 if (localCoords.hasLocalMatrix()) { |
| 317 invert.preConcat(*localCoords.fMatrix); | 311 invert.preConcat(*localCoords.fMatrix); |
| 318 } | 312 } |
| 319 } | 313 } |
| 320 | 314 |
| 321 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 315 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
| 322 return Create(color, coverage, inverted, SkMatrix::I()); | 316 return Create(color, coverage, inverted, SkMatrix::I()); |
| 323 } | 317 } |
| OLD | NEW |