blob: d10c4662e9583bf97955b4ff5c70eadc766de1d1 [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>();
bsalomon7765a472015-07-08 11:26:37 -070035 if (!init.readsColor()) {
joshualitt8072caa2015-02-12 14:20:52 -080036 local->fInputColorType = kIgnored_GrGPInput;
37 local->fColor = GrColor_ILLEGAL;
38 } else {
39 local->fInputColorType = kUniform_GrGPInput;
bsalomon7765a472015-07-08 11:26:37 -070040 if (!init.getOverrideColorIfSet(&local->fColor)) {
41 local->fColor = this->color();
42 }
joshualitt8072caa2015-02-12 14:20:52 -080043 }
44
bsalomon7765a472015-07-08 11:26:37 -070045 local->fInputCoverageType = init.readsCoverage() ? kAllOnes_GrGPInput : kIgnored_GrGPInput;
46 local->fUsesLocalCoords = init.readsLocalCoords();
joshualitt8072caa2015-02-12 14:20:52 -080047}
48
49bool GrPathProcessor::canMakeEqual(const GrBatchTracker& m,
50 const GrPrimitiveProcessor& that,
51 const GrBatchTracker& t) const {
52 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(that)) {
53 return false;
54 }
55
joshualitte578a952015-05-14 10:09:13 -070056 const GrPathProcessor& other = that.cast<GrPathProcessor>();
57 if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) {
joshualitt8072caa2015-02-12 14:20:52 -080058 return false;
59 }
60
61 const PathBatchTracker& mine = m.cast<PathBatchTracker>();
62 const PathBatchTracker& theirs = t.cast<PathBatchTracker>();
joshualittb8c241a2015-05-19 08:23:30 -070063 if (mine.fColor != theirs.fColor) {
64 return false;
65 }
66
67 if (mine.fUsesLocalCoords != theirs.fUsesLocalCoords) {
68 return false;
69 }
70
71 if (mine.fUsesLocalCoords && !this->localMatrix().cheapEqualTo(other.localMatrix())) {
72 return false;
73 }
74
75 return true;
joshualitt8072caa2015-02-12 14:20:52 -080076}
77
78void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070079 const GrGLSLCaps& caps,
joshualitt8072caa2015-02-12 14:20:52 -080080 GrProcessorKeyBuilder* b) const {
81 GrGLPathProcessor::GenKey(*this, bt, caps, b);
82}
83
84GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070085 const GrGLSLCaps& caps) const {
jvanverth50530632015-04-27 10:36:27 -070086 SkASSERT(caps.pathRenderingSupport());
87 return SkNEW_ARGS(GrGLPathProcessor, (*this, bt));
joshualitt8072caa2015-02-12 14:20:52 -080088}