Add WTF::move()
[WebKit-https.git] / Source / WebKit2 / Shared / mac / RemoteLayerTreeTransaction.h
1 /*
2  * Copyright (C) 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef RemoteLayerTreeTransaction_h
27 #define RemoteLayerTreeTransaction_h
28
29 #include "PlatformCAAnimationRemote.h"
30 #include "RemoteLayerBackingStore.h"
31 #include <WebCore/Color.h>
32 #include <WebCore/FilterOperations.h>
33 #include <WebCore/FloatPoint3D.h>
34 #include <WebCore/FloatSize.h>
35 #include <WebCore/PlatformCALayer.h>
36 #include <WebCore/TransformationMatrix.h>
37 #include <wtf/HashMap.h>
38 #include <wtf/HashSet.h>
39 #include <wtf/text/WTFString.h>
40
41 namespace IPC {
42 class ArgumentDecoder;
43 class ArgumentEncoder;
44 }
45
46 namespace WebKit {
47
48 class PlatformCALayerRemote;
49
50 class RemoteLayerTreeTransaction {
51 public:
52     enum LayerChanges {
53         NoChange = 0,
54         NameChanged = 1 << 1,
55         ChildrenChanged = 1 << 2,
56         PositionChanged = 1 << 3,
57         BoundsChanged = 1 << 4,
58         BackgroundColorChanged = 1 << 5,
59         AnchorPointChanged = 1 << 6,
60         BorderWidthChanged = 1 << 7,
61         BorderColorChanged = 1 << 8,
62         OpacityChanged = 1 << 9,
63         TransformChanged = 1 << 10,
64         SublayerTransformChanged = 1 << 11,
65         HiddenChanged = 1 << 12,
66         GeometryFlippedChanged = 1 << 13,
67         DoubleSidedChanged = 1 << 14,
68         MasksToBoundsChanged = 1 << 15,
69         OpaqueChanged = 1 << 16,
70         MaskLayerChanged = 1 << 17,
71         ClonedContentsChanged = 1 << 18,
72         ContentsRectChanged = 1 << 19,
73         ContentsScaleChanged = 1 << 20,
74         MinificationFilterChanged = 1 << 21,
75         MagnificationFilterChanged = 1 << 22,
76         BlendModeChanged = 1 << 23,
77         SpeedChanged = 1 << 24,
78         TimeOffsetChanged = 1 << 25,
79         BackingStoreChanged = 1 << 26,
80         FiltersChanged = 1 << 27,
81         AnimationsChanged = 1 << 28,
82         EdgeAntialiasingMaskChanged = 1 << 29,
83         CustomAppearanceChanged = 1 << 30,
84         CustomBehaviorChanged = 1 << 31
85     };
86     typedef unsigned LayerChange;
87
88     struct LayerCreationProperties {
89         LayerCreationProperties();
90
91         void encode(IPC::ArgumentEncoder&) const;
92         static bool decode(IPC::ArgumentDecoder&, LayerCreationProperties&);
93
94         WebCore::GraphicsLayer::PlatformLayerID layerID;
95         WebCore::PlatformCALayer::LayerType type;
96
97         uint32_t hostingContextID;
98     };
99
100     struct LayerProperties {
101         LayerProperties();
102         LayerProperties(const LayerProperties& other);
103
104         void encode(IPC::ArgumentEncoder&) const;
105         static bool decode(IPC::ArgumentDecoder&, LayerProperties&);
106
107         void notePropertiesChanged(LayerChange changeFlags)
108         {
109             changedProperties |= changeFlags;
110             everChangedProperties |= changeFlags;
111         }
112
113         void resetChangedProperties()
114         {
115             changedProperties = RemoteLayerTreeTransaction::NoChange;
116         }
117
118         LayerChange changedProperties;
119         LayerChange everChangedProperties;
120
121         String name;
122         std::unique_ptr<WebCore::TransformationMatrix> transform;
123         std::unique_ptr<WebCore::TransformationMatrix> sublayerTransform;
124         Vector<WebCore::GraphicsLayer::PlatformLayerID> children;
125
126         Vector<std::pair<String, PlatformCAAnimationRemote::Properties>> addedAnimations;
127         HashSet<String> keyPathsOfAnimationsToRemove;
128
129         WebCore::FloatPoint3D position;
130         WebCore::FloatPoint3D anchorPoint;
131         WebCore::FloatRect bounds;
132         WebCore::FloatRect contentsRect;
133         std::unique_ptr<RemoteLayerBackingStore> backingStore;
134         std::unique_ptr<WebCore::FilterOperations> filters;
135         WebCore::GraphicsLayer::PlatformLayerID maskLayerID;
136         WebCore::GraphicsLayer::PlatformLayerID clonedLayerID;
137         double timeOffset;
138         float speed;
139         float contentsScale;
140         float borderWidth;
141         float opacity;
142         WebCore::Color backgroundColor;
143         WebCore::Color borderColor;
144         unsigned edgeAntialiasingMask;
145         WebCore::GraphicsLayer::CustomAppearance customAppearance;
146         WebCore::GraphicsLayer::CustomBehavior customBehavior;
147         WebCore::PlatformCALayer::FilterType minificationFilter;
148         WebCore::PlatformCALayer::FilterType magnificationFilter;
149         WebCore::BlendMode blendMode;
150         bool hidden;
151         bool geometryFlipped;
152         bool doubleSided;
153         bool masksToBounds;
154         bool opaque;
155     };
156
157     explicit RemoteLayerTreeTransaction();
158     ~RemoteLayerTreeTransaction();
159
160     void encode(IPC::ArgumentEncoder&) const;
161     static bool decode(IPC::ArgumentDecoder&, RemoteLayerTreeTransaction&);
162
163     WebCore::GraphicsLayer::PlatformLayerID rootLayerID() const { return m_rootLayerID; }
164     void setRootLayerID(WebCore::GraphicsLayer::PlatformLayerID);
165     void layerPropertiesChanged(PlatformCALayerRemote&);
166     void setCreatedLayers(Vector<LayerCreationProperties>);
167     void setDestroyedLayerIDs(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
168     void setLayerIDsWithNewlyUnreachableBackingStore(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
169
170 #if !defined(NDEBUG) || !LOG_DISABLED
171     WTF::CString description() const;
172     void dump() const;
173 #endif
174
175     typedef HashMap<WebCore::GraphicsLayer::PlatformLayerID, std::unique_ptr<LayerProperties>> LayerPropertiesMap;
176
177     Vector<LayerCreationProperties> createdLayers() const { return m_createdLayers; }
178     Vector<WebCore::GraphicsLayer::PlatformLayerID> destroyedLayers() const { return m_destroyedLayerIDs; }
179     Vector<WebCore::GraphicsLayer::PlatformLayerID> layerIDsWithNewlyUnreachableBackingStore() const { return m_layerIDsWithNewlyUnreachableBackingStore; }
180
181     Vector<RefPtr<PlatformCALayerRemote>>& changedLayers() { return m_changedLayers; }
182
183     const LayerPropertiesMap& changedLayerProperties() const { return m_changedLayerProperties; }
184     LayerPropertiesMap& changedLayerProperties() { return m_changedLayerProperties; }
185
186     WebCore::IntSize contentsSize() const { return m_contentsSize; }
187     void setContentsSize(const WebCore::IntSize& size) { m_contentsSize = size; };
188     
189     WebCore::Color pageExtendedBackgroundColor() const { return m_pageExtendedBackgroundColor; }
190     void setPageExtendedBackgroundColor(WebCore::Color color) { m_pageExtendedBackgroundColor = color; }
191
192     double pageScaleFactor() const { return m_pageScaleFactor; }
193     void setPageScaleFactor(double pageScaleFactor) { m_pageScaleFactor = pageScaleFactor; }
194
195     bool scaleWasSetByUIProcess() const { return m_scaleWasSetByUIProcess; }
196     void setScaleWasSetByUIProcess(bool scaleWasSetByUIProcess) { m_scaleWasSetByUIProcess = scaleWasSetByUIProcess; }
197     
198     uint64_t renderTreeSize() const { return m_renderTreeSize; }
199     void setRenderTreeSize(uint64_t renderTreeSize) { m_renderTreeSize = renderTreeSize; }
200
201     double minimumScaleFactor() const { return m_minimumScaleFactor; }
202     void setMinimumScaleFactor(double scale) { m_minimumScaleFactor = scale; }
203
204     double maximumScaleFactor() const { return m_maximumScaleFactor; }
205     void setMaximumScaleFactor(double scale) { m_maximumScaleFactor = scale; }
206
207     bool allowsUserScaling() const { return m_allowsUserScaling; }
208     void setAllowsUserScaling(bool allowsUserScaling) { m_allowsUserScaling = allowsUserScaling; }
209
210     uint64_t transactionID() const { return m_transactionID; }
211     void setTransactionID(uint64_t transactionID) { m_transactionID = transactionID; }
212
213     typedef uint64_t TransactionCallbackID;
214     const Vector<TransactionCallbackID>& callbackIDs() const { return m_callbackIDs; }
215     void setCallbackIDs(Vector<TransactionCallbackID> callbackIDs) { m_callbackIDs = WTF::move(callbackIDs); }
216     
217 private:
218     WebCore::GraphicsLayer::PlatformLayerID m_rootLayerID;
219     Vector<RefPtr<PlatformCALayerRemote>> m_changedLayers; // Only used in the Web process.
220     LayerPropertiesMap m_changedLayerProperties; // Only used in the UI process.
221
222     Vector<LayerCreationProperties> m_createdLayers;
223     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_destroyedLayerIDs;
224     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_videoLayerIDsPendingFullscreen;
225     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_layerIDsWithNewlyUnreachableBackingStore;
226
227     Vector<TransactionCallbackID> m_callbackIDs;
228
229     WebCore::IntSize m_contentsSize;
230     WebCore::Color m_pageExtendedBackgroundColor;
231     double m_pageScaleFactor;
232     double m_minimumScaleFactor;
233     double m_maximumScaleFactor;
234     uint64_t m_renderTreeSize;
235     uint64_t m_transactionID;
236     bool m_scaleWasSetByUIProcess;
237     bool m_allowsUserScaling;
238 };
239
240 } // namespace WebKit
241
242 #endif // RemoteLayerTreeTransaction_h