Add animationDidEnd callbacks on GraphicsLayer
[WebKit-https.git] / Source / WebCore / platform / graphics / ca / win / PlatformCALayerWin.cpp
1 /*
2  * Copyright (C) 2011, 2014 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
28 #include "PlatformCALayerWin.h"
29
30 #include "AbstractCACFLayerTreeHost.h"
31 #include "Font.h"
32 #include "GraphicsContext.h"
33 #include "PlatformCAAnimationWin.h"
34 #include "PlatformCALayerWinInternal.h"
35 #include "TileController.h"
36 #include <QuartzCore/CoreAnimationCF.h>
37 #include <WebKitSystemInterface/WebKitSystemInterface.h>
38 #include <wtf/CurrentTime.h>
39 #include <wtf/text/CString.h>
40
41 using namespace WebCore;
42
43 PassRefPtr<PlatformCALayer> PlatformCALayerWin::create(LayerType layerType, PlatformCALayerClient* owner)
44 {
45     return adoptRef(new PlatformCALayerWin(layerType, 0, owner));
46 }
47
48 PassRefPtr<PlatformCALayer> PlatformCALayerWin::create(PlatformLayer* platformLayer, PlatformCALayerClient* owner)
49 {
50     return adoptRef(new PlatformCALayerWin(LayerTypeCustom, platformLayer, owner));
51 }
52
53 static CFStringRef toCACFLayerType(PlatformCALayer::LayerType type)
54 {
55     return (type == PlatformCALayer::LayerTypeTransformLayer) ? kCACFTransformLayer : kCACFLayer;
56 }
57
58 static CFStringRef toCACFFilterType(PlatformCALayer::FilterType type)
59 {
60     switch (type) {
61     case PlatformCALayer::Linear: return kCACFFilterLinear;
62     case PlatformCALayer::Nearest: return kCACFFilterNearest;
63     case PlatformCALayer::Trilinear: return kCACFFilterTrilinear;
64     default: return 0;
65     }
66 }
67
68 static AbstractCACFLayerTreeHost* layerTreeHostForLayer(const PlatformCALayer* layer)
69 {
70     // We need the AbstractCACFLayerTreeHost associated with this layer, which is stored in the UserData of the CACFContext
71     void* userData = wkCACFLayerGetContextUserData(layer->platformLayer());
72     if (!userData)
73         return 0;
74
75     return static_cast<AbstractCACFLayerTreeHost*>(userData);
76 }
77
78 static PlatformCALayerWinInternal* intern(const PlatformCALayer* layer)
79 {
80     return static_cast<PlatformCALayerWinInternal*>(CACFLayerGetUserData(layer->platformLayer()));
81 }
82
83 static PlatformCALayerWinInternal* intern(void* layer)
84 {
85     return static_cast<PlatformCALayerWinInternal*>(CACFLayerGetUserData(static_cast<CACFLayerRef>(layer)));
86 }
87
88 PlatformCALayer* PlatformCALayer::platformCALayer(void* platformLayer)
89 {
90     if (!platformLayer)
91         return 0;
92     
93     PlatformCALayerWinInternal* layerIntern = intern(platformLayer);
94     return layerIntern ? layerIntern->owner() : 0;
95 }
96
97 PlatformCALayer::RepaintRectList PlatformCALayer::collectRectsToPaint(CGContextRef, PlatformCALayer*)
98 {
99     // FIXME: We should actually collect rects to use instead of defaulting to Windows'
100     // normal drawing path.
101     PlatformCALayer::RepaintRectList dirtyRects;
102     return dirtyRects;
103 }
104
105 void PlatformCALayer::drawLayerContents(CGContextRef context, WebCore::PlatformCALayer* platformCALayer, RepaintRectList&)
106 {
107     intern(platformCALayer)->displayCallback(platformCALayer->platformLayer(), context);
108 }
109
110 CGRect PlatformCALayer::frameForLayer(const PlatformLayer* tileLayer)
111 {
112     return CACFLayerGetFrame(static_cast<CACFLayerRef>(const_cast<PlatformLayer*>(tileLayer)));
113 }
114
115 static void displayCallback(CACFLayerRef caLayer, CGContextRef context)
116 {
117     ASSERT_ARG(caLayer, CACFLayerGetUserData(caLayer));
118     intern(caLayer)->displayCallback(caLayer, context);
119 }
120
121 static void layoutSublayersProc(CACFLayerRef caLayer) 
122 {
123     PlatformCALayer* layer = PlatformCALayer::platformCALayer(caLayer);
124     if (layer && layer->owner())
125         layer->owner()->platformCALayerLayoutSublayersOfLayer(layer);
126 }
127
128 PlatformCALayerWin::PlatformCALayerWin(LayerType layerType, PlatformLayer* layer, PlatformCALayerClient* owner)
129     : PlatformCALayer(layer ? LayerTypeCustom : layerType, owner)
130     , m_customAppearance(GraphicsLayer::NoCustomAppearance)
131     , m_customBehavior(GraphicsLayer::NoCustomBehavior)
132 {
133     if (layer) {
134         m_layer = layer;
135         return;
136     }
137
138     m_layer = adoptCF(CACFLayerCreate(toCACFLayerType(layerType)));
139
140     // Create the PlatformCALayerWinInternal object and point to it in the userdata.
141     PlatformCALayerWinInternal* intern = new PlatformCALayerWinInternal(this);
142     CACFLayerSetUserData(m_layer.get(), intern);
143
144     // Set the display callback
145     CACFLayerSetDisplayCallback(m_layer.get(), displayCallback);
146     CACFLayerSetLayoutCallback(m_layer.get(), layoutSublayersProc);
147
148     if (usesTiledBackingLayer()) {
149         TileController* tileController = intern->createTileController(this);
150         m_customSublayers = std::make_unique<PlatformCALayerList>(tileController->containerLayers());
151     }
152 }
153
154 PlatformCALayerWin::~PlatformCALayerWin()
155 {
156     // Toss all the kids
157     removeAllSublayers();
158
159     // Get rid of the user data
160     PlatformCALayerWinInternal* layerIntern = intern(this);
161     CACFLayerSetUserData(m_layer.get(), 0);
162
163     CACFLayerRemoveFromSuperlayer(m_layer.get());
164
165     delete layerIntern;
166 }
167
168 PassRefPtr<PlatformCALayer> PlatformCALayerWin::clone(PlatformCALayerClient* owner) const
169 {
170     PlatformCALayer::LayerType type = (layerType() == PlatformCALayer::LayerTypeTransformLayer) ?
171         PlatformCALayer::LayerTypeTransformLayer : PlatformCALayer::LayerTypeLayer;
172     RefPtr<PlatformCALayer> newLayer = PlatformCALayerWin::create(type, owner);
173
174     newLayer->setPosition(position());
175     newLayer->setBounds(bounds());
176     newLayer->setAnchorPoint(anchorPoint());
177     newLayer->setTransform(transform());
178     newLayer->setSublayerTransform(sublayerTransform());
179     newLayer->setContents(contents());
180     newLayer->setMasksToBounds(masksToBounds());
181     newLayer->setDoubleSided(isDoubleSided());
182     newLayer->setOpaque(isOpaque());
183     newLayer->setBackgroundColor(backgroundColor());
184     newLayer->setContentsScale(contentsScale());
185 #if ENABLE(CSS_FILTERS)
186     newLayer->copyFiltersFrom(this);
187 #endif
188
189     return newLayer;
190 }
191
192 PlatformCALayer* PlatformCALayerWin::rootLayer() const
193 {
194     AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
195     return host ? host->rootLayer() : 0;
196 }
197
198 void PlatformCALayerWin::animationStarted(const String& animationKey, CFTimeInterval beginTime)
199 {
200     // Update start time for any animation not yet started
201     CFTimeInterval cacfBeginTime = currentTimeToMediaTime(beginTime);
202
203     HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator end = m_animations.end();
204     for (HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator it = m_animations.begin(); it != end; ++it)
205         it->value->setActualStartTimeIfNeeded(cacfBeginTime);
206
207     if (m_owner)
208         m_owner->platformCALayerAnimationStarted(animationKey, beginTime);
209 }
210
211 void PlatformCALayerWin::animationEnded(const String& animationKey)
212 {
213     if (m_owner)
214         m_owner->platformCALayerAnimationEnded(animationKey);
215 }
216
217 void PlatformCALayerWin::setNeedsDisplayInRect(const FloatRect& dirtyRect)
218 {
219     intern(this)->setNeedsDisplayInRect(dirtyRect);
220 }
221
222 void PlatformCALayerWin::setNeedsDisplay()
223 {
224     intern(this)->setNeedsDisplay();
225 }
226
227 void PlatformCALayerWin::setNeedsCommit()
228 {
229     AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
230     if (host)
231         host->layerTreeDidChange();
232 }
233
234 void PlatformCALayerWin::copyContentsFromLayer(PlatformCALayer* source)
235 {
236     if (source) {
237         RetainPtr<CFTypeRef> contents = CACFLayerGetContents(source->platformLayer());
238         CACFLayerSetContents(m_layer.get(), contents.get());
239     } else
240         CACFLayerSetContents(m_layer.get(), nullptr);
241
242     setNeedsCommit();
243 }
244
245 void PlatformCALayerWin::setNeedsLayout()
246 {
247     if (!m_owner || !m_owner->platformCALayerRespondsToLayoutChanges())
248         return;
249
250     CACFLayerSetNeedsLayout(m_layer.get());
251     setNeedsCommit();
252 }
253
254 PlatformCALayer* PlatformCALayerWin::superlayer() const
255 {
256     return platformCALayer(CACFLayerGetSuperlayer(m_layer.get()));
257 }
258
259 void PlatformCALayerWin::removeFromSuperlayer()
260 {
261     CACFLayerRemoveFromSuperlayer(m_layer.get());
262     setNeedsCommit();
263 }
264
265 void PlatformCALayerWin::setSublayers(const PlatformCALayerList& list)
266 {
267     intern(this)->setSublayers(list);
268 }
269
270 void PlatformCALayerWin::removeAllSublayers()
271 {
272     intern(this)->removeAllSublayers();
273 }
274
275 void PlatformCALayerWin::appendSublayer(PlatformCALayer* layer)
276 {
277     // This must be in terms of insertSublayer instead of a direct call so PlatformCALayerInternal can override.
278     insertSublayer(layer, intern(this)->sublayerCount());
279 }
280
281 void PlatformCALayerWin::insertSublayer(PlatformCALayer* layer, size_t index)
282 {
283     intern(this)->insertSublayer(layer, index);
284 }
285
286 void PlatformCALayerWin::replaceSublayer(PlatformCALayer* reference, PlatformCALayer* newLayer)
287 {
288     // This must not use direct calls to allow PlatformCALayerInternal to override.
289     ASSERT_ARG(reference, reference);
290     ASSERT_ARG(reference, reference->superlayer() == this);
291
292     if (reference == newLayer)
293         return;
294
295     int referenceIndex = intern(this)->indexOfSublayer(reference);
296     ASSERT(referenceIndex != -1);
297     if (referenceIndex == -1)
298         return;
299
300     reference->removeFromSuperlayer();
301
302     if (newLayer) {
303         newLayer->removeFromSuperlayer();
304         insertSublayer(newLayer, referenceIndex);
305     }
306 }
307
308 void PlatformCALayerWin::adoptSublayers(PlatformCALayer* source)
309 {
310     PlatformCALayerList sublayers;
311     intern(source)->getSublayers(sublayers);
312
313     // Use setSublayers() because it properly nulls out the superlayer pointers.
314     setSublayers(sublayers);
315 }
316
317 void PlatformCALayerWin::addAnimationForKey(const String& key, PlatformCAAnimation* animation)
318 {
319     // Add it to the animation list
320     m_animations.add(key, animation);
321
322     CACFLayerAddAnimation(m_layer.get(), key.createCFString().get(), toPlatformCAAnimationWin(animation)->platformAnimation());
323     setNeedsCommit();
324
325     // Tell the host about it so we can fire the start animation event
326     AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
327     if (host)
328         host->addPendingAnimatedLayer(this);
329 }
330
331 void PlatformCALayerWin::removeAnimationForKey(const String& key)
332 {
333     // Remove it from the animation list
334     m_animations.remove(key);
335
336     CACFLayerRemoveAnimation(m_layer.get(), key.createCFString().get());
337
338     // We don't "remove" a layer from AbstractCACFLayerTreeHost when it loses an animation.
339     // There may be other active animations on the layer and if an animation
340     // callback is fired on a layer without any animations no harm is done.
341
342     setNeedsCommit();
343 }
344
345 PassRefPtr<PlatformCAAnimation> PlatformCALayerWin::animationForKey(const String& key)
346 {
347     HashMap<String, RefPtr<PlatformCAAnimation> >::iterator it = m_animations.find(key);
348     if (it == m_animations.end())
349         return 0;
350
351     return it->value;
352 }
353
354 void PlatformCALayerWin::setMask(PlatformCALayer* layer)
355 {
356     CACFLayerSetMask(m_layer.get(), layer ? layer->platformLayer() : 0);
357     setNeedsCommit();
358 }
359
360 bool PlatformCALayerWin::isOpaque() const
361 {
362     return CACFLayerIsOpaque(m_layer.get());
363 }
364
365 void PlatformCALayerWin::setOpaque(bool value)
366 {
367     CACFLayerSetOpaque(m_layer.get(), value);
368     setNeedsCommit();
369 }
370
371 FloatRect PlatformCALayerWin::bounds() const
372 {
373     return CACFLayerGetBounds(m_layer.get());
374 }
375
376 void PlatformCALayerWin::setBounds(const FloatRect& value)
377 {
378     intern(this)->setBounds(value);
379     setNeedsLayout();
380 }
381
382 FloatPoint3D PlatformCALayerWin::position() const
383 {
384     CGPoint point = CACFLayerGetPosition(m_layer.get());
385     return FloatPoint3D(point.x, point.y, CACFLayerGetZPosition(m_layer.get()));
386 }
387
388 void PlatformCALayerWin::setPosition(const FloatPoint3D& value)
389 {
390     CACFLayerSetPosition(m_layer.get(), CGPointMake(value.x(), value.y()));
391     CACFLayerSetZPosition(m_layer.get(), value.z());
392     setNeedsCommit();
393 }
394
395 FloatPoint3D PlatformCALayerWin::anchorPoint() const
396 {
397     CGPoint point = CACFLayerGetAnchorPoint(m_layer.get());
398     float z = CACFLayerGetAnchorPointZ(m_layer.get());
399     return FloatPoint3D(point.x, point.y, z);
400 }
401
402 void PlatformCALayerWin::setAnchorPoint(const FloatPoint3D& value)
403 {
404     CACFLayerSetAnchorPoint(m_layer.get(), CGPointMake(value.x(), value.y()));
405     CACFLayerSetAnchorPointZ(m_layer.get(), value.z());
406     setNeedsCommit();
407 }
408
409 TransformationMatrix PlatformCALayerWin::transform() const
410 {
411     return CACFLayerGetTransform(m_layer.get());
412 }
413
414 void PlatformCALayerWin::setTransform(const TransformationMatrix& value)
415 {
416     CACFLayerSetTransform(m_layer.get(), value);
417     setNeedsCommit();
418 }
419
420 TransformationMatrix PlatformCALayerWin::sublayerTransform() const
421 {
422     return CACFLayerGetSublayerTransform(m_layer.get());
423 }
424
425 void PlatformCALayerWin::setSublayerTransform(const TransformationMatrix& value)
426 {
427     CACFLayerSetSublayerTransform(m_layer.get(), value);
428     setNeedsCommit();
429 }
430
431 void PlatformCALayerWin::setHidden(bool value)
432 {
433     CACFLayerSetHidden(m_layer.get(), value);
434     setNeedsCommit();
435 }
436
437 void PlatformCALayerWin::setGeometryFlipped(bool value)
438 {
439     CACFLayerSetGeometryFlipped(m_layer.get(), value);
440     setNeedsCommit();
441 }
442
443 bool PlatformCALayerWin::isDoubleSided() const
444 {
445     return CACFLayerIsDoubleSided(m_layer.get());
446 }
447
448 void PlatformCALayerWin::setDoubleSided(bool value)
449 {
450     CACFLayerSetDoubleSided(m_layer.get(), value);
451     setNeedsCommit();
452 }
453
454 bool PlatformCALayerWin::masksToBounds() const
455 {
456     return CACFLayerGetMasksToBounds(m_layer.get());
457 }
458
459 void PlatformCALayerWin::setMasksToBounds(bool value)
460 {
461     CACFLayerSetMasksToBounds(m_layer.get(), value);
462     setNeedsCommit();
463 }
464
465 bool PlatformCALayerWin::acceleratesDrawing() const
466 {
467     return false;
468 }
469
470 void PlatformCALayerWin::setAcceleratesDrawing(bool)
471 {
472 }
473
474 CFTypeRef PlatformCALayerWin::contents() const
475 {
476     return CACFLayerGetContents(m_layer.get());
477 }
478
479 void PlatformCALayerWin::setContents(CFTypeRef value)
480 {
481     CACFLayerSetContents(m_layer.get(), value);
482     setNeedsCommit();
483 }
484
485 void PlatformCALayerWin::setContentsRect(const FloatRect& value)
486 {
487     CACFLayerSetContentsRect(m_layer.get(), value);
488     setNeedsCommit();
489 }
490
491 void PlatformCALayerWin::setMinificationFilter(FilterType value)
492 {
493     CACFLayerSetMinificationFilter(m_layer.get(), toCACFFilterType(value));
494 }
495
496 void PlatformCALayerWin::setMagnificationFilter(FilterType value)
497 {
498     CACFLayerSetMagnificationFilter(m_layer.get(), toCACFFilterType(value));
499     setNeedsCommit();
500 }
501
502 Color PlatformCALayerWin::backgroundColor() const
503 {
504     return CACFLayerGetBackgroundColor(m_layer.get());
505 }
506
507 void PlatformCALayerWin::setBackgroundColor(const Color& value)
508 {
509     CGFloat components[4];
510     value.getRGBA(components[0], components[1], components[2], components[3]);
511
512     RetainPtr<CGColorSpaceRef> colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
513     RetainPtr<CGColorRef> color = adoptCF(CGColorCreate(colorSpace.get(), components));
514
515     CACFLayerSetBackgroundColor(m_layer.get(), color.get());
516     setNeedsCommit();
517 }
518
519 void PlatformCALayerWin::setBorderWidth(float value)
520 {
521     CACFLayerSetBorderWidth(m_layer.get(), value);
522     setNeedsCommit();
523 }
524
525 void PlatformCALayerWin::setBorderColor(const Color& value)
526 {
527     CGFloat components[4];
528     value.getRGBA(components[0], components[1], components[2], components[3]);
529
530     RetainPtr<CGColorSpaceRef> colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
531     RetainPtr<CGColorRef> color = adoptCF(CGColorCreate(colorSpace.get(), components));
532
533     CACFLayerSetBorderColor(m_layer.get(), color.get());
534     setNeedsCommit();
535 }
536
537 float PlatformCALayerWin::opacity() const
538 {
539     return CACFLayerGetOpacity(m_layer.get());
540 }
541
542 void PlatformCALayerWin::setOpacity(float value)
543 {
544     CACFLayerSetOpacity(m_layer.get(), value);
545     setNeedsCommit();
546 }
547
548 #if ENABLE(CSS_FILTERS)
549
550 void PlatformCALayerWin::setFilters(const FilterOperations&)
551 {
552 }
553
554 void PlatformCALayerWin::copyFiltersFrom(const PlatformCALayer*)
555 {
556 }
557
558 #endif // ENABLE(CSS_FILTERS)
559
560 void PlatformCALayerWin::setName(const String& value)
561 {
562     CACFLayerSetName(m_layer.get(), value.createCFString().get());
563     setNeedsCommit();
564 }
565
566 void PlatformCALayerWin::setSpeed(float value)
567 {
568     CACFLayerSetSpeed(m_layer.get(), value);
569     setNeedsCommit();
570 }
571
572 void PlatformCALayerWin::setTimeOffset(CFTimeInterval value)
573 {
574     CACFLayerSetTimeOffset(m_layer.get(), value);
575     setNeedsCommit();
576 }
577
578 void PlatformCALayerWin::setEdgeAntialiasingMask(unsigned mask)
579 {
580     CACFLayerSetEdgeAntialiasingMask(m_layer.get(), mask);
581     setNeedsCommit();
582 }
583
584 float PlatformCALayerWin::contentsScale() const
585 {
586     return 1;
587 }
588
589 void PlatformCALayerWin::setContentsScale(float)
590 {
591 }
592
593 #ifndef NDEBUG
594 static void printIndent(int indent)
595 {
596     for ( ; indent > 0; --indent)
597         fprintf(stderr, "  ");
598 }
599
600 static void printTransform(const CATransform3D& transform)
601 {
602     fprintf(stderr, "[%g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g]",
603                     transform.m11, transform.m12, transform.m13, transform.m14, 
604                     transform.m21, transform.m22, transform.m23, transform.m24, 
605                     transform.m31, transform.m32, transform.m33, transform.m34, 
606                     transform.m41, transform.m42, transform.m43, transform.m44);
607 }
608
609 static void printLayer(const PlatformCALayer* layer, int indent)
610 {
611     FloatPoint3D layerPosition = layer->position();
612     FloatPoint3D layerAnchorPoint = layer->anchorPoint();
613     FloatRect layerBounds = layer->bounds();
614     printIndent(indent);
615
616     char* layerTypeName = 0;
617     switch (layer->layerType()) {
618     case PlatformCALayer::LayerTypeLayer: layerTypeName = "layer"; break;
619     case PlatformCALayer::LayerTypeWebLayer: layerTypeName = "web-layer"; break;
620     case PlatformCALayer::LayerTypeTransformLayer: layerTypeName = "transform-layer"; break;
621     case PlatformCALayer::LayerTypeWebTiledLayer: layerTypeName = "web-tiled-layer"; break;
622     case PlatformCALayer::LayerTypeTiledBackingLayer: layerTypeName = "tiled-backing-layer"; break;
623     case PlatformCALayer::LayerTypeRootLayer: layerTypeName = "root-layer"; break;
624     case PlatformCALayer::LayerTypeCustom: layerTypeName = "custom-layer"; break;
625     }
626
627     fprintf(stderr, "(%s [%g %g %g] [%g %g %g %g] [%g %g %g] superlayer=%p\n",
628         layerTypeName,
629         layerPosition.x(), layerPosition.y(), layerPosition.z(), 
630         layerBounds.x(), layerBounds.y(), layerBounds.width(), layerBounds.height(),
631         layerAnchorPoint.x(), layerAnchorPoint.y(), layerAnchorPoint.z(), layer->superlayer());
632
633     // Print name if needed
634     String layerName = CACFLayerGetName(layer->platformLayer());
635     if (!layerName.isEmpty()) {
636         printIndent(indent + 1);
637         fprintf(stderr, "(name %s)\n", layerName.utf8().data());
638     }
639
640     // Print masksToBounds if needed
641     bool layerMasksToBounds = layer->masksToBounds();
642     if (layerMasksToBounds) {
643         printIndent(indent + 1);
644         fprintf(stderr, "(masksToBounds true)\n");
645     }
646
647     // Print opacity if needed
648     float layerOpacity = layer->opacity();
649     if (layerOpacity != 1) {
650         printIndent(indent + 1);
651         fprintf(stderr, "(opacity %hf)\n", layerOpacity);
652     }
653
654     // Print sublayerTransform if needed
655     TransformationMatrix layerTransform = layer->sublayerTransform();
656     if (!layerTransform.isIdentity()) {
657         printIndent(indent + 1);
658         fprintf(stderr, "(sublayerTransform ");
659         printTransform(layerTransform);
660         fprintf(stderr, ")\n");
661     }
662
663     // Print transform if needed
664     layerTransform = layer->transform();
665     if (!layerTransform.isIdentity()) {
666         printIndent(indent + 1);
667         fprintf(stderr, "(transform ");
668         printTransform(layerTransform);
669         fprintf(stderr, ")\n");
670     }
671
672     // Print contents if needed
673     CFTypeRef layerContents = layer->contents();
674     if (layerContents) {
675         if (CFGetTypeID(layerContents) == CGImageGetTypeID()) {
676             CGImageRef imageContents = static_cast<CGImageRef>(const_cast<void*>(layerContents));
677             printIndent(indent + 1);
678             fprintf(stderr, "(contents (image [%d %d]))\n",
679                 CGImageGetWidth(imageContents), CGImageGetHeight(imageContents));
680         }
681     }
682
683     // Print sublayers if needed
684     int n = intern(layer)->sublayerCount();
685     if (n > 0) {
686         printIndent(indent + 1);
687         fprintf(stderr, "(sublayers\n");
688
689         PlatformCALayerList sublayers;
690         intern(layer)->getSublayers(sublayers);
691         ASSERT(n == sublayers.size());
692         for (int i = 0; i < n; ++i)
693             printLayer(sublayers[i].get(), indent + 2);
694
695         printIndent(indent + 1);
696         fprintf(stderr, ")\n");
697     }
698
699     printIndent(indent);
700     fprintf(stderr, ")\n");
701 }
702
703 void PlatformCALayerWin::printTree() const
704 {
705     // Print heading info
706     CGRect rootBounds = bounds();
707     fprintf(stderr, "\n\n** Render tree at time %g (bounds %g, %g %gx%g) **\n\n", 
708         monotonicallyIncreasingTime(), rootBounds.origin.x, rootBounds.origin.y, rootBounds.size.width, rootBounds.size.height);
709
710     // Print layer tree from the root
711     printLayer(this, 0);
712 }
713 #endif // #ifndef NDEBUG
714
715 PassRefPtr<PlatformCALayer> PlatformCALayerWin::createCompatibleLayer(PlatformCALayer::LayerType layerType, PlatformCALayerClient* client) const
716 {
717     return PlatformCALayerWin::create(layerType, client);
718 }
719
720 TiledBacking* PlatformCALayerWin::tiledBacking()
721 {
722     if (!usesTiledBackingLayer())
723         return nullptr;
724
725     return intern(this)->tiledBacking();
726 }