Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/heads_up_display_layer_impl.h" | 5 #include "cc/heads_up_display_layer_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "cc/debug_colors.h" | 10 #include "cc/debug_colors.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 drawDebugRects(canvas, layerTreeImpl()->debug_rect_history()); | 171 drawDebugRects(canvas, layerTreeImpl()->debug_rect_history()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 int HeadsUpDisplayLayerImpl::drawFPSCounter(SkCanvas* canvas, FrameRateCounter* fpsCounter) | 174 int HeadsUpDisplayLayerImpl::drawFPSCounter(SkCanvas* canvas, FrameRateCounter* fpsCounter) |
| 175 { | 175 { |
| 176 const int padding = 4; | 176 const int padding = 4; |
| 177 const int gap = 6; | 177 const int gap = 6; |
| 178 | 178 |
| 179 const int fontHeight = m_fontAtlas.get() ? m_fontAtlas->fontHeight() : 0; | 179 const int fontHeight = m_fontAtlas.get() ? m_fontAtlas->fontHeight() : 0; |
| 180 | 180 |
| 181 const int graphWidth = fpsCounter->timeStampHistorySize() - 3; | 181 const int graphWidth = fpsCounter->bufferSize() - 3; |
| 182 const int graphHeight = 40; | 182 const int graphHeight = 40; |
| 183 | 183 |
| 184 const int histogramWidth = 37; | 184 const int histogramWidth = 37; |
| 185 | 185 |
| 186 const int width = graphWidth + histogramWidth + 4 * padding; | 186 const int width = graphWidth + histogramWidth + 4 * padding; |
| 187 const int height = fontHeight + graphHeight + 4 * padding + 2; | 187 const int height = fontHeight + graphHeight + 4 * padding + 2; |
| 188 | 188 |
| 189 const int left = bounds().width() - width - 2; | 189 const int left = bounds().width() - width - 2; |
| 190 const int top = 2; | 190 const int top = 2; |
| 191 | 191 |
| 192 SkPaint paint = createPaint(); | 192 SkPaint paint = createPaint(); |
| 193 | 193 |
| 194 // Draw background. | 194 // Draw background. |
| 195 paint.setColor(SkColorSetARGB(215, 17, 17, 17)); | 195 paint.setColor(SkColorSetARGB(215, 17, 17, 17)); |
| 196 canvas->drawRect(SkRect::MakeXYWH(left, top, width, height), paint); | 196 canvas->drawRect(SkRect::MakeXYWH(left, top, width, height), paint); |
| 197 | 197 |
| 198 SkRect textBounds = SkRect::MakeXYWH(left + padding, top + padding, graphWid th + histogramWidth + gap + 2, fontHeight); | 198 SkRect textBounds = SkRect::MakeXYWH(left + padding, top + padding, graphWid th + histogramWidth + gap + 2, fontHeight); |
| 199 SkRect graphBounds = SkRect::MakeXYWH(left + padding, textBounds.bottom() + 2 * padding, graphWidth, graphHeight); | 199 SkRect graphBounds = SkRect::MakeXYWH(left + padding, textBounds.bottom() + 2 * padding, graphWidth, graphHeight); |
| 200 SkRect histogramBounds = SkRect::MakeXYWH(graphBounds.right() + gap, graphBo unds.top(), histogramWidth, graphHeight); | 200 SkRect histogramBounds = SkRect::MakeXYWH(graphBounds.right() + gap, graphBo unds.top(), histogramWidth, graphHeight); |
| 201 | 201 |
| 202 drawFPSCounterText(canvas, paint, fpsCounter, textBounds); | 202 drawFPSCounterText(canvas, paint, fpsCounter, textBounds); |
| 203 drawFPSCounterGraphAndHistogram(canvas, paint, fpsCounter, graphBounds, hist ogramBounds); | 203 drawFPSCounterGraphAndHistogram(canvas, paint, fpsCounter, graphBounds, hist ogramBounds); |
| 204 | 204 |
| 205 return top + height; | 205 return top + height; |
| 206 } | 206 } |
| 207 | 207 |
| 208 void HeadsUpDisplayLayerImpl::drawFPSCounterText(SkCanvas* canvas, SkPaint& pain t, FrameRateCounter* fpsCounter, SkRect bounds) | 208 void HeadsUpDisplayLayerImpl::drawFPSCounterText(SkCanvas* canvas, SkPaint& pain t, FrameRateCounter* fpsCounter, SkRect bounds) |
| 209 { | 209 { |
| 210 // Update FPS text - not every frame so text is readable | 210 // Update FPS text - not every frame so text is readable |
| 211 if (base::TimeDelta(fpsCounter->timeStampOfRecentFrame(0) - textUpdateTime). InSecondsF() > 0.25) { | 211 if (base::TimeDelta(fpsCounter->readBuffer(0) - textUpdateTime).InSecondsF() > 0.25) { |
|
shawnsingh
2013/01/09 20:55:09
Personally, as I'm reading the code here, I would
| |
| 212 m_averageFPS = fpsCounter->getAverageFPS(); | 212 m_averageFPS = fpsCounter->getAverageFPS(); |
| 213 textUpdateTime = fpsCounter->timeStampOfRecentFrame(0); | 213 textUpdateTime = fpsCounter->readBuffer(0); |
| 214 } | 214 } |
| 215 | 215 |
| 216 // Draw FPS text. | 216 // Draw FPS text. |
| 217 if (m_fontAtlas.get()) { | 217 if (m_fontAtlas.get()) { |
| 218 std::string fpsText = base::StringPrintf("FPS:%5.1f", m_averageFPS); | 218 std::string fpsText = base::StringPrintf("FPS:%5.1f", m_averageFPS); |
| 219 std::string minMaxText = base::StringPrintf("%.0f-%.0f", std::min( m_min FPS, m_maxFPS), m_maxFPS); | 219 std::string minMaxText = base::StringPrintf("%.0f-%.0f", std::min( m_min FPS, m_maxFPS), m_maxFPS); |
| 220 | 220 |
| 221 int minMaxWidth = m_fontAtlas->textSize(minMaxText).width(); | 221 int minMaxWidth = m_fontAtlas->textSize(minMaxText).width(); |
| 222 gfx::Size textArea(bounds.width(), bounds.height()); | 222 gfx::Size textArea(bounds.width(), bounds.height()); |
| 223 | 223 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 246 int x = 0; | 246 int x = 0; |
| 247 SkPath path; | 247 SkPath path; |
| 248 | 248 |
| 249 m_minFPS = std::numeric_limits<double>::max(); | 249 m_minFPS = std::numeric_limits<double>::max(); |
| 250 m_maxFPS = 0; | 250 m_maxFPS = 0; |
| 251 | 251 |
| 252 const int histogramSize = 20; | 252 const int histogramSize = 20; |
| 253 double histogram[histogramSize] = {0}; | 253 double histogram[histogramSize] = {0}; |
| 254 double maxBucketValue = 0; | 254 double maxBucketValue = 0; |
| 255 | 255 |
| 256 for (int i = 1; i < fpsCounter->timeStampHistorySize() - 1; ++i) { | 256 for (int i = 1; i < fpsCounter->bufferSize() - 1; ++i) { |
| 257 base::TimeDelta delta = fpsCounter->timeStampOfRecentFrame(i + 1) - fpsC ounter->timeStampOfRecentFrame(i); | 257 base::TimeDelta delta = fpsCounter->readBuffer(i + 1) - fpsCounter->read Buffer(i); |
| 258 | 258 |
| 259 // Skip this particular instantaneous frame rate if it is not likely to have been valid. | 259 // Skip this particular instantaneous frame rate if it is not likely to have been valid. |
| 260 if (!fpsCounter->isBadFrameInterval(delta)) { | 260 if (!fpsCounter->isBadFrameInterval(delta)) { |
| 261 | 261 |
| 262 double fps = 1.0 / delta.InSecondsF(); | 262 double fps = 1.0 / delta.InSecondsF(); |
| 263 | 263 |
| 264 m_minFPS = std::min(fps, m_minFPS); | 264 m_minFPS = std::min(fps, m_minFPS); |
| 265 m_maxFPS = std::max(fps, m_maxFPS); | 265 m_maxFPS = std::max(fps, m_maxFPS); |
| 266 | 266 |
| 267 // Clamp the FPS to the range we want to plot visually. | 267 // Clamp the FPS to the range we want to plot visually. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 | 377 |
| 378 canvas->restore(); | 378 canvas->restore(); |
| 379 } | 379 } |
| 380 | 380 |
| 381 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const | 381 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const |
| 382 { | 382 { |
| 383 return "HeadsUpDisplayLayer"; | 383 return "HeadsUpDisplayLayer"; |
| 384 } | 384 } |
| 385 | 385 |
| 386 } // namespace cc | 386 } // namespace cc |
| OLD | NEW |