# HG changeset patch # User Matt Woodrow # Date 1520390563 -46800 # Node ID fe859b4ec63cc8737ad26a1ca2bc2e7bfaa6dcdc # Parent 49172b2039ae285f5a01a01e1e85a466563b40b3 Bug 1440966 - Store optimized Layer in DisplayItemData as part of AddPaintedLayerFor. r=jnicol diff --git a/layout/painting/FrameLayerBuilder.cpp b/layout/painting/FrameLayerBuilder.cpp --- a/layout/painting/FrameLayerBuilder.cpp +++ b/layout/painting/FrameLayerBuilder.cpp @@ -2035,29 +2035,16 @@ FrameLayerBuilder::DidBeginRetainedLayer mInvalidateAllLayers = data->mInvalidateAllLayers; } else { data = new LayerManagerData(aManager); aManager->SetUserData(&gLayerManagerUserData, data); } } void -FrameLayerBuilder::StoreOptimizedLayerForFrame(nsDisplayItem* aItem, Layer* aLayer) -{ - if (!mRetainingManager) { - return; - } - - DisplayItemData* data = GetDisplayItemDataForManager(aItem, aLayer->Manager()); - NS_ASSERTION(data, "Must have already stored data for this item!"); - data->mOptLayer = aLayer; - data->mItem = nullptr; -} - -void FrameLayerBuilder::DidEndTransaction() { GetMaskLayerImageCache()->Sweep(); } void FrameLayerBuilder::WillEndTransaction() { @@ -3228,26 +3215,16 @@ void ContainerState::FinishPaintedLayerD RefPtr paintedLayer = CreatePaintedLayer(data); data->mLayer = paintedLayer; NS_ASSERTION(FindIndexOfLayerIn(mNewChildLayers, paintedLayer) < 0, "Layer already in list???"); mNewChildLayers[data->mNewChildLayersIndex].mLayer = paintedLayer.forget(); } - for (auto& item : data->mAssignedDisplayItems) { - MOZ_ASSERT(item.mItem->GetType() != DisplayItemType::TYPE_LAYER_EVENT_REGIONS); - MOZ_ASSERT(item.mItem->GetType() != DisplayItemType::TYPE_COMPOSITOR_HITTEST_INFO); - - InvalidateForLayerChange(item.mItem, data->mLayer, item.mDisplayItemData); - mLayerBuilder->AddPaintedDisplayItem(data, item, *this, - data->mAnimatedGeometryRootOffset); - item.mDisplayItemData = nullptr; - } - PaintedDisplayItemLayerUserData* userData = GetPaintedDisplayItemLayerUserData(data->mLayer); NS_ASSERTION(userData, "where did our user data go?"); userData->mLastItemCount = data->mAssignedDisplayItems.Length(); NewLayerEntry* newLayerEntry = &mNewChildLayers[data->mNewChildLayersIndex]; RefPtr layer; bool canOptimizeToImageLayer = data->CanOptimizeToImageLayer(mBuilder); @@ -3282,30 +3259,35 @@ void ContainerState::FinishPaintedLayerD // Hide the PaintedLayer. We leave it in the layer tree so that we // can find and recycle it later. ParentLayerIntRect emptyRect; data->mLayer->SetClipRect(Some(emptyRect)); data->mLayer->SetVisibleRegion(LayerIntRegion()); data->mLayer->InvalidateWholeLayer(); data->mLayer->SetEventRegions(EventRegions()); - - for (auto& item : data->mAssignedDisplayItems) { - mLayerBuilder->StoreOptimizedLayerForFrame(item.mItem, layer); - } } } if (!layer) { // We couldn't optimize to an image layer or a color layer above. layer = data->mLayer; layer->SetClipRect(Nothing()); FLB_LOG_PAINTED_LAYER_DECISION(data, " Selected painted layer=%p\n", layer.get()); } + for (auto& item : data->mAssignedDisplayItems) { + MOZ_ASSERT(item.mItem->GetType() != DisplayItemType::TYPE_LAYER_EVENT_REGIONS); + MOZ_ASSERT(item.mItem->GetType() != DisplayItemType::TYPE_COMPOSITOR_HITTEST_INFO); + + InvalidateForLayerChange(item.mItem, data->mLayer, item.mDisplayItemData); + mLayerBuilder->AddPaintedDisplayItem(data, item, *this, layer); + item.mDisplayItemData = nullptr; + } + if (mLayerBuilder->IsBuildingRetainedLayers()) { newLayerEntry->mVisibleRegion = data->mVisibleRegion; newLayerEntry->mOpaqueRegion = data->mOpaqueRegion; newLayerEntry->mHideAllLayersBelow = data->mHideAllLayersBelow; newLayerEntry->mOpaqueForAnimatedGeometryRootParent = data->mOpaqueForAnimatedGeometryRootParent; } else { SetOuterVisibleRegionForLayer(layer, data->mVisibleRegion); } @@ -4835,33 +4817,33 @@ FrameLayerBuilder::ComputeGeometryChange aData->EndUpdate(geometry); } void FrameLayerBuilder::AddPaintedDisplayItem(PaintedLayerData* aLayerData, AssignedDisplayItem& aItem, ContainerState& aContainerState, - const nsPoint& aTopLeft) + Layer* aLayer) { PaintedLayer* layer = aLayerData->mLayer; PaintedDisplayItemLayerUserData* paintedData = static_cast (layer->GetUserData(&gPaintedDisplayItemLayerUserData)); RefPtr tempManager; nsIntRect intClip; bool hasClip = false; if (aItem.mLayerState != LAYER_NONE) { if (aItem.mDisplayItemData) { tempManager = aItem.mDisplayItemData->mInactiveManager; // We need to grab these before updating the DisplayItemData because it will overwrite them. nsRegion clip; if (aItem.mClip.ComputeRegionInClips(&aItem.mDisplayItemData->GetClip(), - aTopLeft - paintedData->mLastAnimatedGeometryRootOrigin, + aLayerData->mAnimatedGeometryRootOffset - paintedData->mLastAnimatedGeometryRootOrigin, &clip)) { intClip = clip.GetBounds().ScaleToOutsidePixels(paintedData->mXScale, paintedData->mYScale, paintedData->mAppUnitsPerDevPixel); } } if (!tempManager) { tempManager = new BasicLayerManager(BasicLayerManager::BLM_INACTIVE); @@ -4873,16 +4855,22 @@ FrameLayerBuilder::AddPaintedDisplayItem if (data) { if (!data->mUsed) { data->BeginUpdate(layer, aItem.mLayerState, aItem.mItem, aItem.mReused, aItem.mMerged); } } else { data = StoreDataForFrame(aItem.mItem, layer, aItem.mLayerState, nullptr); } data->mInactiveManager = tempManager; + // We optimized this PaintedLayer into a ColorLayer/ImageLayer. Store the optimized + // layer here. + if (aLayer != layer) { + data->mOptLayer = aLayer; + data->mItem = nullptr; + } } if (tempManager) { FLB_LOG_PAINTED_LAYER_DECISION(aLayerData, "Creating nested FLB for item %p\n", aItem.mItem); FrameLayerBuilder* layerBuilder = new FrameLayerBuilder(); layerBuilder->Init(mDisplayListBuilder, tempManager, aLayerData, true, &aItem.mClip); diff --git a/layout/painting/FrameLayerBuilder.h b/layout/painting/FrameLayerBuilder.h --- a/layout/painting/FrameLayerBuilder.h +++ b/layout/painting/FrameLayerBuilder.h @@ -505,20 +505,20 @@ public: /** * Record aItem as a display item that is rendered by the PaintedLayer * aLayer, with aClipRect, where aContainerLayerFrame is the frame * for the container layer this ThebesItem belongs to. * aItem must have an underlying frame. * @param aTopLeft offset from active scrolled root to reference frame */ - void AddPaintedDisplayItem(PaintedLayerData* aLayer, + void AddPaintedDisplayItem(PaintedLayerData* aLayerData, AssignedDisplayItem& aAssignedDisplayItem, ContainerState& aContainerState, - const nsPoint& aTopLeft); + Layer* aLayer); /** * Calls GetOldLayerForFrame on the underlying frame of the display item, * and each subsequent merged frame if no layer is found for the underlying * frame. */ Layer* GetOldLayerFor(nsDisplayItem* aItem, nsDisplayItemGeometry** aOldGeometry = nullptr, @@ -585,24 +585,16 @@ public: * Return the resolution at which we expect to render aFrame's contents, * assuming they are being painted to retained layers. This takes into account * the resolution the contents of the ContainerLayer containing aFrame are * being rendered at, as well as any currently-inactive transforms between * aFrame and that container layer. */ static gfxSize GetPaintedLayerScaleForFrame(nsIFrame* aFrame); - /** - * Stores a Layer as the dedicated layer in the DisplayItemData for a given frame/key pair. - * - * Used when we optimize a PaintedLayer into an ImageLayer and want to retroactively update the - * DisplayItemData so we can retrieve the layer from within layout. - */ - void StoreOptimizedLayerForFrame(nsDisplayItem* aItem, Layer* aLayer); - static void RemoveFrameFromLayerManager(const nsIFrame* aFrame, SmallPointerArray& aArray); /** * Given a frame and a display item key that uniquely identifies a * display item for the frame, find the layer that was last used to * render that display item. Returns null if there is no such layer. * This could be a dedicated layer for the display item, or a PaintedLayer