OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrLayerCache_DEFINED | 8 #ifndef GrLayerCache_DEFINED |
9 #define GrLayerCache_DEFINED | 9 #define GrLayerCache_DEFINED |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 struct Key { | 79 struct Key { |
80 Key(uint32_t pictureID, const SkMatrix& initialMat, | 80 Key(uint32_t pictureID, const SkMatrix& initialMat, |
81 const int* key, int keySize, bool copyKey = false) | 81 const int* key, int keySize, bool copyKey = false) |
82 : fKeySize(keySize) | 82 : fKeySize(keySize) |
83 , fFreeKey(copyKey) { | 83 , fFreeKey(copyKey) { |
84 fIDMatrix.fPictureID = pictureID; | 84 fIDMatrix.fPictureID = pictureID; |
85 fIDMatrix.fInitialMat = initialMat; | 85 fIDMatrix.fInitialMat = initialMat; |
86 fIDMatrix.fInitialMat.getType(); // force initialization of type so
hashes match | 86 fIDMatrix.fInitialMat.getType(); // force initialization of type so
hashes match |
87 | 87 |
88 if (copyKey) { | 88 if (copyKey) { |
89 int* tempKey = SkNEW_ARRAY(int, keySize); | 89 int* tempKey = new int[keySize]; |
90 memcpy(tempKey, key, keySize*sizeof(int)); | 90 memcpy(tempKey, key, keySize*sizeof(int)); |
91 fKey = tempKey; | 91 fKey = tempKey; |
92 } else { | 92 } else { |
93 fKey = key; | 93 fKey = key; |
94 } | 94 } |
95 | 95 |
96 // The pictureID/matrix portion needs to be tightly packed. | 96 // The pictureID/matrix portion needs to be tightly packed. |
97 GR_STATIC_ASSERT(sizeof(IDMatrix) == sizeof(uint32_t)+
// pictureID | 97 GR_STATIC_ASSERT(sizeof(IDMatrix) == sizeof(uint32_t)+
// pictureID |
98 9 * sizeof(SkScalar) + sizeof(uint3
2_t)); // matrix | 98 9 * sizeof(SkScalar) + sizeof(uint3
2_t)); // matrix |
99 } | 99 } |
100 | 100 |
101 ~Key() { | 101 ~Key() { |
102 if (fFreeKey) { | 102 if (fFreeKey) { |
103 SkDELETE_ARRAY(fKey); | 103 delete[] fKey; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 bool operator==(const Key& other) const { | 107 bool operator==(const Key& other) const { |
108 if (fKeySize != other.fKeySize) { | 108 if (fKeySize != other.fKeySize) { |
109 return false; | 109 return false; |
110 } | 110 } |
111 return fIDMatrix.fPictureID == other.fIDMatrix.fPictureID && | 111 return fIDMatrix.fPictureID == other.fIDMatrix.fPictureID && |
112 fIDMatrix.fInitialMat.cheapEqualTo(other.fIDMatrix.fInitialMa
t) && | 112 fIDMatrix.fInitialMat.cheapEqualTo(other.fIDMatrix.fInitialMa
t) && |
113 !memcmp(fKey, other.fKey, fKeySize * sizeof(int)); | 113 !memcmp(fKey, other.fKey, fKeySize * sizeof(int)); |
(...skipping 22 matching lines...) Expand all Loading... |
136 | 136 |
137 const int* fKey; | 137 const int* fKey; |
138 const int fKeySize; | 138 const int fKeySize; |
139 bool fFreeKey; | 139 bool fFreeKey; |
140 }; | 140 }; |
141 | 141 |
142 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } | 142 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } |
143 static uint32_t Hash(const Key& key) { return key.hash(); } | 143 static uint32_t Hash(const Key& key) { return key.hash(); } |
144 | 144 |
145 // GrCachedLayer proper | 145 // GrCachedLayer proper |
146 GrCachedLayer(uint32_t pictureID, int start, int stop, | 146 GrCachedLayer(uint32_t pictureID, |
147 const SkIRect& srcIR, const SkIRect& dstIR, | 147 int start, |
| 148 int stop, |
| 149 const SkIRect& srcIR, |
| 150 const SkIRect& dstIR, |
148 const SkMatrix& ctm, | 151 const SkMatrix& ctm, |
149 const int* key, int keySize, | 152 const int* key, |
| 153 int keySize, |
150 const SkPaint* paint) | 154 const SkPaint* paint) |
151 : fKey(pictureID, ctm, key, keySize, true) | 155 : fKey(pictureID, ctm, key, keySize, true) |
152 , fStart(start) | 156 , fStart(start) |
153 , fStop(stop) | 157 , fStop(stop) |
154 , fSrcIR(srcIR) | 158 , fSrcIR(srcIR) |
155 , fDstIR(dstIR) | 159 , fDstIR(dstIR) |
156 , fOffset(SkIPoint::Make(0, 0)) | 160 , fOffset(SkIPoint::Make(0, 0)) |
157 , fPaint(paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL) | 161 , fPaint(paint ? new SkPaint(*paint) : NULL) |
158 , fFilter(NULL) | 162 , fFilter(NULL) |
159 , fTexture(NULL) | 163 , fTexture(NULL) |
160 , fRect(SkIRect::MakeEmpty()) | 164 , fRect(SkIRect::MakeEmpty()) |
161 , fPlot(NULL) | 165 , fPlot(NULL) |
162 , fUses(0) | 166 , fUses(0) |
163 , fLocked(false) { | 167 , fLocked(false) { |
164 SkASSERT(SK_InvalidGenID != pictureID); | 168 SkASSERT(SK_InvalidGenID != pictureID); |
165 | 169 |
166 if (fPaint) { | 170 if (fPaint) { |
167 if (fPaint->getImageFilter()) { | 171 if (fPaint->getImageFilter()) { |
168 fFilter = SkSafeRef(fPaint->getImageFilter()); | 172 fFilter = SkSafeRef(fPaint->getImageFilter()); |
169 fPaint->setImageFilter(NULL); | 173 fPaint->setImageFilter(NULL); |
170 } | 174 } |
171 } | 175 } |
172 } | 176 } |
173 | 177 |
174 ~GrCachedLayer() { | 178 ~GrCachedLayer() { |
175 SkSafeUnref(fTexture); | 179 SkSafeUnref(fTexture); |
176 SkSafeUnref(fFilter); | 180 SkSafeUnref(fFilter); |
177 SkDELETE(fPaint); | 181 delete fPaint; |
178 } | 182 } |
179 | 183 |
180 uint32_t pictureID() const { return fKey.pictureID(); } | 184 uint32_t pictureID() const { return fKey.pictureID(); } |
181 // TODO: remove these when GrCachedLayer & ReplacementInfo fuse | 185 // TODO: remove these when GrCachedLayer & ReplacementInfo fuse |
182 const int* key() const { return fKey.key(); } | 186 const int* key() const { return fKey.key(); } |
183 int keySize() const { return fKey.keySize(); } | 187 int keySize() const { return fKey.keySize(); } |
184 | 188 |
185 int start() const { return fStart; } | 189 int start() const { return fStart; } |
186 // TODO: make bound debug only | 190 // TODO: make bound debug only |
187 const SkIRect& srcIR() const { return fSrcIR; } | 191 const SkIRect& srcIR() const { return fSrcIR; } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 SkASSERT(fPlotLocks[plotIdx] > 0); | 402 SkASSERT(fPlotLocks[plotIdx] > 0); |
399 --fPlotLocks[plotIdx]; | 403 --fPlotLocks[plotIdx]; |
400 } | 404 } |
401 | 405 |
402 // for testing | 406 // for testing |
403 friend class TestingAccess; | 407 friend class TestingAccess; |
404 int numLayers() const { return fLayerHash.count(); } | 408 int numLayers() const { return fLayerHash.count(); } |
405 }; | 409 }; |
406 | 410 |
407 #endif | 411 #endif |
OLD | NEW |