| Index: include/gpu/GrResourceKey.h
|
| diff --git a/include/gpu/GrResourceKey.h b/include/gpu/GrResourceKey.h
|
| index 26373a785963b2c0f8ff212a19f15bb58405a5fb..4c76b68c2d55e7f67a82915ca3ea22e0b7356ac6 100644
|
| --- a/include/gpu/GrResourceKey.h
|
| +++ b/include/gpu/GrResourceKey.h
|
| @@ -23,14 +23,10 @@ public:
|
|
|
| size_t size() const {
|
| this->validate();
|
| + SkASSERT(this->isValid());
|
| return this->internalSize();
|
| }
|
|
|
| - const uint32_t* data() const {
|
| - this->validate();
|
| - return &fKey[kMetaDataCnt];
|
| - }
|
| -
|
| protected:
|
| static const uint32_t kInvalidDomain = 0;
|
|
|
| @@ -63,6 +59,15 @@ protected:
|
|
|
| uint32_t domain() const { return fKey[kDomainAndSize_MetaDataIdx] & 0xffff; }
|
|
|
| + /** size of the key data, excluding meta-data (hash, domain, etc). */
|
| + size_t dataSize() const { return this->size() - 4 * kMetaDataCnt; }
|
| +
|
| + /** ptr to the key data, excluding meta-data (hash, domain, etc). */
|
| + const uint32_t* data() const {
|
| + this->validate();
|
| + return &fKey[kMetaDataCnt];
|
| + }
|
| +
|
| /** Used to initialize a key. */
|
| class Builder {
|
| public:
|
| @@ -101,6 +106,15 @@ protected:
|
| };
|
|
|
| private:
|
| + enum MetaDataIdx {
|
| + kHash_MetaDataIdx,
|
| + // The key domain and size are packed into a single uint32_t.
|
| + kDomainAndSize_MetaDataIdx,
|
| +
|
| + kLastMetaDataIdx = kDomainAndSize_MetaDataIdx
|
| + };
|
| + static const uint32_t kMetaDataCnt = kLastMetaDataIdx + 1;
|
| +
|
| size_t internalSize() const {
|
| return fKey[kDomainAndSize_MetaDataIdx] >> 16;
|
| }
|
| @@ -109,17 +123,9 @@ private:
|
| SkASSERT(fKey[kHash_MetaDataIdx] ==
|
| GrResourceKeyHash(&fKey[kHash_MetaDataIdx] + 1,
|
| this->internalSize() - sizeof(uint32_t)));
|
| + SkASSERT(SkIsAlign4(this->internalSize()));
|
| }
|
|
|
| - enum MetaDataIdx {
|
| - kHash_MetaDataIdx,
|
| - // The key domain and size are packed into a single uint32_t.
|
| - kDomainAndSize_MetaDataIdx,
|
| -
|
| - kLastMetaDataIdx = kDomainAndSize_MetaDataIdx
|
| - };
|
| - static const uint32_t kMetaDataCnt = kLastMetaDataIdx + 1;
|
| -
|
| friend class TestResource; // For unit test to access kMetaDataCnt.
|
|
|
| // bmp textures require 4 uint32_t values.
|
| @@ -213,12 +219,18 @@ public:
|
| /** Used to build a key that wraps another key and adds additional data. */
|
| Builder(GrContentKey* key, const GrContentKey& innerKey, Domain domain,
|
| int extraData32Cnt)
|
| - : INHERITED::Builder(key, domain, (SkToInt(innerKey.size()) >> 2) + extraData32Cnt) {
|
| - int innerKeyCnt = SkToInt(innerKey.size()) >> 2;
|
| + : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + extraData32Cnt) {
|
| // add the inner key to the end of the key so that op[] can be indexed normally.
|
| - for (int i = 0; i < innerKeyCnt; ++i) {
|
| - this->operator[](extraData32Cnt + i) = innerKey.data()[i];
|
| - }
|
| + uint32_t* innerKeyData = &this->operator[](extraData32Cnt);
|
| + const uint32_t* srcData = innerKey.data();
|
| + (*innerKeyData++) = innerKey.domain();
|
| + memcpy(innerKeyData, srcData, innerKey.dataSize());
|
| + }
|
| +
|
| + private:
|
| + static int Data32CntForInnerKey(const GrContentKey& innerKey) {
|
| + // key data + domain
|
| + return SkToInt((innerKey.dataSize() >> 2) + 1);
|
| }
|
| };
|
| };
|
|
|