Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / compositing / CompositingLayerAssigner.h
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 #ifndef CompositingLayerAssigner_h
28 #define CompositingLayerAssigner_h
29
30 #include "core/rendering/compositing/RenderLayerCompositor.h"
31 #include "platform/geometry/IntRect.h"
32 #include "platform/geometry/LayoutPoint.h"
33
34 namespace WebCore {
35
36 class RenderLayer;
37
38 class CompositingLayerAssigner {
39 public:
40     explicit CompositingLayerAssigner(RenderLayerCompositor*);
41     ~CompositingLayerAssigner();
42
43     void assign(RenderLayer* updateRoot, bool& layersChanged);
44
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*);
48
49 private:
50     struct SquashingState {
51         SquashingState()
52             : mostRecentMapping(0)
53             , hasMostRecentMapping(false)
54             , nextSquashedLayerIndex(0)
55             , totalAreaOfSquashedRects(0) { }
56
57         void updateSquashingStateForNewMapping(CompositedLayerMappingPtr, bool hasNewCompositedLayerMapping, LayoutPoint newOffsetFromTransformedAncestorForSquashingCLM);
58
59         // The most recent composited backing that the layer should squash onto if needed.
60         CompositedLayerMappingPtr mostRecentMapping;
61         bool hasMostRecentMapping;
62
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;
66
67         // Counter that tracks what index the next RenderLayer would be if it gets squashed to the current squashing layer.
68         size_t nextSquashedLayerIndex;
69
70         // The absolute bounding rect of all the squashed layers.
71         IntRect boundingRect;
72
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;
76     };
77
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;
84
85     RenderLayerCompositor* m_compositor;
86     bool m_layerSquashingEnabled;
87 };
88
89 } // namespace WebCore
90
91 #endif // CompositingLayerAssigner_h