blob: a6d1e27c2414791a18ae44c2299e8768c5b762ff [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)
joshualitte578a952015-05-14 10:09:13 -070016 : INHERITED(localMatrix, true)
17 , fViewMatrix(viewMatrix)
joshualitt8072caa2015-02-12 14:20:52 -080018 , fColor(color) {
19 this->initClassID<GrPathProcessor>();
20}
21
22void GrPathProcessor::getInvariantOutputColor(GrInitInvariantOutput* out) const {
23 out->setKnownFourComponents(fColor);
24}
25
26void GrPathProcessor::getInvariantOutputCoverage(GrInitInvariantOutput* out) const {
27 out->setKnownSingleComponent(0xff);
28}
29
30void GrPathProcessor::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const {
31 PathBatchTracker* local = bt->cast<PathBatchTracker>();
32 if (init.fColorIgnored) {
33 local->fInputColorType = kIgnored_GrGPInput;
34 local->fColor = GrColor_ILLEGAL;
35 } else {
36 local->fInputColorType = kUniform_GrGPInput;
37 local->fColor = GrColor_ILLEGAL == init.fOverrideColor ? this->color() :
38 init.fOverrideColor;
39 }
40
41 local->fInputCoverageType = init.fCoverageIgnored ? kIgnored_GrGPInput : kAllOnes_GrGPInput;
42 local->fUsesLocalCoords = init.fUsesLocalCoords;
43}
44
45bool GrPathProcessor::canMakeEqual(const GrBatchTracker& m,
46 const GrPrimitiveProcessor& that,
47 const GrBatchTracker& t) const {
48 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(that)) {
49 return false;
50 }
51
joshualitte578a952015-05-14 10:09:13 -070052 const GrPathProcessor& other = that.cast<GrPathProcessor>();
53 if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) {
joshualitt8072caa2015-02-12 14:20:52 -080054 return false;
55 }
56
57 const PathBatchTracker& mine = m.cast<PathBatchTracker>();
58 const PathBatchTracker& theirs = t.cast<PathBatchTracker>();
59 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords,
60 that, theirs.fUsesLocalCoords) &&
61 CanCombineOutput(mine.fInputColorType, mine.fColor,
62 theirs.fInputColorType, theirs.fColor) &&
63 CanCombineOutput(mine.fInputCoverageType, 0xff,
64 theirs.fInputCoverageType, 0xff);
65}
66
67void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070068 const GrGLSLCaps& caps,
joshualitt8072caa2015-02-12 14:20:52 -080069 GrProcessorKeyBuilder* b) const {
70 GrGLPathProcessor::GenKey(*this, bt, caps, b);
71}
72
73GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070074 const GrGLSLCaps& caps) const {
jvanverth50530632015-04-27 10:36:27 -070075 SkASSERT(caps.pathRenderingSupport());
76 return SkNEW_ARGS(GrGLPathProcessor, (*this, bt));
joshualitt8072caa2015-02-12 14:20:52 -080077}