| 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 #include "GrLayerCache.h" | 8 #include "GrLayerCache.h" |
| 9 #include "GrLayerHoister.h" | 9 #include "GrLayerHoister.h" |
| 10 #include "GrRecordReplaceDraw.h" | 10 #include "GrRecordReplaceDraw.h" |
| 11 | 11 |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkGrPixelRef.h" | 13 #include "SkGrPixelRef.h" |
| 14 #include "SkLayerInfo.h" | 14 #include "SkLayerInfo.h" |
| 15 #include "SkRecordDraw.h" | 15 #include "SkRecordDraw.h" |
| 16 #include "SkSurface.h" | 16 #include "SkSurface.h" |
| 17 | 17 |
| 18 // Create the layer information for the hoisted layer and secure the | 18 // Create the layer information for the hoisted layer and secure the |
| 19 // required texture/render target resources. | 19 // required texture/render target resources. |
| 20 static void prepare_for_hoisting(GrLayerCache* layerCache, | 20 static void prepare_for_hoisting(GrLayerCache* layerCache, |
| 21 const SkPicture* topLevelPicture, | 21 const SkPicture* topLevelPicture, |
| 22 const SkMatrix& matrix, |
| 22 const SkLayerInfo::BlockInfo& info, | 23 const SkLayerInfo::BlockInfo& info, |
| 23 const SkIRect& layerRect, | 24 const SkIRect& layerRect, |
| 24 SkTDArray<GrHoistedLayer>* needRendering, | 25 SkTDArray<GrHoistedLayer>* needRendering, |
| 25 SkTDArray<GrHoistedLayer>* recycled, | 26 SkTDArray<GrHoistedLayer>* recycled, |
| 26 bool attemptToAtlas, | 27 bool attemptToAtlas, |
| 27 int numSamples) { | 28 int numSamples) { |
| 28 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; | 29 const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture; |
| 29 | 30 |
| 30 SkMatrix combined = SkMatrix::Concat(info.fPreMat, info.fLocalMat); | 31 SkMatrix combined = matrix; |
| 32 combined.preConcat(info.fPreMat); |
| 33 combined.preConcat(info.fLocalMat); |
| 31 | 34 |
| 32 GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(), | 35 GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(), |
| 33 info.fSaveLayerOpID, | 36 info.fSaveLayerOpID, |
| 34 info.fRestoreOpID, | 37 info.fRestoreOpID, |
| 35 layerRect, | 38 layerRect, |
| 36 combined, | 39 combined, |
| 37 info.fPaint); | 40 info.fPaint); |
| 38 GrSurfaceDesc desc; | 41 GrSurfaceDesc desc; |
| 39 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 42 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 40 desc.fWidth = layerRect.width(); | 43 desc.fWidth = layerRect.width(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 66 hl = needRendering->append(); | 69 hl = needRendering->append(); |
| 67 } else { | 70 } else { |
| 68 hl = recycled->append(); | 71 hl = recycled->append(); |
| 69 } | 72 } |
| 70 | 73 |
| 71 layerCache->addUse(layer); | 74 layerCache->addUse(layer); |
| 72 hl->fLayer = layer; | 75 hl->fLayer = layer; |
| 73 hl->fPicture = pict; | 76 hl->fPicture = pict; |
| 74 hl->fOffset = SkIPoint::Make(layerRect.fLeft, layerRect.fTop); | 77 hl->fOffset = SkIPoint::Make(layerRect.fLeft, layerRect.fTop); |
| 75 hl->fLocalMat = info.fLocalMat; | 78 hl->fLocalMat = info.fLocalMat; |
| 76 hl->fPreMat = info.fPreMat; | 79 hl->fPreMat = matrix; |
| 80 hl->fPreMat.preConcat(info.fPreMat); |
| 77 } | 81 } |
| 78 | 82 |
| 79 // Atlased layers must be small enough to fit in the atlas, not have a | 83 // Atlased layers must be small enough to fit in the atlas, not have a |
| 80 // paint with an image filter and be neither nested nor nesting. | 84 // paint with an image filter and be neither nested nor nesting. |
| 81 // TODO: allow leaf nested layers to appear in the atlas. | 85 // TODO: allow leaf nested layers to appear in the atlas. |
| 82 void GrLayerHoister::FindLayersToAtlas(GrContext* context, | 86 void GrLayerHoister::FindLayersToAtlas(GrContext* context, |
| 83 const SkPicture* topLevelPicture, | 87 const SkPicture* topLevelPicture, |
| 88 const SkMatrix& initialMat, |
| 84 const SkRect& query, | 89 const SkRect& query, |
| 85 SkTDArray<GrHoistedLayer>* atlased, | 90 SkTDArray<GrHoistedLayer>* atlased, |
| 86 SkTDArray<GrHoistedLayer>* recycled, | 91 SkTDArray<GrHoistedLayer>* recycled, |
| 87 int numSamples) { | 92 int numSamples) { |
| 88 if (0 != numSamples) { | 93 if (0 != numSamples) { |
| 89 // MSAA layers are currently never atlased | 94 // MSAA layers are currently never atlased |
| 90 return; | 95 return; |
| 91 } | 96 } |
| 92 | 97 |
| 93 GrLayerCache* layerCache = context->getLayerCache(); | 98 GrLayerCache* layerCache = context->getLayerCache(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 112 const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i); | 117 const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i); |
| 113 | 118 |
| 114 // TODO: ignore perspective projected layers here? | 119 // TODO: ignore perspective projected layers here? |
| 115 bool disallowAtlasing = info.fHasNestedLayers || info.fIsNested || | 120 bool disallowAtlasing = info.fHasNestedLayers || info.fIsNested || |
| 116 (info.fPaint && info.fPaint->getImageFilter()); | 121 (info.fPaint && info.fPaint->getImageFilter()); |
| 117 | 122 |
| 118 if (disallowAtlasing) { | 123 if (disallowAtlasing) { |
| 119 continue; | 124 continue; |
| 120 } | 125 } |
| 121 | 126 |
| 122 SkRect layerRect = info.fBounds; | 127 SkRect layerRect; |
| 128 initialMat.mapRect(&layerRect, info.fBounds); |
| 123 if (!layerRect.intersect(query)) { | 129 if (!layerRect.intersect(query)) { |
| 124 continue; | 130 continue; |
| 125 } | 131 } |
| 126 | 132 |
| 127 SkIRect ir; | 133 const SkIRect ir = layerRect.roundOut(); |
| 128 layerRect.roundOut(&ir); | |
| 129 | 134 |
| 130 if (!GrLayerCache::PlausiblyAtlasable(ir.width(), ir.height())) { | 135 if (!GrLayerCache::PlausiblyAtlasable(ir.width(), ir.height())) { |
| 131 continue; | 136 continue; |
| 132 } | 137 } |
| 133 | 138 |
| 134 prepare_for_hoisting(layerCache, topLevelPicture, info, ir, atlased, rec
ycled, true, 0); | 139 prepare_for_hoisting(layerCache, topLevelPicture, initialMat, |
| 140 info, ir, atlased, recycled, true, 0); |
| 135 } | 141 } |
| 136 | 142 |
| 137 } | 143 } |
| 138 | 144 |
| 139 void GrLayerHoister::FindLayersToHoist(GrContext* context, | 145 void GrLayerHoister::FindLayersToHoist(GrContext* context, |
| 140 const SkPicture* topLevelPicture, | 146 const SkPicture* topLevelPicture, |
| 147 const SkMatrix& initialMat, |
| 141 const SkRect& query, | 148 const SkRect& query, |
| 142 SkTDArray<GrHoistedLayer>* needRendering, | 149 SkTDArray<GrHoistedLayer>* needRendering, |
| 143 SkTDArray<GrHoistedLayer>* recycled, | 150 SkTDArray<GrHoistedLayer>* recycled, |
| 144 int numSamples) { | 151 int numSamples) { |
| 145 GrLayerCache* layerCache = context->getLayerCache(); | 152 GrLayerCache* layerCache = context->getLayerCache(); |
| 146 | 153 |
| 147 layerCache->processDeletedPictures(); | 154 layerCache->processDeletedPictures(); |
| 148 | 155 |
| 149 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); | 156 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
| 150 | 157 |
| 151 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); | 158 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); |
| 152 if (!topLevelData) { | 159 if (!topLevelData) { |
| 153 return; | 160 return; |
| 154 } | 161 } |
| 155 | 162 |
| 156 const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLeve
lData); | 163 const SkLayerInfo *topLevelGPUData = static_cast<const SkLayerInfo*>(topLeve
lData); |
| 157 if (0 == topLevelGPUData->numBlocks()) { | 164 if (0 == topLevelGPUData->numBlocks()) { |
| 158 return; | 165 return; |
| 159 } | 166 } |
| 160 | 167 |
| 161 // Find and prepare for hoisting all the layers that intersect the query rec
t | 168 // Find and prepare for hoisting all the layers that intersect the query rec
t |
| 162 for (int i = 0; i < topLevelGPUData->numBlocks(); ++i) { | 169 for (int i = 0; i < topLevelGPUData->numBlocks(); ++i) { |
| 163 const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i); | 170 const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i); |
| 164 if (info.fIsNested) { | 171 if (info.fIsNested) { |
| 165 // Parent layers are currently hoisted while nested layers are not. | 172 // Parent layers are currently hoisted while nested layers are not. |
| 166 continue; | 173 continue; |
| 167 } | 174 } |
| 168 | 175 |
| 169 SkRect layerRect = info.fBounds; | 176 SkRect layerRect; |
| 177 initialMat.mapRect(&layerRect, info.fBounds); |
| 170 if (!layerRect.intersect(query)) { | 178 if (!layerRect.intersect(query)) { |
| 171 continue; | 179 continue; |
| 172 } | 180 } |
| 173 | 181 |
| 174 SkIRect ir; | 182 const SkIRect ir = layerRect.roundOut(); |
| 175 layerRect.roundOut(&ir); | |
| 176 | 183 |
| 177 prepare_for_hoisting(layerCache, topLevelPicture, info, ir, | 184 prepare_for_hoisting(layerCache, topLevelPicture, initialMat, info, ir, |
| 178 needRendering, recycled, false, numSamples); | 185 needRendering, recycled, false, numSamples); |
| 179 } | 186 } |
| 180 } | 187 } |
| 181 | 188 |
| 182 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 189 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
| 183 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 190 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 184 result->setInfo(info); | 191 result->setInfo(info); |
| 185 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 192 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
| 186 } | 193 } |
| 187 | 194 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 void GrLayerHoister::PurgeCache(GrContext* context) { | 338 void GrLayerHoister::PurgeCache(GrContext* context) { |
| 332 #if !GR_CACHE_HOISTED_LAYERS | 339 #if !GR_CACHE_HOISTED_LAYERS |
| 333 GrLayerCache* layerCache = context->getLayerCache(); | 340 GrLayerCache* layerCache = context->getLayerCache(); |
| 334 | 341 |
| 335 // This code completely clears out the atlas. It is required when | 342 // This code completely clears out the atlas. It is required when |
| 336 // caching is disabled so the atlas doesn't fill up and force more | 343 // caching is disabled so the atlas doesn't fill up and force more |
| 337 // free floating layers | 344 // free floating layers |
| 338 layerCache->purgeAll(); | 345 layerCache->purgeAll(); |
| 339 #endif | 346 #endif |
| 340 } | 347 } |
| OLD | NEW |