jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 8 | #include "GrPathProcessor.h" |
| 9 | |
| 10 | #include "gl/GrGLPathProcessor.h" |
| 11 | #include "gl/GrGLGpu.h" |
| 12 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 13 | #include "glsl/GrGLSLCaps.h" |
| 14 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 15 | GrPathProcessor::GrPathProcessor(GrColor color, |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame^] | 16 | const GrPipelineOptimizations& opts, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 17 | const SkMatrix& viewMatrix, |
| 18 | const SkMatrix& localMatrix) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 19 | : INHERITED(true) |
| 20 | , fColor(color) |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 21 | , fViewMatrix(viewMatrix) |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame^] | 22 | , fLocalMatrix(localMatrix) |
| 23 | , fOpts(opts) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 24 | this->initClassID<GrPathProcessor>(); |
| 25 | } |
| 26 | |
| 27 | void GrPathProcessor::getInvariantOutputColor(GrInitInvariantOutput* out) const { |
| 28 | out->setKnownFourComponents(fColor); |
| 29 | } |
| 30 | |
| 31 | void GrPathProcessor::getInvariantOutputCoverage(GrInitInvariantOutput* out) const { |
| 32 | out->setKnownSingleComponent(0xff); |
| 33 | } |
| 34 | |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 35 | void GrPathProcessor::initBatchTracker(GrBatchTracker* bt, const GrPipelineOptimizations& opt) const { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 36 | PathBatchTracker* local = bt->cast<PathBatchTracker>(); |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 37 | if (!opt.readsColor()) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 38 | local->fInputColorType = kIgnored_GrGPInput; |
| 39 | local->fColor = GrColor_ILLEGAL; |
| 40 | } else { |
| 41 | local->fInputColorType = kUniform_GrGPInput; |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 42 | if (!opt.getOverrideColorIfSet(&local->fColor)) { |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 43 | local->fColor = this->color(); |
| 44 | } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 45 | } |
| 46 | |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 47 | local->fInputCoverageType = opt.readsCoverage() ? kAllOnes_GrGPInput : kIgnored_GrGPInput; |
| 48 | local->fUsesLocalCoords = opt.readsLocalCoords(); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 49 | } |
| 50 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 51 | bool GrPathProcessor::isEqual(const GrBatchTracker& m, |
| 52 | const GrPrimitiveProcessor& that, |
| 53 | const GrBatchTracker& t) const { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 54 | if (this->classID() != that.classID() || !this->hasSameTextureAccesses(that)) { |
| 55 | return false; |
| 56 | } |
| 57 | |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 58 | const GrPathProcessor& other = that.cast<GrPathProcessor>(); |
| 59 | if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 60 | return false; |
| 61 | } |
| 62 | |
| 63 | const PathBatchTracker& mine = m.cast<PathBatchTracker>(); |
| 64 | const PathBatchTracker& theirs = t.cast<PathBatchTracker>(); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 65 | 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; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 81 | const GrGLSLCaps& caps, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 82 | GrProcessorKeyBuilder* b) const { |
| 83 | GrGLPathProcessor::GenKey(*this, bt, caps, b); |
| 84 | } |
| 85 | |
| 86 | GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 87 | const GrGLSLCaps& caps) const { |
jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 88 | SkASSERT(caps.pathRenderingSupport()); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 89 | return new GrGLPathProcessor(*this, bt); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 90 | } |