Don't composite layers with an invisible FrameView.

Required setting parent/self visible for the FrameView associated
with a WebPagePopupImpl. Previously these defaulted to invisible.

BUG=569643

Review URL: https://codereview.chromium.org/1616183002

Cr-Commit-Position: refs/heads/master@{#372109}
diff --git a/third_party/WebKit/LayoutTests/TestExpectations b/third_party/WebKit/LayoutTests/TestExpectations
index b6e6241b..88f04005 100644
--- a/third_party/WebKit/LayoutTests/TestExpectations
+++ b/third_party/WebKit/LayoutTests/TestExpectations
@@ -1110,6 +1110,8 @@
 crbug.com/509025 [ Mac10.10 ] http/tests/navigation/navigation-redirect-schedule-crash.html [ Failure ]
 crbug.com/509025 [ Mac10.10 ] http/tests/security/contentTypeOptions/nosniff-script-without-content-type-blocked.html [ Failure ]
 
+crbug.com/569643 compositing/iframes/invisible-nested-iframe-hide.html [ NeedsRebaseline ]
+
 crbug.com/545140 [ Mac10.10 ] fast/encoding/denormalised-voiced-japanese-chars.html [ Failure ]
 crbug.com/545141 [ Mac10.10 ] fast/writing-mode/text-orientation-basic.html [ Failure ]
 
diff --git a/third_party/WebKit/LayoutTests/compositing/composited-iframe-hidden-expected.html b/third_party/WebKit/LayoutTests/compositing/composited-iframe-hidden-expected.html
new file mode 100644
index 0000000..14bf34b0
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/compositing/composited-iframe-hidden-expected.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<div style="visibility: hidden;"><iframe></iframe></div>
+<p>This test passes if there is no assert failure in debug builds and there is no visible
+content in the iframe above after the page fully settles.
diff --git a/third_party/WebKit/LayoutTests/compositing/composited-iframe-hidden.html b/third_party/WebKit/LayoutTests/compositing/composited-iframe-hidden.html
new file mode 100644
index 0000000..2259f1a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/compositing/composited-iframe-hidden.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<script src="../resources/run-after-layout-and-paint.js"></script>
+<div id="frameContainer">
+  <iframe src="./resources/composited-iframe-hidden-subframe.html"></iframe>
+</div>
+<p>This test passes if there is no assert failure in debug builds and there is no visible
+content in the iframe above after the page fully settles.
+<script>
+function hideFrameContainer() {
+    frameContainer.style.visibility = 'hidden';
+}
+
+function showFrameContainer() {
+    frameContainer.style.visibility = 'visible';
+}
+
+// We were seeing assert failure when we hid and then re-showed the iframe due
+// to a stale graphics layer with an old invalidation posted by the animated
+// element. To prevent regression we hide and re-show the iframe, and hide again
+// to ensure the content is actually hidden.
+if (window.testRunner)
+    testRunner.waitUntilDone();
+runAfterLayoutAndPaint(function() {
+    hideFrameContainer();
+    runAfterLayoutAndPaint(function() {
+        showFrameContainer();
+        runAfterLayoutAndPaint(function() {
+            hideFrameContainer();
+            if (window.testRunner)
+                runAfterLayoutAndPaint(function() {
+                    testRunner.notifyDone();
+                });
+        });
+    });
+});
+</script>
diff --git a/third_party/WebKit/LayoutTests/compositing/iframes/invisible-nested-iframe-show.html b/third_party/WebKit/LayoutTests/compositing/iframes/invisible-nested-iframe-show.html
index 11e6c7d..013259b0 100644
--- a/third_party/WebKit/LayoutTests/compositing/iframes/invisible-nested-iframe-show.html
+++ b/third_party/WebKit/LayoutTests/compositing/iframes/invisible-nested-iframe-show.html
@@ -48,7 +48,7 @@
 </head>
 <body>
 
-    <!-- The nested iframe should appear when we remove "diplay:none". -->
+    <!-- The nested iframe should appear when we remove "display:none". -->
     <div id="invisible" style="display:none;">
         <iframe src="resources/intermediate-frame.html"></iframe>
     </div>
diff --git a/third_party/WebKit/LayoutTests/compositing/resources/composited-iframe-hidden-subframe.html b/third_party/WebKit/LayoutTests/compositing/resources/composited-iframe-hidden-subframe.html
new file mode 100644
index 0000000..aaeefbd8
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/compositing/resources/composited-iframe-hidden-subframe.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<style>
+.animatedBackground {
+    width: 70px;
+    height: 80px;
+    position: absolute;
+    background: url("./square-blue-100x100.png") no-repeat 0 0 transparent;
+    animation: anim 4s steps(6) infinite;
+}
+
+.transformedItem {
+    transform: translate3d(42px, 43px, 0);
+    width: 40px;
+    height: 50px;
+    background-color: green;
+}
+
+@keyframes anim {
+    100% {
+        background-position: 9px 10px
+    }
+}
+</style>
+<div class="animatedBackground"></div>
+<div class="transformedItem"></div>
diff --git a/third_party/WebKit/LayoutTests/compositing/resources/square-blue-100x100.png b/third_party/WebKit/LayoutTests/compositing/resources/square-blue-100x100.png
new file mode 100644
index 0000000..aca6578a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/compositing/resources/square-blue-100x100.png
Binary files differ
diff --git a/third_party/WebKit/Source/core/frame/FrameView.cpp b/third_party/WebKit/Source/core/frame/FrameView.cpp
index a6304a7..8fd9984 100644
--- a/third_party/WebKit/Source/core/frame/FrameView.cpp
+++ b/third_party/WebKit/Source/core/frame/FrameView.cpp
@@ -3801,6 +3801,10 @@
     if (isParentVisible() == visible)
         return;
 
+    // As parent visibility changes, we may need to recomposite this frame view and potentially child frame views.
+    if (PaintLayerCompositor* compositor = layoutView() ? layoutView()->compositor() : nullptr)
+        compositor->setNeedsCompositingUpdate(CompositingUpdateRebuildTree);
+
     Widget::setParentVisible(visible);
 
     if (!isSelfVisible())
diff --git a/third_party/WebKit/Source/core/frame/FrameViewTest.cpp b/third_party/WebKit/Source/core/frame/FrameViewTest.cpp
index 0b51874..ab9fd994 100644
--- a/third_party/WebKit/Source/core/frame/FrameViewTest.cpp
+++ b/third_party/WebKit/Source/core/frame/FrameViewTest.cpp
@@ -90,6 +90,8 @@
     {
         RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true);
         FrameViewTestBase::SetUp();
+        document().view()->setParentVisible(true);
+        document().view()->setSelfVisible(true);
     }
 
     void TearDown() override
diff --git a/third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp b/third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp
index 0d83855a..8d6a390 100644
--- a/third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp
@@ -67,6 +67,8 @@
     m_subframe = LocalFrame::create(m_frameLoaderClient.get(), document().frame()->host(), &iframe);
     m_subframe->setView(FrameView::create(m_subframe.get(), IntSize(500, 500)));
     m_subframe->init();
+    m_subframe->view()->setParentVisible(true);
+    m_subframe->view()->setSelfVisible(true);
     static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(m_subframe.get());
     document().frame()->host()->incrementSubframeCount();
     Document& frameDocument = *iframe.contentDocument();
diff --git a/third_party/WebKit/Source/core/layout/LayoutTestHelper.h b/third_party/WebKit/Source/core/layout/LayoutTestHelper.h
index 81eb4dce..b27abac 100644
--- a/third_party/WebKit/Source/core/layout/LayoutTestHelper.h
+++ b/third_party/WebKit/Source/core/layout/LayoutTestHelper.h
@@ -45,6 +45,8 @@
     void enableCompositing()
     {
         m_pageHolder->page().settings().setAcceleratedCompositingEnabled(true);
+        document().view()->setParentVisible(true);
+        document().view()->setSelfVisible(true);
         document().view()->updateAllLifecyclePhases();
     }
 
diff --git a/third_party/WebKit/Source/core/layout/compositing/PaintLayerCompositor.cpp b/third_party/WebKit/Source/core/layout/compositing/PaintLayerCompositor.cpp
index afe1f47..9b7b414 100644
--- a/third_party/WebKit/Source/core/layout/compositing/PaintLayerCompositor.cpp
+++ b/third_party/WebKit/Source/core/layout/compositing/PaintLayerCompositor.cpp
@@ -767,6 +767,11 @@
 
 bool PaintLayerCompositor::canBeComposited(const PaintLayer* layer) const
 {
+    FrameView* frameView = layer->layoutObject()->frameView();
+    // Elements within an invisible frame must not be composited because they are not drawn.
+    if (frameView && !frameView->isVisible())
+        return false;
+
     const bool hasCompositorAnimation = m_compositingReasonFinder.requiresCompositingForAnimation(*layer->layoutObject()->style());
     return m_hasAcceleratedCompositing && (hasCompositorAnimation || !layer->subtreeIsInvisible()) && layer->isSelfPaintingLayer() && !layer->layoutObject()->isLayoutFlowThread();
 }
diff --git a/third_party/WebKit/Source/web/WebPagePopupImpl.cpp b/third_party/WebKit/Source/web/WebPagePopupImpl.cpp
index 541a2787..f457c23 100644
--- a/third_party/WebKit/Source/web/WebPagePopupImpl.cpp
+++ b/third_party/WebKit/Source/web/WebPagePopupImpl.cpp
@@ -259,6 +259,8 @@
     frame->setPagePopupOwner(m_popupClient->ownerElement());
     frame->setView(FrameView::create(frame.get()));
     frame->init();
+    frame->view()->setParentVisible(true);
+    frame->view()->setSelfVisible(true);
     frame->view()->setTransparent(false);
     if (AXObjectCache* cache = m_popupClient->ownerElement().document().existingAXObjectCache())
         cache->childrenChanged(&m_popupClient->ownerElement());