| 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" |
| 11 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 11 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 12 #include "glsl/GrGLSLGeometryProcessor.h" | 12 #include "glsl/GrGLSLGeometryProcessor.h" |
| 13 #include "glsl/GrGLSLProgramBuilder.h" | |
| 14 #include "glsl/GrGLSLVertexShaderBuilder.h" | 13 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 15 #include "glsl/GrGLSLVarying.h" | 14 #include "glsl/GrGLSLVarying.h" |
| 15 #include "glsl/GrGLSLUniformHandler.h" |
| 16 #include "glsl/GrGLSLUtil.h" | 16 #include "glsl/GrGLSLUtil.h" |
| 17 | 17 |
| 18 /* | 18 /* |
| 19 * The default Geometry Processor simply takes position and multiplies it by the
uniform view | 19 * The default Geometry Processor simply takes position and multiplies it by the
uniform view |
| 20 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per
vertex color or | 20 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per
vertex color or |
| 21 * local coords. | 21 * local coords. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 enum GPFlag { | 24 enum GPFlag { |
| 25 kColor_GPFlag = 0x1, | 25 kColor_GPFlag = 0x1, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 bool coverageWillBeIgnored() const { return fCoverageWillBeIgnored; } | 57 bool coverageWillBeIgnored() const { return fCoverageWillBeIgnored; } |
| 58 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } | 58 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } |
| 59 | 59 |
| 60 class GLSLProcessor : public GrGLSLGeometryProcessor { | 60 class GLSLProcessor : public GrGLSLGeometryProcessor { |
| 61 public: | 61 public: |
| 62 GLSLProcessor() | 62 GLSLProcessor() |
| 63 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f
Coverage(0xff) {} | 63 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f
Coverage(0xff) {} |
| 64 | 64 |
| 65 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 65 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 66 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); | 66 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
| 67 GrGLSLGPBuilder* pb = args.fPB; | |
| 68 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 67 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
| 69 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 68 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 70 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 69 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
| 70 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 71 | 71 |
| 72 // emit attributes | 72 // emit attributes |
| 73 varyingHandler->emitAttributes(gp); | 73 varyingHandler->emitAttributes(gp); |
| 74 | 74 |
| 75 // Setup pass through color | 75 // Setup pass through color |
| 76 if (!gp.colorIgnored()) { | 76 if (!gp.colorIgnored()) { |
| 77 if (gp.hasVertexColor()) { | 77 if (gp.hasVertexColor()) { |
| 78 varyingHandler->addPassThroughAttribute(gp.inColor(), args.f
OutputColor); | 78 varyingHandler->addPassThroughAttribute(gp.inColor(), args.f
OutputColor); |
| 79 } else { | 79 } else { |
| 80 this->setupUniformColor(pb, fragBuilder, args.fOutputColor,
&fColorUniform); | 80 this->setupUniformColor(fragBuilder, uniformHandler, args.fO
utputColor, |
| 81 &fColorUniform); |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 | 84 |
| 84 // Setup position | 85 // Setup position |
| 85 this->setupPosition(pb, | 86 this->setupPosition(vertBuilder, |
| 86 vertBuilder, | 87 uniformHandler, |
| 87 gpArgs, | 88 gpArgs, |
| 88 gp.inPosition()->fName, | 89 gp.inPosition()->fName, |
| 89 gp.viewMatrix(), | 90 gp.viewMatrix(), |
| 90 &fViewMatrixUniform); | 91 &fViewMatrixUniform); |
| 91 | 92 |
| 92 if (gp.hasExplicitLocalCoords()) { | 93 if (gp.hasExplicitLocalCoords()) { |
| 93 // emit transforms with explicit local coords | 94 // emit transforms with explicit local coords |
| 94 this->emitTransforms(pb, | 95 this->emitTransforms(vertBuilder, |
| 95 vertBuilder, | |
| 96 varyingHandler, | 96 varyingHandler, |
| 97 uniformHandler, |
| 97 gpArgs->fPositionVar, | 98 gpArgs->fPositionVar, |
| 98 gp.inLocalCoords()->fName, | 99 gp.inLocalCoords()->fName, |
| 99 gp.localMatrix(), | 100 gp.localMatrix(), |
| 100 args.fTransformsIn, | 101 args.fTransformsIn, |
| 101 args.fTransformsOut); | 102 args.fTransformsOut); |
| 102 } else if(gp.hasTransformedLocalCoords()) { | 103 } else if(gp.hasTransformedLocalCoords()) { |
| 103 // transforms have already been applied to vertex attributes on
the cpu | 104 // transforms have already been applied to vertex attributes on
the cpu |
| 104 this->emitTransforms(pb, | 105 this->emitTransforms(vertBuilder, |
| 105 vertBuilder, | |
| 106 varyingHandler, | 106 varyingHandler, |
| 107 gp.inLocalCoords()->fName, | 107 gp.inLocalCoords()->fName, |
| 108 args.fTransformsIn, | 108 args.fTransformsIn, |
| 109 args.fTransformsOut); | 109 args.fTransformsOut); |
| 110 } else { | 110 } else { |
| 111 // emit transforms with position | 111 // emit transforms with position |
| 112 this->emitTransforms(pb, | 112 this->emitTransforms(vertBuilder, |
| 113 vertBuilder, | |
| 114 varyingHandler, | 113 varyingHandler, |
| 114 uniformHandler, |
| 115 gpArgs->fPositionVar, | 115 gpArgs->fPositionVar, |
| 116 gp.inPosition()->fName, | 116 gp.inPosition()->fName, |
| 117 gp.localMatrix(), | 117 gp.localMatrix(), |
| 118 args.fTransformsIn, | 118 args.fTransformsIn, |
| 119 args.fTransformsOut); | 119 args.fTransformsOut); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Setup coverage as pass through | 122 // Setup coverage as pass through |
| 123 if (!gp.coverageWillBeIgnored()) { | 123 if (!gp.coverageWillBeIgnored()) { |
| 124 if (gp.hasVertexCoverage()) { | 124 if (gp.hasVertexCoverage()) { |
| 125 fragBuilder->codeAppendf("float alpha = 1.0;"); | 125 fragBuilder->codeAppendf("float alpha = 1.0;"); |
| 126 varyingHandler->addPassThroughAttribute(gp.inCoverage(), "al
pha"); | 126 varyingHandler->addPassThroughAttribute(gp.inCoverage(), "al
pha"); |
| 127 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCo
verage); | 127 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCo
verage); |
| 128 } else if (gp.coverage() == 0xff) { | 128 } else if (gp.coverage() == 0xff) { |
| 129 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCovera
ge); | 129 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCovera
ge); |
| 130 } else { | 130 } else { |
| 131 const char* fragCoverage; | 131 const char* fragCoverage; |
| 132 fCoverageUniform = pb->addUniform(GrGLSLProgramBuilder::kFra
gment_Visibility, | 132 fCoverageUniform = uniformHandler->addUniform( |
| 133 kFloat_GrSLType, | 133 GrGLSLUniformHandler::k
Fragment_Visibility, |
| 134 kDefault_GrSLPrecision, | 134 kFloat_GrSLType, |
| 135 "Coverage", | 135 kDefault_GrSLPrecision, |
| 136 &fragCoverage); | 136 "Coverage", |
| 137 &fragCoverage); |
| 137 fragBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCover
age, fragCoverage); | 138 fragBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCover
age, fragCoverage); |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 | 142 |
| 142 static inline void GenKey(const GrGeometryProcessor& gp, | 143 static inline void GenKey(const GrGeometryProcessor& gp, |
| 143 const GrGLSLCaps&, | 144 const GrGLSLCaps&, |
| 144 GrProcessorKeyBuilder* b) { | 145 GrProcessorKeyBuilder* b) { |
| 145 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); | 146 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
| 146 uint32_t key = def.fFlags; | 147 uint32_t key = def.fFlags; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 335 } |
| 335 | 336 |
| 336 if (localCoords.hasLocalMatrix()) { | 337 if (localCoords.hasLocalMatrix()) { |
| 337 invert.preConcat(*localCoords.fMatrix); | 338 invert.preConcat(*localCoords.fMatrix); |
| 338 } | 339 } |
| 339 } | 340 } |
| 340 | 341 |
| 341 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 342 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
| 342 return Create(color, coverage, inverted, SkMatrix::I()); | 343 return Create(color, coverage, inverted, SkMatrix::I()); |
| 343 } | 344 } |
| OLD | NEW |