| 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 #ifndef GrTInstanceBatch_DEFINED | 8 #ifndef GrTInstanceBatch_DEFINED |
| 9 #define GrTInstanceBatch_DEFINED | 9 #define GrTInstanceBatch_DEFINED |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * | 22 * |
| 23 * const char* Name() | 23 * const char* Name() |
| 24 * | 24 * |
| 25 * void InvariantOutputCoverage(GrInitInvariantOutput* out) | 25 * void InvariantOutputCoverage(GrInitInvariantOutput* out) |
| 26 * | 26 * |
| 27 * void SetBounds(const Geometry& seedGeometry, SkRect* outBounds) | 27 * void SetBounds(const Geometry& seedGeometry, SkRect* outBounds) |
| 28 * | 28 * |
| 29 * void UpdateBoundsAfterAppend(const Geometry& lastGeometry, SkRect* curren
tBounds) | 29 * void UpdateBoundsAfterAppend(const Geometry& lastGeometry, SkRect* curren
tBounds) |
| 30 * | 30 * |
| 31 * bool CanCombine(const Geometry& mine, const Geometry& theirs, | 31 * bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 32 * const GrPipelineOptimizations&) | 32 * const GrXPOverridesForBatch&) |
| 33 * | 33 * |
| 34 * const GrGeometryProcessor* CreateGP(const Geometry& seedGeometry, | 34 * const GrGeometryProcessor* CreateGP(const Geometry& seedGeometry, |
| 35 * const GrPipelineOptimizations& opts) | 35 * const GrXPOverridesForBatch& override
s) |
| 36 * | 36 * |
| 37 * const GrIndexBuffer* GetIndexBuffer(GrResourceProvider*) | 37 * const GrIndexBuffer* GetIndexBuffer(GrResourceProvider*) |
| 38 * | 38 * |
| 39 * Tesselate(intptr_t vertices, size_t vertexStride, const Geometry& geo, | 39 * Tesselate(intptr_t vertices, size_t vertexStride, const Geometry& geo, |
| 40 * const GrPipelineOptimizations& opts) | 40 * const GrXPOverridesForBatch& overrides) |
| 41 */ | 41 */ |
| 42 template <typename Impl> | 42 template <typename Impl> |
| 43 class GrTInstanceBatch : public GrVertexBatch { | 43 class GrTInstanceBatch : public GrVertexBatch { |
| 44 public: | 44 public: |
| 45 DEFINE_BATCH_CLASS_ID | 45 DEFINE_BATCH_CLASS_ID |
| 46 | 46 |
| 47 typedef typename Impl::Geometry Geometry; | 47 typedef typename Impl::Geometry Geometry; |
| 48 | 48 |
| 49 static GrTInstanceBatch* Create() { return new GrTInstanceBatch; } | 49 static GrTInstanceBatch* Create() { return new GrTInstanceBatch; } |
| 50 | 50 |
| 51 const char* name() const override { return Impl::Name(); } | 51 const char* name() const override { return Impl::Name(); } |
| 52 | 52 |
| 53 SkString dumpInfo() const override { | 53 SkString dumpInfo() const override { |
| 54 SkString str; | 54 SkString str; |
| 55 for (int i = 0; i < fGeoData.count(); ++i) { | 55 for (int i = 0; i < fGeoData.count(); ++i) { |
| 56 str.append(Impl::DumpInfo(fGeoData[i], i)); | 56 str.append(Impl::DumpInfo(fGeoData[i], i)); |
| 57 } | 57 } |
| 58 str.append(INHERITED::dumpInfo()); | 58 str.append(INHERITED::dumpInfo()); |
| 59 return str; | 59 return str; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 62 void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 63 GrInitInvariantOutput* coverage, |
| 64 GrBatchToXPOverrides* overrides) const ove
rride { |
| 63 // When this is called on a batch, there is only one geometry bundle | 65 // When this is called on a batch, there is only one geometry bundle |
| 64 out->setKnownFourComponents(fGeoData[0].fColor); | 66 color->setKnownFourComponents(fGeoData[0].fColor); |
| 67 Impl::InitInvariantOutputCoverage(coverage); |
| 68 overrides->fUsePLSDstRead = false; |
| 65 } | 69 } |
| 66 | 70 |
| 67 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 71 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
| 68 Impl::InitInvariantOutputCoverage(out); | 72 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); |
| 69 } | 73 fOverrides = overrides; |
| 70 | |
| 71 void initBatchTracker(const GrPipelineOptimizations& opt) override { | |
| 72 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | |
| 73 fOpts = opt; | |
| 74 } | 74 } |
| 75 | 75 |
| 76 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 76 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 77 | 77 |
| 78 // After seeding, the client should call init() so the Batch can initialize
itself | 78 // After seeding, the client should call init() so the Batch can initialize
itself |
| 79 void init() { | 79 void init() { |
| 80 const Geometry& geo = fGeoData[0]; | 80 const Geometry& geo = fGeoData[0]; |
| 81 Impl::SetBounds(geo, &fBounds); | 81 Impl::SetBounds(geo, &fBounds); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void updateBoundsAfterAppend() { | 84 void updateBoundsAfterAppend() { |
| 85 const Geometry& geo = fGeoData.back(); | 85 const Geometry& geo = fGeoData.back(); |
| 86 Impl::UpdateBoundsAfterAppend(geo, &fBounds); | 86 Impl::UpdateBoundsAfterAppend(geo, &fBounds); |
| 87 } | 87 } |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 GrTInstanceBatch() : INHERITED(ClassID()) {} | 90 GrTInstanceBatch() : INHERITED(ClassID()) {} |
| 91 | 91 |
| 92 void onPrepareDraws(Target* target) override { | 92 void onPrepareDraws(Target* target) override { |
| 93 SkAutoTUnref<const GrGeometryProcessor> gp(Impl::CreateGP(this->seedGeom
etry(), fOpts)); | 93 SkAutoTUnref<const GrGeometryProcessor> gp(Impl::CreateGP(this->seedGeom
etry(), |
| 94 fOverrides)); |
| 94 if (!gp) { | 95 if (!gp) { |
| 95 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 96 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
| 96 return; | 97 return; |
| 97 } | 98 } |
| 98 | 99 |
| 99 target->initDraw(gp, this->pipeline()); | 100 target->initDraw(gp, this->pipeline()); |
| 100 | 101 |
| 101 size_t vertexStride = gp->getVertexStride(); | 102 size_t vertexStride = gp->getVertexStride(); |
| 102 int instanceCount = fGeoData.count(); | 103 int instanceCount = fGeoData.count(); |
| 103 | 104 |
| 104 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 105 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 105 Impl::GetIndexBuffer(target->resourceProvider())); | 106 Impl::GetIndexBuffer(target->resourceProvider())); |
| 106 InstancedHelper helper; | 107 InstancedHelper helper; |
| 107 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, | 108 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, |
| 108 indexBuffer, Impl::kVertsPerInstance, | 109 indexBuffer, Impl::kVertsPerInstance, |
| 109 Impl::kIndicesPerInstance, instanceCount); | 110 Impl::kIndicesPerInstance, instanceCount); |
| 110 if (!vertices || !indexBuffer) { | 111 if (!vertices || !indexBuffer) { |
| 111 SkDebugf("Could not allocate vertices\n"); | 112 SkDebugf("Could not allocate vertices\n"); |
| 112 return; | 113 return; |
| 113 } | 114 } |
| 114 | 115 |
| 115 for (int i = 0; i < instanceCount; i++) { | 116 for (int i = 0; i < instanceCount; i++) { |
| 116 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + | 117 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + |
| 117 i * Impl::kVertsPerInstance * vertexStride; | 118 i * Impl::kVertsPerInstance * vertexStride; |
| 118 Impl::Tesselate(verts, vertexStride, fGeoData[i], fOpts); | 119 Impl::Tesselate(verts, vertexStride, fGeoData[i], fOverrides); |
| 119 } | 120 } |
| 120 helper.recordDraw(target); | 121 helper.recordDraw(target); |
| 121 } | 122 } |
| 122 | 123 |
| 123 const Geometry& seedGeometry() const { return fGeoData[0]; } | 124 const Geometry& seedGeometry() const { return fGeoData[0]; } |
| 124 | 125 |
| 125 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 126 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 126 GrTInstanceBatch* that = t->cast<GrTInstanceBatch>(); | 127 GrTInstanceBatch* that = t->cast<GrTInstanceBatch>(); |
| 127 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), | 128 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 128 that->bounds(), caps)) { | 129 that->bounds(), caps)) { |
| 129 return false; | 130 return false; |
| 130 } | 131 } |
| 131 | 132 |
| 132 if (!Impl::CanCombine(this->seedGeometry(), that->seedGeometry(), fOpts)
) { | 133 if (!Impl::CanCombine(this->seedGeometry(), that->seedGeometry(), fOverr
ides)) { |
| 133 return false; | 134 return false; |
| 134 } | 135 } |
| 135 | 136 |
| 136 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to | 137 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to |
| 137 // not tweaking | 138 // not tweaking |
| 138 if (fOpts.canTweakAlphaForCoverage() && !that->fOpts.canTweakAlphaForCov
erage()) { | 139 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA
lphaForCoverage()) { |
| 139 fOpts = that->fOpts; | 140 fOverrides = that->fOverrides; |
| 140 } | 141 } |
| 141 | 142 |
| 142 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 143 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 143 this->joinBounds(that->bounds()); | 144 this->joinBounds(that->bounds()); |
| 144 return true; | 145 return true; |
| 145 } | 146 } |
| 146 | 147 |
| 147 GrPipelineOptimizations fOpts; | 148 GrXPOverridesForBatch fOverrides; |
| 148 SkSTArray<1, Geometry, true> fGeoData; | 149 SkSTArray<1, Geometry, true> fGeoData; |
| 149 | 150 |
| 150 typedef GrVertexBatch INHERITED; | 151 typedef GrVertexBatch INHERITED; |
| 151 }; | 152 }; |
| 152 | 153 |
| 153 #endif | 154 #endif |
| OLD | NEW |