blob: 5c07a8b156675a5e155bd877ea0c5241f7501875 [file] [log] [blame]
jvanverth50530632015-04-27 10:36:27 -07001/*
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
joshualitt8072caa2015-02-12 14:20:52 -08008#include "GrPathProcessor.h"
9
10#include "gl/GrGLPathProcessor.h"
11#include "gl/GrGLGpu.h"
12
13GrPathProcessor::GrPathProcessor(GrColor color,
14 const SkMatrix& viewMatrix,
15 const SkMatrix& localMatrix)
joshualitte3ababe2015-05-15 07:56:07 -070016 : INHERITED(true)
17 , fColor(color)
joshualitte578a952015-05-14 10:09:13 -070018 , fViewMatrix(viewMatrix)
joshualitte3ababe2015-05-15 07:56:07 -070019 , fLocalMatrix(localMatrix) {
joshualitt8072caa2015-02-12 14:20:52 -080020 this->initClassID<GrPathProcessor>();
21}
22
23void GrPathProcessor::getInvariantOutputColor(GrInitInvariantOutput* out) const {
24 out->setKnownFourComponents(fColor);
25}
26
27void GrPathProcessor::getInvariantOutputCoverage(GrInitInvariantOutput* out) const {
28 out->setKnownSingleComponent(0xff);
29}
30
31void 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
46bool 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
joshualitte578a952015-05-14 10:09:13 -070053 const GrPathProcessor& other = that.cast<GrPathProcessor>();
54 if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) {
joshualitt8072caa2015-02-12 14:20:52 -080055 return false;
56 }
57
58 const PathBatchTracker& mine = m.cast<PathBatchTracker>();
59 const PathBatchTracker& theirs = t.cast<PathBatchTracker>();
joshualittd3a560f2015-05-19 07:15:28 -070060 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);
joshualitt8072caa2015-02-12 14:20:52 -080066}
67
68void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070069 const GrGLSLCaps& caps,
joshualitt8072caa2015-02-12 14:20:52 -080070 GrProcessorKeyBuilder* b) const {
71 GrGLPathProcessor::GenKey(*this, bt, caps, b);
72}
73
74GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070075 const GrGLSLCaps& caps) const {
jvanverth50530632015-04-27 10:36:27 -070076 SkASSERT(caps.pathRenderingSupport());
77 return SkNEW_ARGS(GrGLPathProcessor, (*this, bt));
joshualitt8072caa2015-02-12 14:20:52 -080078}