Prevent infinite loop when turning on then off composited mode

bug:5820635
Change-Id: I24b6eae6c76c29e44106b4ec87e74d945aad7b1b
diff --git a/Source/WebCore/rendering/RenderLayerCompositor.cpp b/Source/WebCore/rendering/RenderLayerCompositor.cpp
index 1ef3b77..33bf2f7 100644
--- a/Source/WebCore/rendering/RenderLayerCompositor.cpp
+++ b/Source/WebCore/rendering/RenderLayerCompositor.cpp
@@ -1366,7 +1366,21 @@
         return false;
 
     // The root layer always has a compositing layer, but it may not have backing.
+#if PLATFORM(ANDROID)
+    // If we do not have a root platform layer, don't use the
+    // mustOverlapCompositedLayers() as a cue that this layer needs to be
+    // composited -- the layers tree has been detached.
+    // Otherwise we can end up in a cycle where updateBacking() switches composited
+    // mode on because a layer has mustOverlapCompositedLayers() (by calling
+    // enableCompositingMode()), while computeCompositingRequirements() will
+    // (correctly) say that we do not need to be in composited mode and turns it
+    // off, rince and repeat...
+    return requiresCompositingLayer(layer)
+        || (m_rootPlatformLayer && layer->mustOverlapCompositedLayers())
+        || (inCompositingMode() && layer->isRootLayer());
+#else
     return requiresCompositingLayer(layer) || layer->mustOverlapCompositedLayers() || (inCompositingMode() && layer->isRootLayer());
+#endif
 }
 
 #if PLATFORM(ANDROID)