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