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 #include "GrPathProcessor.h"
9 
10 #include "gl/GrGLPathProcessor.h"
11 #include "gl/GrGLGpu.h"
12 
GrPathProcessor(GrColor color,const SkMatrix & viewMatrix,const SkMatrix & localMatrix)13 GrPathProcessor::GrPathProcessor(GrColor color,
14                                  const SkMatrix& viewMatrix,
15                                  const SkMatrix& localMatrix)
16     : INHERITED(true)
17     , fColor(color)
18     , fViewMatrix(viewMatrix)
19     , fLocalMatrix(localMatrix) {
20     this->initClassID<GrPathProcessor>();
21 }
22 
getInvariantOutputColor(GrInitInvariantOutput * out) const23 void GrPathProcessor::getInvariantOutputColor(GrInitInvariantOutput* out) const {
24     out->setKnownFourComponents(fColor);
25 }
26 
getInvariantOutputCoverage(GrInitInvariantOutput * out) const27 void GrPathProcessor::getInvariantOutputCoverage(GrInitInvariantOutput* out) const {
28     out->setKnownSingleComponent(0xff);
29 }
30 
initBatchTracker(GrBatchTracker * bt,const GrPipelineInfo & init) const31 void GrPathProcessor::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const {
32     PathBatchTracker* local = bt->cast<PathBatchTracker>();
33     if (init.fColorIgnored) {
34         local->fInputColorType = kIgnored_GrGPInput;
35         local->fColor = GrColor_ILLEGAL;
36     } else {
37         local->fInputColorType = kUniform_GrGPInput;
38         local->fColor = GrColor_ILLEGAL == init.fOverrideColor ? this->color() :
39                                                                  init.fOverrideColor;
40     }
41 
42     local->fInputCoverageType = init.fCoverageIgnored ? kIgnored_GrGPInput : kAllOnes_GrGPInput;
43     local->fUsesLocalCoords = init.fUsesLocalCoords;
44 }
45 
canMakeEqual(const GrBatchTracker & m,const GrPrimitiveProcessor & that,const GrBatchTracker & t) const46 bool GrPathProcessor::canMakeEqual(const GrBatchTracker& m,
47                                    const GrPrimitiveProcessor& that,
48                                    const GrBatchTracker& t) const {
49     if (this->classID() != that.classID() || !this->hasSameTextureAccesses(that)) {
50         return false;
51     }
52 
53     const GrPathProcessor& other = that.cast<GrPathProcessor>();
54     if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) {
55         return false;
56     }
57 
58     const PathBatchTracker& mine = m.cast<PathBatchTracker>();
59     const PathBatchTracker& theirs = t.cast<PathBatchTracker>();
60     return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords,
61                                    that, theirs.fUsesLocalCoords) &&
62            CanCombineOutput(mine.fInputColorType, mine.fColor,
63                             theirs.fInputColorType, theirs.fColor) &&
64            CanCombineOutput(mine.fInputCoverageType, 0xff,
65                             theirs.fInputCoverageType, 0xff);
66 }
67 
getGLProcessorKey(const GrBatchTracker & bt,const GrGLSLCaps & caps,GrProcessorKeyBuilder * b) const68 void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt,
69                                         const GrGLSLCaps& caps,
70                                         GrProcessorKeyBuilder* b) const {
71     GrGLPathProcessor::GenKey(*this, bt, caps, b);
72 }
73 
createGLInstance(const GrBatchTracker & bt,const GrGLSLCaps & caps) const74 GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt,
75                                                           const GrGLSLCaps& caps) const {
76     SkASSERT(caps.pathRenderingSupport());
77     return SkNEW_ARGS(GrGLPathProcessor, (*this, bt));
78 }
79