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/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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "cc/debug/debug_colors.h" | 11 #include "cc/debug/debug_colors.h" |
12 #include "cc/debug/debug_rect_history.h" | |
13 #include "cc/debug/frame_rate_counter.h" | 12 #include "cc/debug/frame_rate_counter.h" |
14 #include "cc/debug/paint_time_counter.h" | 13 #include "cc/debug/paint_time_counter.h" |
15 #include "cc/debug/traced_value.h" | 14 #include "cc/debug/traced_value.h" |
16 #include "cc/layers/quad_sink.h" | 15 #include "cc/layers/quad_sink.h" |
17 #include "cc/output/renderer.h" | 16 #include "cc/output/renderer.h" |
18 #include "cc/quads/texture_draw_quad.h" | 17 #include "cc/quads/texture_draw_quad.h" |
19 #include "cc/resources/memory_history.h" | 18 #include "cc/resources/memory_history.h" |
20 #include "cc/trees/layer_tree_impl.h" | 19 #include "cc/trees/layer_tree_impl.h" |
21 #include "skia/ext/platform_canvas.h" | 20 #include "skia/ext/platform_canvas.h" |
22 #include "third_party/khronos/GLES2/gl2.h" | 21 #include "third_party/khronos/GLES2/gl2.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; | 63 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; |
65 return current_upper_bound; | 64 return current_upper_bound; |
66 } | 65 } |
67 | 66 |
68 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, | 67 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, |
69 int id) | 68 int id) |
70 : LayerImpl(tree_impl, id), | 69 : LayerImpl(tree_impl, id), |
71 typeface_(skia::AdoptRef( | 70 typeface_(skia::AdoptRef( |
72 SkTypeface::CreateFromName("monospace", SkTypeface::kBold))), | 71 SkTypeface::CreateFromName("monospace", SkTypeface::kBold))), |
73 fps_graph_(60.0, 80.0), | 72 fps_graph_(60.0, 80.0), |
74 paint_time_graph_(16.0, 48.0) {} | 73 paint_time_graph_(16.0, 48.0), |
| 74 fade_step_(0) {} |
75 | 75 |
76 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} | 76 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} |
77 | 77 |
78 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( | 78 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( |
79 LayerTreeImpl* tree_impl) { | 79 LayerTreeImpl* tree_impl) { |
80 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 80 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
81 } | 81 } |
82 | 82 |
83 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, | 83 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, |
84 ResourceProvider* resource_provider) { | 84 ResourceProvider* resource_provider) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 memory_entry_ = **memory_history->End(); | 218 memory_entry_ = **memory_history->End(); |
219 else | 219 else |
220 memory_entry_ = MemoryHistory::Entry(); | 220 memory_entry_ = MemoryHistory::Entry(); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 fps_graph_.UpdateUpperBound(); | 224 fps_graph_.UpdateUpperBound(); |
225 paint_time_graph_.UpdateUpperBound(); | 225 paint_time_graph_.UpdateUpperBound(); |
226 } | 226 } |
227 | 227 |
228 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) const { | 228 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) { |
229 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); | 229 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); |
230 | 230 |
231 if (debug_state.ShowHudRects()) | 231 if (debug_state.ShowHudRects()) |
232 DrawDebugRects(canvas, layer_tree_impl()->debug_rect_history()); | 232 DrawDebugRects(canvas, layer_tree_impl()->debug_rect_history()); |
233 | 233 |
234 SkRect area = SkRect::MakeEmpty(); | 234 SkRect area = SkRect::MakeEmpty(); |
235 if (debug_state.continuous_painting) { | 235 if (debug_state.continuous_painting) { |
236 area = DrawPaintTimeDisplay( | 236 area = DrawPaintTimeDisplay( |
237 canvas, layer_tree_impl()->paint_time_counter(), 0, 0); | 237 canvas, layer_tree_impl()->paint_time_counter(), 0, 0); |
238 } else if (debug_state.show_fps_counter) { | 238 } else if (debug_state.show_fps_counter) { |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 1, | 579 1, |
580 p * graph_bounds.height()), | 580 p * graph_bounds.height()), |
581 paint); | 581 paint); |
582 } | 582 } |
583 | 583 |
584 DrawGraphLines(canvas, &paint, graph_bounds, paint_time_graph_); | 584 DrawGraphLines(canvas, &paint, graph_bounds, paint_time_graph_); |
585 | 585 |
586 return area; | 586 return area; |
587 } | 587 } |
588 | 588 |
| 589 void HeadsUpDisplayLayerImpl::DrawDebugRect( |
| 590 SkCanvas* canvas, |
| 591 const DebugRect& rect, |
| 592 const SkColor stroke_color, |
| 593 const SkColor fill_color, |
| 594 const float stroke_width, |
| 595 const std::string label_text) const { |
| 596 SkPaint paint = CreatePaint(); |
| 597 |
| 598 gfx::RectF debug_layer_rect = gfx::ScaleRect( |
| 599 rect.rect, 1.0 / contents_scale_x(), 1.0 / contents_scale_y()); |
| 600 SkRect sk_rect = RectFToSkRect(debug_layer_rect); |
| 601 paint.setColor(fill_color); |
| 602 paint.setStyle(SkPaint::kFill_Style); |
| 603 canvas->drawRect(sk_rect, paint); |
| 604 |
| 605 paint.setColor(stroke_color); |
| 606 paint.setStyle(SkPaint::kStroke_Style); |
| 607 paint.setStrokeWidth(SkFloatToScalar(stroke_width)); |
| 608 canvas->drawRect(sk_rect, paint); |
| 609 |
| 610 if (label_text.length()) { |
| 611 const int kFontHeight = 12; |
| 612 const int kPadding = 3; |
| 613 |
| 614 canvas->save(); |
| 615 canvas->clipRect(sk_rect); |
| 616 canvas->translate(sk_rect.x(), sk_rect.y()); |
| 617 |
| 618 SkPaint label_paint = CreatePaint(); |
| 619 label_paint.setTextSize(kFontHeight); |
| 620 label_paint.setTypeface(typeface_.get()); |
| 621 label_paint.setColor(stroke_color); |
| 622 |
| 623 const SkScalar label_text_width = |
| 624 label_paint.measureText(label_text.c_str(), label_text.length()); |
| 625 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, |
| 626 kFontHeight + 2 * kPadding), |
| 627 label_paint); |
| 628 |
| 629 label_paint.setAntiAlias(true); |
| 630 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); |
| 631 canvas->drawText(label_text.c_str(), |
| 632 label_text.length(), |
| 633 kPadding, |
| 634 kFontHeight * 0.8f + kPadding, |
| 635 label_paint); |
| 636 |
| 637 canvas->restore(); |
| 638 } |
| 639 } |
| 640 |
589 void HeadsUpDisplayLayerImpl::DrawDebugRects( | 641 void HeadsUpDisplayLayerImpl::DrawDebugRects( |
590 SkCanvas* canvas, | 642 SkCanvas* canvas, |
591 DebugRectHistory* debug_rect_history) const { | 643 DebugRectHistory* debug_rect_history) { |
592 const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects(); | 644 const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects(); |
593 SkPaint paint = CreatePaint(); | 645 |
| 646 std::vector<DebugRect> new_paint_rects; |
594 | 647 |
595 for (size_t i = 0; i < debug_rects.size(); ++i) { | 648 for (size_t i = 0; i < debug_rects.size(); ++i) { |
596 SkColor stroke_color = 0; | 649 SkColor stroke_color = 0; |
597 SkColor fill_color = 0; | 650 SkColor fill_color = 0; |
598 float stroke_width = 0.f; | 651 float stroke_width = 0.f; |
599 std::string label_text; | 652 std::string label_text; |
600 | 653 |
601 switch (debug_rects[i].type) { | 654 switch (debug_rects[i].type) { |
602 case PAINT_RECT_TYPE: | 655 case PAINT_RECT_TYPE: |
603 stroke_color = DebugColors::PaintRectBorderColor(); | 656 new_paint_rects.push_back(debug_rects[i]); |
604 fill_color = DebugColors::PaintRectFillColor(); | 657 stroke_color = DebugColors::PaintRectBorderColor(0); |
| 658 fill_color = DebugColors::PaintRectFillColor(0); |
605 stroke_width = DebugColors::PaintRectBorderWidth(); | 659 stroke_width = DebugColors::PaintRectBorderWidth(); |
606 break; | 660 break; |
607 case PROPERTY_CHANGED_RECT_TYPE: | 661 case PROPERTY_CHANGED_RECT_TYPE: |
608 stroke_color = DebugColors::PropertyChangedRectBorderColor(); | 662 stroke_color = DebugColors::PropertyChangedRectBorderColor(); |
609 fill_color = DebugColors::PropertyChangedRectFillColor(); | 663 fill_color = DebugColors::PropertyChangedRectFillColor(); |
610 stroke_width = DebugColors::PropertyChangedRectBorderWidth(); | 664 stroke_width = DebugColors::PropertyChangedRectBorderWidth(); |
611 break; | 665 break; |
612 case SURFACE_DAMAGE_RECT_TYPE: | 666 case SURFACE_DAMAGE_RECT_TYPE: |
613 stroke_color = DebugColors::SurfaceDamageRectBorderColor(); | 667 stroke_color = DebugColors::SurfaceDamageRectBorderColor(); |
614 fill_color = DebugColors::SurfaceDamageRectFillColor(); | 668 fill_color = DebugColors::SurfaceDamageRectFillColor(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 label_text = "repaints on scroll"; | 707 label_text = "repaints on scroll"; |
654 break; | 708 break; |
655 case ANIMATION_BOUNDS_RECT_TYPE: | 709 case ANIMATION_BOUNDS_RECT_TYPE: |
656 stroke_color = DebugColors::LayerAnimationBoundsBorderColor(); | 710 stroke_color = DebugColors::LayerAnimationBoundsBorderColor(); |
657 fill_color = DebugColors::LayerAnimationBoundsFillColor(); | 711 fill_color = DebugColors::LayerAnimationBoundsFillColor(); |
658 stroke_width = DebugColors::LayerAnimationBoundsBorderWidth(); | 712 stroke_width = DebugColors::LayerAnimationBoundsBorderWidth(); |
659 label_text = "animation bounds"; | 713 label_text = "animation bounds"; |
660 break; | 714 break; |
661 } | 715 } |
662 | 716 |
663 gfx::RectF debug_layer_rect = gfx::ScaleRect(debug_rects[i].rect, | 717 DrawDebugRect(canvas, |
664 1.0 / contents_scale_x(), | 718 debug_rects[i], |
665 1.0 / contents_scale_y()); | 719 stroke_color, |
666 SkRect sk_rect = RectFToSkRect(debug_layer_rect); | 720 fill_color, |
667 paint.setColor(fill_color); | 721 stroke_width, |
668 paint.setStyle(SkPaint::kFill_Style); | 722 label_text); |
669 canvas->drawRect(sk_rect, paint); | 723 } |
670 | 724 |
671 paint.setColor(stroke_color); | 725 if (new_paint_rects.size()) { |
672 paint.setStyle(SkPaint::kStroke_Style); | 726 fade_step_ = DebugColors::kFadeSteps; |
673 paint.setStrokeWidth(SkFloatToScalar(stroke_width)); | 727 paint_rects_.swap(new_paint_rects); |
674 canvas->drawRect(sk_rect, paint); | 728 } else if (fade_step_ > 0) { |
675 | 729 fade_step_--; |
676 if (label_text.length()) { | 730 for (size_t i = 0; i < paint_rects_.size(); ++i) { |
677 const int kFontHeight = 12; | 731 DrawDebugRect(canvas, |
678 const int kPadding = 3; | 732 paint_rects_[i], |
679 | 733 DebugColors::PaintRectBorderColor(fade_step_), |
680 canvas->save(); | 734 DebugColors::PaintRectFillColor(fade_step_), |
681 canvas->clipRect(sk_rect); | 735 DebugColors::PaintRectBorderWidth(), |
682 canvas->translate(sk_rect.x(), sk_rect.y()); | 736 ""); |
683 | |
684 SkPaint label_paint = CreatePaint(); | |
685 label_paint.setTextSize(kFontHeight); | |
686 label_paint.setTypeface(typeface_.get()); | |
687 label_paint.setColor(stroke_color); | |
688 | |
689 const SkScalar label_text_width = | |
690 label_paint.measureText(label_text.c_str(), label_text.length()); | |
691 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, | |
692 kFontHeight + 2 * kPadding), | |
693 label_paint); | |
694 | |
695 label_paint.setAntiAlias(true); | |
696 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); | |
697 canvas->drawText(label_text.c_str(), | |
698 label_text.length(), | |
699 kPadding, | |
700 kFontHeight * 0.8f + kPadding, | |
701 label_paint); | |
702 | |
703 canvas->restore(); | |
704 } | 737 } |
705 } | 738 } |
| 739 if (fade_step_ > 0) |
| 740 layer_tree_impl()->SetNeedsRedraw(); |
706 } | 741 } |
707 | 742 |
708 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { | 743 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { |
709 return "cc::HeadsUpDisplayLayerImpl"; | 744 return "cc::HeadsUpDisplayLayerImpl"; |
710 } | 745 } |
711 | 746 |
712 void HeadsUpDisplayLayerImpl::AsValueInto(base::DictionaryValue* dict) const { | 747 void HeadsUpDisplayLayerImpl::AsValueInto(base::DictionaryValue* dict) const { |
713 LayerImpl::AsValueInto(dict); | 748 LayerImpl::AsValueInto(dict); |
714 dict->SetString("layer_name", "Heads Up Display Layer"); | 749 dict->SetString("layer_name", "Heads Up Display Layer"); |
715 } | 750 } |
716 | 751 |
717 } // namespace cc | 752 } // namespace cc |
OLD | NEW |