Assorted cleanup of RenderLayer.

-Move perspectiveOrigin to RenderBox. It's only used in
one place and called on a RenderBox.
-Inline some methods that were just calling out to the renderer.
-Inline updateStackingNode() into the constructor and remove
the branch since requiresStackingNode is always true.
-Delete a bunch of dead code.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/961053002
diff --git a/sky/engine/core/rendering/RenderBox.cpp b/sky/engine/core/rendering/RenderBox.cpp
index c47ab38..87dd460 100644
--- a/sky/engine/core/rendering/RenderBox.cpp
+++ b/sky/engine/core/rendering/RenderBox.cpp
@@ -281,6 +281,17 @@
     return localToAbsoluteQuad(FloatRect(rect));
 }
 
+FloatPoint RenderBox::perspectiveOrigin() const
+{
+    if (!hasTransform())
+        return FloatPoint();
+
+    const LayoutRect borderBox = borderBoxRect();
+    return FloatPoint(
+        floatValueForLength(style()->perspectiveOriginX(), borderBox.width().toFloat()),
+        floatValueForLength(style()->perspectiveOriginY(), borderBox.height().toFloat()));
+}
+
 void RenderBox::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint& additionalOffset, const RenderBox*) const
 {
     if (!size().isEmpty())
@@ -835,7 +846,7 @@
         }
     }
 
-    if (layer()->isTransparent()) {
+    if (isTransparent()) {
         context->save();
         LayoutRect clipRect = intersection(paintingInfo.paintDirtyRect,
             transparencyClipBox(layer(), localPaintingInfo.rootLayer, localPaintingInfo.subPixelAccumulation));
@@ -873,7 +884,7 @@
 
     layer()->restoreClip(context, localPaintingInfo.paintDirtyRect, contentRect);
 
-    if (layer()->isTransparent()) {
+    if (isTransparent()) {
         context->endLayer();
         context->restore();
     }
diff --git a/sky/engine/core/rendering/RenderBox.h b/sky/engine/core/rendering/RenderBox.h
index 7f91918..8ce3293 100644
--- a/sky/engine/core/rendering/RenderBox.h
+++ b/sky/engine/core/rendering/RenderBox.h
@@ -172,6 +172,8 @@
     // The content box converted to absolute coords (taking transforms into account).
     FloatQuad absoluteContentQuad() const;
 
+    FloatPoint perspectiveOrigin() const;
+
     // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
     // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
     LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
diff --git a/sky/engine/core/rendering/RenderLayer.cpp b/sky/engine/core/rendering/RenderLayer.cpp
index 0414075..644a5af 100644
--- a/sky/engine/core/rendering/RenderLayer.cpp
+++ b/sky/engine/core/rendering/RenderLayer.cpp
@@ -92,8 +92,7 @@
     , m_last(0)
     , m_clipper(*renderer)
 {
-    updateStackingNode();
-
+    m_stackingNode = adoptPtr(new RenderLayerStackingNode(this));
     m_isSelfPaintingLayer = shouldBeSelfPaintingLayer();
 }
 
@@ -102,33 +101,15 @@
     removeFilterInfoIfNeeded();
 }
 
-String RenderLayer::debugName() const
-{
-    return renderer()->debugName();
-}
-
-LayoutSize RenderLayer::subpixelAccumulation() const
-{
-    return m_subpixelAccumulation;
-}
-
-void RenderLayer::setSubpixelAccumulation(const LayoutSize& size)
-{
-    m_subpixelAccumulation = size;
-}
-
 void RenderLayer::updateLayerPositionsAfterLayout()
 {
-    TRACE_EVENT0("blink", "RenderLayer::updateLayerPositionsAfterLayout");
-
     m_clipper.clearClipRectsIncludingDescendants();
 }
 
 void RenderLayer::updateTransformationMatrix()
 {
     if (m_transform) {
-        RenderBox* box = renderBox();
-        ASSERT(box);
+        RenderBox* box = renderer();
         m_transform->makeIdentity();
         box->style()->applyTransform(*m_transform, box->pixelSnappedBorderBoxRect().size(), RenderStyle::IncludeTransformOrigin);
         // FIXME(sky): We shouldn't need to do this once Skia has 4x4 matrix support.
@@ -166,38 +147,6 @@
         dirty3DTransformedDescendantStatus();
 }
 
-static RenderLayer* enclosingLayerForContainingBlock(RenderLayer* layer)
-{
-    if (RenderObject* containingBlock = layer->renderer()->containingBlock())
-        return containingBlock->enclosingLayer();
-    return 0;
-}
-
-RenderLayer* RenderLayer::renderingContextRoot()
-{
-    RenderLayer* renderingContext = 0;
-
-    if (shouldPreserve3D())
-        renderingContext = this;
-
-    for (RenderLayer* current = enclosingLayerForContainingBlock(this); current && current->shouldPreserve3D(); current = enclosingLayerForContainingBlock(current))
-        renderingContext = current;
-
-    return renderingContext;
-}
-
-RenderLayer* RenderLayer::enclosingOverflowClipLayer(IncludeSelfOrNot includeSelf) const
-{
-    const RenderLayer* layer = (includeSelf == IncludeSelf) ? this : parent();
-    while (layer) {
-        if (layer->renderer()->hasOverflowClip())
-            return const_cast<RenderLayer*>(layer);
-
-        layer = layer->parent();
-    }
-    return 0;
-}
-
 void RenderLayer::dirty3DTransformedDescendantStatus()
 {
     RenderLayerStackingNode* stackingNode = m_stackingNode->ancestorStackingContextNode();
@@ -241,14 +190,9 @@
 
 IntSize RenderLayer::size() const
 {
-    if (renderer()->isInline() && renderer()->isRenderInline())
-        return toRenderInline(renderer())->linesBoundingBox().size();
-
     // FIXME: Is snapping the size really needed here?
-    if (RenderBox* box = renderBox())
-        return pixelSnappedIntSize(box->size(), box->location());
-
-    return IntSize();
+    RenderBox* box = renderer();
+    return pixelSnappedIntSize(box->size(), box->location());
 }
 
 LayoutPoint RenderLayer::location() const
@@ -261,8 +205,8 @@
         IntRect lineBox = inlineFlow->linesBoundingBox();
         inlineBoundingBoxOffset = toSize(lineBox.location());
         localPoint += inlineBoundingBoxOffset;
-    } else if (RenderBox* box = renderBox()) {
-        localPoint += box->locationOffset();
+    } else {
+        localPoint += renderer()->locationOffset();
     }
 
     if (!renderer()->isOutOfFlowPositioned() && renderer()->parent()) {
@@ -285,47 +229,6 @@
     return localPoint;
 }
 
-TransformationMatrix RenderLayer::perspectiveTransform() const
-{
-    if (!renderer()->hasTransform())
-        return TransformationMatrix();
-
-    RenderStyle* style = renderer()->style();
-    if (!style->hasPerspective())
-        return TransformationMatrix();
-
-    // Maybe fetch the perspective from the backing?
-    const IntRect borderBox = renderer()->pixelSnappedBorderBoxRect();
-    const float boxWidth = borderBox.width();
-    const float boxHeight = borderBox.height();
-
-    float perspectiveOriginX = floatValueForLength(style->perspectiveOriginX(), boxWidth);
-    float perspectiveOriginY = floatValueForLength(style->perspectiveOriginY(), boxHeight);
-
-    // A perspective origin of 0,0 makes the vanishing point in the center of the element.
-    // We want it to be in the top-left, so subtract half the height and width.
-    perspectiveOriginX -= boxWidth / 2.0f;
-    perspectiveOriginY -= boxHeight / 2.0f;
-
-    TransformationMatrix t;
-    t.translate(perspectiveOriginX, perspectiveOriginY);
-    t.applyPerspective(style->perspective());
-    t.translate(-perspectiveOriginX, -perspectiveOriginY);
-
-    return t;
-}
-
-FloatPoint RenderLayer::perspectiveOrigin() const
-{
-    if (!renderer()->hasTransform())
-        return FloatPoint();
-
-    const LayoutRect borderBox = renderer()->borderBoxRect();
-    RenderStyle* style = renderer()->style();
-
-    return FloatPoint(floatValueForLength(style->perspectiveOriginX(), borderBox.width().toFloat()), floatValueForLength(style->perspectiveOriginY(), borderBox.height().toFloat()));
-}
-
 RenderLayer* RenderLayer::enclosingPositionedAncestor() const
 {
     RenderLayer* curr = parent();
@@ -527,14 +430,6 @@
     rect.move(-delta.x(), -delta.y());
 }
 
-void RenderLayer::updateStackingNode()
-{
-    if (requiresStackingNode())
-        m_stackingNode = adoptPtr(new RenderLayerStackingNode(this));
-    else
-        m_stackingNode = nullptr;
-}
-
 static bool inContainingBlockChain(RenderLayer* startLayer, RenderLayer* endLayer)
 {
     if (startLayer == endLayer)
@@ -617,8 +512,7 @@
     if (renderer()->isInline() && renderer()->isRenderInline()) {
         result = toRenderInline(renderer())->linesVisualOverflowBoundingBox();
     } else {
-        RenderBox* box = renderBox();
-        ASSERT(box);
+        RenderBox* box = renderer();
         result = box->borderBoxRect();
         result.unite(box->visualOverflowRect());
     }
@@ -716,22 +610,12 @@
     return m_layerType == NormalLayer;
 }
 
-bool RenderLayer::hasBoxDecorationsOrBackground() const
-{
-    return renderer()->style()->hasBoxDecorations() || renderer()->style()->hasBackground();
-}
-
-bool RenderLayer::hasVisibleBoxDecorations() const
-{
-    return hasBoxDecorationsOrBackground();
-}
-
 void RenderLayer::updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle)
 {
     if (!newStyle->hasFilter() && (!oldStyle || !oldStyle->hasFilter()))
         return;
 
-    if (!hasFilter()) {
+    if (!renderer()->hasFilter()) {
         removeFilterInfoIfNeeded();
         return;
     }
diff --git a/sky/engine/core/rendering/RenderLayer.h b/sky/engine/core/rendering/RenderLayer.h
index 3916819..8c8815a 100644
--- a/sky/engine/core/rendering/RenderLayer.h
+++ b/sky/engine/core/rendering/RenderLayer.h
@@ -73,11 +73,7 @@
     RenderLayer(RenderBox*, LayerType);
     ~RenderLayer();
 
-    String debugName() const;
-
     RenderBox* renderer() const { return m_renderer; }
-    // FIXME(sky): Remove
-    RenderBox* renderBox() const { return m_renderer; }
     RenderLayer* parent() const { return m_parent; }
     RenderLayer* previousSibling() const { return m_previous; }
     RenderLayer* nextSibling() const { return m_next; }
@@ -91,14 +87,9 @@
     void insertOnlyThisLayer();
 
     void styleChanged(StyleDifference, const RenderStyle* oldStyle);
-
-    // FIXME: Many people call this function while it has out-of-date information.
     bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; }
-
     void setLayerType(LayerType layerType) { m_layerType = layerType; }
 
-    bool isTransparent() const { return renderer()->isTransparent(); }
-
     const RenderLayer* root() const
     {
         const RenderLayer* curr = this;
@@ -109,30 +100,20 @@
 
     LayoutPoint location() const;
     IntSize size() const;
-
     LayoutRect rect() const { return LayoutRect(location(), size()); }
 
     bool isRootLayer() const { return m_isRootLayer; }
 
     void updateLayerPositionsAfterLayout();
-
     void updateTransformationMatrix();
-    RenderLayer* renderingContextRoot();
 
     RenderLayerStackingNode* stackingNode() { return m_stackingNode.get(); }
     const RenderLayerStackingNode* stackingNode() const { return m_stackingNode.get(); }
 
-    bool hasBoxDecorationsOrBackground() const;
-    bool hasVisibleBoxDecorations() const;
-    // True if this layer container renderers that paint.
-    bool hasNonEmptyChildRenderers() const;
-
     // Gets the nearest enclosing positioned ancestor layer (also includes
     // the <html> layer and the root layer).
     RenderLayer* enclosingPositionedAncestor() const;
 
-    RenderLayer* enclosingOverflowClipLayer(IncludeSelfOrNot = IncludeSelf) const;
-
     const RenderLayer* compositingContainer() const;
 
     void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint&) const;
@@ -144,25 +125,11 @@
     // Bounding box relative to some ancestor layer. Pass offsetFromRoot if known.
     LayoutRect physicalBoundingBox(const RenderLayer* ancestorLayer, const LayoutPoint* offsetFromRoot = 0) const;
     LayoutRect physicalBoundingBoxIncludingReflectionAndStackingChildren(const RenderLayer* ancestorLayer, const LayoutPoint& offsetFromRoot) const;
-
-    // If true, this layer's children are included in its bounds for overlap testing.
-    // We can't rely on the children's positions if this layer has a filter that could have moved the children's pixels around.
-    bool overlapBoundsIncludeChildren() const { return hasFilter() && renderer()->style()->filter().hasFilterThatMovesPixels(); }
-
     LayoutRect boundingBoxForCompositing(const RenderLayer* ancestorLayer = 0) const;
 
-    LayoutSize subpixelAccumulation() const;
-    void setSubpixelAccumulation(const LayoutSize&);
-
-    bool hasTransform() const { return renderer()->hasTransform(); }
     // This transform has the transform-origin baked in.
     TransformationMatrix* transform() const { return m_transform.get(); }
 
-    // Get the perspective transform, which is applied to transformed sublayers.
-    // Returns true if the layer has a -webkit-perspective.
-    // Note that this transform has the perspective-origin baked in.
-    TransformationMatrix perspectiveTransform() const;
-    FloatPoint perspectiveOrigin() const;
     bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
     bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
 
@@ -173,8 +140,6 @@
     // FIXME: reflections should force transform-style to be flat in the style: https://bugs.webkit.org/show_bug.cgi?id=106959
     bool shouldPreserve3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
 
-    bool hasFilter() const { return renderer()->hasFilter(); }
-
     void* operator new(size_t);
     // Only safe to call from RenderBox::destroyLayer()
     void operator delete(void*);
@@ -196,16 +161,13 @@
     bool hasFilterInfo() const { return m_hasFilterInfo; }
     void setHasFilterInfo(bool hasFilterInfo) { m_hasFilterInfo = hasFilterInfo; }
 
-    void updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle);
-
     RenderLayerClipper& clipper() { return m_clipper; }
     const RenderLayerClipper& clipper() const { return m_clipper; }
 
     inline bool isPositionedContainer() const
     {
         // FIXME: This is not in sync with containingBlock.
-        RenderBox* layerRenderer = renderer();
-        return isRootLayer() || layerRenderer->isPositioned() || hasTransform();
+        return isRootLayer() || renderer()->isPositioned() || renderer()->hasTransform();
     }
 
     void clipToRect(const LayerPaintingInfo&, GraphicsContext*, const ClipRect&, BorderRadiusClippingRule = IncludeSelfForBorderRadius);
@@ -220,14 +182,9 @@
     void setFirstChild(RenderLayer* first) { m_first = first; }
     void setLastChild(RenderLayer* last) { m_last = last; }
 
-    LayoutPoint renderBoxLocation() const { return renderer()->location(); }
-
     bool shouldBeSelfPaintingLayer() const;
 
-    // FIXME: We should only create the stacking node if needed.
-    bool requiresStackingNode() const { return true; }
-    void updateStackingNode();
-
+    void updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle);
     void updateTransform(const RenderStyle* oldStyle, RenderStyle* newStyle);
 
     void dirty3DTransformedDescendantStatus();
@@ -260,8 +217,6 @@
 
     RenderLayerClipper m_clipper; // FIXME: Lazily allocate?
     OwnPtr<RenderLayerStackingNode> m_stackingNode;
-
-    LayoutSize m_subpixelAccumulation; // The accumulated subpixel offset of a composited layer's composited bounds compared to absolute coordinates.
 };
 
 } // namespace blink
diff --git a/sky/engine/core/rendering/RenderObject.cpp b/sky/engine/core/rendering/RenderObject.cpp
index 9a6ca0b..59d41ff 100644
--- a/sky/engine/core/rendering/RenderObject.cpp
+++ b/sky/engine/core/rendering/RenderObject.cpp
@@ -1432,7 +1432,7 @@
     if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) {
         // Perpsective on the container affects us, so we have to factor it in here.
         ASSERT(containerObject->hasLayer());
-        FloatPoint perspectiveOrigin = toRenderBox(containerObject)->layer()->perspectiveOrigin();
+        FloatPoint perspectiveOrigin = toRenderBox(containerObject)->perspectiveOrigin();
 
         TransformationMatrix perspectiveMatrix;
         perspectiveMatrix.applyPerspective(containerObject->style()->perspective());
diff --git a/sky/engine/core/rendering/RenderTreeAsText.cpp b/sky/engine/core/rendering/RenderTreeAsText.cpp
index 2546bca..4b12bf7 100644
--- a/sky/engine/core/rendering/RenderTreeAsText.cpp
+++ b/sky/engine/core/rendering/RenderTreeAsText.cpp
@@ -356,8 +356,6 @@
         if (!adjustedClipRect.contains(adjustedLayoutBounds))
             ts << " clip " << adjustedClipRect;
     }
-    if (l.isTransparent())
-        ts << " transparent";
 
     ts << "\n";
     write(ts, *l.renderer(), indent + 1, behavior);
@@ -369,8 +367,8 @@
     // FIXME: Apply overflow to the root layer to not break every test. Complete hack. Sigh.
     LayoutRect paintDirtyRect(paintRect);
     if (rootLayer == layer) {
-        paintDirtyRect.setWidth(max<LayoutUnit>(paintDirtyRect.width(), rootLayer->renderBox()->layoutOverflowRect().maxX()));
-        paintDirtyRect.setHeight(max<LayoutUnit>(paintDirtyRect.height(), rootLayer->renderBox()->layoutOverflowRect().maxY()));
+        paintDirtyRect.setWidth(max<LayoutUnit>(paintDirtyRect.width(), rootLayer->renderer()->layoutOverflowRect().maxX()));
+        paintDirtyRect.setHeight(max<LayoutUnit>(paintDirtyRect.height(), rootLayer->renderer()->layoutOverflowRect().maxY()));
     }
 
     // Calculate the clip rects we should use.
@@ -380,7 +378,7 @@
 
     // FIXME: Apply overflow to the root layer to not break every test. Complete hack. Sigh.
     if (rootLayer == layer)
-        layerBounds.setSize(layer->size().expandedTo(pixelSnappedIntSize(layer->renderBox()->maxLayoutOverflow(), LayoutPoint(0, 0))));
+        layerBounds.setSize(layer->size().expandedTo(pixelSnappedIntSize(layer->renderer()->maxLayoutOverflow(), LayoutPoint(0, 0))));
 
     // Ensure our lists are up-to-date.
     layer->stackingNode()->updateLayerListsIfNeeded();