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

Side by Side Diff: cc/layers/heads_up_display_layer_impl.cc

Issue 1377823002: Change HUD colors to distinguish status easily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed typecasting warning. Created 5 years, 2 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
« no previous file with comments | « cc/debug/debug_colors.cc ('k') | no next file » | 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/layers/heads_up_display_layer_impl.h" 5 #include "cc/layers/heads_up_display_layer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "base/trace_event/trace_event_argument.h" 13 #include "base/trace_event/trace_event_argument.h"
14 #include "cc/debug/debug_colors.h" 14 #include "cc/debug/debug_colors.h"
15 #include "cc/debug/frame_rate_counter.h" 15 #include "cc/debug/frame_rate_counter.h"
16 #include "cc/output/begin_frame_args.h" 16 #include "cc/output/begin_frame_args.h"
17 #include "cc/output/renderer.h" 17 #include "cc/output/renderer.h"
18 #include "cc/quads/texture_draw_quad.h" 18 #include "cc/quads/texture_draw_quad.h"
19 #include "cc/resources/memory_history.h" 19 #include "cc/resources/memory_history.h"
20 #include "cc/trees/layer_tree_host_impl.h" 20 #include "cc/trees/layer_tree_host_impl.h"
21 #include "cc/trees/layer_tree_impl.h" 21 #include "cc/trees/layer_tree_impl.h"
22 #include "skia/ext/platform_canvas.h" 22 #include "skia/ext/platform_canvas.h"
23 #include "third_party/skia/include/core/SkPaint.h" 23 #include "third_party/skia/include/core/SkPaint.h"
24 #include "third_party/skia/include/core/SkPath.h" 24 #include "third_party/skia/include/core/SkPath.h"
25 #include "third_party/skia/include/core/SkRRect.h"
25 #include "third_party/skia/include/core/SkTypeface.h" 26 #include "third_party/skia/include/core/SkTypeface.h"
26 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 27 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
28 #include "third_party/skia/include/effects/SkGradientShader.h"
27 #include "ui/gfx/geometry/point.h" 29 #include "ui/gfx/geometry/point.h"
28 #include "ui/gfx/geometry/size.h" 30 #include "ui/gfx/geometry/size.h"
29 #include "ui/gfx/geometry/size_conversions.h" 31 #include "ui/gfx/geometry/size_conversions.h"
30 #include "ui/gfx/hud_font.h" 32 #include "ui/gfx/hud_font.h"
31 33
32 namespace cc { 34 namespace cc {
33 35
34 static inline SkPaint CreatePaint() { 36 static inline SkPaint CreatePaint() {
35 SkPaint paint; 37 SkPaint paint;
36 #if (SK_R32_SHIFT || SK_B32_SHIFT != 16) 38 #if (SK_R32_SHIFT || SK_B32_SHIFT != 16)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 270 }
269 271
270 if (!debug_state.show_fps_counter) 272 if (!debug_state.show_fps_counter)
271 return; 273 return;
272 274
273 SkRect area = 275 SkRect area =
274 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0); 276 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0);
275 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(), 277 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(),
276 SkMaxScalar(area.width(), 150)); 278 SkMaxScalar(area.width(), 150));
277 279
278 if (debug_state.ShowMemoryStats()) 280 if (debug_state.ShowMemoryStats() && memory_entry_.total_bytes_used)
279 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); 281 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150));
280 } 282 }
281 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, 283 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint,
282 const std::string& text, 284 const std::string& text,
283 int size) const { 285 int size) const {
284 const bool anti_alias = paint->isAntiAlias(); 286 const bool anti_alias = paint->isAntiAlias();
285 paint->setAntiAlias(true); 287 paint->setAntiAlias(true);
286 paint->setTextSize(size); 288 paint->setTextSize(size);
287 paint->setTypeface(typeface_.get()); 289 paint->setTypeface(typeface_.get());
288 SkScalar text_width = paint->measureText(text.c_str(), text.length()); 290 SkScalar text_width = paint->measureText(text.c_str(), text.length());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 } 356 }
355 357
356 SkRect HeadsUpDisplayLayerImpl::DrawFPSDisplay( 358 SkRect HeadsUpDisplayLayerImpl::DrawFPSDisplay(
357 SkCanvas* canvas, 359 SkCanvas* canvas,
358 const FrameRateCounter* fps_counter, 360 const FrameRateCounter* fps_counter,
359 int right, 361 int right,
360 int top) const { 362 int top) const {
361 const int kPadding = 4; 363 const int kPadding = 4;
362 const int kGap = 6; 364 const int kGap = 6;
363 365
364 const int kFontHeight = 15; 366 const int kTitleFontHeight = 13;
367 const int kFontHeight = 12;
365 368
366 const int kGraphWidth = 369 const int kGraphWidth =
367 base::saturated_cast<int>(fps_counter->time_stamp_history_size()) - 2; 370 base::saturated_cast<int>(fps_counter->time_stamp_history_size()) - 2;
368 const int kGraphHeight = 40; 371 const int kGraphHeight = 40;
369 372
370 const int kHistogramWidth = 37; 373 const int kHistogramWidth = 37;
371 374
372 int width = kGraphWidth + kHistogramWidth + 4 * kPadding; 375 int width = kGraphWidth + kHistogramWidth + 4 * kPadding;
373 int height = kFontHeight + kGraphHeight + 4 * kPadding + 2; 376 int height = kTitleFontHeight + kFontHeight + kGraphHeight + 6 * kPadding + 2;
374 int left = bounds().width() - width - right; 377 int left = bounds().width() - width - right;
375 SkRect area = SkRect::MakeXYWH(left, top, width, height); 378 SkRect area = SkRect::MakeXYWH(left, top, width, height);
376 379
377 SkPaint paint = CreatePaint(); 380 SkPaint paint = CreatePaint();
378 DrawGraphBackground(canvas, &paint, area); 381 DrawGraphBackground(canvas, &paint, area);
379 382
383 SkRect title_bounds = SkRect::MakeXYWH(
384 left + kPadding, top + kPadding, kGraphWidth + kHistogramWidth + kGap + 2,
385 kTitleFontHeight);
380 SkRect text_bounds = 386 SkRect text_bounds =
381 SkRect::MakeXYWH(left + kPadding, 387 SkRect::MakeXYWH(left + kPadding, title_bounds.bottom() + 2 * kPadding,
382 top + kPadding, 388 kGraphWidth + kHistogramWidth + kGap + 2, kFontHeight);
383 kGraphWidth + kHistogramWidth + kGap + 2,
384 kFontHeight);
385 SkRect graph_bounds = SkRect::MakeXYWH(left + kPadding, 389 SkRect graph_bounds = SkRect::MakeXYWH(left + kPadding,
386 text_bounds.bottom() + 2 * kPadding, 390 text_bounds.bottom() + 2 * kPadding,
387 kGraphWidth, 391 kGraphWidth,
388 kGraphHeight); 392 kGraphHeight);
389 SkRect histogram_bounds = SkRect::MakeXYWH(graph_bounds.right() + kGap, 393 SkRect histogram_bounds = SkRect::MakeXYWH(graph_bounds.right() + kGap,
390 graph_bounds.top(), 394 graph_bounds.top(),
391 kHistogramWidth, 395 kHistogramWidth,
392 kGraphHeight); 396 kGraphHeight);
393 397
398 const std::string title("Frame Rate");
394 const std::string value_text = 399 const std::string value_text =
395 base::StringPrintf("FPS:%5.1f", fps_graph_.value); 400 base::StringPrintf("%5.1f fps", fps_graph_.value);
396 const std::string min_max_text = 401 const std::string min_max_text =
397 base::StringPrintf("%.0f-%.0f", fps_graph_.min, fps_graph_.max); 402 base::StringPrintf("%.0f-%.0f", fps_graph_.min, fps_graph_.max);
398 403
399 VLOG(1) << value_text; 404 VLOG(1) << value_text;
400 405
406 paint.setColor(DebugColors::HUDTitleColor());
407 DrawText(canvas, &paint, title, SkPaint::kLeft_Align, kTitleFontHeight,
408 title_bounds.left(), title_bounds.bottom());
409
401 paint.setColor(DebugColors::FPSDisplayTextAndGraphColor()); 410 paint.setColor(DebugColors::FPSDisplayTextAndGraphColor());
402 DrawText(canvas, 411 DrawText(canvas,
403 &paint, 412 &paint,
404 value_text, 413 value_text,
405 SkPaint::kLeft_Align, 414 SkPaint::kLeft_Align,
406 kFontHeight, 415 kFontHeight,
407 text_bounds.left(), 416 text_bounds.left(),
408 text_bounds.bottom()); 417 text_bounds.bottom());
409 DrawText(canvas, 418 DrawText(canvas,
410 &paint, 419 &paint,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 paint.setStrokeWidth(1); 500 paint.setStrokeWidth(1);
492 canvas->drawPath(path, paint); 501 canvas->drawPath(path, paint);
493 502
494 return area; 503 return area;
495 } 504 }
496 505
497 SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas, 506 SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas,
498 int right, 507 int right,
499 int top, 508 int top,
500 int width) const { 509 int width) const {
501 if (!memory_entry_.total_bytes_used) 510 const int kPadding = 4;
502 return SkRect::MakeEmpty(); 511 const int kTitleFontHeight = 13;
512 const int kFontHeight = 12;
503 513
504 const int kPadding = 4; 514 const int height = kTitleFontHeight + 2 * kFontHeight + 5 * kPadding;
505 const int kFontHeight = 13;
506
507 const int height = 3 * kFontHeight + 4 * kPadding;
508 const int left = bounds().width() - width - right; 515 const int left = bounds().width() - width - right;
509 const SkRect area = SkRect::MakeXYWH(left, top, width, height); 516 const SkRect area = SkRect::MakeXYWH(left, top, width, height);
510 517
511 const double kMegabyte = 1024.0 * 1024.0; 518 const double kMegabyte = 1024.0 * 1024.0;
512 519
513 SkPaint paint = CreatePaint(); 520 SkPaint paint = CreatePaint();
514 DrawGraphBackground(canvas, &paint, area); 521 DrawGraphBackground(canvas, &paint, area);
515 522
516 SkPoint title_pos = SkPoint::Make(left + kPadding, top + kFontHeight); 523 SkPoint title_pos =
524 SkPoint::Make(left + kPadding, top + kFontHeight + kPadding);
517 SkPoint stat1_pos = SkPoint::Make(left + width - kPadding - 1, 525 SkPoint stat1_pos = SkPoint::Make(left + width - kPadding - 1,
518 top + kPadding + 2 * kFontHeight); 526 top + kPadding + 2 * kFontHeight);
519 SkPoint stat2_pos = SkPoint::Make(left + width - kPadding - 1, 527 SkPoint stat2_pos = SkPoint::Make(left + width - kPadding - 1,
520 top + 2 * kPadding + 3 * kFontHeight); 528 top + 2 * kPadding + 3 * kFontHeight);
521 529
522 paint.setColor(DebugColors::MemoryDisplayTextColor()); 530 paint.setColor(DebugColors::HUDTitleColor());
523 DrawText(canvas, 531 DrawText(canvas, &paint, "GPU Memory", SkPaint::kLeft_Align, kTitleFontHeight,
524 &paint,
525 "GPU memory",
526 SkPaint::kLeft_Align,
527 kFontHeight,
528 title_pos); 532 title_pos);
529 533
534 paint.setColor(DebugColors::MemoryDisplayTextColor());
530 std::string text = base::StringPrintf( 535 std::string text = base::StringPrintf(
531 "%6.1f MB used", memory_entry_.total_bytes_used / kMegabyte); 536 "%6.1f MB used", memory_entry_.total_bytes_used / kMegabyte);
532 DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat1_pos); 537 DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat1_pos);
533 538
534 if (!memory_entry_.had_enough_memory) 539 if (!memory_entry_.had_enough_memory)
535 paint.setColor(SK_ColorRED); 540 paint.setColor(SK_ColorRED);
536 text = base::StringPrintf("%6.1f MB max ", 541 text = base::StringPrintf("%6.1f MB max ",
537 memory_entry_.total_budget_in_bytes / kMegabyte); 542 memory_entry_.total_budget_in_bytes / kMegabyte);
538 DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat2_pos); 543 DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat2_pos);
539 544
545 // Draw memory graph.
546 int length = 2 * kFontHeight + kPadding + 12;
547 SkRect oval =
548 SkRect::MakeXYWH(left + kPadding * 6,
549 top + kTitleFontHeight + kPadding * 3, length, length);
550 paint.setAntiAlias(true);
551 paint.setStyle(SkPaint::kFill_Style);
552
553 paint.setColor(SkColorSetARGB(64, 255, 255, 0));
554 canvas->drawArc(oval, 180, 180, true, paint);
555
556 int radius = length / 2;
557 int cx = oval.left() + radius;
558 int cy = oval.top() + radius;
559 double angle = ((double)memory_entry_.total_bytes_used /
560 memory_entry_.total_budget_in_bytes) *
561 180;
562
563 SkColor colors[] = {SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN,
564 SkColorSetARGB(255, 255, 140, 0), SK_ColorRED};
565 const SkScalar pos[] = {SkFloatToScalar(0.2f), SkFloatToScalar(0.4f),
566 SkFloatToScalar(0.6f), SkFloatToScalar(0.8f),
567 SkFloatToScalar(1.0f)};
568 skia::RefPtr<SkShader> gradient_shader =
569 skia::AdoptRef(SkGradientShader::CreateSweep(cx, cy, colors, pos, 5));
570 paint.setShader(gradient_shader.get());
571 paint.setFlags(SkPaint::kAntiAlias_Flag);
572
573 // Draw current status.
574 paint.setStyle(SkPaint::kStroke_Style);
575 paint.setAlpha(32);
576 paint.setStrokeWidth(4);
577 canvas->drawArc(oval, 180, angle, true, paint);
578
579 paint.setStyle(SkPaint::kFill_Style);
580 paint.setColor(SkColorSetARGB(255, 0, 255, 0));
581 canvas->drawArc(oval, 180, angle, true, paint);
582 paint.setShader(NULL);
583
540 return area; 584 return area;
541 } 585 }
542 586
543 SkRect HeadsUpDisplayLayerImpl::DrawGpuRasterizationStatus(SkCanvas* canvas, 587 SkRect HeadsUpDisplayLayerImpl::DrawGpuRasterizationStatus(SkCanvas* canvas,
544 int right, 588 int right,
545 int top, 589 int top,
546 int width) const { 590 int width) const {
547 std::string status; 591 std::string status;
548 SkColor color = SK_ColorRED; 592 SkColor color = SK_ColorRED;
549 switch (layer_tree_impl()->GetGpuRasterizationStatus()) { 593 switch (layer_tree_impl()->GetGpuRasterizationStatus()) {
(...skipping 20 matching lines...) Expand all
570 case GpuRasterizationStatus::OFF_CONTENT: 614 case GpuRasterizationStatus::OFF_CONTENT:
571 status = "off (content)"; 615 status = "off (content)";
572 color = SK_ColorYELLOW; 616 color = SK_ColorYELLOW;
573 break; 617 break;
574 } 618 }
575 619
576 if (status.empty()) 620 if (status.empty())
577 return SkRect::MakeEmpty(); 621 return SkRect::MakeEmpty();
578 622
579 const int kPadding = 4; 623 const int kPadding = 4;
580 const int kFontHeight = 13; 624 const int kTitleFontHeight = 13;
625 const int kFontHeight = 12;
581 626
582 const int height = 2 * kFontHeight + 3 * kPadding; 627 const int height = kTitleFontHeight + kFontHeight + 3 * kPadding;
583 const int left = bounds().width() - width - right; 628 const int left = bounds().width() - width - right;
584 const SkRect area = SkRect::MakeXYWH(left, top, width, height); 629 const SkRect area = SkRect::MakeXYWH(left, top, width, height);
585 630
586 SkPaint paint = CreatePaint(); 631 SkPaint paint = CreatePaint();
587 DrawGraphBackground(canvas, &paint, area); 632 DrawGraphBackground(canvas, &paint, area);
588 633
589 SkPoint gpu_status_pos = SkPoint::Make(left + width - kPadding, 634 SkPoint gpu_status_pos = SkPoint::Make(left + width - kPadding,
590 top + 2 * kFontHeight + 2 * kPadding); 635 top + 2 * kFontHeight + 2 * kPadding);
591 636 paint.setColor(DebugColors::HUDTitleColor());
637 DrawText(canvas, &paint, "GPU Raster", SkPaint::kLeft_Align, kTitleFontHeight,
638 left + kPadding, top + kFontHeight + kPadding);
592 paint.setColor(color); 639 paint.setColor(color);
593 DrawText(canvas, &paint, "GPU raster: ", SkPaint::kLeft_Align, kFontHeight,
594 left + kPadding, top + kFontHeight + kPadding);
595 DrawText(canvas, &paint, status, SkPaint::kRight_Align, kFontHeight, 640 DrawText(canvas, &paint, status, SkPaint::kRight_Align, kFontHeight,
596 gpu_status_pos); 641 gpu_status_pos);
597 642
598 return area; 643 return area;
599 } 644 }
600 645
601 void HeadsUpDisplayLayerImpl::DrawDebugRect( 646 void HeadsUpDisplayLayerImpl::DrawDebugRect(
602 SkCanvas* canvas, 647 SkCanvas* canvas,
603 SkPaint* paint, 648 SkPaint* paint,
604 const DebugRect& rect, 649 const DebugRect& rect,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 return "cc::HeadsUpDisplayLayerImpl"; 802 return "cc::HeadsUpDisplayLayerImpl";
758 } 803 }
759 804
760 void HeadsUpDisplayLayerImpl::AsValueInto( 805 void HeadsUpDisplayLayerImpl::AsValueInto(
761 base::trace_event::TracedValue* dict) const { 806 base::trace_event::TracedValue* dict) const {
762 LayerImpl::AsValueInto(dict); 807 LayerImpl::AsValueInto(dict);
763 dict->SetString("layer_name", "Heads Up Display Layer"); 808 dict->SetString("layer_name", "Heads Up Display Layer");
764 } 809 }
765 810
766 } // namespace cc 811 } // namespace cc
OLDNEW
« no previous file with comments | « cc/debug/debug_colors.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698