2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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 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.
28 #include "RenderLayerCompositor.h"
30 #include "AnimationController.h"
31 #include "CanvasRenderingContext.h"
32 #include "CSSPropertyNames.h"
34 #include "ChromeClient.h"
35 #include "FlowThreadController.h"
37 #include "FrameView.h"
38 #include "GraphicsLayer.h"
39 #include "HTMLCanvasElement.h"
40 #include "HTMLIFrameElement.h"
41 #include "HTMLNames.h"
42 #include "HitTestResult.h"
43 #include "InspectorInstrumentation.h"
45 #include "MainFrame.h"
48 #include "ProgressTracker.h"
49 #include "RenderEmbeddedObject.h"
50 #include "RenderFlowThread.h"
51 #include "RenderFullScreen.h"
52 #include "RenderGeometryMap.h"
53 #include "RenderIFrame.h"
54 #include "RenderLayerBacking.h"
55 #include "RenderNamedFlowFragment.h"
56 #include "RenderReplica.h"
57 #include "RenderVideo.h"
58 #include "RenderView.h"
59 #include "ScrollingConstraints.h"
60 #include "ScrollingCoordinator.h"
62 #include "TiledBacking.h"
63 #include "TransformState.h"
64 #include <wtf/CurrentTime.h>
65 #include <wtf/TemporaryChange.h>
66 #include <wtf/text/CString.h>
67 #include <wtf/text/StringBuilder.h>
70 #include "LegacyTileCache.h"
71 #include "MainFrame.h"
73 #include "RenderScrollbar.h"
77 #include "RenderTreeAsText.h"
80 #if ENABLE(3D_RENDERING)
81 // This symbol is used to determine from a script whether 3D rendering is enabled (via 'nm').
82 bool WebCoreHas3DRendering = true;
85 #if !PLATFORM(MAC) && !PLATFORM(IOS)
86 #define WTF_USE_COMPOSITING_FOR_SMALL_CANVASES 1
91 static const int canvasAreaThresholdRequiringCompositing = 50 * 100;
92 // During page loading delay layer flushes up to this many seconds to allow them coalesce, reducing workload.
94 static const double throttledLayerFlushInitialDelay = .5;
95 static const double throttledLayerFlushDelay = 1.5;
97 static const double throttledLayerFlushInitialDelay = .5;
98 static const double throttledLayerFlushDelay = .5;
101 using namespace HTMLNames;
103 class OverlapMapContainer {
105 void add(const IntRect& bounds)
107 m_layerRects.append(bounds);
108 m_boundingBox.unite(bounds);
111 bool overlapsLayers(const IntRect& bounds) const
113 // Checking with the bounding box will quickly reject cases when
114 // layers are created for lists of items going in one direction and
115 // never overlap with each other.
116 if (!bounds.intersects(m_boundingBox))
118 for (unsigned i = 0; i < m_layerRects.size(); i++) {
119 if (m_layerRects[i].intersects(bounds))
125 void unite(const OverlapMapContainer& otherContainer)
127 m_layerRects.appendVector(otherContainer.m_layerRects);
128 m_boundingBox.unite(otherContainer.m_boundingBox);
131 Vector<IntRect> m_layerRects;
132 IntRect m_boundingBox;
135 class RenderLayerCompositor::OverlapMap {
136 WTF_MAKE_NONCOPYABLE(OverlapMap);
139 : m_geometryMap(UseTransforms)
141 // Begin assuming the root layer will be composited so that there is
142 // something on the stack. The root layer should also never get an
143 // popCompositingContainer call.
144 pushCompositingContainer();
147 void add(const RenderLayer* layer, const IntRect& bounds)
149 // Layers do not contribute to overlap immediately--instead, they will
150 // contribute to overlap as soon as their composited ancestor has been
151 // recursively processed and popped off the stack.
152 ASSERT(m_overlapStack.size() >= 2);
153 m_overlapStack[m_overlapStack.size() - 2].add(bounds);
157 bool contains(const RenderLayer* layer)
159 return m_layers.contains(layer);
162 bool overlapsLayers(const IntRect& bounds) const
164 return m_overlapStack.last().overlapsLayers(bounds);
169 return m_layers.isEmpty();
172 void pushCompositingContainer()
174 m_overlapStack.append(OverlapMapContainer());
177 void popCompositingContainer()
179 m_overlapStack[m_overlapStack.size() - 2].unite(m_overlapStack.last());
180 m_overlapStack.removeLast();
183 RenderGeometryMap& geometryMap() { return m_geometryMap; }
187 Vector<IntRect> rects;
188 IntRect boundingRect;
190 void append(const IntRect& rect)
193 boundingRect.unite(rect);
196 void append(const RectList& rectList)
198 rects.appendVector(rectList.rects);
199 boundingRect.unite(rectList.boundingRect);
202 bool intersects(const IntRect& rect) const
204 if (!rects.size() || !boundingRect.intersects(rect))
207 for (unsigned i = 0; i < rects.size(); i++) {
208 if (rects[i].intersects(rect))
215 Vector<OverlapMapContainer> m_overlapStack;
216 HashSet<const RenderLayer*> m_layers;
217 RenderGeometryMap m_geometryMap;
220 struct CompositingState {
221 CompositingState(RenderLayer* compAncestor, bool testOverlap = true)
222 : m_compositingAncestor(compAncestor)
223 , m_subtreeIsCompositing(false)
224 , m_testingOverlap(testOverlap)
225 #if ENABLE(CSS_COMPOSITING)
226 , m_hasUnisolatedCompositedBlendingDescendants(false)
234 CompositingState(const CompositingState& other)
235 : m_compositingAncestor(other.m_compositingAncestor)
236 , m_subtreeIsCompositing(other.m_subtreeIsCompositing)
237 , m_testingOverlap(other.m_testingOverlap)
238 #if ENABLE(CSS_COMPOSITING)
239 , m_hasUnisolatedCompositedBlendingDescendants(other.m_hasUnisolatedCompositedBlendingDescendants)
242 , m_depth(other.m_depth + 1)
247 RenderLayer* m_compositingAncestor;
248 bool m_subtreeIsCompositing;
249 bool m_testingOverlap;
250 #if ENABLE(CSS_COMPOSITING)
251 bool m_hasUnisolatedCompositedBlendingDescendants;
260 static inline bool compositingLogEnabled()
262 return LogCompositing.state == WTFLogChannelOn;
266 RenderLayerCompositor::RenderLayerCompositor(RenderView& renderView)
267 : m_renderView(renderView)
268 , m_updateCompositingLayersTimer(this, &RenderLayerCompositor::updateCompositingLayersTimerFired)
269 , m_hasAcceleratedCompositing(true)
270 , m_compositingTriggers(static_cast<ChromeClient::CompositingTriggerFlags>(ChromeClient::AllTriggers))
271 , m_compositedLayerCount(0)
272 , m_showDebugBorders(false)
273 , m_showRepaintCounter(false)
274 , m_acceleratedDrawingEnabled(false)
275 , m_reevaluateCompositingAfterLayout(false)
276 , m_compositing(false)
277 , m_compositingLayersNeedRebuild(false)
278 , m_flushingLayers(false)
279 , m_shouldFlushOnReattach(false)
280 , m_forceCompositingMode(false)
281 , m_inPostLayoutUpdate(false)
282 , m_isTrackingRepaints(false)
283 , m_layersWithTiledBackingCount(0)
284 , m_rootLayerAttachment(RootLayerUnattached)
285 , m_layerFlushTimer(this, &RenderLayerCompositor::layerFlushTimerFired)
286 , m_layerFlushThrottlingEnabled(page() && page()->progress().isMainLoadProgressing())
287 , m_layerFlushThrottlingTemporarilyDisabledForInteraction(false)
288 , m_hasPendingLayerFlush(false)
289 , m_paintRelatedMilestonesTimer(this, &RenderLayerCompositor::paintRelatedMilestonesTimerFired)
291 , m_rootLayerUpdateCount(0)
292 , m_obligateCompositedLayerCount(0)
293 , m_secondaryCompositedLayerCount(0)
294 , m_obligatoryBackingStoreBytes(0)
295 , m_secondaryBackingStoreBytes(0)
300 RenderLayerCompositor::~RenderLayerCompositor()
302 // Take care that the owned GraphicsLayers are deleted first as their destructors may call back here.
303 m_clipLayer = nullptr;
304 m_scrollLayer = nullptr;
305 ASSERT(m_rootLayerAttachment == RootLayerUnattached);
308 void RenderLayerCompositor::enableCompositingMode(bool enable /* = true */)
310 if (enable != m_compositing) {
311 m_compositing = enable;
315 notifyIFramesOfCompositingChange();
321 void RenderLayerCompositor::cacheAcceleratedCompositingFlags()
323 bool hasAcceleratedCompositing = false;
324 bool showDebugBorders = false;
325 bool showRepaintCounter = false;
326 bool forceCompositingMode = false;
327 bool acceleratedDrawingEnabled = false;
329 const Settings& settings = m_renderView.frameView().frame().settings();
330 hasAcceleratedCompositing = settings.acceleratedCompositingEnabled();
332 // We allow the chrome to override the settings, in case the page is rendered
333 // on a chrome that doesn't allow accelerated compositing.
334 if (hasAcceleratedCompositing) {
335 if (Page* page = this->page()) {
336 m_compositingTriggers = page->chrome().client().allowedCompositingTriggers();
337 hasAcceleratedCompositing = m_compositingTriggers;
341 showDebugBorders = settings.showDebugBorders();
342 showRepaintCounter = settings.showRepaintCounter();
343 forceCompositingMode = settings.forceCompositingMode() && hasAcceleratedCompositing;
345 if (forceCompositingMode && m_renderView.document().ownerElement())
346 forceCompositingMode = requiresCompositingForScrollableFrame();
348 acceleratedDrawingEnabled = settings.acceleratedDrawingEnabled();
350 if (hasAcceleratedCompositing != m_hasAcceleratedCompositing || showDebugBorders != m_showDebugBorders || showRepaintCounter != m_showRepaintCounter || forceCompositingMode != m_forceCompositingMode)
351 setCompositingLayersNeedRebuild();
353 bool debugBordersChanged = m_showDebugBorders != showDebugBorders;
354 m_hasAcceleratedCompositing = hasAcceleratedCompositing;
355 m_showDebugBorders = showDebugBorders;
356 m_showRepaintCounter = showRepaintCounter;
357 m_forceCompositingMode = forceCompositingMode;
358 m_acceleratedDrawingEnabled = acceleratedDrawingEnabled;
360 if (debugBordersChanged) {
361 if (m_layerForHorizontalScrollbar)
362 m_layerForHorizontalScrollbar->setShowDebugBorder(m_showDebugBorders);
364 if (m_layerForVerticalScrollbar)
365 m_layerForVerticalScrollbar->setShowDebugBorder(m_showDebugBorders);
367 if (m_layerForScrollCorner)
368 m_layerForScrollCorner->setShowDebugBorder(m_showDebugBorders);
372 bool RenderLayerCompositor::canRender3DTransforms() const
374 return hasAcceleratedCompositing() && (m_compositingTriggers & ChromeClient::ThreeDTransformTrigger);
377 void RenderLayerCompositor::setCompositingLayersNeedRebuild(bool needRebuild)
379 if (inCompositingMode())
380 m_compositingLayersNeedRebuild = needRebuild;
383 void RenderLayerCompositor::customPositionForVisibleRectComputation(const GraphicsLayer* graphicsLayer, FloatPoint& position) const
385 if (graphicsLayer != m_scrollLayer.get())
388 FloatPoint scrollPosition = -position;
390 if (m_renderView.frameView().scrollBehaviorForFixedElements() == StickToDocumentBounds)
391 scrollPosition = m_renderView.frameView().constrainScrollPositionForOverhang(roundedIntPoint(scrollPosition));
393 position = -scrollPosition;
396 void RenderLayerCompositor::notifyFlushRequired(const GraphicsLayer* layer)
398 scheduleLayerFlush(layer->canThrottleLayerFlush());
401 void RenderLayerCompositor::scheduleLayerFlushNow()
403 m_hasPendingLayerFlush = false;
404 if (Page* page = this->page())
405 page->chrome().client().scheduleCompositingLayerFlush();
408 void RenderLayerCompositor::scheduleLayerFlush(bool canThrottle)
410 ASSERT(!m_flushingLayers);
413 startInitialLayerFlushTimerIfNeeded();
415 if (canThrottle && isThrottlingLayerFlushes()) {
416 m_hasPendingLayerFlush = true;
419 scheduleLayerFlushNow();
423 ChromeClient* RenderLayerCompositor::chromeClient() const
425 Page* page = m_renderView.frameView().frame().page();
428 return &page->chrome().client();
432 void RenderLayerCompositor::flushPendingLayerChanges(bool isFlushRoot)
434 // FrameView::flushCompositingStateIncludingSubframes() flushes each subframe,
435 // but GraphicsLayer::flushCompositingState() will cross frame boundaries
436 // if the GraphicsLayers are connected (the RootLayerAttachedViaEnclosingFrame case).
437 // As long as we're not the root of the flush, we can bail.
438 if (!isFlushRoot && rootLayerAttachment() == RootLayerAttachedViaEnclosingFrame)
441 if (rootLayerAttachment() == RootLayerUnattached) {
443 startLayerFlushTimerIfNeeded();
445 m_shouldFlushOnReattach = true;
449 FrameView& frameView = m_renderView.frameView();
450 AnimationUpdateBlock animationUpdateBlock(&frameView.frame().animation());
452 ASSERT(!m_flushingLayers);
453 m_flushingLayers = true;
455 if (GraphicsLayer* rootLayer = rootGraphicsLayer()) {
457 double horizontalMargin = defaultTileWidth / pageScaleFactor();
458 double verticalMargin = defaultTileHeight / pageScaleFactor();
459 FloatRect visibleRect = frameView.computeCoverageRect(horizontalMargin, verticalMargin);
460 rootLayer->flushCompositingState(visibleRect);
462 // Having a m_clipLayer indicates that we're doing scrolling via GraphicsLayers.
463 IntRect visibleRect = m_clipLayer ? IntRect(IntPoint(), frameView.contentsSize()) : frameView.visibleContentRect();
464 if (!frameView.exposedRect().isInfinite())
465 visibleRect.intersect(IntRect(frameView.exposedRect()));
466 rootLayer->flushCompositingState(visibleRect);
470 ASSERT(m_flushingLayers);
471 m_flushingLayers = false;
474 updateCustomLayersAfterFlush();
476 ChromeClient* client = this->chromeClient();
477 if (client && isFlushRoot)
478 client->didFlushCompositingLayers();
481 for (auto it = m_scrollCoordinatedLayersNeedingUpdate.begin(), end = m_scrollCoordinatedLayersNeedingUpdate.end(); it != end; ++it)
482 updateScrollCoordinatedStatus(**it);
484 m_scrollCoordinatedLayersNeedingUpdate.clear();
485 startLayerFlushTimerIfNeeded();
489 static bool scrollbarHasDisplayNone(Scrollbar* scrollbar)
491 if (!scrollbar || !scrollbar->isCustomScrollbar())
494 RefPtr<RenderStyle> scrollbarStyle = static_cast<RenderScrollbar*>(scrollbar)->getScrollbarPseudoStyle(ScrollbarBGPart, SCROLLBAR);
495 return scrollbarStyle && scrollbarStyle->display() == NONE;
498 // FIXME: Can we make |layer| const RenderLayer&?
499 static void updateScrollingLayerWithClient(RenderLayer& layer, ChromeClient* client)
504 RenderLayerBacking* backing = layer.backing();
507 bool allowHorizontalScrollbar = !scrollbarHasDisplayNone(layer.horizontalScrollbar());
508 bool allowVerticalScrollbar = !scrollbarHasDisplayNone(layer.verticalScrollbar());
509 client->addOrUpdateScrollingLayer(layer.renderer().element(), backing->scrollingLayer()->platformLayer(), backing->scrollingContentsLayer()->platformLayer(),
510 IntSize(layer.scrollWidth(), layer.scrollHeight()), allowHorizontalScrollbar, allowVerticalScrollbar);
513 void RenderLayerCompositor::updateCustomLayersAfterFlush()
515 registerAllViewportConstrainedLayers();
517 if (!m_scrollingLayersNeedingUpdate.isEmpty()) {
518 ChromeClient* chromeClient = this->chromeClient();
520 for (auto it = m_scrollingLayersNeedingUpdate.begin(), end = m_scrollingLayersNeedingUpdate.end(); it != end; ++it)
521 updateScrollingLayerWithClient(**it, chromeClient);
522 m_scrollingLayersNeedingUpdate.clear();
524 m_scrollingLayersNeedingUpdate.clear();
528 void RenderLayerCompositor::didFlushChangesForLayer(RenderLayer& layer, const GraphicsLayer* graphicsLayer)
530 if (m_scrollCoordinatedLayers.contains(&layer))
531 m_scrollCoordinatedLayersNeedingUpdate.add(&layer);
534 if (m_scrollingLayers.contains(&layer))
535 m_scrollingLayersNeedingUpdate.add(&layer);
538 RenderLayerBacking* backing = layer.backing();
539 if (backing->backgroundLayerPaintsFixedRootBackground() && graphicsLayer == backing->backgroundLayer())
540 fixedRootBackgroundLayerChanged();
543 void RenderLayerCompositor::didPaintBacking(RenderLayerBacking*)
545 FrameView& frameView = m_renderView.frameView();
546 frameView.setLastPaintTime(monotonicallyIncreasingTime());
547 if (frameView.milestonesPendingPaint() && !m_paintRelatedMilestonesTimer.isActive())
548 m_paintRelatedMilestonesTimer.startOneShot(0);
551 void RenderLayerCompositor::didChangeVisibleRect()
553 GraphicsLayer* rootLayer = rootGraphicsLayer();
557 const FrameView& frameView = m_renderView.frameView();
560 IntRect visibleRect = frameView.exposedContentRect();
562 IntRect visibleRect = m_clipLayer ? IntRect(IntPoint(), frameView.contentsSize()) : frameView.visibleContentRect();
564 if (!rootLayer->visibleRectChangeRequiresFlush(visibleRect))
566 scheduleLayerFlushNow();
569 void RenderLayerCompositor::notifyFlushBeforeDisplayRefresh(const GraphicsLayer*)
571 if (!m_layerUpdater) {
572 PlatformDisplayID displayID = 0;
573 if (Page* page = this->page())
574 displayID = page->chrome().displayID();
576 m_layerUpdater = std::make_unique<GraphicsLayerUpdater>(this, displayID);
579 m_layerUpdater->scheduleUpdate();
582 void RenderLayerCompositor::flushLayers(GraphicsLayerUpdater*)
584 flushPendingLayerChanges(true); // FIXME: deal with iframes
587 void RenderLayerCompositor::layerTiledBackingUsageChanged(const GraphicsLayer*, bool usingTiledBacking)
589 if (usingTiledBacking)
590 ++m_layersWithTiledBackingCount;
592 ASSERT(m_layersWithTiledBackingCount > 0);
593 --m_layersWithTiledBackingCount;
597 RenderLayerCompositor* RenderLayerCompositor::enclosingCompositorFlushingLayers() const
599 for (Frame* frame = &m_renderView.frameView().frame(); frame; frame = frame->tree().parent()) {
600 RenderLayerCompositor* compositor = frame->contentRenderer() ? &frame->contentRenderer()->compositor() : 0;
601 if (compositor->isFlushingLayers())
608 void RenderLayerCompositor::scheduleCompositingLayerUpdate()
610 if (!m_updateCompositingLayersTimer.isActive())
611 m_updateCompositingLayersTimer.startOneShot(0);
614 void RenderLayerCompositor::updateCompositingLayersTimerFired(Timer<RenderLayerCompositor>&)
616 updateCompositingLayers(CompositingUpdateAfterLayout);
619 bool RenderLayerCompositor::hasAnyAdditionalCompositedLayers(const RenderLayer& rootLayer) const
621 return m_compositedLayerCount > (rootLayer.isComposited() ? 1 : 0);
624 void RenderLayerCompositor::updateCompositingLayers(CompositingUpdateType updateType, RenderLayer* updateRoot)
626 m_updateCompositingLayersTimer.stop();
628 ASSERT(!m_renderView.document().inPageCache());
630 // Compositing layers will be updated in Document::implicitClose() if suppressed here.
631 if (!m_renderView.document().visualUpdatesAllowed())
634 // Avoid updating the layers with old values. Compositing layers will be updated after the layout is finished.
635 if (m_renderView.needsLayout())
638 if (m_forceCompositingMode && !m_compositing)
639 enableCompositingMode(true);
641 if (!m_reevaluateCompositingAfterLayout && !m_compositing)
644 AnimationUpdateBlock animationUpdateBlock(&m_renderView.frameView().frame().animation());
646 TemporaryChange<bool> postLayoutChange(m_inPostLayoutUpdate, true);
648 bool checkForHierarchyUpdate = m_reevaluateCompositingAfterLayout;
649 bool needGeometryUpdate = false;
651 switch (updateType) {
652 case CompositingUpdateAfterStyleChange:
653 case CompositingUpdateAfterLayout:
654 case CompositingUpdateOnHitTest:
655 checkForHierarchyUpdate = true;
657 case CompositingUpdateOnScroll:
658 checkForHierarchyUpdate = true; // Overlap can change with scrolling, so need to check for hierarchy updates.
660 needGeometryUpdate = true;
662 case CompositingUpdateOnCompositedScroll:
663 needGeometryUpdate = true;
667 if (!checkForHierarchyUpdate && !needGeometryUpdate)
670 bool needHierarchyUpdate = m_compositingLayersNeedRebuild;
671 bool isFullUpdate = !updateRoot;
673 // Only clear the flag if we're updating the entire hierarchy.
674 m_compositingLayersNeedRebuild = false;
675 updateRoot = &rootRenderLayer();
677 if (isFullUpdate && updateType == CompositingUpdateAfterLayout)
678 m_reevaluateCompositingAfterLayout = false;
681 double startTime = 0;
682 if (compositingLogEnabled()) {
683 ++m_rootLayerUpdateCount;
684 startTime = monotonicallyIncreasingTime();
688 if (checkForHierarchyUpdate) {
689 if (m_renderView.hasRenderNamedFlowThreads() && isFullUpdate)
690 m_renderView.flowThreadController().updateFlowThreadsLayerToRegionMappingsIfNeeded();
691 // Go through the layers in presentation order, so that we can compute which RenderLayers need compositing layers.
692 // FIXME: we could maybe do this and the hierarchy udpate in one pass, but the parenting logic would be more complex.
693 CompositingState compState(updateRoot);
694 bool layersChanged = false;
695 bool saw3DTransform = false;
696 OverlapMap overlapTestRequestMap;
697 computeCompositingRequirements(nullptr, *updateRoot, &overlapTestRequestMap, compState, layersChanged, saw3DTransform);
698 needHierarchyUpdate |= layersChanged;
702 if (compositingLogEnabled() && isFullUpdate && (needHierarchyUpdate || needGeometryUpdate)) {
703 m_obligateCompositedLayerCount = 0;
704 m_secondaryCompositedLayerCount = 0;
705 m_obligatoryBackingStoreBytes = 0;
706 m_secondaryBackingStoreBytes = 0;
708 Frame& frame = m_renderView.frameView().frame();
709 bool isMainFrame = !m_renderView.document().ownerElement();
710 LOG(Compositing, "\nUpdate %d of %s.\n", m_rootLayerUpdateCount, isMainFrame ? "main frame" : frame.tree().uniqueName().string().utf8().data());
714 if (needHierarchyUpdate) {
715 // Update the hierarchy of the compositing layers.
716 Vector<GraphicsLayer*> childList;
717 rebuildCompositingLayerTree(*updateRoot, childList, 0);
719 // Host the document layer in the RenderView's root layer.
721 appendOverlayLayers(childList);
722 // Even when childList is empty, don't drop out of compositing mode if there are
723 // composited layers that we didn't hit in our traversal (e.g. because of visibility:hidden).
724 if (childList.isEmpty() && !hasAnyAdditionalCompositedLayers(*updateRoot))
726 else if (m_rootContentLayer)
727 m_rootContentLayer->setChildren(childList);
729 } else if (needGeometryUpdate) {
730 // We just need to do a geometry update. This is only used for position:fixed scrolling;
731 // most of the time, geometry is updated via RenderLayer::styleChanged().
732 updateLayerTreeGeometry(*updateRoot, 0);
736 if (compositingLogEnabled() && isFullUpdate && (needHierarchyUpdate || needGeometryUpdate)) {
737 double endTime = monotonicallyIncreasingTime();
738 LOG(Compositing, "Total layers primary secondary obligatory backing (KB) secondary backing(KB) total backing (KB) update time (ms)\n");
740 LOG(Compositing, "%8d %11d %9d %20.2f %22.2f %22.2f %18.2f\n",
741 m_obligateCompositedLayerCount + m_secondaryCompositedLayerCount, m_obligateCompositedLayerCount,
742 m_secondaryCompositedLayerCount, m_obligatoryBackingStoreBytes / 1024, m_secondaryBackingStoreBytes / 1024, (m_obligatoryBackingStoreBytes + m_secondaryBackingStoreBytes) / 1024, 1000.0 * (endTime - startTime));
745 ASSERT(updateRoot || !m_compositingLayersNeedRebuild);
747 if (!hasAcceleratedCompositing())
748 enableCompositingMode(false);
750 // Inform the inspector that the layer tree has changed.
751 InspectorInstrumentation::layerTreeDidChange(page());
754 void RenderLayerCompositor::appendOverlayLayers(Vector<GraphicsLayer*>& childList)
756 Frame& frame = m_renderView.frameView().frame();
757 Page* page = frame.page();
761 if (GraphicsLayer* overlayLayer = page->chrome().client().documentOverlayLayerForFrame(frame))
762 childList.append(overlayLayer);
765 void RenderLayerCompositor::layerBecameNonComposited(const RenderLayer& layer)
767 // Inform the inspector that the given RenderLayer was destroyed.
768 InspectorInstrumentation::renderLayerDestroyed(page(), &layer);
770 ASSERT(m_compositedLayerCount > 0);
771 --m_compositedLayerCount;
775 void RenderLayerCompositor::logLayerInfo(const RenderLayer& layer, int depth)
777 if (!compositingLogEnabled())
780 RenderLayerBacking* backing = layer.backing();
781 if (requiresCompositingLayer(layer) || layer.isRootLayer()) {
782 ++m_obligateCompositedLayerCount;
783 m_obligatoryBackingStoreBytes += backing->backingStoreMemoryEstimate();
785 ++m_secondaryCompositedLayerCount;
786 m_secondaryBackingStoreBytes += backing->backingStoreMemoryEstimate();
789 StringBuilder logString;
790 logString.append(String::format("%*p %dx%d %.2fKB", 12 + depth * 2, &layer,
791 backing->compositedBounds().width().round(), backing->compositedBounds().height().round(),
792 backing->backingStoreMemoryEstimate() / 1024));
794 logString.append(" (");
795 logString.append(logReasonsForCompositing(layer));
796 logString.append(") ");
798 if (backing->graphicsLayer()->contentsOpaque() || backing->paintsIntoCompositedAncestor()) {
799 logString.append('[');
800 if (backing->graphicsLayer()->contentsOpaque())
801 logString.append("opaque");
802 if (backing->paintsIntoCompositedAncestor())
803 logString.append("paints into ancestor");
804 logString.append("] ");
807 logString.append(layer.name());
809 LOG(Compositing, "%s", logString.toString().utf8().data());
813 bool RenderLayerCompositor::updateBacking(RenderLayer& layer, CompositingChangeRepaint shouldRepaint)
815 bool layerChanged = false;
816 RenderLayer::ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason = RenderLayer::NoNotCompositedReason;
818 if (needsToBeComposited(layer, &viewportConstrainedNotCompositedReason)) {
819 enableCompositingMode();
821 if (!layer.backing()) {
822 // If we need to repaint, do so before making backing
823 if (shouldRepaint == CompositingChangeRepaintNow)
824 repaintOnCompositingChange(layer);
826 layer.ensureBacking();
828 // At this time, the ScrollingCoordinator only supports the top-level frame.
829 if (layer.isRootLayer() && !m_renderView.document().ownerElement()) {
830 updateScrollCoordinatedStatus(layer);
831 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
832 scrollingCoordinator->frameViewRootLayerDidChange(&m_renderView.frameView());
833 #if ENABLE(RUBBER_BANDING)
834 if (Page* page = this->page()) {
835 updateLayerForHeader(page->headerHeight());
836 updateLayerForFooter(page->footerHeight());
839 if (m_renderView.frameView().frame().settings().backgroundShouldExtendBeyondPage())
840 m_rootContentLayer->setMasksToBounds(false);
843 // This layer and all of its descendants have cached repaints rects that are relative to
844 // the repaint container, so change when compositing changes; we need to update them here.
846 layer.computeRepaintRectsIncludingDescendants();
851 if (layer.backing()) {
852 // If we're removing backing on a reflection, clear the source GraphicsLayer's pointer to
853 // its replica GraphicsLayer. In practice this should never happen because reflectee and reflection
854 // are both either composited, or not composited.
855 if (layer.isReflection()) {
856 RenderLayer* sourceLayer = toRenderLayerModelObject(layer.renderer().parent())->layer();
857 if (RenderLayerBacking* backing = sourceLayer->backing()) {
858 ASSERT(backing->graphicsLayer()->replicaLayer() == layer.backing()->graphicsLayer());
859 backing->graphicsLayer()->setReplicatedByLayer(0);
863 removeFromScrollCoordinatedLayers(layer);
865 layer.clearBacking();
868 // This layer and all of its descendants have cached repaints rects that are relative to
869 // the repaint container, so change when compositing changes; we need to update them here.
870 layer.computeRepaintRectsIncludingDescendants();
872 // If we need to repaint, do so now that we've removed the backing
873 if (shouldRepaint == CompositingChangeRepaintNow)
874 repaintOnCompositingChange(layer);
879 if (layerChanged && layer.renderer().isVideo()) {
880 // If it's a video, give the media player a chance to hook up to the layer.
881 toRenderVideo(layer.renderer()).acceleratedRenderingStateChanged();
885 if (layerChanged && layer.renderer().isWidget()) {
886 RenderLayerCompositor* innerCompositor = frameContentsCompositor(toRenderWidget(&layer.renderer()));
887 if (innerCompositor && innerCompositor->inCompositingMode())
888 innerCompositor->updateRootLayerAttachment();
892 layer.clearClipRectsIncludingDescendants(PaintingClipRects);
894 // If a fixed position layer gained/lost a backing or the reason not compositing it changed,
895 // the scrolling coordinator needs to recalculate whether it can do fast scrolling.
896 if (layer.renderer().style().position() == FixedPosition) {
897 if (layer.viewportConstrainedNotCompositedReason() != viewportConstrainedNotCompositedReason) {
898 layer.setViewportConstrainedNotCompositedReason(viewportConstrainedNotCompositedReason);
902 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
903 scrollingCoordinator->frameViewFixedObjectsDidChange(&m_renderView.frameView());
906 layer.setViewportConstrainedNotCompositedReason(RenderLayer::NoNotCompositedReason);
909 layer.backing()->updateDebugIndicators(m_showDebugBorders, m_showRepaintCounter);
914 bool RenderLayerCompositor::updateLayerCompositingState(RenderLayer& layer, CompositingChangeRepaint shouldRepaint)
916 bool layerChanged = updateBacking(layer, shouldRepaint);
918 // See if we need content or clipping layers. Methods called here should assume
919 // that the compositing state of descendant layers has not been updated yet.
920 if (layer.backing() && layer.backing()->updateGraphicsLayerConfiguration())
926 void RenderLayerCompositor::repaintOnCompositingChange(RenderLayer& layer)
928 // If the renderer is not attached yet, no need to repaint.
929 if (&layer.renderer() != &m_renderView && !layer.renderer().parent())
932 RenderLayerModelObject* repaintContainer = layer.renderer().containerForRepaint();
933 if (!repaintContainer)
934 repaintContainer = &m_renderView;
936 layer.repaintIncludingNonCompositingDescendants(repaintContainer);
937 if (repaintContainer == &m_renderView) {
938 // The contents of this layer may be moving between the window
939 // and a GraphicsLayer, so we need to make sure the window system
940 // synchronizes those changes on the screen.
941 m_renderView.frameView().setNeedsOneShotDrawingSynchronization();
945 // This method assumes that layout is up-to-date, unlike repaintOnCompositingChange().
946 void RenderLayerCompositor::repaintInCompositedAncestor(RenderLayer& layer, const LayoutRect& rect)
948 RenderLayer* compositedAncestor = layer.enclosingCompositingLayerForRepaint(ExcludeSelf);
949 if (compositedAncestor) {
950 ASSERT(compositedAncestor->backing());
953 layer.convertToLayerCoords(compositedAncestor, offset);
955 LayoutRect repaintRect = rect;
956 repaintRect.moveBy(offset);
958 compositedAncestor->setBackingNeedsRepaintInRect(repaintRect);
961 // The contents of this layer may be moving from a GraphicsLayer to the window,
962 // so we need to make sure the window system synchronizes those changes on the screen.
963 if (compositedAncestor == m_renderView.layer())
964 m_renderView.frameView().setNeedsOneShotDrawingSynchronization();
967 // The bounds of the GraphicsLayer created for a compositing layer is the union of the bounds of all the descendant
968 // RenderLayers that are rendered by the composited RenderLayer.
969 LayoutRect RenderLayerCompositor::calculateCompositedBounds(const RenderLayer& layer, const RenderLayer& ancestorLayer) const
971 if (!canBeComposited(layer))
973 return layer.calculateLayerBounds(&ancestorLayer, nullptr, RenderLayer::DefaultCalculateLayerBoundsFlags | RenderLayer::ExcludeHiddenDescendants | RenderLayer::DontConstrainForMask);
976 void RenderLayerCompositor::layerWasAdded(RenderLayer&, RenderLayer&)
978 setCompositingLayersNeedRebuild();
981 void RenderLayerCompositor::layerWillBeRemoved(RenderLayer& parent, RenderLayer& child)
983 if (!child.isComposited() || parent.renderer().documentBeingDestroyed())
986 removeFromScrollCoordinatedLayers(child);
987 repaintInCompositedAncestor(child, child.backing()->compositedBounds());
989 setCompositingParent(child, nullptr);
990 setCompositingLayersNeedRebuild();
993 RenderLayer* RenderLayerCompositor::enclosingNonStackingClippingLayer(const RenderLayer& layer) const
995 for (RenderLayer* parent = layer.parent(); parent; parent = parent->parent()) {
996 if (parent->isStackingContainer())
998 if (parent->renderer().hasClipOrOverflowClip())
1004 void RenderLayerCompositor::addToOverlapMap(OverlapMap& overlapMap, RenderLayer& layer, IntRect& layerBounds, bool& boundsComputed)
1006 if (layer.isRootLayer())
1009 if (!boundsComputed) {
1010 // FIXME: If this layer's overlap bounds include its children, we don't need to add its
1011 // children's bounds to the overlap map.
1012 layerBounds = enclosingIntRect(overlapMap.geometryMap().absoluteRect(layer.overlapBounds()));
1013 // Empty rects never intersect, but we need them to for the purposes of overlap testing.
1014 if (layerBounds.isEmpty())
1015 layerBounds.setSize(IntSize(1, 1));
1016 boundsComputed = true;
1019 IntRect clipRect = pixelSnappedIntRect(layer.backgroundClipRect(RenderLayer::ClipRectsContext(&rootRenderLayer(), 0, AbsoluteClipRects)).rect()); // FIXME: Incorrect for CSS regions.
1021 // On iOS, pageScaleFactor() is not applied by RenderView, so we should not scale here.
1022 // FIXME: Set Settings::delegatesPageScaling to true for iOS.
1024 const Settings& settings = m_renderView.frameView().frame().settings();
1025 if (!settings.delegatesPageScaling())
1026 clipRect.scale(pageScaleFactor());
1028 clipRect.intersect(layerBounds);
1029 overlapMap.add(&layer, clipRect);
1032 void RenderLayerCompositor::addToOverlapMapRecursive(OverlapMap& overlapMap, RenderLayer& layer, RenderLayer* ancestorLayer)
1034 if (!canBeComposited(layer) || overlapMap.contains(&layer))
1037 // A null ancestorLayer is an indication that 'layer' has already been pushed.
1039 overlapMap.geometryMap().pushMappingsToAncestor(&layer, ancestorLayer);
1042 bool haveComputedBounds = false;
1043 addToOverlapMap(overlapMap, layer, bounds, haveComputedBounds);
1045 #if !ASSERT_DISABLED
1046 LayerListMutationDetector mutationChecker(&layer);
1049 if (layer.isStackingContainer()) {
1050 if (Vector<RenderLayer*>* negZOrderList = layer.negZOrderList()) {
1051 for (size_t i = 0, size = negZOrderList->size(); i < size; ++i)
1052 addToOverlapMapRecursive(overlapMap, *negZOrderList->at(i), &layer);
1056 if (Vector<RenderLayer*>* normalFlowList = layer.normalFlowList()) {
1057 for (size_t i = 0, size = normalFlowList->size(); i < size; ++i)
1058 addToOverlapMapRecursive(overlapMap, *normalFlowList->at(i), &layer);
1061 if (layer.isStackingContainer()) {
1062 if (Vector<RenderLayer*>* posZOrderList = layer.posZOrderList()) {
1063 for (size_t i = 0, size = posZOrderList->size(); i < size; ++i)
1064 addToOverlapMapRecursive(overlapMap, *posZOrderList->at(i), &layer);
1069 overlapMap.geometryMap().popMappingsToAncestor(ancestorLayer);
1072 void RenderLayerCompositor::computeCompositingRequirementsForNamedFlowFixed(RenderLayer& layer, OverlapMap* overlapMap, CompositingState& childState, bool& layersChanged, bool& anyDescendantHas3DTransform)
1074 if (!layer.isRootLayer())
1077 if (!layer.renderer().view().hasRenderNamedFlowThreads())
1080 Vector<RenderLayer*> fixedLayers;
1081 layer.renderer().view().flowThreadController().collectFixedPositionedLayers(fixedLayers);
1083 for (size_t i = 0; i < fixedLayers.size(); ++i) {
1084 RenderLayer* fixedLayer = fixedLayers.at(i);
1085 computeCompositingRequirements(&layer, *fixedLayer, overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
1089 // Recurse through the layers in z-index and overflow order (which is equivalent to painting order)
1090 // For the z-order children of a compositing layer:
1091 // If a child layers has a compositing layer, then all subsequent layers must
1092 // be compositing in order to render above that layer.
1094 // If a child in the negative z-order list is compositing, then the layer itself
1095 // must be compositing so that its contents render over that child.
1096 // This implies that its positive z-index children must also be compositing.
1098 void RenderLayerCompositor::computeCompositingRequirements(RenderLayer* ancestorLayer, RenderLayer& layer, OverlapMap* overlapMap, CompositingState& compositingState, bool& layersChanged, bool& descendantHas3DTransform)
1100 layer.updateDescendantDependentFlags();
1101 layer.updateLayerListsIfNeeded();
1103 if (layer.isFlowThreadCollectingGraphicsLayersUnderRegions()) {
1104 RenderFlowThread& flowThread = toRenderFlowThread(layer.renderer());
1105 layer.setHasCompositingDescendant(flowThread.hasCompositingRegionDescendant());
1107 // Before returning, we need to update the lists of all child layers. This is required because,
1108 // if this flow thread will not be painted (for instance because of having no regions, or only invalid regions),
1109 // the child layers will never have their lists updated (which would normally happen during painting).
1110 layer.updateDescendantsLayerListsIfNeeded(true);
1116 overlapMap->geometryMap().pushMappingsToAncestor(&layer, ancestorLayer);
1119 layer.setHasCompositingDescendant(false);
1120 layer.setIndirectCompositingReason(RenderLayer::NoIndirectCompositingReason);
1122 // Check if the layer needs to be composited for non-indirect reasons (ex. 3D transform).
1123 // We use this value to avoid checking the overlap-map, if we know for sure the layer
1124 // is already going to be composited for other reasons.
1125 bool willBeComposited = needsToBeComposited(layer);
1127 RenderLayer::IndirectCompositingReason compositingReason = compositingState.m_subtreeIsCompositing ? RenderLayer::IndirectCompositingForStacking : RenderLayer::NoIndirectCompositingReason;
1128 bool haveComputedBounds = false;
1131 // If we know for sure the layer is going to be composited, don't bother looking it up in the overlap map
1132 if (!willBeComposited && overlapMap && !overlapMap->isEmpty() && compositingState.m_testingOverlap) {
1133 // If we're testing for overlap, we only need to composite if we overlap something that is already composited.
1134 absBounds = enclosingIntRect(overlapMap->geometryMap().absoluteRect(layer.overlapBounds()));
1136 // Empty rects never intersect, but we need them to for the purposes of overlap testing.
1137 if (absBounds.isEmpty())
1138 absBounds.setSize(IntSize(1, 1));
1139 haveComputedBounds = true;
1140 compositingReason = overlapMap->overlapsLayers(absBounds) ? RenderLayer::IndirectCompositingForOverlap : RenderLayer::NoIndirectCompositingReason;
1144 // Video is special. It's the only RenderLayer type that can both have
1145 // RenderLayer children and whose children can't use its backing to render
1146 // into. These children (the controls) always need to be promoted into their
1147 // own layers to draw on top of the accelerated video.
1148 if (compositingState.m_compositingAncestor && compositingState.m_compositingAncestor->renderer().isVideo())
1149 compositingReason = RenderLayer::IndirectCompositingForOverlap;
1152 layer.setIndirectCompositingReason(compositingReason);
1154 // Check if the computed indirect reason will force the layer to become composited.
1155 if (!willBeComposited && layer.mustCompositeForIndirectReasons() && canBeComposited(layer))
1156 willBeComposited = true;
1157 ASSERT(willBeComposited == needsToBeComposited(layer));
1159 // The children of this layer don't need to composite, unless there is
1160 // a compositing layer among them, so start by inheriting the compositing
1161 // ancestor with m_subtreeIsCompositing set to false.
1162 CompositingState childState(compositingState);
1163 childState.m_subtreeIsCompositing = false;
1164 #if ENABLE(CSS_COMPOSITING)
1165 childState.m_hasUnisolatedCompositedBlendingDescendants = false;
1168 if (willBeComposited) {
1169 // Tell the parent it has compositing descendants.
1170 compositingState.m_subtreeIsCompositing = true;
1171 // This layer now acts as the ancestor for kids.
1172 childState.m_compositingAncestor = &layer;
1175 overlapMap->pushCompositingContainer();
1176 // This layer is going to be composited, so children can safely ignore the fact that there's an
1177 // animation running behind this layer, meaning they can rely on the overlap map testing again.
1178 childState.m_testingOverlap = true;
1181 #if !ASSERT_DISABLED
1182 LayerListMutationDetector mutationChecker(&layer);
1185 bool anyDescendantHas3DTransform = false;
1187 if (layer.isStackingContainer()) {
1188 if (Vector<RenderLayer*>* negZOrderList = layer.negZOrderList()) {
1189 for (size_t i = 0, size = negZOrderList->size(); i < size; ++i) {
1190 computeCompositingRequirements(&layer, *negZOrderList->at(i), overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
1192 // If we have to make a layer for this child, make one now so we can have a contents layer
1193 // (since we need to ensure that the -ve z-order child renders underneath our contents).
1194 if (!willBeComposited && childState.m_subtreeIsCompositing) {
1195 // make layer compositing
1196 layer.setIndirectCompositingReason(RenderLayer::IndirectCompositingForBackgroundLayer);
1197 childState.m_compositingAncestor = &layer;
1199 overlapMap->pushCompositingContainer();
1200 // This layer is going to be composited, so children can safely ignore the fact that there's an
1201 // animation running behind this layer, meaning they can rely on the overlap map testing again
1202 childState.m_testingOverlap = true;
1203 willBeComposited = true;
1209 if (layer.renderer().isRenderNamedFlowFragmentContainer()) {
1210 // We are going to collect layers from the RenderFlowThread into the GraphicsLayer of the parent of the
1211 // anonymous RenderRegion, but first we need to make sure that the parent itself of the region is going to
1212 // have a composited layer. We only want to make regions composited when there's an actual layer that we
1213 // need to move to that region.
1214 computeRegionCompositingRequirements(toRenderBlockFlow(layer.renderer()).renderNamedFlowFragment(), overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
1218 if (Vector<RenderLayer*>* normalFlowList = layer.normalFlowList()) {
1219 for (size_t i = 0, size = normalFlowList->size(); i < size; ++i)
1220 computeCompositingRequirements(&layer, *normalFlowList->at(i), overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
1223 if (layer.isStackingContainer()) {
1224 if (Vector<RenderLayer*>* posZOrderList = layer.posZOrderList()) {
1225 for (size_t i = 0, size = posZOrderList->size(); i < size; ++i)
1226 computeCompositingRequirements(&layer, *posZOrderList->at(i), overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
1230 if (layer.isRootLayer())
1231 computeCompositingRequirementsForNamedFlowFixed(layer, overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
1233 // If we just entered compositing mode, the root will have become composited (as long as accelerated compositing is enabled).
1234 if (layer.isRootLayer()) {
1235 if (inCompositingMode() && m_hasAcceleratedCompositing)
1236 willBeComposited = true;
1239 ASSERT(willBeComposited == needsToBeComposited(layer));
1241 // All layers (even ones that aren't being composited) need to get added to
1242 // the overlap map. Layers that do not composite will draw into their
1243 // compositing ancestor's backing, and so are still considered for overlap.
1244 if (overlapMap && childState.m_compositingAncestor && !childState.m_compositingAncestor->isRootLayer())
1245 addToOverlapMap(*overlapMap, layer, absBounds, haveComputedBounds);
1247 #if ENABLE(CSS_COMPOSITING)
1248 layer.setHasUnisolatedCompositedBlendingDescendants(childState.m_hasUnisolatedCompositedBlendingDescendants);
1249 ASSERT(!layer.hasUnisolatedCompositedBlendingDescendants() || layer.hasUnisolatedBlendingDescendants());
1251 // Now check for reasons to become composited that depend on the state of descendant layers.
1252 RenderLayer::IndirectCompositingReason indirectCompositingReason;
1253 if (!willBeComposited && canBeComposited(layer)
1254 && requiresCompositingForIndirectReason(layer.renderer(), childState.m_subtreeIsCompositing, anyDescendantHas3DTransform, indirectCompositingReason)) {
1255 layer.setIndirectCompositingReason(indirectCompositingReason);
1256 childState.m_compositingAncestor = &layer;
1258 overlapMap->pushCompositingContainer();
1259 addToOverlapMapRecursive(*overlapMap, layer);
1261 willBeComposited = true;
1264 ASSERT(willBeComposited == needsToBeComposited(layer));
1265 if (layer.reflectionLayer()) {
1266 // FIXME: Shouldn't we call computeCompositingRequirements to handle a reflection overlapping with another renderer?
1267 layer.reflectionLayer()->setIndirectCompositingReason(willBeComposited ? RenderLayer::IndirectCompositingForStacking : RenderLayer::NoIndirectCompositingReason);
1270 // Subsequent layers in the parent stacking context also need to composite.
1271 if (childState.m_subtreeIsCompositing)
1272 compositingState.m_subtreeIsCompositing = true;
1274 // Set the flag to say that this SC has compositing children.
1275 layer.setHasCompositingDescendant(childState.m_subtreeIsCompositing);
1277 // setHasCompositingDescendant() may have changed the answer to needsToBeComposited() when clipping,
1278 // so test that again.
1279 bool isCompositedClippingLayer = canBeComposited(layer) && clipsCompositingDescendants(layer);
1281 // Turn overlap testing off for later layers if it's already off, or if we have an animating transform.
1282 // Note that if the layer clips its descendants, there's no reason to propagate the child animation to the parent layers. That's because
1283 // we know for sure the animation is contained inside the clipping rectangle, which is already added to the overlap map.
1284 if ((!childState.m_testingOverlap && !isCompositedClippingLayer) || isRunningAcceleratedTransformAnimation(layer.renderer()))
1285 compositingState.m_testingOverlap = false;
1287 if (isCompositedClippingLayer) {
1288 if (!willBeComposited) {
1289 childState.m_compositingAncestor = &layer;
1291 overlapMap->pushCompositingContainer();
1292 addToOverlapMapRecursive(*overlapMap, layer);
1294 willBeComposited = true;
1298 #if ENABLE(CSS_COMPOSITING)
1299 if ((willBeComposited && layer.hasBlendMode())
1300 || (layer.hasUnisolatedCompositedBlendingDescendants() && !layer.isolatesCompositedBlending()))
1301 compositingState.m_hasUnisolatedCompositedBlendingDescendants = true;
1304 if (overlapMap && childState.m_compositingAncestor == &layer && !layer.isRootLayer())
1305 overlapMap->popCompositingContainer();
1307 // If we're back at the root, and no other layers need to be composited, and the root layer itself doesn't need
1308 // to be composited, then we can drop out of compositing mode altogether. However, don't drop out of compositing mode
1309 // if there are composited layers that we didn't hit in our traversal (e.g. because of visibility:hidden).
1310 if (layer.isRootLayer() && !childState.m_subtreeIsCompositing && !requiresCompositingLayer(layer) && !m_forceCompositingMode && !hasAnyAdditionalCompositedLayers(layer)) {
1311 // Don't drop out of compositing on iOS, because we may flash. See <rdar://problem/8348337>.
1313 enableCompositingMode(false);
1314 willBeComposited = false;
1318 // If the layer is going into compositing mode, repaint its old location.
1319 ASSERT(willBeComposited == needsToBeComposited(layer));
1320 if (!layer.isComposited() && willBeComposited)
1321 repaintOnCompositingChange(layer);
1323 // Update backing now, so that we can use isComposited() reliably during tree traversal in rebuildCompositingLayerTree().
1324 if (updateBacking(layer, CompositingChangeRepaintNow))
1325 layersChanged = true;
1327 if (layer.reflectionLayer() && updateLayerCompositingState(*layer.reflectionLayer(), CompositingChangeRepaintNow))
1328 layersChanged = true;
1330 descendantHas3DTransform |= anyDescendantHas3DTransform || layer.has3DTransform();
1333 overlapMap->geometryMap().popMappingsToAncestor(ancestorLayer);
1336 void RenderLayerCompositor::computeRegionCompositingRequirements(RenderNamedFlowFragment* region, OverlapMap* overlapMap, CompositingState& childState, bool& layersChanged, bool& anyDescendantHas3DTransform)
1338 if (!region->isValid())
1341 RenderFlowThread* flowThread = region->flowThread();
1344 overlapMap->geometryMap().pushRenderFlowThread(flowThread);
1346 if (const RenderLayerList* layerList = flowThread->getLayerListForRegion(region)) {
1347 for (size_t i = 0, listSize = layerList->size(); i < listSize; ++i) {
1348 RenderLayer& curLayer = *layerList->at(i);
1349 ASSERT(flowThread->regionForCompositedLayer(curLayer) == region);
1350 computeCompositingRequirements(flowThread->layer(), curLayer, overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
1355 overlapMap->geometryMap().popMappingsToAncestor(®ion->layerOwner());
1358 void RenderLayerCompositor::setCompositingParent(RenderLayer& childLayer, RenderLayer* parentLayer)
1360 ASSERT(!parentLayer || childLayer.ancestorCompositingLayer() == parentLayer);
1361 ASSERT(childLayer.isComposited());
1363 // It's possible to be called with a parent that isn't yet composited when we're doing
1364 // partial updates as required by painting or hit testing. Just bail in that case;
1365 // we'll do a full layer update soon.
1366 if (!parentLayer || !parentLayer->isComposited())
1370 GraphicsLayer* hostingLayer = parentLayer->backing()->parentForSublayers();
1371 GraphicsLayer* hostedLayer = childLayer.backing()->childForSuperlayers();
1373 hostingLayer->addChild(hostedLayer);
1375 childLayer.backing()->childForSuperlayers()->removeFromParent();
1378 void RenderLayerCompositor::removeCompositedChildren(RenderLayer& layer)
1380 ASSERT(layer.isComposited());
1382 layer.backing()->parentForSublayers()->removeAllChildren();
1386 bool RenderLayerCompositor::canAccelerateVideoRendering(RenderVideo& video) const
1388 if (!m_hasAcceleratedCompositing)
1391 return video.supportsAcceleratedRendering();
1395 void RenderLayerCompositor::rebuildCompositingLayerTreeForNamedFlowFixed(RenderLayer& layer, Vector<GraphicsLayer*>& childGraphicsLayersOfEnclosingLayer, int depth)
1397 if (!layer.isRootLayer())
1400 if (!layer.renderer().view().hasRenderNamedFlowThreads())
1403 Vector<RenderLayer*> fixedLayers;
1404 layer.renderer().view().flowThreadController().collectFixedPositionedLayers(fixedLayers);
1406 for (size_t i = 0; i < fixedLayers.size(); ++i) {
1407 RenderLayer* fixedLayer = fixedLayers.at(i);
1408 rebuildCompositingLayerTree(*fixedLayer, childGraphicsLayersOfEnclosingLayer, depth);
1412 void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer& layer, Vector<GraphicsLayer*>& childLayersOfEnclosingLayer, int depth)
1414 // Make the layer compositing if necessary, and set up clipping and content layers.
1415 // Note that we can only do work here that is independent of whether the descendant layers
1416 // have been processed. computeCompositingRequirements() will already have done the repaint if necessary.
1418 // Do not iterate the RenderFlowThread directly. We are going to collect composited layers as part of regions.
1419 if (layer.isFlowThreadCollectingGraphicsLayersUnderRegions())
1422 RenderLayerBacking* layerBacking = layer.backing();
1424 // The compositing state of all our children has been updated already, so now
1425 // we can compute and cache the composited bounds for this layer.
1426 layerBacking->updateCompositedBounds();
1428 if (RenderLayer* reflection = layer.reflectionLayer()) {
1429 if (reflection->backing())
1430 reflection->backing()->updateCompositedBounds();
1433 if (layerBacking->updateGraphicsLayerConfiguration())
1434 layerBacking->updateDebugIndicators(m_showDebugBorders, m_showRepaintCounter);
1436 layerBacking->updateGraphicsLayerGeometry();
1438 if (!layer.parent())
1439 updateRootLayerPosition();
1442 logLayerInfo(layer, depth);
1444 UNUSED_PARAM(depth);
1446 if (layerBacking->hasUnpositionedOverflowControlsLayers())
1447 layer.positionNewlyCreatedOverflowControls();
1450 // If this layer has backing, then we are collecting its children, otherwise appending
1451 // to the compositing child list of an enclosing layer.
1452 Vector<GraphicsLayer*> layerChildren;
1453 Vector<GraphicsLayer*>& childList = layerBacking ? layerChildren : childLayersOfEnclosingLayer;
1455 #if !ASSERT_DISABLED
1456 LayerListMutationDetector mutationChecker(&layer);
1459 if (layer.isStackingContainer()) {
1460 if (Vector<RenderLayer*>* negZOrderList = layer.negZOrderList()) {
1461 for (size_t i = 0, size = negZOrderList->size(); i < size; ++i)
1462 rebuildCompositingLayerTree(*negZOrderList->at(i), childList, depth + 1);
1465 // If a negative z-order child is compositing, we get a foreground layer which needs to get parented.
1466 if (layerBacking && layerBacking->foregroundLayer())
1467 childList.append(layerBacking->foregroundLayer());
1470 if (layer.renderer().isRenderNamedFlowFragmentContainer())
1471 rebuildRegionCompositingLayerTree(toRenderBlockFlow(layer.renderer()).renderNamedFlowFragment(), layerChildren, depth + 1);
1473 if (Vector<RenderLayer*>* normalFlowList = layer.normalFlowList()) {
1474 for (size_t i = 0, size = normalFlowList->size(); i < size; ++i)
1475 rebuildCompositingLayerTree(*normalFlowList->at(i), childList, depth + 1);
1478 if (layer.isStackingContainer()) {
1479 if (Vector<RenderLayer*>* posZOrderList = layer.posZOrderList()) {
1480 for (size_t i = 0, size = posZOrderList->size(); i < size; ++i)
1481 rebuildCompositingLayerTree(*posZOrderList->at(i), childList, depth + 1);
1485 if (layer.isRootLayer())
1486 rebuildCompositingLayerTreeForNamedFlowFixed(layer, childList, depth + 1);
1489 bool parented = false;
1490 if (layer.renderer().isWidget())
1491 parented = parentFrameContentLayers(toRenderWidget(&layer.renderer()));
1494 layerBacking->parentForSublayers()->setChildren(layerChildren);
1496 // If the layer has a clipping layer the overflow controls layers will be siblings of the clipping layer.
1497 // Otherwise, the overflow control layers are normal children.
1498 if (!layerBacking->hasClippingLayer() && !layerBacking->hasScrollingLayer()) {
1499 if (GraphicsLayer* overflowControlLayer = layerBacking->layerForHorizontalScrollbar()) {
1500 overflowControlLayer->removeFromParent();
1501 layerBacking->parentForSublayers()->addChild(overflowControlLayer);
1504 if (GraphicsLayer* overflowControlLayer = layerBacking->layerForVerticalScrollbar()) {
1505 overflowControlLayer->removeFromParent();
1506 layerBacking->parentForSublayers()->addChild(overflowControlLayer);
1509 if (GraphicsLayer* overflowControlLayer = layerBacking->layerForScrollCorner()) {
1510 overflowControlLayer->removeFromParent();
1511 layerBacking->parentForSublayers()->addChild(overflowControlLayer);
1515 childLayersOfEnclosingLayer.append(layerBacking->childForSuperlayers());
1519 void RenderLayerCompositor::rebuildRegionCompositingLayerTree(RenderNamedFlowFragment* region, Vector<GraphicsLayer*>& childList, int depth)
1521 if (!region->isValid())
1524 RenderFlowThread* flowThread = region->flowThread();
1525 ASSERT(flowThread->collectsGraphicsLayersUnderRegions());
1526 if (const RenderLayerList* layerList = flowThread->getLayerListForRegion(region)) {
1527 for (size_t i = 0, listSize = layerList->size(); i < listSize; ++i) {
1528 RenderLayer& curLayer = *layerList->at(i);
1529 ASSERT(flowThread->regionForCompositedLayer(curLayer) == region);
1530 rebuildCompositingLayerTree(curLayer, childList, depth + 1);
1535 void RenderLayerCompositor::frameViewDidChangeLocation(const IntPoint& contentsOffset)
1537 if (m_overflowControlsHostLayer)
1538 m_overflowControlsHostLayer->setPosition(contentsOffset);
1541 void RenderLayerCompositor::frameViewDidChangeSize()
1544 const FrameView& frameView = m_renderView.frameView();
1545 m_clipLayer->setSize(frameView.unscaledTotalVisibleContentSize());
1547 frameViewDidScroll();
1548 updateOverflowControlsLayers();
1550 #if ENABLE(RUBBER_BANDING)
1551 if (m_layerForOverhangAreas)
1552 m_layerForOverhangAreas->setSize(frameView.frameRect().size());
1557 bool RenderLayerCompositor::hasCoordinatedScrolling() const
1559 ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator();
1560 return scrollingCoordinator && scrollingCoordinator->coordinatesScrollingForFrameView(&m_renderView.frameView());
1563 void RenderLayerCompositor::updateScrollLayerPosition()
1565 ASSERT(m_scrollLayer);
1567 FrameView& frameView = m_renderView.frameView();
1568 IntPoint scrollPosition = frameView.scrollPosition();
1570 m_scrollLayer->setPosition(FloatPoint(-scrollPosition.x(), -scrollPosition.y()));
1572 if (GraphicsLayer* fixedBackgroundLayer = fixedRootBackgroundLayer())
1573 fixedBackgroundLayer->setPosition(toLayoutPoint(frameView.scrollOffsetForFixedPosition()));
1576 void RenderLayerCompositor::frameViewDidScroll()
1581 // If there's a scrolling coordinator that manages scrolling for this frame view,
1582 // it will also manage updating the scroll layer position.
1583 if (hasCoordinatedScrolling()) {
1584 // We have to schedule a flush in order for the main TiledBacking to update its tile coverage.
1585 scheduleLayerFlushNow();
1589 updateScrollLayerPosition();
1592 void RenderLayerCompositor::frameViewDidAddOrRemoveScrollbars()
1594 updateOverflowControlsLayers();
1597 void RenderLayerCompositor::frameViewDidLayout()
1599 RenderLayerBacking* renderViewBacking = m_renderView.layer()->backing();
1600 if (renderViewBacking)
1601 renderViewBacking->adjustTiledBackingCoverage();
1604 void RenderLayerCompositor::rootFixedBackgroundsChanged()
1606 RenderLayerBacking* renderViewBacking = m_renderView.layer()->backing();
1607 if (renderViewBacking && renderViewBacking->usingTiledBacking())
1608 setCompositingLayersNeedRebuild();
1611 void RenderLayerCompositor::scrollingLayerDidChange(RenderLayer& layer)
1613 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
1614 scrollingCoordinator->scrollableAreaScrollLayerDidChange(&layer);
1617 void RenderLayerCompositor::fixedRootBackgroundLayerChanged()
1619 if (m_renderView.documentBeingDestroyed())
1622 if (m_renderView.layer()->isComposited())
1623 updateScrollCoordinatedStatus(*m_renderView.layer());
1626 String RenderLayerCompositor::layerTreeAsText(LayerTreeFlags flags)
1628 updateCompositingLayers(CompositingUpdateAfterLayout);
1630 if (!m_rootContentLayer)
1633 flushPendingLayerChanges(true);
1635 LayerTreeAsTextBehavior layerTreeBehavior = LayerTreeAsTextBehaviorNormal;
1636 if (flags & LayerTreeFlagsIncludeDebugInfo)
1637 layerTreeBehavior |= LayerTreeAsTextDebug;
1638 if (flags & LayerTreeFlagsIncludeVisibleRects)
1639 layerTreeBehavior |= LayerTreeAsTextIncludeVisibleRects;
1640 if (flags & LayerTreeFlagsIncludeTileCaches)
1641 layerTreeBehavior |= LayerTreeAsTextIncludeTileCaches;
1642 if (flags & LayerTreeFlagsIncludeRepaintRects)
1643 layerTreeBehavior |= LayerTreeAsTextIncludeRepaintRects;
1644 if (flags & LayerTreeFlagsIncludePaintingPhases)
1645 layerTreeBehavior |= LayerTreeAsTextIncludePaintingPhases;
1646 if (flags & LayerTreeFlagsIncludeContentLayers)
1647 layerTreeBehavior |= LayerTreeAsTextIncludeContentLayers;
1649 // We skip dumping the scroll and clip layers to keep layerTreeAsText output
1650 // similar between platforms.
1651 String layerTreeText = m_rootContentLayer->layerTreeAsText(layerTreeBehavior);
1653 // Dump an empty layer tree only if the only composited layer is the main frame's tiled backing,
1654 // so that tests expecting us to drop out of accelerated compositing when there are no layers succeed.
1655 if (!hasAnyAdditionalCompositedLayers(rootRenderLayer()) && mainFrameBackingIsTiled() && !(layerTreeBehavior & LayerTreeAsTextIncludeTileCaches))
1658 // The true root layer is not included in the dump, so if we want to report
1659 // its repaint rects, they must be included here.
1660 if (flags & LayerTreeFlagsIncludeRepaintRects)
1661 return m_renderView.frameView().trackedRepaintRectsAsText() + layerTreeText;
1663 return layerTreeText;
1666 RenderLayerCompositor* RenderLayerCompositor::frameContentsCompositor(RenderWidget* renderer)
1668 if (Document* contentDocument = renderer->frameOwnerElement().contentDocument()) {
1669 if (RenderView* view = contentDocument->renderView())
1670 return &view->compositor();
1675 bool RenderLayerCompositor::parentFrameContentLayers(RenderWidget* renderer)
1677 RenderLayerCompositor* innerCompositor = frameContentsCompositor(renderer);
1678 if (!innerCompositor || !innerCompositor->inCompositingMode() || innerCompositor->rootLayerAttachment() != RootLayerAttachedViaEnclosingFrame)
1681 RenderLayer* layer = renderer->layer();
1682 if (!layer->isComposited())
1685 RenderLayerBacking* backing = layer->backing();
1686 GraphicsLayer* hostingLayer = backing->parentForSublayers();
1687 GraphicsLayer* rootLayer = innerCompositor->rootGraphicsLayer();
1688 if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != rootLayer) {
1689 hostingLayer->removeAllChildren();
1690 hostingLayer->addChild(rootLayer);
1695 // This just updates layer geometry without changing the hierarchy.
1696 void RenderLayerCompositor::updateLayerTreeGeometry(RenderLayer& layer, int depth)
1698 if (RenderLayerBacking* layerBacking = layer.backing()) {
1699 // The compositing state of all our children has been updated already, so now
1700 // we can compute and cache the composited bounds for this layer.
1701 layerBacking->updateCompositedBounds();
1703 if (RenderLayer* reflection = layer.reflectionLayer()) {
1704 if (reflection->backing())
1705 reflection->backing()->updateCompositedBounds();
1708 layerBacking->updateGraphicsLayerConfiguration();
1709 layerBacking->updateGraphicsLayerGeometry();
1711 if (!layer.parent())
1712 updateRootLayerPosition();
1715 logLayerInfo(layer, depth);
1717 UNUSED_PARAM(depth);
1721 #if !ASSERT_DISABLED
1722 LayerListMutationDetector mutationChecker(&layer);
1725 if (layer.isStackingContainer()) {
1726 if (Vector<RenderLayer*>* negZOrderList = layer.negZOrderList()) {
1727 for (size_t i = 0, size = negZOrderList->size(); i < size; ++i)
1728 updateLayerTreeGeometry(*negZOrderList->at(i), depth + 1);
1732 if (Vector<RenderLayer*>* normalFlowList = layer.normalFlowList()) {
1733 for (size_t i = 0, size = normalFlowList->size(); i < size; ++i)
1734 updateLayerTreeGeometry(*normalFlowList->at(i), depth + 1);
1737 if (layer.isStackingContainer()) {
1738 if (Vector<RenderLayer*>* posZOrderList = layer.posZOrderList()) {
1739 for (size_t i = 0, size = posZOrderList->size(); i < size; ++i)
1740 updateLayerTreeGeometry(*posZOrderList->at(i), depth + 1);
1745 // Recurs down the RenderLayer tree until its finds the compositing descendants of compositingAncestor and updates their geometry.
1746 void RenderLayerCompositor::updateCompositingDescendantGeometry(RenderLayer& compositingAncestor, RenderLayer& layer, bool compositedChildrenOnly)
1748 if (&layer != &compositingAncestor) {
1749 if (RenderLayerBacking* layerBacking = layer.backing()) {
1750 layerBacking->updateCompositedBounds();
1752 if (RenderLayer* reflection = layer.reflectionLayer()) {
1753 if (reflection->backing())
1754 reflection->backing()->updateCompositedBounds();
1757 layerBacking->updateGraphicsLayerGeometry();
1758 if (compositedChildrenOnly)
1763 if (layer.reflectionLayer())
1764 updateCompositingDescendantGeometry(compositingAncestor, *layer.reflectionLayer(), compositedChildrenOnly);
1766 if (!layer.hasCompositingDescendant())
1769 #if !ASSERT_DISABLED
1770 LayerListMutationDetector mutationChecker(&layer);
1773 if (layer.isStackingContainer()) {
1774 if (Vector<RenderLayer*>* negZOrderList = layer.negZOrderList()) {
1775 size_t listSize = negZOrderList->size();
1776 for (size_t i = 0; i < listSize; ++i)
1777 updateCompositingDescendantGeometry(compositingAncestor, *negZOrderList->at(i), compositedChildrenOnly);
1781 if (Vector<RenderLayer*>* normalFlowList = layer.normalFlowList()) {
1782 size_t listSize = normalFlowList->size();
1783 for (size_t i = 0; i < listSize; ++i)
1784 updateCompositingDescendantGeometry(compositingAncestor, *normalFlowList->at(i), compositedChildrenOnly);
1787 if (layer.isStackingContainer()) {
1788 if (Vector<RenderLayer*>* posZOrderList = layer.posZOrderList()) {
1789 size_t listSize = posZOrderList->size();
1790 for (size_t i = 0; i < listSize; ++i)
1791 updateCompositingDescendantGeometry(compositingAncestor, *posZOrderList->at(i), compositedChildrenOnly);
1797 void RenderLayerCompositor::repaintCompositedLayers(const IntRect* absRect)
1799 recursiveRepaintLayer(rootRenderLayer(), absRect);
1802 void RenderLayerCompositor::recursiveRepaintLayer(RenderLayer& layer, const IntRect* rect)
1804 // FIXME: This method does not work correctly with transforms.
1805 if (layer.isComposited() && !layer.backing()->paintsIntoCompositedAncestor()) {
1807 layer.setBackingNeedsRepaintInRect(*rect);
1809 layer.setBackingNeedsRepaint();
1812 #if !ASSERT_DISABLED
1813 LayerListMutationDetector mutationChecker(&layer);
1816 if (layer.hasCompositingDescendant()) {
1817 if (Vector<RenderLayer*>* negZOrderList = layer.negZOrderList()) {
1818 for (size_t i = 0, size = negZOrderList->size(); i < size; ++i) {
1819 RenderLayer& childLayer = *negZOrderList->at(i);
1821 IntRect childRect(*rect);
1822 childLayer.convertToPixelSnappedLayerCoords(&layer, childRect);
1823 recursiveRepaintLayer(childLayer, &childRect);
1825 recursiveRepaintLayer(childLayer);
1829 if (Vector<RenderLayer*>* posZOrderList = layer.posZOrderList()) {
1830 for (size_t i = 0, size = posZOrderList->size(); i < size; ++i) {
1831 RenderLayer& childLayer = *posZOrderList->at(i);
1833 IntRect childRect(*rect);
1834 childLayer.convertToPixelSnappedLayerCoords(&layer, childRect);
1835 recursiveRepaintLayer(childLayer, &childRect);
1837 recursiveRepaintLayer(childLayer);
1841 if (Vector<RenderLayer*>* normalFlowList = layer.normalFlowList()) {
1842 for (size_t i = 0, size = normalFlowList->size(); i < size; ++i) {
1843 RenderLayer& childLayer = *normalFlowList->at(i);
1845 IntRect childRect(*rect);
1846 childLayer.convertToPixelSnappedLayerCoords(&layer, childRect);
1847 recursiveRepaintLayer(childLayer, &childRect);
1849 recursiveRepaintLayer(childLayer);
1854 RenderLayer& RenderLayerCompositor::rootRenderLayer() const
1856 return *m_renderView.layer();
1859 GraphicsLayer* RenderLayerCompositor::rootGraphicsLayer() const
1861 if (m_overflowControlsHostLayer)
1862 return m_overflowControlsHostLayer.get();
1863 return m_rootContentLayer.get();
1866 GraphicsLayer* RenderLayerCompositor::scrollLayer() const
1868 return m_scrollLayer.get();
1871 #if ENABLE(RUBBER_BANDING)
1872 GraphicsLayer* RenderLayerCompositor::headerLayer() const
1874 return m_layerForHeader.get();
1877 GraphicsLayer* RenderLayerCompositor::footerLayer() const
1879 return m_layerForFooter.get();
1883 TiledBacking* RenderLayerCompositor::pageTiledBacking() const
1885 RenderLayerBacking* renderViewBacking = m_renderView.layer()->backing();
1886 return renderViewBacking ? renderViewBacking->tiledBacking() : nullptr;
1889 void RenderLayerCompositor::setIsInWindow(bool isInWindow)
1891 if (TiledBacking* tiledBacking = pageTiledBacking())
1892 tiledBacking->setIsInWindow(isInWindow);
1894 if (!inCompositingMode())
1898 if (m_rootLayerAttachment != RootLayerUnattached)
1901 RootLayerAttachment attachment = shouldPropagateCompositingToEnclosingFrame() ? RootLayerAttachedViaEnclosingFrame : RootLayerAttachedViaChromeClient;
1902 attachRootLayer(attachment);
1904 registerAllViewportConstrainedLayers();
1905 registerAllScrollingLayers();
1908 if (m_rootLayerAttachment == RootLayerUnattached)
1913 unregisterAllViewportConstrainedLayers();
1914 unregisterAllScrollingLayers();
1919 void RenderLayerCompositor::clearBackingForLayerIncludingDescendants(RenderLayer& layer)
1921 if (layer.isComposited()) {
1922 removeFromScrollCoordinatedLayers(layer);
1923 layer.clearBacking();
1926 for (RenderLayer* childLayer = layer.firstChild(); childLayer; childLayer = childLayer->nextSibling())
1927 clearBackingForLayerIncludingDescendants(*childLayer);
1930 void RenderLayerCompositor::clearBackingForAllLayers()
1932 clearBackingForLayerIncludingDescendants(*m_renderView.layer());
1935 void RenderLayerCompositor::updateRootLayerPosition()
1937 if (m_rootContentLayer) {
1938 const IntRect& documentRect = m_renderView.documentRect();
1939 m_rootContentLayer->setSize(documentRect.size());
1940 m_rootContentLayer->setPosition(FloatPoint(documentRect.x(), documentRect.y() + m_renderView.frameView().headerHeight()
1941 + m_renderView.frameView().topContentInset()));
1944 m_clipLayer->setSize(m_renderView.frameView().unscaledTotalVisibleContentSize());
1946 #if ENABLE(RUBBER_BANDING)
1947 if (m_contentShadowLayer) {
1948 m_contentShadowLayer->setPosition(m_rootContentLayer->position());
1949 m_contentShadowLayer->setSize(m_rootContentLayer->size());
1952 updateLayerForTopOverhangArea(m_layerForTopOverhangArea != nullptr);
1953 updateLayerForBottomOverhangArea(m_layerForBottomOverhangArea != nullptr);
1954 updateLayerForHeader(m_layerForHeader != nullptr);
1955 updateLayerForFooter(m_layerForFooter != nullptr);
1959 bool RenderLayerCompositor::has3DContent() const
1961 return layerHas3DContent(rootRenderLayer());
1964 bool RenderLayerCompositor::allowsIndependentlyCompositedFrames(const FrameView* view)
1967 // frames are only independently composited in Mac pre-WebKit2.
1968 return view->platformWidget();
1975 bool RenderLayerCompositor::shouldPropagateCompositingToEnclosingFrame() const
1977 // Parent document content needs to be able to render on top of a composited frame, so correct behavior
1978 // is to have the parent document become composited too. However, this can cause problems on platforms that
1979 // use native views for frames (like Mac), so disable that behavior on those platforms for now.
1980 HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement();
1981 RenderElement* renderer = ownerElement ? ownerElement->renderer() : 0;
1983 // If we are the top-level frame, don't propagate.
1987 if (!allowsIndependentlyCompositedFrames(&m_renderView.frameView()))
1990 if (!renderer || !renderer->isWidget())
1993 // On Mac, only propagate compositing if the frame is overlapped in the parent
1994 // document, or the parent is already compositing, or the main frame is scaled.
1995 Page* page = this->page();
1996 if (page && page->pageScaleFactor() != 1)
1999 RenderWidget* frameRenderer = toRenderWidget(renderer);
2000 if (frameRenderer->widget()) {
2001 ASSERT(frameRenderer->widget()->isFrameView());
2002 FrameView* view = toFrameView(frameRenderer->widget());
2003 if (view->isOverlappedIncludingAncestors() || view->hasCompositingAncestor())
2010 bool RenderLayerCompositor::needsToBeComposited(const RenderLayer& layer, RenderLayer::ViewportConstrainedNotCompositedReason* viewportConstrainedNotCompositedReason) const
2012 if (!canBeComposited(layer))
2015 return requiresCompositingLayer(layer, viewportConstrainedNotCompositedReason) || layer.mustCompositeForIndirectReasons() || (inCompositingMode() && layer.isRootLayer());
2018 // Note: this specifies whether the RL needs a compositing layer for intrinsic reasons.
2019 // Use needsToBeComposited() to determine if a RL actually needs a compositing layer.
2021 bool RenderLayerCompositor::requiresCompositingLayer(const RenderLayer& layer, RenderLayer::ViewportConstrainedNotCompositedReason* viewportConstrainedNotCompositedReason) const
2023 auto renderer = &layer.renderer();
2025 // The compositing state of a reflection should match that of its reflected layer.
2026 if (layer.isReflection())
2027 renderer = toRenderLayerModelObject(renderer->parent()); // The RenderReplica's parent is the object being reflected.
2029 // The root layer always has a compositing layer, but it may not have backing.
2030 return requiresCompositingForTransform(*renderer)
2031 || requiresCompositingForVideo(*renderer)
2032 || requiresCompositingForCanvas(*renderer)
2033 || requiresCompositingForPlugin(*renderer)
2034 || requiresCompositingForFrame(*renderer)
2035 || requiresCompositingForBackfaceVisibility(*renderer)
2036 || clipsCompositingDescendants(*renderer->layer())
2037 || requiresCompositingForAnimation(*renderer)
2038 || requiresCompositingForFilters(*renderer)
2039 || requiresCompositingForPosition(*renderer, *renderer->layer(), viewportConstrainedNotCompositedReason)
2041 || requiresCompositingForScrolling(*renderer->layer())
2043 || requiresCompositingForOverflowScrolling(*renderer->layer());
2046 bool RenderLayerCompositor::canBeComposited(const RenderLayer& layer) const
2048 if (m_hasAcceleratedCompositing && layer.isSelfPaintingLayer()) {
2049 if (!layer.isInsideFlowThread())
2052 // CSS Regions flow threads do not need to be composited as we use composited RenderRegions
2053 // to render the background of the RenderFlowThread.
2054 if (layer.isRenderFlowThread())
2062 bool RenderLayerCompositor::requiresOwnBackingStore(const RenderLayer& layer, const RenderLayer* compositingAncestorLayer, const LayoutRect& layerCompositedBoundsInAncestor, const LayoutRect& ancestorCompositedBounds) const
2064 auto& renderer = layer.renderer();
2066 if (compositingAncestorLayer
2067 && !(compositingAncestorLayer->backing()->graphicsLayer()->drawsContent()
2068 || compositingAncestorLayer->backing()->paintsIntoWindow()
2069 || compositingAncestorLayer->backing()->paintsIntoCompositedAncestor()))
2072 if (layer.isRootLayer()
2073 || layer.transform() // note: excludes perspective and transformStyle3D.
2074 || requiresCompositingForVideo(renderer)
2075 || requiresCompositingForCanvas(renderer)
2076 || requiresCompositingForPlugin(renderer)
2077 || requiresCompositingForFrame(renderer)
2078 || requiresCompositingForBackfaceVisibility(renderer)
2079 || requiresCompositingForAnimation(renderer)
2080 || requiresCompositingForFilters(renderer)
2081 || requiresCompositingForPosition(renderer, layer)
2082 || requiresCompositingForOverflowScrolling(layer)
2083 || renderer.isTransparent()
2084 || renderer.hasMask()
2085 || renderer.hasReflection()
2086 || renderer.hasFilter()
2088 || requiresCompositingForScrolling(layer)
2094 if (layer.mustCompositeForIndirectReasons()) {
2095 RenderLayer::IndirectCompositingReason reason = layer.indirectCompositingReason();
2096 return reason == RenderLayer::IndirectCompositingForOverlap
2097 || reason == RenderLayer::IndirectCompositingForStacking
2098 || reason == RenderLayer::IndirectCompositingForBackgroundLayer
2099 || reason == RenderLayer::IndirectCompositingForGraphicalEffect
2100 || reason == RenderLayer::IndirectCompositingForPreserve3D; // preserve-3d has to create backing store to ensure that 3d-transformed elements intersect.
2103 if (!ancestorCompositedBounds.contains(layerCompositedBoundsInAncestor))
2109 CompositingReasons RenderLayerCompositor::reasonsForCompositing(const RenderLayer& layer) const
2111 CompositingReasons reasons = CompositingReasonNone;
2113 if (!layer.isComposited())
2116 auto renderer = &layer.renderer();
2117 if (layer.isReflection())
2118 renderer = toRenderLayerModelObject(renderer->parent());
2120 if (requiresCompositingForTransform(*renderer))
2121 reasons |= CompositingReason3DTransform;
2123 if (requiresCompositingForVideo(*renderer))
2124 reasons |= CompositingReasonVideo;
2125 else if (requiresCompositingForCanvas(*renderer))
2126 reasons |= CompositingReasonCanvas;
2127 else if (requiresCompositingForPlugin(*renderer))
2128 reasons |= CompositingReasonPlugin;
2129 else if (requiresCompositingForFrame(*renderer))
2130 reasons |= CompositingReasonIFrame;
2132 if ((canRender3DTransforms() && renderer->style().backfaceVisibility() == BackfaceVisibilityHidden))
2133 reasons |= CompositingReasonBackfaceVisibilityHidden;
2135 if (clipsCompositingDescendants(*renderer->layer()))
2136 reasons |= CompositingReasonClipsCompositingDescendants;
2138 if (requiresCompositingForAnimation(*renderer))
2139 reasons |= CompositingReasonAnimation;
2141 if (requiresCompositingForFilters(*renderer))
2142 reasons |= CompositingReasonFilters;
2144 if (requiresCompositingForPosition(*renderer, *renderer->layer()))
2145 reasons |= renderer->style().position() == FixedPosition ? CompositingReasonPositionFixed : CompositingReasonPositionSticky;
2148 if (requiresCompositingForScrolling(*renderer->layer()))
2149 reasons |= CompositingReasonOverflowScrollingTouch;
2152 if (requiresCompositingForOverflowScrolling(*renderer->layer()))
2153 reasons |= CompositingReasonOverflowScrollingTouch;
2155 if (renderer->layer()->indirectCompositingReason() == RenderLayer::IndirectCompositingForStacking)
2156 reasons |= CompositingReasonStacking;
2157 else if (renderer->layer()->indirectCompositingReason() == RenderLayer::IndirectCompositingForOverlap)
2158 reasons |= CompositingReasonOverlap;
2159 else if (renderer->layer()->indirectCompositingReason() == RenderLayer::IndirectCompositingForBackgroundLayer)
2160 reasons |= CompositingReasonNegativeZIndexChildren;
2161 else if (renderer->layer()->indirectCompositingReason() == RenderLayer::IndirectCompositingForGraphicalEffect) {
2162 if (renderer->layer()->transform())
2163 reasons |= CompositingReasonTransformWithCompositedDescendants;
2165 if (renderer->isTransparent())
2166 reasons |= CompositingReasonOpacityWithCompositedDescendants;
2168 if (renderer->hasMask())
2169 reasons |= CompositingReasonMaskWithCompositedDescendants;
2171 if (renderer->hasReflection())
2172 reasons |= CompositingReasonReflectionWithCompositedDescendants;
2174 if (renderer->hasFilter())
2175 reasons |= CompositingReasonFilterWithCompositedDescendants;
2177 #if ENABLE(CSS_COMPOSITING)
2178 if (layer.isolatesCompositedBlending())
2179 reasons |= CompositingReasonIsolatesCompositedBlendingDescendants;
2181 if (layer.hasBlendMode())
2182 reasons |= CompositingReasonBlendingWithCompositedDescendants;
2185 } else if (renderer->layer()->indirectCompositingReason() == RenderLayer::IndirectCompositingForPerspective)
2186 reasons |= CompositingReasonPerspective;
2187 else if (renderer->layer()->indirectCompositingReason() == RenderLayer::IndirectCompositingForPreserve3D)
2188 reasons |= CompositingReasonPreserve3D;
2190 if (inCompositingMode() && renderer->layer()->isRootLayer())
2191 reasons |= CompositingReasonRoot;
2197 const char* RenderLayerCompositor::logReasonsForCompositing(const RenderLayer& layer)
2199 CompositingReasons reasons = reasonsForCompositing(layer);
2201 if (reasons & CompositingReason3DTransform)
2202 return "3D transform";
2204 if (reasons & CompositingReasonVideo)
2206 else if (reasons & CompositingReasonCanvas)
2208 else if (reasons & CompositingReasonPlugin)
2210 else if (reasons & CompositingReasonIFrame)
2213 if (reasons & CompositingReasonBackfaceVisibilityHidden)
2214 return "backface-visibility: hidden";
2216 if (reasons & CompositingReasonClipsCompositingDescendants)
2217 return "clips compositing descendants";
2219 if (reasons & CompositingReasonAnimation)
2222 if (reasons & CompositingReasonFilters)
2225 if (reasons & CompositingReasonPositionFixed)
2226 return "position: fixed";
2228 if (reasons & CompositingReasonPositionSticky)
2229 return "position: sticky";
2231 if (reasons & CompositingReasonOverflowScrollingTouch)
2232 return "-webkit-overflow-scrolling: touch";
2234 if (reasons & CompositingReasonStacking)
2237 if (reasons & CompositingReasonOverlap)
2240 if (reasons & CompositingReasonNegativeZIndexChildren)
2241 return "negative z-index children";
2243 if (reasons & CompositingReasonTransformWithCompositedDescendants)
2244 return "transform with composited descendants";
2246 if (reasons & CompositingReasonOpacityWithCompositedDescendants)
2247 return "opacity with composited descendants";
2249 if (reasons & CompositingReasonMaskWithCompositedDescendants)
2250 return "mask with composited descendants";
2252 if (reasons & CompositingReasonReflectionWithCompositedDescendants)
2253 return "reflection with composited descendants";
2255 if (reasons & CompositingReasonFilterWithCompositedDescendants)
2256 return "filter with composited descendants";
2258 #if ENABLE(CSS_COMPOSITING)
2259 if (reasons & CompositingReasonBlendingWithCompositedDescendants)
2260 return "blending with composited descendants";
2262 if (reasons & CompositingReasonIsolatesCompositedBlendingDescendants)
2263 return "isolates composited blending descendants";
2266 if (reasons & CompositingReasonPerspective)
2267 return "perspective";
2269 if (reasons & CompositingReasonPreserve3D)
2270 return "preserve-3d";
2272 if (reasons & CompositingReasonRoot)
2279 // Return true if the given layer has some ancestor in the RenderLayer hierarchy that clips,
2280 // up to the enclosing compositing ancestor. This is required because compositing layers are parented
2281 // according to the z-order hierarchy, yet clipping goes down the renderer hierarchy.
2282 // Thus, a RenderLayer can be clipped by a RenderLayer that is an ancestor in the renderer hierarchy,
2283 // but a sibling in the z-order hierarchy.
2284 bool RenderLayerCompositor::clippedByAncestor(RenderLayer& layer) const
2286 if (!layer.isComposited() || !layer.parent())
2289 RenderLayer* compositingAncestor = layer.ancestorCompositingLayer();
2290 if (!compositingAncestor)
2293 // If the compositingAncestor clips, that will be taken care of by clipsCompositingDescendants(),
2294 // so we only care about clipping between its first child that is our ancestor (the computeClipRoot),
2296 RenderLayer* computeClipRoot = nullptr;
2297 RenderLayer* parent = &layer;
2299 RenderLayer* next = parent->parent();
2300 if (next == compositingAncestor) {
2301 computeClipRoot = parent;
2307 if (!computeClipRoot || computeClipRoot == &layer)
2310 return layer.backgroundClipRect(RenderLayer::ClipRectsContext(computeClipRoot, 0, TemporaryClipRects)).rect() != LayoutRect::infiniteRect(); // FIXME: Incorrect for CSS regions.
2313 // Return true if the given layer is a stacking context and has compositing child
2314 // layers that it needs to clip. In this case we insert a clipping GraphicsLayer
2315 // into the hierarchy between this layer and its children in the z-order hierarchy.
2316 bool RenderLayerCompositor::clipsCompositingDescendants(const RenderLayer& layer) const
2318 return layer.hasCompositingDescendant() && layer.renderer().hasClipOrOverflowClip();
2321 bool RenderLayerCompositor::requiresCompositingForScrollableFrame() const
2323 // Need this done first to determine overflow.
2324 ASSERT(!m_renderView.needsLayout());
2325 HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement();
2329 if (!(m_compositingTriggers & ChromeClient::ScrollableInnerFrameTrigger))
2332 return m_renderView.frameView().isScrollable();
2335 bool RenderLayerCompositor::requiresCompositingForTransform(RenderLayerModelObject& renderer) const
2337 if (!(m_compositingTriggers & ChromeClient::ThreeDTransformTrigger))
2340 // Note that we ask the renderer if it has a transform, because the style may have transforms,
2341 // but the renderer may be an inline that doesn't suppport them.
2342 return renderer.hasTransform() && renderer.style().transform().has3DOperation();
2345 bool RenderLayerCompositor::requiresCompositingForBackfaceVisibility(RenderLayerModelObject& renderer) const
2347 if (!(m_compositingTriggers & ChromeClient::ThreeDTransformTrigger))
2350 return renderer.style().backfaceVisibility() == BackfaceVisibilityHidden && renderer.layer()->has3DTransformedAncestor();
2353 bool RenderLayerCompositor::requiresCompositingForVideo(RenderLayerModelObject& renderer) const
2355 if (!(m_compositingTriggers & ChromeClient::VideoTrigger))
2358 if (renderer.isVideo()) {
2359 RenderVideo& video = toRenderVideo(renderer);
2360 return (video.requiresImmediateCompositing() || video.shouldDisplayVideo()) && canAccelerateVideoRendering(video);
2363 UNUSED_PARAM(renderer);
2368 bool RenderLayerCompositor::requiresCompositingForCanvas(RenderLayerModelObject& renderer) const
2370 if (!(m_compositingTriggers & ChromeClient::CanvasTrigger))
2373 if (renderer.isCanvas()) {
2374 #if USE(COMPOSITING_FOR_SMALL_CANVASES)
2375 bool isCanvasLargeEnoughToForceCompositing = true;
2377 HTMLCanvasElement* canvas = toHTMLCanvasElement(renderer.element());
2378 bool isCanvasLargeEnoughToForceCompositing = canvas->size().area() >= canvasAreaThresholdRequiringCompositing;
2380 CanvasCompositingStrategy compositingStrategy = canvasCompositingStrategy(renderer);
2381 return compositingStrategy == CanvasAsLayerContents || (compositingStrategy == CanvasPaintedToLayer && isCanvasLargeEnoughToForceCompositing);
2387 bool RenderLayerCompositor::requiresCompositingForPlugin(RenderLayerModelObject& renderer) const
2389 if (!(m_compositingTriggers & ChromeClient::PluginTrigger))
2392 bool composite = renderer.isEmbeddedObject() && toRenderEmbeddedObject(&renderer)->allowsAcceleratedCompositing();
2396 m_reevaluateCompositingAfterLayout = true;
2398 RenderWidget& pluginRenderer = *toRenderWidget(&renderer);
2399 // If we can't reliably know the size of the plugin yet, don't change compositing state.
2400 if (pluginRenderer.needsLayout())
2401 return pluginRenderer.hasLayer() && pluginRenderer.layer()->isComposited();
2403 // Don't go into compositing mode if height or width are zero, or size is 1x1.
2404 IntRect contentBox = pixelSnappedIntRect(pluginRenderer.contentBoxRect());
2405 return contentBox.height() * contentBox.width() > 1;
2408 bool RenderLayerCompositor::requiresCompositingForFrame(RenderLayerModelObject& renderer) const
2410 if (!renderer.isWidget())
2413 RenderWidget& frameRenderer = *toRenderWidget(&renderer);
2415 if (!frameRenderer.requiresAcceleratedCompositing())
2418 m_reevaluateCompositingAfterLayout = true;
2420 RenderLayerCompositor* innerCompositor = frameContentsCompositor(&frameRenderer);
2421 if (!innerCompositor || !innerCompositor->shouldPropagateCompositingToEnclosingFrame())
2424 // If we can't reliably know the size of the iframe yet, don't change compositing state.
2425 if (!frameRenderer.parent() || frameRenderer.needsLayout())
2426 return frameRenderer.hasLayer() && frameRenderer.layer()->isComposited();
2428 // Don't go into compositing mode if height or width are zero.
2429 return !pixelSnappedIntRect(frameRenderer.contentBoxRect()).isEmpty();
2432 bool RenderLayerCompositor::requiresCompositingForAnimation(RenderLayerModelObject& renderer) const
2434 if (!(m_compositingTriggers & ChromeClient::AnimationTrigger))
2437 const AnimationBase::RunningState activeAnimationState = AnimationBase::Running | AnimationBase::Paused | AnimationBase::FillingFowards;
2438 AnimationController& animController = renderer.animation();
2439 return (animController.isRunningAnimationOnRenderer(&renderer, CSSPropertyOpacity, activeAnimationState)
2440 && (inCompositingMode() || (m_compositingTriggers & ChromeClient::AnimatedOpacityTrigger)))
2441 #if ENABLE(CSS_FILTERS)
2442 || animController.isRunningAnimationOnRenderer(&renderer, CSSPropertyWebkitFilter, activeAnimationState)
2443 #endif // CSS_FILTERS
2444 || animController.isRunningAnimationOnRenderer(&renderer, CSSPropertyWebkitTransform, activeAnimationState);
2447 bool RenderLayerCompositor::requiresCompositingForIndirectReason(RenderLayerModelObject& renderer, bool hasCompositedDescendants, bool has3DTransformedDescendants, RenderLayer::IndirectCompositingReason& reason) const
2449 RenderLayer& layer = *toRenderBoxModelObject(renderer).layer();
2451 // When a layer has composited descendants, some effects, like 2d transforms, filters, masks etc must be implemented
2452 // via compositing so that they also apply to those composited descendants.
2453 if (hasCompositedDescendants && (layer.isolatesCompositedBlending() || layer.transform() || renderer.createsGroup() || renderer.hasReflection() || renderer.isRenderNamedFlowFragmentContainer())) {
2454 reason = RenderLayer::IndirectCompositingForGraphicalEffect;
2458 // A layer with preserve-3d or perspective only needs to be composited if there are descendant layers that
2459 // will be affected by the preserve-3d or perspective.
2460 if (has3DTransformedDescendants) {
2461 if (renderer.style().transformStyle3D() == TransformStyle3DPreserve3D) {
2462 reason = RenderLayer::IndirectCompositingForPreserve3D;
2466 if (renderer.style().hasPerspective()) {
2467 reason = RenderLayer::IndirectCompositingForPerspective;
2472 reason = RenderLayer::NoIndirectCompositingReason;
2477 bool RenderLayerCompositor::requiresCompositingForScrolling(const RenderLayer& layer) const
2479 if (!layer.hasAcceleratedTouchScrolling())
2482 if (!m_inPostLayoutUpdate) {
2483 m_reevaluateCompositingAfterLayout = true;
2484 return layer.isComposited();
2487 return layer.hasTouchScrollableOverflow();
2491 bool RenderLayerCompositor::requiresCompositingForFilters(RenderLayerModelObject& renderer) const
2493 #if ENABLE(CSS_FILTERS)
2494 if (!(m_compositingTriggers & ChromeClient::FilterTrigger))
2497 return renderer.hasFilter();
2499 UNUSED_PARAM(renderer);
2505 static bool isStickyInAcceleratedScrollingLayerOrViewport(const RenderLayer& layer, const RenderLayer** enclosingAcceleratedOverflowLayer = 0)
2507 ASSERT(layer.renderer().isStickyPositioned());
2509 RenderLayer* enclosingOverflowLayer = layer.enclosingOverflowClipLayer(ExcludeSelf);
2510 if (enclosingOverflowLayer && enclosingOverflowLayer->hasTouchScrollableOverflow()) {
2511 if (enclosingAcceleratedOverflowLayer)
2512 *enclosingAcceleratedOverflowLayer = enclosingOverflowLayer;
2516 return !enclosingOverflowLayer;
2520 static bool isViewportConstrainedFixedOrStickyLayer(const RenderLayer& layer)
2523 if (layer.renderer().isStickyPositioned())
2524 return isStickyInAcceleratedScrollingLayerOrViewport(layer);
2526 if (layer.renderer().isStickyPositioned())
2527 return !layer.enclosingOverflowClipLayer(ExcludeSelf);
2530 if (layer.renderer().style().position() != FixedPosition)
2533 // FIXME: Handle fixed inside of a transform, which should not behave as fixed.
2534 for (RenderLayer* stackingContainer = layer.stackingContainer(); stackingContainer; stackingContainer = stackingContainer->stackingContainer()) {
2535 if (stackingContainer->isComposited() && stackingContainer->renderer().style().position() == FixedPosition)
2542 static bool isMainFrameScrollingOrOverflowScrolling(RenderView& view, const RenderLayer& layer)
2544 if (layer.isRootLayer() && !view.document().ownerElement())
2548 return layer.hasTouchScrollableOverflow();
2550 return layer.needsCompositedScrolling();
2554 bool RenderLayerCompositor::requiresCompositingForPosition(RenderLayerModelObject& renderer, const RenderLayer& layer, RenderLayer::ViewportConstrainedNotCompositedReason* viewportConstrainedNotCompositedReason) const
2556 // position:fixed elements that create their own stacking context (e.g. have an explicit z-index,
2557 // opacity, transform) can get their own composited layer. A stacking context is required otherwise
2558 // z-index and clipping will be broken.
2559 if (!renderer.isPositioned())
2562 EPosition position = renderer.style().position();
2563 bool isFixed = renderer.isOutOfFlowPositioned() && position == FixedPosition;
2564 if (isFixed && !layer.isStackingContainer())
2567 bool isSticky = renderer.isInFlowPositioned() && position == StickyPosition;
2568 if (!isFixed && !isSticky)
2571 // FIXME: acceleratedCompositingForFixedPositionEnabled should probably be renamed acceleratedCompositingForViewportConstrainedPositionEnabled().
2572 const Settings& settings = m_renderView.frameView().frame().settings();
2573 if (!settings.acceleratedCompositingForFixedPositionEnabled())
2577 return hasCoordinatedScrolling() && isViewportConstrainedFixedOrStickyLayer(layer);
2579 auto container = renderer.container();
2580 // If the renderer is not hooked up yet then we have to wait until it is.
2582 m_reevaluateCompositingAfterLayout = true;
2586 // Don't promote fixed position elements that are descendants of a non-view container, e.g. transformed elements.
2587 // They will stay fixed wrt the container rather than the enclosing frame.
2588 if (container != &m_renderView && !renderer.fixedPositionedWithNamedFlowContainingBlock()) {
2589 if (viewportConstrainedNotCompositedReason)
2590 *viewportConstrainedNotCompositedReason = RenderLayer::NotCompositedForNonViewContainer;
2594 // Subsequent tests depend on layout. If we can't tell now, just keep things the way they are until layout is done.
2595 if (!m_inPostLayoutUpdate) {
2596 m_reevaluateCompositingAfterLayout = true;
2597 return layer.isComposited();
2600 bool paintsContent = layer.isVisuallyNonEmpty() || layer.hasVisibleDescendant();
2601 if (!paintsContent) {
2602 if (viewportConstrainedNotCompositedReason)
2603 *viewportConstrainedNotCompositedReason = RenderLayer::NotCompositedForNoVisibleContent;
2607 // Fixed position elements that are invisible in the current view don't get their own layer.
2608 LayoutRect viewBounds = m_renderView.frameView().viewportConstrainedExtentRect();
2609 LayoutRect layerBounds = layer.calculateLayerBounds(&layer, 0, RenderLayer::UseLocalClipRectIfPossible | RenderLayer::IncludeLayerFilterOutsets | RenderLayer::UseFragmentBoxes
2610 | RenderLayer::ExcludeHiddenDescendants | RenderLayer::DontConstrainForMask | RenderLayer::IncludeCompositedDescendants);
2611 // Map to m_renderView to ignore page scale.
2612 FloatRect absoluteBounds = layer.renderer().localToContainerQuad(FloatRect(layerBounds), &m_renderView).boundingBox();
2613 if (!viewBounds.intersects(enclosingIntRect(absoluteBounds))) {
2614 if (viewportConstrainedNotCompositedReason)
2615 *viewportConstrainedNotCompositedReason = RenderLayer::NotCompositedForBoundsOutOfView;
2622 bool RenderLayerCompositor::requiresCompositingForOverflowScrolling(const RenderLayer& layer) const
2624 return layer.needsCompositedScrolling();
2627 bool RenderLayerCompositor::isRunningAcceleratedTransformAnimation(RenderLayerModelObject& renderer) const
2629 if (!(m_compositingTriggers & ChromeClient::AnimationTrigger))
2632 return renderer.animation().isRunningAcceleratedAnimationOnRenderer(&renderer, CSSPropertyWebkitTransform, AnimationBase::Running | AnimationBase::Paused);
2635 // If an element has negative z-index children, those children render in front of the
2636 // layer background, so we need an extra 'contents' layer for the foreground of the layer
2638 bool RenderLayerCompositor::needsContentsCompositingLayer(const RenderLayer& layer) const
2640 return layer.hasNegativeZOrderList();
2643 bool RenderLayerCompositor::requiresScrollLayer(RootLayerAttachment attachment) const
2645 // This applies when the application UI handles scrolling, in which case RenderLayerCompositor doesn't need to manage it.
2646 if (m_renderView.frameView().delegatesScrolling())
2649 // We need to handle our own scrolling if we're:
2650 return !m_renderView.frameView().platformWidget() // viewless (i.e. non-Mac, or Mac in WebKit2)
2651 || attachment == RootLayerAttachedViaEnclosingFrame; // a composited frame on Mac
2654 static void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRect& clip)
2660 const IntRect& scrollbarRect = scrollbar->frameRect();
2661 context.translate(-scrollbarRect.x(), -scrollbarRect.y());
2662 IntRect transformedClip = clip;
2663 transformedClip.moveBy(scrollbarRect.location());
2664 scrollbar->paint(&context, transformedClip);
2668 void RenderLayerCompositor::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& context, GraphicsLayerPaintingPhase, const FloatRect& clip)
2670 IntRect pixelSnappedRectForIntegralPositionedItems = pixelSnappedIntRect(LayoutRect(clip));
2671 if (graphicsLayer == layerForHorizontalScrollbar())
2672 paintScrollbar(m_renderView.frameView().horizontalScrollbar(), context, pixelSnappedRectForIntegralPositionedItems);
2673 else if (graphicsLayer == layerForVerticalScrollbar())
2674 paintScrollbar(m_renderView.frameView().verticalScrollbar(), context, pixelSnappedRectForIntegralPositionedItems);
2675 else if (graphicsLayer == layerForScrollCorner()) {
2676 const IntRect& scrollCorner = m_renderView.frameView().scrollCornerRect();
2678 context.translate(-scrollCorner.x(), -scrollCorner.y());
2679 IntRect transformedClip = pixelSnappedRectForIntegralPositionedItems;
2680 transformedClip.moveBy(scrollCorner.location());
2681 m_renderView.frameView().paintScrollCorner(&context, transformedClip);
2686 bool RenderLayerCompositor::supportsFixedRootBackgroundCompositing() const
2688 RenderLayerBacking* renderViewBacking = m_renderView.layer()->backing();
2689 return renderViewBacking && renderViewBacking->usingTiledBacking();
2692 bool RenderLayerCompositor::needsFixedRootBackgroundLayer(const RenderLayer& layer) const
2694 if (&layer != m_renderView.layer())
2697 return supportsFixedRootBackgroundCompositing() && m_renderView.rootBackgroundIsEntirelyFixed();
2700 GraphicsLayer* RenderLayerCompositor::fixedRootBackgroundLayer() const
2702 // Get the fixed root background from the RenderView layer's backing.
2703 RenderLayer* viewLayer = m_renderView.layer();
2707 if (viewLayer->isComposited() && viewLayer->backing()->backgroundLayerPaintsFixedRootBackground())
2708 return viewLayer->backing()->backgroundLayer();
2713 static void resetTrackedRepaintRectsRecursive(GraphicsLayer& graphicsLayer)
2715 graphicsLayer.resetTrackedRepaints();
2717 for (size_t i = 0, size = graphicsLayer.children().size(); i < size; ++i)
2718 resetTrackedRepaintRectsRecursive(*graphicsLayer.children()[i]);
2720 if (GraphicsLayer* replicaLayer = graphicsLayer.replicaLayer())
2721 resetTrackedRepaintRectsRecursive(*replicaLayer);
2723 if (GraphicsLayer* maskLayer = graphicsLayer.maskLayer())
2724 resetTrackedRepaintRectsRecursive(*maskLayer);
2727 void RenderLayerCompositor::resetTrackedRepaintRects()
2729 if (GraphicsLayer* rootLayer = rootGraphicsLayer())
2730 resetTrackedRepaintRectsRecursive(*rootLayer);
2733 void RenderLayerCompositor::setTracksRepaints(bool tracksRepaints)
2735 m_isTrackingRepaints = tracksRepaints;
2738 bool RenderLayerCompositor::isTrackingRepaints() const
2740 return m_isTrackingRepaints;
2743 float RenderLayerCompositor::deviceScaleFactor() const
2745 Page* page = this->page();
2746 return page ? page->deviceScaleFactor() : 1;
2749 float RenderLayerCompositor::pageScaleFactor() const
2751 Page* page = this->page();
2752 return page ? page->pageScaleFactor() : 1;
2755 float RenderLayerCompositor::zoomedOutPageScaleFactor() const
2757 Page* page = this->page();
2758 return page ? page->zoomedOutPageScaleFactor() : 0;
2761 float RenderLayerCompositor::contentsScaleMultiplierForNewTiles(const GraphicsLayer*) const
2764 LegacyTileCache* tileCache = nullptr;
2765 if (Page* page = this->page()) {
2766 if (FrameView* frameView = page->mainFrame().view())
2767 tileCache = frameView->legacyTileCache();
2773 return tileCache->tilingMode() == LegacyTileCache::Zooming ? 0.125 : 1;
2779 void RenderLayerCompositor::didCommitChangesForLayer(const GraphicsLayer*) const
2781 // Nothing to do here yet.
2784 bool RenderLayerCompositor::keepLayersPixelAligned() const
2786 // When scaling, attempt to align compositing layers to pixel boundaries.
2790 bool RenderLayerCompositor::mainFrameBackingIsTiled() const
2792 RenderLayer* layer = m_renderView.layer();
2796 RenderLayerBacking* backing = layer->backing();
2800 return backing->usingTiledBacking();
2803 bool RenderLayerCompositor::shouldCompositeOverflowControls() const
2805 FrameView& frameView = m_renderView.frameView();
2807 if (frameView.platformWidget())
2810 if (frameView.delegatesScrolling())
2813 if (mainFrameBackingIsTiled())
2816 if (!frameView.hasOverlayScrollbars())
2822 bool RenderLayerCompositor::requiresHorizontalScrollbarLayer() const
2824 return shouldCompositeOverflowControls() && m_renderView.frameView().horizontalScrollbar();
2827 bool RenderLayerCompositor::requiresVerticalScrollbarLayer() const
2829 return shouldCompositeOverflowControls() && m_renderView.frameView().verticalScrollbar();
2832 bool RenderLayerCompositor::requiresScrollCornerLayer() const
2834 return shouldCompositeOverflowControls() && m_renderView.frameView().isScrollCornerVisible();
2837 #if ENABLE(RUBBER_BANDING)
2838 bool RenderLayerCompositor::requiresOverhangAreasLayer() const
2840 // We don't want a layer if this is a subframe.
2841 if (m_renderView.document().ownerElement())
2844 // We do want a layer if we're using tiled drawing and can scroll.
2845 if (mainFrameBackingIsTiled() && m_renderView.frameView().hasOpaqueBackground() && !m_renderView.frameView().prohibitsScrolling())
2851 bool RenderLayerCompositor::requiresContentShadowLayer() const
2853 // We don't want a layer if this is a subframe.
2854 if (m_renderView.document().ownerElement())
2858 if (viewHasTransparentBackground())
2861 // If the background is going to extend, then it doesn't make sense to have a shadow layer.
2862 if (m_renderView.frameView().frame().settings().backgroundShouldExtendBeyondPage())
2865 // On Mac, we want a content shadow layer if we're using tiled drawing and can scroll.
2866 if (mainFrameBackingIsTiled() && !m_renderView.frameView().prohibitsScrolling())
2873 GraphicsLayer* RenderLayerCompositor::updateLayerForTopOverhangArea(bool wantsLayer)
2875 if (m_renderView.document().ownerElement())
2879 if (m_layerForTopOverhangArea) {
2880 m_layerForTopOverhangArea->removeFromParent();
2881 m_layerForTopOverhangArea = nullptr;
2886 if (!m_layerForTopOverhangArea) {
2887 m_layerForTopOverhangArea = GraphicsLayer::create(graphicsLayerFactory(), this);
2889 m_layerForTopOverhangArea->setName("top overhang area");
2891 m_scrollLayer->addChildBelow(m_layerForTopOverhangArea.get(), m_rootContentLayer.get());
2894 return m_layerForTopOverhangArea.get();
2897 GraphicsLayer* RenderLayerCompositor::updateLayerForBottomOverhangArea(bool wantsLayer)
2899 if (m_renderView.document().ownerElement())
2903 if (m_layerForBottomOverhangArea) {
2904 m_layerForBottomOverhangArea->removeFromParent();
2905 m_layerForBottomOverhangArea = nullptr;
2910 if (!m_layerForBottomOverhangArea) {
2911 m_layerForBottomOverhangArea = GraphicsLayer::create(graphicsLayerFactory(), this);
2913 m_layerForBottomOverhangArea->setName("bottom overhang area");
2915 m_scrollLayer->addChildBelow(m_layerForBottomOverhangArea.get(), m_rootContentLayer.get());
2918 m_layerForBottomOverhangArea->setPosition(FloatPoint(0, m_rootContentLayer->size().height() + m_renderView.frameView().headerHeight() + m_renderView.frameView().footerHeight()));
2919 return m_layerForBottomOverhangArea.get();
2922 GraphicsLayer* RenderLayerCompositor::updateLayerForHeader(bool wantsLayer)
2924 if (m_renderView.document().ownerElement())
2928 if (m_layerForHeader) {
2929 m_layerForHeader->removeFromParent();
2930 m_layerForHeader = nullptr;
2932 // The ScrollingTree knows about the header layer, and the position of the root layer is affected
2933 // by the header layer, so if we remove the header, we need to tell the scrolling tree.
2934 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
2935 scrollingCoordinator->frameViewRootLayerDidChange(&m_renderView.frameView());
2940 if (!m_layerForHeader) {
2941 m_layerForHeader = GraphicsLayer::create(graphicsLayerFactory(), this);
2943 m_layerForHeader->setName("header");
2945 m_scrollLayer->addChildBelow(m_layerForHeader.get(), m_rootContentLayer.get());
2946 m_renderView.frameView().addPaintPendingMilestones(DidFirstFlushForHeaderLayer);
2949 m_layerForHeader->setPosition(FloatPoint());
2950 m_layerForHeader->setAnchorPoint(FloatPoint3D());
2951 m_layerForHeader->setSize(FloatSize(m_renderView.frameView().visibleWidth(), m_renderView.frameView().headerHeight()));
2953 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
2954 scrollingCoordinator->frameViewRootLayerDidChange(&m_renderView.frameView());
2956 if (Page* page = this->page())
2957 page->chrome().client().didAddHeaderLayer(m_layerForHeader.get());
2959 return m_layerForHeader.get();
2962 GraphicsLayer* RenderLayerCompositor::updateLayerForFooter(bool wantsLayer)
2964 if (m_renderView.document().ownerElement())
2968 if (m_layerForFooter) {
2969 m_layerForFooter->removeFromParent();
2970 m_layerForFooter = nullptr;
2972 // The ScrollingTree knows about the footer layer, and the total scrollable size is affected
2973 // by the footer layer, so if we remove the footer, we need to tell the scrolling tree.
2974 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
2975 scrollingCoordinator->frameViewRootLayerDidChange(&m_renderView.frameView());
2980 if (!m_layerForFooter) {
2981 m_layerForFooter = GraphicsLayer::create(graphicsLayerFactory(), this);
2983 m_layerForFooter->setName("footer");
2985 m_scrollLayer->addChildBelow(m_layerForFooter.get(), m_rootContentLayer.get());
2988 m_layerForFooter->setPosition(FloatPoint(0, m_rootContentLayer->size().height() + m_renderView.frameView().headerHeight()));
2989 m_layerForFooter->setAnchorPoint(FloatPoint3D());
2990 m_layerForFooter->setSize(FloatSize(m_renderView.frameView().visibleWidth(), m_renderView.frameView().footerHeight()));
2992 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
2993 scrollingCoordinator->frameViewRootLayerDidChange(&m_renderView.frameView());
2995 if (Page* page = this->page())
2996 page->chrome().client().didAddFooterLayer(m_layerForFooter.get());
2998 return m_layerForFooter.get();
3003 bool RenderLayerCompositor::viewHasTransparentBackground(Color* backgroundColor) const
3005 if (m_renderView.frameView().isTransparent()) {
3006 if (backgroundColor)
3007 *backgroundColor = Color(); // Return an invalid color.
3011 Color documentBackgroundColor = m_renderView.frameView().documentBackgroundColor();
3012 if (!documentBackgroundColor.isValid())
3013 documentBackgroundColor = Color::white;
3015 if (backgroundColor)
3016 *backgroundColor = documentBackgroundColor;
3018 return documentBackgroundColor.hasAlpha();
3021 void RenderLayerCompositor::setRootExtendedBackgroundColor(const Color& color)
3023 if (color == m_rootExtendedBackgroundColor)
3026 m_rootExtendedBackgroundColor = color;
3028 if (Page* page = this->page())
3029 page->chrome().client().pageExtendedBackgroundColorDidChange(color);
3031 #if ENABLE(RUBBER_BANDING)
3032 if (!m_layerForOverhangAreas)
3035 m_layerForOverhangAreas->setBackgroundColor(m_rootExtendedBackgroundColor);
3037 if (!m_rootExtendedBackgroundColor.isValid())
3038 m_layerForOverhangAreas->setCustomAppearance(GraphicsLayer::ScrollingOverhang);
3042 void RenderLayerCompositor::updateOverflowControlsLayers()
3044 #if ENABLE(RUBBER_BANDING)
3045 if (requiresOverhangAreasLayer()) {
3046 if (!m_layerForOverhangAreas) {
3047 m_layerForOverhangAreas = GraphicsLayer::create(graphicsLayerFactory(), this);
3049 m_layerForOverhangAreas->setName("overhang areas");
3051 m_layerForOverhangAreas->setDrawsContent(false);
3053 float topContentInset = m_renderView.frameView().topContentInset();
3054 IntSize overhangAreaSize = m_renderView.frameView().frameRect().size();
3055 overhangAreaSize.setHeight(overhangAreaSize.height() - topContentInset);
3056 m_layerForOverhangAreas->setSize(overhangAreaSize);
3057 m_layerForOverhangAreas->setPosition(FloatPoint(0, topContentInset));
3059 if (m_renderView.frameView().frame().settings().backgroundShouldExtendBeyondPage())
3060 m_layerForOverhangAreas->setBackgroundColor(m_renderView.frameView().documentBackgroundColor());
3062 m_layerForOverhangAreas->setCustomAppearance(GraphicsLayer::ScrollingOverhang);
3064 // We want the overhang areas layer to be positioned below the frame contents,
3065 // so insert it below the clip layer.
3066 m_overflowControlsHostLayer->addChildBelow(m_layerForOverhangAreas.get(), m_clipLayer.get());
3068 } else if (m_layerForOverhangAreas) {
3069 m_layerForOverhangAreas->removeFromParent();
3070 m_layerForOverhangAreas = nullptr;
3073 if (requiresContentShadowLayer()) {
3074 if (!m_contentShadowLayer) {
3075 m_contentShadowLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
3077 m_contentShadowLayer->setName("content shadow");
3079 m_contentShadowLayer->setSize(m_rootContentLayer->size());
3080 m_contentShadowLayer->setPosition(m_rootContentLayer->position());
3081 m_contentShadowLayer->setCustomAppearance(GraphicsLayer::ScrollingShadow);
3083 m_scrollLayer->addChildBelow(m_contentShadowLayer.get(), m_rootContentLayer.get());
3085 } else if (m_contentShadowLayer) {
3086 m_contentShadowLayer->removeFromParent();
3087 m_contentShadowLayer = nullptr;
3091 if (requiresHorizontalScrollbarLayer()) {
3092 if (!m_layerForHorizontalScrollbar) {
3093 m_layerForHorizontalScrollbar = GraphicsLayer::create(graphicsLayerFactory(), this);
3094 m_layerForHorizontalScrollbar->setShowDebugBorder(m_showDebugBorders);
3096 m_layerForHorizontalScrollbar->setName("horizontal scrollbar container");
3099 #if PLATFORM(COCOA) && USE(CA)
3100 m_layerForHorizontalScrollbar->setAcceleratesDrawing(acceleratedDrawingEnabled());
3102 m_overflowControlsHostLayer->addChild(m_layerForHorizontalScrollbar.get());
3104 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
3105 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(&m_renderView.frameView(), HorizontalScrollbar);
3107 } else if (m_layerForHorizontalScrollbar) {
3108 m_layerForHorizontalScrollbar->removeFromParent();
3109 m_layerForHorizontalScrollbar = nullptr;
3111 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
3112 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(&m_renderView.frameView(), HorizontalScrollbar);
3115 if (requiresVerticalScrollbarLayer()) {
3116 if (!m_layerForVerticalScrollbar) {
3117 m_layerForVerticalScrollbar = GraphicsLayer::create(graphicsLayerFactory(), this);
3118 m_layerForVerticalScrollbar->setShowDebugBorder(m_showDebugBorders);
3120 m_layerForVerticalScrollbar->setName("vertical scrollbar container");
3122 #if PLATFORM(COCOA) && USE(CA)
3123 m_layerForVerticalScrollbar->setAcceleratesDrawing(acceleratedDrawingEnabled());
3125 m_overflowControlsHostLayer->addChild(m_layerForVerticalScrollbar.get());
3127 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
3128 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(&m_renderView.frameView(), VerticalScrollbar);
3130 } else if (m_layerForVerticalScrollbar) {
3131 m_layerForVerticalScrollbar->removeFromParent();
3132 m_layerForVerticalScrollbar = nullptr;
3134 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
3135 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(&m_renderView.frameView(), VerticalScrollbar);
3138 if (requiresScrollCornerLayer()) {
3139 if (!m_layerForScrollCorner) {
3140 m_layerForScrollCorner = GraphicsLayer::create(graphicsLayerFactory(), this);
3141 m_layerForScrollCorner->setShowDebugBorder(m_showDebugBorders);
3143 m_layerForScrollCorner->setName("scroll corner");
3145 #if PLATFORM(COCOA) && USE(CA)
3146 m_layerForScrollCorner->setAcceleratesDrawing(acceleratedDrawingEnabled());
3148 m_overflowControlsHostLayer->addChild(m_layerForScrollCorner.get());
3150 } else if (m_layerForScrollCorner) {
3151 m_layerForScrollCorner->removeFromParent();
3152 m_layerForScrollCorner = nullptr;
3155 m_renderView.frameView().positionScrollbarLayers();
3158 void RenderLayerCompositor::ensureRootLayer()
3160 RootLayerAttachment expectedAttachment = shouldPropagateCompositingToEnclosingFrame() ? RootLayerAttachedViaEnclosingFrame : RootLayerAttachedViaChromeClient;
3161 if (expectedAttachment == m_rootLayerAttachment)
3164 if (!m_rootContentLayer) {
3165 m_rootContentLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
3167 m_rootContentLayer->setName("content root");
3169 IntRect overflowRect = m_renderView.pixelSnappedLayoutOverflowRect();
3170 m_rootContentLayer->setSize(FloatSize(overflowRect.maxX(), overflowRect.maxY()));
3171 m_rootContentLayer->setPosition(FloatPoint());
3173 #if PLATFORM(IOS) || PLATFORM(EFL)
3174 // Page scale is applied above this on iOS, so we'll just say that our root layer applies it.
3175 Frame& frame = m_renderView.frameView().frame();
3176 if (frame.isMainFrame())
3177 m_rootContentLayer->setAppliesPageScale();
3180 // Need to clip to prevent transformed content showing outside this frame
3181 m_rootContentLayer->setMasksToBounds(true);
3184 if (requiresScrollLayer(expectedAttachment)) {
3185 if (!m_overflowControlsHostLayer) {
3186 ASSERT(!m_scrollLayer);
3187 ASSERT(!m_clipLayer);
3189 // Create a layer to host the clipping layer and the overflow controls layers.
3190 m_overflowControlsHostLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
3192 m_overflowControlsHostLayer->setName("overflow controls host");
3195 // Create a clipping layer if this is an iframe
3196 m_clipLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
3198 m_clipLayer->setName("frame clipping");
3200 m_clipLayer->setMasksToBounds(true);
3202 m_scrollLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
3204 m_scrollLayer->setName("frame scrolling");
3207 m_overflowControlsHostLayer->addChild(m_clipLayer.get());
3208 m_clipLayer->addChild(m_scrollLayer.get());
3209 m_scrollLayer->addChild(m_rootContentLayer.get());
3211 m_clipLayer->setSize(m_renderView.frameView().unscaledTotalVisibleContentSize());
3213 updateOverflowControlsLayers();
3215 if (hasCoordinatedScrolling())
3216 scheduleLayerFlush(true);
3218 updateScrollLayerPosition();
3221 if (m_overflowControlsHostLayer) {
3222 m_overflowControlsHostLayer = nullptr;
3223 m_clipLayer = nullptr;
3224 m_scrollLayer = nullptr;
3228 // Check to see if we have to change the attachment
3229 if (m_rootLayerAttachment != RootLayerUnattached)
3232 attachRootLayer(expectedAttachment);
3235 void RenderLayerCompositor::destroyRootLayer()
3237 if (!m_rootContentLayer)
3242 #if ENABLE(RUBBER_BANDING)
3243 if (m_layerForOverhangAreas) {
3244 m_layerForOverhangAreas->removeFromParent();
3245 m_layerForOverhangAreas = nullptr;
3249 if (m_layerForHorizontalScrollbar) {
3250 m_layerForHorizontalScrollbar->removeFromParent();
3251 m_layerForHorizontalScrollbar = nullptr;
3252 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
3253 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(&m_renderView.frameView(), HorizontalScrollbar);
3254 if (Scrollbar* horizontalScrollbar = m_renderView.frameView().verticalScrollbar())
3255 m_renderView.frameView().invalidateScrollbar(horizontalScrollbar, IntRect(IntPoint(0, 0), horizontalScrollbar->frameRect().size()));
3258 if (m_layerForVerticalScrollbar) {
3259 m_layerForVerticalScrollbar->removeFromParent();
3260 m_layerForVerticalScrollbar = nullptr;
3261 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
3262 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(&m_renderView.frameView(), VerticalScrollbar);
3263 if (Scrollbar* verticalScrollbar = m_renderView.frameView().verticalScrollbar())
3264 m_renderView.frameView().invalidateScrollbar(verticalScrollbar, IntRect(IntPoint(0, 0), verticalScrollbar->frameRect().size()));
3267 if (m_layerForScrollCorner) {
3268 m_layerForScrollCorner = nullptr;
3269 m_renderView.frameView().invalidateScrollCorner(m_renderView.frameView().scrollCornerRect());
3272 if (m_overflowControlsHostLayer) {
3273 m_overflowControlsHostLayer = nullptr;
3274 m_clipLayer = nullptr;
3275 m_scrollLayer = nullptr;
3277 ASSERT(!m_scrollLayer);
3278 m_rootContentLayer = nullptr;
3280 m_layerUpdater = nullptr;
3283 void RenderLayerCompositor::attachRootLayer(RootLayerAttachment attachment)
3285 if (!m_rootContentLayer)
3288 switch (attachment) {
3289 case RootLayerUnattached:
3290 ASSERT_NOT_REACHED();
3292 case RootLayerAttachedViaChromeClient: {
3293 Frame& frame = m_renderView.frameView().frame();
3294 Page* page = frame.page();
3298 page->chrome().client().attachRootGraphicsLayer(&frame, rootGraphicsLayer());
3301 case RootLayerAttachedViaEnclosingFrame: {
3302 // The layer will get hooked up via RenderLayerBacking::updateGraphicsLayerConfiguration()
3303 // for the frame's renderer in the parent document.
3304 m_renderView.document().ownerElement()->scheduleSetNeedsStyleRecalc(SyntheticStyleChange);
3309 m_rootLayerAttachment = attachment;
3310 rootLayerAttachmentChanged();
3312 if (m_shouldFlushOnReattach) {
3313 scheduleLayerFlushNow();
3314 m_shouldFlushOnReattach = false;
3318 void RenderLayerCompositor::detachRootLayer()
3320 if (!m_rootContentLayer || m_rootLayerAttachment == RootLayerUnattached)
3323 switch (m_rootLayerAttachment) {
3324 case RootLayerAttachedViaEnclosingFrame: {
3325 // The layer will get unhooked up via RenderLayerBacking::updateGraphicsLayerConfiguration()
3326 // for the frame's renderer in the parent document.
3327 if (m_overflowControlsHostLayer)
3328 m_overflowControlsHostLayer->removeFromParent();
3330 m_rootContentLayer->removeFromParent();
3332 if (HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement())
3333 ownerElement->scheduleSetNeedsStyleRecalc(SyntheticStyleChange);
3336 case RootLayerAttachedViaChromeClient: {
3337 Frame& frame = m_renderView.frameView().frame();
3338 Page* page = frame.page();
3342 page->chrome().client().attachRootGraphicsLayer(&frame, 0);
3345 case RootLayerUnattached:
3349 m_rootLayerAttachment = RootLayerUnattached;
3350 rootLayerAttachmentChanged();
3353 void RenderLayerCompositor::updateRootLayerAttachment()
3358 void RenderLayerCompositor::rootLayerAttachmentChanged()
3360 // The attachment can affect whether the RenderView layer's paintsIntoWindow() behavior,
3361 // so call updateDrawsContent() to update that.
3362 RenderLayer* layer = m_renderView.layer();
3363 if (RenderLayerBacking* backing = layer ? layer->backing() : 0)
3364 backing->updateDrawsContent();
3367 // IFrames are special, because we hook compositing layers together across iframe boundaries
3368 // when both parent and iframe content are composited. So when this frame becomes composited, we have
3369 // to use a synthetic style change to get the iframes into RenderLayers in order to allow them to composite.
3370 void RenderLayerCompositor::notifyIFramesOfCompositingChange()
3372 Frame& frame = m_renderView.frameView().frame();
3374 for (Frame* child = frame.tree().firstChild(); child; child = child->tree().traverseNext(&frame)) {
3375 if (child->document() && child->document()->ownerElement())
3376 child->document()->ownerElement()->scheduleSetNeedsStyleRecalc(SyntheticStyleChange);
3379 // Compositing also affects the answer to RenderIFrame::requiresAcceleratedCompositing(), so
3380 // we need to schedule a style recalc in our parent document.
3381 if (HTMLFrameOwnerElement* ownerElement = m_renderView.document().ownerElement())
3382 ownerElement->scheduleSetNeedsStyleRecalc(SyntheticStyleChange);
3385 bool RenderLayerCompositor::layerHas3DContent(const RenderLayer& layer) const
3387 const RenderStyle& style = layer.renderer().style();
3389 if (style.transformStyle3D() == TransformStyle3DPreserve3D || style.hasPerspective() || style.transform().has3DOperation())
3392 const_cast<RenderLayer&>(layer).updateLayerListsIfNeeded();
3394 #if !ASSERT_DISABLED
3395 LayerListMutationDetector mutationChecker(const_cast<RenderLayer*>(&layer));
3398 if (layer.isStackingContainer()) {
3399 if (Vector<RenderLayer*>* negZOrderList = layer.negZOrderList()) {
3400 for (size_t i = 0, size = negZOrderList->size(); i < size; ++i) {
3401 if (layerHas3DContent(*negZOrderList->at(i)))
3406 if (Vector<RenderLayer*>* posZOrderList = layer.posZOrderList()) {
3407 for (size_t i = 0, size = posZOrderList->size(); i < size; ++i) {
3408 if (layerHas3DContent(*posZOrderList->at(i)))
3414 if (Vector<RenderLayer*>* normalFlowList = layer.normalFlowList()) {
3415 for (size_t i = 0, size = normalFlowList->size(); i < size; ++i) {
3416 if (layerHas3DContent(*normalFlowList->at(i)))
3424 void RenderLayerCompositor::deviceOrPageScaleFactorChanged()
3426 // Page scale will only be applied at to the RenderView and sublayers, but the device scale factor
3427 // needs to be applied at the level of rootGraphicsLayer().
3428 GraphicsLayer* rootLayer = rootGraphicsLayer();
3430 rootLayer->noteDeviceOrPageScaleFactorChangedIncludingDescendants();
3433 void RenderLayerCompositor::updateScrollCoordinatedStatus(RenderLayer& layer)
3435 ScrollCoordinationReasons coordinationReasons = 0;
3436 if (isViewportConstrainedFixedOrStickyLayer(layer))
3437 coordinationReasons |= FixedOrSticky;
3439 if (isMainFrameScrollingOrOverflowScrolling(m_renderView, layer))
3440 coordinationReasons |= Scrolling;
3442 if (coordinationReasons) {
3443 m_scrollCoordinatedLayers.add(&layer);
3444 updateScrollCoordinatedLayer(layer, coordinationReasons);
3446 removeFromScrollCoordinatedLayers(layer);
3449 void RenderLayerCompositor::removeFromScrollCoordinatedLayers(RenderLayer& layer)
3451 if (!m_scrollCoordinatedLayers.contains(&layer))
3454 m_scrollCoordinatedLayers.remove(&layer);
3455 m_scrollCoordinatedLayersNeedingUpdate.remove(&layer);
3457 detachScrollCoordinatedLayer(layer);
3460 FixedPositionViewportConstraints RenderLayerCompositor::computeFixedViewportConstraints(RenderLayer& layer) const
3462 ASSERT(layer.isComposited());
3464 GraphicsLayer* graphicsLayer = layer.backing()->graphicsLayer();
3465 LayoutRect viewportRect = m_renderView.frameView().viewportConstrainedVisibleContentRect();
3467 FixedPositionViewportConstraints constraints;
3468 constraints.setLayerPositionAtLastLayout(graphicsLayer->position());
3469 constraints.setViewportRectAtLastLayout(viewportRect);
3471 const RenderStyle& style = layer.renderer().style();
3472 if (!style.left().isAuto())
3473 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft);
3475 if (!style.right().isAuto())
3476 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeRight);
3478 if (!style.top().isAuto())
3479 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop);
3481 if (!style.bottom().isAuto())
3482 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeBottom);
3484 // If left and right are auto, use left.
3485 if (style.left().isAuto() && style.right().isAuto())
3486 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft);
3488 // If top and bottom are auto, use top.
3489 if (style.top().isAuto() && style.bottom().isAuto())
3490 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop);
3495 StickyPositionViewportConstraints RenderLayerCompositor::computeStickyViewportConstraints(RenderLayer& layer) const
3497 ASSERT(layer.isComposited());
3499 // We should never get here for stickies constrained by an enclosing clipping layer.
3500 // FIXME: Why does this assertion fail on iOS?
3501 ASSERT(!layer.enclosingOverflowClipLayer(ExcludeSelf));
3504 LayoutRect viewportRect = m_renderView.frameView().viewportConstrainedVisibleContentRect();
3505 RenderBoxModelObject& renderer = toRenderBoxModelObject(layer.renderer());
3507 StickyPositionViewportConstraints constraints;
3508 renderer.computeStickyPositionConstraints(constraints, viewportRect);
3510 GraphicsLayer* graphicsLayer = layer.backing()->graphicsLayer();
3512 constraints.setLayerPositionAtLastLayout(graphicsLayer->position());
3513 constraints.setStickyOffsetAtLastLayout(renderer.stickyPositionOffset());
3518 static RenderLayerBacking* nearestScrollCoordinatedAncestor(RenderLayer& layer)
3520 RenderLayer* ancestor = layer.parent();
3522 if (RenderLayerBacking* backing = ancestor->backing()) {
3523 if (backing->scrollingNodeIDForChildren())
3526 ancestor = ancestor->parent();
3532 void RenderLayerCompositor::updateScrollCoordinatedLayer(RenderLayer& layer, ScrollCoordinationReasons reasons)
3534 // FIXME: support scrolling layers in iframes.
3535 if (m_renderView.document().ownerElement())
3538 ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator();
3539 if (!scrollingCoordinator)
3542 bool isRootLayer = &layer == m_renderView.layer();
3544 // FIXME: Remove supportsFixedPositionLayers() since all platforms support them now.
3545 if (!scrollingCoordinator->supportsFixedPositionLayers() || (!layer.parent() && !isRootLayer))
3548 ASSERT(m_scrollCoordinatedLayers.contains(&layer));
3549 ASSERT(layer.isComposited());
3551 RenderLayerBacking* backing = layer.backing();
3555 RenderLayerBacking* parent = nearestScrollCoordinatedAncestor(layer);
3556 if (!parent && !isRootLayer)
3559 ScrollingNodeID parentNodeID = parent ? parent->scrollingNodeIDForChildren() : 0;
3561 // Always call this even if the backing is already attached because the parent may have changed.
3562 // If a node plays both roles, fixed/sticky is always the ancestor node of scrolling.
3563 if (reasons & FixedOrSticky) {
3564 ScrollingNodeID nodeID = backing->viewportConstrainedNodeID();
3566 nodeID = scrollingCoordinator->uniqueScrollLayerID();
3568 ScrollingNodeType nodeType = FrameScrollingNode;
3569 if (layer.renderer().style().position() == FixedPosition)
3570 nodeType = FixedNode;
3571 else if (layer.renderer().style().position() == StickyPosition)
3572 nodeType = StickyNode;
3574 ASSERT_NOT_REACHED();
3576 nodeID = scrollingCoordinator->attachToStateTree(nodeType, nodeID, parentNodeID);
3580 backing->setViewportConstrainedNodeID(nodeID);
3584 scrollingCoordinator->updateViewportConstrainedNode(nodeID, computeFixedViewportConstraints(layer), backing->graphicsLayer());
3587 scrollingCoordinator->updateViewportConstrainedNode(nodeID, computeStickyViewportConstraints(layer), backing->graphicsLayer());
3589 case FrameScrollingNode:
3590 case OverflowScrollingNode:
3594 parentNodeID = nodeID;
3597 if (reasons & Scrolling) {
3598 ScrollingNodeID nodeID = backing->scrollingNodeID();
3600 nodeID = scrollingCoordinator->uniqueScrollLayerID();
3602 nodeID = scrollingCoordinator->attachToStateTree(isRootLayer ? FrameScrollingNode : OverflowScrollingNode, nodeID, parentNodeID);
3606 backing->setScrollingNodeID(nodeID);
3607 m_scrollingNodeToLayerMap.add(nodeID, &layer);
3609 GraphicsLayer* scrollingLayer = backing->scrollingLayer();
3610 GraphicsLayer* scrolledContentsLayer = backing->scrollingContentsLayer();
3611 GraphicsLayer* counterScrollingLayer = nullptr;
3614 scrollingLayer = m_scrollLayer.get();
3615 scrolledContentsLayer = nullptr;
3616 counterScrollingLayer = fixedRootBackgroundLayer();
3617 scrollingCoordinator->updateScrollingNode(nodeID, scrollingLayer, scrolledContentsLayer, counterScrollingLayer);
3619 ScrollingCoordinator::ScrollingGeometry scrollingGeometry;
3620 scrollingGeometry.scrollOrigin = layer.scrollOrigin();
3621 scrollingGeometry.scrollPosition = layer.scrollPosition();
3622 scrollingGeometry.contentSize = layer.contentsSize();
3623 scrollingCoordinator->updateScrollingNode(nodeID, scrollingLayer, scrolledContentsLayer, counterScrollingLayer, &scrollingGeometry);
3628 void RenderLayerCompositor::detachScrollCoordinatedLayer(RenderLayer& layer)
3630 RenderLayerBacking* backing = layer.backing();
3634 backing->detachFromScrollingCoordinator();
3636 if (ScrollingNodeID nodeID = backing->scrollingNodeID())
3637 m_scrollingNodeToLayerMap.remove(nodeID);
3640 ScrollableArea* RenderLayerCompositor::scrollableAreaForScrollLayerID(ScrollingNodeID nodeID) const
3645 return m_scrollingNodeToLayerMap.get(nodeID);
3649 typedef HashMap<PlatformLayer*, std::unique_ptr<ViewportConstraints>> LayerMap;
3650 typedef HashMap<PlatformLayer*, PlatformLayer*> StickyContainerMap;
3652 void RenderLayerCompositor::registerAllViewportConstrainedLayers()
3654 // Only the main frame should register fixed/sticky layers.
3655 if (m_renderView.document().ownerElement())
3658 if (scrollingCoordinator())
3662 StickyContainerMap stickyContainerMap;
3664 for (auto it = m_scrollCoordinatedLayers.begin(), end = m_scrollCoordinatedLayers.end(); it != end; ++it) {
3665 RenderLayer& layer = **it;
3666 ASSERT(layer.isComposited());
3668 std::unique_ptr<ViewportConstraints> constraints;
3669 if (layer.renderer().isStickyPositioned()) {
3670 constraints = std::make_unique<StickyPositionViewportConstraints>(computeStickyViewportConstraints(layer));
3671 const RenderLayer* enclosingTouchScrollableLayer = nullptr;
3672 if (isStickyInAcceleratedScrollingLayerOrViewport(layer, &enclosingTouchScrollableLayer) && enclosingTouchScrollableLayer) {
3673 ASSERT(enclosingTouchScrollableLayer->isComposited());
3674 stickyContainerMap.add(layer.backing()->graphicsLayer()->platformLayer(), enclosingTouchScrollableLayer->backing()->scrollingLayer()->platformLayer());
3676 } else if (layer.renderer().style().position() == FixedPosition)
3677 constraints = std::make_unique<FixedPositionViewportConstraints>(computeFixedViewportConstraints(layer));
3681 layerMap.add(layer.backing()->graphicsLayer()->platformLayer(), std::move(constraints));
3684 if (ChromeClient* client = this->chromeClient())
3685 client->updateViewportConstrainedLayers(layerMap, stickyContainerMap);
3688 void RenderLayerCompositor::unregisterAllViewportConstrainedLayers()
3690 // Only the main frame should register fixed/sticky layers.
3691 if (m_renderView.document().ownerElement())
3694 if (scrollingCoordinator())
3697 if (ChromeClient* client = this->chromeClient()) {
3699 StickyContainerMap stickyContainerMap;
3700 client->updateViewportConstrainedLayers(layerMap, stickyContainerMap);
3704 void RenderLayerCompositor::registerAllScrollingLayers()
3706 ChromeClient* client = this->chromeClient();
3710 for (auto it = m_scrollingLayers.begin(), end = m_scrollingLayers.end(); it != end; ++it)
3711 updateScrollingLayerWithClient(**it, client);
3714 void RenderLayerCompositor::unregisterAllScrollingLayers()
3716 ChromeClient* client = this->chromeClient();
3720 for (auto it = m_scrollingLayers.begin(), end = m_scrollingLayers.end(); it != end; ++it) {
3721 RenderLayer& layer = **it;
3722 RenderLayerBacking* backing = layer.backing();
3724 client->removeScrollingLayer(layer.renderer().element(), backing->scrollingLayer()->platformLayer(), backing->scrollingContentsLayer()->platformLayer());
3729 void RenderLayerCompositor::willRemoveScrollingLayer(RenderLayer& layer)
3731 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
3732 RenderLayerBacking* backing = layer.backing();
3735 scrollingCoordinator->detachFromStateTree(backing->scrollingNodeID());
3737 // For Coordinated Graphics.
3738 scrollingCoordinator->scrollableAreaScrollLayerDidChange(&layer);
3743 m_scrollingLayersNeedingUpdate.remove(&layer);
3744 m_scrollingLayers.remove(&layer);
3746 if (m_renderView.document().inPageCache() || !layer.backing())
3749 if (ChromeClient* client = this->chromeClient()) {
3750 PlatformLayer* scrollingLayer = layer.backing()->scrollingLayer()->platformLayer();
3751 PlatformLayer* contentsLayer = layer.backing()->scrollingContentsLayer()->platformLayer();
3752 client->removeScrollingLayer(layer.renderer().element(), scrollingLayer, contentsLayer);
3757 void RenderLayerCompositor::didAddScrollingLayer(RenderLayer& layer)
3759 updateScrollCoordinatedStatus(layer);
3761 if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
3762 // For Coordinated Graphics.
3763 scrollingCoordinator->scrollableAreaScrollLayerDidChange(&layer);
3768 ASSERT(!m_renderView.document().inPageCache());
3769 m_scrollingLayers.add(&layer);
3773 void RenderLayerCompositor::windowScreenDidChange(PlatformDisplayID displayID)
3776 m_layerUpdater->screenDidChange(displayID);
3779 ScrollingCoordinator* RenderLayerCompositor::scrollingCoordinator() const
3781 if (Page* page = this->page())
3782 return page->scrollingCoordinator();
3787 GraphicsLayerFactory* RenderLayerCompositor::graphicsLayerFactory() const
3789 if (Page* page = this->page())
3790 return page->chrome().client().graphicsLayerFactory();
3795 Page* RenderLayerCompositor::page() const
3797 return m_renderView.frameView().frame().page();
3800 void RenderLayerCompositor::setLayerFlushThrottlingEnabled(bool enabled)
3802 m_layerFlushThrottlingEnabled = enabled;
3803 if (m_layerFlushThrottlingEnabled)
3805 m_layerFlushTimer.stop();
3806 if (!m_hasPendingLayerFlush)
3808 scheduleLayerFlushNow();
3811 void RenderLayerCompositor::disableLayerFlushThrottlingTemporarilyForInteraction()
3813 if (m_layerFlushThrottlingTemporarilyDisabledForInteraction)
3815 m_layerFlushThrottlingTemporarilyDisabledForInteraction = true;
3818 bool RenderLayerCompositor::isThrottlingLayerFlushes() const
3820 if (!m_layerFlushThrottlingEnabled)
3822 if (!m_layerFlushTimer.isActive())
3824 if (m_layerFlushThrottlingTemporarilyDisabledForInteraction)
3829 void RenderLayerCompositor::startLayerFlushTimerIfNeeded()
3831 m_layerFlushThrottlingTemporarilyDisabledForInteraction = false;
3832 m_layerFlushTimer.stop();
3833 if (!m_layerFlushThrottlingEnabled)
3835 m_layerFlushTimer.startOneShot(throttledLayerFlushDelay);
3838 void RenderLayerCompositor::startInitialLayerFlushTimerIfNeeded()
3840 if (!m_layerFlushThrottlingEnabled)
3842 if (m_layerFlushTimer.isActive())
3844 m_layerFlushTimer.startOneShot(throttledLayerFlushInitialDelay);
3847 void RenderLayerCompositor::layerFlushTimerFired(Timer<RenderLayerCompositor>&)
3849 if (!m_hasPendingLayerFlush)
3851 scheduleLayerFlushNow();
3854 void RenderLayerCompositor::paintRelatedMilestonesTimerFired(Timer<RenderLayerCompositor>&)
3856 Frame& frame = m_renderView.frameView().frame();
3857 Page* page = frame.page();
3861 // If the layer tree is frozen, we'll paint when it's unfrozen and schedule the timer again.
3862 if (page->chrome().client().layerTreeStateIsFrozen())
3865 m_renderView.frameView().firePaintRelatedMilestonesIfNeeded();
3868 } // namespace WebCore