| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 void updateBoundsAfterAppend() { | 83 void updateBoundsAfterAppend() { |
| 84 const Geometry& geo = fGeoData.back(); | 84 const Geometry& geo = fGeoData.back(); |
| 85 Impl::UpdateBoundsAfterAppend(geo, &fBounds); | 85 Impl::UpdateBoundsAfterAppend(geo, &fBounds); |
| 86 } | 86 } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 GrTInstanceBatch() : INHERITED(ClassID()) {} | 89 GrTInstanceBatch() : INHERITED(ClassID()) {} |
| 90 | 90 |
| 91 void onPrepareDraws(Target* target) const override { | 91 void onPrepareDraws(Target* target) const override { |
| 92 SkAutoTUnref<const GrGeometryProcessor> gp(Impl::CreateGP(this->seedGeom
etry(), | 92 sk_sp<GrGeometryProcessor> gp(Impl::MakeGP(this->seedGeometry(), fOverri
des)); |
| 93 fOverrides)); | |
| 94 if (!gp) { | 93 if (!gp) { |
| 95 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 94 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
| 96 return; | 95 return; |
| 97 } | 96 } |
| 98 | 97 |
| 99 size_t vertexStride = gp->getVertexStride(); | 98 size_t vertexStride = gp->getVertexStride(); |
| 100 int instanceCount = fGeoData.count(); | 99 int instanceCount = fGeoData.count(); |
| 101 | 100 |
| 102 SkAutoTUnref<const GrBuffer> indexBuffer( | 101 SkAutoTUnref<const GrBuffer> indexBuffer( |
| 103 Impl::GetIndexBuffer(target->resourceProvider())); | 102 Impl::GetIndexBuffer(target->resourceProvider())); |
| 104 InstancedHelper helper; | 103 InstancedHelper helper; |
| 105 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, | 104 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, |
| 106 indexBuffer, Impl::kVertsPerInstance, | 105 indexBuffer, Impl::kVertsPerInstance, |
| 107 Impl::kIndicesPerInstance, instanceCount); | 106 Impl::kIndicesPerInstance, instanceCount); |
| 108 if (!vertices || !indexBuffer) { | 107 if (!vertices || !indexBuffer) { |
| 109 SkDebugf("Could not allocate vertices\n"); | 108 SkDebugf("Could not allocate vertices\n"); |
| 110 return; | 109 return; |
| 111 } | 110 } |
| 112 | 111 |
| 113 for (int i = 0; i < instanceCount; i++) { | 112 for (int i = 0; i < instanceCount; i++) { |
| 114 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + | 113 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + |
| 115 i * Impl::kVertsPerInstance * vertexStride; | 114 i * Impl::kVertsPerInstance * vertexStride; |
| 116 Impl::Tesselate(verts, vertexStride, fGeoData[i], fOverrides); | 115 Impl::Tesselate(verts, vertexStride, fGeoData[i], fOverrides); |
| 117 } | 116 } |
| 118 helper.recordDraw(target, gp); | 117 helper.recordDraw(target, gp.get()); |
| 119 } | 118 } |
| 120 | 119 |
| 121 const Geometry& seedGeometry() const { return fGeoData[0]; } | 120 const Geometry& seedGeometry() const { return fGeoData[0]; } |
| 122 | 121 |
| 123 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 122 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 124 GrTInstanceBatch* that = t->cast<GrTInstanceBatch>(); | 123 GrTInstanceBatch* that = t->cast<GrTInstanceBatch>(); |
| 125 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), | 124 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 126 that->bounds(), caps)) { | 125 that->bounds(), caps)) { |
| 127 return false; | 126 return false; |
| 128 } | 127 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 142 return true; | 141 return true; |
| 143 } | 142 } |
| 144 | 143 |
| 145 GrXPOverridesForBatch fOverrides; | 144 GrXPOverridesForBatch fOverrides; |
| 146 SkSTArray<1, Geometry, true> fGeoData; | 145 SkSTArray<1, Geometry, true> fGeoData; |
| 147 | 146 |
| 148 typedef GrVertexBatch INHERITED; | 147 typedef GrVertexBatch INHERITED; |
| 149 }; | 148 }; |
| 150 | 149 |
| 151 #endif | 150 #endif |
| OLD | NEW |