blob: ca63eac53dc6474c4e22713325ff4d3d9d8285cb [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,
joshualittf2384692015-09-10 11:00:51 -070016 const GrPipelineOptimizations& opts,
joshualitt8072caa2015-02-12 14:20:52 -080017 const SkMatrix& viewMatrix,
18 const SkMatrix& localMatrix)
joshualitte3ababe2015-05-15 07:56:07 -070019 : INHERITED(true)
20 , fColor(color)
joshualitte578a952015-05-14 10:09:13 -070021 , fViewMatrix(viewMatrix)
joshualittf2384692015-09-10 11:00:51 -070022 , fLocalMatrix(localMatrix)
23 , fOpts(opts) {
joshualitt8072caa2015-02-12 14:20:52 -080024 this->initClassID<GrPathProcessor>();
25}
26
27void GrPathProcessor::getInvariantOutputColor(GrInitInvariantOutput* out) const {
28 out->setKnownFourComponents(fColor);
29}
30
31void GrPathProcessor::getInvariantOutputCoverage(GrInitInvariantOutput* out) const {
32 out->setKnownSingleComponent(0xff);
33}
34
bsalomon91d844d2015-08-10 10:47:29 -070035void GrPathProcessor::initBatchTracker(GrBatchTracker* bt, const GrPipelineOptimizations& opt) const {
joshualitt8072caa2015-02-12 14:20:52 -080036 PathBatchTracker* local = bt->cast<PathBatchTracker>();
bsalomon91d844d2015-08-10 10:47:29 -070037 if (!opt.readsColor()) {
joshualitt8072caa2015-02-12 14:20:52 -080038 local->fInputColorType = kIgnored_GrGPInput;
39 local->fColor = GrColor_ILLEGAL;
40 } else {
41 local->fInputColorType = kUniform_GrGPInput;
bsalomon91d844d2015-08-10 10:47:29 -070042 if (!opt.getOverrideColorIfSet(&local->fColor)) {
bsalomon7765a472015-07-08 11:26:37 -070043 local->fColor = this->color();
44 }
joshualitt8072caa2015-02-12 14:20:52 -080045 }
46
bsalomon91d844d2015-08-10 10:47:29 -070047 local->fInputCoverageType = opt.readsCoverage() ? kAllOnes_GrGPInput : kIgnored_GrGPInput;
48 local->fUsesLocalCoords = opt.readsLocalCoords();
joshualitt8072caa2015-02-12 14:20:52 -080049}
50
bsalomon1fcc01c2015-09-09 09:48:06 -070051bool GrPathProcessor::isEqual(const GrBatchTracker& m,
52 const GrPrimitiveProcessor& that,
53 const GrBatchTracker& t) const {
joshualitt8072caa2015-02-12 14:20:52 -080054 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(that)) {
55 return false;
56 }
57
joshualitte578a952015-05-14 10:09:13 -070058 const GrPathProcessor& other = that.cast<GrPathProcessor>();
59 if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) {
joshualitt8072caa2015-02-12 14:20:52 -080060 return false;
61 }
62
63 const PathBatchTracker& mine = m.cast<PathBatchTracker>();
64 const PathBatchTracker& theirs = t.cast<PathBatchTracker>();
joshualittb8c241a2015-05-19 08:23:30 -070065 if (mine.fColor != theirs.fColor) {
66 return false;
67 }
68
69 if (mine.fUsesLocalCoords != theirs.fUsesLocalCoords) {
70 return false;
71 }
72
73 if (mine.fUsesLocalCoords && !this->localMatrix().cheapEqualTo(other.localMatrix())) {
74 return false;
75 }
76
77 return true;
joshualitt8072caa2015-02-12 14:20:52 -080078}
79
80void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070081 const GrGLSLCaps& caps,
joshualitt8072caa2015-02-12 14:20:52 -080082 GrProcessorKeyBuilder* b) const {
83 GrGLPathProcessor::GenKey(*this, bt, caps, b);
84}
85
86GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt,
jvanverthcfc18862015-04-28 08:48:20 -070087 const GrGLSLCaps& caps) const {
jvanverth50530632015-04-27 10:36:27 -070088 SkASSERT(caps.pathRenderingSupport());
halcanary385fe4d2015-08-26 13:07:48 -070089 return new GrGLPathProcessor(*this, bt);
joshualitt8072caa2015-02-12 14:20:52 -080090}