blob: 4660aa080fb393f3bbecc415344fb1b32e8f5487 [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>();
joshualittb8c241a2015-05-19 08:23:30 -070060 if (mine.fColor != theirs.fColor) {
61 return false;
62 }
63
64 if (mine.fUsesLocalCoords != theirs.fUsesLocalCoords) {
65 return false;
66 }
67
68 if (mine.fUsesLocalCoords && !this->localMatrix().cheapEqualTo(other.localMatrix())) {
69 return false;
70 }
71
72 return true;
joshualitt8072caa2015-02-12 14:20:52 -080073}
74
75void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070076 const GrGLSLCaps& caps,
joshualitt8072caa2015-02-12 14:20:52 -080077 GrProcessorKeyBuilder* b) const {
78 GrGLPathProcessor::GenKey(*this, bt, caps, b);
79}
80
81GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070082 const GrGLSLCaps& caps) const {
jvanverth50530632015-04-27 10:36:27 -070083 SkASSERT(caps.pathRenderingSupport());
84 return SkNEW_ARGS(GrGLPathProcessor, (*this, bt));
joshualitt8072caa2015-02-12 14:20:52 -080085}