Refactor GrLayerHoister::FindLayersToHoist to prep for adding clip to cache key

NOTRY=true

Committed: https://skia.googlesource.com/skia/+/27415b71bd529456165945e19b5b7efbebf6fb51

Review URL: https://codereview.chromium.org/640373002
This commit is contained in:
robertphillips 2014-10-09 15:36:06 -07:00 committed by Commit bot
parent 1598899975
commit cbe80caedd

View File

@ -13,78 +13,14 @@
#include "SkGrPixelRef.h"
#include "SkSurface.h"
// Return true if any layers are suitable for hoisting
bool GrLayerHoister::FindLayersToHoist(GrContext* context,
// Create the layer information for the hoisted layer and secure the
// required texture/render target resources.
static void prepare_for_hoisting(GrLayerCache* layerCache,
const SkPicture* topLevelPicture,
const SkRect& query,
const GrAccelData::SaveLayerInfo& info,
SkTDArray<GrHoistedLayer>* atlased,
SkTDArray<GrHoistedLayer>* nonAtlased,
SkTDArray<GrHoistedLayer>* recycled) {
bool anyHoisted = false;
GrLayerCache* layerCache = context->getLayerCache();
layerCache->processDeletedPictures();
SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_getAccelData(key);
if (NULL == topLevelData) {
return false;
}
const GrAccelData *topLevelGPUData = static_cast<const GrAccelData*>(topLevelData);
if (0 == topLevelGPUData->numSaveLayers()) {
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(topLevelGPUData->numSaveLayers());
// Pre-render all the layers that intersect the query rect
for (int i = 0; i < topLevelGPUData->numSaveLayers(); ++i) {
pullForward[i] = false;
const GrAccelData::SaveLayerInfo& info = topLevelGPUData->saveLayerInfo(i);
SkRect layerRect = SkRect::MakeXYWH(SkIntToScalar(info.fOffset.fX),
SkIntToScalar(info.fOffset.fY),
SkIntToScalar(info.fSize.fWidth),
SkIntToScalar(info.fSize.fHeight));
if (!SkRect::Intersects(query, layerRect)) {
continue;
}
// TODO: ignore perspective projected layers here!
// TODO: once this code is more stable unsuitable layers can
// just be omitted during the optimization stage
if (!info.fValid ||
kSaveLayerMaxSize < info.fSize.fWidth ||
kSaveLayerMaxSize < info.fSize.fHeight ||
info.fIsNested) {
continue;
}
pullForward[i] = true;
anyHoisted = true;
}
if (!anyHoisted) {
return false;
}
atlased->setReserve(atlased->reserved() + topLevelGPUData->numSaveLayers());
// Generate the layer and/or ensure it is locked
for (int i = 0; i < topLevelGPUData->numSaveLayers(); ++i) {
if (pullForward[i]) {
const GrAccelData::SaveLayerInfo& info = topLevelGPUData->saveLayerInfo(i);
const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture;
GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(),
@ -100,10 +36,10 @@ bool GrLayerHoister::FindLayersToHoist(GrContext* context,
desc.fConfig = kSkia8888_GrPixelConfig;
// TODO: need to deal with sample count
bool needsRendering = layerCache->lock(layer, desc,
info.fHasNestedLayers || info.fIsNested);
bool needsRendering = layerCache->lock(layer, desc, info.fHasNestedLayers || info.fIsNested);
if (NULL == layer->texture()) {
continue;
// GPU resources could not be secured for the hoisting of this layer
return;
}
GrHoistedLayer* hl;
@ -122,7 +58,67 @@ bool GrLayerHoister::FindLayersToHoist(GrContext* context,
hl->fPicture = pict;
hl->fOffset = info.fOffset;
hl->fCTM = info.fOriginXform;
}
// Return true if any layers are suitable for hoisting
bool GrLayerHoister::FindLayersToHoist(GrContext* context,
const SkPicture* topLevelPicture,
const SkRect& query,
SkTDArray<GrHoistedLayer>* atlased,
SkTDArray<GrHoistedLayer>* nonAtlased,
SkTDArray<GrHoistedLayer>* recycled) {
GrLayerCache* layerCache = context->getLayerCache();
layerCache->processDeletedPictures();
SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_getAccelData(key);
if (!topLevelData) {
return false;
}
const GrAccelData *topLevelGPUData = static_cast<const GrAccelData*>(topLevelData);
if (0 == topLevelGPUData->numSaveLayers()) {
return false;
}
bool anyHoisted = false;
// The layer hoisting code will pre-render and cache an entire layer if most
// of it is being used (~70%) and it will fit in a texture. This is to allow
// such layers to be re-used for different clips/tiles.
// Small layers will additionally be atlased.
// The only limitation right now is that nested layers are currently not hoisted.
// Parent layers are hoisted but are never atlased (so that we never swap
// away from the atlas rendertarget when generating the hoisted layers).
atlased->setReserve(atlased->count() + topLevelGPUData->numSaveLayers());
// Find and prepare for hoisting all the layers that intersect the query rect
for (int i = 0; i < topLevelGPUData->numSaveLayers(); ++i) {
const GrAccelData::SaveLayerInfo& info = topLevelGPUData->saveLayerInfo(i);
SkRect layerRect = SkRect::MakeXYWH(SkIntToScalar(info.fOffset.fX),
SkIntToScalar(info.fOffset.fY),
SkIntToScalar(info.fSize.fWidth),
SkIntToScalar(info.fSize.fHeight));
if (!SkRect::Intersects(query, layerRect)) {
continue;
}
// TODO: ignore perspective projected layers here!
// TODO: once this code is more stable unsuitable layers can
// just be omitted during the optimization stage
if (!info.fValid || info.fIsNested) {
continue;
}
prepare_for_hoisting(layerCache, topLevelPicture, info, atlased, nonAtlased, recycled);
anyHoisted = true;
}
return anyHoisted;