| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrDrawPathBatch.h" | 8 #include "GrDrawPathBatch.h" |
| 9 | 9 |
| 10 SkString GrDrawPathBatch::dumpInfo() const { | 10 SkString GrDrawPathBatch::dumpInfo() const { |
| 11 SkString string; | 11 SkString string; |
| 12 string.printf("PATH: 0x%p", fPath.get()); | 12 string.printf("PATH: 0x%p", fPath.get()); |
| 13 return string; | 13 return string; |
| 14 } | 14 } |
| 15 | 15 |
| 16 void GrDrawPathBatch::onDraw(GrBatchFlushState* state) { | 16 void GrDrawPathBatch::onDraw(GrBatchFlushState* state) { |
| 17 GrProgramDesc desc; | 17 GrProgramDesc desc; |
| 18 state->gpu()->buildProgramDesc(&desc, *this->pathProcessor(), | 18 |
| 19 SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color()
, |
| 20 this->opts(), |
| 21 this->viewMat
rix())); |
| 22 state->gpu()->buildProgramDesc(&desc, *pathProc, |
| 19 *this->pipeline(), *this->tracker()); | 23 *this->pipeline(), *this->tracker()); |
| 20 GrPathRendering::DrawPathArgs args(this->pathProcessor(), this->pipeline(), | 24 GrPathRendering::DrawPathArgs args(pathProc, this->pipeline(), |
| 21 &desc, this->tracker(), &this->stencilSe
ttings()); | 25 &desc, this->tracker(), &this->stencilSe
ttings()); |
| 22 state->gpu()->pathRendering()->drawPath(args, fPath.get()); | 26 state->gpu()->pathRendering()->drawPath(args, fPath.get()); |
| 23 } | 27 } |
| 24 | 28 |
| 25 GrDrawPathRangeBatch::~GrDrawPathRangeBatch() { | 29 GrDrawPathRangeBatch::~GrDrawPathRangeBatch() { |
| 26 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { | 30 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { |
| 27 (*iter.get())->unref(); | 31 (*iter.get())->unref(); |
| 28 } | 32 } |
| 29 } | 33 } |
| 30 | 34 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 45 if (isWinding) { | 49 if (isWinding) { |
| 46 // Double check that it is in fact winding. | 50 // Double check that it is in fact winding. |
| 47 SkASSERT(kIncClamp_StencilOp == this->stencilSettings().passOp(pathFace)
); | 51 SkASSERT(kIncClamp_StencilOp == this->stencilSettings().passOp(pathFace)
); |
| 48 SkASSERT(kIncClamp_StencilOp == this->stencilSettings().failOp(pathFace)
); | 52 SkASSERT(kIncClamp_StencilOp == this->stencilSettings().failOp(pathFace)
); |
| 49 SkASSERT(0x1 != this->stencilSettings().writeMask(pathFace)); | 53 SkASSERT(0x1 != this->stencilSettings().writeMask(pathFace)); |
| 50 SkASSERT(!this->stencilSettings().isTwoSided()); | 54 SkASSERT(!this->stencilSettings().isTwoSided()); |
| 51 } | 55 } |
| 52 return isWinding; | 56 return isWinding; |
| 53 } | 57 } |
| 54 | 58 |
| 55 GrDrawPathRangeBatch::GrDrawPathRangeBatch(const GrPathProcessor* pathProc, | 59 GrDrawPathRangeBatch::GrDrawPathRangeBatch(const SkMatrix& viewMatrix, const SkM
atrix& localMatrix, |
| 56 GrPathRangeDraw* pathRangeDraw) | 60 GrColor color, GrPathRangeDraw* pathR
angeDraw) |
| 57 : INHERITED(pathProc) | 61 : INHERITED(viewMatrix, color) |
| 58 , fDraws(4) { | 62 , fDraws(4) |
| 63 , fLocalMatrix(localMatrix) { |
| 59 SkDEBUGCODE(pathRangeDraw->fUsedInBatch = true;) | 64 SkDEBUGCODE(pathRangeDraw->fUsedInBatch = true;) |
| 60 this->initClassID<GrDrawPathRangeBatch>(); | 65 this->initClassID<GrDrawPathRangeBatch>(); |
| 61 fDraws.addToHead(SkRef(pathRangeDraw)); | 66 fDraws.addToHead(SkRef(pathRangeDraw)); |
| 62 fTotalPathCount = pathRangeDraw->count(); | 67 fTotalPathCount = pathRangeDraw->count(); |
| 63 // Don't compute a bounding box. For dst copy texture, we'll opt instead for
it to just copy | 68 // Don't compute a bounding box. For dst copy texture, we'll opt instead for
it to just copy |
| 64 // the entire dst. Realistically this is a moot point, because any context t
hat supports | 69 // the entire dst. Realistically this is a moot point, because any context t
hat supports |
| 65 // NV_path_rendering will also support NV_blend_equation_advanced. | 70 // NV_path_rendering will also support NV_blend_equation_advanced. |
| 66 // For clipping we'll just skip any optimizations based on the bounds. | 71 // For clipping we'll just skip any optimizations based on the bounds. |
| 67 fBounds.setLargest(); | 72 fBounds.setLargest(); |
| 68 } | 73 } |
| 69 | 74 |
| 70 bool GrDrawPathRangeBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { | 75 bool GrDrawPathRangeBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { |
| 71 GrDrawPathRangeBatch* that = t->cast<GrDrawPathRangeBatch>(); | 76 GrDrawPathRangeBatch* that = t->cast<GrDrawPathRangeBatch>(); |
| 72 if (!GrPathRangeDraw::CanMerge(**this->fDraws.head(), **that->fDraws.head())
) { | 77 if (!GrPathRangeDraw::CanMerge(**this->fDraws.head(), **that->fDraws.head())
) { |
| 73 return false; | 78 return false; |
| 74 } | 79 } |
| 75 if (!GrPipeline::AreEqual(*this->pipeline(), *that->pipeline(), false)) { | 80 if (!GrPipeline::AreEqual(*this->pipeline(), *that->pipeline(), false)) { |
| 76 return false; | 81 return false; |
| 77 } | 82 } |
| 78 if (!this->pathProcessor()->isEqual(*this->tracker(), *that->pathProcessor()
, | 83 if (this->color() != that->color() || |
| 79 *that->tracker())) { | 84 !this->viewMatrix().cheapEqualTo(that->viewMatrix()) || |
| 85 !fLocalMatrix.cheapEqualTo(that->fLocalMatrix)) { |
| 80 return false; | 86 return false; |
| 81 } | 87 } |
| 82 // TODO: Check some other things here. (winding, opaque, pathProc color, vm,
...) | 88 // TODO: Check some other things here. (winding, opaque, pathProc color, vm,
...) |
| 83 // Try to combine this call with the previous DrawPaths. We do this by stenc
iling all the | 89 // Try to combine this call with the previous DrawPaths. We do this by stenc
iling all the |
| 84 // paths together and then covering them in a single pass. This is not equiv
alent to two | 90 // paths together and then covering them in a single pass. This is not equiv
alent to two |
| 85 // separate draw calls, so we can only do it if there is no blending (no ove
rlap would also | 91 // separate draw calls, so we can only do it if there is no blending (no ove
rlap would also |
| 86 // work). Note that it's also possible for overlapping paths to cancel each
other's winding | 92 // work). Note that it's also possible for overlapping paths to cancel each
other's winding |
| 87 // numbers, and we only partially account for this by not allowing even/odd
paths to be | 93 // numbers, and we only partially account for this by not allowing even/odd
paths to be |
| 88 // combined. (Glyphs in the same font tend to wind the same direction so it
works out OK.) | 94 // combined. (Glyphs in the same font tend to wind the same direction so it
works out OK.) |
| 89 if (!this->isWinding() || | 95 if (!this->isWinding() || |
| 90 this->stencilSettings() != that->stencilSettings() || | 96 this->stencilSettings() != that->stencilSettings() || |
| 91 this->opts().willColorBlendWithDst()) { | 97 this->opts().willColorBlendWithDst()) { |
| 92 return false; | 98 return false; |
| 93 } | 99 } |
| 94 SkASSERT(!that->opts().willColorBlendWithDst()); | 100 SkASSERT(!that->opts().willColorBlendWithDst()); |
| 95 fTotalPathCount += that->fTotalPathCount; | 101 fTotalPathCount += that->fTotalPathCount; |
| 96 while (GrPathRangeDraw** head = that->fDraws.head()) { | 102 while (GrPathRangeDraw** head = that->fDraws.head()) { |
| 97 fDraws.addToTail(*head); | 103 fDraws.addToTail(*head); |
| 98 // We're stealing that's refs, so pop without unreffing. | 104 // We're stealing that's refs, so pop without unreffing. |
| 99 that->fDraws.popHead(); | 105 that->fDraws.popHead(); |
| 100 } | 106 } |
| 101 return true; | 107 return true; |
| 102 } | 108 } |
| 103 | 109 |
| 104 void GrDrawPathRangeBatch::onDraw(GrBatchFlushState* state) { | 110 void GrDrawPathRangeBatch::onDraw(GrBatchFlushState* state) { |
| 105 GrProgramDesc desc; | 111 GrProgramDesc desc; |
| 106 state->gpu()->buildProgramDesc(&desc, *this->pathProcessor(), *this->pipelin
e(), | 112 SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color()
, |
| 107 *this->tracker()); | 113 this->opts(), |
| 108 GrPathRendering::DrawPathArgs args(this->pathProcessor(), this->pipeline(), | 114 this->viewMat
rix(), |
| 115 fLocalMatrix)
); |
| 116 state->gpu()->buildProgramDesc(&desc, *pathProc, *this->pipeline(), |
| 117 *this->tracker()); |
| 118 GrPathRendering::DrawPathArgs args(pathProc, this->pipeline(), |
| 109 &desc, this->tracker(), &this->stencilSe
ttings()); | 119 &desc, this->tracker(), &this->stencilSe
ttings()); |
| 110 if (fDraws.count() == 1) { | 120 if (fDraws.count() == 1) { |
| 111 const GrPathRangeDraw& draw = **fDraws.head(); | 121 const GrPathRangeDraw& draw = **fDraws.head(); |
| 112 state->gpu()->pathRendering()->drawPaths(args, draw.range(), draw.indice
s(), | 122 state->gpu()->pathRendering()->drawPaths(args, draw.range(), draw.indice
s(), |
| 113 GrPathRange::kU16_PathIndexType, draw.transforms(), draw.transformTy
pe(), | 123 GrPathRange::kU16_PathIndexType, draw.transforms(), draw.transformTy
pe(), |
| 114 draw.count()); | 124 draw.count()); |
| 115 return; | 125 return; |
| 116 } | 126 } |
| 117 | 127 |
| 118 const GrPathRange* range = (*fDraws.head())->range(); | 128 const GrPathRange* range = (*fDraws.head())->range(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 129 memcpy(indices, (*iter.get())->indices(), cnt * sizeof(uint16_t)); | 139 memcpy(indices, (*iter.get())->indices(), cnt * sizeof(uint16_t)); |
| 130 indices += cnt; | 140 indices += cnt; |
| 131 memcpy(transforms, (*iter.get())->transforms(), cnt * floatsPerTransform
* sizeof(float)); | 141 memcpy(transforms, (*iter.get())->transforms(), cnt * floatsPerTransform
* sizeof(float)); |
| 132 transforms += cnt * floatsPerTransform; | 142 transforms += cnt * floatsPerTransform; |
| 133 } | 143 } |
| 134 SkASSERT(indices - indexStorage.get() == fTotalPathCount); | 144 SkASSERT(indices - indexStorage.get() == fTotalPathCount); |
| 135 state->gpu()->pathRendering()->drawPaths(args, range, indexStorage.get(), | 145 state->gpu()->pathRendering()->drawPaths(args, range, indexStorage.get(), |
| 136 GrPathRange::kU16_PathIndexType, transformStorage.get(), transformType, | 146 GrPathRange::kU16_PathIndexType, transformStorage.get(), transformType, |
| 137 fTotalPathCount); | 147 fTotalPathCount); |
| 138 } | 148 } |
| OLD | NEW |