| 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 static void pre_translate_transform_values(const float* xforms, | 10 static void pre_translate_transform_values(const float* xforms, |
| 11 GrPathRendering::PathTransformType ty
pe, int count, | 11 GrPathRendering::PathTransformType ty
pe, int count, |
| 12 SkScalar x, SkScalar y, float* dst); | 12 SkScalar x, SkScalar y, float* dst); |
| 13 | 13 |
| 14 SkString GrDrawPathBatch::dumpInfo() const { | 14 SkString GrDrawPathBatch::dumpInfo() const { |
| 15 SkString string; | 15 SkString string; |
| 16 string.printf("Color: 0x%08x Fill: %x Path count: %d Paths: ", this->color()
, this->fillType(), | 16 string.printf("PATH: 0x%p", fPath.get()); |
| 17 fTotalPathCount); | |
| 18 const GrDrawPathBatch* batch = this; | |
| 19 do { | |
| 20 string.appendf("0x%p", batch->fPath.get()); | |
| 21 batch = batch->fNext.get(); | |
| 22 } while (batch); | |
| 23 string.append("\n"); | |
| 24 return string; | 17 return string; |
| 25 } | 18 } |
| 26 | 19 |
| 27 bool GrDrawPathBatch::ListBoundsIntersects(const GrDrawPathBatch* a, const GrDra
wPathBatch* b) { | 20 void GrDrawPathBatch::onDraw(GrBatchFlushState* state) { |
| 28 if (!SkRect::Intersects(a->fBounds, b->fBounds)) { | 21 GrProgramDesc desc; |
| 29 return false; | |
| 30 } | |
| 31 if (!a->fNext && !b->fNext) { | |
| 32 return true; | |
| 33 } | |
| 34 const GrDrawPathBatch* firstA = a; | |
| 35 do { | |
| 36 do { | |
| 37 if (SkRect::Intersects(a->fPathBounds, b->fPathBounds)) { | |
| 38 return true; | |
| 39 } | |
| 40 a = a->fNext.get(); | |
| 41 } while (a); | |
| 42 a = firstA; | |
| 43 b = b->fNext.get(); | |
| 44 } while (b); | |
| 45 return false; | |
| 46 } | |
| 47 | 22 |
| 48 bool GrDrawPathBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { | |
| 49 GrDrawPathBatch* that = t->cast<GrDrawPathBatch>(); | |
| 50 if (this->color() != that->color() || | |
| 51 !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { | |
| 52 return false; | |
| 53 } | |
| 54 if (!GrPipeline::AreEqual(*this->pipeline(), *that->pipeline(), false)) { | |
| 55 return false; | |
| 56 } | |
| 57 if (that->fillType() != this->fillType() || | |
| 58 this->stencilSettings() != that->stencilSettings()) { | |
| 59 return false; | |
| 60 } | |
| 61 if (ListBoundsIntersects(this, that)) { | |
| 62 return false; | |
| 63 } | |
| 64 if (!fPath.get()->canCombineDrawPathBatchWith(*that->fPath.get())) { | |
| 65 return false; | |
| 66 } | |
| 67 SkASSERT(!*fLastSlot); | |
| 68 fLastSlot->reset(SkRef(that)); | |
| 69 fLastSlot = that->fLastSlot; | |
| 70 fTotalPathCount += that->fTotalPathCount; | |
| 71 this->joinBounds(that->fBounds); | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 void GrDrawPathBatch::onDraw(GrBatchFlushState* state) { | |
| 76 SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color()
, | 23 SkAutoTUnref<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color()
, |
| 77 this->overrid
es(), | 24 this->overrid
es(), |
| 78 this->viewMat
rix())); | 25 this->viewMat
rix())); |
| 79 if (fTotalPathCount > 1) { | 26 state->gpu()->pathRendering()->drawPath(*this->pipeline(), *pathProc, this->
stencilSettings(), |
| 80 SkAutoSTMalloc<32, const GrPath*> paths(fTotalPathCount); | 27 fPath.get()); |
| 81 GrDrawPathBatch* batch = this; | |
| 82 int i = 0; | |
| 83 do { | |
| 84 paths[i++] = batch->fPath.get(); | |
| 85 batch = batch->fNext.get(); | |
| 86 } while (batch); | |
| 87 state->gpu()->pathRendering()->drawPaths(*this->pipeline(), *pathProc, | |
| 88 this->stencilSettings(), paths,
fTotalPathCount); | |
| 89 } else { | |
| 90 const GrPath* path = fPath.get(); | |
| 91 state->gpu()->pathRendering()->drawPaths(*this->pipeline(), *pathProc, | |
| 92 this->stencilSettings(), &path,
1); | |
| 93 } | |
| 94 } | 28 } |
| 95 | 29 |
| 96 SkString GrDrawPathRangeBatch::dumpInfo() const { | 30 SkString GrDrawPathRangeBatch::dumpInfo() const { |
| 97 SkString string; | 31 SkString string; |
| 98 string.printf("RANGE: 0x%p COUNTS: [", fPathRange.get()); | 32 string.printf("RANGE: 0x%p COUNTS: [", fPathRange.get()); |
| 99 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { | 33 for (DrawList::Iter iter(fDraws); iter.get(); iter.next()) { |
| 100 string.appendf("%d, ", iter.get()->fInstanceData->count()); | 34 string.appendf("%d, ", iter.get()->fInstanceData->count()); |
| 101 } | 35 } |
| 102 string.remove(string.size() - 2, 2); | 36 string.remove(string.size() - 2, 2); |
| 103 string.append("]"); | 37 string.append("]"); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 dst[i + 3] = xforms[i + 3]; | 202 dst[i + 3] = xforms[i + 3]; |
| 269 dst[i + 4] = xforms[i + 4]; | 203 dst[i + 4] = xforms[i + 4]; |
| 270 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i +
5]; | 204 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i +
5]; |
| 271 } | 205 } |
| 272 break; | 206 break; |
| 273 default: | 207 default: |
| 274 SkFAIL("Unknown transform type."); | 208 SkFAIL("Unknown transform type."); |
| 275 break; | 209 break; |
| 276 } | 210 } |
| 277 } | 211 } |
| OLD | NEW |