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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } | 94 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } |
95 static uint32_t Hash(const Key& key) { | 95 static uint32_t Hash(const Key& key) { |
96 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), size
of(Key)); | 96 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), size
of(Key)); |
97 } | 97 } |
98 | 98 |
99 // GrCachedLayer proper | 99 // GrCachedLayer proper |
100 GrCachedLayer(uint32_t pictureID, int start, int stop, | 100 GrCachedLayer(uint32_t pictureID, int start, int stop, |
101 const SkIPoint& offset, const SkMatrix& ctm, | 101 const SkIPoint& offset, const SkMatrix& ctm, |
102 const SkPaint* paint) | 102 const SkPaint* paint) |
103 : fKey(pictureID, start, stop, offset, ctm) | 103 : fKey(pictureID, start, stop, offset, ctm) |
104 , fPaint(paint) | 104 , fPaint(paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL) |
105 , fTexture(NULL) | 105 , fTexture(NULL) |
106 , fRect(GrIRect16::MakeEmpty()) | 106 , fRect(GrIRect16::MakeEmpty()) |
107 , fPlot(NULL) | 107 , fPlot(NULL) |
108 , fLocked(false) { | 108 , fLocked(false) { |
109 SkASSERT(SK_InvalidGenID != pictureID && start >= 0 && stop >= 0); | 109 SkASSERT(SK_InvalidGenID != pictureID && start >= 0 && stop >= 0); |
110 } | 110 } |
111 | 111 |
112 ~GrCachedLayer() { | 112 ~GrCachedLayer() { |
113 SkSafeUnref(fTexture); | 113 SkSafeUnref(fTexture); |
| 114 SkDELETE(fPaint); |
114 } | 115 } |
115 | 116 |
116 uint32_t pictureID() const { return fKey.pictureID(); } | 117 uint32_t pictureID() const { return fKey.pictureID(); } |
117 int start() const { return fKey.start(); } | 118 int start() const { return fKey.start(); } |
118 int stop() const { return fKey.stop(); } | 119 int stop() const { return fKey.stop(); } |
119 const SkIPoint& offset() const { return fKey.offset(); } | 120 const SkIPoint& offset() const { return fKey.offset(); } |
120 const SkMatrix& ctm() const { return fKey.ctm(); } | 121 const SkMatrix& ctm() const { return fKey.ctm(); } |
121 | 122 |
122 void setTexture(GrTexture* texture, const GrIRect16& rect) { | 123 void setTexture(GrTexture* texture, const GrIRect16& rect) { |
123 SkRefCnt_SafeAssign(fTexture, texture); | 124 SkRefCnt_SafeAssign(fTexture, texture); |
(...skipping 14 matching lines...) Expand all Loading... |
138 void setLocked(bool locked) { fLocked = locked; } | 139 void setLocked(bool locked) { fLocked = locked; } |
139 bool locked() const { return fLocked; } | 140 bool locked() const { return fLocked; } |
140 | 141 |
141 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) | 142 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) |
142 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;) | 143 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;) |
143 | 144 |
144 private: | 145 private: |
145 const Key fKey; | 146 const Key fKey; |
146 | 147 |
147 // The paint used when dropping the layer down into the owning canvas. | 148 // The paint used when dropping the layer down into the owning canvas. |
148 // Can be NULL. | 149 // Can be NULL. This class makes a copy for itself. |
149 const SkPaint* fPaint; | 150 const SkPaint* fPaint; |
150 | 151 |
151 // fTexture is a ref on the atlasing texture for atlased layers and a | 152 // fTexture is a ref on the atlasing texture for atlased layers and a |
152 // ref on a GrTexture for non-atlased textures. | 153 // ref on a GrTexture for non-atlased textures. |
153 GrTexture* fTexture; | 154 GrTexture* fTexture; |
154 | 155 |
155 // For both atlased and non-atlased layers 'fRect' contains the bound of | 156 // For both atlased and non-atlased layers 'fRect' contains the bound of |
156 // the layer in whichever texture it resides. It is empty when 'fTexture' | 157 // the layer in whichever texture it resides. It is empty when 'fTexture' |
157 // is NULL. | 158 // is NULL. |
158 GrIRect16 fRect; | 159 GrIRect16 fRect; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // Try to find a purgeable plot and clear it out. Return true if a plot | 264 // Try to find a purgeable plot and clear it out. Return true if a plot |
264 // was purged; false otherwise. | 265 // was purged; false otherwise. |
265 bool purgePlot(); | 266 bool purgePlot(); |
266 | 267 |
267 // for testing | 268 // for testing |
268 friend class TestingAccess; | 269 friend class TestingAccess; |
269 int numLayers() const { return fLayerHash.count(); } | 270 int numLayers() const { return fLayerHash.count(); } |
270 }; | 271 }; |
271 | 272 |
272 #endif | 273 #endif |
OLD | NEW |