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 | d3a560f | 2015-05-19 07:15:28 -0700 | [diff] [blame^] | 60 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 61 | that, theirs.fUsesLocalCoords) && |
| 62 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 63 | theirs.fInputColorType, theirs.fColor) && |
| 64 | CanCombineOutput(mine.fInputCoverageType, 0xff, |
| 65 | theirs.fInputCoverageType, 0xff); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void GrPathProcessor::getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 69 | const GrGLSLCaps& caps, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 70 | GrProcessorKeyBuilder* b) const { |
| 71 | GrGLPathProcessor::GenKey(*this, bt, caps, b); |
| 72 | } |
| 73 | |
| 74 | GrGLPrimitiveProcessor* GrPathProcessor::createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 75 | const GrGLSLCaps& caps) const { |
jvanverth | 5053063 | 2015-04-27 10:36:27 -0700 | [diff] [blame] | 76 | SkASSERT(caps.pathRenderingSupport()); |
| 77 | return SkNEW_ARGS(GrGLPathProcessor, (*this, bt)); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 78 | } |