| 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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkRecordDraw.h" | 11 #include "SkRecordDraw.h" |
| 12 #include "GrRecordReplaceDraw.h" | 12 #include "GrRecordReplaceDraw.h" |
| 13 #include "SkGrPixelRef.h" | 13 #include "SkGrPixelRef.h" |
| 14 #include "SkSurface.h" | 14 #include "SkSurface.h" |
| 15 | 15 |
| 16 // Return true if any layers are suitable for hoisting | 16 // Return true if any layers are suitable for hoisting |
| 17 bool GrLayerHoister::FindLayersToHoist(const SkPicture* topLevelPicture, | 17 bool GrLayerHoister::FindLayersToHoist(GrContext* context, |
| 18 const SkPicture* topLevelPicture, |
| 18 const SkRect& query, | 19 const SkRect& query, |
| 19 SkTDArray<HoistedLayer>* atlased, | 20 SkTDArray<GrHoistedLayer>* atlased, |
| 20 SkTDArray<HoistedLayer>* nonAtlased, | 21 SkTDArray<GrHoistedLayer>* nonAtlased, |
| 21 SkTDArray<HoistedLayer>* recycled, | 22 SkTDArray<GrHoistedLayer>* recycled) { |
| 22 GrLayerCache* layerCache) { | |
| 23 bool anyHoisted = false; | 23 bool anyHoisted = false; |
| 24 | 24 |
| 25 GrLayerCache* layerCache = context->getLayerCache(); |
| 26 |
| 27 layerCache->processDeletedPictures(); |
| 28 |
| 25 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 29 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
| 26 | 30 |
| 27 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); | 31 const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_get
AccelData(key); |
| 28 if (NULL == topLevelData) { | 32 if (NULL == topLevelData) { |
| 29 return false; | 33 return false; |
| 30 } | 34 } |
| 31 | 35 |
| 32 const GrAccelData *topLevelGPUData = static_cast<const GrAccelData*>(topLeve
lData); | 36 const GrAccelData *topLevelGPUData = static_cast<const GrAccelData*>(topLeve
lData); |
| 33 if (0 == topLevelGPUData->numSaveLayers()) { | 37 if (0 == topLevelGPUData->numSaveLayers()) { |
| 34 return false; | 38 return false; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 desc.fHeight = info.fSize.fHeight; | 99 desc.fHeight = info.fSize.fHeight; |
| 96 desc.fConfig = kSkia8888_GrPixelConfig; | 100 desc.fConfig = kSkia8888_GrPixelConfig; |
| 97 // TODO: need to deal with sample count | 101 // TODO: need to deal with sample count |
| 98 | 102 |
| 99 bool needsRendering = layerCache->lock(layer, desc, | 103 bool needsRendering = layerCache->lock(layer, desc, |
| 100 info.fHasNestedLayers || info
.fIsNested); | 104 info.fHasNestedLayers || info
.fIsNested); |
| 101 if (NULL == layer->texture()) { | 105 if (NULL == layer->texture()) { |
| 102 continue; | 106 continue; |
| 103 } | 107 } |
| 104 | 108 |
| 105 HoistedLayer* hl; | 109 GrHoistedLayer* hl; |
| 106 | 110 |
| 107 if (needsRendering) { | 111 if (needsRendering) { |
| 108 if (layer->isAtlased()) { | 112 if (layer->isAtlased()) { |
| 109 hl = atlased->append(); | 113 hl = atlased->append(); |
| 110 } else { | 114 } else { |
| 111 hl = nonAtlased->append(); | 115 hl = nonAtlased->append(); |
| 112 } | 116 } |
| 113 } else { | 117 } else { |
| 114 hl = recycled->append(); | 118 hl = recycled->append(); |
| 115 } | 119 } |
| 116 | 120 |
| 117 hl->fLayer = layer; | 121 hl->fLayer = layer; |
| 118 hl->fPicture = pict; | 122 hl->fPicture = pict; |
| 119 hl->fOffset = info.fOffset; | 123 hl->fOffset = info.fOffset; |
| 120 hl->fCTM = info.fOriginXform; | 124 hl->fCTM = info.fOriginXform; |
| 121 } | 125 } |
| 122 } | 126 } |
| 123 | 127 |
| 124 return anyHoisted; | 128 return anyHoisted; |
| 125 } | 129 } |
| 126 | 130 |
| 127 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { | 131 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re
sult) { |
| 128 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 132 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 129 result->setInfo(info); | 133 result->setInfo(info); |
| 130 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 134 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
| 131 } | 135 } |
| 132 | 136 |
| 133 static void convert_layers_to_replacements(const SkTDArray<GrLayerHoister::Hoist
edLayer>& layers, | 137 static void convert_layers_to_replacements(const SkTDArray<GrHoistedLayer>& laye
rs, |
| 134 GrReplacements* replacements) { | 138 GrReplacements* replacements) { |
| 135 // TODO: just replace GrReplacements::ReplacementInfo with GrCachedLayer? | 139 // TODO: just replace GrReplacements::ReplacementInfo with GrCachedLayer? |
| 136 for (int i = 0; i < layers.count(); ++i) { | 140 for (int i = 0; i < layers.count(); ++i) { |
| 137 GrCachedLayer* layer = layers[i].fLayer; | 141 GrCachedLayer* layer = layers[i].fLayer; |
| 138 const SkPicture* picture = layers[i].fPicture; | 142 const SkPicture* picture = layers[i].fPicture; |
| 139 | 143 |
| 140 GrReplacements::ReplacementInfo* layerInfo = | 144 GrReplacements::ReplacementInfo* layerInfo = |
| 141 replacements->newReplacement(picture->uniqueID(), | 145 replacements->newReplacement(picture->uniqueID(), |
| 142 layer->start(), | 146 layer->start(), |
| 143 layers[i].fCTM); | 147 layers[i].fCTM); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 157 ? SkNEW_ARGS(SkPaint, (*layers[i].fLayer->paint(
))) | 161 ? SkNEW_ARGS(SkPaint, (*layers[i].fLayer->paint(
))) |
| 158 : NULL; | 162 : NULL; |
| 159 | 163 |
| 160 layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i].fLayer->rect().fLeft, | 164 layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i].fLayer->rect().fLeft, |
| 161 layers[i].fLayer->rect().fTop, | 165 layers[i].fLayer->rect().fTop, |
| 162 layers[i].fLayer->rect().width()
, | 166 layers[i].fLayer->rect().width()
, |
| 163 layers[i].fLayer->rect().height(
)); | 167 layers[i].fLayer->rect().height(
)); |
| 164 } | 168 } |
| 165 } | 169 } |
| 166 | 170 |
| 167 void GrLayerHoister::DrawLayers(const SkTDArray<HoistedLayer>& atlased, | 171 void GrLayerHoister::DrawLayers(const SkTDArray<GrHoistedLayer>& atlased, |
| 168 const SkTDArray<HoistedLayer>& nonAtlased, | 172 const SkTDArray<GrHoistedLayer>& nonAtlased, |
| 169 const SkTDArray<HoistedLayer>& recycled, | 173 const SkTDArray<GrHoistedLayer>& recycled, |
| 170 GrReplacements* replacements) { | 174 GrReplacements* replacements) { |
| 171 // Render the atlased layers that require it | 175 // Render the atlased layers that require it |
| 172 if (atlased.count() > 0) { | 176 if (atlased.count() > 0) { |
| 173 // All the atlased layers are rendered into the same GrTexture | 177 // All the atlased layers are rendered into the same GrTexture |
| 174 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( | 178 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( |
| 175 atlased[0].fLayer->texture()->asRenderTa
rget(), NULL)); | 179 atlased[0].fLayer->texture()->asRenderTa
rget(), NULL)); |
| 176 | 180 |
| 177 SkCanvas* atlasCanvas = surface->getCanvas(); | 181 SkCanvas* atlasCanvas = surface->getCanvas(); |
| 178 | 182 |
| 179 SkPaint paint; | 183 SkPaint paint; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 layerCache->unlock(layer); | 273 layerCache->unlock(layer); |
| 270 | 274 |
| 271 #if DISABLE_CACHING | 275 #if DISABLE_CACHING |
| 272 // This code completely clears out the atlas. It is required when | 276 // This code completely clears out the atlas. It is required when |
| 273 // caching is disabled so the atlas doesn't fill up and force more | 277 // caching is disabled so the atlas doesn't fill up and force more |
| 274 // free floating layers | 278 // free floating layers |
| 275 layerCache->purge(picture->uniqueID()); | 279 layerCache->purge(picture->uniqueID()); |
| 276 #endif | 280 #endif |
| 277 } | 281 } |
| 278 | 282 |
| 279 void GrLayerHoister::UnlockLayers(GrLayerCache* layerCache, | 283 void GrLayerHoister::UnlockLayers(GrContext* context, |
| 280 const SkTDArray<HoistedLayer>& atlased, | 284 const SkTDArray<GrHoistedLayer>& atlased, |
| 281 const SkTDArray<HoistedLayer>& nonAtlased, | 285 const SkTDArray<GrHoistedLayer>& nonAtlased, |
| 282 const SkTDArray<HoistedLayer>& recycled) { | 286 const SkTDArray<GrHoistedLayer>& recycled) { |
| 287 GrLayerCache* layerCache = context->getLayerCache(); |
| 283 | 288 |
| 284 for (int i = 0; i < atlased.count(); ++i) { | 289 for (int i = 0; i < atlased.count(); ++i) { |
| 285 unlock_layer_in_cache(layerCache, atlased[i].fPicture, atlased[i].fLayer
); | 290 unlock_layer_in_cache(layerCache, atlased[i].fPicture, atlased[i].fLayer
); |
| 286 } | 291 } |
| 287 | 292 |
| 288 for (int i = 0; i < nonAtlased.count(); ++i) { | 293 for (int i = 0; i < nonAtlased.count(); ++i) { |
| 289 unlock_layer_in_cache(layerCache, nonAtlased[i].fPicture, nonAtlased[i].
fLayer); | 294 unlock_layer_in_cache(layerCache, nonAtlased[i].fPicture, nonAtlased[i].
fLayer); |
| 290 } | 295 } |
| 291 | 296 |
| 292 for (int i = 0; i < recycled.count(); ++i) { | 297 for (int i = 0; i < recycled.count(); ++i) { |
| 293 unlock_layer_in_cache(layerCache, recycled[i].fPicture, recycled[i].fLay
er); | 298 unlock_layer_in_cache(layerCache, recycled[i].fPicture, recycled[i].fLay
er); |
| 294 } | 299 } |
| 295 | 300 |
| 296 #if DISABLE_CACHING | 301 #if DISABLE_CACHING |
| 297 // This code completely clears out the atlas. It is required when | 302 // This code completely clears out the atlas. It is required when |
| 298 // caching is disabled so the atlas doesn't fill up and force more | 303 // caching is disabled so the atlas doesn't fill up and force more |
| 299 // free floating layers | 304 // free floating layers |
| 300 layerCache->purgeAll(); | 305 layerCache->purgeAll(); |
| 301 #endif | 306 #endif |
| 302 } | 307 } |
| 303 | 308 |
| OLD | NEW |