Bug 1442190 - Part 1: Add nsDisplayOpacityGeometry r=mattwoodrow
authorMiko Mynttinen <mikokm@gmail.com>
Wed, 21 Mar 2018 12:13:05 +0100
changeset 781479 df7030abb8e1da3c943e4e112e5567b2df2c49c1
parent 781478 0f807beef229718c015553bac09e4f638ca2add1
child 781480 f4a9c1f73c1dabd9e54490a05d2c4b8e4870f4a0
push id106312
push userhaftandilian@mozilla.com
push dateThu, 12 Apr 2018 23:43:57 +0000
reviewersmattwoodrow
bugs1442190
milestone61.0a1
Bug 1442190 - Part 1: Add nsDisplayOpacityGeometry r=mattwoodrow MozReview-Commit-ID: K7WqIlib10v
layout/painting/nsDisplayList.cpp
layout/painting/nsDisplayList.h
layout/painting/nsDisplayListInvalidation.h
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -6636,16 +6636,30 @@ nsDisplayOpacity::ComputeVisibility(nsDi
   nsRect bounds = GetClippedBounds(aBuilder);
   nsRegion visibleUnderChildren;
   visibleUnderChildren.And(*aVisibleRegion, bounds);
   return
     nsDisplayWrapList::ComputeVisibility(aBuilder, &visibleUnderChildren);
 }
 
 void
+nsDisplayOpacity::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
+                                            const nsDisplayItemGeometry* aGeometry,
+                                            nsRegion* aInvalidRegion) const
+{
+  const nsDisplayOpacityGeometry* geometry =
+    static_cast<const nsDisplayOpacityGeometry*>(aGeometry);
+
+  bool snap;
+  if (mOpacity != geometry->mOpacity) {
+    aInvalidRegion->Or(GetBounds(aBuilder, &snap), geometry->mBounds);
+  }
+}
+
+void
 nsDisplayOpacity::WriteDebugInfo(std::stringstream& aStream)
 {
   aStream << " (opacity " << mOpacity << ")";
 }
 
 bool
 nsDisplayOpacity::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                           mozilla::wr::IpcResourceUpdateQueue& aResources,
--- a/layout/painting/nsDisplayList.h
+++ b/layout/painting/nsDisplayList.h
@@ -5200,22 +5200,25 @@ public:
   virtual bool CanMerge(const nsDisplayItem* aItem) const override
   {
     // items for the same content element should be merged into a single
     // compositing group
     // aItem->GetUnderlyingFrame() returns non-null because it's nsDisplayOpacity
     return HasSameTypeAndClip(aItem) && HasSameContent(aItem);
   }
 
+  virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override
+  {
+    return new nsDisplayOpacityGeometry(this, aBuilder, mOpacity);
+  }
+
   virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
                                          const nsDisplayItemGeometry* aGeometry,
-                                         nsRegion* aInvalidRegion) const override
-  {
-    // We don't need to compute an invalidation region since we have LayerTreeInvalidation
-  }
+                                         nsRegion* aInvalidRegion) const override;
+
   virtual bool IsInvalid(nsRect& aRect) const override
   {
     if (mForEventsAndPluginsOnly) {
       return false;
     }
     return nsDisplayWrapList::IsInvalid(aRect);
   }
   virtual void ApplyOpacity(nsDisplayListBuilder* aBuilder,
--- a/layout/painting/nsDisplayListInvalidation.h
+++ b/layout/painting/nsDisplayListInvalidation.h
@@ -348,9 +348,22 @@ public:
   virtual bool InvalidateForSyncDecodeImages() const override
   {
     return ShouldInvalidateToSyncDecodeImages();
   }
 
   nsPoint mFrameOffsetToViewport;
 };
 
+class nsDisplayOpacityGeometry : public nsDisplayItemGenericGeometry
+{
+public:
+  nsDisplayOpacityGeometry(nsDisplayItem* aItem,
+                           nsDisplayListBuilder* aBuilder,
+                           float aOpacity)
+    : nsDisplayItemGenericGeometry(aItem, aBuilder)
+    , mOpacity(aOpacity)
+  {}
+
+  float mOpacity;
+};
+
 #endif /*NSDISPLAYLISTINVALIDATION_H_*/