1/*
2 * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "ChromeClient.h"
29#include "GraphicsLayerClient.h"
30#include "GraphicsLayerUpdater.h"
31#include "RenderLayer.h"
32#include <wtf/HashMap.h>
33#include <wtf/OptionSet.h>
34
35namespace WebCore {
36
37class FixedPositionViewportConstraints;
38class GraphicsLayer;
39class GraphicsLayerUpdater;
40class LayerOverlapMap;
41class RenderEmbeddedObject;
42class RenderVideo;
43class RenderWidget;
44class ScrollingCoordinator;
45class StickyPositionViewportConstraints;
46class TiledBacking;
47
48typedef unsigned LayerTreeFlags;
49
50enum class CompositingUpdateType {
51 AfterStyleChange,
52 AfterLayout,
53 OnScroll,
54 OnCompositedScroll
55};
56
57enum class CompositingReason {
58 Transform3D = 1 << 0,
59 Video = 1 << 1,
60 Canvas = 1 << 2,
61 Plugin = 1 << 3,
62 IFrame = 1 << 4,
63 BackfaceVisibilityHidden = 1 << 5,
64 ClipsCompositingDescendants = 1 << 6,
65 Animation = 1 << 7,
66 Filters = 1 << 8,
67 PositionFixed = 1 << 9,
68 PositionSticky = 1 << 10,
69 OverflowScrolling = 1 << 11,
70 Stacking = 1 << 12,
71 Overlap = 1 << 13,
72 OverflowScrollPositioning = 1 << 14,
73 NegativeZIndexChildren = 1 << 15,
74 TransformWithCompositedDescendants = 1 << 16,
75 OpacityWithCompositedDescendants = 1 << 17,
76 MaskWithCompositedDescendants = 1 << 18,
77 ReflectionWithCompositedDescendants = 1 << 19,
78 FilterWithCompositedDescendants = 1 << 20,
79 BlendingWithCompositedDescendants = 1 << 21,
80 Perspective = 1 << 22,
81 Preserve3D = 1 << 23,
82 WillChange = 1 << 24,
83 Root = 1 << 25,
84 IsolatesCompositedBlendingDescendants = 1 << 26,
85 EmbeddedView = 1 << 27,
86};
87
88enum class ScrollCoordinationRole {
89 ViewportConstrained = 1 << 0,
90 Scrolling = 1 << 1,
91 FrameHosting = 1 << 2,
92 Positioning = 1 << 3,
93};
94
95#if PLATFORM(IOS_FAMILY)
96class LegacyWebKitScrollingLayerCoordinator {
97public:
98 LegacyWebKitScrollingLayerCoordinator(ChromeClient& chromeClient, bool coordinateViewportConstrainedLayers)
99 : m_chromeClient(chromeClient)
100 , m_coordinateViewportConstrainedLayers(coordinateViewportConstrainedLayers)
101 {
102 }
103
104 void registerAllViewportConstrainedLayers(RenderLayerCompositor&);
105 void unregisterAllViewportConstrainedLayers();
106
107 void registerAllScrollingLayers();
108 void registerScrollingLayersNeedingUpdate();
109 void unregisterAllScrollingLayers();
110
111 void addScrollingLayer(RenderLayer&);
112 void removeScrollingLayer(RenderLayer&, RenderLayerBacking&);
113
114 void addViewportConstrainedLayer(RenderLayer&);
115 void removeViewportConstrainedLayer(RenderLayer&);
116
117 void didChangePlatformLayerForLayer(RenderLayer&);
118
119 void removeLayer(RenderLayer&);
120
121private:
122 void updateScrollingLayer(RenderLayer&);
123
124 ChromeClient& m_chromeClient;
125
126 HashSet<RenderLayer*> m_scrollingLayers;
127 HashSet<RenderLayer*> m_viewportConstrainedLayers;
128
129 HashSet<RenderLayer*> m_scrollingLayersNeedingUpdate;
130 const bool m_coordinateViewportConstrainedLayers;
131};
132#endif
133
134// RenderLayerCompositor manages the hierarchy of
135// composited RenderLayers. It determines which RenderLayers
136// become compositing, and creates and maintains a hierarchy of
137// GraphicsLayers based on the RenderLayer painting order.
138//
139// There is one RenderLayerCompositor per RenderView.
140
141class RenderLayerCompositor final : public GraphicsLayerClient, public GraphicsLayerUpdaterClient {
142 WTF_MAKE_FAST_ALLOCATED;
143 friend class LegacyWebKitScrollingLayerCoordinator;
144public:
145 explicit RenderLayerCompositor(RenderView&);
146 virtual ~RenderLayerCompositor();
147
148 // Return true if this RenderView is in "compositing mode" (i.e. has one or more
149 // composited RenderLayers)
150 bool usesCompositing() const { return m_compositing; }
151 // This will make a compositing layer at the root automatically, and hook up to
152 // the native view/window system.
153 void enableCompositingMode(bool enable = true);
154
155 bool inForcedCompositingMode() const { return m_forceCompositingMode; }
156
157 // True when some content element other than the root is composited.
158 bool hasContentCompositingLayers() const { return m_contentLayersCount; }
159
160 // Returns true if the accelerated compositing is enabled
161 bool hasAcceleratedCompositing() const { return m_hasAcceleratedCompositing; }
162
163 bool canRender3DTransforms() const;
164
165 void willRecalcStyle();
166
167 // Returns true if the composited layers were actually updated.
168 bool didRecalcStyleWithNoPendingLayout();
169
170 // GraphicsLayers buffer state, which gets pushed to the underlying platform layers
171 // at specific times.
172 void scheduleLayerFlush(bool canThrottle = false);
173 void flushPendingLayerChanges(bool isFlushRoot = true);
174
175 // Called when the GraphicsLayer for the given RenderLayer has flushed changes inside of flushPendingLayerChanges().
176 void didChangePlatformLayerForLayer(RenderLayer&, const GraphicsLayer*);
177
178 // Called when something outside WebKit affects the visible rect (e.g. delegated scrolling). Might schedule a layer flush.
179 void didChangeVisibleRect();
180
181 // Rebuild the tree of compositing layers
182 bool updateCompositingLayers(CompositingUpdateType, RenderLayer* updateRoot = nullptr);
183 // This is only used when state changes and we do not exepect a style update or layout to happen soon (e.g. when
184 // we discover that an iframe is overlapped during painting).
185 void scheduleCompositingLayerUpdate();
186 // This is used to cancel any pending update timers when the document goes into page cache.
187 void cancelCompositingLayerUpdate();
188
189 // Update the compositing state of the given layer. Returns true if that state changed.
190 enum CompositingChangeRepaint { CompositingChangeRepaintNow, CompositingChangeWillRepaintLater };
191 enum class LayoutUpToDate {
192 Yes, No
193 };
194
195 struct RequiresCompositingData {
196 LayoutUpToDate layoutUpToDate { LayoutUpToDate::Yes };
197 RenderLayer::ViewportConstrainedNotCompositedReason nonCompositedForPositionReason { RenderLayer::NoNotCompositedReason };
198 bool reevaluateAfterLayout { false };
199 };
200
201 bool updateLayerCompositingState(RenderLayer&, RequiresCompositingData&, CompositingChangeRepaint = CompositingChangeRepaintNow);
202
203 // Whether layer's backing needs a graphics layer to do clipping by an ancestor (non-stacking-context parent with overflow).
204 bool clippedByAncestor(RenderLayer&) const;
205 // Whether layer's backing needs a graphics layer to clip z-order children of the given layer.
206 static bool clipsCompositingDescendants(const RenderLayer&);
207
208 // Whether the given layer needs an extra 'contents' layer.
209 bool needsContentsCompositingLayer(const RenderLayer&) const;
210
211 bool fixedLayerIntersectsViewport(const RenderLayer&) const;
212
213 bool supportsFixedRootBackgroundCompositing() const;
214 bool needsFixedRootBackgroundLayer(const RenderLayer&) const;
215 GraphicsLayer* fixedRootBackgroundLayer() const;
216
217 void rootOrBodyStyleChanged(RenderElement&, const RenderStyle* oldStyle);
218
219 // Called after the view transparency, or the document or base background color change.
220 void rootBackgroundColorOrTransparencyChanged();
221
222 // Repaint the appropriate layers when the given RenderLayer starts or stops being composited.
223 void repaintOnCompositingChange(RenderLayer&);
224
225 void repaintInCompositedAncestor(RenderLayer&, const LayoutRect&);
226
227 // Notify us that a layer has been added or removed
228 void layerWasAdded(RenderLayer& parent, RenderLayer& child);
229 void layerWillBeRemoved(RenderLayer& parent, RenderLayer& child);
230
231 void layerStyleChanged(StyleDifference, RenderLayer&, const RenderStyle* oldStyle);
232
233 static bool canCompositeClipPath(const RenderLayer&);
234
235 // Get the nearest ancestor layer that has overflow or clip, but is not a stacking context
236 RenderLayer* enclosingNonStackingClippingLayer(const RenderLayer&) const;
237
238 // Repaint all composited layers.
239 void repaintCompositedLayers();
240
241 // Returns true if the given layer needs it own backing store.
242 bool requiresOwnBackingStore(const RenderLayer&, const RenderLayer* compositingAncestorLayer, const LayoutRect& layerCompositedBoundsInAncestor, const LayoutRect& ancestorCompositedBounds) const;
243
244 WEBCORE_EXPORT RenderLayer& rootRenderLayer() const;
245 GraphicsLayer* rootGraphicsLayer() const;
246
247 GraphicsLayer* scrollContainerLayer() const { return m_scrollContainerLayer.get(); }
248 GraphicsLayer* scrolledContentsLayer() const { return m_scrolledContentsLayer.get(); }
249 GraphicsLayer* clipLayer() const { return m_clipLayer.get(); }
250 GraphicsLayer* rootContentsLayer() const { return m_rootContentsLayer.get(); }
251
252 GraphicsLayer* layerForClipping() const { return m_clipLayer ? m_clipLayer.get() : m_scrollContainerLayer.get(); }
253
254#if ENABLE(RUBBER_BANDING)
255 GraphicsLayer* headerLayer() const { return m_layerForHeader.get(); }
256 GraphicsLayer* footerLayer() const { return m_layerForFooter.get(); }
257#endif
258
259 enum RootLayerAttachment {
260 RootLayerUnattached,
261 RootLayerAttachedViaChromeClient,
262 RootLayerAttachedViaEnclosingFrame
263 };
264
265 RootLayerAttachment rootLayerAttachment() const { return m_rootLayerAttachment; }
266 void updateRootLayerAttachment();
267 void updateRootLayerPosition();
268
269 void setIsInWindow(bool);
270
271 void clearBackingForAllLayers();
272
273 void layerBecameComposited(const RenderLayer&);
274 void layerBecameNonComposited(const RenderLayer&);
275
276#if ENABLE(VIDEO)
277 // Use by RenderVideo to ask if it should try to use accelerated compositing.
278 bool canAccelerateVideoRendering(RenderVideo&) const;
279#endif
280
281 // Walk the tree looking for layers with 3d transforms. Useful in case you need
282 // to know if there is non-affine content, e.g. for drawing into an image.
283 bool has3DContent() const;
284
285 static RenderLayerCompositor* frameContentsCompositor(RenderWidget&);
286 // Return true if the layers changed.
287 bool parentFrameContentLayers(RenderWidget&);
288
289 // Update the geometry of the layers used for clipping and scrolling in frames.
290 void frameViewDidChangeLocation(const IntPoint& contentsOffset);
291 void frameViewDidChangeSize();
292 void frameViewDidScroll();
293 void frameViewDidAddOrRemoveScrollbars();
294 void frameViewDidLayout();
295 void rootLayerConfigurationChanged();
296
297 String layerTreeAsText(LayerTreeFlags);
298
299 float deviceScaleFactor() const override;
300 float contentsScaleMultiplierForNewTiles(const GraphicsLayer*) const override;
301 float pageScaleFactor() const override;
302 float zoomedOutPageScaleFactor() const override;
303 void didChangePlatformLayerForLayer(const GraphicsLayer*) override { }
304 void notifyFlushBeforeDisplayRefresh(const GraphicsLayer*) override;
305
306 void layerTiledBackingUsageChanged(const GraphicsLayer*, bool /*usingTiledBacking*/);
307
308 bool acceleratedDrawingEnabled() const { return m_acceleratedDrawingEnabled; }
309 bool displayListDrawingEnabled() const { return m_displayListDrawingEnabled; }
310
311 void deviceOrPageScaleFactorChanged();
312
313 void windowScreenDidChange(PlatformDisplayID);
314
315 GraphicsLayer* layerForHorizontalScrollbar() const { return m_layerForHorizontalScrollbar.get(); }
316 GraphicsLayer* layerForVerticalScrollbar() const { return m_layerForVerticalScrollbar.get(); }
317 GraphicsLayer* layerForScrollCorner() const { return m_layerForScrollCorner.get(); }
318#if ENABLE(RUBBER_BANDING)
319 GraphicsLayer* layerForOverhangAreas() const { return m_layerForOverhangAreas.get(); }
320 GraphicsLayer* layerForContentShadow() const { return m_contentShadowLayer.get(); }
321
322 GraphicsLayer* updateLayerForTopOverhangArea(bool wantsLayer);
323 GraphicsLayer* updateLayerForBottomOverhangArea(bool wantsLayer);
324 GraphicsLayer* updateLayerForHeader(bool wantsLayer);
325 GraphicsLayer* updateLayerForFooter(bool wantsLayer);
326#endif
327
328 // FIXME: make the coordinated/async terminology consistent.
329 bool isViewportConstrainedFixedOrStickyLayer(const RenderLayer&) const;
330 bool useCoordinatedScrollingForLayer(const RenderLayer&) const;
331 ScrollPositioningBehavior computeCoordinatedPositioningForLayer(const RenderLayer&) const;
332 bool isLayerForIFrameWithScrollCoordinatedContents(const RenderLayer&) const;
333
334 ScrollableArea* scrollableAreaForScrollLayerID(ScrollingNodeID) const;
335
336 void removeFromScrollCoordinatedLayers(RenderLayer&);
337
338 void willRemoveScrollingLayerWithBacking(RenderLayer&, RenderLayerBacking&);
339 void didAddScrollingLayer(RenderLayer&);
340
341 void resetTrackedRepaintRects();
342 void setTracksRepaints(bool tracksRepaints) { m_isTrackingRepaints = tracksRepaints; }
343
344 bool viewHasTransparentBackground(Color* backgroundColor = nullptr) const;
345
346 bool hasNonMainLayersWithTiledBacking() const { return m_layersWithTiledBackingCount; }
347
348 OptionSet<CompositingReason> reasonsForCompositing(const RenderLayer&) const;
349
350 void setLayerFlushThrottlingEnabled(bool);
351 void disableLayerFlushThrottlingTemporarilyForInteraction();
352
353 void didPaintBacking(RenderLayerBacking*);
354
355 const Color& rootExtendedBackgroundColor() const { return m_rootExtendedBackgroundColor; }
356
357 void updateRootContentLayerClipping();
358
359#if ENABLE(CSS_SCROLL_SNAP)
360 void updateScrollSnapPropertiesWithFrameView(const FrameView&) const;
361#endif
362
363 // For testing.
364 void startTrackingLayerFlushes() { m_layerFlushCount = 0; }
365 unsigned layerFlushCount() const { return m_layerFlushCount; }
366
367 void startTrackingCompositingUpdates() { m_compositingUpdateCount = 0; }
368 unsigned compositingUpdateCount() const { return m_compositingUpdateCount; }
369
370private:
371 class BackingSharingState;
372 struct CompositingState;
373 struct OverlapExtent;
374
375 // Returns true if the policy changed.
376 bool updateCompositingPolicy();
377
378 // GraphicsLayerClient implementation
379 void notifyFlushRequired(const GraphicsLayer*) override;
380 void paintContents(const GraphicsLayer*, GraphicsContext&, OptionSet<GraphicsLayerPaintingPhase>, const FloatRect&, GraphicsLayerPaintBehavior) override;
381 void customPositionForVisibleRectComputation(const GraphicsLayer*, FloatPoint&) const override;
382 bool isTrackingRepaints() const override { return m_isTrackingRepaints; }
383
384 // GraphicsLayerUpdaterClient implementation
385 void flushLayersSoon(GraphicsLayerUpdater&) override;
386
387 // Copy the accelerated compositing related flags from Settings
388 void cacheAcceleratedCompositingFlags();
389 void cacheAcceleratedCompositingFlagsAfterLayout();
390
391 // Whether the given RL needs a compositing layer.
392 bool needsToBeComposited(const RenderLayer&, RequiresCompositingData&) const;
393 // Whether the layer has an intrinsic need for compositing layer.
394 bool requiresCompositingLayer(const RenderLayer&, RequiresCompositingData&) const;
395 // Whether the layer could ever be composited.
396 bool canBeComposited(const RenderLayer&) const;
397 bool needsCompositingUpdateForStyleChangeOnNonCompositedLayer(RenderLayer&, const RenderStyle* oldStyle) const;
398
399 // Make or destroy the backing for this layer; returns true if backing changed.
400 enum class BackingRequired { No, Yes, Unknown };
401 bool updateBacking(RenderLayer&, RequiresCompositingData&, CompositingChangeRepaint shouldRepaint, BackingRequired = BackingRequired::Unknown);
402
403 void clearBackingForLayerIncludingDescendants(RenderLayer&);
404
405 // Repaint this and its child layers.
406 void recursiveRepaintLayer(RenderLayer&);
407
408 void computeExtent(const LayerOverlapMap&, const RenderLayer&, OverlapExtent&) const;
409 void addToOverlapMap(LayerOverlapMap&, const RenderLayer&, OverlapExtent&) const;
410 void addDescendantsToOverlapMapRecursive(LayerOverlapMap&, const RenderLayer&, const RenderLayer* ancestorLayer = nullptr) const;
411 void updateOverlapMap(LayerOverlapMap&, const RenderLayer&, OverlapExtent&, bool didPushContainer, bool addLayerToOverlap, bool addDescendantsToOverlap = false) const;
412 bool layerOverlaps(const LayerOverlapMap&, const RenderLayer&, OverlapExtent&) const;
413
414 void updateCompositingLayersTimerFired();
415
416 void computeCompositingRequirements(RenderLayer* ancestorLayer, RenderLayer&, LayerOverlapMap&, CompositingState&, BackingSharingState&, bool& descendantHas3DTransform);
417 void traverseUnchangedSubtree(RenderLayer* ancestorLayer, RenderLayer&, LayerOverlapMap&, CompositingState&, BackingSharingState&, bool& descendantHas3DTransform);
418
419 enum class UpdateLevel {
420 AllDescendants = 1 << 0,
421 CompositedChildren = 1 << 1,
422 };
423 // Recurses down the tree, parenting descendant compositing layers and collecting an array of child layers for the current compositing layer.
424 void updateBackingAndHierarchy(RenderLayer&, Vector<Ref<GraphicsLayer>>& childGraphicsLayersOfEnclosingLayer, struct ScrollingTreeState&, OptionSet<UpdateLevel> = { }, int depth = 0);
425
426 bool layerHas3DContent(const RenderLayer&) const;
427 bool isRunningTransformAnimation(RenderLayerModelObject&) const;
428
429 void appendDocumentOverlayLayers(Vector<Ref<GraphicsLayer>>&);
430
431 bool needsCompositingForContentOrOverlays() const;
432
433 void ensureRootLayer();
434 void destroyRootLayer();
435
436 void attachRootLayer(RootLayerAttachment);
437 void detachRootLayer();
438
439 void rootLayerAttachmentChanged();
440
441 void updateOverflowControlsLayers();
442
443 void updateScrollLayerPosition();
444 void updateScrollLayerClipping();
445
446 FloatPoint positionForClipLayer() const;
447
448 void notifyIFramesOfCompositingChange();
449
450#if PLATFORM(IOS_FAMILY)
451 void updateScrollCoordinatedLayersAfterFlushIncludingSubframes();
452 void updateScrollCoordinatedLayersAfterFlush();
453#endif
454
455 FloatRect visibleRectForLayerFlushing() const;
456
457 Page& page() const;
458
459 GraphicsLayerFactory* graphicsLayerFactory() const;
460 ScrollingCoordinator* scrollingCoordinator() const;
461
462#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
463 RefPtr<DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) const override;
464#endif
465
466 // Non layout-dependent
467 bool requiresCompositingForAnimation(RenderLayerModelObject&) const;
468 bool requiresCompositingForTransform(RenderLayerModelObject&) const;
469 bool requiresCompositingForBackfaceVisibility(RenderLayerModelObject&) const;
470 bool requiresCompositingForVideo(RenderLayerModelObject&) const;
471 bool requiresCompositingForCanvas(RenderLayerModelObject&) const;
472 bool requiresCompositingForFilters(RenderLayerModelObject&) const;
473 bool requiresCompositingForWillChange(RenderLayerModelObject&) const;
474
475 // Layout-dependent
476 bool requiresCompositingForPlugin(RenderLayerModelObject&, RequiresCompositingData&) const;
477 bool requiresCompositingForFrame(RenderLayerModelObject&, RequiresCompositingData&) const;
478 bool requiresCompositingForScrollableFrame(RequiresCompositingData&) const;
479 bool requiresCompositingForPosition(RenderLayerModelObject&, const RenderLayer&, RequiresCompositingData&) const;
480 bool requiresCompositingForOverflowScrolling(const RenderLayer&, RequiresCompositingData&) const;
481 bool requiresCompositingForEditableImage(RenderLayerModelObject&) const;
482 bool requiresCompositingForIndirectReason(const RenderLayer&, bool hasCompositedDescendants, bool has3DTransformedDescendants, bool paintsIntoProvidedBacking, IndirectCompositingReason&) const;
483
484 static bool layerContainingBlockCrossesCoordinatedScrollingBoundary(const RenderLayer&, const RenderLayer& compositedAncestor);
485
486 static bool styleChangeMayAffectIndirectCompositingReasons(const RenderStyle& oldStyle, const RenderStyle& newStyle);
487
488 enum class ScrollingNodeChangeFlags {
489 Layer = 1 << 0,
490 LayerGeometry = 1 << 1,
491 };
492
493 ScrollingNodeID attachScrollingNode(RenderLayer&, ScrollingNodeType, struct ScrollingTreeState&);
494
495 // Returns the ScrollingNodeID which acts as the parent for children.
496 ScrollingNodeID updateScrollCoordinationForLayer(RenderLayer&, struct ScrollingTreeState&, OptionSet<ScrollCoordinationRole>, OptionSet<ScrollingNodeChangeFlags>);
497
498 // These return the ScrollingNodeID which acts as the parent for children.
499 ScrollingNodeID updateScrollingNodeForViewportConstrainedRole(RenderLayer&, struct ScrollingTreeState&, OptionSet<ScrollingNodeChangeFlags>);
500 ScrollingNodeID updateScrollingNodeForScrollingRole(RenderLayer&, struct ScrollingTreeState&, OptionSet<ScrollingNodeChangeFlags>);
501 ScrollingNodeID updateScrollingNodeForFrameHostingRole(RenderLayer&, struct ScrollingTreeState&, OptionSet<ScrollingNodeChangeFlags>);
502 ScrollingNodeID updateScrollingNodeForPositioningRole(RenderLayer&, struct ScrollingTreeState&, OptionSet<ScrollingNodeChangeFlags>);
503
504 void updateScrollingNodeLayers(ScrollingNodeID, RenderLayer&, ScrollingCoordinator&);
505
506 void detachScrollCoordinatedLayer(RenderLayer&, OptionSet<ScrollCoordinationRole>);
507 void detachScrollCoordinatedLayerWithRole(RenderLayer&, ScrollingCoordinator&, ScrollCoordinationRole);
508
509 FixedPositionViewportConstraints computeFixedViewportConstraints(RenderLayer&) const;
510 StickyPositionViewportConstraints computeStickyViewportConstraints(RenderLayer&) const;
511
512 LayoutRect rootParentRelativeScrollableRect() const;
513 LayoutRect parentRelativeScrollableRect(const RenderLayer&, const RenderLayer* ancestorLayer) const;
514
515 bool requiresScrollLayer(RootLayerAttachment) const;
516 bool requiresHorizontalScrollbarLayer() const;
517 bool requiresVerticalScrollbarLayer() const;
518 bool requiresScrollCornerLayer() const;
519#if ENABLE(RUBBER_BANDING)
520 bool requiresOverhangAreasLayer() const;
521 bool requiresContentShadowLayer() const;
522#endif
523
524 // True if the FrameView uses a ScrollingCoordinator.
525 bool hasCoordinatedScrolling() const;
526
527 // FIXME: make the coordinated/async terminology consistent.
528 bool isAsyncScrollableStickyLayer(const RenderLayer&, const RenderLayer** enclosingAcceleratedOverflowLayer = nullptr) const;
529
530 bool shouldCompositeOverflowControls() const;
531
532 bool isThrottlingLayerFlushes() const;
533 void startInitialLayerFlushTimerIfNeeded();
534 void startLayerFlushTimerIfNeeded();
535 void layerFlushTimerFired();
536
537#if !LOG_DISABLED
538 const char* logReasonsForCompositing(const RenderLayer&);
539 void logLayerInfo(const RenderLayer&, const char*, int depth);
540#endif
541
542 bool documentUsesTiledBacking() const;
543 bool isMainFrameCompositor() const;
544
545private:
546 RenderView& m_renderView;
547 Timer m_updateCompositingLayersTimer;
548
549 ChromeClient::CompositingTriggerFlags m_compositingTriggers { static_cast<ChromeClient::CompositingTriggerFlags>(ChromeClient::AllTriggers) };
550 bool m_hasAcceleratedCompositing { true };
551
552 CompositingPolicy m_compositingPolicy { CompositingPolicy::Normal };
553
554 bool m_showDebugBorders { false };
555 bool m_showRepaintCounter { false };
556 bool m_acceleratedDrawingEnabled { false };
557 bool m_displayListDrawingEnabled { false };
558
559 bool m_compositing { false };
560 bool m_flushingLayers { false };
561 bool m_shouldFlushOnReattach { false };
562 bool m_forceCompositingMode { false };
563 bool m_inPostLayoutUpdate { false }; // true when it's OK to trust layout information (e.g. layer sizes and positions)
564
565 bool m_isTrackingRepaints { false }; // Used for testing.
566
567 unsigned m_contentLayersCount { 0 };
568 unsigned m_layersWithTiledBackingCount { 0 };
569 unsigned m_layerFlushCount { 0 };
570 unsigned m_compositingUpdateCount { 0 };
571
572 RootLayerAttachment m_rootLayerAttachment { RootLayerUnattached };
573
574 RefPtr<GraphicsLayer> m_rootContentsLayer;
575
576 // Enclosing clipping layer for iframe content
577 RefPtr<GraphicsLayer> m_clipLayer;
578 RefPtr<GraphicsLayer> m_scrollContainerLayer;
579 RefPtr<GraphicsLayer> m_scrolledContentsLayer;
580
581 // Enclosing layer for overflow controls and the clipping layer
582 RefPtr<GraphicsLayer> m_overflowControlsHostLayer;
583
584 // Layers for overflow controls
585 RefPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
586 RefPtr<GraphicsLayer> m_layerForVerticalScrollbar;
587 RefPtr<GraphicsLayer> m_layerForScrollCorner;
588#if ENABLE(RUBBER_BANDING)
589 RefPtr<GraphicsLayer> m_layerForOverhangAreas;
590 RefPtr<GraphicsLayer> m_contentShadowLayer;
591 RefPtr<GraphicsLayer> m_layerForTopOverhangArea;
592 RefPtr<GraphicsLayer> m_layerForBottomOverhangArea;
593 RefPtr<GraphicsLayer> m_layerForHeader;
594 RefPtr<GraphicsLayer> m_layerForFooter;
595#endif
596
597 std::unique_ptr<GraphicsLayerUpdater> m_layerUpdater; // Updates tiled layer visible area periodically while animations are running.
598
599 Timer m_layerFlushTimer;
600
601 bool m_layerFlushThrottlingEnabled { false };
602 bool m_layerFlushThrottlingTemporarilyDisabledForInteraction { false };
603 bool m_hasPendingLayerFlush { false };
604 bool m_viewBackgroundIsTransparent { false };
605
606#if !LOG_DISABLED
607 int m_rootLayerUpdateCount { 0 };
608 int m_obligateCompositedLayerCount { 0 }; // count of layer that have to be composited.
609 int m_secondaryCompositedLayerCount { 0 }; // count of layers that have to be composited because of stacking or overlap.
610 double m_obligatoryBackingStoreBytes { 0 };
611 double m_secondaryBackingStoreBytes { 0 };
612#endif
613
614 Color m_viewBackgroundColor;
615 Color m_rootExtendedBackgroundColor;
616
617 HashMap<ScrollingNodeID, RenderLayer*> m_scrollingNodeToLayerMap;
618#if PLATFORM(IOS_FAMILY)
619 std::unique_ptr<LegacyWebKitScrollingLayerCoordinator> m_legacyScrollingLayerCoordinator;
620#endif
621};
622
623void paintScrollbar(Scrollbar*, GraphicsContext&, const IntRect& clip);
624
625WTF::TextStream& operator<<(WTF::TextStream&, CompositingUpdateType);
626WTF::TextStream& operator<<(WTF::TextStream&, CompositingPolicy);
627
628} // namespace WebCore
629
630#if ENABLE(TREE_DEBUGGING)
631// Outside the WebCore namespace for ease of invocation from the debugger.
632void showGraphicsLayerTreeForCompositor(WebCore::RenderLayerCompositor&);
633#endif
634