[Win] Provide a means for viewing the layer tree
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Sep 2015 01:00:32 +0000 (01:00 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Sep 2015 01:00:32 +0000 (01:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149165

Reviewed by Simon Fraser.

Source/WebCore:

Revise the old fprintf logic to generate a string
containing the layer tree so that it can be output
to the debugger (or elsewhere).

* platform/graphics/ca/PlatformCALayer.h: Rename 'printTree'
to 'printLayerTree', and make it available in release builds.
* platform/graphics/ca/win/CACFLayerTreeHost.cpp:
(WebCore::CACFLayerTreeHost::printLayerTree): Added. Calls into
the PlatformCALayer implementation.
* platform/graphics/ca/win/CACFLayerTreeHost.h:
* platform/graphics/ca/win/PlatformCALayerWin.cpp:
(printIndent): Revise to use two-space indent and use StringBuilder.
(printTransform): Ditto.
(printColor): Added helper function.
(printLayer): Revised to output information on the layer contents.
(PlatformCALayerWin::printLayerTree): Renamed from 'printTree'.
(PlatformCALayerWin::printTree): Deleted.
* platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:
(PlatformCALayerWinInternal::drawRepaintCounters): Drive-by fix. Match the
cocoa repaint counter logic by not painting counters for the layers that
contain the tile grid.
* platform/graphics/ca/win/PlatformCALayerWin.h:
* platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:
(PlatformCALayerWinInternal::drawRepaintCounters):

Source/WebKit/win:

Add a new WebView method "printLayerTree" so that clients
can get a string dump of the current layer tree. Add this
to a new COM interface version so no existing clients break
compatibility.

* Interfaces/IWebViewPrivate.idl:
* WebView.cpp:
(WebView::QueryInterface): Recognize the new interface version.
(WebView::printLayerTree): Added. This just calls the WebCore
implementation.
* WebView.h:

Tools:

Update MiniBrowser with a new Debug menu option that will
dump the current layer tree to the debug console.

* MiniBrowser/MiniBrowser.vcxproj/MiniBrowserLib.rc:
* MiniBrowser/MiniBrowser.vcxproj/MiniBrowserLibResource.h:
* MiniBrowser/win/Common.cpp:
(WndProc): Add handler for 'Print Layer Tree' menu option.
* MiniBrowser/win/MiniBrowser.cpp:
(MiniBrowser::printLayerTree): Added Handler.
* MiniBrowser/win/MiniBrowser.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189833 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ca/PlatformCALayer.h
Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.cpp
Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.h
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.cpp
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.h
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/Interfaces/IWebViewPrivate.idl
Source/WebKit/win/WebView.cpp
Source/WebKit/win/WebView.h
Tools/ChangeLog
Tools/MiniBrowser/MiniBrowser.vcxproj/MiniBrowserLib.rc
Tools/MiniBrowser/MiniBrowser.vcxproj/MiniBrowserLibResource.h
Tools/MiniBrowser/win/Common.cpp
Tools/MiniBrowser/win/MiniBrowser.cpp
Tools/MiniBrowser/win/MiniBrowser.h

index 4107dbe..e2319ad 100644 (file)
@@ -1,3 +1,35 @@
+2015-09-15  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] Provide a means for viewing the layer tree
+        https://bugs.webkit.org/show_bug.cgi?id=149165
+
+        Reviewed by Simon Fraser.
+
+        Revise the old fprintf logic to generate a string
+        containing the layer tree so that it can be output
+        to the debugger (or elsewhere).
+
+        * platform/graphics/ca/PlatformCALayer.h: Rename 'printTree'
+        to 'printLayerTree', and make it available in release builds.
+        * platform/graphics/ca/win/CACFLayerTreeHost.cpp:
+        (WebCore::CACFLayerTreeHost::printLayerTree): Added. Calls into
+        the PlatformCALayer implementation.
+        * platform/graphics/ca/win/CACFLayerTreeHost.h:
+        * platform/graphics/ca/win/PlatformCALayerWin.cpp:
+        (printIndent): Revise to use two-space indent and use StringBuilder.
+        (printTransform): Ditto.
+        (printColor): Added helper function.
+        (printLayer): Revised to output information on the layer contents.
+        (PlatformCALayerWin::printLayerTree): Renamed from 'printTree'.
+        (PlatformCALayerWin::printTree): Deleted.
+        * platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:
+        (PlatformCALayerWinInternal::drawRepaintCounters): Drive-by fix. Match the
+        cocoa repaint counter logic by not painting counters for the layers that
+        contain the tile grid.
+        * platform/graphics/ca/win/PlatformCALayerWin.h:
+        * platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:
+        (PlatformCALayerWinInternal::drawRepaintCounters):
+
 2015-09-15  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Nested isolates can cause an infinite loop when laying out bidi runs
index 23ed6a8..886b134 100644 (file)
@@ -234,9 +234,7 @@ public:
     virtual PlatformCALayer* rootLayer() const = 0;
     virtual void setNeedsLayout() = 0;
     virtual void setNeedsCommit() = 0;
-#ifndef NDEBUG
-    virtual void printTree() const = 0;
-#endif // NDEBUG
+    virtual String layerTreeAsString() const = 0;
 #endif // PLATFORM(WIN)
 
 #if PLATFORM(IOS)
index 921bd5a..f5df66e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2013, 2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -322,4 +322,12 @@ CGRect CACFLayerTreeHost::bounds() const
     return winRectToCGRect(clientRect);
 }
 
+String CACFLayerTreeHost::layerTreeAsString() const
+{
+    if (!m_rootLayer)
+        return emptyString();
+
+    return m_rootLayer->layerTreeAsString();
+}
+
 }
index 0efb726..9f90023 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2009-2012, 2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -77,6 +77,8 @@ public:
     // AbstractCACFLayerTreeHost
     virtual void flushPendingLayerChangesNow();
 
+    String layerTreeAsString() const;
+
 protected:
     CACFLayerTreeHost();
 
index 5db4828..4aaefe4 100644 (file)
@@ -40,6 +40,7 @@
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
 
 using namespace WebCore;
 
@@ -641,127 +642,248 @@ void PlatformCALayerWin::setShapePath(const Path&)
     // FIXME: implement.
 }
 
-#ifndef NDEBUG
-static void printIndent(int indent)
+static void printIndent(StringBuilder& builder, int indent)
 {
     for ( ; indent > 0; --indent)
-        fprintf(stderr, "  ");
-}
+        builder.append("  ");
+}
+
+static void printTransform(StringBuilder& builder, const CATransform3D& transform)
+{
+    builder.append('[');
+    builder.appendNumber(transform.m11);
+    builder.append(' ');
+    builder.appendNumber(transform.m12);
+    builder.append(' ');
+    builder.appendNumber(transform.m13);
+    builder.append(' ');
+    builder.appendNumber(transform.m14);
+    builder.append("; ");
+    builder.appendNumber(transform.m21);
+    builder.append(' ');
+    builder.appendNumber(transform.m22);
+    builder.append(' ');
+    builder.appendNumber(transform.m23);
+    builder.append(' ');
+    builder.appendNumber(transform.m24);
+    builder.append("; ");
+    builder.appendNumber(transform.m31);
+    builder.append(' ');
+    builder.appendNumber(transform.m32);
+    builder.append(' ');
+    builder.appendNumber(transform.m33);
+    builder.append(' ');
+    builder.appendNumber(transform.m34);
+    builder.append("; ");
+    builder.appendNumber(transform.m41);
+    builder.append(' ');
+    builder.appendNumber(transform.m42);
+    builder.append(' ');
+    builder.appendNumber(transform.m43);
+    builder.append(' ');
+    builder.appendNumber(transform.m44);
+    builder.append(']');
+}
+
+static void printColor(StringBuilder& builder, int indent, const String& label, CGColorRef color)
+{
+    Color layerColor(color);
+    if (!layerColor.isValid())
+        return;
 
-static void printTransform(const CATransform3D& transform)
-{
-    fprintf(stderr, "[%g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g]",
-                    transform.m11, transform.m12, transform.m13, transform.m14, 
-                    transform.m21, transform.m22, transform.m23, transform.m24, 
-                    transform.m31, transform.m32, transform.m33, transform.m34, 
-                    transform.m41, transform.m42, transform.m43, transform.m44);
+    builder.append('\n');
+    printIndent(builder, indent);
+    builder.append('(');
+    builder.append(label);
+    builder.append(' ');
+    builder.append(layerColor.nameForRenderTreeAsText());
+    builder.append(')');
 }
 
-static void printLayer(const PlatformCALayer* layer, int indent)
+static void printLayer(StringBuilder& builder, const PlatformCALayer* layer, int indent)
 {
     FloatPoint3D layerPosition = layer->position();
     FloatPoint3D layerAnchorPoint = layer->anchorPoint();
     FloatRect layerBounds = layer->bounds();
-    printIndent(indent);
+    builder.append('\n');
+    printIndent(builder, indent);
 
-    char* layerTypeName = 0;
+    char* layerTypeName = nullptr;
     switch (layer->layerType()) {
     case PlatformCALayer::LayerTypeLayer: layerTypeName = "layer"; break;
     case PlatformCALayer::LayerTypeWebLayer: layerTypeName = "web-layer"; break;
+    case PlatformCALayer::LayerTypeSimpleLayer: layerTypeName = "simple-layer"; break;
     case PlatformCALayer::LayerTypeTransformLayer: layerTypeName = "transform-layer"; break;
     case PlatformCALayer::LayerTypeWebTiledLayer: layerTypeName = "web-tiled-layer"; break;
     case PlatformCALayer::LayerTypeTiledBackingLayer: layerTypeName = "tiled-backing-layer"; break;
+    case PlatformCALayer::LayerTypePageTiledBackingLayer: layerTypeName = "page-tiled-backing-layer"; break;
+    case PlatformCALayer::LayerTypeTiledBackingTileLayer: layerTypeName = "tiled-backing-tile-layer"; break;
     case PlatformCALayer::LayerTypeRootLayer: layerTypeName = "root-layer"; break;
+    case PlatformCALayer::LayerTypeAVPlayerLayer: layerTypeName = "avplayer-layer"; break;
+    case PlatformCALayer::LayerTypeWebGLLayer: layerTypeName = "webgl-layer"; break;
+    case PlatformCALayer::LayerTypeBackdropLayer: layerTypeName = "backdrop-layer"; break;
+    case PlatformCALayer::LayerTypeShapeLayer: layerTypeName = "shape-layer"; break;
+    case PlatformCALayer::LayerTypeLightSystemBackdropLayer: layerTypeName = "light-system-backdrop-layer"; break;
+    case PlatformCALayer::LayerTypeDarkSystemBackdropLayer: layerTypeName = "dark-system-backdrop-layer"; break;
+    case PlatformCALayer::LayerTypeScrollingLayer: layerTypeName = "scrolling-layer"; break;
     case PlatformCALayer::LayerTypeCustom: layerTypeName = "custom-layer"; break;
     }
 
-    fprintf(stderr, "(%s [%g %g %g] [%g %g %g %g] [%g %g %g] superlayer=%p\n",
-        layerTypeName,
-        layerPosition.x(), layerPosition.y(), layerPosition.z(), 
-        layerBounds.x(), layerBounds.y(), layerBounds.width(), layerBounds.height(),
-        layerAnchorPoint.x(), layerAnchorPoint.y(), layerAnchorPoint.z(), layer->superlayer());
+    builder.append("(");
+    builder.append(layerTypeName);
+    builder.append(" [");
+    builder.appendNumber(layerPosition.x());
+    builder.append(' ');
+    builder.appendNumber(layerPosition.y());
+    builder.append(' ');
+    builder.appendNumber(layerPosition.z());
+    builder.append("] [");
+    builder.appendNumber(layerBounds.x());
+    builder.append(' ');
+    builder.appendNumber(layerBounds.y());
+    builder.append(' ');
+    builder.appendNumber(layerBounds.width());
+    builder.append(' ');
+    builder.appendNumber(layerBounds.height());
+    builder.append("] [");
+    builder.appendNumber(layerAnchorPoint.x());
+    builder.append(' ');
+    builder.appendNumber(layerAnchorPoint.y());
+    builder.append(' ');
+    builder.appendNumber(layerAnchorPoint.z());
+    builder.append("] superlayer=");
+    builder.appendNumber(reinterpret_cast<unsigned long long>(layer->superlayer()));
 
     // Print name if needed
     String layerName = CACFLayerGetName(layer->platformLayer());
     if (!layerName.isEmpty()) {
-        printIndent(indent + 1);
-        fprintf(stderr, "(name %s)\n", layerName.utf8().data());
+        builder.append('\n');
+        printIndent(builder, indent + 1);
+        builder.append("(name \"");
+        builder.append(layerName);
+        builder.append("\")");
     }
 
+    // Print borderWidth if needed
+    if (CGFloat borderWidth = CACFLayerGetBorderWidth(layer->platformLayer())) {
+        builder.append('\n');
+        printIndent(builder, indent + 1);
+        builder.append("(borderWidth ");
+        builder.appendNumber(borderWidth);
+        builder.append(')');
+    }
+
+    // Print backgroundColor if needed
+    printColor(builder, indent + 1, "backgroundColor", CACFLayerGetBackgroundColor(layer->platformLayer()));
+
+    // Print borderColor if needed
+    printColor(builder, indent + 1, "borderColor", CACFLayerGetBorderColor(layer->platformLayer()));
+
     // Print masksToBounds if needed
-    bool layerMasksToBounds = layer->masksToBounds();
-    if (layerMasksToBounds) {
-        printIndent(indent + 1);
-        fprintf(stderr, "(masksToBounds true)\n");
+    if (bool layerMasksToBounds = layer->masksToBounds()) {
+        builder.append('\n');
+        printIndent(builder, indent + 1);
+        builder.append("(masksToBounds true)");
     }
 
     // Print opacity if needed
     float layerOpacity = layer->opacity();
     if (layerOpacity != 1) {
-        printIndent(indent + 1);
-        fprintf(stderr, "(opacity %hf)\n", layerOpacity);
+        builder.append('\n');
+        printIndent(builder, indent + 1);
+        builder.append("(opacity ");
+        builder.appendNumber(layerOpacity);
+        builder.append(')');
     }
 
     // Print sublayerTransform if needed
     TransformationMatrix layerTransform = layer->sublayerTransform();
     if (!layerTransform.isIdentity()) {
-        printIndent(indent + 1);
-        fprintf(stderr, "(sublayerTransform ");
-        printTransform(layerTransform);
-        fprintf(stderr, ")\n");
+        builder.append('\n');
+        printIndent(builder, indent + 1);
+        builder.append("(sublayerTransform ");
+        printTransform(builder, layerTransform);
+        builder.append(')');
     }
 
     // Print transform if needed
     layerTransform = layer->transform();
     if (!layerTransform.isIdentity()) {
-        printIndent(indent + 1);
-        fprintf(stderr, "(transform ");
-        printTransform(layerTransform);
-        fprintf(stderr, ")\n");
+        builder.append('\n');
+        printIndent(builder, indent + 1);
+        builder.append("(transform ");
+        printTransform(builder, layerTransform);
+        builder.append(')');
     }
 
     // Print contents if needed
-    CFTypeRef layerContents = layer->contents();
-    if (layerContents) {
+    if (CFTypeRef layerContents = layer->contents()) {
         if (CFGetTypeID(layerContents) == CGImageGetTypeID()) {
             CGImageRef imageContents = static_cast<CGImageRef>(const_cast<void*>(layerContents));
-            printIndent(indent + 1);
-            fprintf(stderr, "(contents (image [%Iu %Iu]))\n",
-                CGImageGetWidth(imageContents), CGImageGetHeight(imageContents));
+            builder.append('\n');
+            printIndent(builder, indent + 1);
+            builder.append("(contents (image [");
+            builder.appendNumber(CGImageGetWidth(imageContents));
+            builder.append(' ');
+            builder.appendNumber(CGImageGetHeight(imageContents));
+            builder.append("]))");
+        }
+
+        if (CFGetTypeID(layerContents) == CABackingStoreGetTypeID()) {
+            CABackingStoreRef backingStore = static_cast<CABackingStoreRef>(const_cast<void*>(layerContents));
+            CGImageRef imageContents = CABackingStoreGetCGImage(backingStore);
+            builder.append('\n');
+            printIndent(builder, indent + 1);
+            builder.append("(contents (backing-store [");
+            builder.appendNumber(CGImageGetWidth(imageContents));
+            builder.append(' ');
+            builder.appendNumber(CGImageGetHeight(imageContents));
+            builder.append("]))");
         }
     }
 
     // Print sublayers if needed
     int n = intern(layer)->sublayerCount();
     if (n > 0) {
-        printIndent(indent + 1);
-        fprintf(stderr, "(sublayers\n");
+        builder.append('\n');
+        printIndent(builder, indent + 1);
+        builder.append("(sublayers");
 
         PlatformCALayerList sublayers;
         intern(layer)->getSublayers(sublayers);
         ASSERT(n == sublayers.size());
         for (int i = 0; i < n; ++i)
-            printLayer(sublayers[i].get(), indent + 2);
+            printLayer(builder, sublayers[i].get(), indent + 2);
 
-        printIndent(indent + 1);
-        fprintf(stderr, ")\n");
+        builder.append(')');
     }
 
-    printIndent(indent);
-    fprintf(stderr, ")\n");
+    builder.append(')');
 }
 
-void PlatformCALayerWin::printTree() const
+String PlatformCALayerWin::layerTreeAsString() const
 {
     // Print heading info
     CGRect rootBounds = bounds();
-    fprintf(stderr, "\n\n** Render tree at time %g (bounds %g, %g %gx%g) **\n\n", 
-        monotonicallyIncreasingTime(), rootBounds.origin.x, rootBounds.origin.y, rootBounds.size.width, rootBounds.size.height);
+
+    StringBuilder builder;
+    builder.append("\n\n** Render tree at time ");
+    builder.appendNumber(monotonicallyIncreasingTime());
+    builder.append(" (bounds ");
+    builder.appendNumber(rootBounds.origin.x);
+    builder.append(", ");
+    builder.appendNumber(rootBounds.origin.y);
+    builder.append(' ');
+    builder.appendNumber(rootBounds.size.width);
+    builder.append('x');
+    builder.appendNumber(rootBounds.size.height);
+    builder.append(") **\n\n");
 
     // Print layer tree from the root
-    printLayer(this, 0);
+    printLayer(builder, this, 0);
+
+    return builder.toString();
 }
-#endif // #ifndef NDEBUG
 
 PassRefPtr<PlatformCALayer> PlatformCALayerWin::createCompatibleLayer(PlatformCALayer::LayerType layerType, PlatformCALayerClient* client) const
 {
index 0c8f6b7..fe699d3 100644 (file)
@@ -151,7 +151,7 @@ public:
     virtual void drawTextAtPoint(CGContextRef, CGFloat x, CGFloat y, const char* text, size_t length) const override;
 
 #ifndef NDEBUG
-    virtual void printTree() const override;
+    virtual String layerTreeAsString() const override;
 #endif
 
     virtual PassRefPtr<PlatformCALayer> clone(PlatformCALayerClient* owner) const override;
index 4aeb32a..2264848 100644 (file)
@@ -124,6 +124,11 @@ void PlatformCALayerWinInternal::displayCallback(CACFLayerRef caLayer, CGContext
 
 void PlatformCALayerWinInternal::drawRepaintCounters(CACFLayerRef caLayer, CGContextRef context, CGRect layerBounds, int drawCount)
 {
+    // We always update the repaint count, but we do not paint it for layers that
+    // only contain tiled backing layers. Those report their repaint counts themselves.
+    if (!owner() || owner()->usesTiledBackingLayer())
+        return;
+
     CGColorRef backgroundColor = nullptr;
     // Make the background of the counter the same as the border color,
     // unless there is no border, then make it red
index d7bcf38..b24480e 100644 (file)
@@ -1,3 +1,22 @@
+2015-09-15  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] Provide a means for viewing the layer tree
+        https://bugs.webkit.org/show_bug.cgi?id=149165
+
+        Reviewed by Simon Fraser.
+
+        Add a new WebView method "printLayerTree" so that clients
+        can get a string dump of the current layer tree. Add this
+        to a new COM interface version so no existing clients break
+        compatibility.
+        
+        * Interfaces/IWebViewPrivate.idl:
+        * WebView.cpp:
+        (WebView::QueryInterface): Recognize the new interface version.
+        (WebView::printLayerTree): Added. This just calls the WebCore
+        implementation.
+        * WebView.h:
+
 2015-09-12  Brian Burg  <bburg@apple.com>
 
         Web Inspector: disambiguate inspected/frontend controllers and pages in backend code
index ac93319..fdeddf8 100644 (file)
@@ -319,4 +319,10 @@ interface IWebViewPrivate2 : IWebViewPrivate
         [in] unsigned whitelistCount, [in, size_is(whitelistCount)] BSTR* whitelist,
         [in] unsigned blacklistCount, [in, size_is(blacklistCount)] BSTR* blacklist,
         [in] WebUserContentInjectedFrames injectedFrames);
-}
\ No newline at end of file
+}
+
+[ uuid(08C88359-76AA-48F2-BA27-820540E781E9) ]
+interface IWebViewPrivate3 : IWebViewPrivate2
+{
+    HRESULT layerTreeAsString([out] BSTR*);
+}
index 2212441..b48bdfd 100644 (file)
@@ -2627,6 +2627,8 @@ HRESULT WebView::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
         *ppvObject = static_cast<IWebViewPrivate*>(this);
     else if (IsEqualGUID(riid, IID_IWebViewPrivate2))
         *ppvObject = static_cast<IWebViewPrivate2*>(this);
+    else if (IsEqualGUID(riid, IID_IWebViewPrivate3))
+        *ppvObject = static_cast<IWebViewPrivate3*>(this);
     else if (IsEqualGUID(riid, IID_IWebIBActions))
         *ppvObject = static_cast<IWebIBActions*>(this);
     else if (IsEqualGUID(riid, IID_IWebViewCSS))
@@ -7431,3 +7433,24 @@ HRESULT WebView::backingScaleFactor(_Out_ double* factor)
 
     return S_OK;
 }
+
+HRESULT WebView::layerTreeAsString(_Deref_opt_out_ BSTR* treeBstr)
+{
+    if (!treeBstr)
+        return E_POINTER;
+
+    *treeBstr = nullptr;
+
+#if USE(CA)
+    if (!m_layerTreeHost)
+        return S_OK;
+
+    String tree = m_layerTreeHost->layerTreeAsString();
+
+    *treeBstr = BString(tree).release();
+    if (!*treeBstr && tree.length())
+        return E_OUTOFMEMORY;
+#endif
+
+    return S_OK;
+}
index 494f2b6..04c7ff5 100644 (file)
@@ -82,7 +82,7 @@ interface IDropTargetHelper;
 
 class WebView 
     : public IWebView
-    , public IWebViewPrivate2
+    , public IWebViewPrivate3
     , public IWebIBActions
     , public IWebViewCSS
     , public IWebViewEditing
@@ -390,6 +390,9 @@ public:
     virtual HRESULT STDMETHODCALLTYPE addUserStyleSheetToGroup(_In_ BSTR groupName, _In_opt_ IWebScriptWorld*, _In_ BSTR source, _In_ BSTR url,
         unsigned whitelistCount, __inout_ecount_full(whitelistCount) BSTR* whitelist, unsigned blacklistCount, __inout_ecount_full(blacklistCount) BSTR* blacklist, WebUserContentInjectedFrames);
 
+    // IWebViewPrivate3
+    HRESULT STDMETHODCALLTYPE layerTreeAsString(_Deref_opt_out_ BSTR*);
+
     // WebView
     bool shouldUseEmbeddedView(const WTF::String& mimeType) const;
 
index 7c36d94..48bc436 100644 (file)
@@ -1,3 +1,21 @@
+2015-09-15  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] Provide a means for viewing the layer tree
+        https://bugs.webkit.org/show_bug.cgi?id=149165
+
+        Reviewed by Simon Fraser.
+
+        Update MiniBrowser with a new Debug menu option that will
+        dump the current layer tree to the debug console.
+        
+        * MiniBrowser/MiniBrowser.vcxproj/MiniBrowserLib.rc:
+        * MiniBrowser/MiniBrowser.vcxproj/MiniBrowserLibResource.h:
+        * MiniBrowser/win/Common.cpp:
+        (WndProc): Add handler for 'Print Layer Tree' menu option.
+        * MiniBrowser/win/MiniBrowser.cpp:
+        (MiniBrowser::printLayerTree): Added Handler.
+        * MiniBrowser/win/MiniBrowser.h:
+
 2015-09-14  Myles C. Maxfield  <mmaxfield@apple.com>
 
         WebKitTestRunner declarative language setting is broken for iOS
index 582000f..93c610b 100644 (file)
@@ -107,6 +107,7 @@ BEGIN
         MENUITEM "Show Compositing Borders",    IDM_COMPOSITING_BORDERS\r
         MENUITEM SEPARATOR\r
         MENUITEM "Show Caches Window",          IDM_CACHES\r
+        MENUITEM "Show Layer Tree",             IDM_SHOW_LAYER_TREE\r
     END\r
 END\r
 \r
index db59431..6f58f73 100644 (file)
@@ -52,6 +52,7 @@
 #define IDM_ACTUAL_SIZE                 171
 #define IDM_ZOOM_IN                     172
 #define IDM_ZOOM_OUT                    173
+#define IDM_SHOW_LAYER_TREE             174
 #define IDC_EMPTY_URL_CACHE             1000
 #define IDC_RETURN_FREE_MEMORY          1001
 #define IDC_EMPTY_WEBCORE_CACHE         1002
index 68825a2..db4346c 100644 (file)
@@ -90,7 +90,7 @@ TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
 
 // Support moving the transparent window
 POINT s_windowPosition = { 100, 100 };
-SIZE s_windowSize = { 800, 400 };
+SIZE s_windowSize = { 500, 200 };
 
 // Forward declarations of functions included in this code module:
 ATOM MyRegisterClass(HINSTANCE hInstance);
@@ -512,6 +512,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
             if (gMiniBrowser)
                 gMiniBrowser->zoomOut();
             break;
+        case IDM_SHOW_LAYER_TREE:
+            if (gMiniBrowser)
+                gMiniBrowser->showLayerTree();
+            break;
         default:
             if (!ToggleMenuItem(hWnd, wmId))
                 return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
index 06af2fe..b5aee85 100644 (file)
@@ -486,6 +486,24 @@ void MiniBrowser::zoomOut()
     webActions->zoomPageOut(nullptr);
 }
 
+typedef _com_ptr_t<_com_IIID<IWebViewPrivate3, &__uuidof(IWebViewPrivate3)>> IWebViewPrivate3Ptr;
+
+void MiniBrowser::showLayerTree()
+{
+    IWebViewPrivate3Ptr webViewPrivate;
+    if (FAILED(m_webView->QueryInterface(IID_IWebViewPrivate3, reinterpret_cast<void**>(&webViewPrivate.GetInterfacePtr()))))
+        return;
+
+    OutputDebugString(L"CURRENT TREE:\n");
+
+    _bstr_t layerTreeBstr;
+    if (FAILED(webViewPrivate->layerTreeAsString(layerTreeBstr.GetAddress())))
+        OutputDebugString(L"    Failed to retrieve the layer tree.\n");
+    else
+        OutputDebugString(layerTreeBstr);
+    OutputDebugString(L"\n\n");
+}
+
 void MiniBrowser::generateFontForScaleFactor(float scaleFactor)
 {
     if (m_hURLBarFont)
index 68c89d5..fe8f530 100644 (file)
@@ -90,6 +90,8 @@ public:
     void zoomIn();
     void zoomOut();
 
+    void showLayerTree();
+
     float deviceScaleFactor() { return m_deviceScaleFactor; }
     void updateDeviceScaleFactor();