Changeset 83944 in webkit
- Timestamp:
- Apr 14, 2011 10:13:14 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r83943 r83944 1 2011-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 1 16 2011-04-14 Beth Dakin <bdakin@apple.com> 2 17 -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp
r83915 r83944 45 45 46 46 CCHeadsUpDisplay::CCHeadsUpDisplay(LayerRendererChromium* owner) 47 : m_currentFrameNumber(0) 47 : m_currentFrameNumber(1) 48 , m_filteredFrameTime(0) 48 49 , m_layerRenderer(owner) 49 50 , m_showFPSCounter(false) … … 52 53 m_presentTimeHistoryInSec[0] = currentTime(); 53 54 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); 54 71 } 55 72 … … 112 129 void CCHeadsUpDisplay::drawHudContents(GraphicsContext* ctx, const IntSize& hudSize) 113 130 { 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 132 131 if (m_showPlatformLayerTree) { 133 132 ctx->setFillColor(Color(0, 0, 0, 192), ColorSpaceDeviceRGB); … … 135 134 } 136 135 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 151 void 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) { 147 178 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 207 void 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; 161 217 } 162 218 } … … 164 220 void CCHeadsUpDisplay::onPresent() 165 221 { 166 m_presentTimeHistoryInSec[m_currentFrameNumber % 2] = currentTime();222 m_presentTimeHistoryInSec[m_currentFrameNumber % kPresentHistorySize] = currentTime(); 167 223 m_currentFrameNumber += 1; 168 224 } -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.h
r81884 r83944 28 28 #if USE(ACCELERATED_COMPOSITING) 29 29 30 #include "Font.h" 30 31 #include "LayerRendererChromium.h" 32 31 33 32 34 namespace WebCore { … … 60 62 explicit CCHeadsUpDisplay(LayerRendererChromium* owner); 61 63 void drawHudContents(GraphicsContext*, const IntSize& hudSize); 64 void drawFPSCounter(GraphicsContext*, int top, int height); 65 void drawPlatformLayerTree(GraphicsContext*, int top); 66 62 67 63 68 int m_currentFrameNumber; 69 70 double m_filteredFrameTime; 64 71 65 72 OwnPtr<LayerTexture> m_hudTexture; … … 67 74 LayerRendererChromium* m_layerRenderer; 68 75 69 double m_presentTimeHistoryInSec[2]; 76 static const int kPresentHistorySize = 64; 77 double m_presentTimeHistoryInSec[kPresentHistorySize]; 70 78 71 79 bool m_showFPSCounter; 72 80 bool m_showPlatformLayerTree; 81 82 OwnPtr<Font> m_smallFont; 83 OwnPtr<Font> m_mediumFont; 73 84 }; 74 85
Note: See TracChangeset
for help on using the changeset viewer.