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 | #include "GrAtlas.h" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 9 | #include "GrContext.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 10 | #include "GrDrawContext.h" |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 11 | #include "GrGpu.h" |
| 12 | #include "GrLayerCache.h" |
robertphillips | 84ac082 | 2014-10-14 07:07:59 -0700 | [diff] [blame] | 13 | #include "GrSurfacePriv.h" |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 14 | |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 15 | #ifdef SK_DEBUG |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 16 | void GrCachedLayer::validate(const GrTexture* backingTexture) const { |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 17 | SkASSERT(SK_InvalidGenID != fKey.pictureID()); |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 18 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 19 | if (fTexture) { |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 20 | // If the layer is in some texture then it must occupy some rectangle |
| 21 | SkASSERT(!fRect.isEmpty()); |
| 22 | if (!this->isAtlased()) { |
| 23 | // If it isn't atlased then the rectangle should start at the origin |
| 24 | SkASSERT(0.0f == fRect.fLeft && 0.0f == fRect.fTop); |
| 25 | } |
| 26 | } else { |
| 27 | SkASSERT(fRect.isEmpty()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 28 | SkASSERT(nullptr == fPlot); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 29 | SkASSERT(!fLocked); // layers without a texture cannot be locked |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 30 | } |
| 31 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 32 | if (fPlot) { |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 33 | // If a layer has a plot (i.e., is atlased) then it must point to |
| 34 | // the backing texture. Additionally, its rect should be non-empty. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 35 | SkASSERT(fTexture && backingTexture == fTexture); |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 36 | SkASSERT(!fRect.isEmpty()); |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 37 | } |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 38 | |
| 39 | if (fLocked) { |
| 40 | // If a layer is locked it must have a texture (though it need not be |
| 41 | // the atlas-backing texture) and occupy some space. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 42 | SkASSERT(fTexture); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 43 | SkASSERT(!fRect.isEmpty()); |
| 44 | } |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 45 | |
| 46 | // Unfortunately there is a brief time where a layer can be locked |
| 47 | // but not used, so we can only check the "used implies locked" |
| 48 | // invariant. |
| 49 | if (fUses > 0) { |
| 50 | SkASSERT(fLocked); |
| 51 | } else { |
| 52 | SkASSERT(0 == fUses); |
| 53 | } |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | class GrAutoValidateLayer : ::SkNoncopyable { |
| 57 | public: |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 58 | GrAutoValidateLayer(GrTexture* backingTexture, const GrCachedLayer* layer) |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 59 | : fBackingTexture(backingTexture) |
| 60 | , fLayer(layer) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 61 | if (fLayer) { |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 62 | fLayer->validate(backingTexture); |
| 63 | } |
| 64 | } |
| 65 | ~GrAutoValidateLayer() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 66 | if (fLayer) { |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 67 | fLayer->validate(fBackingTexture); |
| 68 | } |
| 69 | } |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 70 | void setBackingTexture(GrTexture* backingTexture) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 71 | SkASSERT(nullptr == fBackingTexture || fBackingTexture == backingTexture); |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 72 | fBackingTexture = backingTexture; |
| 73 | } |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 74 | |
| 75 | private: |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 76 | const GrTexture* fBackingTexture; |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 77 | const GrCachedLayer* fLayer; |
| 78 | }; |
| 79 | #endif |
| 80 | |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 81 | GrLayerCache::GrLayerCache(GrContext* context) |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 82 | : fContext(context) { |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 83 | memset(fPlotLocks, 0, sizeof(fPlotLocks)); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | GrLayerCache::~GrLayerCache() { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 87 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 88 | SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
| 89 | for (; !iter.done(); ++iter) { |
| 90 | GrCachedLayer* layer = &(*iter); |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 91 | SkASSERT(0 == layer->uses()); |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 92 | this->unlock(layer); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 93 | delete layer; |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 94 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 95 | |
robertphillips | b32f0ad | 2014-11-04 06:46:11 -0800 | [diff] [blame] | 96 | SkASSERT(0 == fPictureHash.count()); |
| 97 | |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 98 | // The atlas only lets go of its texture when the atlas is deleted. |
| 99 | fAtlas.free(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 100 | } |
| 101 | |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 102 | void GrLayerCache::initAtlas() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 103 | SkASSERT(nullptr == fAtlas.get()); |
robertphillips | 225a627 | 2014-10-30 11:39:19 -0700 | [diff] [blame] | 104 | GR_STATIC_ASSERT(kNumPlotsX*kNumPlotsX == GrPictureInfo::kNumPlots); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 105 | |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 106 | SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 107 | fAtlas.reset(new GrAtlas(fContext->getGpu(), kSkia8888_GrPixelConfig, |
| 108 | kRenderTarget_GrSurfaceFlag, textureSize, kNumPlotsX, kNumPlotsY, |
| 109 | false)); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | void GrLayerCache::freeAll() { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 113 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 114 | SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
| 115 | for (; !iter.done(); ++iter) { |
| 116 | GrCachedLayer* layer = &(*iter); |
| 117 | this->unlock(layer); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 118 | delete layer; |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 119 | } |
| 120 | fLayerHash.rewind(); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 121 | |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 122 | // The atlas only lets go of its texture when the atlas is deleted. |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 123 | fAtlas.free(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 124 | } |
| 125 | |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 126 | GrCachedLayer* GrLayerCache::createLayer(uint32_t pictureID, |
| 127 | int start, int stop, |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 128 | const SkIRect& srcIR, |
| 129 | const SkIRect& dstIR, |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 130 | const SkMatrix& initialMat, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 131 | const int* key, |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 132 | int keySize, |
robertphillips | 4aa6dfc | 2014-09-17 07:50:47 -0700 | [diff] [blame] | 133 | const SkPaint* paint) { |
robertphillips | 410dd05 | 2014-10-06 12:19:50 -0700 | [diff] [blame] | 134 | SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 135 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 136 | GrCachedLayer* layer = new GrCachedLayer(pictureID, start, stop, srcIR, dstIR, initialMat, key, |
| 137 | keySize, paint); |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 138 | fLayerHash.add(layer); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 139 | return layer; |
| 140 | } |
| 141 | |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 142 | GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initialMat, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 143 | const int* key, int keySize) { |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 144 | SkASSERT(pictureID != SK_InvalidGenID); |
| 145 | return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySize)); |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 146 | } |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 147 | |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 148 | GrCachedLayer* GrLayerCache::findLayerOrCreate(uint32_t pictureID, |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 149 | int start, int stop, |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 150 | const SkIRect& srcIR, |
| 151 | const SkIRect& dstIR, |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 152 | const SkMatrix& initialMat, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 153 | const int* key, |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 154 | int keySize, |
robertphillips | 4aa6dfc | 2014-09-17 07:50:47 -0700 | [diff] [blame] | 155 | const SkPaint* paint) { |
robertphillips | 410dd05 | 2014-10-06 12:19:50 -0700 | [diff] [blame] | 156 | SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0); |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 157 | GrCachedLayer* layer = fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySize)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 158 | if (nullptr == layer) { |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 159 | layer = this->createLayer(pictureID, start, stop, |
| 160 | srcIR, dstIR, initialMat, |
| 161 | key, keySize, paint); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 162 | } |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 163 | |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 164 | return layer; |
| 165 | } |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 166 | |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 167 | bool GrLayerCache::tryToAtlas(GrCachedLayer* layer, |
| 168 | const GrSurfaceDesc& desc, |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 169 | bool* needsRendering) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 170 | SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : nullptr, layer);) |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 171 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 172 | SkASSERT(PlausiblyAtlasable(desc.fWidth, desc.fHeight)); |
robertphillips | a63f32e | 2014-11-10 08:10:42 -0800 | [diff] [blame] | 173 | SkASSERT(0 == desc.fSampleCnt); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 174 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 175 | if (layer->locked()) { |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 176 | // This layer is already locked |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 177 | SkASSERT(fAtlas); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 178 | SkASSERT(layer->isAtlased()); |
| 179 | SkASSERT(layer->rect().width() == desc.fWidth); |
| 180 | SkASSERT(layer->rect().height() == desc.fHeight); |
| 181 | *needsRendering = false; |
| 182 | return true; |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 183 | } |
| 184 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 185 | if (layer->isAtlased()) { |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 186 | SkASSERT(fAtlas); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 187 | // Hooray it is still in the atlas - make sure it stays there |
| 188 | layer->setLocked(true); |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 189 | this->incPlotLock(layer->plot()->id()); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 190 | *needsRendering = false; |
| 191 | return true; |
| 192 | } else { |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 193 | if (!fAtlas) { |
| 194 | this->initAtlas(); |
| 195 | if (!fAtlas) { |
| 196 | return false; |
| 197 | } |
| 198 | } |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 199 | // Not in the atlas - will it fit? |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 200 | GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 201 | if (nullptr == pictInfo) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 202 | pictInfo = new GrPictureInfo(layer->pictureID()); |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 203 | fPictureHash.add(pictInfo); |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | SkIPoint16 loc; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 207 | for (int i = 0; i < 2; ++i) { // extra pass in case we fail to add but are able to purge |
| 208 | GrPlot* plot = fAtlas->addToAtlas(&pictInfo->fPlotUsage, |
| 209 | desc.fWidth, desc.fHeight, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 210 | nullptr, &loc); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 211 | // addToAtlas can allocate the backing texture |
| 212 | SkDEBUGCODE(avl.setBackingTexture(fAtlas->getTexture())); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 213 | if (plot) { |
robertphillips | 225a627 | 2014-10-30 11:39:19 -0700 | [diff] [blame] | 214 | #if !GR_CACHE_HOISTED_LAYERS |
| 215 | pictInfo->incPlotUsage(plot->id()); |
| 216 | #endif |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 217 | // The layer was successfully added to the atlas |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 218 | const SkIRect bounds = SkIRect::MakeXYWH(loc.fX, loc.fY, |
robertphillips | e99d499 | 2014-12-03 07:33:57 -0800 | [diff] [blame] | 219 | desc.fWidth, desc.fHeight); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 220 | layer->setTexture(fAtlas->getTexture(), bounds); |
| 221 | layer->setPlot(plot); |
| 222 | layer->setLocked(true); |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 223 | this->incPlotLock(layer->plot()->id()); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 224 | *needsRendering = true; |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 225 | return true; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 226 | } |
| 227 | |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 228 | // The layer was rejected by the atlas (even though we know it is |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 229 | // plausibly atlas-able). See if a plot can be purged and try again. |
| 230 | if (!this->purgePlot()) { |
| 231 | break; // We weren't able to purge any plots |
| 232 | } |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 233 | } |
robertphillips | bc0c4bd | 2014-12-01 11:39:59 -0800 | [diff] [blame] | 234 | |
| 235 | if (pictInfo->fPlotUsage.isEmpty()) { |
| 236 | fPictureHash.remove(pictInfo->fPictureID); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 237 | delete pictInfo; |
robertphillips | bc0c4bd | 2014-12-01 11:39:59 -0800 | [diff] [blame] | 238 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 239 | } |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 240 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 241 | return false; |
| 242 | } |
| 243 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 244 | bool GrLayerCache::lock(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* needsRendering) { |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 245 | if (layer->locked()) { |
| 246 | // This layer is already locked |
| 247 | *needsRendering = false; |
| 248 | return true; |
| 249 | } |
| 250 | |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 251 | // TODO: make the test for exact match depend on the image filters themselves |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 252 | SkAutoTUnref<GrTexture> tex; |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 253 | if (layer->fFilter) { |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 254 | tex.reset(fContext->textureProvider()->createTexture(desc, true)); |
| 255 | } else { |
| 256 | tex.reset(fContext->textureProvider()->createApproxTexture(desc)); |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 257 | } |
| 258 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 259 | if (!tex) { |
| 260 | return false; |
| 261 | } |
| 262 | |
robertphillips | e99d499 | 2014-12-03 07:33:57 -0800 | [diff] [blame] | 263 | layer->setTexture(tex, SkIRect::MakeWH(desc.fWidth, desc.fHeight)); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 264 | layer->setLocked(true); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 265 | *needsRendering = true; |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 266 | return true; |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void GrLayerCache::unlock(GrCachedLayer* layer) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 270 | SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : nullptr, layer);) |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 271 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 272 | if (nullptr == layer || !layer->locked()) { |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 273 | // invalid or not locked |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 274 | return; |
| 275 | } |
| 276 | |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 277 | if (layer->isAtlased()) { |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 278 | const int plotID = layer->plot()->id(); |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 279 | |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 280 | this->decPlotLock(plotID); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 281 | // At this point we could aggressively clear out un-locked plots but |
| 282 | // by delaying we may be able to reuse some of the atlased layers later. |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 283 | #if !GR_CACHE_HOISTED_LAYERS |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 284 | // This testing code aggressively removes the atlased layers. This |
| 285 | // can be used to separate the performance contribution of less |
| 286 | // render target pingponging from that due to the re-use of cached layers |
| 287 | GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 288 | SkASSERT(pictInfo); |
robertphillips | 225a627 | 2014-10-30 11:39:19 -0700 | [diff] [blame] | 289 | |
| 290 | pictInfo->decPlotUsage(plotID); |
| 291 | |
| 292 | if (0 == pictInfo->plotUsage(plotID)) { |
| 293 | GrAtlas::RemovePlot(&pictInfo->fPlotUsage, layer->plot()); |
robertphillips | b32f0ad | 2014-11-04 06:46:11 -0800 | [diff] [blame] | 294 | |
| 295 | if (pictInfo->fPlotUsage.isEmpty()) { |
| 296 | fPictureHash.remove(pictInfo->fPictureID); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 297 | delete pictInfo; |
robertphillips | b32f0ad | 2014-11-04 06:46:11 -0800 | [diff] [blame] | 298 | } |
robertphillips | 225a627 | 2014-10-30 11:39:19 -0700 | [diff] [blame] | 299 | } |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 300 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 301 | layer->setPlot(nullptr); |
| 302 | layer->setTexture(nullptr, SkIRect::MakeEmpty()); |
robertphillips | 0c42332 | 2014-07-31 11:02:38 -0700 | [diff] [blame] | 303 | #endif |
| 304 | |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 305 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 306 | layer->setTexture(nullptr, SkIRect::MakeEmpty()); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 307 | } |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 308 | |
| 309 | layer->setLocked(false); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 310 | } |
| 311 | |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 312 | #ifdef SK_DEBUG |
| 313 | void GrLayerCache::validate() const { |
robertphillips | a32c6bc | 2014-10-09 12:47:01 -0700 | [diff] [blame] | 314 | int plotLocks[kNumPlotsX * kNumPlotsY]; |
| 315 | memset(plotLocks, 0, sizeof(plotLocks)); |
| 316 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 317 | SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::ConstIter iter(&fLayerHash); |
| 318 | for (; !iter.done(); ++iter) { |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 319 | const GrCachedLayer* layer = &(*iter); |
| 320 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 321 | layer->validate(fAtlas.get() ? fAtlas->getTexture() : nullptr); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 322 | |
| 323 | const GrPictureInfo* pictInfo = fPictureHash.find(layer->pictureID()); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 324 | if (!pictInfo) { |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 325 | // If there is no picture info for this picture then all of its |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 326 | // layers should be non-atlased. |
| 327 | SkASSERT(!layer->isAtlased()); |
| 328 | } |
| 329 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 330 | if (layer->plot()) { |
| 331 | SkASSERT(pictInfo); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 332 | SkASSERT(pictInfo->fPictureID == layer->pictureID()); |
| 333 | |
| 334 | SkASSERT(pictInfo->fPlotUsage.contains(layer->plot())); |
robertphillips | 225a627 | 2014-10-30 11:39:19 -0700 | [diff] [blame] | 335 | #if !GR_CACHE_HOISTED_LAYERS |
| 336 | SkASSERT(pictInfo->plotUsage(layer->plot()->id()) > 0); |
| 337 | #endif |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 338 | |
| 339 | if (layer->locked()) { |
robertphillips | a32c6bc | 2014-10-09 12:47:01 -0700 | [diff] [blame] | 340 | plotLocks[layer->plot()->id()]++; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 341 | } |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 342 | } |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 343 | } |
robertphillips | a32c6bc | 2014-10-09 12:47:01 -0700 | [diff] [blame] | 344 | |
| 345 | for (int i = 0; i < kNumPlotsX*kNumPlotsY; ++i) { |
| 346 | SkASSERT(plotLocks[i] == fPlotLocks[i]); |
| 347 | } |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | class GrAutoValidateCache : ::SkNoncopyable { |
| 351 | public: |
| 352 | explicit GrAutoValidateCache(GrLayerCache* cache) |
| 353 | : fCache(cache) { |
| 354 | fCache->validate(); |
| 355 | } |
| 356 | ~GrAutoValidateCache() { |
| 357 | fCache->validate(); |
| 358 | } |
| 359 | private: |
| 360 | GrLayerCache* fCache; |
| 361 | }; |
| 362 | #endif |
| 363 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 364 | void GrLayerCache::purge(uint32_t pictureID) { |
| 365 | |
robertphillips | 21048b5 | 2014-07-15 19:46:35 -0700 | [diff] [blame] | 366 | SkDEBUGCODE(GrAutoValidateCache avc(this);) |
| 367 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 368 | // We need to find all the layers associated with 'picture' and remove them. |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 369 | SkTDArray<GrCachedLayer*> toBeRemoved; |
| 370 | |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 371 | SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
| 372 | for (; !iter.done(); ++iter) { |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 373 | if (pictureID == (*iter).pictureID()) { |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 374 | *toBeRemoved.append() = &(*iter); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
| 378 | for (int i = 0; i < toBeRemoved.count(); ++i) { |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 379 | SkASSERT(0 == toBeRemoved[i]->uses()); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 380 | this->unlock(toBeRemoved[i]); |
robertphillips | 3d533ac | 2014-07-20 09:40:00 -0700 | [diff] [blame] | 381 | fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 382 | delete toBeRemoved[i]; |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 383 | } |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 384 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 385 | GrPictureInfo* pictInfo = fPictureHash.find(pictureID); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 386 | if (pictInfo) { |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 387 | fPictureHash.remove(pictureID); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 388 | delete pictInfo; |
robertphillips | 261b8a9 | 2014-07-17 08:26:44 -0700 | [diff] [blame] | 389 | } |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 390 | } |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 391 | |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 392 | bool GrLayerCache::purgePlot() { |
| 393 | SkDEBUGCODE(GrAutoValidateCache avc(this);) |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 394 | SkASSERT(fAtlas); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 395 | |
| 396 | GrAtlas::PlotIter iter; |
| 397 | GrPlot* plot; |
| 398 | for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 399 | plot; |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 400 | plot = iter.prev()) { |
| 401 | if (fPlotLocks[plot->id()] > 0) { |
| 402 | continue; |
| 403 | } |
| 404 | |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 405 | this->purgePlot(plot); |
robertphillips | 320c923 | 2014-07-29 06:07:19 -0700 | [diff] [blame] | 406 | return true; |
| 407 | } |
| 408 | |
| 409 | return false; |
| 410 | } |
| 411 | |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 412 | void GrLayerCache::purgePlot(GrPlot* plot) { |
| 413 | SkASSERT(0 == fPlotLocks[plot->id()]); |
| 414 | |
| 415 | // We need to find all the layers in 'plot' and remove them. |
| 416 | SkTDArray<GrCachedLayer*> toBeRemoved; |
| 417 | |
| 418 | SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
| 419 | for (; !iter.done(); ++iter) { |
| 420 | if (plot == (*iter).plot()) { |
| 421 | *toBeRemoved.append() = &(*iter); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | for (int i = 0; i < toBeRemoved.count(); ++i) { |
robertphillips | 7bb9ed7 | 2014-10-10 11:38:29 -0700 | [diff] [blame] | 426 | SkASSERT(0 == toBeRemoved[i]->uses()); |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 427 | SkASSERT(!toBeRemoved[i]->locked()); |
| 428 | |
robertphillips | 410dd05 | 2014-10-06 12:19:50 -0700 | [diff] [blame] | 429 | uint32_t pictureIDToRemove = toBeRemoved[i]->pictureID(); |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 430 | |
robertphillips | 410dd05 | 2014-10-06 12:19:50 -0700 | [diff] [blame] | 431 | // Aggressively remove layers and, if it becomes totally uncached, delete the picture info |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 432 | fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 433 | delete toBeRemoved[i]; |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 434 | |
robertphillips | 410dd05 | 2014-10-06 12:19:50 -0700 | [diff] [blame] | 435 | GrPictureInfo* pictInfo = fPictureHash.find(pictureIDToRemove); |
| 436 | if (pictInfo) { |
robertphillips | 225a627 | 2014-10-30 11:39:19 -0700 | [diff] [blame] | 437 | #if !GR_CACHE_HOISTED_LAYERS |
| 438 | SkASSERT(0 == pictInfo->plotUsage(plot->id())); |
| 439 | #endif |
robertphillips | 410dd05 | 2014-10-06 12:19:50 -0700 | [diff] [blame] | 440 | GrAtlas::RemovePlot(&pictInfo->fPlotUsage, plot); |
| 441 | |
| 442 | if (pictInfo->fPlotUsage.isEmpty()) { |
| 443 | fPictureHash.remove(pictInfo->fPictureID); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 444 | delete pictInfo; |
robertphillips | 410dd05 | 2014-10-06 12:19:50 -0700 | [diff] [blame] | 445 | } |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
| 449 | plot->resetRects(); |
| 450 | } |
| 451 | |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 452 | #if !GR_CACHE_HOISTED_LAYERS |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 453 | void GrLayerCache::purgeAll() { |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 454 | if (!fAtlas) { |
| 455 | return; |
| 456 | } |
| 457 | |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 458 | GrAtlas::PlotIter iter; |
| 459 | GrPlot* plot; |
| 460 | for (plot = fAtlas->iterInit(&iter, GrAtlas::kLRUFirst_IterOrder); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 461 | plot; |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 462 | plot = iter.prev()) { |
| 463 | SkASSERT(0 == fPlotLocks[plot->id()]); |
| 464 | |
| 465 | this->purgePlot(plot); |
| 466 | } |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 467 | |
robertphillips | b32f0ad | 2014-11-04 06:46:11 -0800 | [diff] [blame] | 468 | SkASSERT(0 == fPictureHash.count()); |
| 469 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 470 | GrDrawContext* drawContext = fContext->drawContext(); |
| 471 | |
| 472 | if (drawContext) { |
| 473 | drawContext->discard(fAtlas->getTexture()->asRenderTarget()); |
| 474 | } |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 475 | } |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 476 | #endif |
robertphillips | 6f294af | 2014-08-18 08:50:03 -0700 | [diff] [blame] | 477 | |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 478 | void GrLayerCache::processDeletedPictures() { |
bsalomon | 23e619c | 2015-02-06 11:54:28 -0800 | [diff] [blame] | 479 | SkTArray<SkPicture::DeletionMessage> deletedPictures; |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 480 | fPictDeletionInbox.poll(&deletedPictures); |
| 481 | |
| 482 | for (int i = 0; i < deletedPictures.count(); i++) { |
mtklein | 04c9695 | 2014-11-24 08:20:57 -0800 | [diff] [blame] | 483 | this->purge(deletedPictures[i].fUniqueID); |
robertphillips | d771f6b | 2014-07-22 10:18:06 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
robertphillips | 84ac082 | 2014-10-14 07:07:59 -0700 | [diff] [blame] | 487 | #ifdef SK_DEVELOPER |
| 488 | void GrLayerCache::writeLayersToDisk(const SkString& dirName) { |
| 489 | |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 490 | if (fAtlas) { |
| 491 | GrTexture* atlasTexture = fAtlas->getTexture(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 492 | if (nullptr != atlasTexture) { |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 493 | SkString fileName(dirName); |
| 494 | fileName.append("\\atlas.png"); |
robertphillips | 84ac082 | 2014-10-14 07:07:59 -0700 | [diff] [blame] | 495 | |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 496 | atlasTexture->surfacePriv().savePixels(fileName.c_str()); |
| 497 | } |
robertphillips | 84ac082 | 2014-10-14 07:07:59 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); |
| 501 | for (; !iter.done(); ++iter) { |
| 502 | GrCachedLayer* layer = &(*iter); |
| 503 | |
| 504 | if (layer->isAtlased() || !layer->texture()) { |
| 505 | continue; |
| 506 | } |
| 507 | |
| 508 | SkString fileName(dirName); |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 509 | fileName.appendf("\\%d", layer->fKey.pictureID()); |
| 510 | for (int i = 0; i < layer->fKey.keySize(); ++i) { |
| 511 | fileName.appendf("-%d", layer->fKey.key()[i]); |
| 512 | } |
| 513 | fileName.appendf(".png"); |
robertphillips | 84ac082 | 2014-10-14 07:07:59 -0700 | [diff] [blame] | 514 | |
| 515 | layer->texture()->surfacePriv().savePixels(fileName.c_str()); |
| 516 | } |
| 517 | } |
| 518 | #endif |