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

Unified Diff: src/gpu/GrRecordReplaceDraw.h

Issue 753253002: Use variable length key (rather than accumulated matrix) as save layer hoisting key (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more cleanup Created 6 years 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
Index: src/gpu/GrRecordReplaceDraw.h
diff --git a/src/gpu/GrRecordReplaceDraw.h b/src/gpu/GrRecordReplaceDraw.h
index fabeec1020ad785cc40dfc51f3a2a1df9917dfdd..538661a7b4afad42fd7e14a9dd5d8e3a6c3067f0 100644
--- a/src/gpu/GrRecordReplaceDraw.h
+++ b/src/gpu/GrRecordReplaceDraw.h
@@ -32,48 +32,70 @@ public:
class ReplacementInfo {
public:
struct Key {
- Key(uint32_t pictureID, unsigned start, const SkMatrix& ctm)
- : fPictureID(pictureID)
- , fStart(start)
- , fCTM(ctm) {
- fCTM.getType(); // force initialization of type so hashes match
-
- // Key needs to be tightly packed.
- GR_STATIC_ASSERT(sizeof(Key) == sizeof(uint32_t) + // picture ID
- sizeof(int) + // start
- 9 * sizeof(SkScalar) // 3x3 from CTM
- +sizeof(uint32_t)); // matrix's type
+ Key(uint32_t pictureID, const SkMatrix& initialMat,
+ const int* key, int keySize, bool copyKey = false)
+ : fKeySize(keySize)
+ , fFreeKey(copyKey) {
+ fIDMatrix.fPictureID = pictureID;
+ fIDMatrix.fInitialMat = initialMat;
+ fIDMatrix.fInitialMat.getType(); // force initialization of type so hashes match
+
+ if (copyKey) {
+ int* tempKey = SkNEW_ARRAY(int, keySize);
+ memcpy(tempKey, key, keySize * sizeof(int));
+ fKey = tempKey;
+ } else {
+ fKey = key;
+ }
+
+ // The pictureID/matrix portion needs to be tightly packed.
+ GR_STATIC_ASSERT(sizeof(IDMatrix) == sizeof(uint32_t)+ // pictureID
+ 9 * sizeof(SkScalar)+sizeof(uint32_t)); // matrix
}
- bool operator==(const Key& other) const {
- return fPictureID == other.fPictureID &&
- fStart == other.fStart &&
- fCTM.cheapEqualTo(other.fCTM); // TODO: should be fuzzy
+ ~Key() {
+ if (fFreeKey) {
+ SkDELETE_ARRAY(fKey);
+ }
+ }
+ bool operator==(const Key& other) const {
+ if (fKeySize != other.fKeySize) {
+ return false;
+ }
+ return fIDMatrix.fPictureID == other.fIDMatrix.fPictureID &&
+ fIDMatrix.fInitialMat.cheapEqualTo(other.fIDMatrix.fInitialMat) &&
+ !memcmp(fKey, other.fKey, fKeySize * sizeof(int));
}
- uint32_t pictureID() const { return fPictureID; }
- unsigned int start() const { return fStart; }
+ uint32_t hash() const {
+ uint32_t hash = SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(fKey),
+ fKeySize * sizeof(int));
+ return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&fIDMatrix),
+ sizeof(IDMatrix), hash);
+ }
private:
- const uint32_t fPictureID;
- const unsigned fStart;
- const SkMatrix fCTM;
+ struct IDMatrix {
+ uint32_t fPictureID;
+ SkMatrix fInitialMat;
+ } fIDMatrix;
+
+ const int* fKey;
+ const int fKeySize;
+ const bool fFreeKey;
};
static const Key& GetKey(const ReplacementInfo& layer) { return layer.fKey; }
- static uint32_t Hash(const Key& key) {
- return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
- }
+ static uint32_t Hash(const Key& key) { return key.hash(); }
- ReplacementInfo(uint32_t pictureID, unsigned int start, const SkMatrix& ctm)
- : fKey(pictureID, start, ctm)
+ ReplacementInfo(uint32_t pictureID, const SkMatrix& initialMat,
+ const int* key, int keySize)
+ : fKey(pictureID, initialMat, key, keySize, true)
, fImage(NULL)
, fPaint(NULL) {
}
~ReplacementInfo() { fImage->unref(); SkDELETE(fPaint); }
- unsigned int start() const { return fKey.start(); }
-
const Key fKey;
unsigned fStop;
SkIPoint fPos;
@@ -86,12 +108,11 @@ public:
~GrReplacements() { this->freeAll(); }
// Add a new replacement range.
- ReplacementInfo* newReplacement(uint32_t pictureID, unsigned start, const SkMatrix& ctm);
+ ReplacementInfo* newReplacement(uint32_t pictureID, const SkMatrix& initialMat,
+ const int* key, int keySize);
- // look up a replacement range by its pictureID, start offset and the CTM
- // TODO: also need to add clip to lookup
- const ReplacementInfo* lookupByStart(uint32_t pictureID, unsigned start,
- const SkMatrix& ctm) const;
+ const ReplacementInfo* lookup(uint32_t pictureID, const SkMatrix& initalMat,
+ const int* key, int keySize) const;
private:
SkTDynamicHash<ReplacementInfo, ReplacementInfo::Key> fReplacementHash;

Powered by Google App Engine
This is Rietveld 408576698