Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: cc/heads_up_display_layer_impl.cc

Issue 12149004: [cc] Show GPU memory usage and overage below FPS counter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/heads_up_display_layer_impl.h ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "cc/debug_colors.h" 8 #include "cc/debug_colors.h"
9 #include "cc/debug_rect_history.h" 9 #include "cc/debug_rect_history.h"
10 #include "cc/font_atlas.h" 10 #include "cc/font_atlas.h"
11 #include "cc/frame_rate_counter.h" 11 #include "cc/frame_rate_counter.h"
12 #include "cc/layer_tree_impl.h" 12 #include "cc/layer_tree_impl.h"
13 #include "cc/memory_history.h"
13 #include "cc/paint_time_counter.h" 14 #include "cc/paint_time_counter.h"
14 #include "cc/quad_sink.h" 15 #include "cc/quad_sink.h"
15 #include "cc/renderer.h" 16 #include "cc/renderer.h"
16 #include "cc/texture_draw_quad.h" 17 #include "cc/texture_draw_quad.h"
18 #include "cc/tile_manager.h"
17 #include "skia/ext/platform_canvas.h" 19 #include "skia/ext/platform_canvas.h"
18 #include "skia/ext/platform_canvas.h" 20 #include "skia/ext/platform_canvas.h"
19 #include "third_party/khronos/GLES2/gl2.h" 21 #include "third_party/khronos/GLES2/gl2.h"
20 #include "third_party/khronos/GLES2/gl2ext.h" 22 #include "third_party/khronos/GLES2/gl2ext.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "third_party/skia/include/core/SkPaint.h" 24 #include "third_party/skia/include/core/SkPaint.h"
23 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 25 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
24 #include "ui/gfx/point.h" 26 #include "ui/gfx/point.h"
25 #include "ui/gfx/size.h" 27 #include "ui/gfx/size.h"
26 28
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 bool HeadsUpDisplayLayerImpl::layerIsAlwaysDamaged() const 186 bool HeadsUpDisplayLayerImpl::layerIsAlwaysDamaged() const
185 { 187 {
186 return true; 188 return true;
187 } 189 }
188 190
189 void HeadsUpDisplayLayerImpl::drawHudContents(SkCanvas* canvas) 191 void HeadsUpDisplayLayerImpl::drawHudContents(SkCanvas* canvas)
190 { 192 {
191 const LayerTreeDebugState& debugState = layerTreeImpl()->debug_state(); 193 const LayerTreeDebugState& debugState = layerTreeImpl()->debug_state();
192 194
193 FrameRateCounter* fpsCounter = layerTreeImpl()->frame_rate_counter(); 195 FrameRateCounter* fpsCounter = layerTreeImpl()->frame_rate_counter();
196 MemoryHistory* memoryHistory = layerTreeImpl()->memory_history();
194 PaintTimeCounter* paintTimeCounter = layerTreeImpl()->paint_time_counter(); 197 PaintTimeCounter* paintTimeCounter = layerTreeImpl()->paint_time_counter();
195 198
196 if (debugState.showPlatformLayerTree) { 199 if (debugState.showPlatformLayerTree) {
197 SkPaint paint = createPaint(); 200 SkPaint paint = createPaint();
198 drawGraphBackground(canvas, &paint, SkRect::MakeXYWH(0, 0, bounds().widt h(), bounds().height())); 201 drawGraphBackground(canvas, &paint, SkRect::MakeXYWH(0, 0, bounds().widt h(), bounds().height()));
199 } 202 }
200 203
201 int top = 2; 204 int top = 2;
202 205
203 if (debugState.continuousPainting || debugState.showFPSCounter) { 206 if (debugState.continuousPainting || debugState.showFPSCounter) {
(...skipping 10 matching lines...) Expand all
214 m_paintTimeGraph.value = latest.InMillisecondsF(); 217 m_paintTimeGraph.value = latest.InMillisecondsF();
215 m_paintTimeGraph.min = min.InMillisecondsF(); 218 m_paintTimeGraph.min = min.InMillisecondsF();
216 m_paintTimeGraph.max = max.InMillisecondsF(); 219 m_paintTimeGraph.max = max.InMillisecondsF();
217 220
218 m_timeOfLastGraphUpdate = now; 221 m_timeOfLastGraphUpdate = now;
219 } 222 }
220 223
221 if (debugState.continuousPainting) 224 if (debugState.continuousPainting)
222 top = drawPaintTimeDisplay(canvas, paintTimeCounter, top); 225 top = drawPaintTimeDisplay(canvas, paintTimeCounter, top);
223 // Don't show the FPS display when continuous painting is enabled, becau se it would show misleading numbers. 226 // Don't show the FPS display when continuous painting is enabled, becau se it would show misleading numbers.
224 else if (debugState.showFPSCounter) 227 else if (debugState.showFPSCounter) {
225 top = drawFPSDisplay(canvas, fpsCounter, top); 228 top = drawFPSDisplay(canvas, fpsCounter, top);
229 }
230 if (debugState.continuousPainting ||
231 debugState.showFPSCounter) {
232 top = drawMemoryDisplay(canvas, memoryHistory, top);
233 }
226 } 234 }
227 235
228 if (debugState.showPlatformLayerTree && m_fontAtlas) { 236 if (debugState.showPlatformLayerTree && m_fontAtlas) {
229 std::string layerTree = layerTreeImpl()->layer_tree_as_text(); 237 std::string layerTree = layerTreeImpl()->layer_tree_as_text();
230 SkPaint paint = createPaint(); 238 SkPaint paint = createPaint();
231 m_fontAtlas->setColor(DebugColors::PlatformLayerTreeTextColor()); 239 m_fontAtlas->setColor(DebugColors::PlatformLayerTreeTextColor());
232 m_fontAtlas->drawText(canvas, &paint, layerTree, gfx::Point(2, top), bou nds()); 240 m_fontAtlas->drawText(canvas, &paint, layerTree, gfx::Point(2, top), bou nds());
233 } 241 }
234 242
235 if (debugState.showHudRects()) 243 if (debugState.showHudRects())
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 303
296 SkPaint paint = createPaint(); 304 SkPaint paint = createPaint();
297 drawGraphBackground(canvas, &paint, SkRect::MakeXYWH(left, top, width, heigh t)); 305 drawGraphBackground(canvas, &paint, SkRect::MakeXYWH(left, top, width, heigh t));
298 306
299 SkRect textBounds = SkRect::MakeXYWH(left + padding, top + padding, graphWid th + histogramWidth + gap + 2, fontHeight); 307 SkRect textBounds = SkRect::MakeXYWH(left + padding, top + padding, graphWid th + histogramWidth + gap + 2, fontHeight);
300 SkRect graphBounds = SkRect::MakeXYWH(left + padding, textBounds.bottom() + 2 * padding, graphWidth, graphHeight); 308 SkRect graphBounds = SkRect::MakeXYWH(left + padding, textBounds.bottom() + 2 * padding, graphWidth, graphHeight);
301 SkRect histogramBounds = SkRect::MakeXYWH(graphBounds.right() + gap, graphBo unds.top(), histogramWidth, graphHeight); 309 SkRect histogramBounds = SkRect::MakeXYWH(graphBounds.right() + gap, graphBo unds.top(), histogramWidth, graphHeight);
302 310
303 if (m_fontAtlas.get()) 311 if (m_fontAtlas.get())
304 m_fontAtlas->setColor(DebugColors::FPSDisplayTextAndGraphColor()); 312 m_fontAtlas->setColor(DebugColors::FPSDisplayTextAndGraphColor());
313
305 drawTextLeftAligned(canvas, &paint, textBounds, base::StringPrintf("FPS:%5.1 f", m_fpsGraph.value)); 314 drawTextLeftAligned(canvas, &paint, textBounds, base::StringPrintf("FPS:%5.1 f", m_fpsGraph.value));
306 drawTextRightAligned(canvas, &paint, textBounds, base::StringPrintf("%.0f-%. 0f", m_fpsGraph.min, m_fpsGraph.max)); 315 drawTextRightAligned(canvas, &paint, textBounds, base::StringPrintf("%.0f-%. 0f", m_fpsGraph.min, m_fpsGraph.max));
307 316
308 const double upperBound = Graph::updateUpperBound(&m_fpsGraph); 317 const double upperBound = Graph::updateUpperBound(&m_fpsGraph);
309 drawGraphLines(canvas, &paint, graphBounds, m_fpsGraph); 318 drawGraphLines(canvas, &paint, graphBounds, m_fpsGraph);
310 319
311 // Collect graph and histogram data. 320 // Collect graph and histogram data.
312 int x = 0; 321 int x = 0;
313 SkPath path; 322 SkPath path;
314 323
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Draw FPS graph. 374 // Draw FPS graph.
366 paint.setAntiAlias(true); 375 paint.setAntiAlias(true);
367 paint.setStyle(SkPaint::kStroke_Style); 376 paint.setStyle(SkPaint::kStroke_Style);
368 paint.setStrokeWidth(1); 377 paint.setStrokeWidth(1);
369 378
370 canvas->drawPath(path, paint); 379 canvas->drawPath(path, paint);
371 380
372 return top + height + 2; 381 return top + height + 2;
373 } 382 }
374 383
384 int HeadsUpDisplayLayerImpl::drawMemoryDisplay(SkCanvas* canvas, MemoryHistory* memoryHistory, const int& initial_top)
385 {
386 // Move up by 2 to create no gap between us and previous counter.
387 int top = initial_top - 2;
388 const int padding = 4;
389 const int fontHeight = m_fontAtlas.get() ? m_fontAtlas->fontHeight() : 0;
390
391 const int width = 181;
392 const int height = 2 * fontHeight + 3 * padding;
393
394 const int left = bounds().width() - width - 2;
395 const double megabyte = static_cast<double>(1024*1024);
396
397 SkPaint paint = createPaint();
398 drawGraphBackground(canvas, &paint, SkRect::MakeXYWH(left, top, width, heigh t));
399
400 SkRect textRun1 = SkRect::MakeXYWH(left + padding, top + padding, width, fon tHeight);
401 SkRect textRun2 = SkRect::MakeXYWH(left + padding, top + 2*padding + fontHei ght, width, fontHeight);
402
403 if (m_fontAtlas.get())
404 m_fontAtlas->setColor(DebugColors::FPSDisplayTextAndGraphColor());
405
406 std::string text;
407 MemoryHistory::Entry curEntry = memoryHistory->GetEntry(
408 memoryHistory->HistorySize() - 1);
409
410 double curMB = curEntry.bytes_total() / megabyte;
411
412 text = base::StringPrintf(
413 "%6.1f MB used",
414 (curEntry.bytes_unreleasable + curEntry.bytes_allocated) / megabyte);
415 drawTextLeftAligned(canvas, &paint, textRun1, text);
416
417 text = base::StringPrintf(
418 "%6.1f MB over budget",
419 (curEntry.bytes_over) / megabyte);
420 drawTextLeftAligned(canvas, &paint, textRun2, text);
421
422 return top + height + 2;
423 }
424
375 int HeadsUpDisplayLayerImpl::drawPaintTimeDisplay(SkCanvas* canvas, PaintTimeCou nter* paintTimeCounter, const int& top) 425 int HeadsUpDisplayLayerImpl::drawPaintTimeDisplay(SkCanvas* canvas, PaintTimeCou nter* paintTimeCounter, const int& top)
376 { 426 {
377 const int padding = 4; 427 const int padding = 4;
378 const int fontHeight = m_fontAtlas.get() ? m_fontAtlas->fontHeight() : 0; 428 const int fontHeight = m_fontAtlas.get() ? m_fontAtlas->fontHeight() : 0;
379 429
380 const int graphWidth = paintTimeCounter->HistorySize() * 2 - 1; 430 const int graphWidth = paintTimeCounter->HistorySize() * 2 - 1;
381 const int graphHeight = 40; 431 const int graphHeight = 40;
382 432
383 const int width = graphWidth + 2 * padding; 433 const int width = graphWidth + 2 * padding;
384 const int height = fontHeight + graphHeight + 4 * padding + 2 + fontHeight + padding; 434 const int height = fontHeight + graphHeight + 4 * padding + 2 + fontHeight + padding;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 533
484 canvas->restore(); 534 canvas->restore();
485 } 535 }
486 536
487 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const 537 const char* HeadsUpDisplayLayerImpl::layerTypeAsString() const
488 { 538 {
489 return "HeadsUpDisplayLayer"; 539 return "HeadsUpDisplayLayer";
490 } 540 }
491 541
492 } // namespace cc 542 } // namespace cc
OLDNEW
« no previous file with comments | « cc/heads_up_display_layer_impl.h ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698