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 "SkThread.h" | |
| 15 #include "SkTypes.h" | |
| 16 | |
| 17 class GrGpu; | |
| 18 class GrIndexBufferAllocPool; | |
| 19 class GrInitInvariantOutput; | |
| 20 class GrOptDrawState; | |
| 21 class GrVertexBufferAllocPool; | |
| 22 | |
| 23 struct GrBatchOpt { | |
| 24 bool fCanTweakAlphaForCoverage; | |
| 25 }; | |
| 26 | |
| 27 class GrBatch : public SkNoncopyable { | |
|
bsalomon
2015/01/20 16:14:02
needs a block comment explaining what this is/does
| |
| 28 public: | |
| 29 virtual ~GrBatch() {} | |
| 30 virtual const char* name() const = 0; | |
| 31 virtual void getInvariantOutputColor(GrInitInvariantOutput* out, | |
| 32 const GrBatchOpt&) const = 0; | |
| 33 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out, | |
| 34 const GrBatchOpt&) const = 0; | |
| 35 | |
| 36 virtual void initBatchOpt(const GrBatchOpt&) = 0; | |
| 37 virtual void initBatchTracker(const GrGeometryProcessor::InitBT& init) = 0; | |
| 38 | |
| 39 bool canMakeEqual(const GrBatch& that) const { | |
| 40 if (this->classID() != that.classID()) { | |
| 41 return false; | |
| 42 } | |
| 43 | |
| 44 return onCanMakeEqual(that); | |
| 45 } | |
| 46 | |
| 47 virtual bool onCanMakeEqual(const GrBatch&) const = 0; | |
| 48 virtual void makeEqual(GrBatch*) = 0; | |
| 49 | |
| 50 virtual void generateGeometry(GrGpu* gpu, | |
| 51 GrVertexBufferAllocPool* vpool, | |
| 52 GrIndexBufferAllocPool* ipool, | |
| 53 GrOptDrawState* optState) = 0; | |
| 54 virtual void draw(GrGpu* gpu, const GrOptDrawState* optState) = 0; | |
| 55 | |
| 56 void* operator new(size_t size); | |
| 57 void operator delete(void* target); | |
| 58 | |
| 59 void* operator new(size_t size, void* placement) { | |
| 60 return ::operator new(size, placement); | |
| 61 } | |
| 62 void operator delete(void* target, void* placement) { | |
| 63 ::operator delete(target, placement); | |
| 64 } | |
| 65 | |
| 66 /** | |
| 67 * Helper for down-casting to a GrBatch subclass | |
| 68 */ | |
| 69 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } | |
| 70 template <typename T> T* cast() { return static_cast<T*>(this); } | |
| 71 | |
| 72 uint32_t classID() const { SkASSERT(kIllegalBatchClassID != fClassID); retur n fClassID; } | |
| 73 | |
| 74 // TODO no GrPrimitiveProcessors yet read fragment position | |
| 75 bool willReadFragmentPosition() const { return false; } | |
| 76 | |
| 77 protected: | |
| 78 template <typename PROC_SUBCLASS> void initClassID() { | |
| 79 static uint32_t kClassID = GenClassID(); | |
| 80 fClassID = kClassID; | |
| 81 } | |
| 82 | |
| 83 uint32_t fClassID; | |
| 84 | |
| 85 private: | |
| 86 static uint32_t GenClassID() { | |
| 87 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The | |
| 88 // atomic inc returns the old value not the incremented value. So we add | |
| 89 // 1 to the returned value. | |
| 90 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) + 1; | |
| 91 if (!id) { | |
| 92 SkFAIL("This should never wrap as it should only be called once for each GrProcessor " | |
|
bsalomon
2015/01/20 16:14:02
each GrBatch subclass
| |
| 93 "subclass."); | |
| 94 } | |
| 95 return id; | |
| 96 } | |
| 97 | |
| 98 enum { | |
| 99 kIllegalBatchClassID = 0, | |
| 100 }; | |
| 101 static int32_t gCurrBatchClassID; | |
| 102 | |
| 103 }; | |
| 104 | |
| 105 #endif | |
| OLD | NEW |