Index: src/gpu/GrLayerHoister.cpp |
diff --git a/src/gpu/GrLayerHoister.cpp b/src/gpu/GrLayerHoister.cpp |
index ba431d33e98c0340210a5a9ea2749087de558762..ed17b5130b21296390328956055d18f97c7c0d69 100644 |
--- a/src/gpu/GrLayerHoister.cpp |
+++ b/src/gpu/GrLayerHoister.cpp |
@@ -14,26 +14,38 @@ |
#include "SkSurface.h" |
// Return true if any layers are suitable for hoisting |
-bool GrLayerHoister::FindLayersToHoist(const GrAccelData *gpuData, |
+bool GrLayerHoister::FindLayersToHoist(const SkPicture* mainPicture, |
const SkRect& query, |
- SkTDArray<GrCachedLayer*>* atlased, |
- SkTDArray<GrCachedLayer*>* nonAtlased, |
+ SkTDArray<HoistingInfo>* atlased, |
+ SkTDArray<HoistingInfo>* nonAtlased, |
GrLayerCache* layerCache) { |
bool anyHoisted = false; |
+ SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
+ |
+ const SkPicture::AccelData* mainData = mainPicture->EXPERIMENTAL_getAccelData(key); |
+ if (NULL == mainData) { |
+ return false; |
+ } |
+ |
+ const GrAccelData *mainGPUData = static_cast<const GrAccelData*>(mainData); |
+ if (0 == mainGPUData->numSaveLayers()) { |
bsalomon
2014/09/23 14:57:35
does numSaveLayers() count the nested layers?
robertphillips
2014/09/24 14:49:03
Yes all the layers (both nested and appearing in s
|
+ return false; |
+ } |
+ |
// Layer hoisting pre-renders the entire layer since it will be cached and potentially |
// reused with different clips (e.g., in different tiles). Because of this the |
// clip will not be limiting the size of the pre-rendered layer. kSaveLayerMaxSize |
// is used to limit which clips are pre-rendered. |
static const int kSaveLayerMaxSize = 256; |
- SkAutoTArray<bool> pullForward(gpuData->numSaveLayers()); |
+ SkAutoTArray<bool> pullForward(mainGPUData->numSaveLayers()); |
// Pre-render all the layers that intersect the query rect |
- for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
+ for (int i = 0; i < mainGPUData->numSaveLayers(); ++i) { |
pullForward[i] = false; |
- const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
+ const GrAccelData::SaveLayerInfo& info = mainGPUData->saveLayerInfo(i); |
SkRect layerRect = SkRect::MakeXYWH(SkIntToScalar(info.fOffset.fX), |
SkIntToScalar(info.fOffset.fY), |
@@ -61,14 +73,15 @@ bool GrLayerHoister::FindLayersToHoist(const GrAccelData *gpuData, |
return false; |
} |
- atlased->setReserve(atlased->reserved() + gpuData->numSaveLayers()); |
+ atlased->setReserve(atlased->reserved() + mainGPUData->numSaveLayers()); |
// Generate the layer and/or ensure it is locked |
- for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
+ for (int i = 0; i < mainGPUData->numSaveLayers(); ++i) { |
if (pullForward[i]) { |
- const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
+ const GrAccelData::SaveLayerInfo& info = mainGPUData->saveLayerInfo(i); |
+ const SkPicture* pict = info.fPicture ? info.fPicture : mainPicture; |
- GrCachedLayer* layer = layerCache->findLayerOrCreate(info.fPictureID, |
+ GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(), |
info.fSaveLayerOpID, |
info.fRestoreOpID, |
info.fOffset, |
@@ -89,11 +102,16 @@ bool GrLayerHoister::FindLayersToHoist(const GrAccelData *gpuData, |
} |
if (needsRendering) { |
+ HoistingInfo* info; |
+ |
if (layer->isAtlased()) { |
- *atlased->append() = layer; |
+ info = atlased->append(); |
} else { |
- *nonAtlased->append() = layer; |
+ info = nonAtlased->append(); |
} |
+ |
+ info->layer = layer; |
+ info->picture = pict; |
} |
} |
} |
@@ -107,42 +125,43 @@ static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re |
result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
} |
-static void convert_layers_to_replacements(const SkTDArray<GrCachedLayer*>& layers, |
+static void convert_layers_to_replacements(const SkTDArray<GrLayerHoister::HoistingInfo>& layers, |
GrReplacements* replacements) { |
// TODO: just replace GrReplacements::ReplacementInfo with GrCachedLayer? |
for (int i = 0; i < layers.count(); ++i) { |
GrReplacements::ReplacementInfo* layerInfo = replacements->push(); |
- layerInfo->fStart = layers[i]->start(); |
- layerInfo->fStop = layers[i]->stop(); |
- layerInfo->fPos = layers[i]->offset();; |
+ layerInfo->fStart = layers[i].layer->start(); |
+ layerInfo->fStop = layers[i].layer->stop(); |
+ layerInfo->fPos = layers[i].layer->offset();; |
SkBitmap bm; |
- wrap_texture(layers[i]->texture(), |
- !layers[i]->isAtlased() ? layers[i]->rect().width() |
- : layers[i]->texture()->width(), |
- !layers[i]->isAtlased() ? layers[i]->rect().height() |
- : layers[i]->texture()->height(), |
+ wrap_texture(layers[i].layer->texture(), |
+ !layers[i].layer->isAtlased() ? layers[i].layer->rect().width() |
+ : layers[i].layer->texture()->width(), |
+ !layers[i].layer->isAtlased() ? layers[i].layer->rect().height() |
+ : layers[i].layer->texture()->height(), |
&bm); |
layerInfo->fImage = SkImage::NewTexture(bm); |
- layerInfo->fPaint = layers[i]->paint() ? SkNEW_ARGS(SkPaint, (*layers[i]->paint())) : NULL; |
+ layerInfo->fPaint = layers[i].layer->paint() |
+ ? SkNEW_ARGS(SkPaint, (*layers[i].layer->paint())) |
+ : NULL; |
- layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i]->rect().fLeft, |
- layers[i]->rect().fTop, |
- layers[i]->rect().width(), |
- layers[i]->rect().height()); |
+ layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i].layer->rect().fLeft, |
+ layers[i].layer->rect().fTop, |
+ layers[i].layer->rect().width(), |
+ layers[i].layer->rect().height()); |
} |
} |
-void GrLayerHoister::DrawLayers(const SkPicture* picture, |
- const SkTDArray<GrCachedLayer*>& atlased, |
- const SkTDArray<GrCachedLayer*>& nonAtlased, |
+void GrLayerHoister::DrawLayers(const SkTDArray<HoistingInfo>& atlased, |
+ const SkTDArray<HoistingInfo>& nonAtlased, |
GrReplacements* replacements) { |
// Render the atlased layers that require it |
if (atlased.count() > 0) { |
// All the atlased layers are rendered into the same GrTexture |
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( |
- atlased[0]->texture()->asRenderTarget(), |
+ atlased[0].layer->texture()->asRenderTarget(), |
SkSurface::kStandard_TextRenderMode)); |
SkCanvas* atlasCanvas = surface->getCanvas(); |
@@ -152,7 +171,8 @@ void GrLayerHoister::DrawLayers(const SkPicture* picture, |
paint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode))->unref(); |
for (int i = 0; i < atlased.count(); ++i) { |
- GrCachedLayer* layer = atlased[i]; |
+ GrCachedLayer* layer = atlased[i].layer; |
+ const SkPicture* pict = atlased[i].picture; |
atlasCanvas->save(); |
@@ -181,7 +201,7 @@ void GrLayerHoister::DrawLayers(const SkPicture* picture, |
atlasCanvas->translate(bound.fLeft, bound.fTop); |
atlasCanvas->concat(layer->ctm()); |
- SkRecordPartialDraw(*picture->fRecord.get(), atlasCanvas, bound, |
+ SkRecordPartialDraw(*pict->fRecord.get(), atlasCanvas, bound, |
layer->start()+1, layer->stop(), initialCTM); |
atlasCanvas->restore(); |
@@ -192,7 +212,8 @@ void GrLayerHoister::DrawLayers(const SkPicture* picture, |
// Render the non-atlased layers that require it |
for (int i = 0; i < nonAtlased.count(); ++i) { |
- GrCachedLayer* layer = nonAtlased[i]; |
+ GrCachedLayer* layer = nonAtlased[i].layer; |
+ const SkPicture* pict = nonAtlased[i].picture; |
// Each non-atlased layer has its own GrTexture |
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( |
@@ -220,7 +241,7 @@ void GrLayerHoister::DrawLayers(const SkPicture* picture, |
SkIntToScalar(-layer->offset().fY)); |
layerCanvas->concat(layer->ctm()); |
- SkRecordPartialDraw(*picture->fRecord.get(), layerCanvas, bound, |
+ SkRecordPartialDraw(*pict->fRecord.get(), layerCanvas, bound, |
layer->start()+1, layer->stop(), initialCTM); |
layerCanvas->flush(); |
@@ -230,33 +251,35 @@ void GrLayerHoister::DrawLayers(const SkPicture* picture, |
convert_layers_to_replacements(nonAtlased, replacements); |
} |
-void GrLayerHoister::UnlockLayers(GrLayerCache* layerCache, const SkPicture* picture) { |
- SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
+static void unlock_layer_in_cache(GrLayerCache* layerCache, |
+ const SkPicture* picture, |
+ GrCachedLayer* layer) { |
+ layerCache->unlock(layer); |
- const SkPicture::AccelData* data = picture->EXPERIMENTAL_getAccelData(key); |
- SkASSERT(data); |
+#if DISABLE_CACHING |
+ // This code completely clears out the atlas. It is required when |
+ // caching is disabled so the atlas doesn't fill up and force more |
+ // free floating layers |
+ layerCache->purge(picture->uniqueID()); |
+#endif |
+} |
- const GrAccelData *gpuData = static_cast<const GrAccelData*>(data); |
- SkASSERT(0 != gpuData->numSaveLayers()); |
+void GrLayerHoister::UnlockLayers(GrLayerCache* layerCache, |
+ const SkTDArray<HoistingInfo>& atlased, |
+ const SkTDArray<HoistingInfo>& nonAtlased) { |
- // unlock the layers |
- for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
- const GrAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
+ for (int i = 0; i < atlased.count(); ++i) { |
+ unlock_layer_in_cache(layerCache, atlased[i].picture, atlased[i].layer); |
+ } |
- GrCachedLayer* layer = layerCache->findLayer(picture->uniqueID(), |
- info.fSaveLayerOpID, |
- info.fRestoreOpID, |
- info.fOffset, |
- info.fOriginXform); |
- layerCache->unlock(layer); |
+ for (int i = 0; i < nonAtlased.count(); ++i) { |
+ unlock_layer_in_cache(layerCache, nonAtlased[i].picture, nonAtlased[i].layer); |
} |
#if DISABLE_CACHING |
// This code completely clears out the atlas. It is required when |
// caching is disabled so the atlas doesn't fill up and force more |
// free floating layers |
- layerCache->purge(picture->uniqueID()); |
- |
layerCache->purgeAll(); |
#endif |
} |