Make it possible to detach GraphicsLayerCA backing store
[WebKit-https.git] / Source / WebKit2 / Shared / mac / 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 "MessageDecoder.h"
31 #import "MessageEncoder.h"
32 #import "PlatformCAAnimationRemote.h"
33 #import "PlatformCALayerRemote.h"
34 #import "WebCoreArgumentCoders.h"
35 #import <QuartzCore/QuartzCore.h>
36 #import <WebCore/LengthFunctions.h>
37 #import <WebCore/TextStream.h>
38 #import <WebCore/TimingFunction.h>
39 #import <wtf/text/CString.h>
40 #import <wtf/text/StringBuilder.h>
41
42 using namespace WebCore;
43
44 namespace WebKit {
45
46 RemoteLayerTreeTransaction::LayerCreationProperties::LayerCreationProperties()
47     : layerID(0)
48     , type(PlatformCALayer::LayerTypeLayer)
49     , hostingContextID(0)
50     , hostingDeviceScaleFactor(1)
51 {
52 }
53
54 void RemoteLayerTreeTransaction::LayerCreationProperties::encode(IPC::ArgumentEncoder& encoder) const
55 {
56     encoder << layerID;
57     encoder.encodeEnum(type);
58     encoder << hostingContextID;
59     encoder << hostingDeviceScaleFactor;
60 }
61
62 bool RemoteLayerTreeTransaction::LayerCreationProperties::decode(IPC::ArgumentDecoder& decoder, LayerCreationProperties& result)
63 {
64     if (!decoder.decode(result.layerID))
65         return false;
66
67     if (!decoder.decodeEnum(result.type))
68         return false;
69
70     if (!decoder.decode(result.hostingContextID))
71         return false;
72
73     if (!decoder.decode(result.hostingDeviceScaleFactor))
74         return false;
75
76     return true;
77 }
78
79 RemoteLayerTreeTransaction::LayerProperties::LayerProperties()
80     : changedProperties(NoChange)
81     , everChangedProperties(NoChange)
82     , anchorPoint(0.5, 0.5, 0)
83     , contentsRect(FloatPoint(), FloatSize(1, 1))
84     , maskLayerID(0)
85     , clonedLayerID(0)
86     , timeOffset(0)
87     , speed(1)
88     , contentsScale(1)
89     , cornerRadius(0)
90     , borderWidth(0)
91     , opacity(1)
92     , backgroundColor(Color::transparent)
93     , borderColor(Color::black)
94     , edgeAntialiasingMask(kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge)
95     , customAppearance(GraphicsLayer::NoCustomAppearance)
96     , minificationFilter(PlatformCALayer::FilterType::Linear)
97     , magnificationFilter(PlatformCALayer::FilterType::Linear)
98     , blendMode(BlendModeNormal)
99     , windRule(RULE_NONZERO)
100     , hidden(false)
101     , backingStoreAttached(true)
102     , geometryFlipped(false)
103     , doubleSided(true)
104     , masksToBounds(false)
105     , opaque(false)
106 {
107 }
108
109 RemoteLayerTreeTransaction::LayerProperties::LayerProperties(const LayerProperties& other)
110     : changedProperties(other.changedProperties)
111     , everChangedProperties(other.everChangedProperties)
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 {
144     // FIXME: LayerProperties should reference backing store by ID, so that two layers can have the same backing store (for clones).
145     // FIXME: LayerProperties shouldn't be copyable; PlatformCALayerRemote::clone should copy the relevant properties.
146
147     if (other.transform)
148         transform = std::make_unique<TransformationMatrix>(*other.transform);
149
150     if (other.sublayerTransform)
151         sublayerTransform = std::make_unique<TransformationMatrix>(*other.sublayerTransform);
152
153     if (other.filters)
154         filters = std::make_unique<FilterOperations>(*other.filters);
155 }
156
157 void RemoteLayerTreeTransaction::LayerProperties::encode(IPC::ArgumentEncoder& encoder) const
158 {
159     encoder.encodeEnum(changedProperties);
160
161     if (changedProperties & NameChanged)
162         encoder << name;
163
164     if (changedProperties & ChildrenChanged)
165         encoder << children;
166
167     if (changedProperties & AnimationsChanged) {
168         encoder << addedAnimations;
169         encoder << keyPathsOfAnimationsToRemove;
170     }
171
172     if (changedProperties & PositionChanged)
173         encoder << position;
174
175     if (changedProperties & BoundsChanged)
176         encoder << bounds;
177
178     if (changedProperties & BackgroundColorChanged)
179         encoder << backgroundColor;
180
181     if (changedProperties & AnchorPointChanged)
182         encoder << anchorPoint;
183
184     if (changedProperties & BorderWidthChanged)
185         encoder << borderWidth;
186
187     if (changedProperties & BorderColorChanged)
188         encoder << borderColor;
189
190     if (changedProperties & OpacityChanged)
191         encoder << opacity;
192
193     if (changedProperties & TransformChanged)
194         encoder << *transform;
195
196     if (changedProperties & SublayerTransformChanged)
197         encoder << *sublayerTransform;
198
199     if (changedProperties & HiddenChanged)
200         encoder << hidden;
201
202     if (changedProperties & GeometryFlippedChanged)
203         encoder << geometryFlipped;
204
205     if (changedProperties & DoubleSidedChanged)
206         encoder << doubleSided;
207
208     if (changedProperties & MasksToBoundsChanged)
209         encoder << masksToBounds;
210
211     if (changedProperties & OpaqueChanged)
212         encoder << opaque;
213
214     if (changedProperties & MaskLayerChanged)
215         encoder << maskLayerID;
216
217     if (changedProperties & ClonedContentsChanged)
218         encoder << clonedLayerID;
219
220     if (changedProperties & ContentsRectChanged)
221         encoder << contentsRect;
222
223     if (changedProperties & ContentsScaleChanged)
224         encoder << contentsScale;
225
226     if (changedProperties & CornerRadiusChanged)
227         encoder << cornerRadius;
228
229     if (changedProperties & ShapeRoundedRectChanged)
230         encoder << *shapeRoundedRect;
231
232     if (changedProperties & ShapePathChanged)
233         encoder << shapePath;
234
235     if (changedProperties & MinificationFilterChanged)
236         encoder.encodeEnum(minificationFilter);
237
238     if (changedProperties & MagnificationFilterChanged)
239         encoder.encodeEnum(magnificationFilter);
240
241     if (changedProperties & BlendModeChanged)
242         encoder.encodeEnum(blendMode);
243
244     if (changedProperties & WindRuleChanged)
245         encoder.encodeEnum(windRule);
246
247     if (changedProperties & SpeedChanged)
248         encoder << speed;
249
250     if (changedProperties & TimeOffsetChanged)
251         encoder << timeOffset;
252
253     if (changedProperties & BackingStoreChanged) {
254         bool hasFrontBuffer = backingStore && backingStore->hasFrontBuffer();
255         encoder << hasFrontBuffer;
256         if (hasFrontBuffer)
257             encoder << *backingStore;
258     }
259
260     if (changedProperties & BackingStoreAttachmentChanged)
261         encoder << backingStoreAttached;
262
263     if (changedProperties & FiltersChanged)
264         encoder << *filters;
265
266     if (changedProperties & EdgeAntialiasingMaskChanged)
267         encoder << edgeAntialiasingMask;
268
269     if (changedProperties & CustomAppearanceChanged)
270         encoder.encodeEnum(customAppearance);
271 }
272
273 bool RemoteLayerTreeTransaction::LayerProperties::decode(IPC::ArgumentDecoder& decoder, LayerProperties& result)
274 {
275     if (!decoder.decodeEnum(result.changedProperties))
276         return false;
277
278     if (result.changedProperties & NameChanged) {
279         if (!decoder.decode(result.name))
280             return false;
281     }
282
283     if (result.changedProperties & ChildrenChanged) {
284         if (!decoder.decode(result.children))
285             return false;
286
287         for (auto& layerID : result.children) {
288             if (!layerID)
289                 return false;
290         }
291     }
292
293     if (result.changedProperties & AnimationsChanged) {
294         if (!decoder.decode(result.addedAnimations))
295             return false;
296
297         if (!decoder.decode(result.keyPathsOfAnimationsToRemove))
298             return false;
299     }
300
301     if (result.changedProperties & PositionChanged) {
302         if (!decoder.decode(result.position))
303             return false;
304     }
305
306     if (result.changedProperties & BoundsChanged) {
307         if (!decoder.decode(result.bounds))
308             return false;
309     }
310
311     if (result.changedProperties & BackgroundColorChanged) {
312         if (!decoder.decode(result.backgroundColor))
313             return false;
314     }
315
316     if (result.changedProperties & AnchorPointChanged) {
317         if (!decoder.decode(result.anchorPoint))
318             return false;
319     }
320
321     if (result.changedProperties & BorderWidthChanged) {
322         if (!decoder.decode(result.borderWidth))
323             return false;
324     }
325
326     if (result.changedProperties & BorderColorChanged) {
327         if (!decoder.decode(result.borderColor))
328             return false;
329     }
330
331     if (result.changedProperties & OpacityChanged) {
332         if (!decoder.decode(result.opacity))
333             return false;
334     }
335
336     if (result.changedProperties & TransformChanged) {
337         TransformationMatrix transform;
338         if (!decoder.decode(transform))
339             return false;
340         
341         result.transform = std::make_unique<TransformationMatrix>(transform);
342     }
343
344     if (result.changedProperties & SublayerTransformChanged) {
345         TransformationMatrix transform;
346         if (!decoder.decode(transform))
347             return false;
348
349         result.sublayerTransform = std::make_unique<TransformationMatrix>(transform);
350     }
351
352     if (result.changedProperties & HiddenChanged) {
353         if (!decoder.decode(result.hidden))
354             return false;
355     }
356
357     if (result.changedProperties & GeometryFlippedChanged) {
358         if (!decoder.decode(result.geometryFlipped))
359             return false;
360     }
361
362     if (result.changedProperties & DoubleSidedChanged) {
363         if (!decoder.decode(result.doubleSided))
364             return false;
365     }
366
367     if (result.changedProperties & MasksToBoundsChanged) {
368         if (!decoder.decode(result.masksToBounds))
369             return false;
370     }
371
372     if (result.changedProperties & OpaqueChanged) {
373         if (!decoder.decode(result.opaque))
374             return false;
375     }
376
377     if (result.changedProperties & MaskLayerChanged) {
378         if (!decoder.decode(result.maskLayerID))
379             return false;
380     }
381
382     if (result.changedProperties & ClonedContentsChanged) {
383         if (!decoder.decode(result.clonedLayerID))
384             return false;
385     }
386
387     if (result.changedProperties & ContentsRectChanged) {
388         if (!decoder.decode(result.contentsRect))
389             return false;
390     }
391
392     if (result.changedProperties & ContentsScaleChanged) {
393         if (!decoder.decode(result.contentsScale))
394             return false;
395     }
396
397     if (result.changedProperties & CornerRadiusChanged) {
398         if (!decoder.decode(result.cornerRadius))
399             return false;
400     }
401
402     if (result.changedProperties & ShapeRoundedRectChanged) {
403         FloatRoundedRect roundedRect;
404         if (!decoder.decode(roundedRect))
405             return false;
406         
407         result.shapeRoundedRect = std::make_unique<FloatRoundedRect>(roundedRect);
408     }
409
410     if (result.changedProperties & ShapePathChanged) {
411         Path path;
412         if (!decoder.decode(path))
413             return false;
414         
415         result.shapePath = WTF::move(path);
416     }
417
418     if (result.changedProperties & MinificationFilterChanged) {
419         if (!decoder.decodeEnum(result.minificationFilter))
420             return false;
421     }
422
423     if (result.changedProperties & MagnificationFilterChanged) {
424         if (!decoder.decodeEnum(result.magnificationFilter))
425             return false;
426     }
427
428     if (result.changedProperties & BlendModeChanged) {
429         if (!decoder.decodeEnum(result.blendMode))
430             return false;
431     }
432
433     if (result.changedProperties & WindRuleChanged) {
434         if (!decoder.decodeEnum(result.windRule))
435             return false;
436     }
437
438     if (result.changedProperties & SpeedChanged) {
439         if (!decoder.decode(result.speed))
440             return false;
441     }
442
443     if (result.changedProperties & TimeOffsetChanged) {
444         if (!decoder.decode(result.timeOffset))
445             return false;
446     }
447
448     if (result.changedProperties & BackingStoreChanged) {
449         bool hasFrontBuffer = false;
450         if (!decoder.decode(hasFrontBuffer))
451             return false;
452         if (hasFrontBuffer) {
453             std::unique_ptr<RemoteLayerBackingStore> backingStore = std::make_unique<RemoteLayerBackingStore>(nullptr);
454             if (!decoder.decode(*backingStore))
455                 return false;
456             
457             result.backingStore = WTF::move(backingStore);
458         } else
459             result.backingStore = nullptr;
460     }
461
462     if (result.changedProperties & BackingStoreAttachmentChanged) {
463         if (!decoder.decode(result.backingStoreAttached))
464             return false;
465     }
466
467     if (result.changedProperties & FiltersChanged) {
468         std::unique_ptr<FilterOperations> filters = std::make_unique<FilterOperations>();
469         if (!decoder.decode(*filters))
470             return false;
471         result.filters = WTF::move(filters);
472     }
473
474     if (result.changedProperties & EdgeAntialiasingMaskChanged) {
475         if (!decoder.decode(result.edgeAntialiasingMask))
476             return false;
477     }
478
479     if (result.changedProperties & CustomAppearanceChanged) {
480         if (!decoder.decodeEnum(result.customAppearance))
481             return false;
482     }
483
484     return true;
485 }
486
487 RemoteLayerTreeTransaction::RemoteLayerTreeTransaction()
488     : m_pageScaleFactor(1)
489     , m_minimumScaleFactor(1)
490     , m_maximumScaleFactor(1)
491     , m_renderTreeSize(0)
492     , m_transactionID(0)
493     , m_scaleWasSetByUIProcess(false)
494     , m_allowsUserScaling(false)
495 {
496 }
497
498 RemoteLayerTreeTransaction::~RemoteLayerTreeTransaction()
499 {
500 }
501
502 void RemoteLayerTreeTransaction::encode(IPC::ArgumentEncoder& encoder) const
503 {
504     encoder << m_rootLayerID;
505     encoder << m_createdLayers;
506
507     encoder << static_cast<uint64_t>(m_changedLayers.size());
508
509     for (RefPtr<PlatformCALayerRemote> layer : m_changedLayers) {
510         encoder << layer->layerID();
511         encoder << layer->properties();
512     }
513     
514     encoder << m_destroyedLayerIDs;
515     encoder << m_videoLayerIDsPendingFullscreen;
516     encoder << m_layerIDsWithNewlyUnreachableBackingStore;
517
518     encoder << m_contentsSize;
519 #if PLATFORM(MAC)
520     encoder << m_scrollPosition;
521 #endif
522     encoder << m_pageExtendedBackgroundColor;
523     encoder << m_pageScaleFactor;
524     encoder << m_minimumScaleFactor;
525     encoder << m_maximumScaleFactor;
526
527     encoder << m_renderTreeSize;
528     encoder << m_transactionID;
529
530     encoder << m_scaleWasSetByUIProcess;
531     encoder << m_allowsUserScaling;
532
533     encoder << m_callbackIDs;
534 }
535
536 bool RemoteLayerTreeTransaction::decode(IPC::ArgumentDecoder& decoder, RemoteLayerTreeTransaction& result)
537 {
538     if (!decoder.decode(result.m_rootLayerID))
539         return false;
540     if (!result.m_rootLayerID)
541         return false;
542
543     if (!decoder.decode(result.m_createdLayers))
544         return false;
545
546     uint64_t numChangedLayerProperties;
547     if (!decoder.decode(numChangedLayerProperties))
548         return false;
549
550     for (uint64_t i = 0; i < numChangedLayerProperties; ++i) {
551         GraphicsLayer::PlatformLayerID layerID;
552         if (!decoder.decode(layerID))
553             return false;
554
555         std::unique_ptr<LayerProperties> layerProperties = std::make_unique<LayerProperties>();
556         if (!decoder.decode(*layerProperties))
557             return false;
558
559         result.changedLayerProperties().set(layerID, WTF::move(layerProperties));
560     }
561
562     if (!decoder.decode(result.m_destroyedLayerIDs))
563         return false;
564
565     for (auto& layerID : result.m_destroyedLayerIDs) {
566         if (!layerID)
567             return false;
568     }
569
570     if (!decoder.decode(result.m_videoLayerIDsPendingFullscreen))
571         return false;
572
573     if (!decoder.decode(result.m_layerIDsWithNewlyUnreachableBackingStore))
574         return false;
575
576     for (auto& layerID : result.m_layerIDsWithNewlyUnreachableBackingStore) {
577         if (!layerID)
578             return false;
579     }
580
581     if (!decoder.decode(result.m_contentsSize))
582         return false;
583
584 #if PLATFORM(MAC)
585     if (!decoder.decode(result.m_scrollPosition))
586         return false;
587 #endif
588     
589     if (!decoder.decode(result.m_pageExtendedBackgroundColor))
590         return false;
591
592     if (!decoder.decode(result.m_pageScaleFactor))
593         return false;
594
595     if (!decoder.decode(result.m_minimumScaleFactor))
596         return false;
597
598     if (!decoder.decode(result.m_maximumScaleFactor))
599         return false;
600
601     if (!decoder.decode(result.m_renderTreeSize))
602         return false;
603
604     if (!decoder.decode(result.m_transactionID))
605         return false;
606
607     if (!decoder.decode(result.m_scaleWasSetByUIProcess))
608         return false;
609
610     if (!decoder.decode(result.m_allowsUserScaling))
611         return false;
612
613     if (!decoder.decode(result.m_callbackIDs))
614         return false;
615
616     return true;
617 }
618
619 void RemoteLayerTreeTransaction::setRootLayerID(GraphicsLayer::PlatformLayerID rootLayerID)
620 {
621     ASSERT_ARG(rootLayerID, rootLayerID);
622
623     m_rootLayerID = rootLayerID;
624 }
625
626 void RemoteLayerTreeTransaction::layerPropertiesChanged(PlatformCALayerRemote& remoteLayer)
627 {
628     m_changedLayers.append(&remoteLayer);
629 }
630
631 void RemoteLayerTreeTransaction::setCreatedLayers(Vector<LayerCreationProperties> createdLayers)
632 {
633     m_createdLayers = WTF::move(createdLayers);
634 }
635
636 void RemoteLayerTreeTransaction::setDestroyedLayerIDs(Vector<GraphicsLayer::PlatformLayerID> destroyedLayerIDs)
637 {
638     m_destroyedLayerIDs = WTF::move(destroyedLayerIDs);
639 }
640
641 void RemoteLayerTreeTransaction::setLayerIDsWithNewlyUnreachableBackingStore(Vector<GraphicsLayer::PlatformLayerID> layerIDsWithNewlyUnreachableBackingStore)
642 {
643     m_layerIDsWithNewlyUnreachableBackingStore = WTF::move(layerIDsWithNewlyUnreachableBackingStore);
644 }
645
646 #if !defined(NDEBUG) || !LOG_DISABLED
647
648 class RemoteLayerTreeTextStream : public TextStream
649 {
650 public:
651     using TextStream::operator<<;
652
653     RemoteLayerTreeTextStream()
654         : m_indent(0)
655     {
656     }
657
658     RemoteLayerTreeTextStream& operator<<(const TransformationMatrix&);
659     RemoteLayerTreeTextStream& operator<<(PlatformCALayer::FilterType);
660     RemoteLayerTreeTextStream& operator<<(const FloatRoundedRect&);
661     RemoteLayerTreeTextStream& operator<<(FloatPoint3D);
662     RemoteLayerTreeTextStream& operator<<(Color);
663     RemoteLayerTreeTextStream& operator<<(FloatRect);
664     RemoteLayerTreeTextStream& operator<<(const Vector<WebCore::GraphicsLayer::PlatformLayerID>&);
665     RemoteLayerTreeTextStream& operator<<(const FilterOperation&);
666     RemoteLayerTreeTextStream& operator<<(const FilterOperations&);
667     RemoteLayerTreeTextStream& operator<<(const PlatformCAAnimationRemote::Properties&);
668     RemoteLayerTreeTextStream& operator<<(const RemoteLayerBackingStore&);
669     RemoteLayerTreeTextStream& operator<<(BlendMode);
670     RemoteLayerTreeTextStream& operator<<(PlatformCAAnimation::AnimationType);
671     RemoteLayerTreeTextStream& operator<<(PlatformCAAnimation::FillModeType);
672     RemoteLayerTreeTextStream& operator<<(PlatformCAAnimation::ValueFunctionType);
673     RemoteLayerTreeTextStream& operator<<(const TimingFunction&);
674     RemoteLayerTreeTextStream& operator<<(const PlatformCAAnimationRemote::KeyframeValue&);
675
676     void increaseIndent() { ++m_indent; }
677     void decreaseIndent() { --m_indent; ASSERT(m_indent >= 0); }
678
679     void writeIndent();
680
681 private:
682     int m_indent;
683 };
684
685 template <class T>
686 static void dumpProperty(RemoteLayerTreeTextStream& ts, String name, T value)
687 {
688     ts << "\n";
689     ts.increaseIndent();
690     ts.writeIndent();
691     ts << "(" << name << " ";
692     ts << value << ")";
693     ts.decreaseIndent();
694 }
695
696 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const TransformationMatrix& transform)
697 {
698     RemoteLayerTreeTextStream& ts = *this;
699     ts << "\n";
700     ts.increaseIndent();
701     ts.writeIndent();
702     ts << "[" << transform.m11() << " " << transform.m12() << " " << transform.m13() << " " << transform.m14() << "]\n";
703     ts.writeIndent();
704     ts << "[" << transform.m21() << " " << transform.m22() << " " << transform.m23() << " " << transform.m24() << "]\n";
705     ts.writeIndent();
706     ts << "[" << transform.m31() << " " << transform.m32() << " " << transform.m33() << " " << transform.m34() << "]\n";
707     ts.writeIndent();
708     ts << "[" << transform.m41() << " " << transform.m42() << " " << transform.m43() << " " << transform.m44() << "]";
709     ts.decreaseIndent();
710     return ts;
711 }
712
713 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const FloatRoundedRect& roundedRect)
714 {
715     RemoteLayerTreeTextStream& ts = *this;
716     ts << roundedRect.rect().x() << " " << roundedRect.rect().y() << " " << roundedRect.rect().width() << " " << roundedRect.rect().height() << "\n";
717
718     ts.increaseIndent();
719     ts.writeIndent();
720     ts << "topLeft=" << roundedRect.topLeftCorner().width() << " " << roundedRect.topLeftCorner().height() << "\n";
721     ts.writeIndent();
722     ts << "topRight=" << roundedRect.topRightCorner().width() << " " << roundedRect.topRightCorner().height() << "\n";
723     ts.writeIndent();
724     ts << "bottomLeft=" << roundedRect.bottomLeftCorner().width() << " " << roundedRect.bottomLeftCorner().height() << "\n";
725     ts.writeIndent();
726     ts << "bottomRight=" << roundedRect.bottomRightCorner().width() << " " << roundedRect.bottomRightCorner().height();
727     ts.decreaseIndent();
728
729     return ts;
730 }
731
732 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(PlatformCALayer::FilterType filterType)
733 {
734     RemoteLayerTreeTextStream& ts = *this;
735     switch (filterType) {
736     case PlatformCALayer::Linear:
737         ts << "linear";
738         break;
739     case PlatformCALayer::Nearest:
740         ts << "nearest";
741         break;
742     case PlatformCALayer::Trilinear:
743         ts << "trilinear";
744         break;
745     default:
746         ASSERT_NOT_REACHED();
747         break;
748     }
749     return ts;
750 }
751
752 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const FilterOperations& filters)
753 {
754     RemoteLayerTreeTextStream& ts = *this;
755     for (size_t i = 0; i < filters.size(); ++i) {
756         const auto filter = filters.at(i);
757         if (filter)
758             ts << *filter;
759         else
760             ts << "(null)";
761         if (i < filters.size() - 1)
762             ts << " ";
763     }
764     return ts;
765 }
766     
767 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const FilterOperation& filter)
768 {
769     RemoteLayerTreeTextStream& ts = *this;
770     switch (filter.type()) {
771     case FilterOperation::REFERENCE:
772         ts << "reference";
773         break;
774     case FilterOperation::GRAYSCALE: {
775         const auto& colorMatrixFilter = downcast<BasicColorMatrixFilterOperation>(filter);
776         ts << "grayscale(" << colorMatrixFilter.amount() << ")";
777         break;
778     }
779     case FilterOperation::SEPIA: {
780         const auto& colorMatrixFilter = downcast<BasicColorMatrixFilterOperation>(filter);
781         ts << "sepia(" << colorMatrixFilter.amount() << ")";
782         break;
783     }
784     case FilterOperation::SATURATE: {
785         const auto& colorMatrixFilter = downcast<BasicColorMatrixFilterOperation>(filter);
786         ts << "saturate(" << colorMatrixFilter.amount() << ")";
787         break;
788     }
789     case FilterOperation::HUE_ROTATE: {
790         const auto& colorMatrixFilter = downcast<BasicColorMatrixFilterOperation>(filter);
791         ts << "hue-rotate(" << colorMatrixFilter.amount() << ")";
792         break;
793     }
794     case FilterOperation::INVERT: {
795         const auto& componentTransferFilter = downcast<BasicComponentTransferFilterOperation>(filter);
796         ts << "invert(" << componentTransferFilter.amount() << ")";
797         break;
798     }
799     case FilterOperation::OPACITY: {
800         const auto& componentTransferFilter = downcast<BasicComponentTransferFilterOperation>(filter);
801         ts << "opacity(" << componentTransferFilter.amount() << ")";
802         break;
803     }
804     case FilterOperation::BRIGHTNESS: {
805         const auto& componentTransferFilter = downcast<BasicComponentTransferFilterOperation>(filter);
806         ts << "brightness(" << componentTransferFilter.amount() << ")";
807         break;
808     }
809     case FilterOperation::CONTRAST: {
810         const auto& componentTransferFilter = downcast<BasicComponentTransferFilterOperation>(filter);
811         ts << "contrast(" << componentTransferFilter.amount() << ")";
812         break;
813     }
814     case FilterOperation::BLUR: {
815         const auto& blurFilter = downcast<BlurFilterOperation>(filter);
816         ts << "blur(" << floatValueForLength(blurFilter.stdDeviation(), 0) << ")";
817         break;
818     }
819     case FilterOperation::DROP_SHADOW: {
820         const auto& dropShadowFilter = downcast<DropShadowFilterOperation>(filter);
821         ts << "drop-shadow(" << dropShadowFilter.x() << " " << dropShadowFilter.y() << " " << dropShadowFilter.location() << " ";
822         ts << dropShadowFilter.color() << ")";
823         break;
824     }
825     case FilterOperation::PASSTHROUGH:
826         ts << "passthrough";
827         break;
828     case FilterOperation::DEFAULT: {
829         const auto& defaultFilter = downcast<DefaultFilterOperation>(filter);
830         ts << "default type=" << (int)defaultFilter.representedType();
831         break;
832     }
833     case FilterOperation::NONE:
834         ts << "none";
835         break;
836     }
837     return ts;
838 }
839
840 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(BlendMode blendMode)
841 {
842     RemoteLayerTreeTextStream& ts = *this;
843     switch (blendMode) {
844     case BlendModeNormal: ts << "normal"; break;
845     case BlendModeMultiply: ts << "multiply"; break;
846     case BlendModeScreen: ts << "screen"; break;
847     case BlendModeOverlay: ts << "overlay"; break;
848     case BlendModeDarken: ts << "darken"; break;
849     case BlendModeLighten: ts << "lighten"; break;
850     case BlendModeColorDodge: ts << "color-dodge"; break;
851     case BlendModeColorBurn: ts << "color-burn"; break;
852     case BlendModeHardLight: ts << "hard-light"; break;
853     case BlendModeSoftLight: ts << "soft-light"; break;
854     case BlendModeDifference: ts << "difference"; break;
855     case BlendModeExclusion: ts << "exclusion"; break;
856     case BlendModeHue: ts << "hue"; break;
857     case BlendModeSaturation: ts << "saturation"; break;
858     case BlendModeColor: ts << "color"; break;
859     case BlendModeLuminosity: ts << "luminosity"; break;
860     case BlendModePlusDarker: ts << "plus-darker"; break;
861     case BlendModePlusLighter: ts << "plus-lighter"; break;
862     }
863     return ts;
864 }
865
866 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(PlatformCAAnimation::AnimationType type)
867 {
868     RemoteLayerTreeTextStream& ts = *this;
869     switch (type) {
870     case PlatformCAAnimation::Basic: ts << "basic"; break;
871     case PlatformCAAnimation::Keyframe: ts << "keyframe"; break;
872     }
873     return ts;
874 }
875
876 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(PlatformCAAnimation::FillModeType type)
877 {
878     RemoteLayerTreeTextStream& ts = *this;
879     switch (type) {
880     case PlatformCAAnimation::NoFillMode: ts << "none"; break;
881     case PlatformCAAnimation::Forwards: ts << "forwards"; break;
882     case PlatformCAAnimation::Backwards: ts << "backwards"; break;
883     case PlatformCAAnimation::Both: ts << "both"; break;
884     }
885     return ts;
886 }
887
888 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(PlatformCAAnimation::ValueFunctionType type)
889 {
890     RemoteLayerTreeTextStream& ts = *this;
891     switch (type) {
892     case PlatformCAAnimation::NoValueFunction: ts << "none"; break;
893     case PlatformCAAnimation::RotateX: ts << "rotateX"; break;
894     case PlatformCAAnimation::RotateY: ts << "rotateY"; break;
895     case PlatformCAAnimation::RotateZ: ts << "rotateX"; break;
896     case PlatformCAAnimation::ScaleX: ts << "scaleX"; break;
897     case PlatformCAAnimation::ScaleY: ts << "scaleY"; break;
898     case PlatformCAAnimation::ScaleZ: ts << "scaleX"; break;
899     case PlatformCAAnimation::Scale: ts << "scale"; break;
900     case PlatformCAAnimation::TranslateX: ts << "translateX"; break;
901     case PlatformCAAnimation::TranslateY: ts << "translateY"; break;
902     case PlatformCAAnimation::TranslateZ: ts << "translateZ"; break;
903     case PlatformCAAnimation::Translate: ts << "translate"; break;
904     }
905     return ts;
906 }
907
908 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const PlatformCAAnimationRemote::KeyframeValue& value)
909 {
910     RemoteLayerTreeTextStream& ts = *this;
911
912     switch (value.keyframeType()) {
913     case PlatformCAAnimationRemote::KeyframeValue::NumberKeyType:
914         ts << "number=" << value.numberValue();
915         break;
916     case PlatformCAAnimationRemote::KeyframeValue::ColorKeyType:
917         ts << "color=";
918         ts << value.colorValue();
919         break;
920     case PlatformCAAnimationRemote::KeyframeValue::PointKeyType:
921         ts << "point=";
922         ts << value.pointValue();
923         break;
924     case PlatformCAAnimationRemote::KeyframeValue::TransformKeyType:
925         ts << "transform=";
926         ts << value.transformValue();
927         break;
928     case PlatformCAAnimationRemote::KeyframeValue::FilterKeyType:
929         ts << "filter=";
930         if (value.filterValue())
931             ts << *value.filterValue();
932         else
933             ts << "null";
934         break;
935     }
936     return ts;
937 }
938
939 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const TimingFunction& timingFunction)
940 {
941     RemoteLayerTreeTextStream& ts = *this;
942     switch (timingFunction.type()) {
943     case TimingFunction::LinearFunction:
944         ts << "linear";
945         break;
946     case TimingFunction::CubicBezierFunction: {
947         const CubicBezierTimingFunction& cubicBezierFunction = static_cast<const CubicBezierTimingFunction&>(timingFunction);
948         ts << "cubic-bezier(" << cubicBezierFunction.x1() << ", " << cubicBezierFunction.y1() << ", " <<  cubicBezierFunction.x2() << ", " << cubicBezierFunction.y2() << ")";
949         break;
950     }
951     case TimingFunction::StepsFunction: {
952         const StepsTimingFunction& stepsFunction = static_cast<const StepsTimingFunction&>(timingFunction);
953         ts << "steps(" << stepsFunction.numberOfSteps() << ", " << (stepsFunction.stepAtStart() ? "start" : "end") << ")";
954         break;
955     }
956     }
957     return ts;
958 }
959
960 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const PlatformCAAnimationRemote::Properties& animation)
961 {
962     RemoteLayerTreeTextStream& ts = *this;
963
964     ts << "type=";
965     ts << animation.animationType;
966     ts << " keyPath=";
967     ts << animation.keyPath;
968
969     if (animation.beginTime)
970         dumpProperty(ts, "beginTime", animation.beginTime);
971
972     if (animation.duration)
973         dumpProperty(ts, "duration", animation.duration);
974
975     if (animation.timeOffset)
976         dumpProperty(ts, "timeOffset", animation.timeOffset);
977
978     dumpProperty(ts, "repeatCount", animation.repeatCount);
979
980     if (animation.speed != 1)
981         dumpProperty(ts, "speed", animation.speed);
982
983     dumpProperty(ts, "fillMode", animation.fillMode);
984     dumpProperty(ts, "valueFunction", animation.valueFunction);
985
986     if (animation.autoReverses)
987         dumpProperty(ts, "autoReverses", animation.autoReverses);
988
989     if (!animation.removedOnCompletion)
990         dumpProperty(ts, "removedOnCompletion", animation.removedOnCompletion);
991
992     if (animation.additive)
993         dumpProperty(ts, "additive", animation.additive);
994
995     if (animation.reverseTimingFunctions)
996         dumpProperty(ts, "reverseTimingFunctions", animation.reverseTimingFunctions);
997
998     if (animation.hasExplicitBeginTime)
999         dumpProperty(ts, "hasExplicitBeginTime", animation.hasExplicitBeginTime);
1000
1001     ts << "\n";
1002     ts.increaseIndent();
1003     ts.writeIndent();
1004     ts << "(" << "keyframes";
1005     ts.increaseIndent();
1006
1007     size_t maxFrames = std::max(animation.keyValues.size(), animation.keyTimes.size());
1008     maxFrames = std::max(maxFrames, animation.timingFunctions.size());
1009
1010     for (size_t i = 0; i < maxFrames; ++i) {
1011         ts << "\n";
1012         ts.writeIndent();
1013         ts << "(keyframe " << unsigned(i);
1014         if (i < animation.keyTimes.size())
1015             dumpProperty(ts, "time", animation.keyTimes[i]);
1016
1017         if (i < animation.timingFunctions.size() && animation.timingFunctions[i])
1018             dumpProperty<const TimingFunction&>(ts, "timing function", *animation.timingFunctions[i]);
1019
1020         if (i < animation.keyValues.size())
1021             dumpProperty(ts, "value", animation.keyValues[i]);
1022
1023         ts << ")";
1024     }
1025
1026     ts.decreaseIndent();
1027     ts.decreaseIndent();
1028
1029     return ts;
1030 }
1031
1032 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(FloatPoint3D point)
1033 {
1034     RemoteLayerTreeTextStream& ts = *this;
1035     ts << point.x() << " " << point.y() << " " << point.z();
1036     return ts;
1037 }
1038
1039 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(Color color)
1040 {
1041     RemoteLayerTreeTextStream& ts = *this;
1042     ts << color.serialized();
1043     return ts;
1044 }
1045
1046 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(FloatRect rect)
1047 {
1048     RemoteLayerTreeTextStream& ts = *this;
1049     ts << rect.x() << " " << rect.y() << " " << rect.width() << " " << rect.height();
1050     return ts;
1051 }
1052
1053 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const Vector<GraphicsLayer::PlatformLayerID>& layers)
1054 {
1055     RemoteLayerTreeTextStream& ts = *this;
1056
1057     for (size_t i = 0; i < layers.size(); ++i) {
1058         if (i)
1059             ts << " ";
1060         ts << layers[i];
1061     }
1062
1063     return ts;
1064 }
1065
1066 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const RemoteLayerBackingStore& backingStore)
1067 {
1068     RemoteLayerTreeTextStream& ts = *this;
1069     ts << backingStore.size();
1070     ts << " scale=" << backingStore.scale();
1071     if (backingStore.isOpaque())
1072         ts << " opaque";
1073     if (backingStore.acceleratesDrawing())
1074         ts << " accelerated";
1075     return ts;
1076 }
1077
1078 void RemoteLayerTreeTextStream::writeIndent()
1079 {
1080     for (int i = 0; i < m_indent; ++i)
1081         *this << "  ";
1082 }
1083
1084 static void dumpChangedLayers(RemoteLayerTreeTextStream& ts, const RemoteLayerTreeTransaction::LayerPropertiesMap& changedLayerProperties)
1085 {
1086     if (changedLayerProperties.isEmpty())
1087         return;
1088
1089     ts << "\n";
1090     ts.writeIndent();
1091     ts << "(changed-layers";
1092
1093     // Dump the layer properties sorted by layer ID.
1094     Vector<GraphicsLayer::PlatformLayerID> layerIDs;
1095     copyKeysToVector(changedLayerProperties, layerIDs);
1096     std::sort(layerIDs.begin(), layerIDs.end());
1097
1098     for (auto& layerID : layerIDs) {
1099         const RemoteLayerTreeTransaction::LayerProperties& layerProperties = *changedLayerProperties.get(layerID);
1100
1101         ts << "\n";
1102         ts.increaseIndent();
1103         ts.writeIndent();
1104         ts << "(layer " << layerID;
1105
1106         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::NameChanged)
1107             dumpProperty(ts, "name", layerProperties.name);
1108
1109         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ChildrenChanged)
1110             dumpProperty<Vector<GraphicsLayer::PlatformLayerID>>(ts, "children", layerProperties.children);
1111
1112         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::PositionChanged)
1113             dumpProperty(ts, "position", layerProperties.position);
1114
1115         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BoundsChanged)
1116             dumpProperty(ts, "bounds", layerProperties.bounds);
1117
1118         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::AnchorPointChanged)
1119             dumpProperty(ts, "anchorPoint", layerProperties.anchorPoint);
1120
1121         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BackgroundColorChanged)
1122             dumpProperty(ts, "backgroundColor", layerProperties.backgroundColor);
1123
1124         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BorderColorChanged)
1125             dumpProperty(ts, "borderColor", layerProperties.borderColor);
1126
1127         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BorderWidthChanged)
1128             dumpProperty(ts, "borderWidth", layerProperties.borderWidth);
1129
1130         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::OpacityChanged)
1131             dumpProperty(ts, "opacity", layerProperties.opacity);
1132
1133         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::TransformChanged)
1134             dumpProperty(ts, "transform", layerProperties.transform ? *layerProperties.transform : TransformationMatrix());
1135
1136         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::SublayerTransformChanged)
1137             dumpProperty(ts, "sublayerTransform", layerProperties.sublayerTransform ? *layerProperties.sublayerTransform : TransformationMatrix());
1138
1139         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::HiddenChanged)
1140             dumpProperty(ts, "hidden", layerProperties.hidden);
1141
1142         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::GeometryFlippedChanged)
1143             dumpProperty(ts, "geometryFlipped", layerProperties.geometryFlipped);
1144
1145         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::DoubleSidedChanged)
1146             dumpProperty(ts, "doubleSided", layerProperties.doubleSided);
1147
1148         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MasksToBoundsChanged)
1149             dumpProperty(ts, "masksToBounds", layerProperties.masksToBounds);
1150
1151         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::OpaqueChanged)
1152             dumpProperty(ts, "opaque", layerProperties.opaque);
1153
1154         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MaskLayerChanged)
1155             dumpProperty(ts, "maskLayer", layerProperties.maskLayerID);
1156
1157         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ClonedContentsChanged)
1158             dumpProperty(ts, "clonedLayer", layerProperties.clonedLayerID);
1159
1160         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ContentsRectChanged)
1161             dumpProperty(ts, "contentsRect", layerProperties.contentsRect);
1162
1163         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ContentsScaleChanged)
1164             dumpProperty(ts, "contentsScale", layerProperties.contentsScale);
1165
1166         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::CornerRadiusChanged)
1167             dumpProperty(ts, "cornerRadius", layerProperties.cornerRadius);
1168
1169         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ShapeRoundedRectChanged)
1170             dumpProperty(ts, "shapeRect", layerProperties.shapeRoundedRect ? *layerProperties.shapeRoundedRect : FloatRoundedRect());
1171
1172         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MinificationFilterChanged)
1173             dumpProperty(ts, "minificationFilter", layerProperties.minificationFilter);
1174
1175         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MagnificationFilterChanged)
1176             dumpProperty(ts, "magnificationFilter", layerProperties.magnificationFilter);
1177
1178         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BlendModeChanged)
1179             dumpProperty(ts, "blendMode", layerProperties.blendMode);
1180
1181         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::SpeedChanged)
1182             dumpProperty(ts, "speed", layerProperties.speed);
1183
1184         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::TimeOffsetChanged)
1185             dumpProperty(ts, "timeOffset", layerProperties.timeOffset);
1186
1187         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BackingStoreChanged) {
1188             if (const RemoteLayerBackingStore* backingStore = layerProperties.backingStore.get())
1189                 dumpProperty<const RemoteLayerBackingStore&>(ts, "backingStore", *backingStore);
1190             else
1191                 dumpProperty(ts, "backingStore", "removed");
1192         }
1193
1194         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BackingStoreAttachmentChanged)
1195             dumpProperty(ts, "backingStoreAttached", layerProperties.backingStoreAttached);
1196
1197         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::FiltersChanged)
1198             dumpProperty(ts, "filters", layerProperties.filters ? *layerProperties.filters : FilterOperations());
1199
1200         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::AnimationsChanged) {
1201             for (const auto& keyAnimationPair : layerProperties.addedAnimations)
1202                 dumpProperty(ts, "animation " +  keyAnimationPair.first, keyAnimationPair.second);
1203
1204             for (const auto& name : layerProperties.keyPathsOfAnimationsToRemove)
1205                 dumpProperty(ts, "removed animation", name);
1206         }
1207
1208         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::EdgeAntialiasingMaskChanged)
1209             dumpProperty(ts, "edgeAntialiasingMask", layerProperties.edgeAntialiasingMask);
1210
1211         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::CustomAppearanceChanged)
1212             dumpProperty(ts, "customAppearance", layerProperties.customAppearance);
1213
1214         ts << ")";
1215
1216         ts.decreaseIndent();
1217     }
1218
1219     ts.decreaseIndent();
1220 }
1221
1222 void RemoteLayerTreeTransaction::dump() const
1223 {
1224     fprintf(stderr, "%s", description().data());
1225 }
1226
1227 CString RemoteLayerTreeTransaction::description() const
1228 {
1229     RemoteLayerTreeTextStream ts;
1230
1231     ts << "(\n";
1232     ts.increaseIndent();
1233     ts.writeIndent();
1234     ts << "(root-layer " << m_rootLayerID << ")";
1235
1236     if (!m_createdLayers.isEmpty()) {
1237         ts << "\n";
1238         ts.writeIndent();
1239         ts << "(created-layers";
1240         ts.increaseIndent();
1241         for (const auto& createdLayer : m_createdLayers) {
1242             ts << "\n";
1243             ts.writeIndent();
1244             ts << "(";
1245             switch (createdLayer.type) {
1246             case PlatformCALayer::LayerTypeLayer:
1247             case PlatformCALayer::LayerTypeWebLayer:
1248             case PlatformCALayer::LayerTypeSimpleLayer:
1249                 ts << "layer";
1250                 break;
1251             case PlatformCALayer::LayerTypeTransformLayer:
1252                 ts << "transform-layer";
1253                 break;
1254             case PlatformCALayer::LayerTypeWebTiledLayer:
1255                 ts << "tiled-layer";
1256                 break;
1257             case PlatformCALayer::LayerTypeTiledBackingLayer:
1258                 ts << "tiled-backing-layer";
1259                 break;
1260             case PlatformCALayer::LayerTypePageTiledBackingLayer:
1261                 ts << "page-tiled-backing-layer";
1262                 break;
1263             case PlatformCALayer::LayerTypeTiledBackingTileLayer:
1264                 ts << "tiled-backing-tile";
1265                 break;
1266             case PlatformCALayer::LayerTypeRootLayer:
1267                 ts << "root-layer";
1268                 break;
1269             case PlatformCALayer::LayerTypeBackdropLayer:
1270                 ts << "backdrop-layer";
1271                 break;
1272             case PlatformCALayer::LayerTypeAVPlayerLayer:
1273                 ts << "av-player-layer (context-id " << createdLayer.hostingContextID << ")";
1274                 break;
1275             case PlatformCALayer::LayerTypeWebGLLayer:
1276                 ts << "web-gl-layer (context-id " << createdLayer.hostingContextID << ")";
1277                 break;
1278             case PlatformCALayer::LayerTypeShapeLayer:
1279                 ts << "shape-layer";
1280                 break;
1281             case PlatformCALayer::LayerTypeScrollingLayer:
1282                 ts << "scrolling-layer";
1283                 break;
1284             case PlatformCALayer::LayerTypeCustom:
1285                 ts << "custom-layer (context-id " << createdLayer.hostingContextID << ")";
1286                 break;
1287             case PlatformCALayer::LayerTypeLightSystemBackdropLayer:
1288                 ts << "light-system-backdrop-layer";
1289                 break;
1290             case PlatformCALayer::LayerTypeDarkSystemBackdropLayer:
1291                 ts << "dark-system-backdrop-layer";
1292                 break;
1293             }
1294             ts << " " << createdLayer.layerID << ")";
1295         }
1296         ts << ")";
1297         ts.decreaseIndent();
1298     }
1299
1300     dumpChangedLayers(ts, m_changedLayerProperties);
1301
1302     if (!m_destroyedLayerIDs.isEmpty())
1303         dumpProperty<Vector<GraphicsLayer::PlatformLayerID>>(ts, "destroyed-layers", m_destroyedLayerIDs);
1304
1305     ts << ")\n";
1306
1307     return ts.release().utf8();
1308 }
1309
1310 #endif // !defined(NDEBUG) || !LOG_DISABLED
1311
1312 } // namespace WebKit