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