| 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) |
| 26 * |
| 27 * void SetBounds(const Geometry& seedGeometry, SkRect* outBounds) |
| 28 * |
| 25 * bool CanCombine(const Geometry& mine, const Geometry& theirs, | 29 * bool CanCombine(const Geometry& mine, const Geometry& theirs, |
| 26 * const GrPipelineOptimizations&) | 30 * const GrPipelineOptimizations&) |
| 27 * | 31 * |
| 28 * const GrGeometryProcessor* CreateGP(const Geometry& seedGeometry, | 32 * const GrGeometryProcessor* CreateGP(const Geometry& seedGeometry, |
| 29 * const GrPipelineOptimizations& opts) | 33 * const GrPipelineOptimizations& opts) |
| 30 * | 34 * |
| 31 * const GrIndexBuffer* GetIndexBuffer(GrResourceProvider*) | 35 * const GrIndexBuffer* GetIndexBuffer(GrResourceProvider*) |
| 32 * | 36 * |
| 33 * Tesselate(intptr_t vertices, size_t vertexStride, const Geometry& geo, | 37 * Tesselate(intptr_t vertices, size_t vertexStride, const Geometry& geo, |
| 34 * const GrPipelineOptimizations& opts) | 38 * const GrPipelineOptimizations& opts) |
| 35 */ | 39 */ |
| 36 template <typename Impl> | 40 template <typename Impl> |
| 37 class GrTInstanceBatch : public GrVertexBatch { | 41 class GrTInstanceBatch : public GrVertexBatch { |
| 38 public: | 42 public: |
| 39 typedef typename Impl::Geometry Geometry; | 43 typedef typename Impl::Geometry Geometry; |
| 40 | 44 |
| 41 static GrTInstanceBatch* Create() { | 45 static GrTInstanceBatch* Create() { |
| 42 return SkNEW(GrTInstanceBatch); | 46 return SkNEW(GrTInstanceBatch); |
| 43 } | 47 } |
| 44 | 48 |
| 45 const char* name() const override { return Impl::Name(); } | 49 const char* name() const override { return Impl::Name(); } |
| 46 | 50 |
| 47 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 51 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 48 // When this is called on a batch, there is only one geometry bundle | 52 // When this is called on a batch, there is only one geometry bundle |
| 49 out->setKnownFourComponents(fGeoData[0].fColor); | 53 out->setKnownFourComponents(fGeoData[0].fColor); |
| 50 } | 54 } |
| 51 | 55 |
| 52 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 56 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 53 out->setUnknownSingleComponent(); | 57 Impl::InitInvariantOutputCoverage(out); |
| 54 } | 58 } |
| 55 | 59 |
| 56 void initBatchTracker(const GrPipelineOptimizations& opt) override { | 60 void initBatchTracker(const GrPipelineOptimizations& opt) override { |
| 57 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 61 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
| 58 fOpts = opt; | 62 fOpts = opt; |
| 59 } | 63 } |
| 60 | 64 |
| 61 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 65 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 62 | 66 |
| 63 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which | 67 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which |
| 64 // is used to seed the batch with its initial geometry. After seeding, the
client should call | 68 // is used to seed the batch with its initial geometry. After seeding, the
client should call |
| 65 // init() so the Batch can initialize itself | 69 // init() so the Batch can initialize itself |
| 66 Geometry* geometry() { return &fGeoData[0]; } | 70 Geometry* geometry() { return &fGeoData[0]; } |
| 67 void init() { | 71 void init() { |
| 68 const Geometry& geo = fGeoData[0]; | 72 const Geometry& geo = fGeoData[0]; |
| 69 this->setBounds(geo.fDevRect); | 73 Impl::SetBounds(geo, &fBounds); |
| 70 } | 74 } |
| 71 | 75 |
| 72 private: | 76 private: |
| 73 GrTInstanceBatch() { | 77 GrTInstanceBatch() { |
| 74 this->initClassID<GrTInstanceBatch<Impl>>(); | 78 this->initClassID<GrTInstanceBatch<Impl>>(); |
| 75 | 79 |
| 76 // Push back an initial geometry | 80 // Push back an initial geometry |
| 77 fGeoData.push_back(); | 81 fGeoData.push_back(); |
| 78 } | 82 } |
| 79 | 83 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 134 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 131 this->joinBounds(that->bounds()); | 135 this->joinBounds(that->bounds()); |
| 132 return true; | 136 return true; |
| 133 } | 137 } |
| 134 | 138 |
| 135 GrPipelineOptimizations fOpts; | 139 GrPipelineOptimizations fOpts; |
| 136 SkSTArray<1, Geometry, true> fGeoData; | 140 SkSTArray<1, Geometry, true> fGeoData; |
| 137 }; | 141 }; |
| 138 | 142 |
| 139 #endif | 143 #endif |
| OLD | NEW |