[chromium] Enable sparkline FPS counter in threaded compositing mode
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Apr 2012 20:36:32 +0000 (20:36 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Apr 2012 20:36:32 +0000 (20:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82959

Patch by James Robinson <jamesr@chromium.org> on 2012-04-03
Reviewed by Adrienne Walker.

This enables rendering the FPS counter sparkline when in threaded compositing mode. We don't currently have a
way to draw text from the thread (since we can't interact with WebCore::Font objects from a non-main thread),
but having a sparkline is still useful for judging framerate stability.

There are no tests for the HUD since it's a developer-facing feature and not user-facing.

* platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
(WebCore::CCHeadsUpDisplay::CCHeadsUpDisplay):
(WebCore):
(WebCore::CCHeadsUpDisplay::~CCHeadsUpDisplay):
(WebCore::CCHeadsUpDisplay::initializeFonts):
(WebCore::CCHeadsUpDisplay::enabled):
(WebCore::CCHeadsUpDisplay::showPlatformLayerTree):
(WebCore::CCHeadsUpDisplay::draw):
(WebCore::CCHeadsUpDisplay::drawHudContents):
(WebCore::CCHeadsUpDisplay::drawFPSCounter):
(WebCore::CCHeadsUpDisplay::drawFPSCounterText):
(WebCore::CCHeadsUpDisplay::drawPlatformLayerTree):
* platform/graphics/chromium/cc/CCHeadsUpDisplay.h:
(CCHeadsUpDisplay):
* platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
(WebCore::CCLayerTreeHost::initialize):

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

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

index 37279da..b49952c 100644 (file)
@@ -1,3 +1,33 @@
+2012-04-03  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Enable sparkline FPS counter in threaded compositing mode
+        https://bugs.webkit.org/show_bug.cgi?id=82959
+
+        Reviewed by Adrienne Walker.
+
+        This enables rendering the FPS counter sparkline when in threaded compositing mode. We don't currently have a
+        way to draw text from the thread (since we can't interact with WebCore::Font objects from a non-main thread),
+        but having a sparkline is still useful for judging framerate stability.
+
+        There are no tests for the HUD since it's a developer-facing feature and not user-facing.
+
+        * platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
+        (WebCore::CCHeadsUpDisplay::CCHeadsUpDisplay):
+        (WebCore):
+        (WebCore::CCHeadsUpDisplay::~CCHeadsUpDisplay):
+        (WebCore::CCHeadsUpDisplay::initializeFonts):
+        (WebCore::CCHeadsUpDisplay::enabled):
+        (WebCore::CCHeadsUpDisplay::showPlatformLayerTree):
+        (WebCore::CCHeadsUpDisplay::draw):
+        (WebCore::CCHeadsUpDisplay::drawHudContents):
+        (WebCore::CCHeadsUpDisplay::drawFPSCounter):
+        (WebCore::CCHeadsUpDisplay::drawFPSCounterText):
+        (WebCore::CCHeadsUpDisplay::drawPlatformLayerTree):
+        * platform/graphics/chromium/cc/CCHeadsUpDisplay.h:
+        (CCHeadsUpDisplay):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+        (WebCore::CCLayerTreeHost::initialize):
+
 2012-04-02  Robert Hogan  <robert@webkit.org>
 
         CSS 2.1 failure: at-import-009.htm fails
index 2b80805..e4b15d7 100644 (file)
@@ -59,6 +59,19 @@ CCHeadsUpDisplay::CCHeadsUpDisplay(LayerRendererChromium* owner)
     for (int i = 2; i < kBeginFrameHistorySize; i++)
         m_beginTimeHistoryInSec[i] = 0;
 
+    // We can't draw text in threaded mode with the current mechanism.
+    // FIXME: Figure out a way to draw text in threaded mode.
+    if (!CCProxy::implThread())
+        initializeFonts();
+}
+
+CCHeadsUpDisplay::~CCHeadsUpDisplay()
+{
+}
+
+void CCHeadsUpDisplay::initializeFonts()
+{
+    ASSERT(!CCProxy::implThread());
     FontDescription mediumFontDesc;
     mediumFontDesc.setGenericFamily(FontDescription::MonospaceFamily);
     mediumFontDesc.setComputedSize(20);
@@ -74,10 +87,6 @@ CCHeadsUpDisplay::CCHeadsUpDisplay(LayerRendererChromium* owner)
     m_smallFont->update(0);
 }
 
-CCHeadsUpDisplay::~CCHeadsUpDisplay()
-{
-}
-
 void CCHeadsUpDisplay::onFrameBegin(double timestamp)
 {
     m_beginTimeHistoryInSec[m_currentFrameNumber % kBeginFrameHistorySize] = timestamp;
@@ -90,10 +99,12 @@ void CCHeadsUpDisplay::onSwapBuffers()
 
 bool CCHeadsUpDisplay::enabled() const
 {
-    // FIXME: HUD does not work in compositor thread mode.
-    if (CCProxy::hasImplThread())
-        return false;
-    return settings().showPlatformLayerTree || settings().showFPSCounter;
+    return showPlatformLayerTree() || settings().showFPSCounter;
+}
+
+bool CCHeadsUpDisplay::showPlatformLayerTree() const
+{
+    return settings().showPlatformLayerTree && !CCProxy::implThread();
 }
 
 void CCHeadsUpDisplay::draw()
@@ -104,7 +115,7 @@ void CCHeadsUpDisplay::draw()
 
     // Use a fullscreen texture only if we need to...
     IntSize hudSize;
-    if (settings().showPlatformLayerTree) {
+    if (showPlatformLayerTree()) {
         hudSize.setWidth(min(2048, m_layerRenderer->viewportWidth()));
         hudSize.setHeight(min(2048, m_layerRenderer->viewportHeight()));
     } else {
@@ -163,16 +174,14 @@ void CCHeadsUpDisplay::draw()
     m_hudTexture->unreserve();
 }
 
-void CCHeadsUpDisplay::drawHudContents(GraphicsContext* ctx, const IntSize& hudSize)
+void CCHeadsUpDisplay::drawHudContents(GraphicsContext* context, const IntSize& hudSize)
 {
-    FontCachePurgePreventer fontCachePurgePreventer;
-
-    if (settings().showPlatformLayerTree) {
-        ctx->setFillColor(Color(0, 0, 0, 192), ColorSpaceDeviceRGB);
-        ctx->fillRect(FloatRect(0, 0, hudSize.width(), hudSize.height()));
+    if (showPlatformLayerTree()) {
+        context->setFillColor(Color(0, 0, 0, 192), ColorSpaceDeviceRGB);
+        context->fillRect(FloatRect(0, 0, hudSize.width(), hudSize.height()));
     }
 
-    int fpsCounterHeight = m_mediumFont->fontMetrics().floatHeight() + 2;
+    int fpsCounterHeight = 25;
     int fpsCounterTop = 2;
     int platformLayerTreeTop;
     if (settings().showFPSCounter)
@@ -181,13 +190,13 @@ void CCHeadsUpDisplay::drawHudContents(GraphicsContext* ctx, const IntSize& hudS
         platformLayerTreeTop = 0;
 
     if (settings().showFPSCounter)
-        drawFPSCounter(ctx, fpsCounterTop, fpsCounterHeight);
+        drawFPSCounter(context, fpsCounterTop, fpsCounterHeight);
 
-    if (settings().showPlatformLayerTree)
-        drawPlatformLayerTree(ctx, platformLayerTreeTop);
+    if (showPlatformLayerTree())
+        drawPlatformLayerTree(context, platformLayerTreeTop);
 }
 
-void CCHeadsUpDisplay::drawFPSCounter(GraphicsContext* ctx, int top, int height)
+void CCHeadsUpDisplay::drawFPSCounter(GraphicsContext* context, int top, int height)
 {
     // Note that since we haven't finished the current frame, the FPS counter
     // actually reports the last frame's time.
@@ -202,27 +211,21 @@ void CCHeadsUpDisplay::drawFPSCounter(GraphicsContext* ctx, int top, int height)
     } else
         m_filteredFrameTime = ((1.0 - alpha) * m_filteredFrameTime) + (alpha * secForLastFrame);
 
-    // Create & measure FPS text.
-    String text(String::format("FPS: %5.1f", 1.0 / m_filteredFrameTime));
-    TextRun run(text);
-    float textWidth = m_mediumFont->width(run) + 2.0f;
-    float graphWidth = kBeginFrameHistorySize;
+    float textWidth = 0;
+    if (!CCProxy::implThread())
+        textWidth = drawFPSCounterText(context, top, height);
 
-    // Draw background.
-    ctx->setFillColor(Color(0, 0, 0, 255), ColorSpaceDeviceRGB);
-    ctx->fillRect(FloatRect(2, top, textWidth + graphWidth, height));
+    float graphWidth = kBeginFrameHistorySize;
 
-    // Draw FPS text.
-    if (m_filteredFrameTime) {
-        ctx->setFillColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
-        ctx->drawText(*m_mediumFont, run, IntPoint(3, top + height - 6));
-    }
+    // Draw background for graph
+    context->setFillColor(Color(0, 0, 0, 255), ColorSpaceDeviceRGB);
+    context->fillRect(FloatRect(2 + textWidth, top, graphWidth, height));
 
     // Draw FPS graph.
     const double loFPS = 0.0;
     const double hiFPS = 120.0;
-    ctx->setStrokeStyle(SolidStroke);
-    ctx->setStrokeColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
+    context->setStrokeStyle(SolidStroke);
+    context->setStrokeColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
     int graphLeft = static_cast<int>(textWidth + 3);
     IntPoint prev(-1, 0);
     int x = 0;
@@ -237,21 +240,49 @@ void CCHeadsUpDisplay::drawFPSCounter(GraphicsContext* ctx, int top, int height)
             p = 1;
         IntPoint cur(graphLeft + x, 1 + top + p*h);
         if (prev.x() != -1)
-            ctx->drawLine(prev, cur);
+            context->drawLine(prev, cur);
         prev = cur;
         x += 1;
     }
 }
 
-void CCHeadsUpDisplay::drawPlatformLayerTree(GraphicsContext* ctx, int top)
+float CCHeadsUpDisplay::drawFPSCounterText(GraphicsContext* context, int top, int height)
 {
+    ASSERT(!CCProxy::implThread());
+
+    FontCachePurgePreventer fontCachePurgePreventer;
+
+    // Create & measure FPS text.
+    String text(String::format("FPS: %5.1f", 1.0 / m_filteredFrameTime));
+    TextRun run(text);
+    float textWidth = m_mediumFont->width(run) + 2.0f;
+
+    // Draw background.
+    context->setFillColor(Color(0, 0, 0, 255), ColorSpaceDeviceRGB);
+    context->fillRect(FloatRect(2, top, textWidth, height));
+
+    // Draw FPS text.
+    if (m_filteredFrameTime) {
+        context->setFillColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
+        context->drawText(*m_mediumFont, run, IntPoint(3, top + height - 6));
+    }
+
+    return textWidth;
+}
+
+void CCHeadsUpDisplay::drawPlatformLayerTree(GraphicsContext* context, int top)
+{
+    ASSERT(!CCProxy::implThread());
+
+    FontCachePurgePreventer fontCachePurgePreventer;
+
     float smallFontHeight = m_smallFont->fontMetrics().floatHeight();
     int y = top + smallFontHeight - 4;
-    ctx->setFillColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
+    context->setFillColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
     Vector<String> lines;
     m_layerRenderer->layerTreeAsText().split('\n', lines);
     for (size_t i = 0; i < lines.size(); ++i) {
-        ctx->drawText(*m_smallFont, TextRun(lines[i]), IntPoint(2, y));
+        context->drawText(*m_smallFont, TextRun(lines[i]), IntPoint(2, y));
         y += smallFontHeight;
     }
 }
index 05cb20d..5adc9e9 100644 (file)
@@ -64,9 +64,14 @@ private:
     explicit CCHeadsUpDisplay(LayerRendererChromium* owner);
     void drawHudContents(GraphicsContext*, const IntSize& hudSize);
     void drawFPSCounter(GraphicsContext*, int top, int height);
+    float drawFPSCounterText(GraphicsContext*, int top, int height);
     void drawPlatformLayerTree(GraphicsContext*, int top);
     const CCSettings& settings() const;
 
+    bool showPlatformLayerTree() const;
+
+    void initializeFonts();
+
     int m_currentFrameNumber;
 
     double m_filteredFrameTime;
index 576fc2b..bbc2786 100644 (file)
@@ -89,13 +89,9 @@ CCLayerTreeHost::CCLayerTreeHost(CCLayerTreeHostClient* client, const CCSettings
 bool CCLayerTreeHost::initialize()
 {
     TRACE_EVENT("CCLayerTreeHost::initialize", this, 0);
-    if (CCProxy::hasImplThread()) {
-        // The HUD does not work in threaded mode. Turn it off.
-        m_settings.showFPSCounter = false;
-        m_settings.showPlatformLayerTree = false;
-
+    if (CCProxy::hasImplThread())
         m_proxy = CCThreadProxy::create(this);
-    else
+    else
         m_proxy = CCSingleThreadProxy::create(this);
     m_proxy->start();