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 | |
| 13 | GrPathProcessor::GrPathProcessor(GrColor color, |
| 14 | const SkMatrix& viewMatrix, |
| 15 | const SkMatrix& localMatrix) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 16 | : INHERITED(true) |
| 17 | , fColor(color) |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 18 | , fViewMatrix(viewMatrix) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 19 | , fLocalMatrix(localMatrix) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 20 | this->initClassID<GrPathProcessor>(); |
| 21 | } |
| 22 | |
| 23 | void GrPathProcessor::getInvariantOutputColor(GrInitInvariantOutput* out) const { |
| 24 | out->setKnownFourComponents(fColor); |
| 25 | } |
| 26 | |
| 27 | void GrPathProcessor::getInvariantOutputCoverage(GrInitInvariantOutput* out) const { |
| 28 | out->setKnownSingleComponent(0xff); |
| 29 | } |
| 30 | |
| 31 | void GrPathProcessor::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { |
| 32 | PathBatchTracker* local = bt->cast<PathBatchTracker>(); |
| 33 | if (init.fColorIgnored) { |
| 34 | local->fInputColorType = kIgnored_GrGPInput; |
| 35 | local->fColor = GrColor_ILLEGAL; |
| 36 | } else { |
| 37 | local->fInputColorType = kUniform_GrGPInput; |
| 38 | local->fColor = GrColor_ILLEGAL == init.fOverrideColor ? this->color() : |
| 39 | init.fOverrideColor; |
| 40 | } |
| 41 | |
| 42 | local->fInputCoverageType = init.fCoverageIgnored ? kIgnored_GrGPInput : kAllOnes_GrGPInput; |
| 43 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 44 | } |
| 45 | |
| 46 | bool GrPathProcessor::canMakeEqual(const GrBatchTracker& m, |
| 47 | const GrPrimitiveProcessor& that, |
| 48 | const GrBatchTracker& t) const { |
| 49 | if (this->classID() != that.classID() || !this->hasSameTextureAccesses(that)) { |
| 50 | return false; |
| 51 | } |
| 52 | |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 53 | const GrPathProcessor& other = that.cast<GrPathProcessor>(); |
| 54 | if (!this->viewMatrix().cheapEqualTo(other.viewMatrix())) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 55 | return false; |
| 56 | } |
| 57 | |
| 58 | const PathBatchTracker& mine = m.cast<PathBatchTracker>(); |
| 59 | const PathBatchTracker& theirs = t.cast<PathBatchTracker>(); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame^] | 60 | if (mine.fColor != theirs.fColor) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | if (mine.fUsesLocalCoords != theirs.fUsesLocalCoords) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | if (mine.fUsesLocalCoords && !this->localMatrix().cheapEqualTo(other.localMatrix())) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | return true; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 76 | const GrGLSLCaps& caps, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 77 | GrProcessorKeyBuilder* b) const { |
| 78 | GrGLPathProcessor::GenKey(*this, bt, caps, b); |
| 79 | } |
| 80 | |
| 81 | GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 82 | const GrGLSLCaps& caps) const { |
jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 83 | SkASSERT(caps.pathRenderingSupport()); |
| 84 | return SkNEW_ARGS(GrGLPathProcessor, (*this, bt)); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 85 | } |