GrPathProcessor.h revision e3ababe44315452cd33b96a18ce316ede09ff3c3
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 13struct 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 */ 24class GrPathProcessor : public GrPrimitiveProcessor { 25public: 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 38 const char* name() const override { return "PathProcessor"; } 39 40 GrColor color() const { return fColor; } 41 const SkMatrix& viewMatrix() const { return fViewMatrix; } 42 const SkMatrix& localMatrix() const { return fLocalMatrix; } 43 44 45 void getInvariantOutputColor(GrInitInvariantOutput* out) const override; 46 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override; 47 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 57private: 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 */ 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 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 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