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

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: Incorporated review comments. 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (IsAnimatingHUDContents()) { 267 if (IsAnimatingHUDContents()) {
266 layer_tree_impl()->SetNeedsRedraw(); 268 layer_tree_impl()->SetNeedsRedraw();
267 } 269 }
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);
277
danakj 2015/10/12 20:51:56 dont add whitespace please
275 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(), 278 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(),
276 SkMaxScalar(area.width(), 150)); 279 SkMaxScalar(area.width(), 150));
277 280
278 if (debug_state.ShowMemoryStats()) 281 if (debug_state.ShowMemoryStats() && !!memory_entry_.total_bytes_used)
danakj 2015/10/12 20:51:56 don't need !!
279 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); 282 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150));
280 } 283 }
281 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, 284 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint,
282 const std::string& text, 285 const std::string& text,
283 int size) const { 286 int size) const {
284 const bool anti_alias = paint->isAntiAlias(); 287 const bool anti_alias = paint->isAntiAlias();
285 paint->setAntiAlias(true); 288 paint->setAntiAlias(true);
286 paint->setTextSize(size); 289 paint->setTextSize(size);
287 paint->setTypeface(typeface_.get()); 290 paint->setTypeface(typeface_.get());
288 SkScalar text_width = paint->measureText(text.c_str(), text.length()); 291 SkScalar text_width = paint->measureText(text.c_str(), text.length());
289 292
290 paint->setAntiAlias(anti_alias); 293 paint->setAntiAlias(anti_alias);
291 return SkScalarCeilToInt(text_width); 294 return SkScalarCeilToInt(text_width);
292 } 295 }
293 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, 296 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas,
294 SkPaint* paint, 297 SkPaint* paint,
295 const std::string& text, 298 const std::string& text,
296 SkPaint::Align align, 299 SkPaint::Align align,
297 int size, 300 int size,
298 int x, 301 int x,
299 int y) const { 302 int y) const {
300 const bool anti_alias = paint->isAntiAlias(); 303 const bool anti_alias = paint->isAntiAlias();
301 paint->setAntiAlias(true); 304 paint->setAntiAlias(true);
302
danakj 2015/10/12 20:51:56 unrelated whitespace changes?
303 paint->setTextSize(size); 305 paint->setTextSize(size);
304 paint->setTextAlign(align); 306 paint->setTextAlign(align);
305 paint->setTypeface(typeface_.get()); 307 paint->setTypeface(typeface_.get());
306 canvas->drawText(text.c_str(), text.length(), x, y, *paint); 308 canvas->drawText(text.c_str(), text.length(), x, y, *paint);
307
308 paint->setAntiAlias(anti_alias); 309 paint->setAntiAlias(anti_alias);
309 } 310 }
310 311
311 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, 312 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas,
312 SkPaint* paint, 313 SkPaint* paint,
313 const std::string& text, 314 const std::string& text,
314 SkPaint::Align align, 315 SkPaint::Align align,
315 int size, 316 int size,
316 const SkPoint& pos) const { 317 const SkPoint& pos) const {
317 DrawText(canvas, paint, text, align, size, pos.x(), pos.y()); 318 DrawText(canvas, paint, text, align, size, pos.x(), pos.y());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 } 355 }
355 356
356 SkRect HeadsUpDisplayLayerImpl::DrawFPSDisplay( 357 SkRect HeadsUpDisplayLayerImpl::DrawFPSDisplay(
357 SkCanvas* canvas, 358 SkCanvas* canvas,
358 const FrameRateCounter* fps_counter, 359 const FrameRateCounter* fps_counter,
359 int right, 360 int right,
360 int top) const { 361 int top) const {
361 const int kPadding = 4; 362 const int kPadding = 4;
362 const int kGap = 6; 363 const int kGap = 6;
363 364
364 const int kFontHeight = 15; 365 const int kTitleFontHeight = 13;
366 const int kFontHeight = 12;
365 367
366 const int kGraphWidth = 368 const int kGraphWidth =
367 base::saturated_cast<int>(fps_counter->time_stamp_history_size()) - 2; 369 base::saturated_cast<int>(fps_counter->time_stamp_history_size()) - 2;
368 const int kGraphHeight = 40; 370 const int kGraphHeight = 40;
369 371
370 const int kHistogramWidth = 37; 372 const int kHistogramWidth = 37;
371 373
372 int width = kGraphWidth + kHistogramWidth + 4 * kPadding; 374 int width = kGraphWidth + kHistogramWidth + 4 * kPadding;
373 int height = kFontHeight + kGraphHeight + 4 * kPadding + 2; 375 int height = kTitleFontHeight + kFontHeight + kGraphHeight + 6 * kPadding + 2;
374 int left = bounds().width() - width - right; 376 int left = bounds().width() - width - right;
375 SkRect area = SkRect::MakeXYWH(left, top, width, height); 377 SkRect area = SkRect::MakeXYWH(left, top, width, height);
376 378
377 SkPaint paint = CreatePaint(); 379 SkPaint paint = CreatePaint();
378 DrawGraphBackground(canvas, &paint, area); 380 DrawGraphBackground(canvas, &paint, area);
379 381
382 SkRect title_bounds = SkRect::MakeXYWH(
383 left + kPadding, top + kPadding, kGraphWidth + kHistogramWidth + kGap + 2,
384 kTitleFontHeight);
380 SkRect text_bounds = 385 SkRect text_bounds =
381 SkRect::MakeXYWH(left + kPadding, 386 SkRect::MakeXYWH(left + kPadding, title_bounds.bottom() + 2 * kPadding,
382 top + kPadding, 387 kGraphWidth + kHistogramWidth + kGap + 2, kFontHeight);
383 kGraphWidth + kHistogramWidth + kGap + 2,
384 kFontHeight);
385 SkRect graph_bounds = SkRect::MakeXYWH(left + kPadding, 388 SkRect graph_bounds = SkRect::MakeXYWH(left + kPadding,
386 text_bounds.bottom() + 2 * kPadding, 389 text_bounds.bottom() + 2 * kPadding,
387 kGraphWidth, 390 kGraphWidth,
388 kGraphHeight); 391 kGraphHeight);
389 SkRect histogram_bounds = SkRect::MakeXYWH(graph_bounds.right() + kGap, 392 SkRect histogram_bounds = SkRect::MakeXYWH(graph_bounds.right() + kGap,
390 graph_bounds.top(), 393 graph_bounds.top(),
391 kHistogramWidth, 394 kHistogramWidth,
392 kGraphHeight); 395 kGraphHeight);
393 396
397 const std::string title("Frame Rate");
394 const std::string value_text = 398 const std::string value_text =
395 base::StringPrintf("FPS:%5.1f", fps_graph_.value); 399 base::StringPrintf("%5.1f fps", fps_graph_.value);
396 const std::string min_max_text = 400 const std::string min_max_text =
397 base::StringPrintf("%.0f-%.0f", fps_graph_.min, fps_graph_.max); 401 base::StringPrintf("%.0f-%.0f", fps_graph_.min, fps_graph_.max);
398 402
399 VLOG(1) << value_text; 403 VLOG(1) << value_text;
400 404
405 paint.setColor(DebugColors::HUDTitleColor());
406 DrawText(canvas, &paint, title, SkPaint::kLeft_Align, kTitleFontHeight,
407 title_bounds.left(), title_bounds.bottom());
408
401 paint.setColor(DebugColors::FPSDisplayTextAndGraphColor()); 409 paint.setColor(DebugColors::FPSDisplayTextAndGraphColor());
402 DrawText(canvas, 410 DrawText(canvas,
403 &paint, 411 &paint,
404 value_text, 412 value_text,
405 SkPaint::kLeft_Align, 413 SkPaint::kLeft_Align,
406 kFontHeight, 414 kFontHeight,
407 text_bounds.left(), 415 text_bounds.left(),
408 text_bounds.bottom()); 416 text_bounds.bottom());
409 DrawText(canvas, 417 DrawText(canvas,
410 &paint, 418 &paint,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 paint.setStrokeWidth(1); 499 paint.setStrokeWidth(1);
492 canvas->drawPath(path, paint); 500 canvas->drawPath(path, paint);
493 501
494 return area; 502 return area;
495 } 503 }
496 504
497 SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas, 505 SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas,
498 int right, 506 int right,
499 int top, 507 int top,
500 int width) const { 508 int width) const {
501 if (!memory_entry_.total_bytes_used) 509 const int kPadding = 4;
502 return SkRect::MakeEmpty(); 510 const int kTitleFontHeight = 13;
511 const int kFontHeight = 12;
503 512
504 const int kPadding = 4; 513 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; 514 const int left = bounds().width() - width - right;
509 const SkRect area = SkRect::MakeXYWH(left, top, width, height); 515 const SkRect area = SkRect::MakeXYWH(left, top, width, height);
510 516
511 const double kMegabyte = 1024.0 * 1024.0; 517 const double kMegabyte = 1024.0 * 1024.0;
512 518
513 SkPaint paint = CreatePaint(); 519 SkPaint paint = CreatePaint();
514 DrawGraphBackground(canvas, &paint, area); 520 DrawGraphBackground(canvas, &paint, area);
515 521
516 SkPoint title_pos = SkPoint::Make(left + kPadding, top + kFontHeight); 522 SkPoint title_pos =
523 SkPoint::Make(left + kPadding, top + kFontHeight + kPadding);
517 SkPoint stat1_pos = SkPoint::Make(left + width - kPadding - 1, 524 SkPoint stat1_pos = SkPoint::Make(left + width - kPadding - 1,
518 top + kPadding + 2 * kFontHeight); 525 top + kPadding + 2 * kFontHeight);
519 SkPoint stat2_pos = SkPoint::Make(left + width - kPadding - 1, 526 SkPoint stat2_pos = SkPoint::Make(left + width - kPadding - 1,
520 top + 2 * kPadding + 3 * kFontHeight); 527 top + 2 * kPadding + 3 * kFontHeight);
521 528
522 paint.setColor(DebugColors::MemoryDisplayTextColor()); 529 paint.setColor(DebugColors::HUDTitleColor());
523 DrawText(canvas, 530 DrawText(canvas, &paint, "GPU Memory", SkPaint::kLeft_Align, kTitleFontHeight,
524 &paint,
525 "GPU memory",
526 SkPaint::kLeft_Align,
527 kFontHeight,
528 title_pos); 531 title_pos);
529 532
533 paint.setColor(DebugColors::MemoryDisplayTextColor());
530 std::string text = base::StringPrintf( 534 std::string text = base::StringPrintf(
531 "%6.1f MB used", memory_entry_.total_bytes_used / kMegabyte); 535 "%6.1f MB used", memory_entry_.total_bytes_used / kMegabyte);
532 DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat1_pos); 536 DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat1_pos);
533 537
534 if (!memory_entry_.had_enough_memory) 538 if (!memory_entry_.had_enough_memory)
535 paint.setColor(SK_ColorRED); 539 paint.setColor(SK_ColorRED);
536 text = base::StringPrintf("%6.1f MB max ", 540 text = base::StringPrintf("%6.1f MB max ",
537 memory_entry_.total_budget_in_bytes / kMegabyte); 541 memory_entry_.total_budget_in_bytes / kMegabyte);
538 DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat2_pos); 542 DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat2_pos);
539 543
544 // Draw memory graph.
545 int length = 2 * kFontHeight + kPadding + 12;
546 SkRect oval =
547 SkRect::MakeXYWH(left + kPadding * 6,
548 top + kTitleFontHeight + kPadding * 3, length, length);
549 paint.setAntiAlias(true);
550 paint.setStyle(SkPaint::kFill_Style);
551
552 paint.setColor(SkColorSetARGB(64, 255, 255, 0));
553 canvas->drawArc(oval, 180, 180, true, paint);
554
555 int radius = length / 2;
556 int cx = oval.left() + radius;
557 int cy = oval.top() + radius;
558 double angle = ((double)memory_entry_.total_bytes_used /
559 memory_entry_.total_budget_in_bytes) *
560 180;
561
562 SkColor colors[] = {SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN,
563 SkColorSetARGB(255, 255, 140, 0), SK_ColorRED};
564 const SkScalar pos[] = {0.2, 0.4, 0.6, 0.8, 1.0};
565 skia::RefPtr<SkShader> gradient_shader =
566 skia::AdoptRef(SkGradientShader::CreateSweep(cx, cy, colors, pos, 5));
567 paint.setShader(gradient_shader.get());
568 paint.setFlags(SkPaint::kAntiAlias_Flag);
569
570 // Draw current status.
571 paint.setStyle(SkPaint::kStroke_Style);
572 paint.setAlpha(32);
573 paint.setStrokeWidth(4);
574 canvas->drawArc(oval, 180, angle, true, paint);
575
576 paint.setStyle(SkPaint::kFill_Style);
577 paint.setColor(SkColorSetARGB(255, 0, 255, 0));
578 canvas->drawArc(oval, 180, angle, true, paint);
579 paint.setShader(NULL);
580
540 return area; 581 return area;
541 } 582 }
542 583
543 SkRect HeadsUpDisplayLayerImpl::DrawGpuRasterizationStatus(SkCanvas* canvas, 584 SkRect HeadsUpDisplayLayerImpl::DrawGpuRasterizationStatus(SkCanvas* canvas,
544 int right, 585 int right,
545 int top, 586 int top,
546 int width) const { 587 int width) const {
547 std::string status; 588 std::string status;
548 SkColor color = SK_ColorRED; 589 SkColor color = SK_ColorRED;
549 switch (layer_tree_impl()->GetGpuRasterizationStatus()) { 590 switch (layer_tree_impl()->GetGpuRasterizationStatus()) {
(...skipping 20 matching lines...) Expand all
570 case GpuRasterizationStatus::OFF_CONTENT: 611 case GpuRasterizationStatus::OFF_CONTENT:
571 status = "off (content)"; 612 status = "off (content)";
572 color = SK_ColorYELLOW; 613 color = SK_ColorYELLOW;
573 break; 614 break;
574 } 615 }
575 616
576 if (status.empty()) 617 if (status.empty())
577 return SkRect::MakeEmpty(); 618 return SkRect::MakeEmpty();
578 619
579 const int kPadding = 4; 620 const int kPadding = 4;
580 const int kFontHeight = 13; 621 const int kTitleFontHeight = 13;
622 const int kFontHeight = 12;
581 623
582 const int height = 2 * kFontHeight + 3 * kPadding; 624 const int height = kTitleFontHeight + kFontHeight + 3 * kPadding;
583 const int left = bounds().width() - width - right; 625 const int left = bounds().width() - width - right;
584 const SkRect area = SkRect::MakeXYWH(left, top, width, height); 626 const SkRect area = SkRect::MakeXYWH(left, top, width, height);
585 627
586 SkPaint paint = CreatePaint(); 628 SkPaint paint = CreatePaint();
587 DrawGraphBackground(canvas, &paint, area); 629 DrawGraphBackground(canvas, &paint, area);
588 630
589 SkPoint gpu_status_pos = SkPoint::Make(left + width - kPadding, 631 SkPoint gpu_status_pos = SkPoint::Make(left + width - kPadding,
590 top + 2 * kFontHeight + 2 * kPadding); 632 top + 2 * kFontHeight + 2 * kPadding);
591 633 paint.setColor(DebugColors::HUDTitleColor());
634 DrawText(canvas, &paint, "GPU Raster", SkPaint::kLeft_Align, kTitleFontHeight,
635 left + kPadding, top + kFontHeight + kPadding);
592 paint.setColor(color); 636 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, 637 DrawText(canvas, &paint, status, SkPaint::kRight_Align, kFontHeight,
596 gpu_status_pos); 638 gpu_status_pos);
597 639
598 return area; 640 return area;
599 } 641 }
600 642
601 void HeadsUpDisplayLayerImpl::DrawDebugRect( 643 void HeadsUpDisplayLayerImpl::DrawDebugRect(
602 SkCanvas* canvas, 644 SkCanvas* canvas,
603 SkPaint* paint, 645 SkPaint* paint,
604 const DebugRect& rect, 646 const DebugRect& rect,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 return "cc::HeadsUpDisplayLayerImpl"; 799 return "cc::HeadsUpDisplayLayerImpl";
758 } 800 }
759 801
760 void HeadsUpDisplayLayerImpl::AsValueInto( 802 void HeadsUpDisplayLayerImpl::AsValueInto(
761 base::trace_event::TracedValue* dict) const { 803 base::trace_event::TracedValue* dict) const {
762 LayerImpl::AsValueInto(dict); 804 LayerImpl::AsValueInto(dict);
763 dict->SetString("layer_name", "Heads Up Display Layer"); 805 dict->SetString("layer_name", "Heads Up Display Layer");
764 } 806 }
765 807
766 } // namespace cc 808 } // 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