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 | |
| 33 | void GrPathProcessor::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { |
| 34 | PathBatchTracker* local = bt->cast<PathBatchTracker>(); |
bsalomon | d07a279 | 2015-07-08 10:20:21 -0700 | [diff] [blame] | 35 | if (init.fColorIgnored) { |
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 | d07a279 | 2015-07-08 10:20:21 -0700 | [diff] [blame] | 40 | local->fColor = GrColor_ILLEGAL == init.fOverrideColor ? this->color() : |
| 41 | init.fOverrideColor; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 42 | } |
| 43 | |
bsalomon | d07a279 | 2015-07-08 10:20:21 -0700 | [diff] [blame] | 44 | local->fInputCoverageType = init.fCoverageIgnored ? kIgnored_GrGPInput : kAllOnes_GrGPInput; |
| 45 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | bool 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 | |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 55 | const GrPathProcessor& other = that.cast<GrPathProcessor>(); |
| 56 | if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 57 | return false; |
| 58 | } |
| 59 | |
| 60 | const PathBatchTracker& mine = m.cast<PathBatchTracker>(); |
| 61 | const PathBatchTracker& theirs = t.cast<PathBatchTracker>(); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 62 | 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; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 78 | const GrGLSLCaps& caps, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 79 | GrProcessorKeyBuilder* b) const { |
| 80 | GrGLPathProcessor::GenKey(*this, bt, caps, b); |
| 81 | } |
| 82 | |
| 83 | GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 84 | const GrGLSLCaps& caps) const { |
jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 85 | SkASSERT(caps.pathRenderingSupport()); |
| 86 | return SkNEW_ARGS(GrGLPathProcessor, (*this, bt)); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 87 | } |