Bug 913443 - Break CreateOrRecyclePaintedLayer up even more. r=roc

--HG--
extra : rebase_source : 925d0803b07ff088297327b9082cbb1ff84ecb61
This commit is contained in:
Markus Stange 2015-03-02 19:25:13 -05:00
Родитель 4215086d34
Коммит 3c736ea719
1 изменённых файлов: 51 добавлений и 35 удалений

Просмотреть файл

@ -711,6 +711,13 @@ protected:
const nsIFrame *aReferenceFrame,
const nsPoint& aTopLeft);
/**
* Find a PaintedLayer for recycling, recycle it and prepare it for use, or
* return null if no suitable layer was found.
*/
already_AddRefed<PaintedLayer> AttemptToRecyclePaintedLayer(const nsIFrame* aAnimatedGeometryRoot,
const nsIFrame *aReferenceFrame,
const nsPoint& aTopLeft);
/**
* Recycle aLayer and do any necessary invalidation.
*/
@ -1700,55 +1707,64 @@ ContainerState::GetLayerCreationHint(const nsIFrame* aAnimatedGeometryRoot)
return LayerManager::NONE;
}
already_AddRefed<PaintedLayer>
ContainerState::AttemptToRecyclePaintedLayer(const nsIFrame* aAnimatedGeometryRoot,
const nsIFrame* aReferenceFrame,
const nsPoint& aTopLeft)
{
if (mNextFreeRecycledPaintedLayer >= mRecycledPaintedLayers.Length()) {
return nullptr;
}
// Try to recycle a layer
nsRefPtr<PaintedLayer> layer = mRecycledPaintedLayers[mNextFreeRecycledPaintedLayer];
++mNextFreeRecycledPaintedLayer;
// Check if the layer hint has changed and whether or not the layer should
// be recreated because of it.
if (!mManager->IsOptimizedFor(layer, GetLayerCreationHint(aAnimatedGeometryRoot))) {
return nullptr;
}
bool didResetScrollPositionForLayerPixelAlignment = false;
PaintedDisplayItemLayerUserData* data =
RecyclePaintedLayer(layer, aAnimatedGeometryRoot,
didResetScrollPositionForLayerPixelAlignment);
PreparePaintedLayerForUse(layer, data, aAnimatedGeometryRoot, aReferenceFrame,
aTopLeft,
didResetScrollPositionForLayerPixelAlignment);
return layer.forget();
}
already_AddRefed<PaintedLayer>
ContainerState::CreateOrRecyclePaintedLayer(const nsIFrame* aAnimatedGeometryRoot,
const nsIFrame* aReferenceFrame,
const nsPoint& aTopLeft)
{
// We need a new painted layer
nsRefPtr<PaintedLayer> layer;
PaintedDisplayItemLayerUserData* data;
bool layerRecycled = false;
bool didResetScrollPositionForLayerPixelAlignment = false;
nsRefPtr<PaintedLayer> layer =
AttemptToRecyclePaintedLayer(aAnimatedGeometryRoot, aReferenceFrame, aTopLeft);
if (layer) {
return layer.forget();
}
// Check whether the layer will be scrollable. This is used as a hint to
// influence whether tiled layers are used or not.
LayerManager::PaintedLayerCreationHint creationHint =
GetLayerCreationHint(aAnimatedGeometryRoot);
if (mNextFreeRecycledPaintedLayer < mRecycledPaintedLayers.Length()) {
// Try to recycle a layer
layer = mRecycledPaintedLayers[mNextFreeRecycledPaintedLayer];
++mNextFreeRecycledPaintedLayer;
// Check if the layer hint has changed and whether or not the layer should
// be recreated because of it.
if (mManager->IsOptimizedFor(layer, creationHint)) {
layerRecycled = true;
data = RecyclePaintedLayer(layer, aAnimatedGeometryRoot,
didResetScrollPositionForLayerPixelAlignment);
// We do not need to Invalidate these areas in the widget because we
// assume the caller of InvalidatePaintedLayerContents has ensured
// the area is invalidated in the widget.
}
// Create a new painted layer
layer = mManager->CreatePaintedLayerWithHint(creationHint);
if (!layer) {
return nullptr;
}
if (!layerRecycled) {
// Create a new painted layer
layer = mManager->CreatePaintedLayerWithHint(creationHint);
if (!layer)
return nullptr;
// Mark this layer as being used for painting display items
data = new PaintedDisplayItemLayerUserData();
layer->SetUserData(&gPaintedDisplayItemLayerUserData, data);
ResetScrollPositionForLayerPixelAlignment(aAnimatedGeometryRoot);
didResetScrollPositionForLayerPixelAlignment = true;
}
// Mark this layer as being used for painting display items
PaintedDisplayItemLayerUserData* data = new PaintedDisplayItemLayerUserData();
layer->SetUserData(&gPaintedDisplayItemLayerUserData, data);
ResetScrollPositionForLayerPixelAlignment(aAnimatedGeometryRoot);
PreparePaintedLayerForUse(layer, data, aAnimatedGeometryRoot,
aReferenceFrame, aTopLeft,
didResetScrollPositionForLayerPixelAlignment);
aReferenceFrame, aTopLeft, true);
return layer.forget();
}