Replace OptionSet |= and -= operators with add() and remove() functions
[WebKit-https.git] / Source / WebKit / Shared / RemoteLayerTree / 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 #pragma once
27
28 #include "DrawingAreaInfo.h"
29 #include "DynamicViewportSizeUpdate.h"
30 #include "EditorState.h"
31 #include "GenericCallback.h"
32 #include "PlatformCAAnimationRemote.h"
33 #include "RemoteLayerBackingStore.h"
34 #include <WebCore/Color.h>
35 #include <WebCore/FilterOperations.h>
36 #include <WebCore/FloatPoint3D.h>
37 #include <WebCore/FloatSize.h>
38 #include <WebCore/LayoutMilestones.h>
39 #include <WebCore/PlatformCALayer.h>
40 #include <WebCore/TransformationMatrix.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/HashSet.h>
43 #include <wtf/text/StringHash.h>
44 #include <wtf/text/WTFString.h>
45
46 namespace IPC {
47 class Decoder;
48 class Encoder;
49 }
50
51 namespace WebKit {
52
53 class PlatformCALayerRemote;
54
55 class RemoteLayerTreeTransaction {
56 public:
57     enum LayerChange {
58         NameChanged                     = 1LLU << 1,
59         ChildrenChanged                 = 1LLU << 2,
60         PositionChanged                 = 1LLU << 3,
61         BoundsChanged                   = 1LLU << 4,
62         BackgroundColorChanged          = 1LLU << 5,
63         AnchorPointChanged              = 1LLU << 6,
64         BorderWidthChanged              = 1LLU << 7,
65         BorderColorChanged              = 1LLU << 8,
66         OpacityChanged                  = 1LLU << 9,
67         TransformChanged                = 1LLU << 10,
68         SublayerTransformChanged        = 1LLU << 11,
69         HiddenChanged                   = 1LLU << 12,
70         GeometryFlippedChanged          = 1LLU << 13,
71         DoubleSidedChanged              = 1LLU << 14,
72         MasksToBoundsChanged            = 1LLU << 15,
73         OpaqueChanged                   = 1LLU << 16,
74         ContentsHiddenChanged           = 1LLU << 17,
75         MaskLayerChanged                = 1LLU << 18,
76         ClonedContentsChanged           = 1LLU << 19,
77         ContentsRectChanged             = 1LLU << 20,
78         ContentsScaleChanged            = 1LLU << 21,
79         CornerRadiusChanged             = 1LLU << 22,
80         ShapeRoundedRectChanged         = 1LLU << 23,
81         ShapePathChanged                = 1LLU << 24,
82         MinificationFilterChanged       = 1LLU << 25,
83         MagnificationFilterChanged      = 1LLU << 26,
84         BlendModeChanged                = 1LLU << 27,
85         WindRuleChanged                 = 1LLU << 28,
86         SpeedChanged                    = 1LLU << 29,
87         TimeOffsetChanged               = 1LLU << 30,
88         BackingStoreChanged             = 1LLU << 31,
89         BackingStoreAttachmentChanged   = 1LLU << 32,
90         FiltersChanged                  = 1LLU << 33,
91         AnimationsChanged               = 1LLU << 34,
92         EdgeAntialiasingMaskChanged     = 1LLU << 35,
93         CustomAppearanceChanged         = 1LLU << 36,
94         UserInteractionEnabledChanged   = 1LLU << 37,
95     };
96
97     struct LayerCreationProperties {
98         LayerCreationProperties();
99
100         void encode(IPC::Encoder&) const;
101         static std::optional<LayerCreationProperties> decode(IPC::Decoder&);
102
103         WebCore::GraphicsLayer::PlatformLayerID layerID;
104         WebCore::PlatformCALayer::LayerType type;
105
106         uint32_t hostingContextID;
107         float hostingDeviceScaleFactor;
108     };
109
110     struct LayerProperties {
111         LayerProperties();
112         LayerProperties(const LayerProperties& other);
113
114         void encode(IPC::Encoder&) const;
115         static bool decode(IPC::Decoder&, LayerProperties&);
116
117         void notePropertiesChanged(OptionSet<LayerChange> changeFlags)
118         {
119             changedProperties.add(changeFlags);
120         }
121
122         void resetChangedProperties()
123         {
124             changedProperties = { };
125         }
126
127         OptionSet<LayerChange> changedProperties;
128
129         String name;
130         std::unique_ptr<WebCore::TransformationMatrix> transform;
131         std::unique_ptr<WebCore::TransformationMatrix> sublayerTransform;
132         std::unique_ptr<WebCore::FloatRoundedRect> shapeRoundedRect;
133
134         Vector<WebCore::GraphicsLayer::PlatformLayerID> children;
135
136         Vector<std::pair<String, PlatformCAAnimationRemote::Properties>> addedAnimations;
137         HashSet<String> keyPathsOfAnimationsToRemove;
138
139         WebCore::FloatPoint3D position;
140         WebCore::FloatPoint3D anchorPoint;
141         WebCore::FloatRect bounds;
142         WebCore::FloatRect contentsRect;
143         std::unique_ptr<RemoteLayerBackingStore> backingStore;
144         std::unique_ptr<WebCore::FilterOperations> filters;
145         WebCore::Path shapePath;
146         WebCore::GraphicsLayer::PlatformLayerID maskLayerID;
147         WebCore::GraphicsLayer::PlatformLayerID clonedLayerID;
148         double timeOffset;
149         float speed;
150         float contentsScale;
151         float cornerRadius;
152         float borderWidth;
153         float opacity;
154         WebCore::Color backgroundColor;
155         WebCore::Color borderColor;
156         unsigned edgeAntialiasingMask;
157         WebCore::GraphicsLayer::CustomAppearance customAppearance;
158         WebCore::PlatformCALayer::FilterType minificationFilter;
159         WebCore::PlatformCALayer::FilterType magnificationFilter;
160         WebCore::BlendMode blendMode;
161         WebCore::WindRule windRule;
162         bool hidden;
163         bool backingStoreAttached;
164         bool geometryFlipped;
165         bool doubleSided;
166         bool masksToBounds;
167         bool opaque;
168         bool contentsHidden;
169         bool userInteractionEnabled;
170     };
171
172     explicit RemoteLayerTreeTransaction();
173     ~RemoteLayerTreeTransaction();
174
175     void encode(IPC::Encoder&) const;
176     static bool decode(IPC::Decoder&, RemoteLayerTreeTransaction&);
177
178     WebCore::GraphicsLayer::PlatformLayerID rootLayerID() const { return m_rootLayerID; }
179     void setRootLayerID(WebCore::GraphicsLayer::PlatformLayerID);
180     void layerPropertiesChanged(PlatformCALayerRemote&);
181     void setCreatedLayers(Vector<LayerCreationProperties>);
182     void setDestroyedLayerIDs(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
183     void setLayerIDsWithNewlyUnreachableBackingStore(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
184
185 #if !defined(NDEBUG) || !LOG_DISABLED
186     WTF::CString description() const;
187     void dump() const;
188 #endif
189
190     typedef HashMap<WebCore::GraphicsLayer::PlatformLayerID, std::unique_ptr<LayerProperties>> LayerPropertiesMap;
191
192     Vector<LayerCreationProperties> createdLayers() const { return m_createdLayers; }
193     Vector<WebCore::GraphicsLayer::PlatformLayerID> destroyedLayers() const { return m_destroyedLayerIDs; }
194     Vector<WebCore::GraphicsLayer::PlatformLayerID> layerIDsWithNewlyUnreachableBackingStore() const { return m_layerIDsWithNewlyUnreachableBackingStore; }
195
196     Vector<RefPtr<PlatformCALayerRemote>>& changedLayers() { return m_changedLayers; }
197
198     const LayerPropertiesMap& changedLayerProperties() const { return m_changedLayerProperties; }
199     LayerPropertiesMap& changedLayerProperties() { return m_changedLayerProperties; }
200
201     WebCore::IntSize contentsSize() const { return m_contentsSize; }
202     void setContentsSize(const WebCore::IntSize& size) { m_contentsSize = size; };
203
204     WebCore::IntPoint scrollOrigin() const { return m_scrollOrigin; }
205     void setScrollOrigin(const WebCore::IntPoint& origin) { m_scrollOrigin = origin; };
206
207     WebCore::LayoutSize baseLayoutViewportSize() const { return m_baseLayoutViewportSize; }
208     void setBaseLayoutViewportSize(const WebCore::LayoutSize& size) { m_baseLayoutViewportSize = size; };
209     
210     WebCore::LayoutPoint minStableLayoutViewportOrigin() const { return m_minStableLayoutViewportOrigin; }
211     void setMinStableLayoutViewportOrigin(const WebCore::LayoutPoint& point) { m_minStableLayoutViewportOrigin = point; };
212     
213     WebCore::LayoutPoint maxStableLayoutViewportOrigin() const { return m_maxStableLayoutViewportOrigin; }
214     void setMaxStableLayoutViewportOrigin(const WebCore::LayoutPoint& point) { m_maxStableLayoutViewportOrigin = point; };
215     
216     WebCore::Color pageExtendedBackgroundColor() const { return m_pageExtendedBackgroundColor; }
217     void setPageExtendedBackgroundColor(WebCore::Color color) { m_pageExtendedBackgroundColor = color; }
218
219     WebCore::IntPoint scrollPosition() const { return m_scrollPosition; }
220     void setScrollPosition(WebCore::IntPoint p) { m_scrollPosition = p; }
221
222     double pageScaleFactor() const { return m_pageScaleFactor; }
223     void setPageScaleFactor(double pageScaleFactor) { m_pageScaleFactor = pageScaleFactor; }
224
225     bool scaleWasSetByUIProcess() const { return m_scaleWasSetByUIProcess; }
226     void setScaleWasSetByUIProcess(bool scaleWasSetByUIProcess) { m_scaleWasSetByUIProcess = scaleWasSetByUIProcess; }
227     
228     uint64_t renderTreeSize() const { return m_renderTreeSize; }
229     void setRenderTreeSize(uint64_t renderTreeSize) { m_renderTreeSize = renderTreeSize; }
230
231     double minimumScaleFactor() const { return m_minimumScaleFactor; }
232     void setMinimumScaleFactor(double scale) { m_minimumScaleFactor = scale; }
233
234     double maximumScaleFactor() const { return m_maximumScaleFactor; }
235     void setMaximumScaleFactor(double scale) { m_maximumScaleFactor = scale; }
236
237     double initialScaleFactor() const { return m_initialScaleFactor; }
238     void setInitialScaleFactor(double scale) { m_initialScaleFactor = scale; }
239
240     double viewportMetaTagWidth() const { return m_viewportMetaTagWidth; }
241     void setViewportMetaTagWidth(double width) { m_viewportMetaTagWidth = width; }
242
243     bool viewportMetaTagWidthWasExplicit() const { return m_viewportMetaTagWidthWasExplicit; }
244     void setViewportMetaTagWidthWasExplicit(bool widthWasExplicit) { m_viewportMetaTagWidthWasExplicit = widthWasExplicit; }
245
246     bool viewportMetaTagCameFromImageDocument() const { return m_viewportMetaTagCameFromImageDocument; }
247     void setViewportMetaTagCameFromImageDocument(bool cameFromImageDocument) { m_viewportMetaTagCameFromImageDocument = cameFromImageDocument; }
248
249     bool isInStableState() const { return m_isInStableState; }
250     void setIsInStableState(bool isInStableState) { m_isInStableState = isInStableState; }
251
252     bool allowsUserScaling() const { return m_allowsUserScaling; }
253     void setAllowsUserScaling(bool allowsUserScaling) { m_allowsUserScaling = allowsUserScaling; }
254
255     bool avoidsUnsafeArea() const { return m_avoidsUnsafeArea; }
256     void setAvoidsUnsafeArea(bool avoidsUnsafeArea) { m_avoidsUnsafeArea = avoidsUnsafeArea; }
257
258     uint64_t transactionID() const { return m_transactionID; }
259     void setTransactionID(uint64_t transactionID) { m_transactionID = transactionID; }
260
261     ActivityStateChangeID activityStateChangeID() const { return m_activityStateChangeID; }
262     void setActivityStateChangeID(ActivityStateChangeID activityStateChangeID) { m_activityStateChangeID = activityStateChangeID; }
263
264     typedef CallbackID TransactionCallbackID;
265     const Vector<TransactionCallbackID>& callbackIDs() const { return m_callbackIDs; }
266     void setCallbackIDs(Vector<TransactionCallbackID>&& callbackIDs) { m_callbackIDs = WTFMove(callbackIDs); }
267
268     WebCore::LayoutMilestones newlyReachedLayoutMilestones() const { return m_newlyReachedLayoutMilestones; }
269     void setNewlyReachedLayoutMilestones(WebCore::LayoutMilestones milestones) { m_newlyReachedLayoutMilestones = milestones; }
270
271     bool hasEditorState() const { return !!m_editorState; }
272     const EditorState& editorState() const { return m_editorState.value(); }
273     void setEditorState(const EditorState& editorState) { m_editorState = editorState; }
274
275     std::optional<DynamicViewportSizeUpdateID> dynamicViewportSizeUpdateID() const { return m_dynamicViewportSizeUpdateID; }
276     void setDynamicViewportSizeUpdateID(DynamicViewportSizeUpdateID resizeID) { m_dynamicViewportSizeUpdateID = resizeID; }
277     
278 private:
279     WebCore::GraphicsLayer::PlatformLayerID m_rootLayerID;
280     Vector<RefPtr<PlatformCALayerRemote>> m_changedLayers; // Only used in the Web process.
281     LayerPropertiesMap m_changedLayerProperties; // Only used in the UI process.
282
283     Vector<LayerCreationProperties> m_createdLayers;
284     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_destroyedLayerIDs;
285     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_videoLayerIDsPendingFullscreen;
286     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_layerIDsWithNewlyUnreachableBackingStore;
287
288     Vector<TransactionCallbackID> m_callbackIDs;
289
290     WebCore::IntSize m_contentsSize;
291     WebCore::IntPoint m_scrollOrigin;
292     WebCore::LayoutSize m_baseLayoutViewportSize;
293     WebCore::LayoutPoint m_minStableLayoutViewportOrigin;
294     WebCore::LayoutPoint m_maxStableLayoutViewportOrigin;
295     WebCore::IntPoint m_scrollPosition;
296     WebCore::Color m_pageExtendedBackgroundColor;
297     double m_pageScaleFactor { 1 };
298     double m_minimumScaleFactor { 1 };
299     double m_maximumScaleFactor { 1 };
300     double m_initialScaleFactor { 1 };
301     double m_viewportMetaTagWidth { -1 };
302     uint64_t m_renderTreeSize { 0 };
303     uint64_t m_transactionID { 0 };
304     ActivityStateChangeID m_activityStateChangeID { ActivityStateChangeAsynchronous };
305     WebCore::LayoutMilestones m_newlyReachedLayoutMilestones { 0 };
306     bool m_scaleWasSetByUIProcess { false };
307     bool m_allowsUserScaling { false };
308     bool m_avoidsUnsafeArea { true };
309     bool m_viewportMetaTagWidthWasExplicit { false };
310     bool m_viewportMetaTagCameFromImageDocument { false };
311     bool m_isInStableState { false };
312
313     std::optional<EditorState> m_editorState;
314     std::optional<DynamicViewportSizeUpdateID> m_dynamicViewportSizeUpdateID;
315 };
316
317 } // namespace WebKit