aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrXferProcessor.h
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-01-07 09:37:13 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-09 15:44:53 +0000
commita8f80de2bc17672b4b6f26d3cf6b38123ac850c9 (patch)
treeae254be1a14e5ccaf0e0d8deffc43eff2983b923 /include/gpu/GrXferProcessor.h
parentc083e4f586831459ef7b8e197a5bee3b189b8511 (diff)
Removing ref counting from GrXPFactory.
All GrXPFactory instances are static constexpr. Change-Id: If1086b08534166201e53b3fd9379104e361eb5e6 Reviewed-on: https://skia-review.googlesource.com/6701 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'include/gpu/GrXferProcessor.h')
-rw-r--r--include/gpu/GrXferProcessor.h64
1 files changed, 20 insertions, 44 deletions
diff --git a/include/gpu/GrXferProcessor.h b/include/gpu/GrXferProcessor.h
index e97c0b92c7..17cd2c7bf3 100644
--- a/include/gpu/GrXferProcessor.h
+++ b/include/gpu/GrXferProcessor.h
@@ -289,8 +289,22 @@ GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags);
* Before the XP is created, the XPF is able to answer queries about what functionality the XPs it
* creates will have. For example, can it create an XP that supports RGB coverage or will the XP
* blend with the destination color.
+ *
+ * GrXPFactories are intended to be static immutable objects. We pass them around as raw pointers
+ * and expect the pointers to always be valid and for the factories to be reusable and thread safe.
+ * Equality is tested for using pointer comparison. GrXPFactory destructors must be no-ops.
*/
-class GrXPFactory : public SkRefCnt {
+
+// In order to construct GrXPFactory subclass instances as constexpr the subclass, and therefore
+// GrXPFactory, must be a literal type. One requirement is having a trivial destructor. This is ok
+// since these objects have no need for destructors. However, GCC and clang throw a warning when a
+// class has virtual functions and a non-virtual destructor. We suppress that warning here and
+// for the subclasses.
+#if defined(__GNUC__) || defined(__clang)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+class GrXPFactory {
public:
typedef GrXferProcessor::DstTexture DstTexture;
GrXferProcessor* createXferProcessor(const GrPipelineAnalysis&,
@@ -317,29 +331,8 @@ public:
bool willNeedDstTexture(const GrCaps& caps, const GrPipelineAnalysis&) const;
- bool isEqual(const GrXPFactory& that) const {
- if (this->classID() != that.classID()) {
- return false;
- }
- return this->onIsEqual(that);
- }
-
- /**
- * Helper for down-casting to a GrXPFactory subclass
- */
- template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
-
- uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return fClassID; }
-
protected:
- GrXPFactory() : fClassID(kIllegalXPFClassID) {}
-
- template <typename XPF_SUBCLASS> void initClassID() {
- static uint32_t kClassID = GenClassID();
- fClassID = kClassID;
- }
-
- uint32_t fClassID;
+ constexpr GrXPFactory() {}
private:
virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
@@ -347,34 +340,17 @@ private:
bool hasMixedSamples,
const DstTexture*) const = 0;
- virtual bool onIsEqual(const GrXPFactory&) const = 0;
-
bool willReadDstColor(const GrCaps&, const GrPipelineAnalysis&) const;
+
/**
* Returns true if the XP generated by this factory will explicitly read dst in the fragment
* shader.
*/
virtual bool onWillReadDstColor(const GrCaps&, const GrPipelineAnalysis&) const = 0;
-
- static uint32_t GenClassID() {
- // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. 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(&gCurrXPFClassID)) + 1;
- if (!id) {
- SkFAIL("This should never wrap as it should only be called once for each GrXPFactory "
- "subclass.");
- }
- return id;
- }
-
- enum {
- kIllegalXPFClassID = 0,
- };
- static int32_t gCurrXPFClassID;
-
- typedef GrProgramElement INHERITED;
};
+#if defined(__GNUC__) || defined(__clang)
+#pragma GCC diagnostic pop
+#endif
#endif