Chromium Code Reviews| 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 |
| 11 #include "GrVertexBatch.h" | 11 #include "GrVertexBatch.h" |
| 12 | 12 |
| 13 #include "GrBatchFlushState.h" | 13 #include "GrBatchFlushState.h" |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * GrTInstanceBatch is an optional template to help with writing batches | 16 * GrTInstanceBatch is an optional template to help with writing batches |
| 17 * To use this template, The 'Impl' must define the following statics: | 17 * To use this template, The 'Impl' must define the following statics: |
| 18 * A Geometry struct | 18 * A Geometry struct |
| 19 * | 19 * |
| 20 * static const int kVertsPerInstance | 20 * static const int kVertsPerInstance |
| 21 * static const int kIndicesPerInstance | 21 * static const int kIndicesPerInstance |
| 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 * |
|
robertphillips
2015/09/18 17:42:26
UpdateBoundsForAppend ?
joshualitt
2015/09/18 18:34:10
Acknowledged.
| |
| 29 * void UpdateBounds(const Geometry& lastGeometry, SkRect* currentBounds) | |
| 30 * | |
| 29 * bool CanCombine(const Geometry& mine, const Geometry& theirs, | 31 * bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 30 * const GrPipelineOptimizations&) | 32 * const GrPipelineOptimizations&) |
| 31 * | 33 * |
| 32 * const GrGeometryProcessor* CreateGP(const Geometry& seedGeometry, | 34 * const GrGeometryProcessor* CreateGP(const Geometry& seedGeometry, |
| 33 * const GrPipelineOptimizations& opts) | 35 * const GrPipelineOptimizations& opts) |
| 34 * | 36 * |
| 35 * const GrIndexBuffer* GetIndexBuffer(GrResourceProvider*) | 37 * const GrIndexBuffer* GetIndexBuffer(GrResourceProvider*) |
| 36 * | 38 * |
| 37 * Tesselate(intptr_t vertices, size_t vertexStride, const Geometry& geo, | 39 * Tesselate(intptr_t vertices, size_t vertexStride, const Geometry& geo, |
| 38 * const GrPipelineOptimizations& opts) | 40 * const GrPipelineOptimizations& opts) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 57 Impl::InitInvariantOutputCoverage(out); | 59 Impl::InitInvariantOutputCoverage(out); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void initBatchTracker(const GrPipelineOptimizations& opt) override { | 62 void initBatchTracker(const GrPipelineOptimizations& opt) override { |
| 61 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 63 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
| 62 fOpts = opt; | 64 fOpts = opt; |
| 63 } | 65 } |
| 64 | 66 |
| 65 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 67 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 66 | 68 |
| 67 // to avoid even the initial copy of the struct, we have a getter for the fi rst item which | 69 // After seeding, the client should call init() so the Batch can initialize itself |
| 68 // is used to seed the batch with its initial geometry. After seeding, the client should call | |
| 69 // init() so the Batch can initialize itself | |
| 70 Geometry* geometry() { return &fGeoData[0]; } | |
| 71 void init() { | 70 void init() { |
| 72 const Geometry& geo = fGeoData[0]; | 71 const Geometry& geo = fGeoData[0]; |
| 73 Impl::SetBounds(geo, &fBounds); | 72 Impl::SetBounds(geo, &fBounds); |
| 74 } | 73 } |
| 75 | 74 |
|
robertphillips
2015/09/18 17:42:26
updateBoundsAfterAppend ?
updateBoundsForAppend ?
joshualitt
2015/09/18 18:34:11
Acknowledged.
| |
| 75 void updateBounds() { | |
| 76 const Geometry& geo = fGeoData.back(); | |
| 77 Impl::UpdateBounds(geo, &fBounds); | |
| 78 } | |
| 79 | |
| 76 private: | 80 private: |
| 77 GrTInstanceBatch() : INHERITED(ClassID()) { | 81 GrTInstanceBatch() : INHERITED(ClassID()) {} |
| 78 // Push back an initial geometry | |
| 79 fGeoData.push_back(); | |
| 80 } | |
| 81 | 82 |
| 82 void onPrepareDraws(Target* target) override { | 83 void onPrepareDraws(Target* target) override { |
| 83 SkAutoTUnref<const GrGeometryProcessor> gp(Impl::CreateGP(this->seedGeom etry(), fOpts)); | 84 SkAutoTUnref<const GrGeometryProcessor> gp(Impl::CreateGP(this->seedGeom etry(), fOpts)); |
| 84 if (!gp) { | 85 if (!gp) { |
| 85 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 86 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
| 86 return; | 87 return; |
| 87 } | 88 } |
| 88 | 89 |
| 89 target->initDraw(gp, this->pipeline()); | 90 target->initDraw(gp, this->pipeline()); |
| 90 | 91 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 return true; | 135 return true; |
| 135 } | 136 } |
| 136 | 137 |
| 137 GrPipelineOptimizations fOpts; | 138 GrPipelineOptimizations fOpts; |
| 138 SkSTArray<1, Geometry, true> fGeoData; | 139 SkSTArray<1, Geometry, true> fGeoData; |
| 139 | 140 |
| 140 typedef GrVertexBatch INHERITED; | 141 typedef GrVertexBatch INHERITED; |
| 141 }; | 142 }; |
| 142 | 143 |
| 143 #endif | 144 #endif |
| OLD | NEW |