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 needs_update_(false) {} | |
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 | |
641 int fade_step = 0; | |
642 std::vector<DebugRect> paint_rects; | |
caseq
2014/03/05 13:20:59
WAT?
malch
2014/03/05 14:43:26
Done.
| |
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) { |
592 const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects(); | 647 const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects(); |
593 SkPaint paint = CreatePaint(); | 648 |
649 layer_tree_impl()->SetNeedsRedraw(); | |
caseq
2014/03/05 13:20:59
Why do we do this unconditionally?
malch
2014/03/05 14:43:26
Done.
| |
650 bool has_new_paint_rects = false; | |
caseq
2014/03/05 13:20:59
Why do you need this?
malch
2014/03/05 14:43:26
Done.
| |
651 std::vector<DebugRect> new_paint_rects; | |
594 | 652 |
595 for (size_t i = 0; i < debug_rects.size(); ++i) { | 653 for (size_t i = 0; i < debug_rects.size(); ++i) { |
596 SkColor stroke_color = 0; | 654 SkColor stroke_color = 0; |
597 SkColor fill_color = 0; | 655 SkColor fill_color = 0; |
598 float stroke_width = 0.f; | 656 float stroke_width = 0.f; |
599 std::string label_text; | 657 std::string label_text; |
600 | 658 |
601 switch (debug_rects[i].type) { | 659 switch (debug_rects[i].type) { |
602 case PAINT_RECT_TYPE: | 660 case PAINT_RECT_TYPE: |
603 stroke_color = DebugColors::PaintRectBorderColor(); | 661 has_new_paint_rects = true; |
604 fill_color = DebugColors::PaintRectFillColor(); | 662 new_paint_rects.push_back(debug_rects[i]); |
663 stroke_color = DebugColors::PaintRectBorderColor(0); | |
664 fill_color = DebugColors::PaintRectFillColor(0); | |
605 stroke_width = DebugColors::PaintRectBorderWidth(); | 665 stroke_width = DebugColors::PaintRectBorderWidth(); |
606 break; | 666 break; |
607 case PROPERTY_CHANGED_RECT_TYPE: | 667 case PROPERTY_CHANGED_RECT_TYPE: |
608 stroke_color = DebugColors::PropertyChangedRectBorderColor(); | 668 stroke_color = DebugColors::PropertyChangedRectBorderColor(); |
609 fill_color = DebugColors::PropertyChangedRectFillColor(); | 669 fill_color = DebugColors::PropertyChangedRectFillColor(); |
610 stroke_width = DebugColors::PropertyChangedRectBorderWidth(); | 670 stroke_width = DebugColors::PropertyChangedRectBorderWidth(); |
611 break; | 671 break; |
612 case SURFACE_DAMAGE_RECT_TYPE: | 672 case SURFACE_DAMAGE_RECT_TYPE: |
613 stroke_color = DebugColors::SurfaceDamageRectBorderColor(); | 673 stroke_color = DebugColors::SurfaceDamageRectBorderColor(); |
614 fill_color = DebugColors::SurfaceDamageRectFillColor(); | 674 fill_color = DebugColors::SurfaceDamageRectFillColor(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 label_text = "repaints on scroll"; | 713 label_text = "repaints on scroll"; |
654 break; | 714 break; |
655 case ANIMATION_BOUNDS_RECT_TYPE: | 715 case ANIMATION_BOUNDS_RECT_TYPE: |
656 stroke_color = DebugColors::LayerAnimationBoundsBorderColor(); | 716 stroke_color = DebugColors::LayerAnimationBoundsBorderColor(); |
657 fill_color = DebugColors::LayerAnimationBoundsFillColor(); | 717 fill_color = DebugColors::LayerAnimationBoundsFillColor(); |
658 stroke_width = DebugColors::LayerAnimationBoundsBorderWidth(); | 718 stroke_width = DebugColors::LayerAnimationBoundsBorderWidth(); |
659 label_text = "animation bounds"; | 719 label_text = "animation bounds"; |
660 break; | 720 break; |
661 } | 721 } |
662 | 722 |
663 gfx::RectF debug_layer_rect = gfx::ScaleRect(debug_rects[i].rect, | 723 DrawDebugRect(canvas, |
664 1.0 / contents_scale_x(), | 724 debug_rects[i], |
665 1.0 / contents_scale_y()); | 725 stroke_color, |
666 SkRect sk_rect = RectFToSkRect(debug_layer_rect); | 726 fill_color, |
667 paint.setColor(fill_color); | 727 stroke_width, |
668 paint.setStyle(SkPaint::kFill_Style); | 728 label_text); |
669 canvas->drawRect(sk_rect, paint); | 729 } |
670 | 730 |
671 paint.setColor(stroke_color); | 731 if (has_new_paint_rects) { |
672 paint.setStyle(SkPaint::kStroke_Style); | 732 fade_step = 0; |
673 paint.setStrokeWidth(SkFloatToScalar(stroke_width)); | 733 paint_rects = new_paint_rects; |
674 canvas->drawRect(sk_rect, paint); | 734 needs_update_ = true; |
675 | 735 } else if (needs_update_) { |
676 if (label_text.length()) { | 736 fade_step++; |
677 const int kFontHeight = 12; | 737 if (fade_step >= DebugColors::kFadeSteps) |
678 const int kPadding = 3; | 738 needs_update_ = false; |
679 | 739 for (size_t i = 0; i < paint_rects.size(); ++i) { |
680 canvas->save(); | 740 DrawDebugRect(canvas, |
681 canvas->clipRect(sk_rect); | 741 paint_rects[i], |
682 canvas->translate(sk_rect.x(), sk_rect.y()); | 742 DebugColors::PaintRectBorderColor(fade_step), |
683 | 743 DebugColors::PaintRectFillColor(fade_step), |
684 SkPaint label_paint = CreatePaint(); | 744 DebugColors::PaintRectBorderWidth(), |
685 label_paint.setTextSize(kFontHeight); | 745 ""); |
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 } | 746 } |
705 } | 747 } |
706 } | 748 } |
707 | 749 |
708 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { | 750 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { |
709 return "cc::HeadsUpDisplayLayerImpl"; | 751 return "cc::HeadsUpDisplayLayerImpl"; |
710 } | 752 } |
711 | 753 |
712 void HeadsUpDisplayLayerImpl::AsValueInto(base::DictionaryValue* dict) const { | 754 void HeadsUpDisplayLayerImpl::AsValueInto(base::DictionaryValue* dict) const { |
713 LayerImpl::AsValueInto(dict); | 755 LayerImpl::AsValueInto(dict); |
714 dict->SetString("layer_name", "Heads Up Display Layer"); | 756 dict->SetString("layer_name", "Heads Up Display Layer"); |
715 } | 757 } |
716 | 758 |
717 } // namespace cc | 759 } // namespace cc |
OLD | NEW |