[chromium] Add setting for painting debug info onto tiles
authorenne@google.com <enne@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 May 2012 22:49:35 +0000 (22:49 +0000)
committerenne@google.com <enne@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 May 2012 22:49:35 +0000 (22:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=75763

Reviewed by James Robinson.

Add a compile-time CCSetting to paint debug information onto tiles. This
can help to understand paint counts and layer indices. This setting is
off by default.

* platform/graphics/chromium/ContentLayerChromium.cpp:
(WebCore::ContentLayerPainter::create):
(WebCore::ContentLayerPainter::paint):
(WebCore::ContentLayerPainter::ContentLayerPainter):
(WebCore::ContentLayerChromium::createTextureUpdater):
* platform/graphics/chromium/TiledLayerChromium.cpp:
(WebCore::UpdatableTile::UpdatableTile):
(WebCore::UpdatableTile::setUpdateFrame):
(WebCore::UpdatableTile::incrementPaintCount):
(WebCore::UpdatableTile::updateFrame):
(WebCore::UpdatableTile::paintCount):
(WebCore::TiledLayerChromium::TiledLayerChromium):
(WebCore::TiledLayerChromium::prepareToUpdateTiles):
(WebCore::TiledLayerChromium::paintDebugTileInfo):
* platform/graphics/chromium/TiledLayerChromium.h:
* platform/graphics/chromium/cc/CCLayerTreeHost.h:
(WebCore::CCSettings::CCSettings):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h

index 75685a9..a6414d5 100644 (file)
@@ -1,3 +1,32 @@
+2012-05-25  Adrienne Walker  <enne@google.com>
+
+        [chromium] Add setting for painting debug info onto tiles
+        https://bugs.webkit.org/show_bug.cgi?id=75763
+
+        Reviewed by James Robinson.
+
+        Add a compile-time CCSetting to paint debug information onto tiles. This
+        can help to understand paint counts and layer indices. This setting is
+        off by default.
+
+        * platform/graphics/chromium/ContentLayerChromium.cpp:
+        (WebCore::ContentLayerPainter::create):
+        (WebCore::ContentLayerPainter::paint):
+        (WebCore::ContentLayerPainter::ContentLayerPainter):
+        (WebCore::ContentLayerChromium::createTextureUpdater):
+        * platform/graphics/chromium/TiledLayerChromium.cpp:
+        (WebCore::UpdatableTile::UpdatableTile):
+        (WebCore::UpdatableTile::setUpdateFrame):
+        (WebCore::UpdatableTile::incrementPaintCount):
+        (WebCore::UpdatableTile::updateFrame):
+        (WebCore::UpdatableTile::paintCount):
+        (WebCore::TiledLayerChromium::TiledLayerChromium):
+        (WebCore::TiledLayerChromium::prepareToUpdateTiles):
+        (WebCore::TiledLayerChromium::paintDebugTileInfo):
+        * platform/graphics/chromium/TiledLayerChromium.h:
+        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+        (WebCore::CCSettings::CCSettings):
+
 2012-05-25  Ami Fischman  <fischman@chromium.org>
 
         [chromium] Default media controls should render only the currentTime-containing buffered range
index ae8d320..b86ad31 100644 (file)
@@ -49,9 +49,9 @@ namespace WebCore {
 class ContentLayerPainter : public LayerPainterChromium {
     WTF_MAKE_NONCOPYABLE(ContentLayerPainter);
 public:
-    static PassOwnPtr<ContentLayerPainter> create(ContentLayerDelegate* delegate)
+    static PassOwnPtr<ContentLayerPainter> create(ContentLayerDelegate* delegate, TiledLayerChromium* layer)
     {
-        return adoptPtr(new ContentLayerPainter(delegate));
+        return adoptPtr(new ContentLayerPainter(delegate, layer));
     }
 
     virtual void paint(GraphicsContext& context, const IntRect& contentRect)
@@ -59,19 +59,27 @@ public:
         double paintStart = currentTime();
         context.clearRect(contentRect);
         context.clip(contentRect);
-        m_delegate->paintContents(context, contentRect);
-        double paintEnd = currentTime();
-        double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart);
-        WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30);
-        WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
+        {
+            GraphicsContextStateSaver stateSaver(context, m_layer->layerTreeHost()->settings().debugShowTileInfo);
+
+            m_delegate->paintContents(context, contentRect);
+            double paintEnd = currentTime();
+            double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart);
+            WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30);
+            WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
+        }
+        if (m_layer->layerTreeHost()->settings().debugShowTileInfo)
+            m_layer->paintDebugTileInfo(context, contentRect);
     }
 private:
-    explicit ContentLayerPainter(ContentLayerDelegate* delegate)
+    explicit ContentLayerPainter(ContentLayerDelegate* delegate, TiledLayerChromium* layer)
         : m_delegate(delegate)
+        , m_layer(layer)
     {
     }
 
     ContentLayerDelegate* m_delegate;
+    TiledLayerChromium* m_layer;
 };
 
 PassRefPtr<ContentLayerChromium> ContentLayerChromium::create(ContentLayerDelegate* delegate)
@@ -126,11 +134,11 @@ void ContentLayerChromium::createTextureUpdaterIfNeeded()
     if (m_textureUpdater)
         return;
     if (layerTreeHost()->settings().acceleratePainting)
-        m_textureUpdater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate));
+        m_textureUpdater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate, this));
     else if (layerTreeHost()->settings().perTilePainting)
-        m_textureUpdater = BitmapSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate), layerTreeHost()->layerRendererCapabilities().usingMapSub);
+        m_textureUpdater = BitmapSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate, this), layerTreeHost()->layerRendererCapabilities().usingMapSub);
     else
-        m_textureUpdater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate), layerTreeHost()->layerRendererCapabilities().usingMapSub);
+        m_textureUpdater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate, this), layerTreeHost()->layerRendererCapabilities().usingMapSub);
     m_textureUpdater->setOpaque(opaque());
 
     GC3Denum textureFormat = layerTreeHost()->layerRendererCapabilities().bestTextureFormat;
index 17c351f..d029d77 100644 (file)
 
 #include "TiledLayerChromium.h"
 
+#include "FontCache.h"
+#include "FontDescription.h"
 #include "GraphicsContext3D.h"
 #include "LayerRendererChromium.h"
 #include "ManagedTexture.h"
 #include "Region.h"
+#include "TextRun.h"
 #include "TextStream.h"
 #include "TraceEvent.h"
 
@@ -73,11 +76,15 @@ public:
     bool partialUpdate;
     bool updated;
     bool isInUseOnImpl;
+    int lastUpdateFrame;
+    int totalPaintCount;
 private:
     explicit UpdatableTile(PassOwnPtr<LayerTextureUpdater::Texture> texture)
         : partialUpdate(false)
         , updated(false)
         , isInUseOnImpl(false)
+        , lastUpdateFrame(0)
+        , totalPaintCount(0)
         , m_texture(texture)
     {
     }
@@ -409,6 +416,13 @@ void TiledLayerChromium::updateTiles(bool idle, int left, int top, int right, in
                 return;
             }
 
+            if (tile->isDirty() && layerTreeHost()->settings().debugShowTileInfo) {
+                // Invalidate the entire tile so that text updates.
+                tile->dirtyRect = m_tiler->tileRect(tile);
+                tile->lastUpdateFrame = layerTreeHost()->frameNumber();
+                tile->totalPaintCount++;
+            }
+
             paintRect.unite(tile->dirtyRect);
         }
     }
@@ -712,5 +726,71 @@ IntRect TiledLayerChromium::idlePaintRect(const IntRect& visibleLayerRect)
     return prepaintRect;
 }
 
+void TiledLayerChromium::paintDebugTileInfo(GraphicsContext& context, const IntRect& layerRect)
+{
+    FontCachePurgePreventer fontCachePurgePreventer;
+
+    // Don't bother writing info onto small tiles.
+    const int minDimension = 200;
+    if (m_tiler->tileSize().width() < minDimension || m_tiler->tileSize().height() < minDimension)
+        return;
+
+    if (!m_debugInfoFont) {
+        FontDescription fontDesc;
+        fontDesc.setGenericFamily(FontDescription::MonospaceFamily);
+        fontDesc.setComputedSize(10);
+        m_debugInfoFont = adoptPtr(new Font(fontDesc, 0, 0));
+        m_debugInfoFont->update(0);
+    }
+
+    int fontHeight = m_debugInfoFont->fontMetrics().floatHeight() + 2;
+
+    int left, top, right, bottom;
+    m_tiler->layerRectToTileIndices(layerRect, left, top, right, bottom);
+    for (int j = top; j <= bottom; ++j) {
+        for (int i = left; i <= right; ++i) {
+            UpdatableTile* tile = tileAt(i, j);
+            if (!tile)
+                continue;
+
+            IntRect tileRect = m_tiler->tileRect(tile);
+            String info[] = {
+                String::format("LayerId(%d)", id()),
+                String::format("Index(%d, %d)", i, j),
+                String::format("Tile(%d, %d, %d, %d)", tileRect.x(), tileRect.y(), tileRect.width(), tileRect.height()),
+                String::format("Frame(%d)", tile->lastUpdateFrame),
+                String::format("Count(%d)", tile->totalPaintCount),
+                String::format("Layer(%d, %d)", contentBounds().width(), contentBounds().height()),
+            };
+            const size_t lines = sizeof(info) / sizeof(info[0]);
+            int width[lines];
+
+            IntPoint center = m_tiler->tileRect(tile).center();
+            int currentY = center.y() - fontHeight * lines / 2;
+
+            int maxWidth = 0;
+            for (size_t i = 0; i < lines; ++i) {
+                width[i] = m_debugInfoFont->width(TextRun(info[i]));
+                maxWidth = max(width[i], maxWidth);
+            }
+
+            IntRect textRect(IntPoint(center.x() - maxWidth / 2, currentY - fontHeight / 2), IntSize(maxWidth, fontHeight * lines + fontHeight / 2));
+
+            context.setFillColor(Color(192, 192, 192, 192), ColorSpaceDeviceRGB);
+            context.fillRect(FloatRect(textRect));
+
+            context.setFillColor(Color(64, 64, 64), ColorSpaceDeviceRGB);
+
+            for (size_t i = 0; i < lines; ++i) {
+                TextRun run(info[i]);
+                int textWidth = m_debugInfoFont->width(run);
+                IntPoint textStart(center.x() - textWidth / 2, currentY + fontHeight / 2);
+                context.drawText(*m_debugInfoFont, run, textStart);
+                currentY += fontHeight;
+            }
+        }
+    }
+}
+
 }
 #endif // USE(ACCELERATED_COMPOSITING)
index ca389f2..ebc4ee4 100644 (file)
@@ -28,6 +28,7 @@
 
 #if USE(ACCELERATED_COMPOSITING)
 
+#include "Font.h"
 #include "LayerChromium.h"
 #include "cc/CCLayerTilingData.h"
 #include "cc/CCTiledLayerImpl.h"
@@ -65,6 +66,8 @@ public:
 
     virtual Region visibleContentOpaqueRegion() const OVERRIDE;
 
+    void paintDebugTileInfo(GraphicsContext&, const IntRect&);
+
 protected:
     TiledLayerChromium();
 
@@ -127,6 +130,7 @@ private:
 
     TilingOption m_tilingOption;
     OwnPtr<CCLayerTilingData> m_tiler;
+    OwnPtr<Font> m_debugInfoFont;
 };
 
 }
index ecec23b..7146023 100644 (file)
@@ -77,6 +77,7 @@ protected:
 struct CCSettings {
     CCSettings()
             : acceleratePainting(false)
+            , debugShowTileInfo(false)
             , showFPSCounter(false)
             , showPlatformLayerTree(false)
             , showPaintRects(false)
@@ -93,6 +94,7 @@ struct CCSettings {
     { }
 
     bool acceleratePainting;
+    bool debugShowTileInfo;
     bool showFPSCounter;
     bool showPlatformLayerTree;
     bool showPaintRects;