robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrLayerCache_DEFINED |
| 9 | #define GrLayerCache_DEFINED |
| 10 | |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 11 | #include "GrAtlas.h" |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 12 | #include "GrPictureUtils.h" |
| 13 | #include "GrRect.h" |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 14 | #include "SkChecksum.h" |
| 15 | #include "SkTDynamicHash.h" |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 16 | #include "SkMessageBus.h" |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 17 | |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 18 | class SkPicture; |
| 19 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 20 | // The layer cache listens for these messages to purge picture-related resources. |
| 21 | struct GrPictureDeletedMessage { |
| 22 | uint32_t pictureID; |
| 23 | }; |
| 24 | |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 25 | // GrPictureInfo stores the atlas plots used by a single picture. A single |
| 26 | // plot may be used to store layers from multiple pictures. |
| 27 | struct GrPictureInfo { |
| 28 | public: |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 29 | // for SkTDynamicHash - just use the pictureID as the hash key |
| 30 | static const uint32_t& GetKey(const GrPictureInfo& pictInfo) { return pictInfo.fPictureID; } |
| 31 | static uint32_t Hash(const uint32_t& key) { return SkChecksum::Mix(key); } |
| 32 | |
| 33 | // GrPictureInfo proper |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 34 | GrPictureInfo(uint32_t pictureID) : fPictureID(pictureID) { } |
| 35 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 36 | const uint32_t fPictureID; |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 37 | |
| 38 | GrAtlas::ClientPlotUsage fPlotUsage; |
| 39 | }; |
| 40 | |
commit-bot@chromium.org | 365cd31 | 2014-04-11 15:53:47 +0000 | [diff] [blame] | 41 | // GrCachedLayer encapsulates the caching information for a single saveLayer. |
| 42 | // |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 43 | // Atlased layers get a ref to the backing GrTexture while non-atlased layers |
| 44 | // get a ref to the GrTexture in which they reside. In both cases 'fRect' |
| 45 | // contains the layer's extent in its texture. |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 46 | // Atlased layers also get a pointer to the plot in which they reside. |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 47 | // For non-atlased layers, the lock field just corresponds to locking in |
| 48 | // the resource cache. For atlased layers, it implements an additional level |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 49 | // of locking to allow atlased layers to be reused multiple times. |
commit-bot@chromium.org | 365cd31 | 2014-04-11 15:53:47 +0000 | [diff] [blame] | 50 | struct GrCachedLayer { |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 51 | public: |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 52 | // For SkTDynamicHash |
| 53 | struct Key { |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 54 | // TODO: the key needs to include the clip |
| 55 | Key(uint32_t pictureID, int start, const SkMatrix& ctm) |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 56 | : fPictureID(pictureID) |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 57 | , fStart(start) { |
| 58 | fCTM[0] = ctm.getScaleX(); |
| 59 | fCTM[1] = ctm.getSkewX(); |
| 60 | fCTM[2] = ctm.getSkewY(); |
| 61 | fCTM[3] = ctm.getScaleY(); |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 62 | // Key needs to be tightly packed. |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 63 | GR_STATIC_ASSERT(sizeof(Key) == sizeof(uint32_t) + // picture ID |
| 64 | sizeof(int) + // start index |
| 65 | 4 * sizeof(SkScalar)); // 2x2 from CTM |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 66 | } |
| 67 | |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 68 | bool operator==(const Key& other) const { |
| 69 | return fPictureID == other.fPictureID && |
| 70 | fStart == other.fStart && |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 71 | 0 == memcmp(fCTM, other.fCTM, sizeof(fCTM)); |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | uint32_t pictureID() const { return fPictureID; } |
| 75 | int start() const { return fStart; } |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | // ID of the picture of which this layer is a part |
| 79 | const uint32_t fPictureID; |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 80 | // The the index of the saveLayer command in the picture |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 81 | const int fStart; |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 82 | // The 2x2 portion of the CTM applied to this layer in the picture |
| 83 | SkScalar fCTM[4]; |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } |
| 87 | static uint32_t Hash(const Key& key) { |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 88 | return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key)); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 89 | } |
| 90 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 91 | // GrCachedLayer proper |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 92 | GrCachedLayer(uint32_t pictureID, int start, int stop, |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 93 | const SkMatrix& ctm, const SkPaint* paint) |
| 94 | : fKey(pictureID, start, ctm) |
| 95 | , fStop(stop) |
robertphillips | a0537de | 2014-09-18 08:01:23 -0700 | [diff] [blame] | 96 | , fPaint(paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL) |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 97 | , fTexture(NULL) |
| 98 | , fRect(GrIRect16::MakeEmpty()) |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 99 | , fPlot(NULL) |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame^] | 100 | , fUses(0) |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 101 | , fLocked(false) { |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 102 | SkASSERT(SK_InvalidGenID != pictureID && start >= 0 && stop >= 0); |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 103 | } |
| 104 | |
robertphillips | ed6f03e | 2014-07-30 07:31:35 -0700 | [diff] [blame] | 105 | ~GrCachedLayer() { |
| 106 | SkSafeUnref(fTexture); |
robertphillips | a0537de | 2014-09-18 08:01:23 -0700 | [diff] [blame] | 107 | SkDELETE(fPaint); |
robertphillips | ed6f03e | 2014-07-30 07:31:35 -0700 | [diff] [blame] | 108 | } |
| 109 | |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 110 | uint32_t pictureID() const { return fKey.pictureID(); } |
| 111 | int start() const { return fKey.start(); } |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 112 | |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 113 | int stop() const { return fStop; } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 114 | void setTexture(GrTexture* texture, const GrIRect16& rect) { |
robertphillips | ed6f03e | 2014-07-30 07:31:35 -0700 | [diff] [blame] | 115 | SkRefCnt_SafeAssign(fTexture, texture); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 116 | fRect = rect; |
commit-bot@chromium.org | 365cd31 | 2014-04-11 15:53:47 +0000 | [diff] [blame] | 117 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 118 | GrTexture* texture() { return fTexture; } |
robertphillips | 4aa6dfc | 2014-09-17 07:50:47 -0700 | [diff] [blame] | 119 | const SkPaint* paint() const { return fPaint; } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 120 | const GrIRect16& rect() const { return fRect; } |
commit-bot@chromium.org | 365cd31 | 2014-04-11 15:53:47 +0000 | [diff] [blame] | 121 | |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 122 | void setPlot(GrPlot* plot) { |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 123 | SkASSERT(NULL == plot || NULL == fPlot); |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 124 | fPlot = plot; |
| 125 | } |
| 126 | GrPlot* plot() { return fPlot; } |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 127 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 128 | bool isAtlased() const { return SkToBool(fPlot); } |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 129 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 130 | void setLocked(bool locked) { fLocked = locked; } |
| 131 | bool locked() const { return fLocked; } |
| 132 | |
| 133 | SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 134 | SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;) |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 135 | |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 136 | private: |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 137 | const Key fKey; |
commit-bot@chromium.org | 365cd31 | 2014-04-11 15:53:47 +0000 | [diff] [blame] | 138 | |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 139 | // The final "restore" operation index of the cached layer |
| 140 | const int fStop; |
| 141 | |
robertphillips | 4aa6dfc | 2014-09-17 07:50:47 -0700 | [diff] [blame] | 142 | // The paint used when dropping the layer down into the owning canvas. |
robertphillips | a0537de | 2014-09-18 08:01:23 -0700 | [diff] [blame] | 143 | // Can be NULL. This class makes a copy for itself. |
robertphillips | 4aa6dfc | 2014-09-17 07:50:47 -0700 | [diff] [blame] | 144 | const SkPaint* fPaint; |
| 145 | |
skia.committer@gmail.com | d942731 | 2014-04-12 03:05:59 +0000 | [diff] [blame] | 146 | // fTexture is a ref on the atlasing texture for atlased layers and a |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 147 | // ref on a GrTexture for non-atlased textures. |
commit-bot@chromium.org | 365cd31 | 2014-04-11 15:53:47 +0000 | [diff] [blame] | 148 | GrTexture* fTexture; |
| 149 | |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 150 | // For both atlased and non-atlased layers 'fRect' contains the bound of |
| 151 | // the layer in whichever texture it resides. It is empty when 'fTexture' |
| 152 | // is NULL. |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 153 | GrIRect16 fRect; |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 154 | |
| 155 | // For atlased layers, fPlot stores the atlas plot in which the layer rests. |
| 156 | // It is always NULL for non-atlased layers. |
| 157 | GrPlot* fPlot; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 158 | |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame^] | 159 | // The number of actively hoisted layers using this cached image (e.g., |
| 160 | // extant GrHoistedLayers pointing at this object). This object will |
| 161 | // be unlocked when the use count reaches 0. |
| 162 | int fUses; |
| 163 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 164 | // For non-atlased layers 'fLocked' should always match "fTexture". |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 165 | // (i.e., if there is a texture it is locked). |
| 166 | // For atlased layers, 'fLocked' is true if the layer is in a plot and |
| 167 | // actively required for rendering. If the layer is in a plot but not |
| 168 | // actively required for rendering, then 'fLocked' is false. If the |
| 169 | // layer isn't in a plot then is can never be locked. |
| 170 | bool fLocked; |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame^] | 171 | |
| 172 | void addUse() { ++fUses; } |
| 173 | void removeUse() { SkASSERT(fUses > 0); --fUses; } |
| 174 | int uses() const { return fUses; } |
| 175 | |
| 176 | friend class GrLayerCache; // for access to usage methods |
| 177 | friend class TestingAccess; // for testing |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | // The GrLayerCache caches pre-computed saveLayers for later rendering. |
commit-bot@chromium.org | 365cd31 | 2014-04-11 15:53:47 +0000 | [diff] [blame] | 181 | // Non-atlased layers are stored in their own GrTexture while the atlased |
| 182 | // layers share a single GrTexture. |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 183 | // Unlike the GrFontCache, the GrTexture atlas only has one GrAtlas (for 8888) |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 184 | // and one GrPlot (for the entire atlas). As such, the GrLayerCache |
| 185 | // roughly combines the functionality of the GrFontCache and GrTextStrike |
| 186 | // classes. |
| 187 | class GrLayerCache { |
| 188 | public: |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 189 | GrLayerCache(GrContext*); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 190 | ~GrLayerCache(); |
| 191 | |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 192 | // As a cache, the GrLayerCache can be ordered to free up all its cached |
| 193 | // elements by the GrContext |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 194 | void freeAll(); |
| 195 | |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 196 | GrCachedLayer* findLayer(uint32_t pictureID, int start, const SkMatrix& ctm); |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 197 | GrCachedLayer* findLayerOrCreate(uint32_t pictureID, |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 198 | int start, int stop, |
robertphillips | 4aa6dfc | 2014-09-17 07:50:47 -0700 | [diff] [blame] | 199 | const SkMatrix& ctm, |
| 200 | const SkPaint* paint); |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 201 | |
| 202 | // Inform the cache that layer's cached image is now required. |
| 203 | // Return true if the layer must be re-rendered. Return false if the |
| 204 | // layer was found in the cache and can be reused. |
| 205 | bool lock(GrCachedLayer* layer, const GrTextureDesc& desc, bool dontAtlas); |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 206 | |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame^] | 207 | // addUse is just here to keep the API symmetric |
| 208 | void addUse(GrCachedLayer* layer) { layer->addUse(); } |
| 209 | void removeUse(GrCachedLayer* layer) { |
| 210 | layer->removeUse(); |
| 211 | if (layer->uses() == 0) { |
| 212 | // If no one cares about the layer allow it to be recycled. |
| 213 | this->unlock(layer); |
| 214 | } |
| 215 | } |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 216 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 217 | // Setup to be notified when 'picture' is deleted |
| 218 | void trackPicture(const SkPicture* picture); |
| 219 | |
| 220 | // Cleanup after any SkPicture deletions |
| 221 | void processDeletedPictures(); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 222 | |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 223 | SkDEBUGCODE(void validate() const;) |
| 224 | |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 225 | private: |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 226 | static const int kAtlasTextureWidth = 1024; |
| 227 | static const int kAtlasTextureHeight = 1024; |
| 228 | |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 229 | static const int kNumPlotsX = 2; |
| 230 | static const int kNumPlotsY = 2; |
| 231 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 232 | static const int kPlotWidth = kAtlasTextureWidth / kNumPlotsX; |
| 233 | static const int kPlotHeight = kAtlasTextureHeight / kNumPlotsY; |
| 234 | |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 235 | GrContext* fContext; // pointer back to owning context |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 236 | SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 237 | |
| 238 | // We cache this information here (rather then, say, on the owning picture) |
| 239 | // because we want to be able to clean it up as needed (e.g., if a picture |
| 240 | // is leaked and never cleans itself up we still want to be able to |
| 241 | // remove the GrPictureInfo once its layers are purged from all the atlas |
| 242 | // plots). |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 243 | SkTDynamicHash<GrPictureInfo, uint32_t> fPictureHash; |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 244 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 245 | SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key> fLayerHash; |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 246 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 247 | SkMessageBus<GrPictureDeletedMessage>::Inbox fPictDeletionInbox; |
| 248 | |
| 249 | SkAutoTUnref<SkPicture::DeletionListener> fDeletionListener; |
| 250 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 251 | // This implements a plot-centric locking mechanism (since the atlas |
| 252 | // backing texture is always locked). Each layer that is locked (i.e., |
| 253 | // needed for the current rendering) in a plot increments the plot lock |
robertphillips | a32c6bc | 2014-10-09 12:47:01 -0700 | [diff] [blame] | 254 | // count for that plot. Similarly, once a rendering is complete all the |
| 255 | // layers used in it decrement the lock count for the used plots. |
| 256 | // Plots with a 0 lock count are open for recycling/purging. |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 257 | int fPlotLocks[kNumPlotsX * kNumPlotsY]; |
| 258 | |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame^] | 259 | // Inform the cache that layer's cached image is not currently required |
| 260 | void unlock(GrCachedLayer* layer); |
| 261 | |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 262 | void initAtlas(); |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 263 | GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop, |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 264 | const SkMatrix& ctm, const SkPaint* paint); |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 265 | |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 266 | void purgeAll(); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 267 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 268 | // Remove all the layers (and unlock any resources) associated with 'pictureID' |
| 269 | void purge(uint32_t pictureID); |
| 270 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 271 | static bool PlausiblyAtlasable(int width, int height) { |
| 272 | return width <= kPlotWidth && height <= kPlotHeight; |
| 273 | } |
| 274 | |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 275 | void purgePlot(GrPlot* plot); |
| 276 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 277 | // Try to find a purgeable plot and clear it out. Return true if a plot |
| 278 | // was purged; false otherwise. |
| 279 | bool purgePlot(); |
| 280 | |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame^] | 281 | void incPlotLock(int plotIdx) { ++fPlotLocks[plotIdx]; } |
| 282 | void decPlotLock(int plotIdx) { |
| 283 | SkASSERT(fPlotLocks[plotIdx] > 0); |
| 284 | --fPlotLocks[plotIdx]; |
| 285 | } |
| 286 | |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 287 | // for testing |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 288 | friend class TestingAccess; |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 289 | int numLayers() const { return fLayerHash.count(); } |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | #endif |