2 * Copyright (C) 2011, 2014-2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
28 #include "PlatformCALayerWin.h"
32 #include "AbstractCACFLayerTreeHost.h"
33 #include "FontCascade.h"
34 #include "GDIUtilities.h"
35 #include "GraphicsContext.h"
36 #include "PlatformCAAnimationWin.h"
37 #include "PlatformCALayerWinInternal.h"
39 #include "TileController.h"
40 #include "WebTiledBackingLayerWin.h"
41 #include <QuartzCore/CoreAnimationCF.h>
42 #include <WebKitSystemInterface/WebKitSystemInterface.h>
43 #include <wtf/CurrentTime.h>
44 #include <wtf/text/CString.h>
45 #include <wtf/text/StringBuilder.h>
47 using namespace WebCore;
49 Ref<PlatformCALayer> PlatformCALayerWin::create(LayerType layerType, PlatformCALayerClient* owner)
51 return adoptRef(*new PlatformCALayerWin(layerType, nullptr, owner));
54 Ref<PlatformCALayer> PlatformCALayerWin::create(PlatformLayer* platformLayer, PlatformCALayerClient* owner)
56 return adoptRef(*new PlatformCALayerWin(LayerTypeCustom, platformLayer, owner));
59 static CFStringRef toCACFLayerType(PlatformCALayer::LayerType type)
61 return (type == PlatformCALayer::LayerTypeTransformLayer) ? kCACFTransformLayer : kCACFLayer;
64 static CFStringRef toCACFFilterType(PlatformCALayer::FilterType type)
67 case PlatformCALayer::Linear: return kCACFFilterLinear;
68 case PlatformCALayer::Nearest: return kCACFFilterNearest;
69 case PlatformCALayer::Trilinear: return kCACFFilterTrilinear;
70 default: return nullptr;
74 static AbstractCACFLayerTreeHost* layerTreeHostForLayer(const PlatformCALayer* layer)
76 // We need the AbstractCACFLayerTreeHost associated with this layer, which is stored in the UserData of the CACFContext
77 void* userData = wkCACFLayerGetContextUserData(layer->platformLayer());
81 return static_cast<AbstractCACFLayerTreeHost*>(userData);
84 static PlatformCALayerWinInternal* intern(const PlatformCALayer* layer)
86 return static_cast<PlatformCALayerWinInternal*>(CACFLayerGetUserData(layer->platformLayer()));
89 static PlatformCALayerWinInternal* intern(void* layer)
91 return static_cast<PlatformCALayerWinInternal*>(CACFLayerGetUserData(static_cast<CACFLayerRef>(layer)));
94 PlatformCALayer* PlatformCALayer::platformCALayer(void* platformLayer)
99 PlatformCALayerWinInternal* layerIntern = intern(platformLayer);
100 return layerIntern ? layerIntern->owner() : nullptr;
103 PlatformCALayer::RepaintRectList PlatformCALayer::collectRectsToPaint(CGContextRef, PlatformCALayer*)
105 // FIXME: We should actually collect rects to use instead of defaulting to Windows'
106 // normal drawing path.
107 PlatformCALayer::RepaintRectList dirtyRects;
111 void PlatformCALayer::drawLayerContents(CGContextRef context, WebCore::PlatformCALayer* platformCALayer, RepaintRectList&, GraphicsLayerPaintBehavior)
113 intern(platformCALayer)->displayCallback(platformCALayer->platformLayer(), context);
116 CGRect PlatformCALayer::frameForLayer(const PlatformLayer* tileLayer)
118 return CACFLayerGetFrame(static_cast<CACFLayerRef>(const_cast<PlatformLayer*>(tileLayer)));
121 static void displayCallback(CACFLayerRef caLayer, CGContextRef context)
123 ASSERT_ARG(caLayer, CACFLayerGetUserData(caLayer));
124 intern(caLayer)->displayCallback(caLayer, context);
127 static void layoutSublayersProc(CACFLayerRef caLayer)
129 PlatformCALayer* layer = PlatformCALayer::platformCALayer(caLayer);
130 if (layer && layer->owner())
131 layer->owner()->platformCALayerLayoutSublayersOfLayer(layer);
134 PlatformCALayerWin::PlatformCALayerWin(LayerType layerType, PlatformLayer* layer, PlatformCALayerClient* owner)
135 : PlatformCALayer(layer ? LayerTypeCustom : layerType, owner)
136 , m_customAppearance(GraphicsLayer::NoCustomAppearance)
143 m_layer = adoptCF(CACFLayerCreate(toCACFLayerType(layerType)));
145 #if HAVE(CACFLAYER_SETCONTENTSSCALE)
146 CACFLayerSetContentsScale(m_layer.get(), owner ? owner->platformCALayerDeviceScaleFactor() : deviceScaleFactorForWindow(nullptr));
149 // Create the PlatformCALayerWinInternal object and point to it in the userdata.
150 PlatformCALayerWinInternal* intern = nullptr;
152 if (usesTiledBackingLayer()) {
153 intern = new WebTiledBackingLayerWin(this);
154 TileController* tileController = reinterpret_cast<WebTiledBackingLayerWin*>(intern)->createTileController(this);
155 m_customSublayers = std::make_unique<PlatformCALayerList>(tileController->containerLayers());
157 intern = new PlatformCALayerWinInternal(this);
159 CACFLayerSetUserData(m_layer.get(), intern);
161 // Set the display callback
162 CACFLayerSetDisplayCallback(m_layer.get(), displayCallback);
163 CACFLayerSetLayoutCallback(m_layer.get(), layoutSublayersProc);
166 PlatformCALayerWin::~PlatformCALayerWin()
169 removeAllSublayers();
171 PlatformCALayerWinInternal* layerIntern = intern(this);
172 if (usesTiledBackingLayer())
173 reinterpret_cast<WebTiledBackingLayerWin*>(layerIntern)->invalidate();
175 // Get rid of the user data
176 CACFLayerSetUserData(m_layer.get(), nullptr);
178 CACFLayerRemoveFromSuperlayer(m_layer.get());
183 Ref<PlatformCALayer> PlatformCALayerWin::clone(PlatformCALayerClient* owner) const
185 PlatformCALayer::LayerType type = (layerType() == PlatformCALayer::LayerTypeTransformLayer) ?
186 PlatformCALayer::LayerTypeTransformLayer : PlatformCALayer::LayerTypeLayer;
187 auto newLayer = PlatformCALayerWin::create(type, owner);
189 newLayer->setPosition(position());
190 newLayer->setBounds(bounds());
191 newLayer->setAnchorPoint(anchorPoint());
192 newLayer->setTransform(transform());
193 newLayer->setSublayerTransform(sublayerTransform());
194 newLayer->setContents(contents());
195 newLayer->setMasksToBounds(masksToBounds());
196 newLayer->setDoubleSided(isDoubleSided());
197 newLayer->setOpaque(isOpaque());
198 newLayer->setBackgroundColor(backgroundColor());
199 newLayer->setContentsScale(contentsScale());
200 newLayer->copyFiltersFrom(*this);
205 PlatformCALayer* PlatformCALayerWin::rootLayer() const
207 AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
208 return host ? host->rootLayer() : nullptr;
211 void PlatformCALayerWin::animationStarted(const String& animationKey, CFTimeInterval beginTime)
213 // Update start time for any animation not yet started
214 CFTimeInterval cacfBeginTime = currentTimeToMediaTime(beginTime);
216 HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator end = m_animations.end();
217 for (HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator it = m_animations.begin(); it != end; ++it)
218 it->value->setActualStartTimeIfNeeded(cacfBeginTime);
221 m_owner->platformCALayerAnimationStarted(animationKey, beginTime);
224 void PlatformCALayerWin::animationEnded(const String& animationKey)
227 m_owner->platformCALayerAnimationEnded(animationKey);
230 void PlatformCALayerWin::setNeedsDisplayInRect(const FloatRect& dirtyRect)
232 intern(this)->setNeedsDisplayInRect(dirtyRect);
235 void PlatformCALayerWin::setNeedsDisplay()
237 intern(this)->setNeedsDisplay();
240 void PlatformCALayerWin::setNeedsCommit()
242 AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
244 host->layerTreeDidChange();
247 void PlatformCALayerWin::copyContentsFromLayer(PlatformCALayer* source)
250 RetainPtr<CFTypeRef> contents = CACFLayerGetContents(source->platformLayer());
251 CACFLayerSetContents(m_layer.get(), contents.get());
253 CACFLayerSetContents(m_layer.get(), nullptr);
258 void PlatformCALayerWin::setNeedsLayout()
260 if (!m_owner || !m_owner->platformCALayerRespondsToLayoutChanges())
263 CACFLayerSetNeedsLayout(m_layer.get());
267 PlatformCALayer* PlatformCALayerWin::superlayer() const
269 return platformCALayer(CACFLayerGetSuperlayer(m_layer.get()));
272 void PlatformCALayerWin::removeFromSuperlayer()
274 CACFLayerRemoveFromSuperlayer(m_layer.get());
278 void PlatformCALayerWin::setSublayers(const PlatformCALayerList& list)
280 intern(this)->setSublayers(list);
283 void PlatformCALayerWin::removeAllSublayers()
285 intern(this)->removeAllSublayers();
288 void PlatformCALayerWin::appendSublayer(PlatformCALayer& layer)
290 // This must be in terms of insertSublayer instead of a direct call so PlatformCALayerInternal can override.
291 insertSublayer(layer, intern(this)->sublayerCount());
294 void PlatformCALayerWin::insertSublayer(PlatformCALayer& layer, size_t index)
296 intern(this)->insertSublayer(layer, index);
299 void PlatformCALayerWin::replaceSublayer(PlatformCALayer& reference, PlatformCALayer& newLayer)
301 // This must not use direct calls to allow PlatformCALayerInternal to override.
302 ASSERT_ARG(reference, reference.superlayer() == this);
304 if (&reference == &newLayer)
307 int referenceIndex = intern(this)->indexOfSublayer(&reference);
308 ASSERT(referenceIndex != -1);
309 if (referenceIndex == -1)
312 reference.removeFromSuperlayer();
314 newLayer.removeFromSuperlayer();
315 insertSublayer(newLayer, referenceIndex);
318 void PlatformCALayerWin::adoptSublayers(PlatformCALayer& source)
320 PlatformCALayerList sublayers;
321 intern(&source)->getSublayers(sublayers);
323 // Use setSublayers() because it properly nulls out the superlayer pointers.
324 setSublayers(sublayers);
327 void PlatformCALayerWin::addAnimationForKey(const String& key, PlatformCAAnimation& animation)
329 // Add it to the animation list
330 m_animations.add(key, &animation);
332 CACFLayerAddAnimation(m_layer.get(), key.createCFString().get(), downcast<PlatformCAAnimationWin>(animation).platformAnimation());
335 // Tell the host about it so we can fire the start animation event
336 AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
338 host->addPendingAnimatedLayer(*this);
341 void PlatformCALayerWin::removeAnimationForKey(const String& key)
343 // Remove it from the animation list
344 m_animations.remove(key);
346 CACFLayerRemoveAnimation(m_layer.get(), key.createCFString().get());
348 // We don't "remove" a layer from AbstractCACFLayerTreeHost when it loses an animation.
349 // There may be other active animations on the layer and if an animation
350 // callback is fired on a layer without any animations no harm is done.
355 RefPtr<PlatformCAAnimation> PlatformCALayerWin::animationForKey(const String& key)
357 HashMap<String, RefPtr<PlatformCAAnimation> >::iterator it = m_animations.find(key);
358 if (it == m_animations.end())
364 void PlatformCALayerWin::setMask(PlatformCALayer* layer)
366 CACFLayerSetMask(m_layer.get(), layer ? layer->platformLayer() : 0);
370 bool PlatformCALayerWin::isOpaque() const
372 return intern(this)->isOpaque();
375 void PlatformCALayerWin::setOpaque(bool value)
377 intern(this)->setOpaque(value);
381 FloatRect PlatformCALayerWin::bounds() const
383 return CACFLayerGetBounds(m_layer.get());
386 void PlatformCALayerWin::setBounds(const FloatRect& value)
388 intern(this)->setBounds(value);
392 FloatPoint3D PlatformCALayerWin::position() const
394 CGPoint point = CACFLayerGetPosition(m_layer.get());
395 return FloatPoint3D(point.x, point.y, CACFLayerGetZPosition(m_layer.get()));
398 void PlatformCALayerWin::setPosition(const FloatPoint3D& value)
400 CACFLayerSetPosition(m_layer.get(), CGPointMake(value.x(), value.y()));
401 CACFLayerSetZPosition(m_layer.get(), value.z());
405 FloatPoint3D PlatformCALayerWin::anchorPoint() const
407 CGPoint point = CACFLayerGetAnchorPoint(m_layer.get());
408 float z = CACFLayerGetAnchorPointZ(m_layer.get());
409 return FloatPoint3D(point.x, point.y, z);
412 void PlatformCALayerWin::setAnchorPoint(const FloatPoint3D& value)
414 CACFLayerSetAnchorPoint(m_layer.get(), CGPointMake(value.x(), value.y()));
415 CACFLayerSetAnchorPointZ(m_layer.get(), value.z());
419 TransformationMatrix PlatformCALayerWin::transform() const
421 return CACFLayerGetTransform(m_layer.get());
424 void PlatformCALayerWin::setTransform(const TransformationMatrix& value)
426 CACFLayerSetTransform(m_layer.get(), value);
430 TransformationMatrix PlatformCALayerWin::sublayerTransform() const
432 return CACFLayerGetSublayerTransform(m_layer.get());
435 void PlatformCALayerWin::setSublayerTransform(const TransformationMatrix& value)
437 CACFLayerSetSublayerTransform(m_layer.get(), value);
441 bool PlatformCALayerWin::isHidden() const
443 return CACFLayerIsHidden(m_layer.get());
446 void PlatformCALayerWin::setHidden(bool value)
448 CACFLayerSetHidden(m_layer.get(), value);
452 bool PlatformCALayerWin::contentsHidden() const
457 void PlatformCALayerWin::setContentsHidden(bool)
461 void PlatformCALayerWin::setBackingStoreAttached(bool)
465 bool PlatformCALayerWin::backingStoreAttached() const
470 bool PlatformCALayerWin::userInteractionEnabled() const
475 void PlatformCALayerWin::setUserInteractionEnabled(bool)
479 bool PlatformCALayerWin::geometryFlipped() const
481 return CACFLayerIsGeometryFlipped(m_layer.get());
484 void PlatformCALayerWin::setGeometryFlipped(bool value)
486 CACFLayerSetGeometryFlipped(m_layer.get(), value);
490 bool PlatformCALayerWin::isDoubleSided() const
492 return CACFLayerIsDoubleSided(m_layer.get());
495 void PlatformCALayerWin::setDoubleSided(bool value)
497 CACFLayerSetDoubleSided(m_layer.get(), value);
501 bool PlatformCALayerWin::masksToBounds() const
503 return CACFLayerGetMasksToBounds(m_layer.get());
506 void PlatformCALayerWin::setMasksToBounds(bool value)
508 CACFLayerSetMasksToBounds(m_layer.get(), value);
512 bool PlatformCALayerWin::acceleratesDrawing() const
517 void PlatformCALayerWin::setAcceleratesDrawing(bool)
521 bool PlatformCALayerWin::wantsDeepColorBackingStore() const
526 void PlatformCALayerWin::setWantsDeepColorBackingStore(bool)
530 bool PlatformCALayerWin::supportsSubpixelAntialiasedText() const
535 void PlatformCALayerWin::setSupportsSubpixelAntialiasedText(bool)
539 CFTypeRef PlatformCALayerWin::contents() const
541 return CACFLayerGetContents(m_layer.get());
544 void PlatformCALayerWin::setContents(CFTypeRef value)
546 CACFLayerSetContents(m_layer.get(), value);
550 void PlatformCALayerWin::setContentsRect(const FloatRect& value)
552 CACFLayerSetContentsRect(m_layer.get(), value);
556 void PlatformCALayerWin::setMinificationFilter(FilterType value)
558 CACFLayerSetMinificationFilter(m_layer.get(), toCACFFilterType(value));
561 void PlatformCALayerWin::setMagnificationFilter(FilterType value)
563 CACFLayerSetMagnificationFilter(m_layer.get(), toCACFFilterType(value));
567 Color PlatformCALayerWin::backgroundColor() const
569 return CACFLayerGetBackgroundColor(m_layer.get());
572 void PlatformCALayerWin::setBackgroundColor(const Color& value)
574 CGFloat components[4];
575 value.getRGBA(components[0], components[1], components[2], components[3]);
577 RetainPtr<CGColorSpaceRef> colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
578 RetainPtr<CGColorRef> color = adoptCF(CGColorCreate(colorSpace.get(), components));
580 CACFLayerSetBackgroundColor(m_layer.get(), color.get());
584 void PlatformCALayerWin::setBorderWidth(float value)
586 intern(this)->setBorderWidth(value);
590 void PlatformCALayerWin::setBorderColor(const Color& value)
592 intern(this)->setBorderColor(value);
596 float PlatformCALayerWin::opacity() const
598 return CACFLayerGetOpacity(m_layer.get());
601 void PlatformCALayerWin::setOpacity(float value)
603 CACFLayerSetOpacity(m_layer.get(), value);
607 void PlatformCALayerWin::setFilters(const FilterOperations&)
611 void PlatformCALayerWin::copyFiltersFrom(const PlatformCALayer&)
615 void PlatformCALayerWin::setName(const String& value)
617 CACFLayerSetName(m_layer.get(), value.createCFString().get());
621 void PlatformCALayerWin::setSpeed(float value)
623 CACFLayerSetSpeed(m_layer.get(), value);
627 void PlatformCALayerWin::setTimeOffset(CFTimeInterval value)
629 CACFLayerSetTimeOffset(m_layer.get(), value);
633 void PlatformCALayerWin::setEdgeAntialiasingMask(unsigned mask)
635 CACFLayerSetEdgeAntialiasingMask(m_layer.get(), mask);
639 float PlatformCALayerWin::contentsScale() const
641 return intern(this)->contentsScale();
644 void PlatformCALayerWin::setContentsScale(float scaleFactor)
646 intern(this)->setContentsScale(scaleFactor);
650 float PlatformCALayerWin::cornerRadius() const
652 return 0; // FIXME: implement.
655 void PlatformCALayerWin::setCornerRadius(float value)
660 FloatRoundedRect PlatformCALayerWin::shapeRoundedRect() const
663 return FloatRoundedRect();
666 void PlatformCALayerWin::setShapeRoundedRect(const FloatRoundedRect&)
671 WindRule PlatformCALayerWin::shapeWindRule() const
677 void PlatformCALayerWin::setShapeWindRule(WindRule)
682 Path PlatformCALayerWin::shapePath() const
688 void PlatformCALayerWin::setShapePath(const Path&)
693 static void printIndent(StringBuilder& builder, int indent)
695 for ( ; indent > 0; --indent)
699 static void printTransform(StringBuilder& builder, const CATransform3D& transform)
702 builder.appendNumber(transform.m11);
704 builder.appendNumber(transform.m12);
706 builder.appendNumber(transform.m13);
708 builder.appendNumber(transform.m14);
709 builder.append("; ");
710 builder.appendNumber(transform.m21);
712 builder.appendNumber(transform.m22);
714 builder.appendNumber(transform.m23);
716 builder.appendNumber(transform.m24);
717 builder.append("; ");
718 builder.appendNumber(transform.m31);
720 builder.appendNumber(transform.m32);
722 builder.appendNumber(transform.m33);
724 builder.appendNumber(transform.m34);
725 builder.append("; ");
726 builder.appendNumber(transform.m41);
728 builder.appendNumber(transform.m42);
730 builder.appendNumber(transform.m43);
732 builder.appendNumber(transform.m44);
736 static void printColor(StringBuilder& builder, int indent, const String& label, CGColorRef color)
738 Color layerColor(color);
739 if (!layerColor.isValid())
742 builder.append('\n');
743 printIndent(builder, indent);
745 builder.append(label);
747 builder.append(layerColor.nameForRenderTreeAsText());
751 static void printLayer(StringBuilder& builder, const PlatformCALayer* layer, int indent)
753 FloatPoint3D layerPosition = layer->position();
754 FloatPoint3D layerAnchorPoint = layer->anchorPoint();
755 FloatRect layerBounds = layer->bounds();
756 builder.append('\n');
757 printIndent(builder, indent);
759 char* layerTypeName = nullptr;
760 switch (layer->layerType()) {
761 case PlatformCALayer::LayerTypeLayer: layerTypeName = "layer"; break;
762 case PlatformCALayer::LayerTypeWebLayer: layerTypeName = "web-layer"; break;
763 case PlatformCALayer::LayerTypeSimpleLayer: layerTypeName = "simple-layer"; break;
764 case PlatformCALayer::LayerTypeTransformLayer: layerTypeName = "transform-layer"; break;
765 case PlatformCALayer::LayerTypeTiledBackingLayer: layerTypeName = "tiled-backing-layer"; break;
766 case PlatformCALayer::LayerTypePageTiledBackingLayer: layerTypeName = "page-tiled-backing-layer"; break;
767 case PlatformCALayer::LayerTypeTiledBackingTileLayer: layerTypeName = "tiled-backing-tile-layer"; break;
768 case PlatformCALayer::LayerTypeRootLayer: layerTypeName = "root-layer"; break;
769 case PlatformCALayer::LayerTypeAVPlayerLayer: layerTypeName = "avplayer-layer"; break;
770 case PlatformCALayer::LayerTypeContentsProvidedLayer: layerTypeName = "contents-provided-layer"; break;
771 case PlatformCALayer::LayerTypeBackdropLayer: layerTypeName = "backdrop-layer"; break;
772 case PlatformCALayer::LayerTypeShapeLayer: layerTypeName = "shape-layer"; break;
773 case PlatformCALayer::LayerTypeLightSystemBackdropLayer: layerTypeName = "light-system-backdrop-layer"; break;
774 case PlatformCALayer::LayerTypeDarkSystemBackdropLayer: layerTypeName = "dark-system-backdrop-layer"; break;
775 case PlatformCALayer::LayerTypeScrollingLayer: layerTypeName = "scrolling-layer"; break;
776 case PlatformCALayer::LayerTypeCustom: layerTypeName = "custom-layer"; break;
780 builder.append(layerTypeName);
781 builder.append(" [");
782 builder.appendNumber(layerPosition.x());
784 builder.appendNumber(layerPosition.y());
786 builder.appendNumber(layerPosition.z());
787 builder.append("] [");
788 builder.appendNumber(layerBounds.x());
790 builder.appendNumber(layerBounds.y());
792 builder.appendNumber(layerBounds.width());
794 builder.appendNumber(layerBounds.height());
795 builder.append("] [");
796 builder.appendNumber(layerAnchorPoint.x());
798 builder.appendNumber(layerAnchorPoint.y());
800 builder.appendNumber(layerAnchorPoint.z());
801 builder.append("] superlayer=");
802 builder.appendNumber(reinterpret_cast<unsigned long long>(layer->superlayer()));
804 // Print name if needed
805 String layerName = CACFLayerGetName(layer->platformLayer());
806 if (!layerName.isEmpty()) {
807 builder.append('\n');
808 printIndent(builder, indent + 1);
809 builder.append("(name \"");
810 builder.append(layerName);
811 builder.append("\")");
814 // Print borderWidth if needed
815 if (CGFloat borderWidth = CACFLayerGetBorderWidth(layer->platformLayer())) {
816 builder.append('\n');
817 printIndent(builder, indent + 1);
818 builder.append("(borderWidth ");
819 builder.appendNumber(borderWidth);
823 // Print backgroundColor if needed
824 printColor(builder, indent + 1, "backgroundColor", CACFLayerGetBackgroundColor(layer->platformLayer()));
826 // Print borderColor if needed
827 printColor(builder, indent + 1, "borderColor", CACFLayerGetBorderColor(layer->platformLayer()));
829 // Print masksToBounds if needed
830 if (bool layerMasksToBounds = layer->masksToBounds()) {
831 builder.append('\n');
832 printIndent(builder, indent + 1);
833 builder.append("(masksToBounds true)");
836 if (bool geometryFlipped = layer->geometryFlipped()) {
837 builder.append('\n');
838 printIndent(builder, indent + 1);
839 builder.append("(geometryFlipped true)");
842 // Print opacity if needed
843 float layerOpacity = layer->opacity();
844 if (layerOpacity != 1) {
845 builder.append('\n');
846 printIndent(builder, indent + 1);
847 builder.append("(opacity ");
848 builder.appendNumber(layerOpacity);
852 // Print sublayerTransform if needed
853 TransformationMatrix layerTransform = layer->sublayerTransform();
854 if (!layerTransform.isIdentity()) {
855 builder.append('\n');
856 printIndent(builder, indent + 1);
857 builder.append("(sublayerTransform ");
858 printTransform(builder, layerTransform);
862 // Print transform if needed
863 layerTransform = layer->transform();
864 if (!layerTransform.isIdentity()) {
865 builder.append('\n');
866 printIndent(builder, indent + 1);
867 builder.append("(transform ");
868 printTransform(builder, layerTransform);
872 // Print contents if needed
873 if (CFTypeRef layerContents = layer->contents()) {
874 if (CFGetTypeID(layerContents) == CGImageGetTypeID()) {
875 CGImageRef imageContents = static_cast<CGImageRef>(const_cast<void*>(layerContents));
876 builder.append('\n');
877 printIndent(builder, indent + 1);
878 builder.append("(contents (image [");
879 builder.appendNumber(CGImageGetWidth(imageContents));
881 builder.appendNumber(CGImageGetHeight(imageContents));
882 builder.append("]))");
885 if (CFGetTypeID(layerContents) == CABackingStoreGetTypeID()) {
886 CABackingStoreRef backingStore = static_cast<CABackingStoreRef>(const_cast<void*>(layerContents));
887 CGImageRef imageContents = CABackingStoreGetCGImage(backingStore);
888 builder.append('\n');
889 printIndent(builder, indent + 1);
890 builder.append("(contents (backing-store [");
891 builder.appendNumber(CGImageGetWidth(imageContents));
893 builder.appendNumber(CGImageGetHeight(imageContents));
894 builder.append("]))");
898 // Print sublayers if needed
899 int n = intern(layer)->sublayerCount();
901 builder.append('\n');
902 printIndent(builder, indent + 1);
903 builder.append("(sublayers");
905 PlatformCALayerList sublayers;
906 intern(layer)->getSublayers(sublayers);
907 ASSERT(n == sublayers.size());
908 for (int i = 0; i < n; ++i)
909 printLayer(builder, sublayers[i].get(), indent + 2);
917 String PlatformCALayerWin::layerTreeAsString() const
919 // Print heading info
920 CGRect rootBounds = bounds();
922 StringBuilder builder;
923 builder.append("\n\n** Render tree at time ");
924 builder.appendNumber(monotonicallyIncreasingTime());
925 builder.append(" (bounds ");
926 builder.appendNumber(rootBounds.origin.x);
927 builder.append(", ");
928 builder.appendNumber(rootBounds.origin.y);
930 builder.appendNumber(rootBounds.size.width);
932 builder.appendNumber(rootBounds.size.height);
933 builder.append(") **\n\n");
935 // Print layer tree from the root
936 printLayer(builder, this, 0);
938 return builder.toString();
941 Ref<PlatformCALayer> PlatformCALayerWin::createCompatibleLayer(PlatformCALayer::LayerType layerType, PlatformCALayerClient* client) const
943 return PlatformCALayerWin::create(layerType, client);
946 TiledBacking* PlatformCALayerWin::tiledBacking()
948 if (!usesTiledBackingLayer())
951 return reinterpret_cast<WebTiledBackingLayerWin*>(intern(this))->tiledBacking();
954 void PlatformCALayerWin::drawTextAtPoint(CGContextRef context, CGFloat x, CGFloat y, CGSize scale, CGFloat fontSize, const char* message, size_t length, CGFloat, Color) const
956 String text(message, length);
958 FontCascadeDescription desc;
960 NONCLIENTMETRICS metrics;
961 metrics.cbSize = sizeof(metrics);
962 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0);
963 desc.setOneFamily(metrics.lfSmCaptionFont.lfFaceName);
965 desc.setComputedSize(scale.width * fontSize);
967 FontCascade font = FontCascade(desc, 0, 0);
968 font.update(nullptr);
970 GraphicsContext cg(context);
971 cg.setFillColor(Color::black);
972 cg.drawText(font, TextRun(text), IntPoint(x, y));