Make it possible to detach GraphicsLayerCA backing store
[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         BackingStoreAttachmentChanged   = 1LLU << 31,
85         FiltersChanged                  = 1LLU << 32,
86         AnimationsChanged               = 1LLU << 33,
87         EdgeAntialiasingMaskChanged     = 1LLU << 34,
88         CustomAppearanceChanged         = 1LLU << 35,
89     };
90     typedef uint64_t LayerChange;
91
92     struct LayerCreationProperties {
93         LayerCreationProperties();
94
95         void encode(IPC::ArgumentEncoder&) const;
96         static bool decode(IPC::ArgumentDecoder&, LayerCreationProperties&);
97
98         WebCore::GraphicsLayer::PlatformLayerID layerID;
99         WebCore::PlatformCALayer::LayerType type;
100
101         uint32_t hostingContextID;
102         float hostingDeviceScaleFactor;
103     };
104
105     struct LayerProperties {
106         LayerProperties();
107         LayerProperties(const LayerProperties& other);
108
109         void encode(IPC::ArgumentEncoder&) const;
110         static bool decode(IPC::ArgumentDecoder&, LayerProperties&);
111
112         void notePropertiesChanged(LayerChange changeFlags)
113         {
114             changedProperties |= changeFlags;
115             everChangedProperties |= changeFlags;
116         }
117
118         void resetChangedProperties()
119         {
120             changedProperties = RemoteLayerTreeTransaction::NoChange;
121         }
122
123         LayerChange changedProperties;
124         LayerChange everChangedProperties;
125
126         String name;
127         std::unique_ptr<WebCore::TransformationMatrix> transform;
128         std::unique_ptr<WebCore::TransformationMatrix> sublayerTransform;
129         std::unique_ptr<WebCore::FloatRoundedRect> shapeRoundedRect;
130
131         Vector<WebCore::GraphicsLayer::PlatformLayerID> children;
132
133         Vector<std::pair<String, PlatformCAAnimationRemote::Properties>> addedAnimations;
134         HashSet<String> keyPathsOfAnimationsToRemove;
135
136         WebCore::FloatPoint3D position;
137         WebCore::FloatPoint3D anchorPoint;
138         WebCore::FloatRect bounds;
139         WebCore::FloatRect contentsRect;
140         std::unique_ptr<RemoteLayerBackingStore> backingStore;
141         std::unique_ptr<WebCore::FilterOperations> filters;
142         WebCore::Path shapePath;
143         WebCore::GraphicsLayer::PlatformLayerID maskLayerID;
144         WebCore::GraphicsLayer::PlatformLayerID clonedLayerID;
145         double timeOffset;
146         float speed;
147         float contentsScale;
148         float cornerRadius;
149         float borderWidth;
150         float opacity;
151         WebCore::Color backgroundColor;
152         WebCore::Color borderColor;
153         unsigned edgeAntialiasingMask;
154         WebCore::GraphicsLayer::CustomAppearance customAppearance;
155         WebCore::PlatformCALayer::FilterType minificationFilter;
156         WebCore::PlatformCALayer::FilterType magnificationFilter;
157         WebCore::BlendMode blendMode;
158         WebCore::WindRule windRule;
159         bool hidden;
160         bool backingStoreAttached;
161         bool geometryFlipped;
162         bool doubleSided;
163         bool masksToBounds;
164         bool opaque;
165     };
166
167     explicit RemoteLayerTreeTransaction();
168     ~RemoteLayerTreeTransaction();
169
170     void encode(IPC::ArgumentEncoder&) const;
171     static bool decode(IPC::ArgumentDecoder&, RemoteLayerTreeTransaction&);
172
173     WebCore::GraphicsLayer::PlatformLayerID rootLayerID() const { return m_rootLayerID; }
174     void setRootLayerID(WebCore::GraphicsLayer::PlatformLayerID);
175     void layerPropertiesChanged(PlatformCALayerRemote&);
176     void setCreatedLayers(Vector<LayerCreationProperties>);
177     void setDestroyedLayerIDs(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
178     void setLayerIDsWithNewlyUnreachableBackingStore(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
179
180 #if !defined(NDEBUG) || !LOG_DISABLED
181     WTF::CString description() const;
182     void dump() const;
183 #endif
184
185     typedef HashMap<WebCore::GraphicsLayer::PlatformLayerID, std::unique_ptr<LayerProperties>> LayerPropertiesMap;
186
187     Vector<LayerCreationProperties> createdLayers() const { return m_createdLayers; }
188     Vector<WebCore::GraphicsLayer::PlatformLayerID> destroyedLayers() const { return m_destroyedLayerIDs; }
189     Vector<WebCore::GraphicsLayer::PlatformLayerID> layerIDsWithNewlyUnreachableBackingStore() const { return m_layerIDsWithNewlyUnreachableBackingStore; }
190
191     Vector<RefPtr<PlatformCALayerRemote>>& changedLayers() { return m_changedLayers; }
192
193     const LayerPropertiesMap& changedLayerProperties() const { return m_changedLayerProperties; }
194     LayerPropertiesMap& changedLayerProperties() { return m_changedLayerProperties; }
195
196     WebCore::IntSize contentsSize() const { return m_contentsSize; }
197     void setContentsSize(const WebCore::IntSize& size) { m_contentsSize = size; };
198     
199     WebCore::Color pageExtendedBackgroundColor() const { return m_pageExtendedBackgroundColor; }
200     void setPageExtendedBackgroundColor(WebCore::Color color) { m_pageExtendedBackgroundColor = color; }
201
202 #if PLATFORM(MAC)
203     WebCore::IntPoint scrollPosition() const { return m_scrollPosition; }
204     void setScrollPosition(WebCore::IntPoint p) { m_scrollPosition = p; }
205 #endif
206
207     double pageScaleFactor() const { return m_pageScaleFactor; }
208     void setPageScaleFactor(double pageScaleFactor) { m_pageScaleFactor = pageScaleFactor; }
209
210     bool scaleWasSetByUIProcess() const { return m_scaleWasSetByUIProcess; }
211     void setScaleWasSetByUIProcess(bool scaleWasSetByUIProcess) { m_scaleWasSetByUIProcess = scaleWasSetByUIProcess; }
212     
213     uint64_t renderTreeSize() const { return m_renderTreeSize; }
214     void setRenderTreeSize(uint64_t renderTreeSize) { m_renderTreeSize = renderTreeSize; }
215
216     double minimumScaleFactor() const { return m_minimumScaleFactor; }
217     void setMinimumScaleFactor(double scale) { m_minimumScaleFactor = scale; }
218
219     double maximumScaleFactor() const { return m_maximumScaleFactor; }
220     void setMaximumScaleFactor(double scale) { m_maximumScaleFactor = scale; }
221
222     bool allowsUserScaling() const { return m_allowsUserScaling; }
223     void setAllowsUserScaling(bool allowsUserScaling) { m_allowsUserScaling = allowsUserScaling; }
224
225     uint64_t transactionID() const { return m_transactionID; }
226     void setTransactionID(uint64_t transactionID) { m_transactionID = transactionID; }
227
228     typedef uint64_t TransactionCallbackID;
229     const Vector<TransactionCallbackID>& callbackIDs() const { return m_callbackIDs; }
230     void setCallbackIDs(Vector<TransactionCallbackID> callbackIDs) { m_callbackIDs = WTF::move(callbackIDs); }
231     
232 private:
233     WebCore::GraphicsLayer::PlatformLayerID m_rootLayerID;
234     Vector<RefPtr<PlatformCALayerRemote>> m_changedLayers; // Only used in the Web process.
235     LayerPropertiesMap m_changedLayerProperties; // Only used in the UI process.
236
237     Vector<LayerCreationProperties> m_createdLayers;
238     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_destroyedLayerIDs;
239     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_videoLayerIDsPendingFullscreen;
240     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_layerIDsWithNewlyUnreachableBackingStore;
241
242     Vector<TransactionCallbackID> m_callbackIDs;
243
244     WebCore::IntSize m_contentsSize;
245 #if PLATFORM(MAC)
246     WebCore::IntPoint m_scrollPosition;
247 #endif
248     WebCore::Color m_pageExtendedBackgroundColor;
249     double m_pageScaleFactor;
250     double m_minimumScaleFactor;
251     double m_maximumScaleFactor;
252     uint64_t m_renderTreeSize;
253     uint64_t m_transactionID;
254     bool m_scaleWasSetByUIProcess;
255     bool m_allowsUserScaling;
256 };
257
258 } // namespace WebKit
259
260 #endif // RemoteLayerTreeTransaction_h