Commit e415dc84 authored by Matt Woodrow's avatar Matt Woodrow
Browse files

Bug 1440966 - Store optimized Layer in DisplayItemData as part of AddPaintedLayerFor. r=jnicol

parent 0ed88b02
Loading
Loading
Loading
Loading
+17 −30
Original line number Diff line number Diff line
@@ -2011,19 +2011,6 @@ FrameLayerBuilder::DidBeginRetainedLayerTransaction(LayerManager* aManager)
  }
}

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()
{
@@ -3192,16 +3179,6 @@ void ContainerState::FinishPaintedLayerData(PaintedLayerData& aData, FindOpaqueB
    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();
@@ -3246,10 +3223,6 @@ void ContainerState::FinishPaintedLayerData(PaintedLayerData& aData, FindOpaqueB
      data->mLayer->SetVisibleRegion(LayerIntRegion());
      data->mLayer->InvalidateWholeLayer();
      data->mLayer->SetEventRegions(EventRegions());

      for (auto& item : data->mAssignedDisplayItems) {
        mLayerBuilder->StoreOptimizedLayerForFrame(item.mItem, layer);
      }
    }
  }

@@ -3260,6 +3233,15 @@ void ContainerState::FinishPaintedLayerData(PaintedLayerData& aData, FindOpaqueB
    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;
@@ -4784,8 +4766,7 @@ FrameLayerBuilder::ComputeGeometryChangeForItem(DisplayItemData* aData)
void
FrameLayerBuilder::AddPaintedDisplayItem(PaintedLayerData* aLayerData,
                                         AssignedDisplayItem& aItem,
                                         ContainerState& aContainerState,
                                         const nsPoint& aTopLeft)
                                         ContainerState& aContainerState)
{
  PaintedLayer* layer = aLayerData->mLayer;
  PaintedDisplayItemLayerUserData* paintedData =
@@ -4801,7 +4782,7 @@ FrameLayerBuilder::AddPaintedDisplayItem(PaintedLayerData* aLayerData,
      // 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,
@@ -4823,6 +4804,12 @@ FrameLayerBuilder::AddPaintedDisplayItem(PaintedLayerData* aLayerData,
      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) {
+2 −10
Original line number Diff line number Diff line
@@ -510,10 +510,10 @@ public:
   * 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,
@@ -590,14 +590,6 @@ public:
   */
  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<DisplayItemData>& aArray);