Font antialiasing (smoothing) changes when elements are rendered into compositing...
[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/LayoutMilestones.h>
36 #include <WebCore/PlatformCALayer.h>
37 #include <WebCore/TransformationMatrix.h>
38 #include <wtf/HashMap.h>
39 #include <wtf/HashSet.h>
40 #include <wtf/text/StringHash.h>
41 #include <wtf/text/WTFString.h>
42
43 namespace IPC {
44 class ArgumentDecoder;
45 class ArgumentEncoder;
46 }
47
48 namespace WebKit {
49
50 class PlatformCALayerRemote;
51
52 class RemoteLayerTreeTransaction {
53 public:
54     enum LayerChanges {
55         NoChange                        = 0,
56         NameChanged                     = 1LLU << 1,
57         ChildrenChanged                 = 1LLU << 2,
58         PositionChanged                 = 1LLU << 3,
59         BoundsChanged                   = 1LLU << 4,
60         BackgroundColorChanged          = 1LLU << 5,
61         AnchorPointChanged              = 1LLU << 6,
62         BorderWidthChanged              = 1LLU << 7,
63         BorderColorChanged              = 1LLU << 8,
64         OpacityChanged                  = 1LLU << 9,
65         TransformChanged                = 1LLU << 10,
66         SublayerTransformChanged        = 1LLU << 11,
67         HiddenChanged                   = 1LLU << 12,
68         GeometryFlippedChanged          = 1LLU << 13,
69         DoubleSidedChanged              = 1LLU << 14,
70         MasksToBoundsChanged            = 1LLU << 15,
71         OpaqueChanged                   = 1LLU << 16,
72         MaskLayerChanged                = 1LLU << 17,
73         ClonedContentsChanged           = 1LLU << 18,
74         ContentsRectChanged             = 1LLU << 19,
75         ContentsScaleChanged            = 1LLU << 20,
76         CornerRadiusChanged             = 1LLU << 21,
77         ShapeRoundedRectChanged         = 1LLU << 22,
78         ShapePathChanged                = 1LLU << 23,
79         MinificationFilterChanged       = 1LLU << 24,
80         MagnificationFilterChanged      = 1LLU << 25,
81         BlendModeChanged                = 1LLU << 26,
82         WindRuleChanged                 = 1LLU << 27,
83         SpeedChanged                    = 1LLU << 28,
84         TimeOffsetChanged               = 1LLU << 29,
85         BackingStoreChanged             = 1LLU << 30,
86         BackingStoreAttachmentChanged   = 1LLU << 31,
87         FiltersChanged                  = 1LLU << 32,
88         AnimationsChanged               = 1LLU << 33,
89         EdgeAntialiasingMaskChanged     = 1LLU << 34,
90         ContentsFormatFlagsChanged      = 1LLU << 35,
91         CustomAppearanceChanged         = 1LLU << 36,
92     };
93     typedef uint64_t LayerChange;
94
95     struct LayerCreationProperties {
96         LayerCreationProperties();
97
98         void encode(IPC::ArgumentEncoder&) const;
99         static bool decode(IPC::ArgumentDecoder&, LayerCreationProperties&);
100
101         WebCore::GraphicsLayer::PlatformLayerID layerID;
102         WebCore::PlatformCALayer::LayerType type;
103
104         uint32_t hostingContextID;
105         float hostingDeviceScaleFactor;
106     };
107
108     struct LayerProperties {
109         LayerProperties();
110         LayerProperties(const LayerProperties& other);
111
112         void encode(IPC::ArgumentEncoder&) const;
113         static bool decode(IPC::ArgumentDecoder&, LayerProperties&);
114
115         void notePropertiesChanged(LayerChange changeFlags)
116         {
117             changedProperties |= changeFlags;
118             everChangedProperties |= changeFlags;
119         }
120
121         void resetChangedProperties()
122         {
123             changedProperties = RemoteLayerTreeTransaction::NoChange;
124         }
125
126         LayerChange changedProperties;
127         LayerChange everChangedProperties;
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::PlatformCALayer::ContentsFormatFlags contentsFormatFlags;
158         WebCore::GraphicsLayer::CustomAppearance customAppearance;
159         WebCore::PlatformCALayer::FilterType minificationFilter;
160         WebCore::PlatformCALayer::FilterType magnificationFilter;
161         WebCore::BlendMode blendMode;
162         WebCore::WindRule windRule;
163         bool hidden;
164         bool backingStoreAttached;
165         bool geometryFlipped;
166         bool doubleSided;
167         bool masksToBounds;
168         bool opaque;
169     };
170
171     explicit RemoteLayerTreeTransaction();
172     ~RemoteLayerTreeTransaction();
173
174     void encode(IPC::ArgumentEncoder&) const;
175     static bool decode(IPC::ArgumentDecoder&, RemoteLayerTreeTransaction&);
176
177     WebCore::GraphicsLayer::PlatformLayerID rootLayerID() const { return m_rootLayerID; }
178     void setRootLayerID(WebCore::GraphicsLayer::PlatformLayerID);
179     void layerPropertiesChanged(PlatformCALayerRemote&);
180     void setCreatedLayers(Vector<LayerCreationProperties>);
181     void setDestroyedLayerIDs(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
182     void setLayerIDsWithNewlyUnreachableBackingStore(Vector<WebCore::GraphicsLayer::PlatformLayerID>);
183
184 #if !defined(NDEBUG) || !LOG_DISABLED
185     WTF::CString description() const;
186     void dump() const;
187 #endif
188
189     typedef HashMap<WebCore::GraphicsLayer::PlatformLayerID, std::unique_ptr<LayerProperties>> LayerPropertiesMap;
190
191     Vector<LayerCreationProperties> createdLayers() const { return m_createdLayers; }
192     Vector<WebCore::GraphicsLayer::PlatformLayerID> destroyedLayers() const { return m_destroyedLayerIDs; }
193     Vector<WebCore::GraphicsLayer::PlatformLayerID> layerIDsWithNewlyUnreachableBackingStore() const { return m_layerIDsWithNewlyUnreachableBackingStore; }
194
195     Vector<RefPtr<PlatformCALayerRemote>>& changedLayers() { return m_changedLayers; }
196
197     const LayerPropertiesMap& changedLayerProperties() const { return m_changedLayerProperties; }
198     LayerPropertiesMap& changedLayerProperties() { return m_changedLayerProperties; }
199
200     WebCore::IntSize contentsSize() const { return m_contentsSize; }
201     void setContentsSize(const WebCore::IntSize& size) { m_contentsSize = size; };
202
203     WebCore::IntPoint scrollOrigin() const { return m_scrollOrigin; }
204     void setScrollOrigin(const WebCore::IntPoint& origin) { m_scrollOrigin = origin; };
205     
206     WebCore::Color pageExtendedBackgroundColor() const { return m_pageExtendedBackgroundColor; }
207     void setPageExtendedBackgroundColor(WebCore::Color color) { m_pageExtendedBackgroundColor = color; }
208
209 #if PLATFORM(MAC)
210     WebCore::IntPoint scrollPosition() const { return m_scrollPosition; }
211     void setScrollPosition(WebCore::IntPoint p) { m_scrollPosition = p; }
212 #endif
213
214     double pageScaleFactor() const { return m_pageScaleFactor; }
215     void setPageScaleFactor(double pageScaleFactor) { m_pageScaleFactor = pageScaleFactor; }
216
217     bool scaleWasSetByUIProcess() const { return m_scaleWasSetByUIProcess; }
218     void setScaleWasSetByUIProcess(bool scaleWasSetByUIProcess) { m_scaleWasSetByUIProcess = scaleWasSetByUIProcess; }
219     
220     uint64_t renderTreeSize() const { return m_renderTreeSize; }
221     void setRenderTreeSize(uint64_t renderTreeSize) { m_renderTreeSize = renderTreeSize; }
222
223     double minimumScaleFactor() const { return m_minimumScaleFactor; }
224     void setMinimumScaleFactor(double scale) { m_minimumScaleFactor = scale; }
225
226     double maximumScaleFactor() const { return m_maximumScaleFactor; }
227     void setMaximumScaleFactor(double scale) { m_maximumScaleFactor = scale; }
228
229     double initialScaleFactor() const { return m_initialScaleFactor; }
230     void setInitialScaleFactor(double scale) { m_initialScaleFactor = scale; }
231
232     double viewportMetaTagWidth() const { return m_viewportMetaTagWidth; }
233     void setViewportMetaTagWidth(double width) { m_viewportMetaTagWidth = width; }
234
235     bool viewportMetaTagWidthWasExplicit() const { return m_viewportMetaTagWidthWasExplicit; }
236     void setViewportMetaTagWidthWasExplicit(bool widthWasExplicit) { m_viewportMetaTagWidthWasExplicit = widthWasExplicit; }
237
238     bool viewportMetaTagCameFromImageDocument() const { return m_viewportMetaTagCameFromImageDocument; }
239     void setViewportMetaTagCameFromImageDocument(bool cameFromImageDocument) { m_viewportMetaTagCameFromImageDocument = cameFromImageDocument; }
240
241     bool allowsUserScaling() const { return m_allowsUserScaling; }
242     void setAllowsUserScaling(bool allowsUserScaling) { m_allowsUserScaling = allowsUserScaling; }
243
244     uint64_t transactionID() const { return m_transactionID; }
245     void setTransactionID(uint64_t transactionID) { m_transactionID = transactionID; }
246
247     typedef uint64_t TransactionCallbackID;
248     const Vector<TransactionCallbackID>& callbackIDs() const { return m_callbackIDs; }
249     void setCallbackIDs(Vector<TransactionCallbackID>&& callbackIDs) { m_callbackIDs = WTFMove(callbackIDs); }
250
251     WebCore::LayoutMilestones newlyReachedLayoutMilestones() const { return m_newlyReachedLayoutMilestones; }
252     void setNewlyReachedLayoutMilestones(WebCore::LayoutMilestones milestones) { m_newlyReachedLayoutMilestones = milestones; }
253     
254 private:
255     WebCore::GraphicsLayer::PlatformLayerID m_rootLayerID;
256     Vector<RefPtr<PlatformCALayerRemote>> m_changedLayers; // Only used in the Web process.
257     LayerPropertiesMap m_changedLayerProperties; // Only used in the UI process.
258
259     Vector<LayerCreationProperties> m_createdLayers;
260     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_destroyedLayerIDs;
261     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_videoLayerIDsPendingFullscreen;
262     Vector<WebCore::GraphicsLayer::PlatformLayerID> m_layerIDsWithNewlyUnreachableBackingStore;
263
264     Vector<TransactionCallbackID> m_callbackIDs;
265
266     WebCore::IntSize m_contentsSize;
267     WebCore::IntPoint m_scrollOrigin;
268 #if PLATFORM(MAC)
269     WebCore::IntPoint m_scrollPosition;
270 #endif
271     WebCore::Color m_pageExtendedBackgroundColor;
272     double m_pageScaleFactor { 1 };
273     double m_minimumScaleFactor { 1 };
274     double m_maximumScaleFactor { 1 };
275     double m_initialScaleFactor { 1 };
276     double m_viewportMetaTagWidth { -1 };
277     uint64_t m_renderTreeSize { 0 };
278     uint64_t m_transactionID { 0 };
279     WebCore::LayoutMilestones m_newlyReachedLayoutMilestones { 0 };
280     bool m_scaleWasSetByUIProcess { false };
281     bool m_allowsUserScaling { false };
282     bool m_viewportMetaTagWidthWasExplicit { false };
283     bool m_viewportMetaTagCameFromImageDocument { false };
284 };
285
286 } // namespace WebKit
287
288 #endif // RemoteLayerTreeTransaction_h