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 if (IsAnimatingHUDContents()) { |
| 234 layer_tree_impl()->SetNeedsRedraw(); |
| 235 } |
| 236 } |
233 | 237 |
234 SkRect area = SkRect::MakeEmpty(); | 238 SkRect area = SkRect::MakeEmpty(); |
235 if (debug_state.continuous_painting) { | 239 if (debug_state.continuous_painting) { |
236 area = DrawPaintTimeDisplay( | 240 area = DrawPaintTimeDisplay( |
237 canvas, layer_tree_impl()->paint_time_counter(), 0, 0); | 241 canvas, layer_tree_impl()->paint_time_counter(), 0, 0); |
238 } else if (debug_state.show_fps_counter) { | 242 } else if (debug_state.show_fps_counter) { |
239 // Don't show the FPS display when continuous painting is enabled, because | 243 // Don't show the FPS display when continuous painting is enabled, because |
240 // it would show misleading numbers. | 244 // it would show misleading numbers. |
241 area = | 245 area = |
242 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0); | 246 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 1, | 583 1, |
580 p * graph_bounds.height()), | 584 p * graph_bounds.height()), |
581 paint); | 585 paint); |
582 } | 586 } |
583 | 587 |
584 DrawGraphLines(canvas, &paint, graph_bounds, paint_time_graph_); | 588 DrawGraphLines(canvas, &paint, graph_bounds, paint_time_graph_); |
585 | 589 |
586 return area; | 590 return area; |
587 } | 591 } |
588 | 592 |
| 593 void HeadsUpDisplayLayerImpl::DrawDebugRect( |
| 594 SkCanvas* canvas, |
| 595 SkPaint& paint, |
| 596 const DebugRect& rect, |
| 597 SkColor stroke_color, |
| 598 SkColor fill_color, |
| 599 float stroke_width, |
| 600 const std::string& label_text) const { |
| 601 gfx::RectF debug_layer_rect = gfx::ScaleRect( |
| 602 rect.rect, 1.0 / contents_scale_x(), 1.0 / contents_scale_y()); |
| 603 SkRect sk_rect = RectFToSkRect(debug_layer_rect); |
| 604 paint.setColor(fill_color); |
| 605 paint.setStyle(SkPaint::kFill_Style); |
| 606 canvas->drawRect(sk_rect, paint); |
| 607 |
| 608 paint.setColor(stroke_color); |
| 609 paint.setStyle(SkPaint::kStroke_Style); |
| 610 paint.setStrokeWidth(SkFloatToScalar(stroke_width)); |
| 611 canvas->drawRect(sk_rect, paint); |
| 612 |
| 613 if (label_text.length()) { |
| 614 const int kFontHeight = 12; |
| 615 const int kPadding = 3; |
| 616 |
| 617 canvas->save(); |
| 618 canvas->clipRect(sk_rect); |
| 619 canvas->translate(sk_rect.x(), sk_rect.y()); |
| 620 |
| 621 SkPaint label_paint = CreatePaint(); |
| 622 label_paint.setTextSize(kFontHeight); |
| 623 label_paint.setTypeface(typeface_.get()); |
| 624 label_paint.setColor(stroke_color); |
| 625 |
| 626 const SkScalar label_text_width = |
| 627 label_paint.measureText(label_text.c_str(), label_text.length()); |
| 628 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, |
| 629 kFontHeight + 2 * kPadding), |
| 630 label_paint); |
| 631 |
| 632 label_paint.setAntiAlias(true); |
| 633 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); |
| 634 canvas->drawText(label_text.c_str(), |
| 635 label_text.length(), |
| 636 kPadding, |
| 637 kFontHeight * 0.8f + kPadding, |
| 638 label_paint); |
| 639 |
| 640 canvas->restore(); |
| 641 } |
| 642 } |
| 643 |
589 void HeadsUpDisplayLayerImpl::DrawDebugRects( | 644 void HeadsUpDisplayLayerImpl::DrawDebugRects( |
590 SkCanvas* canvas, | 645 SkCanvas* canvas, |
591 DebugRectHistory* debug_rect_history) const { | 646 DebugRectHistory* debug_rect_history) { |
| 647 SkPaint paint = CreatePaint(); |
| 648 |
592 const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects(); | 649 const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects(); |
593 SkPaint paint = CreatePaint(); | 650 std::vector<DebugRect> new_paint_rects; |
594 | 651 |
595 for (size_t i = 0; i < debug_rects.size(); ++i) { | 652 for (size_t i = 0; i < debug_rects.size(); ++i) { |
596 SkColor stroke_color = 0; | 653 SkColor stroke_color = 0; |
597 SkColor fill_color = 0; | 654 SkColor fill_color = 0; |
598 float stroke_width = 0.f; | 655 float stroke_width = 0.f; |
599 std::string label_text; | 656 std::string label_text; |
600 | 657 |
601 switch (debug_rects[i].type) { | 658 switch (debug_rects[i].type) { |
602 case PAINT_RECT_TYPE: | 659 case PAINT_RECT_TYPE: |
603 stroke_color = DebugColors::PaintRectBorderColor(); | 660 new_paint_rects.push_back(debug_rects[i]); |
604 fill_color = DebugColors::PaintRectFillColor(); | 661 continue; |
605 stroke_width = DebugColors::PaintRectBorderWidth(); | |
606 break; | |
607 case PROPERTY_CHANGED_RECT_TYPE: | 662 case PROPERTY_CHANGED_RECT_TYPE: |
608 stroke_color = DebugColors::PropertyChangedRectBorderColor(); | 663 stroke_color = DebugColors::PropertyChangedRectBorderColor(); |
609 fill_color = DebugColors::PropertyChangedRectFillColor(); | 664 fill_color = DebugColors::PropertyChangedRectFillColor(); |
610 stroke_width = DebugColors::PropertyChangedRectBorderWidth(); | 665 stroke_width = DebugColors::PropertyChangedRectBorderWidth(); |
611 break; | 666 break; |
612 case SURFACE_DAMAGE_RECT_TYPE: | 667 case SURFACE_DAMAGE_RECT_TYPE: |
613 stroke_color = DebugColors::SurfaceDamageRectBorderColor(); | 668 stroke_color = DebugColors::SurfaceDamageRectBorderColor(); |
614 fill_color = DebugColors::SurfaceDamageRectFillColor(); | 669 fill_color = DebugColors::SurfaceDamageRectFillColor(); |
615 stroke_width = DebugColors::SurfaceDamageRectBorderWidth(); | 670 stroke_width = DebugColors::SurfaceDamageRectBorderWidth(); |
616 break; | 671 break; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 label_text = "repaints on scroll"; | 708 label_text = "repaints on scroll"; |
654 break; | 709 break; |
655 case ANIMATION_BOUNDS_RECT_TYPE: | 710 case ANIMATION_BOUNDS_RECT_TYPE: |
656 stroke_color = DebugColors::LayerAnimationBoundsBorderColor(); | 711 stroke_color = DebugColors::LayerAnimationBoundsBorderColor(); |
657 fill_color = DebugColors::LayerAnimationBoundsFillColor(); | 712 fill_color = DebugColors::LayerAnimationBoundsFillColor(); |
658 stroke_width = DebugColors::LayerAnimationBoundsBorderWidth(); | 713 stroke_width = DebugColors::LayerAnimationBoundsBorderWidth(); |
659 label_text = "animation bounds"; | 714 label_text = "animation bounds"; |
660 break; | 715 break; |
661 } | 716 } |
662 | 717 |
663 gfx::RectF debug_layer_rect = gfx::ScaleRect(debug_rects[i].rect, | 718 DrawDebugRect(canvas, |
664 1.0 / contents_scale_x(), | 719 paint, |
665 1.0 / contents_scale_y()); | 720 debug_rects[i], |
666 SkRect sk_rect = RectFToSkRect(debug_layer_rect); | 721 stroke_color, |
667 paint.setColor(fill_color); | 722 fill_color, |
668 paint.setStyle(SkPaint::kFill_Style); | 723 stroke_width, |
669 canvas->drawRect(sk_rect, paint); | 724 label_text); |
| 725 } |
670 | 726 |
671 paint.setColor(stroke_color); | 727 if (new_paint_rects.size()) { |
672 paint.setStyle(SkPaint::kStroke_Style); | 728 paint_rects_.swap(new_paint_rects); |
673 paint.setStrokeWidth(SkFloatToScalar(stroke_width)); | 729 fade_step_ = DebugColors::kFadeSteps; |
674 canvas->drawRect(sk_rect, paint); | 730 } |
675 | 731 if (fade_step_ > 0) { |
676 if (label_text.length()) { | 732 fade_step_--; |
677 const int kFontHeight = 12; | 733 for (size_t i = 0; i < paint_rects_.size(); ++i) { |
678 const int kPadding = 3; | 734 DrawDebugRect(canvas, |
679 | 735 paint, |
680 canvas->save(); | 736 paint_rects_[i], |
681 canvas->clipRect(sk_rect); | 737 DebugColors::PaintRectBorderColor(fade_step_), |
682 canvas->translate(sk_rect.x(), sk_rect.y()); | 738 DebugColors::PaintRectFillColor(fade_step_), |
683 | 739 DebugColors::PaintRectBorderWidth(), |
684 SkPaint label_paint = CreatePaint(); | 740 ""); |
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 } | 741 } |
705 } | 742 } |
706 } | 743 } |
707 | 744 |
708 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { | 745 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { |
709 return "cc::HeadsUpDisplayLayerImpl"; | 746 return "cc::HeadsUpDisplayLayerImpl"; |
710 } | 747 } |
711 | 748 |
712 void HeadsUpDisplayLayerImpl::AsValueInto(base::DictionaryValue* dict) const { | 749 void HeadsUpDisplayLayerImpl::AsValueInto(base::DictionaryValue* dict) const { |
713 LayerImpl::AsValueInto(dict); | 750 LayerImpl::AsValueInto(dict); |
714 dict->SetString("layer_name", "Heads Up Display Layer"); | 751 dict->SetString("layer_name", "Heads Up Display Layer"); |
715 } | 752 } |
716 | 753 |
717 } // namespace cc | 754 } // namespace cc |
OLD | NEW |