15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
28d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/rendering/compositing/RenderLayerCompositor.h"
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/animation/DocumentAnimations.h"
319e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)#include "core/dom/Fullscreen.h"
3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/frame/FrameView.h"
33d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/frame/LocalFrame.h"
3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/frame/Settings.h"
3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLIFrameElement.h"
3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorInstrumentation.h"
37d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "core/inspector/InspectorNodeIds.h"
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/Chrome.h"
39197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/page/ChromeClient.h"
4053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/Page.h"
4153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/scrolling/ScrollingCoordinator.h"
42197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/rendering/RenderEmbeddedObject.h"
43f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "core/rendering/RenderLayerStackingNode.h"
44f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "core/rendering/RenderLayerStackingNodeIterator.h"
45197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/rendering/RenderPart.h"
4653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderVideo.h"
4753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderView.h"
48d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/rendering/compositing/CompositedLayerMapping.h"
495d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "core/rendering/compositing/CompositingInputsUpdater.h"
50323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)#include "core/rendering/compositing/CompositingLayerAssigner.h"
51a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch#include "core/rendering/compositing/CompositingRequirementsUpdater.h"
525d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "core/rendering/compositing/GraphicsLayerTreeBuilder.h"
53d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/rendering/compositing/GraphicsLayerUpdater.h"
54a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/OverscrollTheme.h"
555d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "platform/RuntimeEnabledFeatures.h"
56197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "platform/ScriptForbiddenScope.h"
571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/TraceEvent.h"
58a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/GraphicsLayer.h"
59f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "public/platform/Platform.h"
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
61c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
63d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)RenderLayerCompositor::RenderLayerCompositor(RenderView& renderView)
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    : m_renderView(renderView)
65d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    , m_compositingReasonFinder(renderView)
66aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    , m_pendingUpdateType(CompositingUpdateNone)
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_hasAcceleratedCompositing(true)
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_compositing(false)
6910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    , m_rootShouldAlwaysCompositeDirty(true)
7010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    , m_needsUpdateFixedBackground(false)
71e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    , m_isTrackingPaintInvalidations(false)
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_rootLayerAttachment(RootLayerUnattached)
735d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_inOverlayFullscreenVideo(false)
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
756f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    updateAcceleratedCompositingSettings();
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)RenderLayerCompositor::~RenderLayerCompositor()
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(m_rootLayerAttachment == RootLayerUnattached);
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochbool RenderLayerCompositor::inCompositingMode() const
8410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch{
85f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // FIXME: This should assert that lificycle is >= CompositingClean since
86f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // the last step of updateIfNeeded can set this bit to false.
8710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    ASSERT(!m_rootShouldAlwaysCompositeDirty);
8810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    return m_compositing;
8910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch}
9010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
9110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochbool RenderLayerCompositor::staleInCompositingMode() const
9210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch{
9310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    return m_compositing;
9410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch}
9510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
9610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochvoid RenderLayerCompositor::setCompositingModeEnabled(bool enable)
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
9807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    if (enable == m_compositing)
9907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        return;
10002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
10107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    m_compositing = enable;
10207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
103f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // RenderPart::requiresAcceleratedCompositing is used to determine self-paintingness
104f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // and bases it's return value for frames on the m_compositing bit here.
105f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement()) {
106f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        if (RenderPart* renderer = ownerElement->renderPart())
107f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)            renderer->layer()->updateSelfPaintingLayer();
108f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    }
109f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
11007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    if (m_compositing)
11107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        ensureRootLayer();
11207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    else
11307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        destroyRootLayer();
11407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
115f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // Compositing also affects the answer to RenderIFrame::requiresAcceleratedCompositing(), so
116f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    // we need to schedule a style recalc in our parent document.
117f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement())
118f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        ownerElement->setNeedsCompositingUpdate();
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
12110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochvoid RenderLayerCompositor::enableCompositingModeIfNeeded()
1226f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch{
12310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (!m_rootShouldAlwaysCompositeDirty)
12410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        return;
12510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
12610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    m_rootShouldAlwaysCompositeDirty = false;
12710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (m_compositing)
12810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        return;
12910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
13010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (rootShouldAlwaysComposite()) {
13110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        // FIXME: Is this needed? It was added in https://bugs.webkit.org/show_bug.cgi?id=26651.
13210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        // No tests fail if it's deleted.
1335d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        setNeedsCompositingUpdate(CompositingUpdateRebuildTree);
13410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        setCompositingModeEnabled(true);
1356f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    }
1366f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch}
1376f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch
13810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochbool RenderLayerCompositor::rootShouldAlwaysComposite() const
13910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch{
1405d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (!m_hasAcceleratedCompositing)
1415d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        return false;
142197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    return m_renderView.frame()->isLocalRoot() || m_compositingReasonFinder.requiresCompositingForScrollableFrame();
14310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch}
1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
14510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochvoid RenderLayerCompositor::updateAcceleratedCompositingSettings()
14610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch{
14710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    m_compositingReasonFinder.updateTriggers();
1485d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    m_hasAcceleratedCompositing = m_renderView.document().settings()->acceleratedCompositingEnabled();
14910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    m_rootShouldAlwaysCompositeDirty = true;
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
15209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool RenderLayerCompositor::layerSquashingEnabled() const
15351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
154f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    if (!RuntimeEnabledFeatures::layerSquashingEnabled())
155f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        return false;
156d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (Settings* settings = m_renderView.document().settings())
15709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return settings->layerSquashingEnabled();
15810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    return true;
15951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
16051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
1619e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)bool RenderLayerCompositor::preferCompositingToLCDTextEnabled() const
162a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch{
163a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    return m_compositingReasonFinder.hasOverflowScrollTrigger();
164a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch}
165a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch
166d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)static RenderVideo* findFullscreenVideoRenderer(Document& document)
16706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles){
168c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    // Recursively find the document that is in fullscreen.
1699e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    Element* fullscreenElement = Fullscreen::fullscreenElementFrom(document);
170c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    Document* contentDocument = &document;
17106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    while (fullscreenElement && fullscreenElement->isFrameOwnerElement()) {
172c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        contentDocument = toHTMLFrameOwnerElement(fullscreenElement)->contentDocument();
173d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (!contentDocument)
17406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)            return 0;
1759e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        fullscreenElement = Fullscreen::fullscreenElementFrom(*contentDocument);
17606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    }
177c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    // Get the current fullscreen element from the document.
1789e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    fullscreenElement = Fullscreen::currentFullScreenElementFrom(*contentDocument);
179d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (!isHTMLVideoElement(fullscreenElement))
18006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)        return 0;
18106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    RenderObject* renderer = fullscreenElement->renderer();
18206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    if (!renderer)
18306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)        return 0;
18406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    return toRenderVideo(renderer);
18506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)}
18606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
187a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdochvoid RenderLayerCompositor::updateIfNeededRecursive()
18819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){
1895d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    for (Frame* child = m_renderView.frameView()->frame().tree().firstChild(); child; child = child->tree().nextSibling()) {
1905d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        if (child->isLocalFrame())
1915d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            toLocalFrame(child)->contentRenderer()->compositor()->updateIfNeededRecursive();
1925d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    }
19319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)
194e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    TRACE_EVENT0("blink", "RenderLayerCompositor::updateIfNeededRecursive");
195a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch
196a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    ASSERT(!m_renderView.needsLayout());
19710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
198f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    ScriptForbiddenScope forbidScript;
199f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
2005d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // FIXME: enableCompositingModeIfNeeded can trigger a CompositingUpdateRebuildTree,
2015d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // which asserts that it's not InCompositingUpdate.
2025d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    enableCompositingModeIfNeeded();
203e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
204e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    rootRenderLayer()->updateDescendantDependentFlagsForEntireSubtree();
205a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch
2065d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    lifecycle().advanceTo(DocumentLifecycle::InCompositingUpdate);
207a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    updateIfNeeded();
208a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    lifecycle().advanceTo(DocumentLifecycle::CompositingClean);
209a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch
210a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    DocumentAnimations::startPendingAnimations(m_renderView.document());
211d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
212197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(ASSERT)
213197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    ASSERT(lifecycle().state() == DocumentLifecycle::CompositingClean);
214d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    assertNoUnresolvedDirtyBits();
2155d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    for (Frame* child = m_renderView.frameView()->frame().tree().firstChild(); child; child = child->tree().nextSibling()) {
2165d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        if (child->isLocalFrame())
2175d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            toLocalFrame(child)->contentRenderer()->compositor()->assertNoUnresolvedDirtyBits();
2185d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    }
219f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#endif
22019cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)}
22119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)
22209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void RenderLayerCompositor::setNeedsCompositingUpdate(CompositingUpdateType updateType)
2235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
224aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    ASSERT(updateType != CompositingUpdateNone);
225aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    m_pendingUpdateType = std::max(m_pendingUpdateType, updateType);
22607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    page()->animator().scheduleVisualUpdate();
2276f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    lifecycle().ensureStateAtMost(DocumentLifecycle::LayoutClean);
22807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
22907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
2305d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)void RenderLayerCompositor::didLayout()
2315d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles){
2325d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // FIXME: Technically we only need to do this when the FrameView's
2335d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // isScrollable method would return a different value.
2345d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    m_rootShouldAlwaysCompositeDirty = true;
2355d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    enableCompositingModeIfNeeded();
2365d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
2375d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // FIXME: Rather than marking the entire RenderView as dirty, we should
2385d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // track which RenderLayers moved during layout and only dirty those
2395d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // specific RenderLayers.
2405d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    rootRenderLayer()->setNeedsCompositingInputsUpdate();
2415d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)}
2425d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
243197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(ASSERT)
244f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
245d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)void RenderLayerCompositor::assertNoUnresolvedDirtyBits()
24607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch{
247d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    ASSERT(m_pendingUpdateType == CompositingUpdateNone);
248d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    ASSERT(!m_rootShouldAlwaysCompositeDirty);
24907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
25007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
251f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#endif
252f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
253d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)void RenderLayerCompositor::applyOverlayFullscreenVideoAdjustment()
25407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch{
2555d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    m_inOverlayFullscreenVideo = false;
256d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    if (!m_rootContentLayer)
257d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        return;
258d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
259197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool isLocalRoot = m_renderView.frame()->isLocalRoot();
260d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    RenderVideo* video = findFullscreenVideoRenderer(m_renderView.document());
261197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (!video || !video->layer()->hasCompositedLayerMapping()) {
262197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        if (isLocalRoot) {
263d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)            GraphicsLayer* backgroundLayer = fixedRootBackgroundLayer();
264d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)            if (backgroundLayer && !backgroundLayer->parent())
265d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)                rootFixedBackgroundsChanged();
266d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        }
267d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        return;
268d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    }
269d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
270197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    GraphicsLayer* videoLayer = video->layer()->compositedLayerMapping()->mainGraphicsLayer();
271d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
272d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // The fullscreen video has layer position equal to its enclosing frame's scroll position because fullscreen container is fixed-positioned.
273d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // We should reset layer position here since we are going to reattach the layer at the very top level.
274d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    videoLayer->setPosition(IntPoint());
275d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
276d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    // Only steal fullscreen video layer and clear all other layers if we are the main frame.
277197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (!isLocalRoot)
278d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        return;
279d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
280d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    m_rootContentLayer->removeAllChildren();
281d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    m_overflowControlsHostLayer->addChild(videoLayer);
282d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    if (GraphicsLayer* backgroundLayer = fixedRootBackgroundLayer())
283d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        backgroundLayer->removeFromParent();
2845d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    m_inOverlayFullscreenVideo = true;
28507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
28607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
287e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)void RenderLayerCompositor::updateWithoutAcceleratedCompositing(CompositingUpdateType updateType)
288e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles){
289e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    ASSERT(!hasAcceleratedCompositing());
290e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
291e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    if (updateType >= CompositingUpdateAfterCompositingInputChange)
292e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        CompositingInputsUpdater(rootRenderLayer()).update();
293e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
294e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)#if ENABLE(ASSERT)
295e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    CompositingInputsUpdater::assertNeedsCompositingInputsUpdateBitsCleared(rootRenderLayer());
296e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)#endif
297e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)}
298e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
2997242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccistatic void forceRecomputePaintInvalidationRectsIncludingNonCompositingDescendants(RenderObject* renderer)
3007242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci{
3017242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // We clear the previous paint invalidation rect as it's wrong (paint invaliation container
3027242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // changed, ...). Forcing a full invalidation will make us recompute it. Also we are not
3037242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // changing the previous position from our paint invalidation container, which is fine as
3047242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // we want a full paint invalidation anyway.
3057242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    renderer->setPreviousPaintInvalidationRect(LayoutRect());
3067242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    renderer->setShouldDoFullPaintInvalidation(true);
3077242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
3087242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    for (RenderObject* child = renderer->slowFirstChild(); child; child = child->nextSibling()) {
3097242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        if (!child->isPaintInvalidationContainer())
3107242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            forceRecomputePaintInvalidationRectsIncludingNonCompositingDescendants(child);
3117242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    }
3127242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci}
3137242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
3147242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
315a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdochvoid RenderLayerCompositor::updateIfNeeded()
316d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
3176f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    CompositingUpdateType updateType = m_pendingUpdateType;
31810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    m_pendingUpdateType = CompositingUpdateNone;
31910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
320e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    if (!hasAcceleratedCompositing()) {
321e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        updateWithoutAcceleratedCompositing(updateType);
322e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        return;
323e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    }
324e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
325e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    if (updateType == CompositingUpdateNone)
32609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return;
32753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
32819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    RenderLayer* updateRoot = rootRenderLayer();
3295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
330e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    Vector<RenderLayer*> layersNeedingPaintInvalidation;
33107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
332f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (updateType >= CompositingUpdateAfterCompositingInputChange) {
333197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        CompositingInputsUpdater(updateRoot).update();
334197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
335197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(ASSERT)
336197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        // FIXME: Move this check to the end of the compositing update.
337197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        CompositingInputsUpdater::assertNeedsCompositingInputsUpdateBitsCleared(updateRoot);
33807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch#endif
33907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
340323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        CompositingRequirementsUpdater(m_renderView, m_compositingReasonFinder).update(updateRoot);
341f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
342197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        CompositingLayerAssigner layerAssigner(this);
343e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        layerAssigner.assign(updateRoot, layersNeedingPaintInvalidation);
344197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
345197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        bool layersChanged = layerAssigner.layersChanged();
34609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
34709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        {
348e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)            TRACE_EVENT0("blink", "RenderLayerCompositor::updateAfterCompositingChange");
349f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)            if (const FrameView::ScrollableAreaSet* scrollableAreas = m_renderView.frameView()->scrollableAreas()) {
350f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)                for (FrameView::ScrollableAreaSet::iterator it = scrollableAreas->begin(); it != scrollableAreas->end(); ++it)
351197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                    layersChanged |= (*it)->updateAfterCompositingChange();
352f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)            }
35353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        }
35409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
355d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (layersChanged)
3565d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            updateType = std::max(updateType, CompositingUpdateRebuildTree);
3575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
3585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3595d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (updateType != CompositingUpdateNone) {
360a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch        GraphicsLayerUpdater updater;
361e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        updater.update(*updateRoot, layersNeedingPaintInvalidation);
362a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch
363a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch        if (updater.needsRebuildTree())
3645d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            updateType = std::max(updateType, CompositingUpdateRebuildTree);
365a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch
366197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(ASSERT)
36707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        // FIXME: Move this check to the end of the compositing update.
36807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        GraphicsLayerUpdater::assertNeedsToUpdateGraphicsLayerBitsCleared(*updateRoot);
36907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch#endif
37007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    }
37107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
3725d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (updateType >= CompositingUpdateRebuildTree) {
373197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        GraphicsLayerTreeBuilder::AncestorInfo ancestorInfo;
374d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        GraphicsLayerVector childList;
375197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        ancestorInfo.childLayersOfEnclosingCompositedLayer = &childList;
37653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        {
377e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)            TRACE_EVENT0("blink", "GraphicsLayerTreeBuilder::rebuild");
378197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            GraphicsLayerTreeBuilder().rebuild(*updateRoot, ancestorInfo);
37953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        }
3805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
38109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (childList.isEmpty())
38219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            destroyRootLayer();
38319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)        else
38419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            m_rootContentLayer->setChildren(childList);
385d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
386d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled())
387d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)            applyOverlayFullscreenVideoAdjustment();
3885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
38902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
3906f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    if (m_needsUpdateFixedBackground) {
3916f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch        rootFixedBackgroundsChanged();
3926f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch        m_needsUpdateFixedBackground = false;
3936f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    }
3946f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch
3957242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    for (unsigned i = 0; i < layersNeedingPaintInvalidation.size(); i++)
3967242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        forceRecomputePaintInvalidationRectsIncludingNonCompositingDescendants(layersNeedingPaintInvalidation[i]->renderer());
397f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
398926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // Inform the inspector that the layer tree has changed.
39910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (m_renderView.frame()->isMainFrame())
40010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        InspectorInstrumentation::layerTreeDidChange(m_renderView.frame());
401926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
402926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
403d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)bool RenderLayerCompositor::allocateOrClearCompositedLayerMapping(RenderLayer* layer, const CompositingStateTransitionType compositedLayerUpdate)
4045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
40551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    bool compositedLayerMappingChanged = false;
4065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
40793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // FIXME: It would be nice to directly use the layer's compositing reason,
40851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    // but allocateOrClearCompositedLayerMapping also gets called without having updated compositing
40993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // requirements fully.
41009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    switch (compositedLayerUpdate) {
41109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case AllocateOwnCompositedLayerMapping:
41209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        ASSERT(!layer->hasCompositedLayerMapping());
413f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        setCompositingModeEnabled(true);
41402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
415e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        // If we need to issue paint invalidations, do so before allocating the compositedLayerMapping and clearing out the groupedMapping.
416e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        paintInvalidationOnCompositingChange(layer);
417c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
418f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        // If this layer was previously squashed, we need to remove its reference to a groupedMapping right away, so
419e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        // that computing paint invalidation rects will know the layer's correct compositingState.
420f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        // FIXME: do we need to also remove the layer from it's location in the squashing list of its groupedMapping?
421f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        // Need to create a test where a squashed layer pops into compositing. And also to cover all other
422f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        // sorts of compositingState transitions.
423f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        layer->setLostGroupedMapping(false);
424f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        layer->setGroupedMapping(0);
425f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
42609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        layer->ensureCompositedLayerMapping();
42709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        compositedLayerMappingChanged = true;
4285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
42909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // At this time, the ScrollingCooridnator only supports the top-level frame.
430197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        if (layer->isRootLayer() && m_renderView.frame()->isLocalRoot()) {
43109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
432d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                scrollingCoordinator->frameViewRootLayerDidChange(m_renderView.frameView());
4335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
43409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        break;
43509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case RemoveOwnCompositedLayerMapping:
43609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // PutInSquashingLayer means you might have to remove the composited layer mapping first.
43709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case PutInSquashingLayer:
43851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        if (layer->hasCompositedLayerMapping()) {
4391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            // If we're removing the compositedLayerMapping from a reflection, clear the source GraphicsLayer's pointer to
44002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch            // its replica GraphicsLayer. In practice this should never happen because reflectee and reflection
4415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // are both either composited, or not composited.
4425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (layer->isReflection()) {
4435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                RenderLayer* sourceLayer = toRenderLayerModelObject(layer->renderer()->parent())->layer();
44451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)                if (sourceLayer->hasCompositedLayerMapping()) {
44551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)                    ASSERT(sourceLayer->compositedLayerMapping()->mainGraphicsLayer()->replicaLayer() == layer->compositedLayerMapping()->mainGraphicsLayer());
44651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)                    sourceLayer->compositedLayerMapping()->mainGraphicsLayer()->setReplicatedByLayer(0);
4475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                }
4485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
4495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            layer->clearCompositedLayerMapping();
45151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            compositedLayerMappingChanged = true;
4525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
45309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
45409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        break;
45509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case RemoveFromSquashingLayer:
45609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case NoCompositingStateChange:
45709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        // Do nothing.
45809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        break;
4595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
46053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
4617242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (layer->hasCompositedLayerMapping() && layer->compositedLayerMapping()->updateRequiresOwnBackingStoreForIntrinsicReasons()) {
46209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        compositedLayerMappingChanged = true;
4637242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        layer->compositedLayerMapping()->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree);
4647242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    }
46509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
46651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (compositedLayerMappingChanged && layer->renderer()->isRenderPart()) {
4675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        RenderLayerCompositor* innerCompositor = frameContentsCompositor(toRenderPart(layer->renderer()));
46810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        if (innerCompositor && innerCompositor->staleInCompositingMode())
4695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            innerCompositor->updateRootLayerAttachment();
4705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
47102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
47251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (compositedLayerMappingChanged)
473bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        layer->clipper().clearClipRectsIncludingDescendants(PaintingClipRects);
4745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // If a fixed position layer gained/lost a compositedLayerMapping or the reason not compositing it changed,
476926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // the scrolling coordinator needs to recalculate whether it can do fast scrolling.
477e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    if (compositedLayerMappingChanged) {
47809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
479d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            scrollingCoordinator->frameViewFixedObjectsDidChange(m_renderView.frameView());
48009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
48109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
482e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    return compositedLayerMappingChanged;
48309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
48409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
485e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)void RenderLayerCompositor::paintInvalidationOnCompositingChange(RenderLayer* layer)
4865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
487e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // If the renderer is not attached yet, no need to issue paint invalidations.
488d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (layer->renderer() != &m_renderView && !layer->renderer()->parent())
4895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
4905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // For querying RenderLayer::compositingState()
4927242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // Eager invalidation here is correct, since we are invalidating with respect to the previous frame's
4937242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // compositing state when changing the compositing backing of the layer.
4947242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    DisableCompositingQueryAsserts disabler;
4957242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
4967242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    layer->renderer()->invalidatePaintIncludingNonCompositingDescendants();
4975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
4985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::frameViewDidChangeLocation(const IntPoint& contentsOffset)
5005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_overflowControlsHostLayer)
5025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_overflowControlsHostLayer->setPosition(contentsOffset);
5035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::frameViewDidChangeSize()
5065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
507e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    if (m_containerLayer) {
508d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        FrameView* frameView = m_renderView.frameView();
509e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_containerLayer->setSize(frameView->unscaledVisibleContentSize());
5107242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        m_overflowControlsHostLayer->setSize(frameView->unscaledVisibleContentSize(IncludeScrollbars));
5115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        frameViewDidScroll();
5135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        updateOverflowControlsLayers();
5145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
5155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)enum AcceleratedFixedRootBackgroundHistogramBuckets {
5188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ScrolledMainFrameBucket = 0,
5198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ScrolledMainFrameWithAcceleratedFixedRootBackground = 1,
5208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ScrolledMainFrameWithUnacceleratedFixedRootBackground = 2,
5218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    AcceleratedFixedRootBackgroundHistogramMax = 3
5228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)};
5238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
5245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::frameViewDidScroll()
5255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
526d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FrameView* frameView = m_renderView.frameView();
5275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    IntPoint scrollPosition = frameView->scrollPosition();
5285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_scrollLayer)
5305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
5315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
532e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    bool scrollingCoordinatorHandlesOffset = false;
5335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
534d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (Settings* settings = m_renderView.document().settings()) {
5359e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)            if (m_renderView.frame()->isLocalRoot() || settings->preferCompositingToLCDTextEnabled())
536e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch                scrollingCoordinatorHandlesOffset = scrollingCoordinator->scrollableAreaScrollLayerDidChange(frameView);
537926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        }
5385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
5395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
540e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // Scroll position = scroll minimum + scroll offset. Adjust the layer's
541e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // position to handle whatever the scroll coordinator isn't handling.
542e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // The minimum scroll position is non-zero for RTL pages with overflow.
543e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    if (scrollingCoordinatorHandlesOffset)
544e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_scrollLayer->setPosition(-frameView->minimumScrollPosition());
545e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    else
546e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_scrollLayer->setPosition(-scrollPosition);
5478abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
5488abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
549e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    Platform::current()->histogramEnumeration("Renderer.AcceleratedFixedRootBackground",
5508abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        ScrolledMainFrameBucket,
5518abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        AcceleratedFixedRootBackgroundHistogramMax);
5525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
5535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
554bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)void RenderLayerCompositor::frameViewScrollbarsExistenceDidChange()
555bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){
556bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (m_containerLayer)
557bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        updateOverflowControlsLayers();
558bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}
559bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
560926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void RenderLayerCompositor::rootFixedBackgroundsChanged()
561926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
562e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    if (!supportsFixedRootBackgroundCompositing())
563e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        return;
5645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
565e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // To avoid having to make the fixed root background layer fixed positioned to
566e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // stay put, we position it in the layer tree as follows:
567e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    //
568e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // + Overflow controls host
569d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    //   + LocalFrame clip
570e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    //     + (Fixed root background) <-- Here.
571d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    //     + LocalFrame scroll
572e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    //       + Root content layer
573e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    //   + Scrollbars
574e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    //
575e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // That is, it needs to be the first child of the frame clip, the sibling of
576e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // the frame scroll layer. The compositor does not own the background layer, it
577e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // just positions it (like the foreground layer).
578e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    if (GraphicsLayer* backgroundLayer = fixedRootBackgroundLayer())
579e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_containerLayer->addChildBelow(backgroundLayer, m_scrollLayer.get());
580e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}
581e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
582e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochbool RenderLayerCompositor::scrollingLayerDidChange(RenderLayer* layer)
5835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
585e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return scrollingCoordinator->scrollableAreaScrollLayerDidChange(layer->scrollableArea());
586e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    return false;
587926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
588926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
5895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String RenderLayerCompositor::layerTreeAsText(LayerTreeFlags flags)
5905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
591c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    ASSERT(lifecycle().state() >= DocumentLifecycle::PaintInvalidationClean);
5925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_rootContentLayer)
5945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return String();
5955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // We skip dumping the scroll and clip layers to keep layerTreeAsText output
597e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // similar between platforms (unless we explicitly request dumping from the
598e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // root.
599e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    GraphicsLayer* rootLayer = m_rootContentLayer.get();
600e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    if (flags & LayerTreeIncludesRootLayer)
601e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        rootLayer = rootGraphicsLayer();
602e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
603e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    String layerTreeText = rootLayer->layerTreeAsText(flags);
6045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // The true root layer is not included in the dump, so if we want to report
606e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    // its paint invalidation rects, they must be included here.
607e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    if (flags & LayerTreeIncludesPaintInvalidationRects)
608f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        return m_renderView.frameView()->trackedPaintInvalidationRectsAsText() + layerTreeText;
6095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return layerTreeText;
6115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)RenderLayerCompositor* RenderLayerCompositor::frameContentsCompositor(RenderPart* renderer)
6145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!renderer->node()->isFrameOwnerElement())
6165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
61702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
618e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(renderer->node());
6195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (Document* contentDocument = element->contentDocument()) {
6205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (RenderView* view = contentDocument->renderView())
6215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return view->compositor();
6225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
6235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
6245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
626d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)// FIXME: What does this function do? It needs a clearer name.
6275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderLayerCompositor::parentFrameContentLayers(RenderPart* renderer)
6285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderLayerCompositor* innerCompositor = frameContentsCompositor(renderer);
63010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (!innerCompositor || !innerCompositor->staleInCompositingMode() || innerCompositor->rootLayerAttachment() != RootLayerAttachedViaEnclosingFrame)
6315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
63202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
6335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderLayer* layer = renderer->layer();
63451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    if (!layer->hasCompositedLayerMapping())
6355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
6365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
637e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    CompositedLayerMapping* compositedLayerMapping = layer->compositedLayerMapping();
6381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    GraphicsLayer* hostingLayer = compositedLayerMapping->parentForSublayers();
6395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    GraphicsLayer* rootLayer = innerCompositor->rootGraphicsLayer();
6405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != rootLayer) {
6415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        hostingLayer->removeAllChildren();
6425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        hostingLayer->addChild(rootLayer);
6435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
6445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
6455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
647c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)static void fullyInvalidatePaintRecursive(RenderLayer* layer)
6485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6495d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    if (layer->compositingState() == PaintsIntoOwnBacking) {
6505d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        layer->compositedLayerMapping()->setContentsNeedDisplay();
6515d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        layer->compositedLayerMapping()->setSquashingContentsNeedDisplay();
6525d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    }
6535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
654c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    for (RenderLayer* child = layer->firstChild(); child; child = child->nextSibling())
655c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        fullyInvalidatePaintRecursive(child);
656c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)}
6575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
658c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)void RenderLayerCompositor::fullyInvalidatePaint()
659c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){
660c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    // We're walking all compositing layers and invalidating them, so there's
661c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    // no need to have up-to-date compositing state.
662c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    DisableCompositingQueryAsserts disabler;
663c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    fullyInvalidatePaintRecursive(rootRenderLayer());
6645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)RenderLayer* RenderLayerCompositor::rootRenderLayer() const
6675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
668d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return m_renderView.layer();
6695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)GraphicsLayer* RenderLayerCompositor::rootGraphicsLayer() const
6725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_overflowControlsHostLayer)
6745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return m_overflowControlsHostLayer.get();
6755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return m_rootContentLayer.get();
6765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)GraphicsLayer* RenderLayerCompositor::scrollLayer() const
6795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return m_scrollLayer.get();
6815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
68309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)GraphicsLayer* RenderLayerCompositor::containerLayer() const
68409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
68509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return m_containerLayer.get();
68609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
68709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
688d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)GraphicsLayer* RenderLayerCompositor::ensureRootTransformLayer()
689d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
690d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    ASSERT(rootGraphicsLayer());
691d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
692d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (!m_rootTransformLayer.get()) {
693d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_rootTransformLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
694d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_overflowControlsHostLayer->addChild(m_rootTransformLayer.get());
695d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_rootTransformLayer->addChild(m_containerLayer.get());
696d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        updateOverflowControlsLayers();
697d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
698d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
699d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return m_rootTransformLayer.get();
700d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
701d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
702926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void RenderLayerCompositor::setIsInWindow(bool isInWindow)
7035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
70410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (!staleInCompositingMode())
7055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
7065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
707926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (isInWindow) {
708926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (m_rootLayerAttachment != RootLayerUnattached)
709926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            return;
7105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
711197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        RootLayerAttachment attachment = m_renderView.frame()->isLocalRoot() ? RootLayerAttachedViaChromeClient : RootLayerAttachedViaEnclosingFrame;
712926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        attachRootLayer(attachment);
713926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    } else {
714926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (m_rootLayerAttachment == RootLayerUnattached)
715926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            return;
7165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
717926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        detachRootLayer();
718926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
7195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::updateRootLayerPosition()
7225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_rootContentLayer) {
724d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        const IntRect& documentRect = m_renderView.documentRect();
7255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_rootContentLayer->setSize(documentRect.size());
7265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_rootContentLayer->setPosition(documentRect.location());
72706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#if USE(RUBBER_BANDING)
728c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        if (m_layerForOverhangShadow)
729f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)            OverscrollTheme::theme()->updateOverhangShadowLayer(m_layerForOverhangShadow.get(), m_rootContentLayer.get());
730c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)#endif
7315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
732e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    if (m_containerLayer) {
733d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        FrameView* frameView = m_renderView.frameView();
734e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_containerLayer->setSize(frameView->unscaledVisibleContentSize());
7357242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        m_overflowControlsHostLayer->setSize(frameView->unscaledVisibleContentSize(IncludeScrollbars));
7365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
7375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
739197021e6b966cfb06891637935ef33fff06433d1Ben Murdochvoid RenderLayerCompositor::updatePotentialCompositingReasonsFromStyle(RenderLayer* layer)
7405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
741197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    layer->setPotentialCompositingReasonsFromStyle(m_compositingReasonFinder.potentialCompositingReasonsFromStyle(layer->renderer()));
7425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
74451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void RenderLayerCompositor::updateDirectCompositingReasons(RenderLayer* layer)
74551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
746197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    layer->setCompositingReasons(m_compositingReasonFinder.directReasons(layer), CompositingReasonComboAllDirectReasons);
74751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
74851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
749f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)void RenderLayerCompositor::setOverlayLayer(GraphicsLayer* layer)
750f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles){
751f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    ASSERT(rootGraphicsLayer());
752f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
753f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    if (layer->parent() != m_overflowControlsHostLayer.get())
754f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        m_overflowControlsHostLayer->addChild(layer);
755f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)}
756f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
7575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderLayerCompositor::canBeComposited(const RenderLayer* layer) const
7585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // FIXME: We disable accelerated compositing for elements in a RenderFlowThread as it doesn't work properly.
7605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // See http://webkit.org/b/84900 to re-enable it.
761d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    return m_hasAcceleratedCompositing && layer->isSelfPaintingLayer() && !layer->subtreeIsInvisible() && layer->renderer()->flowThreadState() == RenderObject::NotInsideFlowThread;
7625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Return true if the given layer is a stacking context and has compositing child
7655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// layers that it needs to clip. In this case we insert a clipping GraphicsLayer
7665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// into the hierarchy between this layer and its children in the z-order hierarchy.
7675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderLayerCompositor::clipsCompositingDescendants(const RenderLayer* layer) const
7685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return layer->hasCompositingDescendant() && layer->renderer()->hasClipOrOverflowClip();
7705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7727242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci// If an element has composited negative z-index children, those children render in front of the
7735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// layer background, so we need an extra 'contents' layer for the foreground of the layer
7745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// object.
7755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderLayerCompositor::needsContentsCompositingLayer(const RenderLayer* layer) const
7765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7777242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (!layer->hasCompositingDescendant())
7787242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        return false;
779bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    return layer->stackingNode()->hasNegativeZOrderList();
7805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRect& clip)
7835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!scrollbar)
7855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
7865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    context.save();
7885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const IntRect& scrollbarRect = scrollbar->frameRect();
7895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    context.translate(-scrollbarRect.x(), -scrollbarRect.y());
7905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    IntRect transformedClip = clip;
7915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    transformedClip.moveBy(scrollbarRect.location());
7925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    scrollbar->paint(&context, transformedClip);
7935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    context.restore();
7945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
7955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& context, GraphicsLayerPaintingPhase, const IntRect& clip)
7975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
7985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (graphicsLayer == layerForHorizontalScrollbar())
799d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        paintScrollbar(m_renderView.frameView()->horizontalScrollbar(), context, clip);
8005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else if (graphicsLayer == layerForVerticalScrollbar())
801d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        paintScrollbar(m_renderView.frameView()->verticalScrollbar(), context, clip);
8025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    else if (graphicsLayer == layerForScrollCorner()) {
803d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        const IntRect& scrollCorner = m_renderView.frameView()->scrollCornerRect();
8045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        context.save();
8055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        context.translate(-scrollCorner.x(), -scrollCorner.y());
8065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        IntRect transformedClip = clip;
8075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        transformedClip.moveBy(scrollCorner.location());
808d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_renderView.frameView()->paintScrollCorner(&context, transformedClip);
8095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        context.restore();
8105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
8115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
813926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)bool RenderLayerCompositor::supportsFixedRootBackgroundCompositing() const
8145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
8159e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    if (Settings* settings = m_renderView.document().settings())
8169e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        return settings->preferCompositingToLCDTextEnabled();
817e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    return false;
818926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
8195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
820926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)bool RenderLayerCompositor::needsFixedRootBackgroundLayer(const RenderLayer* layer) const
821926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
822d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    if (layer != m_renderView.layer())
823926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return false;
8245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
825d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return supportsFixedRootBackgroundCompositing() && m_renderView.rootBackgroundIsEntirelyFixed();
826926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
827926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
828926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)GraphicsLayer* RenderLayerCompositor::fixedRootBackgroundLayer() const
829926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
8301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Get the fixed root background from the RenderView layer's compositedLayerMapping.
831d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    RenderLayer* viewLayer = m_renderView.layer();
832926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!viewLayer)
833926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return 0;
83402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
835bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (viewLayer->compositingState() == PaintsIntoOwnBacking && viewLayer->compositedLayerMapping()->backgroundLayerPaintsFixedRootBackground())
8361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return viewLayer->compositedLayerMapping()->backgroundLayer();
837926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
838926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return 0;
8395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
841e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)static void resetTrackedPaintInvalidationRectsRecursive(GraphicsLayer* graphicsLayer)
8425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
8435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!graphicsLayer)
8445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
8455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
846e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    graphicsLayer->resetTrackedPaintInvalidations();
8475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    for (size_t i = 0; i < graphicsLayer->children().size(); ++i)
849e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        resetTrackedPaintInvalidationRectsRecursive(graphicsLayer->children()[i]);
8505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (GraphicsLayer* replicaLayer = graphicsLayer->replicaLayer())
852e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        resetTrackedPaintInvalidationRectsRecursive(replicaLayer);
8535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (GraphicsLayer* maskLayer = graphicsLayer->maskLayer())
855e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        resetTrackedPaintInvalidationRectsRecursive(maskLayer);
85606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
85706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    if (GraphicsLayer* clippingMaskLayer = graphicsLayer->contentsClippingMaskLayer())
858e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        resetTrackedPaintInvalidationRectsRecursive(clippingMaskLayer);
8595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
861e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)void RenderLayerCompositor::resetTrackedPaintInvalidationRects()
8625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
8635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (GraphicsLayer* rootLayer = rootGraphicsLayer())
864e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        resetTrackedPaintInvalidationRectsRecursive(rootLayer);
8655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
867e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)void RenderLayerCompositor::setTracksPaintInvalidations(bool tracksPaintInvalidations)
8685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
869c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    ASSERT(lifecycle().state() == DocumentLifecycle::PaintInvalidationClean);
870e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    m_isTrackingPaintInvalidations = tracksPaintInvalidations;
8715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
873e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)bool RenderLayerCompositor::isTrackingPaintInvalidations() const
8745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
875e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    return m_isTrackingPaintInvalidations;
8765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static bool shouldCompositeOverflowControls(FrameView* view)
8795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
8808abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    if (Page* page = view->frame().page()) {
8815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
8825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (scrollingCoordinator->coordinatesScrollingForFrameView(view))
8835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                return true;
8845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
8855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
8875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderLayerCompositor::requiresHorizontalScrollbarLayer() const
8905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
891d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FrameView* view = m_renderView.frameView();
8925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return shouldCompositeOverflowControls(view) && view->horizontalScrollbar();
8935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderLayerCompositor::requiresVerticalScrollbarLayer() const
8965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
897d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FrameView* view = m_renderView.frameView();
8985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return shouldCompositeOverflowControls(view) && view->verticalScrollbar();
8995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
9005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderLayerCompositor::requiresScrollCornerLayer() const
9025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
903d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FrameView* view = m_renderView.frameView();
9045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return shouldCompositeOverflowControls(view) && view->isScrollCornerVisible();
9055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
9065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::updateOverflowControlsLayers()
9085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
90906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#if USE(RUBBER_BANDING)
910197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (m_renderView.frame()->isLocalRoot()) {
911c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        if (!m_layerForOverhangShadow) {
912c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)            m_layerForOverhangShadow = GraphicsLayer::create(graphicsLayerFactory(), this);
913f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)            OverscrollTheme::theme()->setUpOverhangShadowLayer(m_layerForOverhangShadow.get());
914f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)            OverscrollTheme::theme()->updateOverhangShadowLayer(m_layerForOverhangShadow.get(), m_rootContentLayer.get());
915c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)            m_scrollLayer->addChild(m_layerForOverhangShadow.get());
916c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        }
917c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)    } else {
9185d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        ASSERT(!m_layerForOverhangShadow);
9195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
9205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
921d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    GraphicsLayer* controlsParent = m_rootTransformLayer.get() ? m_rootTransformLayer.get() : m_overflowControlsHostLayer.get();
9225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (requiresHorizontalScrollbarLayer()) {
9245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!m_layerForHorizontalScrollbar) {
9255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_layerForHorizontalScrollbar = GraphicsLayer::create(graphicsLayerFactory(), this);
926323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        }
927323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
928323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        if (m_layerForHorizontalScrollbar->parent() != controlsParent) {
929d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            controlsParent->addChild(m_layerForHorizontalScrollbar.get());
9305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
932d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), HorizontalScrollbar);
9335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
9345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } else if (m_layerForHorizontalScrollbar) {
9355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForHorizontalScrollbar->removeFromParent();
9365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForHorizontalScrollbar = nullptr;
9375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
939d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), HorizontalScrollbar);
9405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
9415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (requiresVerticalScrollbarLayer()) {
9435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!m_layerForVerticalScrollbar) {
9445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_layerForVerticalScrollbar = GraphicsLayer::create(graphicsLayerFactory(), this);
945323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        }
946323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
947323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        if (m_layerForVerticalScrollbar->parent() != controlsParent) {
948d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            controlsParent->addChild(m_layerForVerticalScrollbar.get());
9495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
951d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), VerticalScrollbar);
9525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
9535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } else if (m_layerForVerticalScrollbar) {
9545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForVerticalScrollbar->removeFromParent();
9555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForVerticalScrollbar = nullptr;
9565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
958d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), VerticalScrollbar);
9595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
9605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (requiresScrollCornerLayer()) {
9625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!m_layerForScrollCorner) {
9635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_layerForScrollCorner = GraphicsLayer::create(graphicsLayerFactory(), this);
964d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            controlsParent->addChild(m_layerForScrollCorner.get());
9655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
9665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } else if (m_layerForScrollCorner) {
9675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForScrollCorner->removeFromParent();
9685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForScrollCorner = nullptr;
9695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
9705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
971d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    m_renderView.frameView()->positionScrollbarLayers();
9725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
9735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::ensureRootLayer()
9755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
976197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    RootLayerAttachment expectedAttachment = m_renderView.frame()->isLocalRoot() ? RootLayerAttachedViaChromeClient : RootLayerAttachedViaEnclosingFrame;
9775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (expectedAttachment == m_rootLayerAttachment)
9785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)         return;
9795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_rootContentLayer) {
9815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_rootContentLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
982d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        IntRect overflowRect = m_renderView.pixelSnappedLayoutOverflowRect();
9835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_rootContentLayer->setSize(FloatSize(overflowRect.maxX(), overflowRect.maxY()));
9845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_rootContentLayer->setPosition(FloatPoint());
985d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        m_rootContentLayer->setOwnerNodeId(InspectorNodeIds::idForNode(m_renderView.generatingNode()));
9865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Need to clip to prevent transformed content showing outside this frame
9885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_rootContentLayer->setMasksToBounds(true);
9895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
9905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
99153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    if (!m_overflowControlsHostLayer) {
99253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        ASSERT(!m_scrollLayer);
993e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        ASSERT(!m_containerLayer);
9945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
99553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        // Create a layer to host the clipping layer and the overflow controls layers.
99653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_overflowControlsHostLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
9975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9987242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        // Clip iframe's overflow controls layer.
9997242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        bool containerMasksToBounds = !m_renderView.frame()->isLocalRoot();
10007242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        m_overflowControlsHostLayer->setMasksToBounds(containerMasksToBounds);
10017242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
10021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        // Create a clipping layer if this is an iframe or settings require to clip.
1003e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_containerLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
1004d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (Settings* settings = m_renderView.document().settings()) {
10051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            if (settings->mainFrameClipsContent())
10061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)                containerMasksToBounds = true;
10071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        }
10081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        m_containerLayer->setMasksToBounds(containerMasksToBounds);
100953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
101053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_scrollLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
101153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
101253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)            scrollingCoordinator->setLayerIsContainerForFixedPositionLayers(m_scrollLayer.get(), true);
10135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
101453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        // Hook them up
1015e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_overflowControlsHostLayer->addChild(m_containerLayer.get());
1016e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_containerLayer->addChild(m_scrollLayer.get());
101753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        m_scrollLayer->addChild(m_rootContentLayer.get());
10185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
101953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        frameViewDidChangeSize();
10205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
10215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Check to see if we have to change the attachment
10235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_rootLayerAttachment != RootLayerUnattached)
10245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        detachRootLayer();
10255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    attachRootLayer(expectedAttachment);
10275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
10285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::destroyRootLayer()
10305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
10315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_rootContentLayer)
10325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
10335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    detachRootLayer();
10355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
103606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#if USE(RUBBER_BANDING)
1037c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)    if (m_layerForOverhangShadow) {
1038c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        m_layerForOverhangShadow->removeFromParent();
1039c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        m_layerForOverhangShadow = nullptr;
1040c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)    }
10415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
10425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_layerForHorizontalScrollbar) {
10445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForHorizontalScrollbar->removeFromParent();
10455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForHorizontalScrollbar = nullptr;
1046926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
1047d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), HorizontalScrollbar);
1048d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (Scrollbar* horizontalScrollbar = m_renderView.frameView()->verticalScrollbar())
1049d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            m_renderView.frameView()->invalidateScrollbar(horizontalScrollbar, IntRect(IntPoint(0, 0), horizontalScrollbar->frameRect().size()));
10505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
10515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_layerForVerticalScrollbar) {
10535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForVerticalScrollbar->removeFromParent();
10545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForVerticalScrollbar = nullptr;
1055926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
1056d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), VerticalScrollbar);
1057d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (Scrollbar* verticalScrollbar = m_renderView.frameView()->verticalScrollbar())
1058d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            m_renderView.frameView()->invalidateScrollbar(verticalScrollbar, IntRect(IntPoint(0, 0), verticalScrollbar->frameRect().size()));
10595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
10605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_layerForScrollCorner) {
10625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_layerForScrollCorner = nullptr;
1063d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        m_renderView.frameView()->invalidateScrollCorner(m_renderView.frameView()->scrollCornerRect());
10645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
10655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (m_overflowControlsHostLayer) {
10675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_overflowControlsHostLayer = nullptr;
1068e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        m_containerLayer = nullptr;
10695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_scrollLayer = nullptr;
10705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
10715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(!m_scrollLayer);
10725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_rootContentLayer = nullptr;
1073d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    m_rootTransformLayer = nullptr;
10745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
10755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::attachRootLayer(RootLayerAttachment attachment)
10775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
10785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_rootContentLayer)
10795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
10805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    switch (attachment) {
10825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case RootLayerUnattached:
10835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            ASSERT_NOT_REACHED();
10845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
10855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case RootLayerAttachedViaChromeClient: {
1086d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            LocalFrame& frame = m_renderView.frameView()->frame();
10878abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)            Page* page = frame.page();
10885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!page)
10895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                return;
1090d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            page->chrome().client().attachRootGraphicsLayer(rootGraphicsLayer());
10915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
10925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
10935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        case RootLayerAttachedViaEnclosingFrame: {
1094d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement();
109509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            ASSERT(ownerElement);
10961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            // The layer will get hooked up via CompositedLayerMapping::updateGraphicsLayerConfiguration()
10975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // for the frame's renderer in the parent document.
1098f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)            ownerElement->setNeedsCompositingUpdate();
10995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            break;
11005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
11015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_rootLayerAttachment = attachment;
11045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::detachRootLayer()
11075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
11085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!m_rootContentLayer || m_rootLayerAttachment == RootLayerUnattached)
11095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
11105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    switch (m_rootLayerAttachment) {
11125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    case RootLayerAttachedViaEnclosingFrame: {
11131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        // The layer will get unhooked up via CompositedLayerMapping::updateGraphicsLayerConfiguration()
11145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // for the frame's renderer in the parent document.
11155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (m_overflowControlsHostLayer)
11165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_overflowControlsHostLayer->removeFromParent();
11175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        else
11185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_rootContentLayer->removeFromParent();
11195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1120f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        if (HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement())
1121f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)            ownerElement->setNeedsCompositingUpdate();
11225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        break;
11235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    case RootLayerAttachedViaChromeClient: {
1125d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        LocalFrame& frame = m_renderView.frameView()->frame();
11268abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        Page* page = frame.page();
11275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!page)
11285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return;
1129d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        page->chrome().client().attachRootGraphicsLayer(0);
11305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    break;
11325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    case RootLayerUnattached:
11335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        break;
11345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
11355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_rootLayerAttachment = RootLayerUnattached;
11375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderLayerCompositor::updateRootLayerAttachment()
11405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
11415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ensureRootLayer();
11425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)ScrollingCoordinator* RenderLayerCompositor::scrollingCoordinator() const
11455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
11465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (Page* page = this->page())
11475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return page->scrollingCoordinator();
11485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
11505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)GraphicsLayerFactory* RenderLayerCompositor::graphicsLayerFactory() const
11535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
11545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (Page* page = this->page())
1155e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return page->chrome().client().graphicsLayerFactory();
11565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
11575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
11595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)Page* RenderLayerCompositor::page() const
11605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1161d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return m_renderView.frameView()->frame().page();
11625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
11635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
116409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)DocumentLifecycle& RenderLayerCompositor::lifecycle() const
116509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
1166d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    return m_renderView.document().lifecycle();
116709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
116809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
1169e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)String RenderLayerCompositor::debugName(const GraphicsLayer* graphicsLayer)
1170e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
1171e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    String name;
1172e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    if (graphicsLayer == m_rootContentLayer.get()) {
1173e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        name = "Content Root Layer";
1174d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    } else if (graphicsLayer == m_rootTransformLayer.get()) {
1175d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        name = "Root Transform Layer";
117606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#if USE(RUBBER_BANDING)
1177f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    } else if (graphicsLayer == m_layerForOverhangShadow.get()) {
1178c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        name = "Overhang Areas Shadow";
1179e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#endif
1180e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    } else if (graphicsLayer == m_overflowControlsHostLayer.get()) {
1181e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        name = "Overflow Controls Host Layer";
1182e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    } else if (graphicsLayer == m_layerForHorizontalScrollbar.get()) {
1183e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        name = "Horizontal Scrollbar Layer";
1184e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    } else if (graphicsLayer == m_layerForVerticalScrollbar.get()) {
1185e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        name = "Vertical Scrollbar Layer";
1186e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    } else if (graphicsLayer == m_layerForScrollCorner.get()) {
1187e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        name = "Scroll Corner Layer";
1188e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    } else if (graphicsLayer == m_containerLayer.get()) {
1189d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        name = "LocalFrame Clipping Layer";
1190e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    } else if (graphicsLayer == m_scrollLayer.get()) {
1191d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        name = "LocalFrame Scrolling Layer";
1192e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    } else {
1193e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        ASSERT_NOT_REACHED();
1194e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    }
1195e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
1196e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    return name;
1197e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
1198e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
1199c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
1200