Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: include/gpu/GrResourceKey.h

Issue 879193002: Fix wrapped content keys for npot textures. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix warning Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
};
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698