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