Add support for tagging GrUniqueKeys with a debug string
Change-Id: Ie7d56214fdee7a19a1e8ca3869e5e4d5e72cedf8
Reviewed-on: https://skia-review.googlesource.com/6632
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/include/gpu/GrResourceKey.h b/include/gpu/GrResourceKey.h
index 0ead35e..8ba1140 100644
--- a/include/gpu/GrResourceKey.h
+++ b/include/gpu/GrResourceKey.h
@@ -9,10 +9,11 @@
#ifndef GrResourceKey_DEFINED
#define GrResourceKey_DEFINED
+#include "../private/SkOnce.h"
#include "../private/SkTemplates.h"
#include "GrTypes.h"
#include "SkData.h"
-#include "../private/SkOnce.h"
+#include "SkString.h"
uint32_t GrResourceKeyHash(const uint32_t* data, size_t size);
@@ -239,6 +240,7 @@
GrUniqueKey& operator=(const GrUniqueKey& that) {
this->INHERITED::operator=(that);
this->setCustomData(sk_ref_sp(that.getCustomData()));
+ SkDEBUGCODE(fTag = that.fTag;)
return *this;
}
@@ -254,21 +256,28 @@
return fData.get();
}
+ SkDEBUGCODE(const char* tag() const { return fTag.c_str(); })
+
class Builder : public INHERITED::Builder {
public:
- Builder(GrUniqueKey* key, Domain domain, int data32Count)
- : INHERITED::Builder(key, domain, data32Count) {}
+ Builder(GrUniqueKey* key, Domain type, int data32Count, const char* tag = nullptr)
+ : INHERITED::Builder(key, type, data32Count) {
+ SkDEBUGCODE(key->fTag = tag;)
+ (void) tag; // suppress unused named param warning.
+ }
/** Used to build a key that wraps another key and adds additional data. */
- Builder(GrUniqueKey* key, const GrUniqueKey& innerKey, Domain domain,
- int extraData32Cnt)
- : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + extraData32Cnt) {
+ Builder(GrUniqueKey* key, const GrUniqueKey& innerKey, Domain domain, int extraData32Cnt,
+ const char* tag = nullptr)
+ : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + extraData32Cnt) {
SkASSERT(&innerKey != key);
// add the inner key to the end of the key so that op[] can be indexed normally.
uint32_t* innerKeyData = &this->operator[](extraData32Cnt);
const uint32_t* srcData = innerKey.data();
(*innerKeyData++) = innerKey.domain();
memcpy(innerKeyData, srcData, innerKey.dataSize());
+ SkDEBUGCODE(key->fTag = tag;)
+ (void) tag; // suppress unused named param warning.
}
private:
@@ -280,6 +289,7 @@
private:
sk_sp<SkData> fData;
+ SkDEBUGCODE(SkString fTag;)
};
/**