Combine event and touch action regions into a single class
[WebKit-https.git] / Source / WebKit / Shared / RemoteLayerTree / RemoteLayerTreeTransaction.mm
1 /*
2  * Copyright (C) 2012-2018 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 #import "config.h"
27 #import "RemoteLayerTreeTransaction.h"
28
29 #import "ArgumentCoders.h"
30 #import "PlatformCAAnimationRemote.h"
31 #import "PlatformCALayerRemote.h"
32 #import "WebCoreArgumentCoders.h"
33 #import <QuartzCore/QuartzCore.h>
34 #import <WebCore/EventRegion.h>
35 #import <WebCore/LengthFunctions.h>
36 #import <WebCore/TimingFunction.h>
37 #import <wtf/text/CString.h>
38 #import <wtf/text/TextStream.h>
39
40 namespace WebKit {
41
42 RemoteLayerTreeTransaction::RemoteLayerTreeTransaction(RemoteLayerTreeTransaction&&) = default;
43 RemoteLayerTreeTransaction& RemoteLayerTreeTransaction::operator=(RemoteLayerTreeTransaction&&) = default;
44
45 RemoteLayerTreeTransaction::LayerCreationProperties::LayerCreationProperties()
46     : layerID(0)
47     , type(WebCore::PlatformCALayer::LayerTypeLayer)
48     , embeddedViewID(0)
49     , hostingContextID(0)
50     , hostingDeviceScaleFactor(1)
51 {
52 }
53
54 void RemoteLayerTreeTransaction::LayerCreationProperties::encode(IPC::Encoder& encoder) const
55 {
56     encoder << layerID;
57     encoder.encodeEnum(type);
58     encoder << embeddedViewID;
59     encoder << hostingContextID;
60     encoder << hostingDeviceScaleFactor;
61 }
62
63 auto RemoteLayerTreeTransaction::LayerCreationProperties::decode(IPC::Decoder& decoder) -> Optional<LayerCreationProperties>
64 {
65     LayerCreationProperties result;
66     if (!decoder.decode(result.layerID))
67         return WTF::nullopt;
68
69     if (!decoder.decodeEnum(result.type))
70         return WTF::nullopt;
71
72     if (!decoder.decode(result.embeddedViewID))
73         return WTF::nullopt;
74
75     if (!decoder.decode(result.hostingContextID))
76         return WTF::nullopt;
77
78     if (!decoder.decode(result.hostingDeviceScaleFactor))
79         return WTF::nullopt;
80
81     return WTFMove(result);
82 }
83
84 RemoteLayerTreeTransaction::LayerProperties::LayerProperties()
85     : anchorPoint(0.5, 0.5, 0)
86     , contentsRect(WebCore::FloatPoint(), WebCore::FloatSize(1, 1))
87     , maskLayerID(0)
88     , clonedLayerID(0)
89     , timeOffset(0)
90     , speed(1)
91     , contentsScale(1)
92     , cornerRadius(0)
93     , borderWidth(0)
94     , opacity(1)
95     , backgroundColor(WebCore::Color::transparent)
96     , borderColor(WebCore::Color::black)
97     , edgeAntialiasingMask(kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge)
98     , customAppearance(WebCore::GraphicsLayer::CustomAppearance::None)
99     , minificationFilter(WebCore::PlatformCALayer::FilterType::Linear)
100     , magnificationFilter(WebCore::PlatformCALayer::FilterType::Linear)
101     , blendMode(WebCore::BlendMode::Normal)
102     , windRule(WebCore::WindRule::NonZero)
103     , hidden(false)
104     , backingStoreAttached(true)
105     , geometryFlipped(false)
106     , doubleSided(true)
107     , masksToBounds(false)
108     , opaque(false)
109     , contentsHidden(false)
110     , userInteractionEnabled(true)
111 {
112 }
113
114 RemoteLayerTreeTransaction::LayerProperties::LayerProperties(const LayerProperties& other)
115     : changedProperties(other.changedProperties)
116     , name(other.name)
117     , children(other.children)
118     , addedAnimations(other.addedAnimations)
119     , keyPathsOfAnimationsToRemove(other.keyPathsOfAnimationsToRemove)
120     , position(other.position)
121     , anchorPoint(other.anchorPoint)
122     , bounds(other.bounds)
123     , contentsRect(other.contentsRect)
124     , shapePath(other.shapePath)
125     , maskLayerID(other.maskLayerID)
126     , clonedLayerID(other.clonedLayerID)
127     , timeOffset(other.timeOffset)
128     , speed(other.speed)
129     , contentsScale(other.contentsScale)
130     , cornerRadius(other.cornerRadius)
131     , borderWidth(other.borderWidth)
132     , opacity(other.opacity)
133     , backgroundColor(other.backgroundColor)
134     , borderColor(other.borderColor)
135     , edgeAntialiasingMask(other.edgeAntialiasingMask)
136     , customAppearance(other.customAppearance)
137     , minificationFilter(other.minificationFilter)
138     , magnificationFilter(other.magnificationFilter)
139     , blendMode(other.blendMode)
140     , windRule(other.windRule)
141     , hidden(other.hidden)
142     , backingStoreAttached(other.backingStoreAttached)
143     , geometryFlipped(other.geometryFlipped)
144     , doubleSided(other.doubleSided)
145     , masksToBounds(other.masksToBounds)
146     , opaque(other.opaque)
147     , contentsHidden(other.contentsHidden)
148     , userInteractionEnabled(other.userInteractionEnabled)
149     , eventRegion(other.eventRegion)
150 {
151     // FIXME: LayerProperties should reference backing store by ID, so that two layers can have the same backing store (for clones).
152     // FIXME: LayerProperties shouldn't be copyable; PlatformCALayerRemote::clone should copy the relevant properties.
153
154     if (other.transform)
155         transform = std::make_unique<WebCore::TransformationMatrix>(*other.transform);
156
157     if (other.sublayerTransform)
158         sublayerTransform = std::make_unique<WebCore::TransformationMatrix>(*other.sublayerTransform);
159
160     if (other.filters)
161         filters = std::make_unique<WebCore::FilterOperations>(*other.filters);
162 }
163
164 void RemoteLayerTreeTransaction::LayerProperties::encode(IPC::Encoder& encoder) const
165 {
166     encoder.encode(changedProperties);
167
168     if (changedProperties & NameChanged)
169         encoder << name;
170
171     if (changedProperties & ChildrenChanged)
172         encoder << children;
173
174     if (changedProperties & AnimationsChanged) {
175         encoder << addedAnimations;
176         encoder << keyPathsOfAnimationsToRemove;
177     }
178
179     if (changedProperties & PositionChanged)
180         encoder << position;
181
182     if (changedProperties & BoundsChanged)
183         encoder << bounds;
184
185     if (changedProperties & BackgroundColorChanged)
186         encoder << backgroundColor;
187
188     if (changedProperties & AnchorPointChanged)
189         encoder << anchorPoint;
190
191     if (changedProperties & BorderWidthChanged)
192         encoder << borderWidth;
193
194     if (changedProperties & BorderColorChanged)
195         encoder << borderColor;
196
197     if (changedProperties & OpacityChanged)
198         encoder << opacity;
199
200     if (changedProperties & TransformChanged)
201         encoder << *transform;
202
203     if (changedProperties & SublayerTransformChanged)
204         encoder << *sublayerTransform;
205
206     if (changedProperties & HiddenChanged)
207         encoder << hidden;
208
209     if (changedProperties & GeometryFlippedChanged)
210         encoder << geometryFlipped;
211
212     if (changedProperties & DoubleSidedChanged)
213         encoder << doubleSided;
214
215     if (changedProperties & MasksToBoundsChanged)
216         encoder << masksToBounds;
217
218     if (changedProperties & OpaqueChanged)
219         encoder << opaque;
220
221     if (changedProperties & ContentsHiddenChanged)
222         encoder << contentsHidden;
223
224     if (changedProperties & MaskLayerChanged)
225         encoder << maskLayerID;
226
227     if (changedProperties & ClonedContentsChanged)
228         encoder << clonedLayerID;
229
230     if (changedProperties & ContentsRectChanged)
231         encoder << contentsRect;
232
233     if (changedProperties & ContentsScaleChanged)
234         encoder << contentsScale;
235
236     if (changedProperties & CornerRadiusChanged)
237         encoder << cornerRadius;
238
239     if (changedProperties & ShapeRoundedRectChanged)
240         encoder << *shapeRoundedRect;
241
242     if (changedProperties & ShapePathChanged)
243         encoder << shapePath;
244
245     if (changedProperties & MinificationFilterChanged)
246         encoder.encodeEnum(minificationFilter);
247
248     if (changedProperties & MagnificationFilterChanged)
249         encoder.encodeEnum(magnificationFilter);
250
251     if (changedProperties & BlendModeChanged)
252         encoder.encodeEnum(blendMode);
253
254     if (changedProperties & WindRuleChanged)
255         encoder.encodeEnum(windRule);
256
257     if (changedProperties & SpeedChanged)
258         encoder << speed;
259
260     if (changedProperties & TimeOffsetChanged)
261         encoder << timeOffset;
262
263     if (changedProperties & BackingStoreChanged) {
264         bool hasFrontBuffer = backingStore && backingStore->hasFrontBuffer();
265         encoder << hasFrontBuffer;
266         if (hasFrontBuffer)
267             encoder << *backingStore;
268     }
269
270     if (changedProperties & BackingStoreAttachmentChanged)
271         encoder << backingStoreAttached;
272
273     if (changedProperties & FiltersChanged)
274         encoder << *filters;
275
276     if (changedProperties & EdgeAntialiasingMaskChanged)
277         encoder << edgeAntialiasingMask;
278
279     if (changedProperties & CustomAppearanceChanged)
280         encoder.encodeEnum(customAppearance);
281
282     if (changedProperties & UserInteractionEnabledChanged)
283         encoder << userInteractionEnabled;
284
285     if (changedProperties & EventRegionChanged)
286         encoder << eventRegion;
287 }
288
289 bool RemoteLayerTreeTransaction::LayerProperties::decode(IPC::Decoder& decoder, LayerProperties& result)
290 {
291     if (!decoder.decode(result.changedProperties))
292         return false;
293
294     if (result.changedProperties & NameChanged) {
295         if (!decoder.decode(result.name))
296             return false;
297     }
298
299     if (result.changedProperties & ChildrenChanged) {
300         if (!decoder.decode(result.children))
301             return false;
302
303         for (auto& layerID : result.children) {
304             if (!layerID)
305                 return false;
306         }
307     }
308
309     if (result.changedProperties & AnimationsChanged) {
310         if (!decoder.decode(result.addedAnimations))
311             return false;
312
313         if (!decoder.decode(result.keyPathsOfAnimationsToRemove))
314             return false;
315     }
316
317     if (result.changedProperties & PositionChanged) {
318         if (!decoder.decode(result.position))
319             return false;
320     }
321
322     if (result.changedProperties & BoundsChanged) {
323         if (!decoder.decode(result.bounds))
324             return false;
325     }
326
327     if (result.changedProperties & BackgroundColorChanged) {
328         if (!decoder.decode(result.backgroundColor))
329             return false;
330     }
331
332     if (result.changedProperties & AnchorPointChanged) {
333         if (!decoder.decode(result.anchorPoint))
334             return false;
335     }
336
337     if (result.changedProperties & BorderWidthChanged) {
338         if (!decoder.decode(result.borderWidth))
339             return false;
340     }
341
342     if (result.changedProperties & BorderColorChanged) {
343         if (!decoder.decode(result.borderColor))
344             return false;
345     }
346
347     if (result.changedProperties & OpacityChanged) {
348         if (!decoder.decode(result.opacity))
349             return false;
350     }
351
352     if (result.changedProperties & TransformChanged) {
353         WebCore::TransformationMatrix transform;
354         if (!decoder.decode(transform))
355             return false;
356         
357         result.transform = std::make_unique<WebCore::TransformationMatrix>(transform);
358     }
359
360     if (result.changedProperties & SublayerTransformChanged) {
361         WebCore::TransformationMatrix transform;
362         if (!decoder.decode(transform))
363             return false;
364
365         result.sublayerTransform = std::make_unique<WebCore::TransformationMatrix>(transform);
366     }
367
368     if (result.changedProperties & HiddenChanged) {
369         if (!decoder.decode(result.hidden))
370             return false;
371     }
372
373     if (result.changedProperties & GeometryFlippedChanged) {
374         if (!decoder.decode(result.geometryFlipped))
375             return false;
376     }
377
378     if (result.changedProperties & DoubleSidedChanged) {
379         if (!decoder.decode(result.doubleSided))
380             return false;
381     }
382
383     if (result.changedProperties & MasksToBoundsChanged) {
384         if (!decoder.decode(result.masksToBounds))
385             return false;
386     }
387
388     if (result.changedProperties & OpaqueChanged) {
389         if (!decoder.decode(result.opaque))
390             return false;
391     }
392
393     if (result.changedProperties & ContentsHiddenChanged) {
394         if (!decoder.decode(result.contentsHidden))
395             return false;
396     }
397
398     if (result.changedProperties & MaskLayerChanged) {
399         if (!decoder.decode(result.maskLayerID))
400             return false;
401     }
402
403     if (result.changedProperties & ClonedContentsChanged) {
404         if (!decoder.decode(result.clonedLayerID))
405             return false;
406     }
407
408     if (result.changedProperties & ContentsRectChanged) {
409         if (!decoder.decode(result.contentsRect))
410             return false;
411     }
412
413     if (result.changedProperties & ContentsScaleChanged) {
414         if (!decoder.decode(result.contentsScale))
415             return false;
416     }
417
418     if (result.changedProperties & CornerRadiusChanged) {
419         if (!decoder.decode(result.cornerRadius))
420             return false;
421     }
422
423     if (result.changedProperties & ShapeRoundedRectChanged) {
424         WebCore::FloatRoundedRect roundedRect;
425         if (!decoder.decode(roundedRect))
426             return false;
427         
428         result.shapeRoundedRect = std::make_unique<WebCore::FloatRoundedRect>(roundedRect);
429     }
430
431     if (result.changedProperties & ShapePathChanged) {
432         WebCore::Path path;
433         if (!decoder.decode(path))
434             return false;
435         
436         result.shapePath = WTFMove(path);
437     }
438
439     if (result.changedProperties & MinificationFilterChanged) {
440         if (!decoder.decodeEnum(result.minificationFilter))
441             return false;
442     }
443
444     if (result.changedProperties & MagnificationFilterChanged) {
445         if (!decoder.decodeEnum(result.magnificationFilter))
446             return false;
447     }
448
449     if (result.changedProperties & BlendModeChanged) {
450         if (!decoder.decodeEnum(result.blendMode))
451             return false;
452     }
453
454     if (result.changedProperties & WindRuleChanged) {
455         if (!decoder.decodeEnum(result.windRule))
456             return false;
457     }
458
459     if (result.changedProperties & SpeedChanged) {
460         if (!decoder.decode(result.speed))
461             return false;
462     }
463
464     if (result.changedProperties & TimeOffsetChanged) {
465         if (!decoder.decode(result.timeOffset))
466             return false;
467     }
468
469     if (result.changedProperties & BackingStoreChanged) {
470         bool hasFrontBuffer = false;
471         if (!decoder.decode(hasFrontBuffer))
472             return false;
473         if (hasFrontBuffer) {
474             auto backingStore = std::make_unique<RemoteLayerBackingStore>(nullptr);
475             if (!decoder.decode(*backingStore))
476                 return false;
477             
478             result.backingStore = WTFMove(backingStore);
479         } else
480             result.backingStore = nullptr;
481     }
482
483     if (result.changedProperties & BackingStoreAttachmentChanged) {
484         if (!decoder.decode(result.backingStoreAttached))
485             return false;
486     }
487
488     if (result.changedProperties & FiltersChanged) {
489         auto filters = std::make_unique<WebCore::FilterOperations>();
490         if (!decoder.decode(*filters))
491             return false;
492         result.filters = WTFMove(filters);
493     }
494
495     if (result.changedProperties & EdgeAntialiasingMaskChanged) {
496         if (!decoder.decode(result.edgeAntialiasingMask))
497             return false;
498     }
499
500     if (result.changedProperties & CustomAppearanceChanged) {
501         if (!decoder.decodeEnum(result.customAppearance))
502             return false;
503     }
504
505     if (result.changedProperties & UserInteractionEnabledChanged) {
506         if (!decoder.decode(result.userInteractionEnabled))
507             return false;
508     }
509
510     if (result.changedProperties & EventRegionChanged) {
511         Optional<WebCore::EventRegion> eventRegion;
512         decoder >> eventRegion;
513         if (!eventRegion)
514             return false;
515         result.eventRegion = WTFMove(*eventRegion);
516     }
517
518     return true;
519 }
520
521 RemoteLayerTreeTransaction::RemoteLayerTreeTransaction()
522 {
523 }
524
525 RemoteLayerTreeTransaction::~RemoteLayerTreeTransaction()
526 {
527 }
528
529 void RemoteLayerTreeTransaction::encode(IPC::Encoder& encoder) const
530 {
531     encoder << m_rootLayerID;
532     encoder << m_createdLayers;
533
534     encoder << static_cast<uint64_t>(m_changedLayers.size());
535
536     for (const auto& layer : m_changedLayers) {
537         encoder << layer->layerID();
538         encoder << layer->properties();
539     }
540     
541     encoder << m_destroyedLayerIDs;
542     encoder << m_videoLayerIDsPendingFullscreen;
543     encoder << m_layerIDsWithNewlyUnreachableBackingStore;
544
545     encoder << m_contentsSize;
546     encoder << m_scrollOrigin;
547
548     encoder << m_baseLayoutViewportSize;
549     encoder << m_minStableLayoutViewportOrigin;
550     encoder << m_maxStableLayoutViewportOrigin;
551
552     encoder << m_scrollPosition;
553
554     encoder << m_pageExtendedBackgroundColor;
555     encoder << m_pageScaleFactor;
556     encoder << m_minimumScaleFactor;
557     encoder << m_maximumScaleFactor;
558     encoder << m_initialScaleFactor;
559     encoder << m_viewportMetaTagWidth;
560
561     encoder << m_renderTreeSize;
562     encoder << m_transactionID;
563     encoder << m_activityStateChangeID;
564
565     encoder << m_newlyReachedLayoutMilestones;
566
567     encoder << m_scaleWasSetByUIProcess;
568     encoder << m_allowsUserScaling;
569
570     encoder << m_avoidsUnsafeArea;
571
572     encoder << m_viewportMetaTagWidthWasExplicit;
573     encoder << m_viewportMetaTagCameFromImageDocument;
574
575     encoder << m_isInStableState;
576
577     encoder << m_callbackIDs;
578
579     encoder << hasEditorState();
580     if (m_editorState)
581         encoder << *m_editorState;
582
583     encoder << m_dynamicViewportSizeUpdateID;
584 }
585
586 bool RemoteLayerTreeTransaction::decode(IPC::Decoder& decoder, RemoteLayerTreeTransaction& result)
587 {
588     if (!decoder.decode(result.m_rootLayerID))
589         return false;
590     if (!result.m_rootLayerID)
591         return false;
592
593     if (!decoder.decode(result.m_createdLayers))
594         return false;
595
596     uint64_t numChangedLayerProperties;
597     if (!decoder.decode(numChangedLayerProperties))
598         return false;
599
600     for (uint64_t i = 0; i < numChangedLayerProperties; ++i) {
601         WebCore::GraphicsLayer::PlatformLayerID layerID;
602         if (!decoder.decode(layerID))
603             return false;
604
605         std::unique_ptr<LayerProperties> layerProperties = std::make_unique<LayerProperties>();
606         if (!decoder.decode(*layerProperties))
607             return false;
608
609         result.changedLayerProperties().set(layerID, WTFMove(layerProperties));
610     }
611
612     if (!decoder.decode(result.m_destroyedLayerIDs))
613         return false;
614
615     for (auto& layerID : result.m_destroyedLayerIDs) {
616         if (!layerID)
617             return false;
618     }
619
620     if (!decoder.decode(result.m_videoLayerIDsPendingFullscreen))
621         return false;
622
623     if (!decoder.decode(result.m_layerIDsWithNewlyUnreachableBackingStore))
624         return false;
625
626     for (auto& layerID : result.m_layerIDsWithNewlyUnreachableBackingStore) {
627         if (!layerID)
628             return false;
629     }
630
631     if (!decoder.decode(result.m_contentsSize))
632         return false;
633
634     if (!decoder.decode(result.m_scrollOrigin))
635         return false;
636
637     if (!decoder.decode(result.m_baseLayoutViewportSize))
638         return false;
639
640     if (!decoder.decode(result.m_minStableLayoutViewportOrigin))
641         return false;
642
643     if (!decoder.decode(result.m_maxStableLayoutViewportOrigin))
644         return false;
645
646     if (!decoder.decode(result.m_scrollPosition))
647         return false;
648     
649     if (!decoder.decode(result.m_pageExtendedBackgroundColor))
650         return false;
651
652     if (!decoder.decode(result.m_pageScaleFactor))
653         return false;
654
655     if (!decoder.decode(result.m_minimumScaleFactor))
656         return false;
657
658     if (!decoder.decode(result.m_maximumScaleFactor))
659         return false;
660
661     if (!decoder.decode(result.m_initialScaleFactor))
662         return false;
663
664     if (!decoder.decode(result.m_viewportMetaTagWidth))
665         return false;
666
667     if (!decoder.decode(result.m_renderTreeSize))
668         return false;
669
670     if (!decoder.decode(result.m_transactionID))
671         return false;
672
673     if (!decoder.decode(result.m_activityStateChangeID))
674         return false;
675
676     if (!decoder.decode(result.m_newlyReachedLayoutMilestones))
677         return false;
678
679     if (!decoder.decode(result.m_scaleWasSetByUIProcess))
680         return false;
681
682     if (!decoder.decode(result.m_allowsUserScaling))
683         return false;
684
685     if (!decoder.decode(result.m_avoidsUnsafeArea))
686         return false;
687
688     if (!decoder.decode(result.m_viewportMetaTagWidthWasExplicit))
689         return false;
690
691     if (!decoder.decode(result.m_viewportMetaTagCameFromImageDocument))
692         return false;
693
694     if (!decoder.decode(result.m_isInStableState))
695         return false;
696
697     Optional<Vector<TransactionCallbackID>> callbackIDs;
698     decoder >> callbackIDs;
699     if (!callbackIDs)
700         return false;
701     result.m_callbackIDs = WTFMove(*callbackIDs);
702
703     bool hasEditorState;
704     if (!decoder.decode(hasEditorState))
705         return false;
706
707     if (hasEditorState) {
708         EditorState editorState;
709         if (!decoder.decode(editorState))
710             return false;
711         result.setEditorState(editorState);
712     }
713
714     if (!decoder.decode(result.m_dynamicViewportSizeUpdateID))
715         return false;
716
717     return true;
718 }
719
720 void RemoteLayerTreeTransaction::setRootLayerID(WebCore::GraphicsLayer::PlatformLayerID rootLayerID)
721 {
722     ASSERT_ARG(rootLayerID, rootLayerID);
723
724     m_rootLayerID = rootLayerID;
725 }
726
727 void RemoteLayerTreeTransaction::layerPropertiesChanged(PlatformCALayerRemote& remoteLayer)
728 {
729     m_changedLayers.append(&remoteLayer);
730 }
731
732 void RemoteLayerTreeTransaction::setCreatedLayers(Vector<LayerCreationProperties> createdLayers)
733 {
734     m_createdLayers = WTFMove(createdLayers);
735 }
736
737 void RemoteLayerTreeTransaction::setDestroyedLayerIDs(Vector<WebCore::GraphicsLayer::PlatformLayerID> destroyedLayerIDs)
738 {
739     m_destroyedLayerIDs = WTFMove(destroyedLayerIDs);
740 }
741
742 void RemoteLayerTreeTransaction::setLayerIDsWithNewlyUnreachableBackingStore(Vector<WebCore::GraphicsLayer::PlatformLayerID> layerIDsWithNewlyUnreachableBackingStore)
743 {
744     m_layerIDsWithNewlyUnreachableBackingStore = WTFMove(layerIDsWithNewlyUnreachableBackingStore);
745 }
746
747 #if !defined(NDEBUG) || !LOG_DISABLED
748
749 static TextStream& operator<<(TextStream& ts, const RemoteLayerBackingStore& backingStore)
750 {
751     ts << backingStore.size();
752     ts << " scale=" << backingStore.scale();
753     if (backingStore.isOpaque())
754         ts << " opaque";
755     if (backingStore.acceleratesDrawing())
756         ts << " accelerated";
757     return ts;
758 }
759
760 static void dumpChangedLayers(TextStream& ts, const RemoteLayerTreeTransaction::LayerPropertiesMap& changedLayerProperties)
761 {
762     if (changedLayerProperties.isEmpty())
763         return;
764
765     TextStream::GroupScope group(ts);
766     ts << "changed-layers";
767
768     // Dump the layer properties sorted by layer ID.
769     auto layerIDs = copyToVector(changedLayerProperties.keys());
770     std::sort(layerIDs.begin(), layerIDs.end());
771
772     for (auto& layerID : layerIDs) {
773         const RemoteLayerTreeTransaction::LayerProperties& layerProperties = *changedLayerProperties.get(layerID);
774
775         TextStream::GroupScope group(ts);
776         ts << "layer " << layerID;
777
778         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::NameChanged)
779             ts.dumpProperty("name", layerProperties.name);
780
781         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ChildrenChanged)
782             ts.dumpProperty<Vector<WebCore::GraphicsLayer::PlatformLayerID>>("children", layerProperties.children);
783
784         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::PositionChanged)
785             ts.dumpProperty("position", layerProperties.position);
786
787         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BoundsChanged)
788             ts.dumpProperty("bounds", layerProperties.bounds);
789
790         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::AnchorPointChanged)
791             ts.dumpProperty("anchorPoint", layerProperties.anchorPoint);
792
793         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BackgroundColorChanged)
794             ts.dumpProperty("backgroundColor", layerProperties.backgroundColor);
795
796         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BorderColorChanged)
797             ts.dumpProperty("borderColor", layerProperties.borderColor);
798
799         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BorderWidthChanged)
800             ts.dumpProperty("borderWidth", layerProperties.borderWidth);
801
802         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::OpacityChanged)
803             ts.dumpProperty("opacity", layerProperties.opacity);
804
805         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::TransformChanged)
806             ts.dumpProperty("transform", layerProperties.transform ? *layerProperties.transform : WebCore::TransformationMatrix());
807
808         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::SublayerTransformChanged)
809             ts.dumpProperty("sublayerTransform", layerProperties.sublayerTransform ? *layerProperties.sublayerTransform : WebCore::TransformationMatrix());
810
811         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::HiddenChanged)
812             ts.dumpProperty("hidden", layerProperties.hidden);
813
814         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::GeometryFlippedChanged)
815             ts.dumpProperty("geometryFlipped", layerProperties.geometryFlipped);
816
817         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::DoubleSidedChanged)
818             ts.dumpProperty("doubleSided", layerProperties.doubleSided);
819
820         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MasksToBoundsChanged)
821             ts.dumpProperty("masksToBounds", layerProperties.masksToBounds);
822
823         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::OpaqueChanged)
824             ts.dumpProperty("opaque", layerProperties.opaque);
825
826         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ContentsHiddenChanged)
827             ts.dumpProperty("contentsHidden", layerProperties.contentsHidden);
828
829         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MaskLayerChanged)
830             ts.dumpProperty("maskLayer", layerProperties.maskLayerID);
831
832         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ClonedContentsChanged)
833             ts.dumpProperty("clonedLayer", layerProperties.clonedLayerID);
834
835         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ContentsRectChanged)
836             ts.dumpProperty("contentsRect", layerProperties.contentsRect);
837
838         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ContentsScaleChanged)
839             ts.dumpProperty("contentsScale", layerProperties.contentsScale);
840
841         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::CornerRadiusChanged)
842             ts.dumpProperty("cornerRadius", layerProperties.cornerRadius);
843
844         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ShapeRoundedRectChanged)
845             ts.dumpProperty("shapeRect", layerProperties.shapeRoundedRect ? *layerProperties.shapeRoundedRect : WebCore::FloatRoundedRect());
846
847         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MinificationFilterChanged)
848             ts.dumpProperty("minificationFilter", layerProperties.minificationFilter);
849
850         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MagnificationFilterChanged)
851             ts.dumpProperty("magnificationFilter", layerProperties.magnificationFilter);
852
853         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BlendModeChanged)
854             ts.dumpProperty("blendMode", layerProperties.blendMode);
855
856         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::SpeedChanged)
857             ts.dumpProperty("speed", layerProperties.speed);
858
859         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::TimeOffsetChanged)
860             ts.dumpProperty("timeOffset", layerProperties.timeOffset);
861
862         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BackingStoreChanged) {
863             if (const RemoteLayerBackingStore* backingStore = layerProperties.backingStore.get())
864                 ts.dumpProperty<const RemoteLayerBackingStore&>("backingStore", *backingStore);
865             else
866                 ts.dumpProperty("backingStore", "removed");
867         }
868
869         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BackingStoreAttachmentChanged)
870             ts.dumpProperty("backingStoreAttached", layerProperties.backingStoreAttached);
871
872         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::FiltersChanged)
873             ts.dumpProperty("filters", layerProperties.filters ? *layerProperties.filters : WebCore::FilterOperations());
874
875         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::AnimationsChanged) {
876             for (const auto& keyAnimationPair : layerProperties.addedAnimations)
877                 ts.dumpProperty("animation " +  keyAnimationPair.first, keyAnimationPair.second);
878
879             for (const auto& name : layerProperties.keyPathsOfAnimationsToRemove)
880                 ts.dumpProperty("removed animation", name);
881         }
882
883         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::EdgeAntialiasingMaskChanged)
884             ts.dumpProperty("edgeAntialiasingMask", layerProperties.edgeAntialiasingMask);
885
886         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::CustomAppearanceChanged)
887             ts.dumpProperty("customAppearance", layerProperties.customAppearance);
888
889         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::UserInteractionEnabledChanged)
890             ts.dumpProperty("userInteractionEnabled", layerProperties.userInteractionEnabled);
891     }
892 }
893
894 void RemoteLayerTreeTransaction::dump() const
895 {
896     fprintf(stderr, "%s", description().data());
897 }
898
899 CString RemoteLayerTreeTransaction::description() const
900 {
901     TextStream ts;
902
903     ts.startGroup();
904     ts << "layer tree";
905
906     ts.dumpProperty("transactionID", m_transactionID);
907     ts.dumpProperty("contentsSize", m_contentsSize);
908     if (m_scrollOrigin != WebCore::IntPoint::zero())
909         ts.dumpProperty("scrollOrigin", m_scrollOrigin);
910
911     ts.dumpProperty("baseLayoutViewportSize", WebCore::FloatSize(m_baseLayoutViewportSize));
912
913     if (m_minStableLayoutViewportOrigin != WebCore::LayoutPoint::zero())
914         ts.dumpProperty("minStableLayoutViewportOrigin", WebCore::FloatPoint(m_minStableLayoutViewportOrigin));
915     ts.dumpProperty("maxStableLayoutViewportOrigin", WebCore::FloatPoint(m_maxStableLayoutViewportOrigin));
916
917     if (m_pageScaleFactor != 1)
918         ts.dumpProperty("pageScaleFactor", m_pageScaleFactor);
919
920     ts.dumpProperty("minimumScaleFactor", m_minimumScaleFactor);
921     ts.dumpProperty("maximumScaleFactor", m_maximumScaleFactor);
922     ts.dumpProperty("initialScaleFactor", m_initialScaleFactor);
923     ts.dumpProperty("viewportMetaTagWidth", m_viewportMetaTagWidth);
924     ts.dumpProperty("viewportMetaTagWidthWasExplicit", m_viewportMetaTagWidthWasExplicit);
925     ts.dumpProperty("viewportMetaTagCameFromImageDocument", m_viewportMetaTagCameFromImageDocument);
926     ts.dumpProperty("allowsUserScaling", m_allowsUserScaling);
927     ts.dumpProperty("avoidsUnsafeArea", m_avoidsUnsafeArea);
928     ts.dumpProperty("isInStableState", m_isInStableState);
929     ts.dumpProperty("renderTreeSize", m_renderTreeSize);
930     ts.dumpProperty("root-layer", m_rootLayerID);
931
932     if (!m_createdLayers.isEmpty()) {
933         TextStream::GroupScope group(ts);
934         ts << "created-layers";
935         for (const auto& createdLayer : m_createdLayers) {
936             TextStream::GroupScope group(ts);
937             ts << createdLayer.type <<" " << createdLayer.layerID;
938             switch (createdLayer.type) {
939             case WebCore::PlatformCALayer::LayerTypeAVPlayerLayer:
940                 ts << " (context-id " << createdLayer.hostingContextID << ")";
941                 break;
942             case WebCore::PlatformCALayer::LayerTypeContentsProvidedLayer:
943                 ts << " (context-id " << createdLayer.hostingContextID << ")";
944                 break;
945             case WebCore::PlatformCALayer::LayerTypeCustom:
946                 ts << " (context-id " << createdLayer.hostingContextID << ")";
947                 break;
948             default:
949                 break;
950             }
951         }
952     }
953
954     dumpChangedLayers(ts, m_changedLayerProperties);
955
956     if (!m_destroyedLayerIDs.isEmpty())
957         ts.dumpProperty<Vector<WebCore::GraphicsLayer::PlatformLayerID>>("destroyed-layers", m_destroyedLayerIDs);
958
959     if (m_editorState) {
960         TextStream::GroupScope scope(ts);
961         ts << "EditorState";
962         ts << *m_editorState;
963     }
964
965     ts.endGroup();
966
967     return ts.release().utf8();
968 }
969
970 #endif // !defined(NDEBUG) || !LOG_DISABLED
971
972 } // namespace WebKit