Chromium Code Reviews| 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 virtual void setData(const GrGLProgramDataManager& pdman, |
| 135 const GrPrimitiveProcessor& gp, | 134 const GrPrimitiveProcessor& gp) override { |
| 136 const GrBatchTracker& bt) override { | |
| 137 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); | 135 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
| 138 | 136 |
| 139 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp. viewMatrix())) { | 137 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp. viewMatrix())) { |
| 140 fViewMatrix = dgp.viewMatrix(); | 138 fViewMatrix = dgp.viewMatrix(); |
| 141 GrGLfloat viewMatrix[3 * 3]; | 139 GrGLfloat viewMatrix[3 * 3]; |
| 142 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 140 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 143 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 141 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 144 } | 142 } |
| 145 | 143 |
| 146 if (dgp.color() != fColor && !dgp.hasVertexColor()) { | 144 if (dgp.color() != fColor && !dgp.hasVertexColor()) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 168 SkMatrix fViewMatrix; | 166 SkMatrix fViewMatrix; |
| 169 GrColor fColor; | 167 GrColor fColor; |
| 170 uint8_t fCoverage; | 168 uint8_t fCoverage; |
| 171 UniformHandle fViewMatrixUniform; | 169 UniformHandle fViewMatrixUniform; |
| 172 UniformHandle fColorUniform; | 170 UniformHandle fColorUniform; |
| 173 UniformHandle fCoverageUniform; | 171 UniformHandle fCoverageUniform; |
| 174 | 172 |
| 175 typedef GrGLGeometryProcessor INHERITED; | 173 typedef GrGLGeometryProcessor INHERITED; |
| 176 }; | 174 }; |
| 177 | 175 |
| 178 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 176 virtual void getGLProcessorKey(const GrGLSLCaps& caps, |
| 179 const GrGLSLCaps& caps, | |
| 180 GrProcessorKeyBuilder* b) const override { | 177 GrProcessorKeyBuilder* b) const override { |
| 181 GLProcessor::GenKey(*this, bt, caps, b); | 178 GLProcessor::GenKey(*this, caps, b); |
| 182 } | 179 } |
| 183 | 180 |
| 184 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 181 virtual GrGLPrimitiveProcessor* createGLInstance(const GrGLSLCaps&) const ov erride { |
|
bsalomon
2015/09/10 18:55:30
-virtual?
joshualitt
2015/09/10 20:08:04
Acknowledged.
| |
| 185 const GrGLSLCaps&) const ov erride { | 182 return new GLProcessor(); |
| 186 return new GLProcessor(*this, bt); | |
| 187 } | 183 } |
| 188 | 184 |
| 189 private: | 185 private: |
| 190 DefaultGeoProc(uint32_t gpTypeFlags, | 186 DefaultGeoProc(uint32_t gpTypeFlags, |
| 191 GrColor color, | 187 GrColor color, |
| 192 const SkMatrix& viewMatrix, | 188 const SkMatrix& viewMatrix, |
| 193 const SkMatrix& localMatrix, | 189 const SkMatrix& localMatrix, |
| 194 uint8_t coverage, | 190 uint8_t coverage, |
| 195 bool localCoordsWillBeRead, | 191 bool localCoordsWillBeRead, |
| 196 bool coverageWillBeIgnored) | 192 bool coverageWillBeIgnored) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 } | 310 } |
| 315 | 311 |
| 316 if (localCoords.hasLocalMatrix()) { | 312 if (localCoords.hasLocalMatrix()) { |
| 317 invert.preConcat(*localCoords.fMatrix); | 313 invert.preConcat(*localCoords.fMatrix); |
| 318 } | 314 } |
| 319 } | 315 } |
| 320 | 316 |
| 321 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 317 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
| 322 return Create(color, coverage, inverted, SkMatrix::I()); | 318 return Create(color, coverage, inverted, SkMatrix::I()); |
| 323 } | 319 } |
| OLD | NEW |