• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
3  * Copyright (C) 2014 Google Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include "config.h"
28 #include "core/rendering/compositing/GraphicsLayerUpdater.h"
29 
30 #include "core/html/HTMLMediaElement.h"
31 #include "core/rendering/RenderLayer.h"
32 #include "core/rendering/RenderLayerReflectionInfo.h"
33 #include "core/rendering/RenderPart.h"
34 #include "core/rendering/compositing/CompositedLayerMapping.h"
35 #include "core/rendering/compositing/RenderLayerCompositor.h"
36 
37 namespace WebCore {
38 
UpdateContext(const UpdateContext & other,const RenderLayer & layer)39 GraphicsLayerUpdater::UpdateContext::UpdateContext(const UpdateContext& other, const RenderLayer& layer)
40     : m_compositingStackingContext(other.m_compositingStackingContext)
41     , m_compositingAncestor(other.compositingContainer(layer))
42 {
43     CompositingState compositingState = layer.compositingState();
44     if (compositingState != NotComposited && compositingState != PaintsIntoGroupedBacking) {
45         m_compositingAncestor = &layer;
46         if (layer.stackingNode()->isStackingContext())
47             m_compositingStackingContext = &layer;
48     }
49 }
50 
compositingContainer(const RenderLayer & layer) const51 const RenderLayer* GraphicsLayerUpdater::UpdateContext::compositingContainer(const RenderLayer& layer) const
52 {
53     return layer.stackingNode()->isNormalFlowOnly() ? m_compositingAncestor : m_compositingStackingContext;
54 }
55 
GraphicsLayerUpdater()56 GraphicsLayerUpdater::GraphicsLayerUpdater()
57     : m_needsRebuildTree(false)
58 {
59 }
60 
~GraphicsLayerUpdater()61 GraphicsLayerUpdater::~GraphicsLayerUpdater()
62 {
63 }
64 
update(Vector<RenderLayer * > & layersNeedingPaintInvalidation,RenderLayer & layer,UpdateType updateType,const UpdateContext & context)65 void GraphicsLayerUpdater::update(Vector<RenderLayer*>& layersNeedingPaintInvalidation, RenderLayer& layer, UpdateType updateType, const UpdateContext& context)
66 {
67     if (layer.hasCompositedLayerMapping()) {
68         CompositedLayerMappingPtr mapping = layer.compositedLayerMapping();
69 
70         const RenderLayer* compositingContainer = context.compositingContainer(layer);
71         ASSERT(compositingContainer == layer.ancestorCompositingLayer());
72         if (mapping->updateRequiresOwnBackingStoreForAncestorReasons(compositingContainer))
73             updateType = ForceUpdate;
74 
75         // Note carefully: here we assume that the compositing state of all descendants have been updated already,
76         // so it is legitimate to compute and cache the composited bounds for this layer.
77         mapping->updateCompositedBounds(updateType);
78 
79         if (RenderLayerReflectionInfo* reflection = layer.reflectionInfo()) {
80             if (reflection->reflectionLayer()->hasCompositedLayerMapping())
81                 reflection->reflectionLayer()->compositedLayerMapping()->updateCompositedBounds(ForceUpdate);
82         }
83 
84         if (mapping->updateGraphicsLayerConfiguration(updateType))
85             m_needsRebuildTree = true;
86 
87         mapping->updateGraphicsLayerGeometry(updateType, compositingContainer, layersNeedingPaintInvalidation);
88 
89         updateType = mapping->updateTypeForChildren(updateType);
90         mapping->clearNeedsGraphicsLayerUpdate();
91 
92         if (!layer.parent())
93             layer.compositor()->updateRootLayerPosition();
94 
95         if (mapping->hasUnpositionedOverflowControlsLayers())
96             layer.scrollableArea()->positionOverflowControls(IntSize());
97     }
98 
99     UpdateContext childContext(context, layer);
100     for (RenderLayer* child = layer.firstChild(); child; child = child->nextSibling())
101         update(layersNeedingPaintInvalidation, *child, updateType, childContext);
102 }
103 
104 #if ASSERT_ENABLED
105 
assertNeedsToUpdateGraphicsLayerBitsCleared(RenderLayer & layer)106 void GraphicsLayerUpdater::assertNeedsToUpdateGraphicsLayerBitsCleared(RenderLayer& layer)
107 {
108     if (layer.hasCompositedLayerMapping())
109         layer.compositedLayerMapping()->assertNeedsToUpdateGraphicsLayerBitsCleared();
110 
111     for (RenderLayer* child = layer.firstChild(); child; child = child->nextSibling())
112         assertNeedsToUpdateGraphicsLayerBitsCleared(*child);
113 }
114 
115 #endif
116 
117 } // namespace WebCore
118