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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 drawDebugRects(canvas, layerTreeHostImpl()->debugRectHistory()); | 168 drawDebugRects(canvas, layerTreeHostImpl()->debugRectHistory()); |
169 } | 169 } |
170 | 170 |
171 int HeadsUpDisplayLayerImpl::drawFPSCounter(SkCanvas* canvas, FrameRateCounter*
fpsCounter) | 171 int HeadsUpDisplayLayerImpl::drawFPSCounter(SkCanvas* canvas, FrameRateCounter*
fpsCounter) |
172 { | 172 { |
173 const int padding = 4; | 173 const int padding = 4; |
174 const int gap = 6; | 174 const int gap = 6; |
175 | 175 |
176 const int fontHeight = m_fontAtlas.get() ? m_fontAtlas->fontHeight() : 0; | 176 const int fontHeight = m_fontAtlas.get() ? m_fontAtlas->fontHeight() : 0; |
177 | 177 |
178 const int graphWidth = 120; | 178 const int graphWidth = fpsCounter->timeStampHistorySize() - 3; |
179 const int graphHeight = 40; | 179 const int graphHeight = 40; |
180 | 180 |
181 const int histogramWidth = 37; | 181 const int histogramWidth = 37; |
182 | 182 |
183 const int width = graphWidth + histogramWidth + 4 * padding; | 183 const int width = graphWidth + histogramWidth + 4 * padding; |
184 const int height = fontHeight + graphHeight + 4 * padding + 2; | 184 const int height = fontHeight + graphHeight + 4 * padding + 2; |
185 | 185 |
186 const int left = bounds().width() - width - 2; | 186 const int left = bounds().width() - width - 2; |
187 const int top = 2; | 187 const int top = 2; |
188 | 188 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 paint.setColor(SkColorSetRGB(130, 130, 130)); | 233 paint.setColor(SkColorSetRGB(130, 130, 130)); |
234 canvas->drawLine(graphBounds.left(), graphBounds.top() - 1, graphBounds.righ
t(), graphBounds.top() - 1, paint); | 234 canvas->drawLine(graphBounds.left(), graphBounds.top() - 1, graphBounds.righ
t(), graphBounds.top() - 1, paint); |
235 canvas->drawLine(graphBounds.left(), graphBounds.bottom(), graphBounds.right
(), graphBounds.bottom(), paint); | 235 canvas->drawLine(graphBounds.left(), graphBounds.bottom(), graphBounds.right
(), graphBounds.bottom(), paint); |
236 | 236 |
237 // Draw 60fps line. | 237 // Draw 60fps line. |
238 const double top60 = graphBounds.top() + graphBounds.height() * (1 - ((60 -
loFPS) / (hiFPS - loFPS))) - 1; | 238 const double top60 = graphBounds.top() + graphBounds.height() * (1 - ((60 -
loFPS) / (hiFPS - loFPS))) - 1; |
239 paint.setColor(SkColorSetRGB(100, 100, 100)); | 239 paint.setColor(SkColorSetRGB(100, 100, 100)); |
240 canvas->drawLine(graphBounds.left(), top60, graphBounds.right(), top60, pain
t); | 240 canvas->drawLine(graphBounds.left(), top60, graphBounds.right(), top60, pain
t); |
241 | 241 |
242 // Collect graph and histogram data. | 242 // Collect graph and histogram data. |
243 double x = 0; | 243 int x = 0; |
244 const double timeScale = 60; // in pixels/second | |
245 SkPath path; | 244 SkPath path; |
246 | 245 |
247 m_minFPS = std::numeric_limits<double>::max(); | 246 m_minFPS = std::numeric_limits<double>::max(); |
248 m_maxFPS = 0; | 247 m_maxFPS = 0; |
249 | 248 |
250 const int histogramSize = 20; | 249 const int histogramSize = 20; |
251 double histogram[histogramSize] = {0}; | 250 double histogram[histogramSize] = {0}; |
252 double maxBucketValue = 0; | 251 double maxBucketValue = 0; |
253 | 252 |
254 for (int i = fpsCounter->timeStampHistorySize() - 2; i > 0 && x <= graphBoun
ds.width(); --i) { | 253 for (int i = 1; i < fpsCounter->timeStampHistorySize() - 1; ++i) { |
255 base::TimeDelta delta = fpsCounter->timeStampOfRecentFrame(i + 1) - fpsC
ounter->timeStampOfRecentFrame(i); | 254 base::TimeDelta delta = fpsCounter->timeStampOfRecentFrame(i + 1) - fpsC
ounter->timeStampOfRecentFrame(i); |
256 | 255 |
257 // Skip this particular instantaneous frame rate if it is not likely to
have been valid. | 256 // Skip this particular instantaneous frame rate if it is not likely to
have been valid. |
258 if (!fpsCounter->isBadFrameInterval(delta)) { | 257 if (!fpsCounter->isBadFrameInterval(delta)) { |
259 | 258 |
260 double fps = 1.0 / delta.InSecondsF(); | 259 double fps = 1.0 / delta.InSecondsF(); |
261 | 260 |
262 m_minFPS = std::min(fps, m_minFPS); | 261 m_minFPS = std::min(fps, m_minFPS); |
263 m_maxFPS = std::max(fps, m_maxFPS); | 262 m_maxFPS = std::max(fps, m_maxFPS); |
264 | 263 |
265 // Clamp the FPS to the range we want to plot visually. | 264 // Clamp the FPS to the range we want to plot visually. |
266 double p = (fps - loFPS) / (hiFPS - loFPS); | 265 double p = (fps - loFPS) / (hiFPS - loFPS); |
267 if (p < 0) | 266 if (p < 0) |
268 p = 0; | 267 p = 0; |
269 if (p > 1) | 268 if (p > 1) |
270 p = 1; | 269 p = 1; |
271 | 270 |
272 // Plot this data point. | 271 // Plot this data point. |
273 SkPoint cur = SkPoint::Make(graphBounds.right() - x, graphBounds.bot
tom() - p * graphBounds.height()); | 272 SkPoint cur = SkPoint::Make(graphBounds.left() + x, graphBounds.bott
om() - p * graphBounds.height()); |
274 if (path.isEmpty()) | 273 if (path.isEmpty()) |
275 path.moveTo(cur); | 274 path.moveTo(cur); |
276 else | 275 else |
277 path.lineTo(cur); | 276 path.lineTo(cur); |
278 | 277 |
279 // Use the fps value to find the right bucket in the histogram. | 278 // Use the fps value to find the right bucket in the histogram. |
280 int bucketIndex = floor(p * (histogramSize - 1)); | 279 int bucketIndex = floor(p * (histogramSize - 1)); |
281 | 280 |
282 // Add the delta time to take the time spent at that fps rate into a
ccount. | 281 // Add the delta time to take the time spent at that fps rate into a
ccount. |
283 histogram[bucketIndex] += delta.InSecondsF(); | 282 histogram[bucketIndex] += delta.InSecondsF(); |
284 maxBucketValue = std::max(histogram[bucketIndex], maxBucketValue); | 283 maxBucketValue = std::max(histogram[bucketIndex], maxBucketValue); |
285 } | 284 } |
286 | 285 |
287 x += delta.InSecondsF() * timeScale; | 286 x++; |
288 } | 287 } |
289 | 288 |
290 // Draw FPS histogram. | 289 // Draw FPS histogram. |
291 paint.setColor(SkColorSetRGB(130, 130, 130)); | 290 paint.setColor(SkColorSetRGB(130, 130, 130)); |
292 canvas->drawLine(histogramBounds.left() - 1, histogramBounds.top() - 1, hist
ogramBounds.left() - 1, histogramBounds.bottom() + 1, paint); | 291 canvas->drawLine(histogramBounds.left() - 1, histogramBounds.top() - 1, hist
ogramBounds.left() - 1, histogramBounds.bottom() + 1, paint); |
293 canvas->drawLine(histogramBounds.right() + 1, histogramBounds.top() - 1, his
togramBounds.right() + 1, histogramBounds.bottom() + 1, paint); | 292 canvas->drawLine(histogramBounds.right() + 1, histogramBounds.top() - 1, his
togramBounds.right() + 1, histogramBounds.bottom() + 1, paint); |
294 | 293 |
295 paint.setColor(SK_ColorRED); | 294 paint.setColor(SK_ColorRED); |
296 const double barHeight = histogramBounds.height() / histogramSize; | 295 const double barHeight = histogramBounds.height() / histogramSize; |
297 | 296 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 374 |
376 canvas->restore(); | 375 canvas->restore(); |
377 } | 376 } |
378 | 377 |
379 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const | 378 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const |
380 { | 379 { |
381 return "HeadsUpDisplayLayer"; | 380 return "HeadsUpDisplayLayer"; |
382 } | 381 } |
383 | 382 |
384 } // namespace cc | 383 } // namespace cc |
OLD | NEW |