1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrPathProcessor_DEFINED 9 #define GrPathProcessor_DEFINED 10 11 #include "GrPrimitiveProcessor.h" 12 13 struct PathBatchTracker { 14 GrGPInput fInputColorType; 15 GrGPInput fInputCoverageType; 16 GrColor fColor; 17 bool fUsesLocalCoords; 18 }; 19 20 /* 21 * The path equivalent of the GP. For now this just manages color. In the long term we plan on 22 * extending this class to handle all nvpr uniform / varying / program work. 23 */ 24 class GrPathProcessor : public GrPrimitiveProcessor { 25 public: 26 static GrPathProcessor* Create(GrColor color, 27 const SkMatrix& viewMatrix = SkMatrix::I(), 28 const SkMatrix& localMatrix = SkMatrix::I()) { 29 return SkNEW_ARGS(GrPathProcessor, (color, viewMatrix, localMatrix)); 30 } 31 32 void initBatchTracker(GrBatchTracker*, const GrPipelineInfo&) const override; 33 34 bool canMakeEqual(const GrBatchTracker& mine, 35 const GrPrimitiveProcessor& that, 36 const GrBatchTracker& theirs) const override; 37 name()38 const char* name() const override { return "PathProcessor"; } 39 color()40 GrColor color() const { return fColor; } viewMatrix()41 const SkMatrix& viewMatrix() const { return fViewMatrix; } localMatrix()42 const SkMatrix& localMatrix() const { return fLocalMatrix; } 43 44 45 void getInvariantOutputColor(GrInitInvariantOutput* out) const override; 46 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override; 47 willUseGeoShader()48 bool willUseGeoShader() const override { return false; } 49 50 virtual void getGLProcessorKey(const GrBatchTracker& bt, 51 const GrGLSLCaps& caps, 52 GrProcessorKeyBuilder* b) const override; 53 54 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, 55 const GrGLSLCaps& caps) const override; 56 57 private: 58 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& localMatrix); 59 60 /* 61 * CanCombineOutput will return true if two draws are 'batchable' from a color perspective. 62 * TODO is this really necessary? 63 */ CanCombineOutput(GrGPInput left,GrColor lColor,GrGPInput right,GrColor rColor)64 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right, GrColor rColor) { 65 if (left != right) { 66 return false; 67 } 68 69 if (kUniform_GrGPInput == left && lColor != rColor) { 70 return false; 71 } 72 73 return true; 74 } 75 CanCombineLocalMatrices(const GrPrimitiveProcessor & l,bool leftUsesLocalCoords,const GrPrimitiveProcessor & r,bool rightUsesLocalCoords)76 static bool CanCombineLocalMatrices(const GrPrimitiveProcessor& l, 77 bool leftUsesLocalCoords, 78 const GrPrimitiveProcessor& r, 79 bool rightUsesLocalCoords) { 80 if (leftUsesLocalCoords != rightUsesLocalCoords) { 81 return false; 82 } 83 84 const GrPathProcessor& left = l.cast<GrPathProcessor>(); 85 const GrPathProcessor& right = r.cast<GrPathProcessor>(); 86 if (leftUsesLocalCoords && !left.localMatrix().cheapEqualTo(right.localMatrix())) { 87 return false; 88 } 89 return true; 90 } 91 hasExplicitLocalCoords()92 bool hasExplicitLocalCoords() const override { return false; } 93 94 GrColor fColor; 95 const SkMatrix fViewMatrix; 96 const SkMatrix fLocalMatrix; 97 98 typedef GrPrimitiveProcessor INHERITED; 99 }; 100 101 #endif 102