2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2014 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef CompositingLayerAssigner_h
28 #define CompositingLayerAssigner_h
30 #include "core/rendering/compositing/RenderLayerCompositor.h"
31 #include "platform/geometry/IntRect.h"
32 #include "platform/geometry/LayoutPoint.h"
38 class CompositingLayerAssigner {
40 explicit CompositingLayerAssigner(RenderLayerCompositor*);
41 ~CompositingLayerAssigner();
43 void assign(RenderLayer* updateRoot, bool& layersChanged);
45 // FIXME: This function should be private. We should remove the one caller
46 // once we've fixed the compositing chicken/egg issues.
47 CompositingStateTransitionType computeCompositedLayerUpdate(RenderLayer*);
50 struct SquashingState {
52 : mostRecentMapping(0)
53 , hasMostRecentMapping(false)
54 , nextSquashedLayerIndex(0)
55 , totalAreaOfSquashedRects(0) { }
57 void updateSquashingStateForNewMapping(CompositedLayerMappingPtr, bool hasNewCompositedLayerMapping, LayoutPoint newOffsetFromTransformedAncestorForSquashingCLM);
59 // The most recent composited backing that the layer should squash onto if needed.
60 CompositedLayerMappingPtr mostRecentMapping;
61 bool hasMostRecentMapping;
63 // Coordinates of the compositedLayerMapping's owning layer in the space of the transformed ancestor. This is used for computing the correct
64 // positions of renderlayers when they paint into the squashing layer.
65 LayoutPoint offsetFromTransformedAncestorForSquashingCLM;
67 // Counter that tracks what index the next RenderLayer would be if it gets squashed to the current squashing layer.
68 size_t nextSquashedLayerIndex;
70 // The absolute bounding rect of all the squashed layers.
73 // This is simply the sum of the areas of the squashed rects. This can be very skewed if the rects overlap,
74 // but should be close enough to drive a heuristic.
75 uint64_t totalAreaOfSquashedRects;
78 void assignLayersToBackingsInternal(RenderLayer*, SquashingState&, bool& layersChanged);
79 void assignLayersToBackingsForReflectionLayer(RenderLayer* reflectionLayer, bool& layersChanged);
80 bool canSquashIntoCurrentSquashingOwner(const RenderLayer*, const SquashingState&);
81 bool squashingWouldExceedSparsityTolerance(const RenderLayer* candidate, const SquashingState&);
82 bool updateSquashingAssignment(RenderLayer*, SquashingState&, CompositingStateTransitionType);
83 bool needsOwnBacking(const RenderLayer*) const;
85 RenderLayerCompositor* m_compositor;
86 bool m_layerSquashingEnabled;
89 } // namespace WebCore
91 #endif // CompositingLayerAssigner_h