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