[UI-side compositing] Proxy animations to the UI process
[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 "PlatformCALayerRemote.h"
33 #import "WebCoreArgumentCoders.h"
34 #import <QuartzCore/QuartzCore.h>
35 #import <WebCore/TextStream.h>
36 #import <wtf/text/CString.h>
37 #import <wtf/text/StringBuilder.h>
38
39 using namespace WebCore;
40
41 namespace WebKit {
42
43 RemoteLayerTreeTransaction::LayerCreationProperties::LayerCreationProperties()
44     : layerID(0)
45     , type(PlatformCALayer::LayerTypeLayer)
46     , hostingContextID(0)
47 {
48 }
49
50 void RemoteLayerTreeTransaction::LayerCreationProperties::encode(IPC::ArgumentEncoder& encoder) const
51 {
52     encoder << layerID;
53     encoder.encodeEnum(type);
54
55     if (type == PlatformCALayer::LayerTypeCustom)
56         encoder << hostingContextID;
57 }
58
59 bool RemoteLayerTreeTransaction::LayerCreationProperties::decode(IPC::ArgumentDecoder& decoder, LayerCreationProperties& result)
60 {
61     if (!decoder.decode(result.layerID))
62         return false;
63
64     if (!decoder.decodeEnum(result.type))
65         return false;
66
67     if (result.type == PlatformCALayer::LayerTypeCustom) {
68         if (!decoder.decode(result.hostingContextID))
69             return false;
70     }
71
72     return true;
73 }
74
75 RemoteLayerTreeTransaction::LayerProperties::LayerProperties()
76     : changedProperties(NoChange)
77     , everChangedProperties(NoChange)
78     , anchorPoint(0.5, 0.5, 0)
79     , contentsRect(FloatPoint(), FloatSize(1, 1))
80     , maskLayerID(0)
81     , timeOffset(0)
82     , speed(1)
83     , contentsScale(1)
84     , borderWidth(0)
85     , opacity(1)
86     , backgroundColor(Color::transparent)
87     , borderColor(Color::black)
88     , edgeAntialiasingMask(kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge)
89     , customAppearance(GraphicsLayer::NoCustomAppearance)
90     , customBehavior(GraphicsLayer::NoCustomBehavior)
91     , minificationFilter(PlatformCALayer::FilterType::Linear)
92     , magnificationFilter(PlatformCALayer::FilterType::Linear)
93     , hidden(false)
94     , geometryFlipped(false)
95     , doubleSided(true)
96     , masksToBounds(false)
97     , opaque(false)
98 {
99 }
100
101 RemoteLayerTreeTransaction::LayerProperties::LayerProperties(const LayerProperties& other)
102     : changedProperties(other.changedProperties)
103     , everChangedProperties(other.everChangedProperties)
104     , name(other.name)
105     , children(other.children)
106     , addedAnimations(other.addedAnimations)
107     , keyPathsOfAnimationsToRemove(other.keyPathsOfAnimationsToRemove)
108     , position(other.position)
109     , anchorPoint(other.anchorPoint)
110     , size(other.size)
111     , contentsRect(other.contentsRect)
112     , maskLayerID(other.maskLayerID)
113     , timeOffset(other.timeOffset)
114     , speed(other.speed)
115     , contentsScale(other.contentsScale)
116     , borderWidth(other.borderWidth)
117     , opacity(other.opacity)
118     , backgroundColor(other.backgroundColor)
119     , borderColor(other.borderColor)
120     , edgeAntialiasingMask(other.edgeAntialiasingMask)
121     , customAppearance(other.customAppearance)
122     , customBehavior(other.customBehavior)
123     , minificationFilter(other.minificationFilter)
124     , magnificationFilter(other.magnificationFilter)
125     , hidden(other.hidden)
126     , geometryFlipped(other.geometryFlipped)
127     , doubleSided(other.doubleSided)
128     , masksToBounds(other.masksToBounds)
129     , opaque(other.opaque)
130 {
131     if (other.transform)
132         transform = std::make_unique<TransformationMatrix>(*other.transform);
133
134     if (other.sublayerTransform)
135         sublayerTransform = std::make_unique<TransformationMatrix>(*other.sublayerTransform);
136     
137     if (other.backingStore)
138         backingStore = std::make_unique<RemoteLayerBackingStore>(*other.backingStore);
139
140     if (other.filters)
141         filters = std::make_unique<FilterOperations>(*other.filters);
142 }
143
144 void RemoteLayerTreeTransaction::LayerProperties::encode(IPC::ArgumentEncoder& encoder) const
145 {
146     encoder.encodeEnum(changedProperties);
147
148     if (changedProperties & NameChanged)
149         encoder << name;
150
151     if (changedProperties & ChildrenChanged)
152         encoder << children;
153
154     if (changedProperties & AnimationsChanged) {
155         encoder << addedAnimations;
156         encoder << keyPathsOfAnimationsToRemove;
157     }
158
159     if (changedProperties & PositionChanged)
160         encoder << position;
161
162     if (changedProperties & SizeChanged)
163         encoder << size;
164
165     if (changedProperties & BackgroundColorChanged)
166         encoder << backgroundColor;
167
168     if (changedProperties & AnchorPointChanged)
169         encoder << anchorPoint;
170
171     if (changedProperties & BorderWidthChanged)
172         encoder << borderWidth;
173
174     if (changedProperties & BorderColorChanged)
175         encoder << borderColor;
176
177     if (changedProperties & OpacityChanged)
178         encoder << opacity;
179
180     if (changedProperties & TransformChanged)
181         encoder << *transform;
182
183     if (changedProperties & SublayerTransformChanged)
184         encoder << *sublayerTransform;
185
186     if (changedProperties & HiddenChanged)
187         encoder << hidden;
188
189     if (changedProperties & GeometryFlippedChanged)
190         encoder << geometryFlipped;
191
192     if (changedProperties & DoubleSidedChanged)
193         encoder << doubleSided;
194
195     if (changedProperties & MasksToBoundsChanged)
196         encoder << masksToBounds;
197
198     if (changedProperties & OpaqueChanged)
199         encoder << opaque;
200
201     if (changedProperties & MaskLayerChanged)
202         encoder << maskLayerID;
203
204     if (changedProperties & ContentsRectChanged)
205         encoder << contentsRect;
206
207     if (changedProperties & ContentsScaleChanged)
208         encoder << contentsScale;
209
210     if (changedProperties & MinificationFilterChanged)
211         encoder.encodeEnum(minificationFilter);
212
213     if (changedProperties & MagnificationFilterChanged)
214         encoder.encodeEnum(magnificationFilter);
215
216     if (changedProperties & SpeedChanged)
217         encoder << speed;
218
219     if (changedProperties & TimeOffsetChanged)
220         encoder << timeOffset;
221
222     if (changedProperties & BackingStoreChanged) {
223         encoder << backingStore->hasFrontBuffer();
224         if (backingStore->hasFrontBuffer())
225             encoder << *backingStore;
226     }
227
228     if (changedProperties & FiltersChanged)
229         encoder << *filters;
230
231     if (changedProperties & EdgeAntialiasingMaskChanged)
232         encoder << edgeAntialiasingMask;
233
234     if (changedProperties & CustomAppearanceChanged)
235         encoder.encodeEnum(customAppearance);
236
237     if (changedProperties & CustomBehaviorChanged)
238         encoder.encodeEnum(customBehavior);
239 }
240
241 bool RemoteLayerTreeTransaction::LayerProperties::decode(IPC::ArgumentDecoder& decoder, LayerProperties& result)
242 {
243     if (!decoder.decodeEnum(result.changedProperties))
244         return false;
245
246     if (result.changedProperties & NameChanged) {
247         if (!decoder.decode(result.name))
248             return false;
249     }
250
251     if (result.changedProperties & ChildrenChanged) {
252         if (!decoder.decode(result.children))
253             return false;
254
255         for (auto& layerID : result.children) {
256             if (!layerID)
257                 return false;
258         }
259     }
260
261     if (result.changedProperties & AnimationsChanged) {
262         if (!decoder.decode(result.addedAnimations))
263             return false;
264
265         if (!decoder.decode(result.keyPathsOfAnimationsToRemove))
266             return false;
267     }
268
269     if (result.changedProperties & PositionChanged) {
270         if (!decoder.decode(result.position))
271             return false;
272     }
273
274     if (result.changedProperties & SizeChanged) {
275         if (!decoder.decode(result.size))
276             return false;
277     }
278
279     if (result.changedProperties & BackgroundColorChanged) {
280         if (!decoder.decode(result.backgroundColor))
281             return false;
282     }
283
284     if (result.changedProperties & AnchorPointChanged) {
285         if (!decoder.decode(result.anchorPoint))
286             return false;
287     }
288
289     if (result.changedProperties & BorderWidthChanged) {
290         if (!decoder.decode(result.borderWidth))
291             return false;
292     }
293
294     if (result.changedProperties & BorderColorChanged) {
295         if (!decoder.decode(result.borderColor))
296             return false;
297     }
298
299     if (result.changedProperties & OpacityChanged) {
300         if (!decoder.decode(result.opacity))
301             return false;
302     }
303
304     if (result.changedProperties & TransformChanged) {
305         TransformationMatrix transform;
306         if (!decoder.decode(transform))
307             return false;
308         
309         result.transform = std::make_unique<TransformationMatrix>(transform);
310     }
311
312     if (result.changedProperties & SublayerTransformChanged) {
313         TransformationMatrix transform;
314         if (!decoder.decode(transform))
315             return false;
316
317         result.sublayerTransform = std::make_unique<TransformationMatrix>(transform);
318     }
319
320     if (result.changedProperties & HiddenChanged) {
321         if (!decoder.decode(result.hidden))
322             return false;
323     }
324
325     if (result.changedProperties & GeometryFlippedChanged) {
326         if (!decoder.decode(result.geometryFlipped))
327             return false;
328     }
329
330     if (result.changedProperties & DoubleSidedChanged) {
331         if (!decoder.decode(result.doubleSided))
332             return false;
333     }
334
335     if (result.changedProperties & MasksToBoundsChanged) {
336         if (!decoder.decode(result.masksToBounds))
337             return false;
338     }
339
340     if (result.changedProperties & OpaqueChanged) {
341         if (!decoder.decode(result.opaque))
342             return false;
343     }
344
345     if (result.changedProperties & MaskLayerChanged) {
346         if (!decoder.decode(result.maskLayerID))
347             return false;
348     }
349
350     if (result.changedProperties & ContentsRectChanged) {
351         if (!decoder.decode(result.contentsRect))
352             return false;
353     }
354
355     if (result.changedProperties & ContentsScaleChanged) {
356         if (!decoder.decode(result.contentsScale))
357             return false;
358     }
359
360     if (result.changedProperties & MinificationFilterChanged) {
361         if (!decoder.decodeEnum(result.minificationFilter))
362             return false;
363     }
364
365     if (result.changedProperties & MagnificationFilterChanged) {
366         if (!decoder.decodeEnum(result.magnificationFilter))
367             return false;
368     }
369
370     if (result.changedProperties & SpeedChanged) {
371         if (!decoder.decode(result.speed))
372             return false;
373     }
374
375     if (result.changedProperties & TimeOffsetChanged) {
376         if (!decoder.decode(result.timeOffset))
377             return false;
378     }
379
380     if (result.changedProperties & BackingStoreChanged) {
381         bool hasFrontBuffer = false;
382         if (!decoder.decode(hasFrontBuffer))
383             return false;
384         if (hasFrontBuffer) {
385             RemoteLayerBackingStore backingStore;
386             if (!decoder.decode(backingStore))
387                 return false;
388             
389             result.backingStore = std::make_unique<RemoteLayerBackingStore>(backingStore);
390         }
391     }
392
393     if (result.changedProperties & FiltersChanged) {
394         std::unique_ptr<FilterOperations> filters = std::make_unique<FilterOperations>();
395         if (!decoder.decode(*filters))
396             return false;
397         result.filters = std::move(filters);
398     }
399
400     if (result.changedProperties & EdgeAntialiasingMaskChanged) {
401         if (!decoder.decode(result.edgeAntialiasingMask))
402             return false;
403     }
404
405     if (result.changedProperties & CustomAppearanceChanged) {
406         if (!decoder.decodeEnum(result.customAppearance))
407             return false;
408     }
409
410     if (result.changedProperties & CustomBehaviorChanged) {
411         if (!decoder.decodeEnum(result.customBehavior))
412             return false;
413     }
414
415     return true;
416 }
417
418 RemoteLayerTreeTransaction::RemoteLayerTreeTransaction()
419 {
420 }
421
422 RemoteLayerTreeTransaction::~RemoteLayerTreeTransaction()
423 {
424 }
425
426 void RemoteLayerTreeTransaction::encode(IPC::ArgumentEncoder& encoder) const
427 {
428     encoder << m_rootLayerID;
429     encoder << m_createdLayers;
430
431     encoder << m_changedLayerProperties.size();
432
433     for (const auto& layerProperties : m_changedLayerProperties) {
434         encoder << layerProperties.key;
435         encoder << *layerProperties.value;
436     }
437     
438     encoder << m_destroyedLayerIDs;
439     encoder << m_videoLayerIDsPendingFullscreen;
440
441     encoder << m_contentsSize;
442     encoder << m_pageExtendedBackgroundColor;
443     encoder << m_pageScaleFactor;
444     encoder << m_minimumScaleFactor;
445     encoder << m_maximumScaleFactor;
446
447     encoder << m_lastVisibleContentRectUpdateID;
448     encoder << m_renderTreeSize;
449
450     encoder << m_scaleWasSetByUIProcess;
451     encoder << m_allowsUserScaling;
452 }
453
454 bool RemoteLayerTreeTransaction::decode(IPC::ArgumentDecoder& decoder, RemoteLayerTreeTransaction& result)
455 {
456     if (!decoder.decode(result.m_rootLayerID))
457         return false;
458     if (!result.m_rootLayerID)
459         return false;
460
461     if (!decoder.decode(result.m_createdLayers))
462         return false;
463
464     int numChangedLayerProperties;
465     if (!decoder.decode(numChangedLayerProperties))
466         return false;
467
468     for (int i = 0; i < numChangedLayerProperties; ++i) {
469         GraphicsLayer::PlatformLayerID layerID;
470         if (!decoder.decode(layerID))
471             return false;
472
473         std::unique_ptr<LayerProperties> layerProperties = std::make_unique<LayerProperties>();
474         if (!decoder.decode(*layerProperties))
475             return false;
476
477         result.changedLayers().set(layerID, std::move(layerProperties));
478     }
479
480     if (!decoder.decode(result.m_destroyedLayerIDs))
481         return false;
482
483     for (auto& layerID : result.m_destroyedLayerIDs) {
484         if (!layerID)
485             return false;
486     }
487
488     if (!decoder.decode(result.m_videoLayerIDsPendingFullscreen))
489         return false;
490
491     if (!decoder.decode(result.m_contentsSize))
492         return false;
493     
494     if (!decoder.decode(result.m_pageExtendedBackgroundColor))
495         return false;
496
497     if (!decoder.decode(result.m_pageScaleFactor))
498         return false;
499
500     if (!decoder.decode(result.m_minimumScaleFactor))
501         return false;
502
503     if (!decoder.decode(result.m_maximumScaleFactor))
504         return false;
505
506     if (!decoder.decode(result.m_lastVisibleContentRectUpdateID))
507         return false;
508
509     if (!decoder.decode(result.m_renderTreeSize))
510         return false;
511
512     if (!decoder.decode(result.m_scaleWasSetByUIProcess))
513         return false;
514
515     if (!decoder.decode(result.m_allowsUserScaling))
516         return false;
517
518     return true;
519 }
520
521 void RemoteLayerTreeTransaction::setRootLayerID(GraphicsLayer::PlatformLayerID rootLayerID)
522 {
523     ASSERT_ARG(rootLayerID, rootLayerID);
524
525     m_rootLayerID = rootLayerID;
526 }
527
528 void RemoteLayerTreeTransaction::layerPropertiesChanged(PlatformCALayerRemote* remoteLayer, RemoteLayerTreeTransaction::LayerProperties& properties)
529 {
530     m_changedLayerProperties.set(remoteLayer->layerID(), std::make_unique<RemoteLayerTreeTransaction::LayerProperties>(properties));
531 }
532
533 void RemoteLayerTreeTransaction::setCreatedLayers(Vector<LayerCreationProperties> createdLayers)
534 {
535     m_createdLayers = std::move(createdLayers);
536 }
537
538 void RemoteLayerTreeTransaction::setDestroyedLayerIDs(Vector<GraphicsLayer::PlatformLayerID> destroyedLayerIDs)
539 {
540     m_destroyedLayerIDs = std::move(destroyedLayerIDs);
541 }
542
543 #if !defined(NDEBUG) || !LOG_DISABLED
544
545 class RemoteLayerTreeTextStream : public TextStream
546 {
547 public:
548     using TextStream::operator<<;
549
550     RemoteLayerTreeTextStream()
551         : m_indent(0)
552     {
553     }
554
555     RemoteLayerTreeTextStream& operator<<(const TransformationMatrix&);
556     RemoteLayerTreeTextStream& operator<<(PlatformCALayer::FilterType);
557     RemoteLayerTreeTextStream& operator<<(FloatPoint3D);
558     RemoteLayerTreeTextStream& operator<<(Color);
559     RemoteLayerTreeTextStream& operator<<(FloatRect);
560     RemoteLayerTreeTextStream& operator<<(const Vector<WebCore::GraphicsLayer::PlatformLayerID>& layers);
561     RemoteLayerTreeTextStream& operator<<(const FilterOperations&);
562     RemoteLayerTreeTextStream& operator<<(const RemoteLayerBackingStore& backingStore);
563
564     void increaseIndent() { ++m_indent; }
565     void decreaseIndent() { --m_indent; ASSERT(m_indent >= 0); }
566
567     void writeIndent();
568
569 private:
570     int m_indent;
571 };
572
573 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const TransformationMatrix& transform)
574 {
575     RemoteLayerTreeTextStream& ts = *this;
576     ts << "\n";
577     ts.increaseIndent();
578     ts.writeIndent();
579     ts << "[" << transform.m11() << " " << transform.m12() << " " << transform.m13() << " " << transform.m14() << "]\n";
580     ts.writeIndent();
581     ts << "[" << transform.m21() << " " << transform.m22() << " " << transform.m23() << " " << transform.m24() << "]\n";
582     ts.writeIndent();
583     ts << "[" << transform.m31() << " " << transform.m32() << " " << transform.m33() << " " << transform.m34() << "]\n";
584     ts.writeIndent();
585     ts << "[" << transform.m41() << " " << transform.m42() << " " << transform.m43() << " " << transform.m44() << "]";
586     ts.decreaseIndent();
587     return ts;
588 }
589
590 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(PlatformCALayer::FilterType filterType)
591 {
592     RemoteLayerTreeTextStream& ts = *this;
593     switch (filterType) {
594     case PlatformCALayer::Linear:
595         ts << "linear";
596         break;
597     case PlatformCALayer::Nearest:
598         ts << "nearest";
599         break;
600     case PlatformCALayer::Trilinear:
601         ts << "trilinear";
602         break;
603     default:
604         ASSERT_NOT_REACHED();
605         break;
606     }
607     return ts;
608 }
609
610 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const FilterOperations& filters)
611 {
612     RemoteLayerTreeTextStream& ts = *this;
613     for (size_t i = 0; i < filters.size(); ++i) {
614         const auto filter = filters.at(i);
615         switch (filter->type()) {
616         case FilterOperation::REFERENCE:
617             ts << "reference";
618             break;
619         case FilterOperation::GRAYSCALE:
620             ts << "grayscale";
621             break;
622         case FilterOperation::SEPIA:
623             ts << "sepia";
624             break;
625         case FilterOperation::SATURATE:
626             ts << "saturate";
627             break;
628         case FilterOperation::HUE_ROTATE:
629             ts << "hue rotate";
630             break;
631         case FilterOperation::INVERT:
632             ts << "invert";
633             break;
634         case FilterOperation::OPACITY:
635             ts << "opacity";
636             break;
637         case FilterOperation::BRIGHTNESS:
638             ts << "brightness";
639             break;
640         case FilterOperation::CONTRAST:
641             ts << "contrast";
642             break;
643         case FilterOperation::BLUR:
644             ts << "blur";
645             break;
646         case FilterOperation::DROP_SHADOW:
647             ts << "drop shadow";
648             break;
649         case FilterOperation::PASSTHROUGH:
650             ts << "passthrough";
651             break;
652         case FilterOperation::NONE:
653             ts << "none";
654             break;
655         }
656
657         if (i < filters.size() - 1)
658             ts << " ";
659     }
660     return ts;
661 }
662
663 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(FloatPoint3D point)
664 {
665     RemoteLayerTreeTextStream& ts = *this;
666     ts << point.x() << " " << point.y() << " " << point.z();
667     return ts;
668 }
669
670 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(Color color)
671 {
672     RemoteLayerTreeTextStream& ts = *this;
673     ts << color.serialized();
674     return ts;
675 }
676
677 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(FloatRect rect)
678 {
679     RemoteLayerTreeTextStream& ts = *this;
680     ts << rect.x() << " " << rect.y() << " " << rect.width() << " " << rect.height();
681     return ts;
682 }
683
684 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const Vector<GraphicsLayer::PlatformLayerID>& layers)
685 {
686     RemoteLayerTreeTextStream& ts = *this;
687
688     for (size_t i = 0; i < layers.size(); ++i) {
689         if (i)
690             ts << " ";
691         ts << layers[i];
692     }
693
694     return ts;
695 }
696
697 RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const RemoteLayerBackingStore& backingStore)
698 {
699     RemoteLayerTreeTextStream& ts = *this;
700     ts << backingStore.size();
701     ts << " scale=" << backingStore.scale();
702     if (backingStore.isOpaque())
703         ts << " opaque";
704     if (backingStore.acceleratesDrawing())
705         ts << " accelerated";
706     return ts;
707 }
708
709 void RemoteLayerTreeTextStream::writeIndent()
710 {
711     for (int i = 0; i < m_indent; ++i)
712         *this << "  ";
713 }
714
715 template <class T>
716 static void dumpProperty(RemoteLayerTreeTextStream& ts, String name, T value)
717 {
718     ts << "\n";
719     ts.increaseIndent();
720     ts.writeIndent();
721     ts << "(" << name << " ";
722     ts << value << ")";
723     ts.decreaseIndent();
724 }
725
726 static void dumpChangedLayers(RemoteLayerTreeTextStream& ts, const RemoteLayerTreeTransaction::LayerPropertiesMap& changedLayerProperties)
727 {
728     if (changedLayerProperties.isEmpty())
729         return;
730
731     ts << "\n";
732     ts.writeIndent();
733     ts << "(changed-layers";
734
735     // Dump the layer properties sorted by layer ID.
736     Vector<GraphicsLayer::PlatformLayerID> layerIDs;
737     copyKeysToVector(changedLayerProperties, layerIDs);
738     std::sort(layerIDs.begin(), layerIDs.end());
739
740     for (auto& layerID : layerIDs) {
741         const RemoteLayerTreeTransaction::LayerProperties& layerProperties = *changedLayerProperties.get(layerID);
742
743         ts << "\n";
744         ts.increaseIndent();
745         ts.writeIndent();
746         ts << "(layer " << layerID;
747
748         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::NameChanged)
749             dumpProperty<String>(ts, "name", layerProperties.name);
750
751         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ChildrenChanged)
752             dumpProperty<Vector<GraphicsLayer::PlatformLayerID>>(ts, "children", layerProperties.children);
753
754 // FIXME: dump animations
755
756         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::PositionChanged)
757             dumpProperty<FloatPoint3D>(ts, "position", layerProperties.position);
758
759         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::SizeChanged)
760             dumpProperty<FloatSize>(ts, "size", layerProperties.size);
761
762         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::AnchorPointChanged)
763             dumpProperty<FloatPoint3D>(ts, "anchorPoint", layerProperties.anchorPoint);
764
765         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BackgroundColorChanged)
766             dumpProperty<Color>(ts, "backgroundColor", layerProperties.backgroundColor);
767
768         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BorderColorChanged)
769             dumpProperty<Color>(ts, "borderColor", layerProperties.borderColor);
770
771         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BorderWidthChanged)
772             dumpProperty<float>(ts, "borderWidth", layerProperties.borderWidth);
773
774         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::OpacityChanged)
775             dumpProperty<float>(ts, "opacity", layerProperties.opacity);
776
777         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::TransformChanged)
778             dumpProperty<TransformationMatrix>(ts, "transform", layerProperties.transform ? *layerProperties.transform : TransformationMatrix());
779
780         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::SublayerTransformChanged)
781             dumpProperty<TransformationMatrix>(ts, "sublayerTransform", layerProperties.sublayerTransform ? *layerProperties.sublayerTransform : TransformationMatrix());
782
783         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::HiddenChanged)
784             dumpProperty<bool>(ts, "hidden", layerProperties.hidden);
785
786         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::GeometryFlippedChanged)
787             dumpProperty<bool>(ts, "geometryFlipped", layerProperties.geometryFlipped);
788
789         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::DoubleSidedChanged)
790             dumpProperty<bool>(ts, "doubleSided", layerProperties.doubleSided);
791
792         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MasksToBoundsChanged)
793             dumpProperty<bool>(ts, "masksToBounds", layerProperties.masksToBounds);
794
795         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::OpaqueChanged)
796             dumpProperty<bool>(ts, "opaque", layerProperties.opaque);
797
798         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MaskLayerChanged)
799             dumpProperty<GraphicsLayer::PlatformLayerID>(ts, "maskLayer", layerProperties.maskLayerID);
800
801         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ContentsRectChanged)
802             dumpProperty<FloatRect>(ts, "contentsRect", layerProperties.contentsRect);
803
804         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::ContentsScaleChanged)
805             dumpProperty<float>(ts, "contentsScale", layerProperties.contentsScale);
806
807         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MinificationFilterChanged)
808             dumpProperty<PlatformCALayer::FilterType>(ts, "minificationFilter", layerProperties.minificationFilter);
809
810         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::MagnificationFilterChanged)
811             dumpProperty<PlatformCALayer::FilterType>(ts, "magnificationFilter", layerProperties.magnificationFilter);
812
813         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::SpeedChanged)
814             dumpProperty<float>(ts, "speed", layerProperties.speed);
815
816         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::TimeOffsetChanged)
817             dumpProperty<double>(ts, "timeOffset", layerProperties.timeOffset);
818
819         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::BackingStoreChanged) {
820             if (const RemoteLayerBackingStore* backingStore = layerProperties.backingStore.get())
821                 dumpProperty<RemoteLayerBackingStore>(ts, "backingStore", *backingStore);
822             else
823                 dumpProperty<String>(ts, "backingStore", "removed");
824         }
825
826         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::FiltersChanged)
827             dumpProperty<FilterOperations>(ts, "filters", layerProperties.filters ? *layerProperties.filters : FilterOperations());
828
829         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::EdgeAntialiasingMaskChanged)
830             dumpProperty<unsigned>(ts, "edgeAntialiasingMask", layerProperties.edgeAntialiasingMask);
831
832         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::CustomAppearanceChanged)
833             dumpProperty<GraphicsLayer::CustomAppearance>(ts, "customAppearance", layerProperties.customAppearance);
834
835         if (layerProperties.changedProperties & RemoteLayerTreeTransaction::CustomBehaviorChanged)
836             dumpProperty<GraphicsLayer::CustomBehavior>(ts, "customBehavior", layerProperties.customBehavior);
837
838         ts << ")";
839
840         ts.decreaseIndent();
841     }
842
843     ts.decreaseIndent();
844 }
845
846 void RemoteLayerTreeTransaction::dump() const
847 {
848     fprintf(stderr, "%s", description().data());
849 }
850
851 CString RemoteLayerTreeTransaction::description() const
852 {
853     RemoteLayerTreeTextStream ts;
854
855     ts << "(\n";
856     ts.increaseIndent();
857     ts.writeIndent();
858     ts << "(root-layer " << m_rootLayerID << ")";
859
860     if (!m_createdLayers.isEmpty()) {
861         ts << "\n";
862         ts.writeIndent();
863         ts << "(created-layers";
864         ts.increaseIndent();
865         for (const auto& createdLayer : m_createdLayers) {
866             ts << "\n";
867             ts.writeIndent();
868             ts << "(";
869             switch (createdLayer.type) {
870             case PlatformCALayer::LayerTypeLayer:
871             case PlatformCALayer::LayerTypeWebLayer:
872             case PlatformCALayer::LayerTypeSimpleLayer:
873                 ts << "layer";
874                 break;
875             case PlatformCALayer::LayerTypeTransformLayer:
876                 ts << "transform-layer";
877                 break;
878             case PlatformCALayer::LayerTypeWebTiledLayer:
879                 ts << "tiled-layer";
880                 break;
881             case PlatformCALayer::LayerTypeTiledBackingLayer:
882                 ts << "tiled-backing-layer";
883                 break;
884             case PlatformCALayer::LayerTypePageTiledBackingLayer:
885                 ts << "page-tiled-backing-layer";
886                 break;
887             case PlatformCALayer::LayerTypeTiledBackingTileLayer:
888                 ts << "tiled-backing-tile";
889                 break;
890             case PlatformCALayer::LayerTypeRootLayer:
891                 ts << "root-layer";
892                 break;
893             case PlatformCALayer::LayerTypeAVPlayerLayer:
894                 ts << "av-player-layer";
895                 break;
896             case PlatformCALayer::LayerTypeCustom:
897                 ts << "custom-layer (context-id " << createdLayer.hostingContextID << ")";
898                 break;
899             }
900             ts << " " << createdLayer.layerID << ")";
901         }
902         ts << ")";
903         ts.decreaseIndent();
904     }
905
906     dumpChangedLayers(ts, m_changedLayerProperties);
907
908     if (!m_destroyedLayerIDs.isEmpty())
909         dumpProperty<Vector<GraphicsLayer::PlatformLayerID>>(ts, "destroyed-layers", m_destroyedLayerIDs);
910
911     ts << ")\n";
912
913     return ts.release().utf8();
914 }
915
916 #endif // !defined(NDEBUG) || !LOG_DISABLED
917
918 } // namespace WebKit