4d02a57d465ee90f302b298d580073b0405c563d
[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                     = 1LLU << 1,
55         ChildrenChanged                 = 1LLU << 2,
56         PositionChanged                 = 1LLU << 3,
57         BoundsChanged                   = 1LLU << 4,
58         BackgroundColorChanged          = 1LLU << 5,
59         AnchorPointChanged              = 1LLU << 6,
60         BorderWidthChanged              = 1LLU << 7,
61         BorderColorChanged              = 1LLU << 8,
62         OpacityChanged                  = 1LLU << 9,
63         TransformChanged                = 1LLU << 10,
64         SublayerTransformChanged        = 1LLU << 11,
65         HiddenChanged                   = 1LLU << 12,
66         GeometryFlippedChanged          = 1LLU << 13,
67         DoubleSidedChanged              = 1LLU << 14,
68         MasksToBoundsChanged            = 1LLU << 15,
69         OpaqueChanged                   = 1LLU << 16,
70         MaskLayerChanged                = 1LLU << 17,
71         ClonedContentsChanged           = 1LLU << 18,
72         ContentsRectChanged             = 1LLU << 19,
73         ContentsScaleChanged            = 1LLU << 20,
74         CornerRadiusChanged             = 1LLU << 21,
75         ShapeRoundedRectChanged         = 1LLU << 22,
76         ShapePathChanged                = 1LLU << 23,
77         MinificationFilterChanged       = 1LLU << 24,
78         MagnificationFilterChanged      = 1LLU << 25,
79         BlendModeChanged                = 1LLU << 26,
80         WindRuleChanged                 = 1LLU << 27,
81         SpeedChanged                    = 1LLU << 28,
82         TimeOffsetChanged               = 1LLU << 29,
83         BackingStoreChanged             = 1LLU << 30,
84         FiltersChanged                  = 1LLU << 31,
85         AnimationsChanged               = 1LLU << 32,
86         EdgeAntialiasingMaskChanged     = 1LLU << 33,
87         CustomAppearanceChanged         = 1LLU << 34
88     };
89     typedef uint64_t LayerChange;
90
91     struct LayerCreationProperties {
92         LayerCreationProperties();
93
94         void encode(IPC::ArgumentEncoder&) const;
95         static bool decode(IPC::ArgumentDecoder&, LayerCreationProperties&);
96
97         WebCore::GraphicsLayer::PlatformLayerID layerID;
98         WebCore::PlatformCALayer::LayerType type;
99
100         uint32_t hostingContextID;
101         float hostingDeviceScaleFactor;
102     };
103
104     struct LayerProperties {
105         LayerProperties();
106         LayerProperties(const LayerProperties& other);
107
108         void encode(IPC::ArgumentEncoder&) const;
109         static bool decode(IPC::ArgumentDecoder&, LayerProperties&);
110
111         void notePropertiesChanged(LayerChange changeFlags)
112         {
113             changedProperties |= changeFlags;
114             everChangedProperties |= changeFlags;
115         }
116
117         void resetChangedProperties()
118         {
119             changedProperties = RemoteLayerTreeTransaction::NoChange;
120         }
121
122         LayerChange changedProperties;
123         LayerChange everChangedProperties;
124
125         String name;
126         std::unique_ptr<WebCore::TransformationMatrix> transform;
127         std::unique_ptr<WebCore::TransformationMatrix> sublayerTransform;
128         std::unique_ptr<WebCore::FloatRoundedRect> shapeRoundedRect;
129
130         Vector<WebCore::GraphicsLayer::PlatformLayerID> children;
131
132         Vector<std::pair<String, PlatformCAAnimationRemote::Properties>> addedAnimations;
133         HashSet<String> keyPathsOfAnimationsToRemove;
134
135         WebCore::FloatPoint3D position;
136         WebCore::FloatPoint3D anchorPoint;
137         WebCore::FloatRect bounds;
138         WebCore::FloatRect contentsRect;
139         std::unique_ptr<RemoteLayerBackingStore> backingStore;
140         std::unique_ptr<WebCore::FilterOperations> filters;
141         WebCore::Path shapePath;
142         WebCore::GraphicsLayer::PlatformLayerID maskLayerID;
143         WebCore::GraphicsLayer::PlatformLayerID clonedLayerID;
144         double timeOffset;
145         float speed;
146         float contentsScale;
147         float cornerRadius;
148         float borderWidth;
149         float opacity;
150         WebCore::Color backgroundColor;
151         WebCore::Color borderColor;
152         unsigned edgeAntialiasingMask;
153         WebCore::GraphicsLayer::CustomAppearance customAppearance;
154         WebCore::PlatformCALayer::FilterType minificationFilter;
155         WebCore::PlatformCALayer::FilterType magnificationFilter;
156         WebCore::BlendMode blendMode;
157         WebCore::WindRule windRule;
158         bool hidden;
159         bool geometryFlipped;
160         bool doubleSided;
161         bool masksToBounds;
162         bool opaque;
163     };
164
165     explicit RemoteLayerTreeTransaction();
166     ~RemoteLayerTreeTransaction();
167
168     void encode(IPC::ArgumentEncoder&) const;
169     static bool decode(IPC::ArgumentDecoder&, RemoteLayerTreeTransaction&);
170
171     WebCore::GraphicsLayer::PlatformLayerID rootLayerID() const { return m_rootLayerID; }
172     void setRootLayerID(WebCore::GraphicsLayer::PlatformLayerID);
173     void layerPropertiesChanged(PlatformCALayerRemote&);
174     void setCreatedLayers(Vector<LayerCreationProperties>);
175     void setDestroyedLayerIDs(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
176     void setLayerIDsWithNewlyUnreachableBackingStore(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
177
178 #if !defined(NDEBUG) || !LOG_DISABLED
179     WTF::CString description() const;
180     void dump() const;
181 #endif
182
183     typedef HashMap<WebCore::GraphicsLayer::PlatformLayerID, std::unique_ptr<LayerProperties>> LayerPropertiesMap;
184
185     Vector<LayerCreationProperties> createdLayers() const { return m_createdLayers; }
186     Vector<WebCore::GraphicsLayer::PlatformLayerID> destroyedLayers() const { return m_destroyedLayerIDs; }
187     Vector<WebCore::GraphicsLayer::PlatformLayerID> layerIDsWithNewlyUnreachableBackingStore() const { return m_layerIDsWithNewlyUnreachableBackingStore; }
188
189     Vector<RefPtr<PlatformCALayerRemote>>& changedLayers() { return m_changedLayers; }
190
191     const LayerPropertiesMap& changedLayerProperties() const { return m_changedLayerProperties; }
192     LayerPropertiesMap& changedLayerProperties() { return m_changedLayerProperties; }
193
194     WebCore::IntSize contentsSize() const { return m_contentsSize; }
195     void setContentsSize(const WebCore::IntSize& size) { m_contentsSize = size; };
196     
197     WebCore::Color pageExtendedBackgroundColor() const { return m_pageExtendedBackgroundColor; }
198     void setPageExtendedBackgroundColor(WebCore::Color color) { m_pageExtendedBackgroundColor = color; }
199
200 #if PLATFORM(MAC)
201     WebCore::IntPoint scrollPosition() const { return m_scrollPosition; }
202     void setScrollPosition(WebCore::IntPoint p) { m_scrollPosition = p; }
203 #endif
204
205     double pageScaleFactor() const { return m_pageScaleFactor; }
206     void setPageScaleFactor(double pageScaleFactor) { m_pageScaleFactor = pageScaleFactor; }
207
208     bool scaleWasSetByUIProcess() const { return m_scaleWasSetByUIProcess; }
209     void setScaleWasSetByUIProcess(bool scaleWasSetByUIProcess) { m_scaleWasSetByUIProcess = scaleWasSetByUIProcess; }
210     
211     uint64_t renderTreeSize() const { return m_renderTreeSize; }
212     void setRenderTreeSize(uint64_t renderTreeSize) { m_renderTreeSize = renderTreeSize; }
213
214     double minimumScaleFactor() const { return m_minimumScaleFactor; }
215     void setMinimumScaleFactor(double scale) { m_minimumScaleFactor = scale; }
216
217     double maximumScaleFactor() const { return m_maximumScaleFactor; }
218     void setMaximumScaleFactor(double scale) { m_maximumScaleFactor = scale; }
219
220     bool allowsUserScaling() const { return m_allowsUserScaling; }
221     void setAllowsUserScaling(bool allowsUserScaling) { m_allowsUserScaling = allowsUserScaling; }
222
223     uint64_t transactionID() const { return m_transactionID; }
224     void setTransactionID(uint64_t transactionID) { m_transactionID = transactionID; }
225
226     typedef uint64_t TransactionCallbackID;
227     const Vector<TransactionCallbackID>& callbackIDs() const { return m_callbackIDs; }
228     void setCallbackIDs(Vector<TransactionCallbackID> callbackIDs) { m_callbackIDs = WTF::move(callbackIDs); }
229     
230 private:
231     WebCore::GraphicsLayer::PlatformLayerID m_rootLayerID;
232     Vector<RefPtr<PlatformCALayerRemote>> m_changedLayers; // Only used in the Web process.
233     LayerPropertiesMap m_changedLayerProperties; // Only used in the UI process.
234
235     Vector<LayerCreationProperties> m_createdLayers;
236     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_destroyedLayerIDs;
237     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_videoLayerIDsPendingFullscreen;
238     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_layerIDsWithNewlyUnreachableBackingStore;
239
240     Vector<TransactionCallbackID> m_callbackIDs;
241
242     WebCore::IntSize m_contentsSize;
243 #if PLATFORM(MAC)
244     WebCore::IntPoint m_scrollPosition;
245 #endif
246     WebCore::Color m_pageExtendedBackgroundColor;
247     double m_pageScaleFactor;
248     double m_minimumScaleFactor;
249     double m_maximumScaleFactor;
250     uint64_t m_renderTreeSize;
251     uint64_t m_transactionID;
252     bool m_scaleWasSetByUIProcess;
253     bool m_allowsUserScaling;
254 };
255
256 } // namespace WebKit
257
258 #endif // RemoteLayerTreeTransaction_h