Index: src/gpu/draws/GrDraw.h |
diff --git a/src/gpu/draws/GrDraw.h b/src/gpu/draws/GrDraw.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aaadeb4d43f491912630274e9396542c43bb2542 |
--- /dev/null |
+++ b/src/gpu/draws/GrDraw.h |
@@ -0,0 +1,74 @@ |
+/* |
+ * Copyright 2015 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef GrDraw_DEFINED |
+#define GrDraw_DEFINED |
+ |
+#include "GrNonAtomicRef.h" |
+ |
+#include "GrRenderTarget.h" |
+ |
+class GrDrawTarget; |
+ |
+#define GRDRAW_ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) |
+ |
+/* |
+ * GrDraw is a virtual class which captures the scope of the entry point on SkGpuDevice where it |
+ * originates. After creation, it lives on the GrPipeline where it used as a potential fast path |
+ * for batching. |
+ * |
+ * A GrDraw must be able to fully draw itself if fastpath batching is not possible |
+ */ |
+ |
+class GrDraw { |
+public: |
+ GrDraw() : fClassID(kIllegalDrawClassID) {} |
+ virtual ~GrDraw() {} |
+ |
+ virtual void execute(GrDrawTarget*) const=0; |
+ uint32_t classID() const { SkASSERT(!fClassID == kIllegalDrawClassID); return fClassID; } |
+ template <typename PROC_SUBCLASS> static uint32_t ClassID() { |
+ static uint32_t kClassID = GenID(&gCurrDrawClassID); |
+ return kClassID; |
+ } |
+ |
+protected: |
+ static uint32_t GenID(int32_t* idCounter) { |
+ // The atomic inc returns the old value not the incremented value. So we add |
+ // 1 to the returned value. |
+ uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; |
+ if (!id) { |
+ SkFAIL("This should never wrap as it should only be called once for each GrDraw " |
+ "subclass."); |
+ } |
+ return id; |
+ } |
+ |
+ enum { |
+ kIllegalDrawClassID = 0 |
+ }; |
+ |
+ static int32_t gCurrDrawClassID; |
+ uint32_t fClassID; |
+ |
+ friend class GrDrawSnap; // for class ID stuff |
+}; |
+ |
+class GrDrawSnap : public GrNonAtomicRef { |
+public: |
+ GrDrawSnap() : fClassID(GrDraw::kIllegalDrawClassID) {} |
+ uint32_t classID() const { |
+ SkASSERT(!fClassID == GrDraw::kIllegalDrawClassID); |
+ return fClassID; |
+ } |
+ |
+protected: |
+ uint32_t fClassID; |
+ typedef GrNonAtomicRef INHERITED; |
+}; |
+ |
+#endif |