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 GrDraw_DEFINED |
| 9 #define GrDraw_DEFINED |
| 10 |
| 11 #include "GrNonAtomicRef.h" |
| 12 |
| 13 #include "GrRenderTarget.h" |
| 14 |
| 15 class GrDrawTarget; |
| 16 |
| 17 #define GRDRAW_ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fC
ontext) |
| 18 |
| 19 /* |
| 20 * GrDraw is a base class which captures the scope of the entry point on SkGpuDe
vice where it |
| 21 * originates. The purpose of a GrDraw is to encapsulate a set of decisions abo
ut the type of |
| 22 * GrBatch Ganesh will create for a given primitive. It is also responsible for
transforming the |
| 23 * SkPaint. A GrDraw should also leave some kind of GrDrawSnap on the GrBatch i
t creates, as a way |
| 24 * for it to fastpath drawing decisions. In the fastpath case, a GrDraw should
batch draw calls |
| 25 * without transforming the SkPaint, by directly pushing new geometry onto exist
ing GrBatches |
| 26 * |
| 27 * A GrDraw must be able to fully draw itself if fastpath batching is not possib
le. |
| 28 * |
| 29 * The only reason this base class exists is so that all GrDraw's have separate
class IDs |
| 30 */ |
| 31 |
| 32 class GrDraw { |
| 33 public: |
| 34 // Each derived class must have a unique class id. This is achieved by provi
ding each |
| 35 // derived class with a templatized version of ClassID() which uses the GrDr
aw-global |
| 36 // gCurrDrawClassID counter. |
| 37 template <typename PROC_SUBCLASS> static uint32_t ClassID() { |
| 38 static uint32_t kClassID = GenID(&gCurrDrawClassID); |
| 39 return kClassID; |
| 40 } |
| 41 |
| 42 protected: |
| 43 static uint32_t GenID(int32_t* idCounter) { |
| 44 // The atomic inc returns the old value not the incremented value. So we
add |
| 45 // 1 to the returned value. |
| 46 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; |
| 47 if (!id) { |
| 48 SkFAIL("This should never wrap as it should only be called once for
each GrDraw " |
| 49 "subclass."); |
| 50 } |
| 51 return id; |
| 52 } |
| 53 |
| 54 enum { |
| 55 kIllegalDrawClassID = 0 |
| 56 }; |
| 57 |
| 58 static int32_t gCurrDrawClassID; |
| 59 |
| 60 friend class GrDrawSnap; // for class ID stuff |
| 61 }; |
| 62 |
| 63 /* |
| 64 * A GrDrawSnap is the marker a GrDraw can use to determine whether or not it ca
n take a fastpath. |
| 65 * After creation, a GrDrawSnap subclass will live directly on a GrBatch |
| 66 */ |
| 67 class GrDrawSnap : public GrNonAtomicRef { |
| 68 public: |
| 69 GrDrawSnap() : fClassID(GrDraw::kIllegalDrawClassID) {} |
| 70 uint32_t classID() const { |
| 71 SkASSERT(fClassID != GrDraw::kIllegalDrawClassID); |
| 72 return fClassID; |
| 73 } |
| 74 |
| 75 protected: |
| 76 uint32_t fClassID; |
| 77 typedef GrNonAtomicRef INHERITED; |
| 78 }; |
| 79 |
| 80 #endif |
OLD | NEW |