Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / compositing / RenderLayerCompositor.cpp
1 /*
2  * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27
28 #include "core/rendering/compositing/RenderLayerCompositor.h"
29
30 #include "core/animation/DocumentAnimations.h"
31 #include "core/dom/Fullscreen.h"
32 #include "core/frame/FrameView.h"
33 #include "core/frame/LocalFrame.h"
34 #include "core/frame/Settings.h"
35 #include "core/html/HTMLIFrameElement.h"
36 #include "core/inspector/InspectorInstrumentation.h"
37 #include "core/inspector/InspectorNodeIds.h"
38 #include "core/page/Chrome.h"
39 #include "core/page/ChromeClient.h"
40 #include "core/page/Page.h"
41 #include "core/page/scrolling/ScrollingCoordinator.h"
42 #include "core/paint/FramePainter.h"
43 #include "core/rendering/RenderEmbeddedObject.h"
44 #include "core/rendering/RenderLayerStackingNode.h"
45 #include "core/rendering/RenderLayerStackingNodeIterator.h"
46 #include "core/rendering/RenderPart.h"
47 #include "core/rendering/RenderVideo.h"
48 #include "core/rendering/RenderView.h"
49 #include "core/rendering/compositing/CompositedLayerMapping.h"
50 #include "core/rendering/compositing/CompositingInputsUpdater.h"
51 #include "core/rendering/compositing/CompositingLayerAssigner.h"
52 #include "core/rendering/compositing/CompositingRequirementsUpdater.h"
53 #include "core/rendering/compositing/GraphicsLayerTreeBuilder.h"
54 #include "core/rendering/compositing/GraphicsLayerUpdater.h"
55 #include "platform/OverscrollTheme.h"
56 #include "platform/RuntimeEnabledFeatures.h"
57 #include "platform/ScriptForbiddenScope.h"
58 #include "platform/TraceEvent.h"
59 #include "platform/graphics/GraphicsLayer.h"
60 #include "public/platform/Platform.h"
61
62 namespace blink {
63
64 RenderLayerCompositor::RenderLayerCompositor(RenderView& renderView)
65     : m_renderView(renderView)
66     , m_compositingReasonFinder(renderView)
67     , m_pendingUpdateType(CompositingUpdateNone)
68     , m_hasAcceleratedCompositing(true)
69     , m_compositing(false)
70     , m_rootShouldAlwaysCompositeDirty(true)
71     , m_needsUpdateFixedBackground(false)
72     , m_isTrackingPaintInvalidations(false)
73     , m_rootLayerAttachment(RootLayerUnattached)
74     , m_inOverlayFullscreenVideo(false)
75 {
76     updateAcceleratedCompositingSettings();
77 }
78
79 RenderLayerCompositor::~RenderLayerCompositor()
80 {
81     ASSERT(m_rootLayerAttachment == RootLayerUnattached);
82 }
83
84 bool RenderLayerCompositor::inCompositingMode() const
85 {
86     // FIXME: This should assert that lificycle is >= CompositingClean since
87     // the last step of updateIfNeeded can set this bit to false.
88     ASSERT(!m_rootShouldAlwaysCompositeDirty);
89     return m_compositing;
90 }
91
92 bool RenderLayerCompositor::staleInCompositingMode() const
93 {
94     return m_compositing;
95 }
96
97 void RenderLayerCompositor::setCompositingModeEnabled(bool enable)
98 {
99     if (enable == m_compositing)
100         return;
101
102     m_compositing = enable;
103
104     // RenderPart::requiresAcceleratedCompositing is used to determine self-paintingness
105     // and bases it's return value for frames on the m_compositing bit here.
106     if (HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement()) {
107         if (RenderPart* renderer = ownerElement->renderPart())
108             renderer->layer()->updateSelfPaintingLayer();
109     }
110
111     if (m_compositing)
112         ensureRootLayer();
113     else
114         destroyRootLayer();
115
116     // Compositing also affects the answer to RenderIFrame::requiresAcceleratedCompositing(), so
117     // we need to schedule a style recalc in our parent document.
118     if (HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement())
119         ownerElement->setNeedsCompositingUpdate();
120 }
121
122 void RenderLayerCompositor::enableCompositingModeIfNeeded()
123 {
124     if (!m_rootShouldAlwaysCompositeDirty)
125         return;
126
127     m_rootShouldAlwaysCompositeDirty = false;
128     if (m_compositing)
129         return;
130
131     if (rootShouldAlwaysComposite()) {
132         // FIXME: Is this needed? It was added in https://bugs.webkit.org/show_bug.cgi?id=26651.
133         // No tests fail if it's deleted.
134         setNeedsCompositingUpdate(CompositingUpdateRebuildTree);
135         setCompositingModeEnabled(true);
136     }
137 }
138
139 bool RenderLayerCompositor::rootShouldAlwaysComposite() const
140 {
141     if (!m_hasAcceleratedCompositing)
142         return false;
143     return m_renderView.frame()->isLocalRoot() || m_compositingReasonFinder.requiresCompositingForScrollableFrame();
144 }
145
146 void RenderLayerCompositor::updateAcceleratedCompositingSettings()
147 {
148     m_compositingReasonFinder.updateTriggers();
149     m_hasAcceleratedCompositing = m_renderView.document().settings()->acceleratedCompositingEnabled();
150     m_rootShouldAlwaysCompositeDirty = true;
151 }
152
153 bool RenderLayerCompositor::layerSquashingEnabled() const
154 {
155     if (!RuntimeEnabledFeatures::layerSquashingEnabled())
156         return false;
157     if (Settings* settings = m_renderView.document().settings())
158         return settings->layerSquashingEnabled();
159     return true;
160 }
161
162 bool RenderLayerCompositor::preferCompositingToLCDTextEnabled() const
163 {
164     return m_compositingReasonFinder.hasOverflowScrollTrigger();
165 }
166
167 static RenderVideo* findFullscreenVideoRenderer(Document& document)
168 {
169     // Recursively find the document that is in fullscreen.
170     Element* fullscreenElement = Fullscreen::fullscreenElementFrom(document);
171     Document* contentDocument = &document;
172     while (fullscreenElement && fullscreenElement->isFrameOwnerElement()) {
173         contentDocument = toHTMLFrameOwnerElement(fullscreenElement)->contentDocument();
174         if (!contentDocument)
175             return 0;
176         fullscreenElement = Fullscreen::fullscreenElementFrom(*contentDocument);
177     }
178     // Get the current fullscreen element from the document.
179     fullscreenElement = Fullscreen::currentFullScreenElementFrom(*contentDocument);
180     if (!isHTMLVideoElement(fullscreenElement))
181         return 0;
182     RenderObject* renderer = fullscreenElement->renderer();
183     if (!renderer)
184         return 0;
185     return toRenderVideo(renderer);
186 }
187
188 void RenderLayerCompositor::updateIfNeededRecursive()
189 {
190     for (Frame* child = m_renderView.frameView()->frame().tree().firstChild(); child; child = child->tree().nextSibling()) {
191         if (child->isLocalFrame())
192             toLocalFrame(child)->contentRenderer()->compositor()->updateIfNeededRecursive();
193     }
194
195     TRACE_EVENT0("blink", "RenderLayerCompositor::updateIfNeededRecursive");
196
197     ASSERT(!m_renderView.needsLayout());
198
199     ScriptForbiddenScope forbidScript;
200
201     // FIXME: enableCompositingModeIfNeeded can trigger a CompositingUpdateRebuildTree,
202     // which asserts that it's not InCompositingUpdate.
203     enableCompositingModeIfNeeded();
204
205     rootRenderLayer()->updateDescendantDependentFlagsForEntireSubtree();
206
207     lifecycle().advanceTo(DocumentLifecycle::InCompositingUpdate);
208     updateIfNeeded();
209     lifecycle().advanceTo(DocumentLifecycle::CompositingClean);
210
211     DocumentAnimations::startPendingAnimations(m_renderView.document());
212
213 #if ENABLE(ASSERT)
214     ASSERT(lifecycle().state() == DocumentLifecycle::CompositingClean);
215     assertNoUnresolvedDirtyBits();
216     for (Frame* child = m_renderView.frameView()->frame().tree().firstChild(); child; child = child->tree().nextSibling()) {
217         if (child->isLocalFrame())
218             toLocalFrame(child)->contentRenderer()->compositor()->assertNoUnresolvedDirtyBits();
219     }
220 #endif
221 }
222
223 void RenderLayerCompositor::setNeedsCompositingUpdate(CompositingUpdateType updateType)
224 {
225     ASSERT(updateType != CompositingUpdateNone);
226     m_pendingUpdateType = std::max(m_pendingUpdateType, updateType);
227     page()->animator().scheduleVisualUpdate();
228     lifecycle().ensureStateAtMost(DocumentLifecycle::LayoutClean);
229 }
230
231 void RenderLayerCompositor::didLayout()
232 {
233     // FIXME: Technically we only need to do this when the FrameView's
234     // isScrollable method would return a different value.
235     m_rootShouldAlwaysCompositeDirty = true;
236     enableCompositingModeIfNeeded();
237
238     // FIXME: Rather than marking the entire RenderView as dirty, we should
239     // track which RenderLayers moved during layout and only dirty those
240     // specific RenderLayers.
241     rootRenderLayer()->setNeedsCompositingInputsUpdate();
242 }
243
244 #if ENABLE(ASSERT)
245
246 void RenderLayerCompositor::assertNoUnresolvedDirtyBits()
247 {
248     ASSERT(m_pendingUpdateType == CompositingUpdateNone);
249     ASSERT(!m_rootShouldAlwaysCompositeDirty);
250 }
251
252 #endif
253
254 void RenderLayerCompositor::applyOverlayFullscreenVideoAdjustment()
255 {
256     m_inOverlayFullscreenVideo = false;
257     if (!m_rootContentLayer)
258         return;
259
260     bool isLocalRoot = m_renderView.frame()->isLocalRoot();
261     RenderVideo* video = findFullscreenVideoRenderer(m_renderView.document());
262     if (!video || !video->layer()->hasCompositedLayerMapping()) {
263         if (isLocalRoot) {
264             GraphicsLayer* backgroundLayer = fixedRootBackgroundLayer();
265             if (backgroundLayer && !backgroundLayer->parent())
266                 rootFixedBackgroundsChanged();
267         }
268         return;
269     }
270
271     GraphicsLayer* videoLayer = video->layer()->compositedLayerMapping()->mainGraphicsLayer();
272
273     // The fullscreen video has layer position equal to its enclosing frame's scroll position because fullscreen container is fixed-positioned.
274     // We should reset layer position here since we are going to reattach the layer at the very top level.
275     videoLayer->setPosition(IntPoint());
276
277     // Only steal fullscreen video layer and clear all other layers if we are the main frame.
278     if (!isLocalRoot)
279         return;
280
281     m_rootContentLayer->removeAllChildren();
282     m_overflowControlsHostLayer->addChild(videoLayer);
283     if (GraphicsLayer* backgroundLayer = fixedRootBackgroundLayer())
284         backgroundLayer->removeFromParent();
285     m_inOverlayFullscreenVideo = true;
286 }
287
288 void RenderLayerCompositor::updateWithoutAcceleratedCompositing(CompositingUpdateType updateType)
289 {
290     ASSERT(!hasAcceleratedCompositing());
291
292     if (updateType >= CompositingUpdateAfterCompositingInputChange)
293         CompositingInputsUpdater(rootRenderLayer()).update();
294
295 #if ENABLE(ASSERT)
296     CompositingInputsUpdater::assertNeedsCompositingInputsUpdateBitsCleared(rootRenderLayer());
297 #endif
298 }
299
300 static void forceRecomputePaintInvalidationRectsIncludingNonCompositingDescendants(RenderObject* renderer)
301 {
302     // We clear the previous paint invalidation rect as it's wrong (paint invaliation container
303     // changed, ...). Forcing a full invalidation will make us recompute it. Also we are not
304     // changing the previous position from our paint invalidation container, which is fine as
305     // we want a full paint invalidation anyway.
306     renderer->setPreviousPaintInvalidationRect(LayoutRect());
307     renderer->setShouldDoFullPaintInvalidation();
308
309     for (RenderObject* child = renderer->slowFirstChild(); child; child = child->nextSibling()) {
310         if (!child->isPaintInvalidationContainer())
311             forceRecomputePaintInvalidationRectsIncludingNonCompositingDescendants(child);
312     }
313 }
314
315
316 void RenderLayerCompositor::updateIfNeeded()
317 {
318     CompositingUpdateType updateType = m_pendingUpdateType;
319     m_pendingUpdateType = CompositingUpdateNone;
320
321     if (!hasAcceleratedCompositing()) {
322         updateWithoutAcceleratedCompositing(updateType);
323         return;
324     }
325
326     if (updateType == CompositingUpdateNone)
327         return;
328
329     RenderLayer* updateRoot = rootRenderLayer();
330
331     Vector<RenderLayer*> layersNeedingPaintInvalidation;
332
333     if (updateType >= CompositingUpdateAfterCompositingInputChange) {
334         CompositingInputsUpdater(updateRoot).update();
335
336 #if ENABLE(ASSERT)
337         // FIXME: Move this check to the end of the compositing update.
338         CompositingInputsUpdater::assertNeedsCompositingInputsUpdateBitsCleared(updateRoot);
339 #endif
340
341         CompositingRequirementsUpdater(m_renderView, m_compositingReasonFinder).update(updateRoot);
342
343         CompositingLayerAssigner layerAssigner(this);
344         layerAssigner.assign(updateRoot, layersNeedingPaintInvalidation);
345
346         bool layersChanged = layerAssigner.layersChanged();
347
348         {
349             TRACE_EVENT0("blink", "RenderLayerCompositor::updateAfterCompositingChange");
350             if (const FrameView::ScrollableAreaSet* scrollableAreas = m_renderView.frameView()->scrollableAreas()) {
351                 for (FrameView::ScrollableAreaSet::iterator it = scrollableAreas->begin(); it != scrollableAreas->end(); ++it)
352                     layersChanged |= (*it)->updateAfterCompositingChange();
353             }
354         }
355
356         if (layersChanged)
357             updateType = std::max(updateType, CompositingUpdateRebuildTree);
358     }
359
360     if (updateType != CompositingUpdateNone) {
361         GraphicsLayerUpdater updater;
362         updater.update(*updateRoot, layersNeedingPaintInvalidation);
363
364         if (updater.needsRebuildTree())
365             updateType = std::max(updateType, CompositingUpdateRebuildTree);
366
367 #if ENABLE(ASSERT)
368         // FIXME: Move this check to the end of the compositing update.
369         GraphicsLayerUpdater::assertNeedsToUpdateGraphicsLayerBitsCleared(*updateRoot);
370 #endif
371     }
372
373     if (updateType >= CompositingUpdateRebuildTree) {
374         GraphicsLayerTreeBuilder::AncestorInfo ancestorInfo;
375         GraphicsLayerVector childList;
376         ancestorInfo.childLayersOfEnclosingCompositedLayer = &childList;
377         {
378             TRACE_EVENT0("blink", "GraphicsLayerTreeBuilder::rebuild");
379             GraphicsLayerTreeBuilder().rebuild(*updateRoot, ancestorInfo);
380         }
381
382         if (childList.isEmpty())
383             destroyRootLayer();
384         else
385             m_rootContentLayer->setChildren(childList);
386
387         if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled())
388             applyOverlayFullscreenVideoAdjustment();
389     }
390
391     if (m_needsUpdateFixedBackground) {
392         rootFixedBackgroundsChanged();
393         m_needsUpdateFixedBackground = false;
394     }
395
396     for (unsigned i = 0; i < layersNeedingPaintInvalidation.size(); i++)
397         forceRecomputePaintInvalidationRectsIncludingNonCompositingDescendants(layersNeedingPaintInvalidation[i]->renderer());
398
399     // Inform the inspector that the layer tree has changed.
400     if (m_renderView.frame()->isMainFrame())
401         InspectorInstrumentation::layerTreeDidChange(m_renderView.frame());
402 }
403
404 bool RenderLayerCompositor::allocateOrClearCompositedLayerMapping(RenderLayer* layer, const CompositingStateTransitionType compositedLayerUpdate)
405 {
406     bool compositedLayerMappingChanged = false;
407
408     // FIXME: It would be nice to directly use the layer's compositing reason,
409     // but allocateOrClearCompositedLayerMapping also gets called without having updated compositing
410     // requirements fully.
411     switch (compositedLayerUpdate) {
412     case AllocateOwnCompositedLayerMapping:
413         ASSERT(!layer->hasCompositedLayerMapping());
414         setCompositingModeEnabled(true);
415
416         // If we need to issue paint invalidations, do so before allocating the compositedLayerMapping and clearing out the groupedMapping.
417         paintInvalidationOnCompositingChange(layer);
418
419         // If this layer was previously squashed, we need to remove its reference to a groupedMapping right away, so
420         // that computing paint invalidation rects will know the layer's correct compositingState.
421         // FIXME: do we need to also remove the layer from it's location in the squashing list of its groupedMapping?
422         // Need to create a test where a squashed layer pops into compositing. And also to cover all other
423         // sorts of compositingState transitions.
424         layer->setLostGroupedMapping(false);
425         layer->setGroupedMapping(0);
426
427         layer->ensureCompositedLayerMapping();
428         compositedLayerMappingChanged = true;
429
430         // At this time, the ScrollingCooridnator only supports the top-level frame.
431         if (layer->isRootLayer() && m_renderView.frame()->isLocalRoot()) {
432             if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
433                 scrollingCoordinator->frameViewRootLayerDidChange(m_renderView.frameView());
434         }
435         break;
436     case RemoveOwnCompositedLayerMapping:
437     // PutInSquashingLayer means you might have to remove the composited layer mapping first.
438     case PutInSquashingLayer:
439         if (layer->hasCompositedLayerMapping()) {
440             // If we're removing the compositedLayerMapping from a reflection, clear the source GraphicsLayer's pointer to
441             // its replica GraphicsLayer. In practice this should never happen because reflectee and reflection
442             // are both either composited, or not composited.
443             if (layer->isReflection()) {
444                 RenderLayer* sourceLayer = toRenderLayerModelObject(layer->renderer()->parent())->layer();
445                 if (sourceLayer->hasCompositedLayerMapping()) {
446                     ASSERT(sourceLayer->compositedLayerMapping()->mainGraphicsLayer()->replicaLayer() == layer->compositedLayerMapping()->mainGraphicsLayer());
447                     sourceLayer->compositedLayerMapping()->mainGraphicsLayer()->setReplicatedByLayer(0);
448                 }
449             }
450
451             layer->clearCompositedLayerMapping();
452             compositedLayerMappingChanged = true;
453         }
454
455         break;
456     case RemoveFromSquashingLayer:
457     case NoCompositingStateChange:
458         // Do nothing.
459         break;
460     }
461
462     if (compositedLayerMappingChanged && layer->renderer()->isRenderPart()) {
463         RenderLayerCompositor* innerCompositor = frameContentsCompositor(toRenderPart(layer->renderer()));
464         if (innerCompositor && innerCompositor->staleInCompositingMode())
465             innerCompositor->updateRootLayerAttachment();
466     }
467
468     if (compositedLayerMappingChanged)
469         layer->clipper().clearClipRectsIncludingDescendants(PaintingClipRects);
470
471     // If a fixed position layer gained/lost a compositedLayerMapping or the reason not compositing it changed,
472     // the scrolling coordinator needs to recalculate whether it can do fast scrolling.
473     if (compositedLayerMappingChanged) {
474         if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
475             scrollingCoordinator->frameViewFixedObjectsDidChange(m_renderView.frameView());
476     }
477
478     return compositedLayerMappingChanged;
479 }
480
481 void RenderLayerCompositor::paintInvalidationOnCompositingChange(RenderLayer* layer)
482 {
483     // If the renderer is not attached yet, no need to issue paint invalidations.
484     if (layer->renderer() != &m_renderView && !layer->renderer()->parent())
485         return;
486
487     // For querying RenderLayer::compositingState()
488     // Eager invalidation here is correct, since we are invalidating with respect to the previous frame's
489     // compositing state when changing the compositing backing of the layer.
490     DisableCompositingQueryAsserts disabler;
491
492     layer->renderer()->invalidatePaintIncludingNonCompositingDescendants();
493 }
494
495 void RenderLayerCompositor::frameViewDidChangeLocation(const IntPoint& contentsOffset)
496 {
497     if (m_overflowControlsHostLayer)
498         m_overflowControlsHostLayer->setPosition(contentsOffset);
499 }
500
501 void RenderLayerCompositor::frameViewDidChangeSize()
502 {
503     if (m_containerLayer) {
504         FrameView* frameView = m_renderView.frameView();
505         m_containerLayer->setSize(frameView->unscaledVisibleContentSize());
506         m_overflowControlsHostLayer->setSize(frameView->unscaledVisibleContentSize(IncludeScrollbars));
507
508         frameViewDidScroll();
509         updateOverflowControlsLayers();
510     }
511 }
512
513 enum AcceleratedFixedRootBackgroundHistogramBuckets {
514     ScrolledMainFrameBucket = 0,
515     ScrolledMainFrameWithAcceleratedFixedRootBackground = 1,
516     ScrolledMainFrameWithUnacceleratedFixedRootBackground = 2,
517     AcceleratedFixedRootBackgroundHistogramMax = 3
518 };
519
520 void RenderLayerCompositor::frameViewDidScroll()
521 {
522     FrameView* frameView = m_renderView.frameView();
523     IntPoint scrollPosition = frameView->scrollPosition();
524
525     if (!m_scrollLayer)
526         return;
527
528     bool scrollingCoordinatorHandlesOffset = false;
529     if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
530         if (Settings* settings = m_renderView.document().settings()) {
531             if (m_renderView.frame()->isLocalRoot() || settings->preferCompositingToLCDTextEnabled())
532                 scrollingCoordinatorHandlesOffset = scrollingCoordinator->scrollableAreaScrollLayerDidChange(frameView);
533         }
534     }
535
536     // Scroll position = scroll minimum + scroll offset. Adjust the layer's
537     // position to handle whatever the scroll coordinator isn't handling.
538     // The minimum scroll position is non-zero for RTL pages with overflow.
539     if (scrollingCoordinatorHandlesOffset)
540         m_scrollLayer->setPosition(-frameView->minimumScrollPosition());
541     else
542         m_scrollLayer->setPosition(-scrollPosition);
543
544
545     Platform::current()->histogramEnumeration("Renderer.AcceleratedFixedRootBackground",
546         ScrolledMainFrameBucket,
547         AcceleratedFixedRootBackgroundHistogramMax);
548 }
549
550 void RenderLayerCompositor::frameViewScrollbarsExistenceDidChange()
551 {
552     if (m_containerLayer)
553         updateOverflowControlsLayers();
554 }
555
556 void RenderLayerCompositor::rootFixedBackgroundsChanged()
557 {
558     if (!supportsFixedRootBackgroundCompositing())
559         return;
560
561     // To avoid having to make the fixed root background layer fixed positioned to
562     // stay put, we position it in the layer tree as follows:
563     //
564     // + Overflow controls host
565     //   + LocalFrame clip
566     //     + (Fixed root background) <-- Here.
567     //     + LocalFrame scroll
568     //       + Root content layer
569     //   + Scrollbars
570     //
571     // That is, it needs to be the first child of the frame clip, the sibling of
572     // the frame scroll layer. The compositor does not own the background layer, it
573     // just positions it (like the foreground layer).
574     if (GraphicsLayer* backgroundLayer = fixedRootBackgroundLayer())
575         m_containerLayer->addChildBelow(backgroundLayer, m_scrollLayer.get());
576 }
577
578 bool RenderLayerCompositor::scrollingLayerDidChange(RenderLayer* layer)
579 {
580     if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
581         return scrollingCoordinator->scrollableAreaScrollLayerDidChange(layer->scrollableArea());
582     return false;
583 }
584
585 String RenderLayerCompositor::layerTreeAsText(LayerTreeFlags flags)
586 {
587     ASSERT(lifecycle().state() >= DocumentLifecycle::PaintInvalidationClean);
588
589     if (!m_rootContentLayer)
590         return String();
591
592     // We skip dumping the scroll and clip layers to keep layerTreeAsText output
593     // similar between platforms (unless we explicitly request dumping from the
594     // root.
595     GraphicsLayer* rootLayer = m_rootContentLayer.get();
596     if (flags & LayerTreeIncludesRootLayer)
597         rootLayer = rootGraphicsLayer();
598
599     String layerTreeText = rootLayer->layerTreeAsText(flags);
600
601     // The true root layer is not included in the dump, so if we want to report
602     // its paint invalidation rects, they must be included here.
603     if (flags & LayerTreeIncludesPaintInvalidationRects)
604         return m_renderView.frameView()->trackedPaintInvalidationRectsAsText() + layerTreeText;
605
606     return layerTreeText;
607 }
608
609 RenderLayerCompositor* RenderLayerCompositor::frameContentsCompositor(RenderPart* renderer)
610 {
611     if (!renderer->node()->isFrameOwnerElement())
612         return 0;
613
614     HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(renderer->node());
615     if (Document* contentDocument = element->contentDocument()) {
616         if (RenderView* view = contentDocument->renderView())
617             return view->compositor();
618     }
619     return 0;
620 }
621
622 // FIXME: What does this function do? It needs a clearer name.
623 bool RenderLayerCompositor::parentFrameContentLayers(RenderPart* renderer)
624 {
625     RenderLayerCompositor* innerCompositor = frameContentsCompositor(renderer);
626     if (!innerCompositor || !innerCompositor->staleInCompositingMode() || innerCompositor->rootLayerAttachment() != RootLayerAttachedViaEnclosingFrame)
627         return false;
628
629     RenderLayer* layer = renderer->layer();
630     if (!layer->hasCompositedLayerMapping())
631         return false;
632
633     CompositedLayerMapping* compositedLayerMapping = layer->compositedLayerMapping();
634     GraphicsLayer* hostingLayer = compositedLayerMapping->parentForSublayers();
635     GraphicsLayer* rootLayer = innerCompositor->rootGraphicsLayer();
636     if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != rootLayer) {
637         hostingLayer->removeAllChildren();
638         hostingLayer->addChild(rootLayer);
639     }
640     return true;
641 }
642
643 static void fullyInvalidatePaintRecursive(RenderLayer* layer)
644 {
645     if (layer->compositingState() == PaintsIntoOwnBacking) {
646         layer->compositedLayerMapping()->setContentsNeedDisplay();
647         layer->compositedLayerMapping()->setSquashingContentsNeedDisplay();
648     }
649
650     for (RenderLayer* child = layer->firstChild(); child; child = child->nextSibling())
651         fullyInvalidatePaintRecursive(child);
652 }
653
654 void RenderLayerCompositor::fullyInvalidatePaint()
655 {
656     // We're walking all compositing layers and invalidating them, so there's
657     // no need to have up-to-date compositing state.
658     DisableCompositingQueryAsserts disabler;
659     fullyInvalidatePaintRecursive(rootRenderLayer());
660 }
661
662 RenderLayer* RenderLayerCompositor::rootRenderLayer() const
663 {
664     return m_renderView.layer();
665 }
666
667 GraphicsLayer* RenderLayerCompositor::rootGraphicsLayer() const
668 {
669     if (m_overflowControlsHostLayer)
670         return m_overflowControlsHostLayer.get();
671     return m_rootContentLayer.get();
672 }
673
674 GraphicsLayer* RenderLayerCompositor::scrollLayer() const
675 {
676     return m_scrollLayer.get();
677 }
678
679 GraphicsLayer* RenderLayerCompositor::containerLayer() const
680 {
681     return m_containerLayer.get();
682 }
683
684 GraphicsLayer* RenderLayerCompositor::ensureRootTransformLayer()
685 {
686     ASSERT(rootGraphicsLayer());
687
688     if (!m_rootTransformLayer.get()) {
689         m_rootTransformLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
690         m_overflowControlsHostLayer->addChild(m_rootTransformLayer.get());
691         m_rootTransformLayer->addChild(m_containerLayer.get());
692         updateOverflowControlsLayers();
693     }
694
695     return m_rootTransformLayer.get();
696 }
697
698 void RenderLayerCompositor::setIsInWindow(bool isInWindow)
699 {
700     if (!staleInCompositingMode())
701         return;
702
703     if (isInWindow) {
704         if (m_rootLayerAttachment != RootLayerUnattached)
705             return;
706
707         RootLayerAttachment attachment = m_renderView.frame()->isLocalRoot() ? RootLayerAttachedViaChromeClient : RootLayerAttachedViaEnclosingFrame;
708         attachRootLayer(attachment);
709     } else {
710         if (m_rootLayerAttachment == RootLayerUnattached)
711             return;
712
713         detachRootLayer();
714     }
715 }
716
717 void RenderLayerCompositor::updateRootLayerPosition()
718 {
719     if (m_rootContentLayer) {
720         const IntRect& documentRect = m_renderView.documentRect();
721         m_rootContentLayer->setSize(documentRect.size());
722         m_rootContentLayer->setPosition(documentRect.location());
723 #if USE(RUBBER_BANDING)
724         if (m_layerForOverhangShadow)
725             OverscrollTheme::theme()->updateOverhangShadowLayer(m_layerForOverhangShadow.get(), m_rootContentLayer.get());
726 #endif
727     }
728     if (m_containerLayer) {
729         FrameView* frameView = m_renderView.frameView();
730         m_containerLayer->setSize(frameView->unscaledVisibleContentSize());
731         m_overflowControlsHostLayer->setSize(frameView->unscaledVisibleContentSize(IncludeScrollbars));
732     }
733 }
734
735 void RenderLayerCompositor::updatePotentialCompositingReasonsFromStyle(RenderLayer* layer)
736 {
737     layer->setPotentialCompositingReasonsFromStyle(m_compositingReasonFinder.potentialCompositingReasonsFromStyle(layer->renderer()));
738 }
739
740 void RenderLayerCompositor::updateDirectCompositingReasons(RenderLayer* layer)
741 {
742     layer->setCompositingReasons(m_compositingReasonFinder.directReasons(layer), CompositingReasonComboAllDirectReasons);
743 }
744
745 void RenderLayerCompositor::setOverlayLayer(GraphicsLayer* layer)
746 {
747     ASSERT(rootGraphicsLayer());
748
749     if (layer->parent() != m_overflowControlsHostLayer.get())
750         m_overflowControlsHostLayer->addChild(layer);
751 }
752
753 bool RenderLayerCompositor::canBeComposited(const RenderLayer* layer) const
754 {
755     return m_hasAcceleratedCompositing && layer->isSelfPaintingLayer() && !layer->subtreeIsInvisible();
756 }
757
758 // Return true if the given layer is a stacking context and has compositing child
759 // layers that it needs to clip. In this case we insert a clipping GraphicsLayer
760 // into the hierarchy between this layer and its children in the z-order hierarchy.
761 bool RenderLayerCompositor::clipsCompositingDescendants(const RenderLayer* layer) const
762 {
763     return layer->hasCompositingDescendant() && layer->renderer()->hasClipOrOverflowClip();
764 }
765
766 // If an element has composited negative z-index children, those children render in front of the
767 // layer background, so we need an extra 'contents' layer for the foreground of the layer
768 // object.
769 bool RenderLayerCompositor::needsContentsCompositingLayer(const RenderLayer* layer) const
770 {
771     if (!layer->hasCompositingDescendant())
772         return false;
773     return layer->stackingNode()->hasNegativeZOrderList();
774 }
775
776 static void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRect& clip)
777 {
778     if (!scrollbar)
779         return;
780
781     context.save();
782     const IntRect& scrollbarRect = scrollbar->frameRect();
783     context.translate(-scrollbarRect.x(), -scrollbarRect.y());
784     IntRect transformedClip = clip;
785     transformedClip.moveBy(scrollbarRect.location());
786     scrollbar->paint(&context, transformedClip);
787     context.restore();
788 }
789
790 void RenderLayerCompositor::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& context, GraphicsLayerPaintingPhase, const IntRect& clip)
791 {
792     if (graphicsLayer == layerForHorizontalScrollbar())
793         paintScrollbar(m_renderView.frameView()->horizontalScrollbar(), context, clip);
794     else if (graphicsLayer == layerForVerticalScrollbar())
795         paintScrollbar(m_renderView.frameView()->verticalScrollbar(), context, clip);
796     else if (graphicsLayer == layerForScrollCorner()) {
797         const IntRect& scrollCorner = m_renderView.frameView()->scrollCornerRect();
798         context.save();
799         context.translate(-scrollCorner.x(), -scrollCorner.y());
800         IntRect transformedClip = clip;
801         transformedClip.moveBy(scrollCorner.location());
802         FramePainter(*m_renderView.frameView()).paintScrollCorner(&context, transformedClip);
803         context.restore();
804     }
805 }
806
807 bool RenderLayerCompositor::supportsFixedRootBackgroundCompositing() const
808 {
809     if (Settings* settings = m_renderView.document().settings())
810         return settings->preferCompositingToLCDTextEnabled();
811     return false;
812 }
813
814 bool RenderLayerCompositor::needsFixedRootBackgroundLayer(const RenderLayer* layer) const
815 {
816     if (layer != m_renderView.layer())
817         return false;
818
819     return supportsFixedRootBackgroundCompositing() && m_renderView.rootBackgroundIsEntirelyFixed();
820 }
821
822 GraphicsLayer* RenderLayerCompositor::fixedRootBackgroundLayer() const
823 {
824     // Get the fixed root background from the RenderView layer's compositedLayerMapping.
825     RenderLayer* viewLayer = m_renderView.layer();
826     if (!viewLayer)
827         return 0;
828
829     if (viewLayer->compositingState() == PaintsIntoOwnBacking && viewLayer->compositedLayerMapping()->backgroundLayerPaintsFixedRootBackground())
830         return viewLayer->compositedLayerMapping()->backgroundLayer();
831
832     return 0;
833 }
834
835 static void resetTrackedPaintInvalidationRectsRecursive(GraphicsLayer* graphicsLayer)
836 {
837     if (!graphicsLayer)
838         return;
839
840     graphicsLayer->resetTrackedPaintInvalidations();
841
842     for (size_t i = 0; i < graphicsLayer->children().size(); ++i)
843         resetTrackedPaintInvalidationRectsRecursive(graphicsLayer->children()[i]);
844
845     if (GraphicsLayer* replicaLayer = graphicsLayer->replicaLayer())
846         resetTrackedPaintInvalidationRectsRecursive(replicaLayer);
847
848     if (GraphicsLayer* maskLayer = graphicsLayer->maskLayer())
849         resetTrackedPaintInvalidationRectsRecursive(maskLayer);
850
851     if (GraphicsLayer* clippingMaskLayer = graphicsLayer->contentsClippingMaskLayer())
852         resetTrackedPaintInvalidationRectsRecursive(clippingMaskLayer);
853 }
854
855 void RenderLayerCompositor::resetTrackedPaintInvalidationRects()
856 {
857     if (GraphicsLayer* rootLayer = rootGraphicsLayer())
858         resetTrackedPaintInvalidationRectsRecursive(rootLayer);
859 }
860
861 void RenderLayerCompositor::setTracksPaintInvalidations(bool tracksPaintInvalidations)
862 {
863     ASSERT(lifecycle().state() == DocumentLifecycle::PaintInvalidationClean);
864     m_isTrackingPaintInvalidations = tracksPaintInvalidations;
865 }
866
867 bool RenderLayerCompositor::isTrackingPaintInvalidations() const
868 {
869     return m_isTrackingPaintInvalidations;
870 }
871
872 static bool shouldCompositeOverflowControls(FrameView* view)
873 {
874     if (Page* page = view->frame().page()) {
875         if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator())
876             if (scrollingCoordinator->coordinatesScrollingForFrameView(view))
877                 return true;
878     }
879
880     return true;
881 }
882
883 bool RenderLayerCompositor::requiresHorizontalScrollbarLayer() const
884 {
885     FrameView* view = m_renderView.frameView();
886     return shouldCompositeOverflowControls(view) && view->horizontalScrollbar();
887 }
888
889 bool RenderLayerCompositor::requiresVerticalScrollbarLayer() const
890 {
891     FrameView* view = m_renderView.frameView();
892     return shouldCompositeOverflowControls(view) && view->verticalScrollbar();
893 }
894
895 bool RenderLayerCompositor::requiresScrollCornerLayer() const
896 {
897     FrameView* view = m_renderView.frameView();
898     return shouldCompositeOverflowControls(view) && view->isScrollCornerVisible();
899 }
900
901 void RenderLayerCompositor::updateOverflowControlsLayers()
902 {
903 #if USE(RUBBER_BANDING)
904     if (m_renderView.frame()->isLocalRoot()) {
905         if (!m_layerForOverhangShadow) {
906             m_layerForOverhangShadow = GraphicsLayer::create(graphicsLayerFactory(), this);
907             OverscrollTheme::theme()->setUpOverhangShadowLayer(m_layerForOverhangShadow.get());
908             OverscrollTheme::theme()->updateOverhangShadowLayer(m_layerForOverhangShadow.get(), m_rootContentLayer.get());
909             m_scrollLayer->addChild(m_layerForOverhangShadow.get());
910         }
911     } else {
912         ASSERT(!m_layerForOverhangShadow);
913     }
914 #endif
915     GraphicsLayer* controlsParent = m_rootTransformLayer.get() ? m_rootTransformLayer.get() : m_overflowControlsHostLayer.get();
916
917     if (requiresHorizontalScrollbarLayer()) {
918         if (!m_layerForHorizontalScrollbar) {
919             m_layerForHorizontalScrollbar = GraphicsLayer::create(graphicsLayerFactory(), this);
920         }
921
922         if (m_layerForHorizontalScrollbar->parent() != controlsParent) {
923             controlsParent->addChild(m_layerForHorizontalScrollbar.get());
924
925             if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
926                 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), HorizontalScrollbar);
927         }
928     } else if (m_layerForHorizontalScrollbar) {
929         m_layerForHorizontalScrollbar->removeFromParent();
930         m_layerForHorizontalScrollbar = nullptr;
931
932         if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
933             scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), HorizontalScrollbar);
934     }
935
936     if (requiresVerticalScrollbarLayer()) {
937         if (!m_layerForVerticalScrollbar) {
938             m_layerForVerticalScrollbar = GraphicsLayer::create(graphicsLayerFactory(), this);
939         }
940
941         if (m_layerForVerticalScrollbar->parent() != controlsParent) {
942             controlsParent->addChild(m_layerForVerticalScrollbar.get());
943
944             if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
945                 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), VerticalScrollbar);
946         }
947     } else if (m_layerForVerticalScrollbar) {
948         m_layerForVerticalScrollbar->removeFromParent();
949         m_layerForVerticalScrollbar = nullptr;
950
951         if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
952             scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), VerticalScrollbar);
953     }
954
955     if (requiresScrollCornerLayer()) {
956         if (!m_layerForScrollCorner) {
957             m_layerForScrollCorner = GraphicsLayer::create(graphicsLayerFactory(), this);
958             controlsParent->addChild(m_layerForScrollCorner.get());
959         }
960     } else if (m_layerForScrollCorner) {
961         m_layerForScrollCorner->removeFromParent();
962         m_layerForScrollCorner = nullptr;
963     }
964
965     m_renderView.frameView()->positionScrollbarLayers();
966 }
967
968 void RenderLayerCompositor::ensureRootLayer()
969 {
970     RootLayerAttachment expectedAttachment = m_renderView.frame()->isLocalRoot() ? RootLayerAttachedViaChromeClient : RootLayerAttachedViaEnclosingFrame;
971     if (expectedAttachment == m_rootLayerAttachment)
972          return;
973
974     Settings* settings = m_renderView.document().settings();
975     if (!m_rootContentLayer) {
976         m_rootContentLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
977         IntRect overflowRect = m_renderView.pixelSnappedLayoutOverflowRect();
978         m_rootContentLayer->setSize(FloatSize(overflowRect.maxX(), overflowRect.maxY()));
979         m_rootContentLayer->setPosition(FloatPoint());
980         m_rootContentLayer->setOwnerNodeId(InspectorNodeIds::idForNode(m_renderView.generatingNode()));
981
982         // FIXME: with rootLayerScrolls, we probably don't even need m_rootContentLayer?
983         if (!(settings && settings->rootLayerScrolls())) {
984             // Need to clip to prevent transformed content showing outside this frame
985             m_rootContentLayer->setMasksToBounds(true);
986         }
987     }
988
989     if (!m_overflowControlsHostLayer) {
990         ASSERT(!m_scrollLayer);
991         ASSERT(!m_containerLayer);
992
993         // Create a layer to host the clipping layer and the overflow controls layers.
994         m_overflowControlsHostLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
995
996         // Clip iframe's overflow controls layer.
997         bool containerMasksToBounds = !m_renderView.frame()->isLocalRoot();
998         m_overflowControlsHostLayer->setMasksToBounds(containerMasksToBounds);
999
1000         // Create a clipping layer if this is an iframe or settings require to clip.
1001         m_containerLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
1002         if (Settings* settings = m_renderView.document().settings()) {
1003             if (settings->mainFrameClipsContent())
1004                 containerMasksToBounds = true;
1005         }
1006         m_containerLayer->setMasksToBounds(containerMasksToBounds);
1007
1008         m_scrollLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
1009         if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
1010             scrollingCoordinator->setLayerIsContainerForFixedPositionLayers(m_scrollLayer.get(), true);
1011
1012         // Hook them up
1013         m_overflowControlsHostLayer->addChild(m_containerLayer.get());
1014         m_containerLayer->addChild(m_scrollLayer.get());
1015         m_scrollLayer->addChild(m_rootContentLayer.get());
1016
1017         frameViewDidChangeSize();
1018     }
1019
1020     // Check to see if we have to change the attachment
1021     if (m_rootLayerAttachment != RootLayerUnattached)
1022         detachRootLayer();
1023
1024     attachRootLayer(expectedAttachment);
1025 }
1026
1027 void RenderLayerCompositor::destroyRootLayer()
1028 {
1029     if (!m_rootContentLayer)
1030         return;
1031
1032     detachRootLayer();
1033
1034 #if USE(RUBBER_BANDING)
1035     if (m_layerForOverhangShadow) {
1036         m_layerForOverhangShadow->removeFromParent();
1037         m_layerForOverhangShadow = nullptr;
1038     }
1039 #endif
1040
1041     if (m_layerForHorizontalScrollbar) {
1042         m_layerForHorizontalScrollbar->removeFromParent();
1043         m_layerForHorizontalScrollbar = nullptr;
1044         if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
1045             scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), HorizontalScrollbar);
1046         if (Scrollbar* horizontalScrollbar = m_renderView.frameView()->verticalScrollbar())
1047             m_renderView.frameView()->invalidateScrollbar(horizontalScrollbar, IntRect(IntPoint(0, 0), horizontalScrollbar->frameRect().size()));
1048     }
1049
1050     if (m_layerForVerticalScrollbar) {
1051         m_layerForVerticalScrollbar->removeFromParent();
1052         m_layerForVerticalScrollbar = nullptr;
1053         if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
1054             scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), VerticalScrollbar);
1055         if (Scrollbar* verticalScrollbar = m_renderView.frameView()->verticalScrollbar())
1056             m_renderView.frameView()->invalidateScrollbar(verticalScrollbar, IntRect(IntPoint(0, 0), verticalScrollbar->frameRect().size()));
1057     }
1058
1059     if (m_layerForScrollCorner) {
1060         m_layerForScrollCorner = nullptr;
1061         m_renderView.frameView()->invalidateScrollCorner(m_renderView.frameView()->scrollCornerRect());
1062     }
1063
1064     if (m_overflowControlsHostLayer) {
1065         m_overflowControlsHostLayer = nullptr;
1066         m_containerLayer = nullptr;
1067         m_scrollLayer = nullptr;
1068     }
1069     ASSERT(!m_scrollLayer);
1070     m_rootContentLayer = nullptr;
1071     m_rootTransformLayer = nullptr;
1072 }
1073
1074 void RenderLayerCompositor::attachRootLayer(RootLayerAttachment attachment)
1075 {
1076     if (!m_rootContentLayer)
1077         return;
1078
1079     switch (attachment) {
1080         case RootLayerUnattached:
1081             ASSERT_NOT_REACHED();
1082             break;
1083         case RootLayerAttachedViaChromeClient: {
1084             LocalFrame& frame = m_renderView.frameView()->frame();
1085             Page* page = frame.page();
1086             if (!page)
1087                 return;
1088             page->chrome().client().attachRootGraphicsLayer(rootGraphicsLayer());
1089             break;
1090         }
1091         case RootLayerAttachedViaEnclosingFrame: {
1092             HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement();
1093             ASSERT(ownerElement);
1094             // The layer will get hooked up via CompositedLayerMapping::updateGraphicsLayerConfiguration()
1095             // for the frame's renderer in the parent document.
1096             ownerElement->setNeedsCompositingUpdate();
1097             break;
1098         }
1099     }
1100
1101     m_rootLayerAttachment = attachment;
1102 }
1103
1104 void RenderLayerCompositor::detachRootLayer()
1105 {
1106     if (!m_rootContentLayer || m_rootLayerAttachment == RootLayerUnattached)
1107         return;
1108
1109     switch (m_rootLayerAttachment) {
1110     case RootLayerAttachedViaEnclosingFrame: {
1111         // The layer will get unhooked up via CompositedLayerMapping::updateGraphicsLayerConfiguration()
1112         // for the frame's renderer in the parent document.
1113         if (m_overflowControlsHostLayer)
1114             m_overflowControlsHostLayer->removeFromParent();
1115         else
1116             m_rootContentLayer->removeFromParent();
1117
1118         if (HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement())
1119             ownerElement->setNeedsCompositingUpdate();
1120         break;
1121     }
1122     case RootLayerAttachedViaChromeClient: {
1123         LocalFrame& frame = m_renderView.frameView()->frame();
1124         Page* page = frame.page();
1125         if (!page)
1126             return;
1127         page->chrome().client().attachRootGraphicsLayer(0);
1128     }
1129     break;
1130     case RootLayerUnattached:
1131         break;
1132     }
1133
1134     m_rootLayerAttachment = RootLayerUnattached;
1135 }
1136
1137 void RenderLayerCompositor::updateRootLayerAttachment()
1138 {
1139     ensureRootLayer();
1140 }
1141
1142 ScrollingCoordinator* RenderLayerCompositor::scrollingCoordinator() const
1143 {
1144     if (Page* page = this->page())
1145         return page->scrollingCoordinator();
1146
1147     return 0;
1148 }
1149
1150 GraphicsLayerFactory* RenderLayerCompositor::graphicsLayerFactory() const
1151 {
1152     if (Page* page = this->page())
1153         return page->chrome().client().graphicsLayerFactory();
1154     return 0;
1155 }
1156
1157 Page* RenderLayerCompositor::page() const
1158 {
1159     return m_renderView.frameView()->frame().page();
1160 }
1161
1162 DocumentLifecycle& RenderLayerCompositor::lifecycle() const
1163 {
1164     return m_renderView.document().lifecycle();
1165 }
1166
1167 String RenderLayerCompositor::debugName(const GraphicsLayer* graphicsLayer)
1168 {
1169     String name;
1170     if (graphicsLayer == m_rootContentLayer.get()) {
1171         name = "Content Root Layer";
1172     } else if (graphicsLayer == m_rootTransformLayer.get()) {
1173         name = "Root Transform Layer";
1174 #if USE(RUBBER_BANDING)
1175     } else if (graphicsLayer == m_layerForOverhangShadow.get()) {
1176         name = "Overhang Areas Shadow";
1177 #endif
1178     } else if (graphicsLayer == m_overflowControlsHostLayer.get()) {
1179         name = "Overflow Controls Host Layer";
1180     } else if (graphicsLayer == m_layerForHorizontalScrollbar.get()) {
1181         name = "Horizontal Scrollbar Layer";
1182     } else if (graphicsLayer == m_layerForVerticalScrollbar.get()) {
1183         name = "Vertical Scrollbar Layer";
1184     } else if (graphicsLayer == m_layerForScrollCorner.get()) {
1185         name = "Scroll Corner Layer";
1186     } else if (graphicsLayer == m_containerLayer.get()) {
1187         name = "LocalFrame Clipping Layer";
1188     } else if (graphicsLayer == m_scrollLayer.get()) {
1189         name = "LocalFrame Scrolling Layer";
1190     } else {
1191         ASSERT_NOT_REACHED();
1192     }
1193
1194     return name;
1195 }
1196
1197 } // namespace blink