Changeset 83944 in webkit


Ignore:
Timestamp:
Apr 14, 2011 10:13:14 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-14 Nat Duca <nduca@chromium.org>

Reviewed by Darin Fisher.

[chromium] Add lowpass filter and graph to fps indicator
https://bugs.webkit.org/show_bug.cgi?id=58186

  • platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp: (WebCore::CCHeadsUpDisplay::CCHeadsUpDisplay): (WebCore::CCHeadsUpDisplay::drawHudContents): (WebCore::CCHeadsUpDisplay::drawFPSCounter): (WebCore::CCHeadsUpDisplay::drawPlatformLayerTree): (WebCore::CCHeadsUpDisplay::onPresent):
  • platform/graphics/chromium/cc/CCHeadsUpDisplay.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r83943 r83944  
     12011-04-14  Nat Duca  <nduca@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [chromium] Add lowpass filter and graph to fps indicator
     6        https://bugs.webkit.org/show_bug.cgi?id=58186
     7
     8        * platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp:
     9        (WebCore::CCHeadsUpDisplay::CCHeadsUpDisplay):
     10        (WebCore::CCHeadsUpDisplay::drawHudContents):
     11        (WebCore::CCHeadsUpDisplay::drawFPSCounter):
     12        (WebCore::CCHeadsUpDisplay::drawPlatformLayerTree):
     13        (WebCore::CCHeadsUpDisplay::onPresent):
     14        * platform/graphics/chromium/cc/CCHeadsUpDisplay.h:
     15
    1162011-04-14  Beth Dakin  <bdakin@apple.com>
    217
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp

    r83915 r83944  
    4545
    4646CCHeadsUpDisplay::CCHeadsUpDisplay(LayerRendererChromium* owner)
    47     : m_currentFrameNumber(0)
     47    : m_currentFrameNumber(1)
     48    , m_filteredFrameTime(0)
    4849    , m_layerRenderer(owner)
    4950    , m_showFPSCounter(false)
     
    5253    m_presentTimeHistoryInSec[0] = currentTime();
    5354    m_presentTimeHistoryInSec[1] = m_presentTimeHistoryInSec[0];
     55    for (int i = 2; i < kPresentHistorySize; i++)
     56        m_presentTimeHistoryInSec[i] = 0;
     57
     58    FontDescription mediumFontDesc;
     59    mediumFontDesc.setGenericFamily(FontDescription::MonospaceFamily);
     60    mediumFontDesc.setComputedSize(20);
     61
     62    m_mediumFont = adoptPtr(new Font(mediumFontDesc, 0, 0));
     63    m_mediumFont->update(0);
     64
     65    FontDescription smallFontDesc;
     66    smallFontDesc.setGenericFamily(FontDescription::MonospaceFamily);
     67    smallFontDesc.setComputedSize(10);
     68
     69    m_smallFont = adoptPtr(new Font(smallFontDesc, 0, 0));
     70    m_smallFont->update(0);
    5471}
    5572
     
    112129void CCHeadsUpDisplay::drawHudContents(GraphicsContext* ctx, const IntSize& hudSize)
    113130{
    114     FontDescription mediumFontDesc;
    115     mediumFontDesc.setGenericFamily(FontDescription::MonospaceFamily);
    116     mediumFontDesc.setComputedSize(12);
    117     Font mediumFont(mediumFontDesc, 0, 0);
    118     mediumFont.update(0);
    119 
    120     FontDescription smallFontDesc;
    121     smallFontDesc.setGenericFamily(FontDescription::MonospaceFamily);
    122     smallFontDesc.setComputedSize(10);
    123     Font smallFont(smallFontDesc, 0, 0);
    124     smallFont.update(0);
    125 
    126     // We haven't finished rendering yet, so we don't now the "current" present time.
    127     // So, consider the *last two* present times and use those as our present time.
    128     double secForLastFrame = m_presentTimeHistoryInSec[(m_currentFrameNumber - 1) % 2] - m_presentTimeHistoryInSec[m_currentFrameNumber % 2];
    129 
    130     int y = 14;
    131 
    132131    if (m_showPlatformLayerTree) {
    133132        ctx->setFillColor(Color(0, 0, 0, 192), ColorSpaceDeviceRGB);
     
    135134    }
    136135
    137     // Draw fps.
    138     String topLine = "";
    139     if (secForLastFrame > 0 && m_showFPSCounter) {
    140         double fps = 1.0 / secForLastFrame;
    141         topLine += String::format("FPS: %3.1f", fps);
    142     }
    143     if (topLine.length()) {
    144         ctx->setFillColor(Color(0, 0, 0, 255), ColorSpaceDeviceRGB);
    145         TextRun run(topLine);
    146         ctx->fillRect(FloatRect(2, 2, mediumFont.width(run) + 2.0f, 15));
     136    int fpsCounterHeight = m_mediumFont->fontMetrics().floatHeight() + 2;
     137    int fpsCounterTop = 2;
     138    int platformLayerTreeTop;
     139    if (m_showFPSCounter)
     140        platformLayerTreeTop = fpsCounterTop + fpsCounterHeight + 2;
     141    else
     142        platformLayerTreeTop = 0;
     143
     144    if (m_showFPSCounter)
     145        drawFPSCounter(ctx, fpsCounterTop, fpsCounterHeight);
     146
     147    if (m_showPlatformLayerTree)
     148        drawPlatformLayerTree(ctx, platformLayerTreeTop);
     149}
     150
     151void CCHeadsUpDisplay::drawFPSCounter(GraphicsContext* ctx, int top, int height)
     152{
     153    // Note that since we haven't finished the current frame, the FPS counter
     154    // actually reports the last frame's time.
     155    double secForLastFrame = m_presentTimeHistoryInSec[(m_currentFrameNumber + kPresentHistorySize - 1) % kPresentHistorySize] -
     156                             m_presentTimeHistoryInSec[(m_currentFrameNumber + kPresentHistorySize - 2) % kPresentHistorySize];
     157
     158    // Filter the frame times to avoid spikes.
     159    const float alpha = 0.1;
     160    if (!m_filteredFrameTime) {
     161        if (m_currentFrameNumber == 2)
     162            m_filteredFrameTime = secForLastFrame;
     163    } else
     164        m_filteredFrameTime = ((1.0 - alpha) * m_filteredFrameTime) + (alpha * secForLastFrame);
     165
     166    // Create & measure FPS text.
     167    String text(String::format("FPS: %5.1f", 1.0 / m_filteredFrameTime));
     168    TextRun run(text);
     169    float textWidth = m_mediumFont->width(run) + 2.0f;
     170    float graphWidth = kPresentHistorySize;
     171
     172    // Draw background.
     173    ctx->setFillColor(Color(0, 0, 0, 255), ColorSpaceDeviceRGB);
     174    ctx->fillRect(FloatRect(2, top, textWidth + graphWidth, height));
     175
     176    // Draw FPS text.
     177    if (m_filteredFrameTime) {
    147178        ctx->setFillColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
    148         ctx->drawText(mediumFont, run, IntPoint(3, y));
    149         y = 26;
    150     }
    151 
    152     // Draw layer tree, if enabled.
    153     if (m_showPlatformLayerTree) {
    154         ctx->setFillColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
    155         Vector<String> lines;
    156         m_layerRenderer->layerTreeAsText().split('\n', lines);
    157         for (size_t i = 0; i < lines.size(); ++i) {
    158             ctx->drawText(smallFont, TextRun(lines[i]), IntPoint(2, y));
    159             y += 12;
    160         }
     179        ctx->drawText(*m_mediumFont, run, IntPoint(3, top + height - 6));
     180    }
     181
     182    // Draw FPS graph.
     183    const double loFPS = 0.0;
     184    const double hiFPS = 120.0;
     185    ctx->setStrokeStyle(SolidStroke);
     186    ctx->setStrokeColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
     187    int graphLeft = static_cast<int>(textWidth + 3);
     188    IntPoint prev(-1, 0);
     189    int x = 0;
     190    double h = static_cast<double>(height - 2);
     191    for (int i = m_currentFrameNumber % kPresentHistorySize; i != (m_currentFrameNumber - 1) % kPresentHistorySize; i = (i + 1) % kPresentHistorySize) {
     192        int j = (i + 1) % kPresentHistorySize;
     193        double fps = 1.0 / (m_presentTimeHistoryInSec[j] - m_presentTimeHistoryInSec[i]);
     194        double p = 1 - ((fps - loFPS) / (hiFPS - loFPS));
     195        if (p < 0)
     196            p = 0;
     197        if (p > 1)
     198            p = 1;
     199        IntPoint cur(graphLeft + x, 1 + top + p*h);
     200        if (prev.x() != -1)
     201            ctx->drawLine(prev, cur);
     202        prev = cur;
     203        x += 1;
     204    }
     205}
     206
     207void CCHeadsUpDisplay::drawPlatformLayerTree(GraphicsContext* ctx, int top)
     208{
     209    float smallFontHeight = m_smallFont->fontMetrics().floatHeight();
     210    int y = top + smallFontHeight - 4;
     211    ctx->setFillColor(Color(255, 0, 0), ColorSpaceDeviceRGB);
     212    Vector<String> lines;
     213    m_layerRenderer->layerTreeAsText().split('\n', lines);
     214    for (size_t i = 0; i < lines.size(); ++i) {
     215        ctx->drawText(*m_smallFont, TextRun(lines[i]), IntPoint(2, y));
     216        y += smallFontHeight;
    161217    }
    162218}
     
    164220void CCHeadsUpDisplay::onPresent()
    165221{
    166     m_presentTimeHistoryInSec[m_currentFrameNumber % 2] = currentTime();
     222    m_presentTimeHistoryInSec[m_currentFrameNumber % kPresentHistorySize] = currentTime();
    167223    m_currentFrameNumber += 1;
    168224}
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.h

    r81884 r83944  
    2828#if USE(ACCELERATED_COMPOSITING)
    2929
     30#include "Font.h"
    3031#include "LayerRendererChromium.h"
     32
    3133
    3234namespace WebCore {
     
    6062    explicit CCHeadsUpDisplay(LayerRendererChromium* owner);
    6163    void drawHudContents(GraphicsContext*, const IntSize& hudSize);
     64    void drawFPSCounter(GraphicsContext*, int top, int height);
     65    void drawPlatformLayerTree(GraphicsContext*, int top);
     66
    6267
    6368    int m_currentFrameNumber;
     69
     70    double m_filteredFrameTime;
    6471
    6572    OwnPtr<LayerTexture> m_hudTexture;
     
    6774    LayerRendererChromium* m_layerRenderer;
    6875
    69     double m_presentTimeHistoryInSec[2];
     76    static const int kPresentHistorySize = 64;
     77    double m_presentTimeHistoryInSec[kPresentHistorySize];
    7078
    7179    bool m_showFPSCounter;
    7280    bool m_showPlatformLayerTree;
     81
     82    OwnPtr<Font> m_smallFont;
     83    OwnPtr<Font> m_mediumFont;
    7384};
    7485
Note: See TracChangeset for help on using the changeset viewer.