Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef GrBatch_DEFINED | |
| 9 #define GrBatch_DEFINED | |
| 10 | |
| 11 #include <new> | |
| 12 // TODO remove this header when we move entirely to batch | |
| 13 #include "GrGeometryProcessor.h" | |
| 14 #include "SkRefCnt.h" | |
| 15 #include "SkThread.h" | |
| 16 #include "SkTypes.h" | |
| 17 | |
| 18 class GrBatchBuffer; | |
| 19 class GrGpu; | |
| 20 class GrIndexBufferAllocPool; | |
| 21 class GrInitInvariantOutput; | |
| 22 class GrOptDrawState; | |
| 23 class GrVertexBufferAllocPool; | |
| 24 | |
| 25 /* | |
| 26 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa cilitate | |
| 27 * reorderable batching, Ganesh does not generate geometry inline with draw call s. Instead, it | |
| 28 * captures the arguments to the draw and then generates the geometry on demand. This gives GrBatch | |
| 29 * subclasses complete freedom to decide how / what they can batch. | |
| 30 * | |
| 31 * Batches are created generally in renderers, but they cannot be reused. Inste ad, they are owned | |
|
bsalomon
2015/01/21 21:39:29
How about
"Batches are created when GrContext pro
| |
| 32 * by a GrDrawTarget subclass after being passed into BatchDraw. Two GrBatches may be batched. The | |
| 33 * canMakeEqual and MakeEqual calls below are used to determine if two batches c an batch. MakeEqual | |
| 34 * can be destructive. | |
| 35 * | |
| 36 * GrBatches are always drawn with a GrOptDrawState. Of the GrOptDrawState dete rmines any | |
|
bsalomon
2015/01/21 21:39:29
The second sentence is confusing. Also, this might
| |
| 37 * pipeline optimizations are possible, it will communicate this information to the GrBatch through | |
| 38 * GrBatchOpt. | |
| 39 * | |
| 40 * Finally, generateGeometry is called with a GrOptDrawState, and a GrBatchBuffe r. GrBatchBuffer | |
|
bsalomon
2015/01/21 21:39:29
Can you just explain it directly in terms of GrBat
| |
| 41 * can be treated somewhat like a Gpu, and though it guarantees in order playbac k to a real gpu, it | |
| 42 * may delay flushing to the gpu for performance reasons. | |
| 43 */ | |
| 44 | |
| 45 struct GrBatchOpt { | |
| 46 bool fCanTweakAlphaForCoverage; | |
| 47 }; | |
| 48 | |
| 49 class GrBatch : public SkRefCnt { | |
| 50 public: | |
| 51 SK_DECLARE_INST_COUNT(GrBatch) | |
| 52 GrBatch() { SkDEBUGCODE(fUsed = false;) } | |
| 53 virtual ~GrBatch() {} | |
| 54 virtual const char* name() const = 0; | |
| 55 virtual void getInvariantOutputColor(GrInitInvariantOutput* out, | |
| 56 const GrBatchOpt&) const = 0; | |
| 57 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out, | |
| 58 const GrBatchOpt&) const = 0; | |
| 59 | |
| 60 virtual void initBatchOpt(const GrBatchOpt&) = 0; | |
| 61 virtual void initBatchTracker(const GrGeometryProcessor::InitBT& init) = 0; | |
| 62 | |
| 63 bool combineIfPossible(GrBatch* that) { | |
| 64 if (this->classID() != that->classID()) { | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 return onCombineIfPossible(that); | |
| 69 } | |
| 70 | |
| 71 virtual bool onCombineIfPossible(GrBatch*) = 0; | |
| 72 | |
| 73 virtual void generateGeometry(GrBatchBuffer*, const GrOptDrawState*) = 0; | |
| 74 | |
| 75 void* operator new(size_t size); | |
| 76 void operator delete(void* target); | |
| 77 | |
| 78 void* operator new(size_t size, void* placement) { | |
| 79 return ::operator new(size, placement); | |
| 80 } | |
| 81 void operator delete(void* target, void* placement) { | |
| 82 ::operator delete(target, placement); | |
| 83 } | |
| 84 | |
| 85 /** | |
| 86 * Helper for down-casting to a GrBatch subclass | |
| 87 */ | |
| 88 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } | |
| 89 template <typename T> T* cast() { return static_cast<T*>(this); } | |
| 90 | |
| 91 uint32_t classID() const { SkASSERT(kIllegalBatchClassID != fClassID); retur n fClassID; } | |
| 92 | |
| 93 // TODO no GrPrimitiveProcessors yet read fragment position | |
| 94 bool willReadFragmentPosition() const { return false; } | |
| 95 | |
| 96 SkDEBUGCODE(bool isUsed() const { return fUsed; }) | |
| 97 | |
| 98 protected: | |
| 99 template <typename PROC_SUBCLASS> void initClassID() { | |
| 100 static uint32_t kClassID = GenClassID(); | |
| 101 fClassID = kClassID; | |
| 102 } | |
| 103 | |
| 104 uint32_t fClassID; | |
| 105 | |
| 106 private: | |
| 107 static uint32_t GenClassID() { | |
| 108 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The | |
| 109 // atomic inc returns the old value not the incremented value. So we add | |
| 110 // 1 to the returned value. | |
| 111 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) + 1; | |
| 112 if (!id) { | |
| 113 SkFAIL("This should never wrap as it should only be called once for each GrBatch " | |
| 114 "subclass."); | |
| 115 } | |
| 116 return id; | |
| 117 } | |
| 118 | |
| 119 enum { | |
| 120 kIllegalBatchClassID = 0, | |
| 121 }; | |
| 122 static int32_t gCurrBatchClassID; | |
| 123 | |
| 124 SkDEBUGCODE(bool fUsed;) | |
| 125 | |
| 126 typedef SkRefCnt INHERITED; | |
| 127 }; | |
| 128 | |
| 129 #endif | |
| OLD | NEW |