2 * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Intel Corporation. All rights reserved.
5 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
8 * Robert O'Callahan <roc+@cs.cmu.edu>
9 * David Baron <dbaron@fas.harvard.edu>
10 * Christian Biesinger <cbiesinger@web.de>
11 * Randall Jesup <rjesup@wgate.com>
12 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
13 * Josh Soref <timeless@mac.com>
14 * Boris Zbarsky <bzbarsky@mit.edu>
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 * Alternatively, the contents of this file may be used under the terms
31 * of either the Mozilla Public License Version 1.1, found at
32 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
33 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
34 * (the "GPL"), in which case the provisions of the MPL or the GPL are
35 * applicable instead of those above. If you wish to allow use of your
36 * version of this file only under the terms of one of those two
37 * licenses (the MPL or the GPL) and not to allow others to use your
38 * version of this file under the LGPL, indicate your decision by
39 * deletingthe provisions above and replace them with the notice and
40 * other provisions required by the MPL or the GPL, as the case may be.
41 * If you do not delete the provisions above, a recipient may use your
42 * version of this file under any of the LGPL, the MPL or the GPL.
48 #include "core/rendering/CompositedLayerMappingPtr.h"
49 #include "core/rendering/LayerPaintingInfo.h"
50 #include "core/rendering/RenderBox.h"
51 #include "core/rendering/RenderLayerBlendInfo.h"
52 #include "core/rendering/RenderLayerClipper.h"
53 #include "core/rendering/RenderLayerFilterInfo.h"
54 #include "core/rendering/RenderLayerReflectionInfo.h"
55 #include "core/rendering/RenderLayerRepainter.h"
56 #include "core/rendering/RenderLayerScrollableArea.h"
57 #include "core/rendering/RenderLayerStackingNode.h"
58 #include "core/rendering/RenderLayerStackingNodeIterator.h"
59 #include "platform/graphics/CompositingReasons.h"
60 #include "wtf/OwnPtr.h"
64 class FilterEffectRenderer;
65 class FilterOperations;
68 class HitTestingTransformState;
69 class RenderFlowThread;
70 class RenderGeometryMap;
71 class CompositedLayerMapping;
72 class RenderLayerCompositor;
75 class TransformationMatrix;
77 enum BorderRadiusClippingRule { IncludeSelfForBorderRadius, DoNotIncludeSelfForBorderRadius };
78 enum IncludeSelfOrNot { IncludeSelf, ExcludeSelf };
80 enum CompositedScrollingHistogramBuckets {
81 IsScrollableAreaBucket = 0,
82 NeedsToBeStackingContainerBucket = 1,
83 WillUseCompositedScrollingBucket = 2,
84 CompositedScrollingHistogramMax = 3
87 enum CompositingQueryMode {
88 CompositingQueriesAreAllowed,
89 CompositingQueriesAreOnlyAllowedInCertainDocumentLifecyclePhases
92 // FIXME: remove this once the compositing query ASSERTS are no longer hit.
93 class DisableCompositingQueryAsserts {
94 WTF_MAKE_NONCOPYABLE(DisableCompositingQueryAsserts);
96 DisableCompositingQueryAsserts();
98 TemporaryChange<CompositingQueryMode> m_disabler;
103 friend class RenderReplica;
104 // FIXME: Needed until we move all the necessary bits to the new class.
105 friend class RenderLayerStackingNode;
106 // FIXME: Needed until we move all the necessary bits to the new class.
107 friend class RenderLayerScrollableArea;
109 RenderLayer(RenderLayerModelObject*, LayerType);
112 String debugName() const;
114 RenderLayerModelObject* renderer() const { return m_renderer; }
115 RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; }
116 RenderLayer* parent() const { return m_parent; }
117 RenderLayer* previousSibling() const { return m_previous; }
118 RenderLayer* nextSibling() const { return m_next; }
119 RenderLayer* firstChild() const { return m_first; }
120 RenderLayer* lastChild() const { return m_last; }
122 const RenderLayer* compositingContainer() const;
124 void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0);
125 RenderLayer* removeChild(RenderLayer*);
127 void removeOnlyThisLayer();
128 void insertOnlyThisLayer();
130 void styleChanged(StyleDifference, const RenderStyle* oldStyle);
132 bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; }
133 bool isOverflowOnlyLayer() const { return m_layerType == OverflowClipLayer; }
134 bool isForcedLayer() const { return m_layerType == ForcedLayer; }
136 void setLayerType(LayerType layerType) { m_layerType = layerType; }
138 bool cannotBlitToWindow() const;
140 bool isTransparent() const;
141 RenderLayer* transparentPaintingAncestor();
142 void beginTransparencyLayers(GraphicsContext*, const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, PaintBehavior);
144 bool isReflection() const { return renderer()->isReplica(); }
145 RenderLayerReflectionInfo* reflectionInfo() { return m_reflectionInfo.get(); }
146 const RenderLayerReflectionInfo* reflectionInfo() const { return m_reflectionInfo.get(); }
148 const RenderLayer* root() const
150 const RenderLayer* curr = this;
151 while (curr->parent())
152 curr = curr->parent();
156 const LayoutPoint& location() const { return m_topLeft; }
157 void setLocation(const LayoutPoint& p) { m_topLeft = p; }
159 const IntSize& size() const { return m_layerSize; }
160 void setSize(const IntSize& size) { m_layerSize = size; }
162 LayoutRect rect() const { return LayoutRect(location(), size()); }
164 bool isRootLayer() const { return m_isRootLayer; }
166 RenderLayerCompositor* compositor() const;
168 // Notification from the renderer that its content changed (e.g. current frame of image changed).
169 // Allows updates of layer content without repainting.
170 void contentChanged(ContentChangeType);
172 bool canRender3DTransforms() const;
174 enum UpdateLayerPositionsFlag {
175 CheckForRepaint = 1 << 0,
176 NeedsFullRepaintInBacking = 1 << 1,
177 IsCompositingUpdateRoot = 1 << 2,
178 UpdateCompositingLayers = 1 << 3,
179 UpdatePagination = 1 << 4
181 typedef unsigned UpdateLayerPositionsFlags;
182 static const UpdateLayerPositionsFlags defaultFlags = CheckForRepaint | IsCompositingUpdateRoot | UpdateCompositingLayers;
184 void updateLayerPositionsAfterLayout(const RenderLayer* rootLayer, UpdateLayerPositionsFlags);
186 void updateLayerPositionsAfterOverflowScroll();
187 void updateLayerPositionsAfterDocumentScroll();
189 bool isPaginated() const { return m_isPaginated; }
190 RenderLayer* enclosingPaginationLayer() const { return m_enclosingPaginationLayer; }
192 void updateTransform();
193 void update3dRenderingContext();
194 RenderLayer* renderingContextRoot() const { return m_3dRenderingContextRoot; }
196 const LayoutSize& offsetForInFlowPosition() const { return m_offsetForInFlowPosition; }
198 void addBlockSelectionGapsBounds(const LayoutRect&);
199 void clearBlockSelectionGapsBounds();
200 void repaintBlockSelectionGaps();
201 bool hasBlockSelectionGapBounds() const;
203 RenderLayerStackingNode* stackingNode() { return m_stackingNode.get(); }
204 const RenderLayerStackingNode* stackingNode() const { return m_stackingNode.get(); }
206 bool subtreeIsInvisible() const { return !hasVisibleContent() && !hasVisibleDescendant(); }
208 // FIXME: We should ASSERT(!m_visibleContentStatusDirty) here, but see https://bugs.webkit.org/show_bug.cgi?id=71044
209 // ditto for hasVisibleDescendant(), see https://bugs.webkit.org/show_bug.cgi?id=71277
210 bool hasVisibleContent() const { return m_hasVisibleContent; }
211 bool hasVisibleDescendant() const { return m_hasVisibleDescendant; }
213 void setHasVisibleContent();
214 void dirtyVisibleContentStatus();
216 bool hasBoxDecorationsOrBackground() const;
217 bool hasVisibleBoxDecorations() const;
218 // Returns true if this layer has visible content (ignoring any child layers).
219 bool isVisuallyNonEmpty() const;
220 // True if this layer container renderers that paint.
221 bool hasNonEmptyChildRenderers() const;
223 // FIXME: We should ASSERT(!m_hasSelfPaintingLayerDescendantDirty); here but we hit the same bugs as visible content above.
224 // Part of the issue is with subtree relayout: we don't check if our ancestors have some descendant flags dirty, missing some updates.
225 bool hasSelfPaintingLayerDescendant() const { return m_hasSelfPaintingLayerDescendant; }
227 // FIXME: We should ASSERT(!m_hasOutOfFlowPositionedDescendantDirty) here. See above.
228 bool hasOutOfFlowPositionedDescendant() const { return m_hasOutOfFlowPositionedDescendant; }
230 void setHasOutOfFlowPositionedDescendant(bool hasDescendant) { m_hasOutOfFlowPositionedDescendant = hasDescendant; }
231 void setHasOutOfFlowPositionedDescendantDirty(bool dirty) { m_hasOutOfFlowPositionedDescendantDirty = dirty; }
233 bool hasUnclippedDescendant() const { return m_hasUnclippedDescendant; }
234 void setHasUnclippedDescendant(bool hasDescendant) { m_hasUnclippedDescendant = hasDescendant; }
235 void updateHasUnclippedDescendant();
236 bool isUnclippedDescendant() const { return m_isUnclippedDescendant; }
238 bool hasVisibleNonLayerContent() const { return m_hasVisibleNonLayerContent; }
239 void updateHasVisibleNonLayerContent();
241 // Gets the nearest enclosing positioned ancestor layer (also includes
242 // the <html> layer and the root layer).
243 RenderLayer* enclosingPositionedAncestor() const;
245 RenderLayer* enclosingOverflowClipLayer(IncludeSelfOrNot = IncludeSelf) const;
247 // Enclosing compositing layer; if includeSelf is true, may return this.
248 RenderLayer* enclosingCompositingLayer(IncludeSelfOrNot = IncludeSelf) const;
249 RenderLayer* enclosingCompositingLayerForRepaint(IncludeSelfOrNot = IncludeSelf) const;
250 // Ancestor compositing layer, excluding this.
251 RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(ExcludeSelf); }
253 // Ancestor composited scrolling layer at or above our containing block.
254 RenderLayer* ancestorCompositedScrollingLayer() const;
256 // Ancestor scrolling layer at or above our containing block.
257 RenderLayer* ancestorScrollingLayer() const;
259 RenderLayer* enclosingFilterLayer(IncludeSelfOrNot = IncludeSelf) const;
260 RenderLayer* enclosingFilterRepaintLayer() const;
261 bool hasAncestorWithFilterOutsets() const;
263 bool canUseConvertToLayerCoords() const
265 // These RenderObjects have an impact on their layers without the renderers knowing about it.
266 return !renderer()->hasColumns() && !renderer()->hasTransform() && !renderer()->isSVGRoot();
269 void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntPoint& location) const;
270 void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntRect&) const;
271 void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const;
272 void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect&) const;
274 // The two main functions that use the layer system. The paint method
275 // paints the layers that intersect the damage rect from back to
276 // front. The hitTest method looks for mouse events by walking
277 // layers that intersect the point from front to back.
278 void paint(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior = PaintBehaviorNormal, RenderObject* paintingRoot = 0, PaintLayerFlags = 0);
279 bool hitTest(const HitTestRequest&, HitTestResult&);
280 bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
281 void paintOverlayScrollbars(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior, RenderObject* paintingRoot = 0);
283 // Pass offsetFromRoot if known.
284 bool intersectsDamageRect(const LayoutRect& layerBounds, const LayoutRect& damageRect, const RenderLayer* rootLayer, const LayoutPoint* offsetFromRoot = 0) const;
286 enum CalculateLayerBoundsFlag {
287 IncludeSelfTransform = 1 << 0,
288 UseLocalClipRectIfPossible = 1 << 1,
289 IncludeLayerFilterOutsets = 1 << 2,
290 ExcludeHiddenDescendants = 1 << 3,
291 DontConstrainForMask = 1 << 4,
292 IncludeCompositedDescendants = 1 << 5,
293 UseFragmentBoxes = 1 << 6,
294 PretendLayerHasOwnBacking = 1 << 7,
295 DefaultCalculateLayerBoundsFlags = IncludeSelfTransform | UseLocalClipRectIfPossible | IncludeLayerFilterOutsets | UseFragmentBoxes
297 typedef unsigned CalculateLayerBoundsFlags;
299 // Bounding box relative to some ancestor layer. Pass offsetFromRoot if known.
300 LayoutRect boundingBox(const RenderLayer* rootLayer, CalculateLayerBoundsFlags = 0, const LayoutPoint* offsetFromRoot = 0) const;
301 // Bounding box in the coordinates of this layer.
302 LayoutRect localBoundingBox(CalculateLayerBoundsFlags = 0) const;
303 // Pixel snapped bounding box relative to the root.
304 IntRect absoluteBoundingBox() const;
306 // Bounds used for layer overlap testing in RenderLayerCompositor.
307 LayoutRect overlapBounds() const { return overlapBoundsIncludeChildren() ? calculateLayerBounds(this) : localBoundingBox(); }
309 // If true, this layer's children are included in its bounds for overlap testing.
310 // We can't rely on the children's positions if this layer has a filter that could have moved the children's pixels around.
311 bool overlapBoundsIncludeChildren() const { return hasFilter() && renderer()->style()->filter().hasFilterThatMovesPixels(); }
313 // Can pass offsetFromRoot if known.
314 LayoutRect calculateLayerBounds(const RenderLayer* ancestorLayer, const LayoutPoint* offsetFromRoot = 0, CalculateLayerBoundsFlags = DefaultCalculateLayerBoundsFlags) const;
316 // WARNING: This method returns the offset for the parent as this is what updateLayerPositions expects.
317 LayoutPoint computeOffsetFromRoot(bool& hasLayerOffset) const;
319 LayoutUnit staticInlinePosition() const { return m_staticInlinePosition; }
320 LayoutUnit staticBlockPosition() const { return m_staticBlockPosition; }
322 void setStaticInlinePosition(LayoutUnit position) { m_staticInlinePosition = position; }
323 void setStaticBlockPosition(LayoutUnit position) { m_staticBlockPosition = position; }
325 bool hasTransform() const { return renderer()->hasTransform(); }
326 // Note that this transform has the transform-origin baked in.
327 TransformationMatrix* transform() const { return m_transform.get(); }
328 // currentTransform computes a transform which takes accelerated animations into account. The
329 // resulting transform has transform-origin baked in. If the layer does not have a transform,
330 // returns the identity matrix.
331 TransformationMatrix currentTransform(RenderStyle::ApplyTransformOrigin = RenderStyle::IncludeTransformOrigin) const;
332 TransformationMatrix renderableTransform(PaintBehavior) const;
334 // Get the perspective transform, which is applied to transformed sublayers.
335 // Returns true if the layer has a -webkit-perspective.
336 // Note that this transform has the perspective-origin baked in.
337 TransformationMatrix perspectiveTransform() const;
338 FloatPoint perspectiveOrigin() const;
339 bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
340 bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
342 // FIXME: reflections should force transform-style to be flat in the style: https://bugs.webkit.org/show_bug.cgi?id=106959
343 bool shouldFlattenTransform() const { return renderer()->hasReflection() || !renderer()->style() || renderer()->style()->transformStyle3D() != TransformStyle3DPreserve3D; }
345 void filterNeedsRepaint();
346 bool hasFilter() const { return renderer()->hasFilter(); }
348 bool paintsWithBlendMode() const;
350 void* operator new(size_t);
351 // Only safe to call from RenderLayerModelObject::destroyLayer()
352 void operator delete(void*);
354 CompositingState compositingState() const;
356 // This returns true if our document is in a phase of its lifestyle during which
357 // compositing state may legally be read.
358 bool isAllowedToQueryCompositingState() const;
360 CompositedLayerMappingPtr compositedLayerMapping() const { return m_compositedLayerMapping.get(); }
361 CompositedLayerMappingPtr ensureCompositedLayerMapping();
363 // NOTE: If you are using hasCompositedLayerMapping to determine the state of compositing for this layer,
364 // (and not just to do bookkeeping related to the mapping like, say, allocating or deallocating a mapping),
365 // then you may have incorrect logic. Use compositingState() instead.
366 bool hasCompositedLayerMapping() const { return m_compositedLayerMapping.get(); }
367 void clearCompositedLayerMapping(bool layerBeingDestroyed = false);
369 CompositedLayerMapping* groupedMapping() const { return m_groupedMapping; }
370 void setGroupedMapping(CompositedLayerMapping* groupedMapping) { m_groupedMapping = groupedMapping; }
372 bool hasCompositedMask() const;
373 bool hasCompositedClippingMask() const;
374 bool needsCompositedScrolling() const { return m_scrollableArea && m_scrollableArea->needsCompositedScrolling(); }
376 bool clipsCompositingDescendantsWithBorderRadius() const;
378 RenderLayer* scrollParent() const;
379 RenderLayer* clipParent() const;
381 bool needsCompositingLayersRebuiltForClip(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
382 bool needsCompositingLayersRebuiltForOverflow(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
383 bool needsCompositingLayersRebuiltForFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle, bool didPaintWithFilters) const;
384 bool needsCompositingLayersRebuiltForBlending(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
386 bool paintsWithTransparency(PaintBehavior paintBehavior) const
388 return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || compositingState() != PaintsIntoOwnBacking);
391 bool paintsWithTransform(PaintBehavior) const;
393 // Returns true if background phase is painted opaque in the given rect.
394 // The query rect is given in local coordinates.
395 bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
397 bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; }
398 void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; }
400 FilterOperations computeFilterOperations(const RenderStyle*);
401 bool paintsWithFilters() const;
402 bool requiresFullLayerImageForFilters() const;
403 FilterEffectRenderer* filterRenderer() const
405 RenderLayerFilterInfo* filterInfo = this->filterInfo();
406 return filterInfo ? filterInfo->renderer() : 0;
409 RenderLayerFilterInfo* filterInfo() const { return hasFilterInfo() ? RenderLayerFilterInfo::filterInfoForRenderLayer(this) : 0; }
410 RenderLayerFilterInfo* ensureFilterInfo() { return RenderLayerFilterInfo::createFilterInfoForRenderLayerIfNeeded(this); }
411 void removeFilterInfoIfNeeded()
414 RenderLayerFilterInfo::removeFilterInfoForRenderLayer(this);
417 bool hasFilterInfo() const { return m_hasFilterInfo; }
418 void setHasFilterInfo(bool hasFilterInfo) { m_hasFilterInfo = hasFilterInfo; }
420 void updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle);
422 Node* enclosingElement() const;
424 bool isInTopLayer() const;
425 bool isInTopLayerSubtree() const;
427 enum ViewportConstrainedNotCompositedReason {
428 NoNotCompositedReason,
429 NotCompositedForBoundsOutOfView,
430 NotCompositedForNonViewContainer,
431 NotCompositedForNoVisibleContent,
432 NotCompositedForUnscrollableAncestors,
435 void setViewportConstrainedNotCompositedReason(ViewportConstrainedNotCompositedReason reason) { m_compositingProperties.viewportConstrainedNotCompositedReason = reason; }
436 ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason() const { return static_cast<ViewportConstrainedNotCompositedReason>(m_compositingProperties.viewportConstrainedNotCompositedReason); }
438 bool isOutOfFlowRenderFlowThread() const { return renderer()->isOutOfFlowRenderFlowThread(); }
440 bool scrollsWithRespectTo(const RenderLayer*) const;
442 void addLayerHitTestRects(LayerHitTestRects&) const;
444 // Compute rects only for this layer
445 void computeSelfHitTestRects(LayerHitTestRects&) const;
447 // FIXME: This should probably return a ScrollableArea but a lot of internal methods are mistakenly exposed.
448 RenderLayerScrollableArea* scrollableArea() const { return m_scrollableArea.get(); }
449 RenderLayerRepainter& repainter() { return m_repainter; }
450 RenderLayerClipper& clipper() { return m_clipper; }
451 const RenderLayerClipper& clipper() const { return m_clipper; }
453 inline bool isPositionedContainer() const
455 // FIXME: This is not in sync with containingBlock.
456 // RenderObject::canContainFixedPositionedObject() should probably be used
458 RenderLayerModelObject* layerRenderer = renderer();
459 return isRootLayer() || layerRenderer->isPositioned() || hasTransform();
462 void paintLayer(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
464 PassOwnPtr<Vector<FloatRect> > collectTrackedRepaintRects() const;
466 RenderLayerBlendInfo& blendInfo() { return m_blendInfo; }
468 void setOffsetFromSquashingLayerOrigin(IntSize offset) { m_compositingProperties.offsetFromSquashingLayerOrigin = offset; }
469 IntSize offsetFromSquashingLayerOrigin() const { return m_compositingProperties.offsetFromSquashingLayerOrigin; }
471 bool scrollsOverflow() const;
474 bool hasOverflowControls() const;
476 void setIsUnclippedDescendant(bool isUnclippedDescendant) { m_isUnclippedDescendant = isUnclippedDescendant; }
478 void setAncestorChainHasSelfPaintingLayerDescendant();
479 void dirtyAncestorChainHasSelfPaintingLayerDescendantStatus();
481 void setAncestorChainHasOutOfFlowPositionedDescendant();
482 void dirtyAncestorChainHasOutOfFlowPositionedDescendantStatus();
484 void clipToRect(RenderLayer* rootLayer, GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&,
485 BorderRadiusClippingRule = IncludeSelfForBorderRadius);
486 void restoreClip(GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&);
488 void updateSelfPaintingLayer();
490 void updateOutOfFlowPositioned(const RenderStyle* oldStyle);
492 void didUpdateNeedsCompositedScrolling();
494 // Returns true if the position changed.
495 bool updateLayerPosition();
497 void updateLayerPositions(RenderGeometryMap* = 0, UpdateLayerPositionsFlags = defaultFlags);
499 enum UpdateLayerPositionsAfterScrollFlag {
501 IsOverflowScroll = 1 << 0,
502 HasSeenViewportConstrainedAncestor = 1 << 1,
503 HasSeenAncestorWithOverflowClip = 1 << 2,
504 HasChangedAncestor = 1 << 3
506 typedef unsigned UpdateLayerPositionsAfterScrollFlags;
507 void updateLayerPositionsAfterScroll(RenderGeometryMap*, UpdateLayerPositionsAfterScrollFlags = NoFlag);
509 void setNextSibling(RenderLayer* next) { m_next = next; }
510 void setPreviousSibling(RenderLayer* prev) { m_previous = prev; }
511 void setParent(RenderLayer* parent);
512 void setFirstChild(RenderLayer* first) { m_first = first; }
513 void setLastChild(RenderLayer* last) { m_last = last; }
515 LayoutPoint renderBoxLocation() const { return renderer()->isBox() ? toRenderBox(renderer())->location() : LayoutPoint(); }
517 void paintLayerContentsAndReflection(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
518 void paintLayerByApplyingTransform(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const LayoutPoint& translationOffset = LayoutPoint());
519 void paintLayerContents(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
520 void paintChildren(unsigned childrenToVisit, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
521 void paintPaginatedChildLayer(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
522 void paintChildLayerIntoColumns(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
524 void collectFragments(LayerFragments&, const RenderLayer* rootLayer, const LayoutRect& dirtyRect,
525 ClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize,
526 ShouldRespectOverflowClip = RespectOverflowClip, const LayoutPoint* offsetFromRoot = 0,
527 const LayoutSize& subPixelAccumulation = LayoutSize(), const LayoutRect* layerBoundingBox = 0);
528 void updatePaintingInfoForFragments(LayerFragments&, const LayerPaintingInfo&, PaintLayerFlags, bool shouldPaintContent, const LayoutPoint* offsetFromRoot);
529 void paintBackgroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
530 const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
531 void paintForegroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
532 const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer,
533 bool selectionOnly, bool forceBlackText);
534 void paintForegroundForFragmentsWithPhase(PaintPhase, const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
535 void paintOutlineForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
536 void paintOverflowControlsForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&);
537 void paintMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
538 void paintChildClippingMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
539 void paintTransformedLayerIntoFragments(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
541 RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result,
542 const LayoutRect& hitTestRect, const HitTestLocation&, bool appliedTransform,
543 const HitTestingTransformState* transformState = 0, double* zOffset = 0);
544 RenderLayer* hitTestLayerByApplyingTransform(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
545 const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0,
546 const LayoutPoint& translationOffset = LayoutPoint());
547 RenderLayer* hitTestChildren(ChildrenIteration, RenderLayer* rootLayer, const HitTestRequest&, HitTestResult&,
548 const LayoutRect& hitTestRect, const HitTestLocation&,
549 const HitTestingTransformState* transformState, double* zOffsetForDescendants, double* zOffset,
550 const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants);
551 RenderLayer* hitTestPaginatedChildLayer(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
552 const LayoutRect& hitTestRect, const HitTestLocation&,
553 const HitTestingTransformState* transformState, double* zOffset);
554 RenderLayer* hitTestChildLayerColumns(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
555 const LayoutRect& hitTestRect, const HitTestLocation&,
556 const HitTestingTransformState* transformState, double* zOffset,
557 const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
559 PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer,
560 const LayoutRect& hitTestRect, const HitTestLocation&,
561 const HitTestingTransformState* containerTransformState,
562 const LayoutPoint& translationOffset = LayoutPoint()) const;
564 bool hitTestContents(const HitTestRequest&, HitTestResult&, const LayoutRect& layerBounds, const HitTestLocation&, HitTestFilter) const;
565 bool hitTestContentsForFragments(const LayerFragments&, const HitTestRequest&, HitTestResult&, const HitTestLocation&, HitTestFilter, bool& insideClipRect) const;
566 RenderLayer* hitTestTransformedLayerInFragments(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
567 const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0);
569 bool childBackgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
571 bool shouldBeSelfPaintingLayer() const;
574 // FIXME: We should only create the stacking node if needed.
575 bool requiresStackingNode() const { return true; }
576 void updateStackingNode();
578 void updateReflectionInfo(const RenderStyle*);
580 // FIXME: We could lazily allocate our ScrollableArea based on style properties ('overflow', ...)
581 // but for now, we are always allocating it for RenderBox as it's safer.
582 bool requiresScrollableArea() const { return renderBox(); }
583 void updateScrollableArea();
585 void dirtyAncestorChainVisibleDescendantStatus();
586 void setAncestorChainHasVisibleDescendant();
588 void updateDescendantDependentFlags();
590 void dirty3DTransformedDescendantStatus();
591 // Both updates the status, and returns true if descendants of this have 3d.
592 bool update3DTransformedDescendantStatus();
594 void updateOrRemoveFilterClients();
595 void updateOrRemoveFilterEffectRenderer();
597 LayoutRect paintingExtent(const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, PaintBehavior);
599 RenderLayer* enclosingTransformedAncestor() const;
601 void updatePagination();
603 // FIXME: Temporary. Remove when new columns come online.
604 bool useRegionBasedColumns() const;
606 bool hasCompositingDescendant() const { return m_compositingProperties.hasCompositingDescendant; }
607 void setHasCompositingDescendant(bool b) { m_compositingProperties.hasCompositingDescendant = b; }
609 bool hasNonCompositedChild() const { return m_compositingProperties.hasNonCompositedChild; }
610 void setHasNonCompositedChild(bool b) { m_compositingProperties.hasNonCompositedChild = b; }
612 bool shouldIsolateCompositedDescendants() const { return m_compositingProperties.shouldIsolateCompositedDescendants; }
613 void setShouldIsolateCompositedDescendants(bool b) { m_compositingProperties.shouldIsolateCompositedDescendants = b; }
615 bool lostGroupedMapping() const { return m_compositingProperties.lostGroupedMapping; }
616 void setLostGroupedMapping(bool b) { m_compositingProperties.lostGroupedMapping = b; }
618 void setCompositingReasons(CompositingReasons reasons) { m_compositingProperties.compositingReasons = reasons; }
619 CompositingReasons compositingReasons() const { return m_compositingProperties.compositingReasons; }
621 friend class CompositedLayerMapping;
622 friend class RenderLayerCompositor;
623 friend class RenderLayerModelObject;
626 LayerType m_layerType;
628 // Self-painting layer is an optimization where we avoid the heavy RenderLayer painting
629 // machinery for a RenderLayer allocated only to handle the overflow clip case.
630 // FIXME(crbug.com/332791): Self-painting layer should be merged into the overflow-only concept.
631 unsigned m_isSelfPaintingLayer : 1;
633 // If have no self-painting descendants, we don't have to walk our children during painting. This can lead to
634 // significant savings, especially if the tree has lots of non-self-painting layers grouped together (e.g. table cells).
635 unsigned m_hasSelfPaintingLayerDescendant : 1;
636 unsigned m_hasSelfPaintingLayerDescendantDirty : 1;
638 unsigned m_hasOutOfFlowPositionedDescendant : 1;
639 unsigned m_hasOutOfFlowPositionedDescendantDirty : 1;
641 // This is true if we have an out-of-flow positioned descendant whose
642 // containing block is our ancestor. If this is the case, the descendant
643 // may fall outside of our clip preventing things like opting into
644 // composited scrolling (which causes clipping of all descendants).
645 unsigned m_hasUnclippedDescendant : 1;
647 unsigned m_isUnclippedDescendant : 1;
649 const unsigned m_isRootLayer : 1;
651 unsigned m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether
652 // we ended up painting this layer or any descendants (and therefore need to
655 unsigned m_visibleContentStatusDirty : 1;
656 unsigned m_hasVisibleContent : 1;
657 unsigned m_visibleDescendantStatusDirty : 1;
658 unsigned m_hasVisibleDescendant : 1;
660 unsigned m_hasVisibleNonLayerContent : 1;
662 unsigned m_isPaginated : 1; // If we think this layer is split by a multi-column ancestor, then this bit will be set.
664 unsigned m_3DTransformedDescendantStatusDirty : 1;
665 // Set on a stacking context layer that has 3D descendants anywhere
666 // in a preserves3D hierarchy. Hint to do 3D-aware hit testing.
667 unsigned m_has3DTransformedDescendant : 1;
669 unsigned m_containsDirtyOverlayScrollbars : 1;
671 // This is an optimization added for <table>.
672 // Currently cells do not need to update their repaint rectangles when scrolling. This also
673 // saves a lot of time when scrolling on a table.
674 const unsigned m_canSkipRepaintRectsUpdateOnScroll : 1;
676 unsigned m_hasFilterInfo : 1;
678 RenderLayerModelObject* m_renderer;
680 RenderLayer* m_parent;
681 RenderLayer* m_previous;
683 RenderLayer* m_first;
686 // Our current relative position offset.
687 LayoutSize m_offsetForInFlowPosition;
689 // Our (x,y) coordinates are in our parent layer's coordinate space.
690 LayoutPoint m_topLeft;
692 // The layer's width/height
695 // Cached normal flow values for absolute positioned elements with static left/top values.
696 LayoutUnit m_staticInlinePosition;
697 LayoutUnit m_staticBlockPosition;
699 OwnPtr<TransformationMatrix> m_transform;
701 // Pointer to the enclosing RenderLayer that caused us to be paginated. It is 0 if we are not paginated.
702 RenderLayer* m_enclosingPaginationLayer;
704 // Pointer to the enclosing RenderLayer that establishes the 3d rendering context in which this layer participates.
705 // If it 0, it does not participate in a 3d rendering context.
706 RenderLayer* m_3dRenderingContextRoot;
708 // Properties that are computed while updating compositing layers. These values may be dirty/invalid if
709 // compositing status is not up-to-date before using them.
710 struct CompositingProperties {
711 CompositingProperties()
712 : hasCompositingDescendant(false)
713 , hasNonCompositedChild(false)
714 , shouldIsolateCompositedDescendants(false)
715 , lostGroupedMapping(false)
716 , viewportConstrainedNotCompositedReason(NoNotCompositedReason)
717 , compositingReasons(CompositingReasonNone)
720 // Used only while determining what layers should be composited. Applies to the tree of z-order lists.
721 bool hasCompositingDescendant : 1;
723 // Applies to the real render layer tree (i.e., the tree determined by the layer's parent and children and
724 // as opposed to the tree formed by the z-order and normal flow lists).
725 bool hasNonCompositedChild : 1;
727 // Should be for stacking contexts having unisolated blending descendants.
728 bool shouldIsolateCompositedDescendants : 1;
730 // True if this render layer just lost its grouped mapping due to the CompositedLayerMapping being destroyed,
731 // and we don't yet know to what graphics layer this RenderLayer will be assigned.
732 bool lostGroupedMapping : 1;
734 // The reason, if any exists, that a fixed-position layer is chosen not to be composited.
735 unsigned viewportConstrainedNotCompositedReason : 2;
737 // Once computed, indicates all that a layer needs to become composited using the CompositingReasons enum bitfield.
738 CompositingReasons compositingReasons;
740 // Used for invalidating this layer's contents on the squashing GraphicsLayer.
741 IntSize offsetFromSquashingLayerOrigin;
744 CompositingProperties m_compositingProperties;
747 IntRect m_blockSelectionGapsBounds;
749 OwnPtr<CompositedLayerMapping> m_compositedLayerMapping;
750 OwnPtr<RenderLayerScrollableArea> m_scrollableArea;
752 CompositedLayerMapping* m_groupedMapping;
754 RenderLayerRepainter m_repainter;
755 RenderLayerClipper m_clipper; // FIXME: Lazily allocate?
756 OwnPtr<RenderLayerStackingNode> m_stackingNode;
757 OwnPtr<RenderLayerReflectionInfo> m_reflectionInfo;
758 RenderLayerBlendInfo m_blendInfo;
761 } // namespace WebCore
764 // Outside the WebCore namespace for ease of invocation from gdb.
765 void showLayerTree(const WebCore::RenderLayer*);
766 void showLayerTree(const WebCore::RenderObject*);
769 #endif // RenderLayer_h