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/compositing/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;
102 WTF_MAKE_NONCOPYABLE(RenderLayer);
104 RenderLayer(RenderLayerModelObject*, LayerType);
107 String debugName() const;
109 RenderLayerModelObject* renderer() const { return m_renderer; }
110 RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; }
111 RenderLayer* parent() const { return m_parent; }
112 RenderLayer* previousSibling() const { return m_previous; }
113 RenderLayer* nextSibling() const { return m_next; }
114 RenderLayer* firstChild() const { return m_first; }
115 RenderLayer* lastChild() const { return m_last; }
117 const RenderLayer* compositingContainer() const;
119 void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0);
120 RenderLayer* removeChild(RenderLayer*);
122 void removeOnlyThisLayer();
123 void insertOnlyThisLayer();
125 void styleChanged(StyleDifference, const RenderStyle* oldStyle);
127 bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; }
129 void setLayerType(LayerType layerType) { m_layerType = layerType; }
131 bool cannotBlitToWindow() const;
133 bool isTransparent() const;
134 RenderLayer* transparentPaintingAncestor();
135 void beginTransparencyLayers(GraphicsContext*, const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, const LayoutSize& subPixelAccumulation, PaintBehavior);
137 bool isReflection() const { return renderer()->isReplica(); }
138 RenderLayerReflectionInfo* reflectionInfo() { return m_reflectionInfo.get(); }
139 const RenderLayerReflectionInfo* reflectionInfo() const { return m_reflectionInfo.get(); }
141 const RenderLayer* root() const
143 const RenderLayer* curr = this;
144 while (curr->parent())
145 curr = curr->parent();
149 const LayoutPoint& location() const { return m_topLeft; }
150 void setLocation(const LayoutPoint& p) { m_topLeft = p; }
152 const IntSize& size() const { return m_layerSize; }
153 void setSize(const IntSize& size) { m_layerSize = size; }
155 LayoutRect rect() const { return LayoutRect(location(), size()); }
157 bool isRootLayer() const { return m_isRootLayer; }
159 RenderLayerCompositor* compositor() const;
161 // Notification from the renderer that its content changed (e.g. current frame of image changed).
162 // Allows updates of layer content without repainting.
163 void contentChanged(ContentChangeType);
165 enum UpdateLayerPositionsFlag {
166 CheckForRepaint = 1 << 0,
167 NeedsFullRepaintInBacking = 1 << 1,
168 UpdatePagination = 1 << 2,
170 typedef unsigned UpdateLayerPositionsFlags;
172 void updateLayerPositionsAfterLayout(const RenderLayer* rootLayer, UpdateLayerPositionsFlags);
173 void updateLayerPositionsAfterOverflowScroll();
174 void updateLayerPositionsAfterDocumentScroll();
176 // FIXME: Should updateLayerPositions be private?
177 void updateLayerPositions(RenderGeometryMap*, UpdateLayerPositionsFlags = CheckForRepaint);
179 bool isPaginated() const { return m_isPaginated; }
180 RenderLayer* enclosingPaginationLayer() const { return m_enclosingPaginationLayer; }
182 void updateTransform();
183 RenderLayer* renderingContextRoot();
185 const LayoutSize& offsetForInFlowPosition() const { return m_offsetForInFlowPosition; }
187 void addBlockSelectionGapsBounds(const LayoutRect&);
188 void clearBlockSelectionGapsBounds();
189 void repaintBlockSelectionGaps();
190 bool hasBlockSelectionGapBounds() const;
192 RenderLayerStackingNode* stackingNode() { return m_stackingNode.get(); }
193 const RenderLayerStackingNode* stackingNode() const { return m_stackingNode.get(); }
195 bool subtreeIsInvisible() const { return !hasVisibleContent() && !hasVisibleDescendant(); }
197 // FIXME: We should ASSERT(!m_visibleContentStatusDirty) here, but see https://bugs.webkit.org/show_bug.cgi?id=71044
198 // ditto for hasVisibleDescendant(), see https://bugs.webkit.org/show_bug.cgi?id=71277
199 bool hasVisibleContent() const { return m_hasVisibleContent; }
200 bool hasVisibleDescendant() const { return m_hasVisibleDescendant; }
202 void setHasVisibleContent();
203 void dirtyVisibleContentStatus();
205 bool hasBoxDecorationsOrBackground() const;
206 bool hasVisibleBoxDecorations() const;
207 // Returns true if this layer has visible content (ignoring any child layers).
208 bool isVisuallyNonEmpty() const;
209 // True if this layer container renderers that paint.
210 bool hasNonEmptyChildRenderers() const;
212 // FIXME: We should ASSERT(!m_hasSelfPaintingLayerDescendantDirty); here but we hit the same bugs as visible content above.
213 // Part of the issue is with subtree relayout: we don't check if our ancestors have some descendant flags dirty, missing some updates.
214 bool hasSelfPaintingLayerDescendant() const { return m_hasSelfPaintingLayerDescendant; }
216 // FIXME: We should ASSERT(!m_hasOutOfFlowPositionedDescendantDirty) here. See above.
217 bool hasOutOfFlowPositionedDescendant() const { return m_hasOutOfFlowPositionedDescendant; }
219 void setHasOutOfFlowPositionedDescendant(bool hasDescendant) { m_hasOutOfFlowPositionedDescendant = hasDescendant; }
220 void setHasOutOfFlowPositionedDescendantDirty(bool dirty) { m_hasOutOfFlowPositionedDescendantDirty = dirty; }
223 bool hasUnclippedDescendant() const { return m_hasUnclippedDescendant; }
224 void setHasUnclippedDescendant(bool hasDescendant) { m_hasUnclippedDescendant = hasDescendant; }
225 void updateHasUnclippedDescendant();
226 bool isUnclippedDescendant() const { return m_isUnclippedDescendant; }
228 // Will ensure that hasUnclippedDescendant and hasNonCompositiedChild are up to date.
229 void updateScrollingStateAfterCompositingChange();
230 bool hasVisibleNonLayerContent() const { return m_hasVisibleNonLayerContent; }
231 bool hasNonCompositedChild() const { ASSERT(isAllowedToQueryCompositingState()); return m_hasNonCompositedChild; }
233 bool usedTransparency() const { return m_usedTransparency; }
235 // Gets the nearest enclosing positioned ancestor layer (also includes
236 // the <html> layer and the root layer).
237 RenderLayer* enclosingPositionedAncestor() const;
239 RenderLayer* enclosingOverflowClipLayer(IncludeSelfOrNot = IncludeSelf) const;
241 // Enclosing compositing layer; if includeSelf is true, may return this.
242 RenderLayer* enclosingCompositingLayer(IncludeSelfOrNot = IncludeSelf) const;
243 RenderLayer* enclosingCompositingLayerForRepaint(IncludeSelfOrNot = IncludeSelf) const;
244 // Ancestor compositing layer, excluding this.
245 RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(ExcludeSelf); }
247 // Ancestor composited scrolling layer at or above our containing block.
248 RenderLayer* ancestorCompositedScrollingLayer() const;
250 // Ancestor scrolling layer at or above our containing block.
251 RenderLayer* ancestorScrollingLayer() const;
253 RenderLayer* enclosingFilterLayer(IncludeSelfOrNot = IncludeSelf) const;
254 bool hasAncestorWithFilterOutsets() const;
256 bool canUseConvertToLayerCoords() const
258 // These RenderObjects have an impact on their layers without the renderers knowing about it.
259 return !renderer()->hasColumns() && !renderer()->hasTransform() && !renderer()->isSVGRoot();
262 void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const;
263 void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect&) const;
265 // The two main functions that use the layer system. The paint method
266 // paints the layers that intersect the damage rect from back to
267 // front. The hitTest method looks for mouse events by walking
268 // layers that intersect the point from front to back.
269 // paint() assumes that the caller will clip to the bounds of damageRect if necessary.
270 void paint(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior = PaintBehaviorNormal, RenderObject* paintingRoot = 0, PaintLayerFlags = 0);
271 bool hitTest(const HitTestRequest&, HitTestResult&);
272 bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
273 void paintOverlayScrollbars(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior, RenderObject* paintingRoot = 0);
275 // Pass offsetFromRoot if known.
276 bool intersectsDamageRect(const LayoutRect& layerBounds, const LayoutRect& damageRect, const RenderLayer* rootLayer, const LayoutPoint* offsetFromRoot = 0) const;
278 // Bounding box relative to some ancestor layer. Pass offsetFromRoot if known.
279 LayoutRect physicalBoundingBox(const RenderLayer* ancestorLayer, const LayoutPoint* offsetFromRoot = 0) const;
280 LayoutRect physicalBoundingBoxIncludingReflectionAndStackingChildren(const RenderLayer* ancestorLayer, const LayoutPoint& offsetFromRoot) const;
282 // FIXME: This function is inconsistent as to whether the returned rect has been flipped for writing mode.
283 LayoutRect boundingBoxForCompositingOverlapTest() const { return overlapBoundsIncludeChildren() ? boundingBoxForCompositing() : logicalBoundingBox(); }
285 // If true, this layer's children are included in its bounds for overlap testing.
286 // We can't rely on the children's positions if this layer has a filter that could have moved the children's pixels around.
287 bool overlapBoundsIncludeChildren() const { return hasFilter() && renderer()->style()->filter().hasFilterThatMovesPixels(); }
289 enum CalculateBoundsOptions {
290 ApplyBoundsChickenEggHacks,
291 DoNotApplyBoundsChickenEggHacks,
293 LayoutRect boundingBoxForCompositing(const RenderLayer* ancestorLayer = 0, CalculateBoundsOptions = DoNotApplyBoundsChickenEggHacks) const;
295 LayoutUnit staticInlinePosition() const { return m_staticInlinePosition; }
296 LayoutUnit staticBlockPosition() const { return m_staticBlockPosition; }
298 void setStaticInlinePosition(LayoutUnit position) { m_staticInlinePosition = position; }
299 void setStaticBlockPosition(LayoutUnit position) { m_staticBlockPosition = position; }
301 LayoutSize subpixelAccumulation() const;
302 void setSubpixelAccumulation(const LayoutSize&);
304 bool hasTransform() const { return renderer()->hasTransform(); }
305 // Note that this transform has the transform-origin baked in.
306 TransformationMatrix* transform() const { return m_transform.get(); }
307 // currentTransform computes a transform which takes accelerated animations into account. The
308 // resulting transform has transform-origin baked in. If the layer does not have a transform,
309 // returns the identity matrix.
310 TransformationMatrix currentTransform(RenderStyle::ApplyTransformOrigin = RenderStyle::IncludeTransformOrigin) const;
311 TransformationMatrix renderableTransform(PaintBehavior) const;
313 // Get the perspective transform, which is applied to transformed sublayers.
314 // Returns true if the layer has a -webkit-perspective.
315 // Note that this transform has the perspective-origin baked in.
316 TransformationMatrix perspectiveTransform() const;
317 FloatPoint perspectiveOrigin() const;
318 bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
319 bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
321 // FIXME: reflections should force transform-style to be flat in the style: https://bugs.webkit.org/show_bug.cgi?id=106959
322 bool shouldPreserve3D() const { return !renderer()->hasReflection() && renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
324 void filterNeedsRepaint();
325 bool hasFilter() const { return renderer()->hasFilter(); }
327 bool paintsWithBlendMode() const;
329 void* operator new(size_t);
330 // Only safe to call from RenderLayerModelObject::destroyLayer()
331 void operator delete(void*);
333 CompositingState compositingState() const;
335 // This returns true if our document is in a phase of its lifestyle during which
336 // compositing state may legally be read.
337 bool isAllowedToQueryCompositingState() const;
339 CompositedLayerMappingPtr compositedLayerMapping() const;
340 CompositedLayerMappingPtr ensureCompositedLayerMapping();
342 // NOTE: If you are using hasCompositedLayerMapping to determine the state of compositing for this layer,
343 // (and not just to do bookkeeping related to the mapping like, say, allocating or deallocating a mapping),
344 // then you may have incorrect logic. Use compositingState() instead.
345 bool hasCompositedLayerMapping() const { return m_compositedLayerMapping.get(); }
346 void clearCompositedLayerMapping(bool layerBeingDestroyed = false);
348 CompositedLayerMapping* groupedMapping() const { return m_groupedMapping; }
349 void setGroupedMapping(CompositedLayerMapping* groupedMapping, bool layerBeingDestroyed = false);
351 bool hasCompositedMask() const;
352 bool hasCompositedClippingMask() const;
353 bool needsCompositedScrolling() const { return m_scrollableArea && m_scrollableArea->needsCompositedScrolling(); }
355 bool clipsCompositingDescendantsWithBorderRadius() const;
357 RenderLayer* scrollParent() const;
358 RenderLayer* clipParent() const;
360 bool needsCompositingLayersRebuiltForClip(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
361 bool needsCompositingLayersRebuiltForOverflow(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
362 bool needsCompositingLayersRebuiltForFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
363 bool needsCompositingLayersRebuiltForBlending(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
365 bool paintsWithTransparency(PaintBehavior paintBehavior) const
367 return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || compositingState() != PaintsIntoOwnBacking);
370 bool paintsWithTransform(PaintBehavior) const;
372 // Returns true if background phase is painted opaque in the given rect.
373 // The query rect is given in local coordinates.
374 bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
376 bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; }
377 void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; }
379 FilterOperations computeFilterOperations(const RenderStyle*);
380 bool paintsWithFilters() const;
381 bool requiresFullLayerImageForFilters() const;
382 FilterEffectRenderer* filterRenderer() const
384 RenderLayerFilterInfo* filterInfo = this->filterInfo();
385 return filterInfo ? filterInfo->renderer() : 0;
388 RenderLayerFilterInfo* filterInfo() const { return hasFilterInfo() ? RenderLayerFilterInfo::filterInfoForRenderLayer(this) : 0; }
389 RenderLayerFilterInfo* ensureFilterInfo() { return RenderLayerFilterInfo::createFilterInfoForRenderLayerIfNeeded(this); }
390 void removeFilterInfoIfNeeded()
393 RenderLayerFilterInfo::removeFilterInfoForRenderLayer(this);
396 bool hasFilterInfo() const { return m_hasFilterInfo; }
397 void setHasFilterInfo(bool hasFilterInfo) { m_hasFilterInfo = hasFilterInfo; }
399 void updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle);
401 Node* enclosingElement() const;
403 bool isInTopLayer() const;
405 enum ViewportConstrainedNotCompositedReason {
406 NoNotCompositedReason = 0,
407 NotCompositedForBoundsOutOfView,
408 NotCompositedForNonViewContainer,
409 NotCompositedForNoVisibleContent,
410 NotCompositedForUnscrollableAncestors,
411 NumNotCompositedReasons,
413 // This is the number of bits used to store the viewport constrained not composited
414 // reasons. We define this constant since sizeof won't return the number of bits, and we
415 // shouldn't duplicate the constant.
416 ViewportConstrainedNotCompositedReasonBits = 3
419 void setViewportConstrainedNotCompositedReason(ViewportConstrainedNotCompositedReason reason) { m_viewportConstrainedNotCompositedReason = reason; }
420 ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason() const { ASSERT(isAllowedToQueryCompositingState()); return static_cast<ViewportConstrainedNotCompositedReason>(m_viewportConstrainedNotCompositedReason); }
422 bool isOutOfFlowRenderFlowThread() const { return renderer()->isOutOfFlowRenderFlowThread(); }
424 bool scrollsWithRespectTo(const RenderLayer*) const;
426 void addLayerHitTestRects(LayerHitTestRects&) const;
428 // Compute rects only for this layer
429 void computeSelfHitTestRects(LayerHitTestRects&) const;
431 // FIXME: This should probably return a ScrollableArea but a lot of internal methods are mistakenly exposed.
432 RenderLayerScrollableArea* scrollableArea() const { return m_scrollableArea.get(); }
433 RenderLayerRepainter& repainter() { return m_repainter; }
434 RenderLayerClipper& clipper() { return m_clipper; }
435 const RenderLayerClipper& clipper() const { return m_clipper; }
437 inline bool isPositionedContainer() const
439 // FIXME: This is not in sync with containingBlock.
440 // RenderObject::canContainFixedPositionedObject() should probably be used
442 RenderLayerModelObject* layerRenderer = renderer();
443 return isRootLayer() || layerRenderer->isPositioned() || hasTransform();
446 // paintLayer() assumes that the caller will clip to the bounds of the painting dirty if necessary.
447 void paintLayer(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
449 PassOwnPtr<Vector<FloatRect> > collectTrackedRepaintRects() const;
451 RenderLayerBlendInfo& blendInfo() { return m_blendInfo; }
453 void setOffsetFromSquashingLayerOrigin(IntSize offset) { m_offsetFromSquashingLayerOrigin = offset; }
454 IntSize offsetFromSquashingLayerOrigin() const { ASSERT(isAllowedToQueryCompositingState()); return m_offsetFromSquashingLayerOrigin; }
456 bool scrollsOverflow() const;
458 bool hasDirectReasonsForCompositing() const { return compositingReasons() & CompositingReasonComboAllDirectReasons; }
460 CompositingReasons styleDeterminedCompositingReasons() const { return m_styleDeterminedCompositingReasons; }
461 void setStyleDeterminedCompositingReasons(CompositingReasons reasons) { ASSERT(reasons == (reasons & CompositingReasonComboAllStyleDeterminedReasons)); m_styleDeterminedCompositingReasons = reasons; }
463 class AncestorDependentProperties {
465 AncestorDependentProperties()
467 , transformAncestor(0)
471 IntRect clippedAbsoluteBoundingBox;
472 const RenderLayer* opacityAncestor;
473 const RenderLayer* transformAncestor;
474 const RenderLayer* filterAncestor;
477 void setNeedsToUpdateAncestorDependentProperties();
478 bool childNeedsToUpdateAncestorDependantProperties() const { return m_childNeedsToUpdateAncestorDependantProperties; }
479 bool needsToUpdateAncestorDependentProperties() const { return m_needsToUpdateAncestorDependentProperties; }
481 void updateAncestorDependentProperties(const AncestorDependentProperties&);
482 void clearChildNeedsToUpdateAncestorDependantProperties();
484 const AncestorDependentProperties& ancestorDependentProperties() const { ASSERT(!m_needsToUpdateAncestorDependentProperties); return m_ancestorDependentProperties; }
486 bool lostGroupedMapping() const { ASSERT(isAllowedToQueryCompositingState()); return m_lostGroupedMapping; }
487 void setLostGroupedMapping(bool b) { m_lostGroupedMapping = b; }
489 CompositingReasons compositingReasons() const { ASSERT(isAllowedToQueryCompositingState()); return m_compositingReasons; }
490 void setCompositingReasons(CompositingReasons, CompositingReasons mask = CompositingReasonAll);
492 bool hasCompositingDescendant() const { ASSERT(isAllowedToQueryCompositingState()); return m_hasCompositingDescendant; }
493 void setHasCompositingDescendant(bool b) { m_hasCompositingDescendant = b; }
495 bool shouldIsolateCompositedDescendants() const { ASSERT(isAllowedToQueryCompositingState()); return m_shouldIsolateCompositedDescendants; }
496 void setShouldIsolateCompositedDescendants(bool b) { m_shouldIsolateCompositedDescendants = b; }
498 void updateDescendantDependentFlags();
500 void updateOrRemoveFilterEffectRenderer();
502 void updateSelfPaintingLayer();
504 // paintLayerContents() assumes that the caller will clip to the bounds of the painting dirty rect if necessary.
505 void paintLayerContents(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
507 RenderLayer* enclosingTransformedAncestor() const;
508 LayoutPoint computeOffsetFromTransformedAncestor() const;
510 void didUpdateNeedsCompositedScrolling();
513 // Bounding box in the coordinates of this layer.
514 LayoutRect logicalBoundingBox() const;
516 bool hasOverflowControls() const;
518 void setIsUnclippedDescendant(bool isUnclippedDescendant) { m_isUnclippedDescendant = isUnclippedDescendant; }
520 void setAncestorChainHasSelfPaintingLayerDescendant();
521 void dirtyAncestorChainHasSelfPaintingLayerDescendantStatus();
523 void setAncestorChainHasOutOfFlowPositionedDescendant();
524 void dirtyAncestorChainHasOutOfFlowPositionedDescendantStatus();
526 void clipToRect(const LayerPaintingInfo&, GraphicsContext*, const ClipRect&, BorderRadiusClippingRule = IncludeSelfForBorderRadius);
527 void restoreClip(GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&);
529 void updateOutOfFlowPositioned(const RenderStyle* oldStyle);
531 // Returns true if the position changed.
532 bool updateLayerPosition();
534 enum UpdateLayerPositionsAfterScrollFlag {
536 IsOverflowScroll = 1 << 0,
537 HasSeenViewportConstrainedAncestor = 1 << 1,
538 HasSeenAncestorWithOverflowClip = 1 << 2,
539 HasChangedAncestor = 1 << 3
541 typedef unsigned UpdateLayerPositionsAfterScrollFlags;
542 void updateLayerPositionsAfterScroll(RenderGeometryMap*, UpdateLayerPositionsAfterScrollFlags = NoFlag);
544 void setNextSibling(RenderLayer* next) { m_next = next; }
545 void setPreviousSibling(RenderLayer* prev) { m_previous = prev; }
546 void setFirstChild(RenderLayer* first) { m_first = first; }
547 void setLastChild(RenderLayer* last) { m_last = last; }
549 LayoutPoint renderBoxLocation() const { return renderer()->isBox() ? toRenderBox(renderer())->location() : LayoutPoint(); }
551 void paintLayerContentsAndReflection(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
552 void paintLayerByApplyingTransform(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const LayoutPoint& translationOffset = LayoutPoint());
553 void paintChildren(unsigned childrenToVisit, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
554 void paintPaginatedChildLayer(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
555 void paintChildLayerIntoColumns(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
557 void collectFragments(LayerFragments&, const RenderLayer* rootLayer, const LayoutRect& dirtyRect,
558 ClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize,
559 ShouldRespectOverflowClip = RespectOverflowClip, const LayoutPoint* offsetFromRoot = 0,
560 const LayoutSize& subPixelAccumulation = LayoutSize(), const LayoutRect* layerBoundingBox = 0);
561 void updatePaintingInfoForFragments(LayerFragments&, const LayerPaintingInfo&, PaintLayerFlags, bool shouldPaintContent, const LayoutPoint* offsetFromRoot);
562 void paintBackgroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
563 const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
564 void paintForegroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
565 const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer,
566 bool selectionOnly, bool forceBlackText);
567 void paintForegroundForFragmentsWithPhase(PaintPhase, const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
568 void paintOutlineForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
569 void paintOverflowControlsForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&);
570 void paintMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
571 void paintChildClippingMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
572 void paintTransformedLayerIntoFragments(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
574 RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result,
575 const LayoutRect& hitTestRect, const HitTestLocation&, bool appliedTransform,
576 const HitTestingTransformState* transformState = 0, double* zOffset = 0);
577 RenderLayer* hitTestLayerByApplyingTransform(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
578 const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0,
579 const LayoutPoint& translationOffset = LayoutPoint());
580 RenderLayer* hitTestChildren(ChildrenIteration, RenderLayer* rootLayer, const HitTestRequest&, HitTestResult&,
581 const LayoutRect& hitTestRect, const HitTestLocation&,
582 const HitTestingTransformState* transformState, double* zOffsetForDescendants, double* zOffset,
583 const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants);
584 RenderLayer* hitTestPaginatedChildLayer(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
585 const LayoutRect& hitTestRect, const HitTestLocation&,
586 const HitTestingTransformState* transformState, double* zOffset);
587 RenderLayer* hitTestChildLayerColumns(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
588 const LayoutRect& hitTestRect, const HitTestLocation&,
589 const HitTestingTransformState* transformState, double* zOffset,
590 const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
592 PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer,
593 const LayoutRect& hitTestRect, const HitTestLocation&,
594 const HitTestingTransformState* containerTransformState,
595 const LayoutPoint& translationOffset = LayoutPoint()) const;
597 bool hitTestContents(const HitTestRequest&, HitTestResult&, const LayoutRect& layerBounds, const HitTestLocation&, HitTestFilter) const;
598 bool hitTestContentsForFragments(const LayerFragments&, const HitTestRequest&, HitTestResult&, const HitTestLocation&, HitTestFilter, bool& insideClipRect) const;
599 RenderLayer* hitTestTransformedLayerInFragments(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
600 const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0);
602 bool childBackgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
604 bool shouldBeSelfPaintingLayer() const;
606 // FIXME: We should only create the stacking node if needed.
607 bool requiresStackingNode() const { return true; }
608 void updateStackingNode();
610 void updateReflectionInfo(const RenderStyle*);
612 // FIXME: We could lazily allocate our ScrollableArea based on style properties ('overflow', ...)
613 // but for now, we are always allocating it for RenderBox as it's safer.
614 bool requiresScrollableArea() const { return renderBox(); }
615 void updateScrollableArea();
617 void dirtyAncestorChainVisibleDescendantStatus();
618 void setAncestorChainHasVisibleDescendant();
620 void dirty3DTransformedDescendantStatus();
621 // Both updates the status, and returns true if descendants of this have 3d.
622 bool update3DTransformedDescendantStatus();
624 void updateOrRemoveFilterClients();
626 LayoutRect paintingExtent(const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, const LayoutSize& subPixelAccumulation, PaintBehavior);
628 void updatePagination();
630 // FIXME: Temporary. Remove when new columns come online.
631 bool useRegionBasedColumns() const;
633 LayerType m_layerType;
635 // Self-painting layer is an optimization where we avoid the heavy RenderLayer painting
636 // machinery for a RenderLayer allocated only to handle the overflow clip case.
637 // FIXME(crbug.com/332791): Self-painting layer should be merged into the overflow-only concept.
638 unsigned m_isSelfPaintingLayer : 1;
640 // If have no self-painting descendants, we don't have to walk our children during painting. This can lead to
641 // significant savings, especially if the tree has lots of non-self-painting layers grouped together (e.g. table cells).
642 unsigned m_hasSelfPaintingLayerDescendant : 1;
643 unsigned m_hasSelfPaintingLayerDescendantDirty : 1;
645 unsigned m_hasOutOfFlowPositionedDescendant : 1;
646 unsigned m_hasOutOfFlowPositionedDescendantDirty : 1;
648 // This is true if we have an out-of-flow positioned descendant whose
649 // containing block is our ancestor. If this is the case, the descendant
650 // may fall outside of our clip preventing things like opting into
651 // composited scrolling (which causes clipping of all descendants).
652 unsigned m_hasUnclippedDescendant : 1;
654 unsigned m_isUnclippedDescendant : 1;
656 const unsigned m_isRootLayer : 1;
658 unsigned m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether
659 // we ended up painting this layer or any descendants (and therefore need to
662 unsigned m_visibleContentStatusDirty : 1;
663 unsigned m_hasVisibleContent : 1;
664 unsigned m_visibleDescendantStatusDirty : 1;
665 unsigned m_hasVisibleDescendant : 1;
667 unsigned m_hasVisibleNonLayerContent : 1;
669 unsigned m_isPaginated : 1; // If we think this layer is split by a multi-column ancestor, then this bit will be set.
671 unsigned m_3DTransformedDescendantStatusDirty : 1;
672 // Set on a stacking context layer that has 3D descendants anywhere
673 // in a preserves3D hierarchy. Hint to do 3D-aware hit testing.
674 unsigned m_has3DTransformedDescendant : 1;
676 unsigned m_containsDirtyOverlayScrollbars : 1;
678 // This is an optimization added for <table>.
679 // Currently cells do not need to update their repaint rectangles when scrolling. This also
680 // saves a lot of time when scrolling on a table.
681 const unsigned m_canSkipRepaintRectsUpdateOnScroll : 1;
683 unsigned m_hasFilterInfo : 1;
684 unsigned m_needsToUpdateAncestorDependentProperties : 1;
685 unsigned m_childNeedsToUpdateAncestorDependantProperties : 1;
687 // Used only while determining what layers should be composited. Applies to the tree of z-order lists.
688 unsigned m_hasCompositingDescendant : 1;
690 // Applies to the real render layer tree (i.e., the tree determined by the layer's parent and children and
691 // as opposed to the tree formed by the z-order and normal flow lists).
692 unsigned m_hasNonCompositedChild : 1;
694 // Should be for stacking contexts having unisolated blending descendants.
695 unsigned m_shouldIsolateCompositedDescendants : 1;
697 // True if this render layer just lost its grouped mapping due to the CompositedLayerMapping being destroyed,
698 // and we don't yet know to what graphics layer this RenderLayer will be assigned.
699 unsigned m_lostGroupedMapping : 1;
701 // The reason, if any exists, that a fixed-position layer is chosen not to be composited.
702 unsigned m_viewportConstrainedNotCompositedReason : ViewportConstrainedNotCompositedReasonBits;
704 RenderLayerModelObject* m_renderer;
706 RenderLayer* m_parent;
707 RenderLayer* m_previous;
709 RenderLayer* m_first;
712 // Our current relative position offset.
713 LayoutSize m_offsetForInFlowPosition;
715 // Our (x,y) coordinates are in our parent layer's coordinate space.
716 LayoutPoint m_topLeft;
718 // The layer's width/height
721 // Cached normal flow values for absolute positioned elements with static left/top values.
722 LayoutUnit m_staticInlinePosition;
723 LayoutUnit m_staticBlockPosition;
725 OwnPtr<TransformationMatrix> m_transform;
727 // Pointer to the enclosing RenderLayer that caused us to be paginated. It is 0 if we are not paginated.
728 RenderLayer* m_enclosingPaginationLayer;
730 // These compositing reasons are updated whenever style changes, not while updating compositing layers.
731 // They should not be used to infer the compositing state of this layer.
732 CompositingReasons m_styleDeterminedCompositingReasons;
734 // Once computed, indicates all that a layer needs to become composited using the CompositingReasons enum bitfield.
735 CompositingReasons m_compositingReasons;
737 // Used for invalidating this layer's contents on the squashing GraphicsLayer.
738 IntSize m_offsetFromSquashingLayerOrigin;
740 AncestorDependentProperties m_ancestorDependentProperties;
742 IntRect m_blockSelectionGapsBounds;
744 OwnPtr<CompositedLayerMapping> m_compositedLayerMapping;
745 OwnPtr<RenderLayerScrollableArea> m_scrollableArea;
747 CompositedLayerMapping* m_groupedMapping;
749 RenderLayerRepainter m_repainter;
750 RenderLayerClipper m_clipper; // FIXME: Lazily allocate?
751 OwnPtr<RenderLayerStackingNode> m_stackingNode;
752 OwnPtr<RenderLayerReflectionInfo> m_reflectionInfo;
753 RenderLayerBlendInfo m_blendInfo;
755 LayoutSize m_subpixelAccumulation; // The accumulated subpixel offset of a composited layer's composited bounds compared to absolute coordinates.
758 } // namespace WebCore
761 // Outside the WebCore namespace for ease of invocation from gdb.
762 void showLayerTree(const WebCore::RenderLayer*);
763 void showLayerTree(const WebCore::RenderObject*);
766 #endif // RenderLayer_h