blob: b47fa6a97387c646a5d95ad4e40fb8eb42c637ef [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
jvanverthcba99b82015-06-24 06:59:57 -070013#include "glsl/GrGLSLCaps.h"
14
joshualitt8072caa2015-02-12 14:20:52 -080015GrPathProcessor::GrPathProcessor(GrColor color,
16 const SkMatrix& viewMatrix,
17 const SkMatrix& localMatrix)
joshualitte3ababe2015-05-15 07:56:07 -070018 : INHERITED(true)
19 , fColor(color)
joshualitte578a952015-05-14 10:09:13 -070020 , fViewMatrix(viewMatrix)
joshualitte3ababe2015-05-15 07:56:07 -070021 , fLocalMatrix(localMatrix) {
joshualitt8072caa2015-02-12 14:20:52 -080022 this->initClassID<GrPathProcessor>();
23}
24
25void GrPathProcessor::getInvariantOutputColor(GrInitInvariantOutput* out) const {
26 out->setKnownFourComponents(fColor);
27}
28
29void GrPathProcessor::getInvariantOutputCoverage(GrInitInvariantOutput* out) const {
30 out->setKnownSingleComponent(0xff);
31}
32
33void GrPathProcessor::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const {
34 PathBatchTracker* local = bt->cast<PathBatchTracker>();
bsalomond07a2792015-07-08 10:20:21 -070035 if (init.fColorIgnored) {
joshualitt8072caa2015-02-12 14:20:52 -080036 local->fInputColorType = kIgnored_GrGPInput;
37 local->fColor = GrColor_ILLEGAL;
38 } else {
39 local->fInputColorType = kUniform_GrGPInput;
bsalomond07a2792015-07-08 10:20:21 -070040 local->fColor = GrColor_ILLEGAL == init.fOverrideColor ? this->color() :
41 init.fOverrideColor;
joshualitt8072caa2015-02-12 14:20:52 -080042 }
43
bsalomond07a2792015-07-08 10:20:21 -070044 local->fInputCoverageType = init.fCoverageIgnored ? kIgnored_GrGPInput : kAllOnes_GrGPInput;
45 local->fUsesLocalCoords = init.fUsesLocalCoords;
joshualitt8072caa2015-02-12 14:20:52 -080046}
47
48bool GrPathProcessor::canMakeEqual(const GrBatchTracker& m,
49 const GrPrimitiveProcessor& that,
50 const GrBatchTracker& t) const {
51 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(that)) {
52 return false;
53 }
54
joshualitte578a952015-05-14 10:09:13 -070055 const GrPathProcessor& other = that.cast<GrPathProcessor>();
56 if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) {
joshualitt8072caa2015-02-12 14:20:52 -080057 return false;
58 }
59
60 const PathBatchTracker& mine = m.cast<PathBatchTracker>();
61 const PathBatchTracker& theirs = t.cast<PathBatchTracker>();
joshualittb8c241a2015-05-19 08:23:30 -070062 if (mine.fColor != theirs.fColor) {
63 return false;
64 }
65
66 if (mine.fUsesLocalCoords != theirs.fUsesLocalCoords) {
67 return false;
68 }
69
70 if (mine.fUsesLocalCoords && !this->localMatrix().cheapEqualTo(other.localMatrix())) {
71 return false;
72 }
73
74 return true;
joshualitt8072caa2015-02-12 14:20:52 -080075}
76
77void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070078 const GrGLSLCaps& caps,
joshualitt8072caa2015-02-12 14:20:52 -080079 GrProcessorKeyBuilder* b) const {
80 GrGLPathProcessor::GenKey(*this, bt, caps, b);
81}
82
83GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070084 const GrGLSLCaps& caps) const {
jvanverth50530632015-04-27 10:36:27 -070085 SkASSERT(caps.pathRenderingSupport());
86 return SkNEW_ARGS(GrGLPathProcessor, (*this, bt));
joshualitt8072caa2015-02-12 14:20:52 -080087}