78216677e32a836cad6a4a14b7415b5320363a21
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / mac / PlatformCALayerRemote.cpp
1 /*
2  * Copyright (C) 2013 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. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #import "PlatformCALayerRemote.h"
28
29 #import "PlatformCALayerRemoteCustom.h"
30 #import "PlatformCALayerRemoteTiledBacking.h"
31 #import "RemoteLayerBackingStore.h"
32 #import "RemoteLayerTreeContext.h"
33 #import "RemoteLayerTreePropertyApplier.h"
34 #import <WebCore/AnimationUtilities.h>
35 #import <WebCore/GraphicsContext.h>
36 #import <WebCore/GraphicsLayerCA.h>
37 #import <WebCore/LengthFunctions.h>
38 #import <WebCore/PlatformCAFilters.h>
39 #import <WebCore/PlatformCALayerCocoa.h>
40 #import <WebCore/TiledBacking.h>
41 #import <wtf/CurrentTime.h>
42 #import <wtf/RetainPtr.h>
43
44 using namespace WebCore;
45
46 namespace WebKit {
47
48 PassRefPtr<PlatformCALayerRemote> PlatformCALayerRemote::create(LayerType layerType, PlatformCALayerClient* owner, RemoteLayerTreeContext& context)
49 {
50     RefPtr<PlatformCALayerRemote> layer;
51
52     if (layerType == LayerTypeTiledBackingLayer ||  layerType == LayerTypePageTiledBackingLayer)
53         layer = adoptRef(new PlatformCALayerRemoteTiledBacking(layerType, owner, context));
54     else
55         layer = adoptRef(new PlatformCALayerRemote(layerType, owner, context));
56
57     context.layerWasCreated(*layer, layerType);
58
59     return layer.release();
60 }
61
62 PassRefPtr<PlatformCALayerRemote> PlatformCALayerRemote::create(PlatformLayer *platformLayer, PlatformCALayerClient* owner, RemoteLayerTreeContext& context)
63 {
64     return PlatformCALayerRemoteCustom::create(platformLayer, owner, context);
65 }
66
67 PassRefPtr<PlatformCALayerRemote> PlatformCALayerRemote::create(const PlatformCALayerRemote& other, WebCore::PlatformCALayerClient* owner, RemoteLayerTreeContext& context)
68 {
69     RefPtr<PlatformCALayerRemote> layer = adoptRef(new PlatformCALayerRemote(other, owner, context));
70
71     context.layerWasCreated(*layer, other.layerType());
72
73     return layer.release();
74 }
75
76 PlatformCALayerRemote::PlatformCALayerRemote(LayerType layerType, PlatformCALayerClient* owner, RemoteLayerTreeContext& context)
77     : PlatformCALayer(layerType, owner)
78     , m_superlayer(nullptr)
79     , m_maskLayer(nullptr)
80     , m_acceleratesDrawing(false)
81     , m_context(&context)
82 {
83     if (owner)
84         m_properties.contentsScale = owner->platformCALayerDeviceScaleFactor();
85 }
86
87 PlatformCALayerRemote::PlatformCALayerRemote(const PlatformCALayerRemote& other, PlatformCALayerClient* owner, RemoteLayerTreeContext& context)
88     : PlatformCALayer(other.layerType(), owner)
89     , m_superlayer(nullptr)
90     , m_maskLayer(nullptr)
91     , m_acceleratesDrawing(other.acceleratesDrawing())
92     , m_context(&context)
93 {
94 }
95
96 PassRefPtr<PlatformCALayer> PlatformCALayerRemote::clone(PlatformCALayerClient* owner) const
97 {
98     RefPtr<PlatformCALayerRemote> clone = PlatformCALayerRemote::create(*this, owner, *m_context);
99
100     updateClonedLayerProperties(*clone);
101
102     clone->setClonedLayer(this);
103     return clone.release();
104 }
105
106 PlatformCALayerRemote::~PlatformCALayerRemote()
107 {
108     for (const auto& layer : m_children)
109         downcast<PlatformCALayerRemote>(*layer).m_superlayer = nullptr;
110
111     if (m_context)
112         m_context->layerWillBeDestroyed(*this);
113 }
114
115 void PlatformCALayerRemote::updateClonedLayerProperties(PlatformCALayerRemote& clone, bool copyContents) const
116 {
117     clone.setPosition(position());
118     clone.setBounds(bounds());
119     clone.setAnchorPoint(anchorPoint());
120
121     if (m_properties.transform)
122         clone.setTransform(*m_properties.transform);
123
124     if (m_properties.sublayerTransform)
125         clone.setSublayerTransform(*m_properties.sublayerTransform);
126
127     if (copyContents)
128         clone.setContents(contents());
129
130     clone.setMasksToBounds(masksToBounds());
131     clone.setDoubleSided(isDoubleSided());
132     clone.setOpaque(isOpaque());
133     clone.setBackgroundColor(backgroundColor());
134     clone.setContentsScale(contentsScale());
135     clone.setCornerRadius(cornerRadius());
136
137     if (m_properties.shapeRoundedRect)
138         clone.setShapeRoundedRect(*m_properties.shapeRoundedRect);
139
140     if (m_properties.filters)
141         clone.copyFiltersFrom(*this);
142
143     clone.updateCustomAppearance(customAppearance());
144 }
145
146 void PlatformCALayerRemote::recursiveBuildTransaction(RemoteLayerTreeContext& context, RemoteLayerTreeTransaction& transaction)
147 {
148     ASSERT(!m_properties.backingStore || owner());
149     ASSERT_WITH_SECURITY_IMPLICATION(&context == m_context);
150     
151     if (m_properties.backingStore && (!owner() || !owner()->platformCALayerDrawsContent())) {
152         m_properties.backingStore = nullptr;
153         m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BackingStoreChanged);
154     }
155
156     if (m_properties.backingStore && m_properties.backingStoreAttached && m_properties.backingStore->display())
157         m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BackingStoreChanged);
158
159     if (m_properties.changedProperties != RemoteLayerTreeTransaction::NoChange) {
160         if (m_properties.changedProperties & RemoteLayerTreeTransaction::ChildrenChanged) {
161             m_properties.children.resize(m_children.size());
162             for (size_t i = 0; i < m_children.size(); ++i)
163                 m_properties.children[i] = m_children[i]->layerID();
164         }
165
166         if (isPlatformCALayerRemoteCustom()) {
167             RemoteLayerTreePropertyApplier::applyProperties(platformLayer(), nullptr, m_properties, RemoteLayerTreePropertyApplier::RelatedLayerMap());
168             didCommit();
169             return;
170         }
171
172         transaction.layerPropertiesChanged(*this);
173     }
174
175     for (size_t i = 0; i < m_children.size(); ++i) {
176         PlatformCALayerRemote& child = downcast<PlatformCALayerRemote>(*m_children[i]);
177         ASSERT(child.superlayer() == this);
178         child.recursiveBuildTransaction(context, transaction);
179     }
180
181     if (m_maskLayer)
182         m_maskLayer->recursiveBuildTransaction(context, transaction);
183 }
184
185 void PlatformCALayerRemote::didCommit()
186 {
187     m_properties.addedAnimations.clear();
188     m_properties.keyPathsOfAnimationsToRemove.clear();
189     m_properties.resetChangedProperties();
190 }
191
192 void PlatformCALayerRemote::ensureBackingStore()
193 {
194     ASSERT(owner());
195     
196     if (!m_properties.backingStore)
197         m_properties.backingStore = std::make_unique<RemoteLayerBackingStore>(this);
198
199     updateBackingStore();
200 }
201
202 void PlatformCALayerRemote::updateBackingStore()
203 {
204     if (!m_properties.backingStore)
205         return;
206
207     m_properties.backingStore->ensureBackingStore(m_properties.bounds.size(), m_properties.contentsScale, m_acceleratesDrawing, m_properties.opaque);
208 }
209
210 void PlatformCALayerRemote::setNeedsDisplayInRect(const FloatRect& rect)
211 {
212     ensureBackingStore();
213
214     // FIXME: Need to map this through contentsRect/etc.
215     m_properties.backingStore->setNeedsDisplay(enclosingIntRect(rect));
216 }
217
218 void PlatformCALayerRemote::setNeedsDisplay()
219 {
220     ensureBackingStore();
221
222     m_properties.backingStore->setNeedsDisplay();
223 }
224
225 void PlatformCALayerRemote::copyContentsFromLayer(PlatformCALayer* layer)
226 {
227     ASSERT(m_properties.clonedLayerID == layer->layerID());
228     
229     if (!m_properties.changedProperties)
230         m_context->layerPropertyChangedWhileBuildingTransaction(*this);
231
232     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ClonedContentsChanged);
233 }
234
235 PlatformCALayer* PlatformCALayerRemote::superlayer() const
236 {
237     return m_superlayer;
238 }
239
240 void PlatformCALayerRemote::removeFromSuperlayer()
241 {
242     if (!m_superlayer)
243         return;
244
245     m_superlayer->removeSublayer(this);
246 }
247
248 void PlatformCALayerRemote::removeSublayer(PlatformCALayerRemote* layer)
249 {
250     size_t childIndex = m_children.find(layer);
251     if (childIndex != notFound)
252         m_children.remove(childIndex);
253     layer->m_superlayer = nullptr;
254     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
255 }
256
257 void PlatformCALayerRemote::setSublayers(const PlatformCALayerList& list)
258 {
259     removeAllSublayers();
260     m_children = list;
261
262     for (const auto& layer : list) {
263         layer->removeFromSuperlayer();
264         downcast<PlatformCALayerRemote>(*layer).m_superlayer = this;
265     }
266
267     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
268 }
269
270 void PlatformCALayerRemote::removeAllSublayers()
271 {
272     PlatformCALayerList layersToRemove = m_children;
273     for (const auto& layer : layersToRemove)
274         layer->removeFromSuperlayer();
275     ASSERT(m_children.isEmpty());
276     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
277 }
278
279 void PlatformCALayerRemote::appendSublayer(PlatformCALayer& layer)
280 {
281     Ref<PlatformCALayer> layerProtector(layer);
282
283     layer.removeFromSuperlayer();
284     m_children.append(&layer);
285     downcast<PlatformCALayerRemote>(layer).m_superlayer = this;
286     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
287 }
288
289 void PlatformCALayerRemote::insertSublayer(PlatformCALayer& layer, size_t index)
290 {
291     Ref<PlatformCALayer> layerProtector(layer);
292
293     layer.removeFromSuperlayer();
294     m_children.insert(index, &layer);
295     downcast<PlatformCALayerRemote>(layer).m_superlayer = this;
296     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
297 }
298
299 void PlatformCALayerRemote::replaceSublayer(PlatformCALayer& reference, PlatformCALayer& layer)
300 {
301     ASSERT(reference.superlayer() == this);
302     Ref<PlatformCALayer> layerProtector(layer);
303
304     layer.removeFromSuperlayer();
305     size_t referenceIndex = m_children.find(&reference);
306     if (referenceIndex != notFound) {
307         m_children[referenceIndex]->removeFromSuperlayer();
308         m_children.insert(referenceIndex, &layer);
309         downcast<PlatformCALayerRemote>(layer).m_superlayer = this;
310     }
311
312     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ChildrenChanged);
313 }
314
315 void PlatformCALayerRemote::adoptSublayers(PlatformCALayer& source)
316 {
317     PlatformCALayerList layersToMove = downcast<PlatformCALayerRemote>(source).m_children;
318
319     if (const PlatformCALayerList* customLayers = source.customSublayers()) {
320         for (const auto& layer : *customLayers) {
321             size_t layerIndex = layersToMove.find(layer);
322             if (layerIndex != notFound)
323                 layersToMove.remove(layerIndex);
324         }
325     }
326
327     setSublayers(layersToMove);
328 }
329
330 void PlatformCALayerRemote::addAnimationForKey(const String& key, PlatformCAAnimation& animation)
331 {
332     auto addResult = m_animations.set(key, &animation);
333     if (addResult.isNewEntry)
334         m_properties.addedAnimations.append(std::pair<String, PlatformCAAnimationRemote::Properties>(key, downcast<PlatformCAAnimationRemote>(animation).properties()));
335     else {
336         for (auto& keyAnimationPair : m_properties.addedAnimations) {
337             if (keyAnimationPair.first == key) {
338                 keyAnimationPair.second = downcast<PlatformCAAnimationRemote>(animation).properties();
339                 break;
340             }
341         }
342     }
343     
344     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::AnimationsChanged);
345
346     if (m_context)
347         m_context->willStartAnimationOnLayer(*this);
348 }
349
350 void PlatformCALayerRemote::removeAnimationForKey(const String& key)
351 {
352     if (m_animations.remove(key)) {
353         m_properties.addedAnimations.removeFirstMatching([&key] (const std::pair<String, PlatformCAAnimationRemote::Properties>& pair) {
354             return pair.first == key;
355         });
356     }
357     m_properties.keyPathsOfAnimationsToRemove.add(key);
358     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::AnimationsChanged);
359 }
360
361 PassRefPtr<PlatformCAAnimation> PlatformCALayerRemote::animationForKey(const String& key)
362 {
363     return m_animations.get(key);
364 }
365
366 static inline bool isEquivalentLayer(const PlatformCALayer* layer, GraphicsLayer::PlatformLayerID layerID)
367 {
368     GraphicsLayer::PlatformLayerID newLayerID = layer ? layer->layerID() : 0;
369     return layerID == newLayerID;
370 }
371
372 void PlatformCALayerRemote::animationStarted(const String& key, CFTimeInterval beginTime)
373 {
374     auto it = m_animations.find(key);
375     if (it != m_animations.end())
376         downcast<PlatformCAAnimationRemote>(*it->value).didStart(beginTime);
377     
378     if (m_owner)
379         m_owner->platformCALayerAnimationStarted(key, beginTime);
380 }
381
382 void PlatformCALayerRemote::animationEnded(const String& key)
383 {
384     if (m_owner)
385         m_owner->platformCALayerAnimationEnded(key);
386 }
387
388 void PlatformCALayerRemote::setMask(PlatformCALayer* layer)
389 {
390     if (isEquivalentLayer(layer, m_properties.maskLayerID))
391         return;
392     
393     if (layer) {
394         m_maskLayer = downcast<PlatformCALayerRemote>(layer);
395         m_properties.maskLayerID = m_maskLayer->layerID();
396     } else {
397         m_maskLayer = nullptr;
398         m_properties.maskLayerID = 0;
399     }
400
401     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::MaskLayerChanged);
402 }
403
404 void PlatformCALayerRemote::setClonedLayer(const PlatformCALayer* layer)
405 {
406     if (isEquivalentLayer(layer, m_properties.clonedLayerID))
407         return;
408
409     if (layer)
410         m_properties.clonedLayerID = layer->layerID();
411     else
412         m_properties.clonedLayerID = 0;
413
414     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ClonedContentsChanged);
415 }
416
417 bool PlatformCALayerRemote::isOpaque() const
418 {
419     return m_properties.opaque;
420 }
421
422 void PlatformCALayerRemote::setOpaque(bool value)
423 {
424     m_properties.opaque = value;
425     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::OpaqueChanged);
426
427     updateBackingStore();
428 }
429
430 FloatRect PlatformCALayerRemote::bounds() const
431 {
432     return m_properties.bounds;
433 }
434
435 void PlatformCALayerRemote::setBounds(const FloatRect& value)
436 {
437     if (value == m_properties.bounds)
438         return;
439
440     m_properties.bounds = value;
441     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BoundsChanged);
442     
443     if (requiresCustomAppearanceUpdateOnBoundsChange())
444         m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::CustomAppearanceChanged);
445
446     updateBackingStore();
447 }
448
449 FloatPoint3D PlatformCALayerRemote::position() const
450 {
451     return m_properties.position;
452 }
453
454 void PlatformCALayerRemote::setPosition(const FloatPoint3D& value)
455 {
456     if (value == m_properties.position)
457         return;
458
459     m_properties.position = value;
460     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::PositionChanged);
461 }
462
463 FloatPoint3D PlatformCALayerRemote::anchorPoint() const
464 {
465     return m_properties.anchorPoint;
466 }
467
468 void PlatformCALayerRemote::setAnchorPoint(const FloatPoint3D& value)
469 {
470     if (value == m_properties.anchorPoint)
471         return;
472
473     m_properties.anchorPoint = value;
474     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::AnchorPointChanged);
475 }
476
477 TransformationMatrix PlatformCALayerRemote::transform() const
478 {
479     return m_properties.transform ? *m_properties.transform : TransformationMatrix();
480 }
481
482 void PlatformCALayerRemote::setTransform(const TransformationMatrix& value)
483 {
484     m_properties.transform = std::make_unique<TransformationMatrix>(value);
485     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::TransformChanged);
486 }
487
488 TransformationMatrix PlatformCALayerRemote::sublayerTransform() const
489 {
490     return m_properties.sublayerTransform ? *m_properties.sublayerTransform : TransformationMatrix();
491 }
492
493 void PlatformCALayerRemote::setSublayerTransform(const TransformationMatrix& value)
494 {
495     m_properties.sublayerTransform = std::make_unique<TransformationMatrix>(value);
496     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::SublayerTransformChanged);
497 }
498
499 void PlatformCALayerRemote::setHidden(bool value)
500 {
501     m_properties.hidden = value;
502     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::HiddenChanged);
503 }
504
505 void PlatformCALayerRemote::setBackingStoreAttached(bool value)
506 {
507     if (m_properties.backingStoreAttached == value)
508         return;
509
510     m_properties.backingStoreAttached = value;
511     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BackingStoreAttachmentChanged);
512 }
513
514 bool PlatformCALayerRemote::backingStoreAttached() const
515 {
516     return m_properties.backingStoreAttached;
517 }
518
519 void PlatformCALayerRemote::setGeometryFlipped(bool value)
520 {
521     m_properties.geometryFlipped = value;
522     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::GeometryFlippedChanged);
523 }
524
525 bool PlatformCALayerRemote::geometryFlipped() const
526 {
527     return m_properties.geometryFlipped;
528 }
529
530 bool PlatformCALayerRemote::isDoubleSided() const
531 {
532     return m_properties.doubleSided;
533 }
534
535 void PlatformCALayerRemote::setDoubleSided(bool value)
536 {
537     m_properties.doubleSided = value;
538     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::DoubleSidedChanged);
539 }
540
541 bool PlatformCALayerRemote::masksToBounds() const
542 {
543     return m_properties.masksToBounds;
544 }
545
546 void PlatformCALayerRemote::setMasksToBounds(bool value)
547 {
548     if (value == m_properties.masksToBounds)
549         return;
550
551     m_properties.masksToBounds = value;
552     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::MasksToBoundsChanged);
553 }
554
555 bool PlatformCALayerRemote::acceleratesDrawing() const
556 {
557     return m_acceleratesDrawing;
558 }
559
560 void PlatformCALayerRemote::setAcceleratesDrawing(bool acceleratesDrawing)
561 {
562     m_acceleratesDrawing = acceleratesDrawing;
563     updateBackingStore();
564 }
565
566 CFTypeRef PlatformCALayerRemote::contents() const
567 {
568     return nullptr;
569 }
570
571 void PlatformCALayerRemote::setContents(CFTypeRef value)
572 {
573 }
574
575 void PlatformCALayerRemote::setContentsRect(const FloatRect& value)
576 {
577     m_properties.contentsRect = value;
578     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ContentsRectChanged);
579 }
580
581 void PlatformCALayerRemote::setMinificationFilter(FilterType value)
582 {
583     m_properties.minificationFilter = value;
584     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::MinificationFilterChanged);
585 }
586
587 void PlatformCALayerRemote::setMagnificationFilter(FilterType value)
588 {
589     m_properties.magnificationFilter = value;
590     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::MagnificationFilterChanged);
591 }
592
593 Color PlatformCALayerRemote::backgroundColor() const
594 {
595     return m_properties.backgroundColor;
596 }
597
598 void PlatformCALayerRemote::setBackgroundColor(const Color& value)
599 {
600     m_properties.backgroundColor = value;
601     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BackgroundColorChanged);
602 }
603
604 void PlatformCALayerRemote::setBorderWidth(float value)
605 {
606     if (value == m_properties.borderWidth)
607         return;
608
609     m_properties.borderWidth = value;
610     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BorderWidthChanged);
611 }
612
613 void PlatformCALayerRemote::setBorderColor(const Color& value)
614 {
615     if (value == m_properties.borderColor)
616         return;
617
618     m_properties.borderColor = value;
619     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BorderColorChanged);
620 }
621
622 float PlatformCALayerRemote::opacity() const
623 {
624     return m_properties.opacity;
625 }
626
627 void PlatformCALayerRemote::setOpacity(float value)
628 {
629     m_properties.opacity = value;
630     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::OpacityChanged);
631 }
632
633 void PlatformCALayerRemote::setFilters(const FilterOperations& filters)
634 {
635     m_properties.filters = std::make_unique<FilterOperations>(filters);
636     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::FiltersChanged);
637 }
638
639 void PlatformCALayerRemote::copyFiltersFrom(const PlatformCALayer& sourceLayer)
640 {
641     if (const FilterOperations* filters = downcast<PlatformCALayerRemote>(sourceLayer).m_properties.filters.get())
642         setFilters(*filters);
643     else if (m_properties.filters)
644         m_properties.filters = nullptr;
645
646     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::FiltersChanged);
647 }
648
649 #if ENABLE(CSS_COMPOSITING)
650 void PlatformCALayerRemote::setBlendMode(BlendMode blendMode)
651 {
652     m_properties.blendMode = blendMode;
653     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::BlendModeChanged);
654 }
655 #endif
656
657 bool PlatformCALayerRemote::filtersCanBeComposited(const FilterOperations& filters)
658 {
659     return PlatformCALayerCocoa::filtersCanBeComposited(filters);
660 }
661
662 void PlatformCALayerRemote::setName(const String& value)
663 {
664     m_properties.name = value;
665     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::NameChanged);
666 }
667
668 void PlatformCALayerRemote::setSpeed(float value)
669 {
670     m_properties.speed = value;
671     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::SpeedChanged);
672 }
673
674 void PlatformCALayerRemote::setTimeOffset(CFTimeInterval value)
675 {
676     m_properties.timeOffset = value;
677     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::TimeOffsetChanged);
678 }
679
680 float PlatformCALayerRemote::contentsScale() const
681 {
682     return m_properties.contentsScale;
683 }
684
685 void PlatformCALayerRemote::setContentsScale(float value)
686 {
687     m_properties.contentsScale = value;
688     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ContentsScaleChanged);
689
690     updateBackingStore();
691 }
692
693 float PlatformCALayerRemote::cornerRadius() const
694 {
695     return m_properties.cornerRadius;
696 }
697
698 void PlatformCALayerRemote::setCornerRadius(float value)
699 {
700     if (m_properties.cornerRadius == value)
701         return;
702
703     m_properties.cornerRadius = value;
704     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::CornerRadiusChanged);
705 }
706
707 void PlatformCALayerRemote::setEdgeAntialiasingMask(unsigned value)
708 {
709     m_properties.edgeAntialiasingMask = value;
710     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::EdgeAntialiasingMaskChanged);
711 }
712
713 FloatRoundedRect PlatformCALayerRemote::shapeRoundedRect() const
714 {
715     return m_properties.shapeRoundedRect ? *m_properties.shapeRoundedRect : FloatRoundedRect(FloatRect());
716 }
717
718 void PlatformCALayerRemote::setShapeRoundedRect(const FloatRoundedRect& roundedRect)
719 {
720     if (m_properties.shapeRoundedRect && *m_properties.shapeRoundedRect == roundedRect)
721         return;
722
723     m_properties.shapeRoundedRect = std::make_unique<FloatRoundedRect>(roundedRect);
724     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ShapeRoundedRectChanged);
725 }
726
727 Path PlatformCALayerRemote::shapePath() const
728 {
729     ASSERT(m_layerType == LayerTypeShapeLayer);
730     return m_properties.shapePath;
731 }
732
733 void PlatformCALayerRemote::setShapePath(const Path& path)
734 {
735     ASSERT(m_layerType == LayerTypeShapeLayer);
736     m_properties.shapePath = path;
737     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ShapePathChanged);
738 }
739
740 WindRule PlatformCALayerRemote::shapeWindRule() const
741 {
742     ASSERT(m_layerType == LayerTypeShapeLayer);
743     return m_properties.windRule;
744 }
745
746 void PlatformCALayerRemote::setShapeWindRule(WindRule windRule)
747 {
748     ASSERT(m_layerType == LayerTypeShapeLayer);
749     m_properties.windRule = windRule;
750     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::WindRuleChanged);
751 }
752
753 bool PlatformCALayerRemote::requiresCustomAppearanceUpdateOnBoundsChange() const
754 {
755     return m_properties.customAppearance == GraphicsLayer::ScrollingShadow;
756 }
757
758 GraphicsLayer::CustomAppearance PlatformCALayerRemote::customAppearance() const
759 {
760     return m_properties.customAppearance;
761 }
762
763 void PlatformCALayerRemote::updateCustomAppearance(GraphicsLayer::CustomAppearance customAppearance)
764 {
765     m_properties.customAppearance = customAppearance;
766     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::CustomAppearanceChanged);
767 }
768
769 PassRefPtr<PlatformCALayer> PlatformCALayerRemote::createCompatibleLayer(PlatformCALayer::LayerType layerType, PlatformCALayerClient* client) const
770 {
771     return PlatformCALayerRemote::create(layerType, client, *m_context);
772 }
773
774 void PlatformCALayerRemote::enumerateRectsBeingDrawn(CGContextRef context, void (^block)(CGRect))
775 {
776     m_properties.backingStore->enumerateRectsBeingDrawn(context, block);
777 }
778
779 uint32_t PlatformCALayerRemote::hostingContextID()
780 {
781     ASSERT_NOT_REACHED();
782     return 0;
783 }
784
785 unsigned PlatformCALayerRemote::backingStoreBytesPerPixel() const
786 {
787     if (!m_properties.backingStore)
788         return 4;
789
790     return m_properties.backingStore->bytesPerPixel();
791 }
792
793 LayerPool& PlatformCALayerRemote::layerPool()
794 {
795     return m_context->layerPool();
796 }
797
798 } // namespace WebKit