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