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