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