Chromium Code Reviews| 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) { |
| 239 // Don't show the FPS display when continuous painting is enabled, because | 239 // Don't show the FPS display when continuous painting is enabled, because |
| 240 // it would show misleading numbers. | 240 // it would show misleading numbers. |
| 241 area = | 241 area = |
| 242 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0); | 242 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0); |
| 243 } | 243 } |
| 244 | 244 |
| 245 if (debug_state.ShowMemoryStats()) | 245 if (debug_state.ShowMemoryStats()) |
| 246 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); | 246 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); |
| 247 } | 247 } |
|
danakj
2014/03/07 20:50:20
Can we move the SetNeedsRedraw() call up here, and
malch
2014/03/11 16:14:42
Done.
| |
| 248 | 248 |
| 249 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, | 249 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, |
| 250 SkPaint* paint, | 250 SkPaint* paint, |
| 251 const std::string& text, | 251 const std::string& text, |
| 252 SkPaint::Align align, | 252 SkPaint::Align align, |
| 253 int size, | 253 int size, |
| 254 int x, | 254 int x, |
| 255 int y) const { | 255 int y) const { |
| 256 const bool anti_alias = paint->isAntiAlias(); | 256 const bool anti_alias = paint->isAntiAlias(); |
| 257 paint->setAntiAlias(true); | 257 paint->setAntiAlias(true); |
| (...skipping 321 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 SkColor stroke_color, | |
| 593 SkColor fill_color, | |
| 594 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 |
|
danakj
2014/03/06 19:03:21
Can you create the SkPaint once and reuse it still
malch
2014/03/11 16:14:42
Done.
| |
| 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]); |
|
danakj
2014/03/06 19:03:21
How about doing here:
new_paint_rects.push_back
malch
2014/03/11 16:14:42
Done.
| |
| 604 fill_color = DebugColors::PaintRectFillColor(); | 657 stroke_color = |
| 658 DebugColors::PaintRectBorderColor(DebugColors::kFadeSteps); | |
| 659 fill_color = DebugColors::PaintRectFillColor(DebugColors::kFadeSteps); | |
| 605 stroke_width = DebugColors::PaintRectBorderWidth(); | 660 stroke_width = DebugColors::PaintRectBorderWidth(); |
| 606 break; | 661 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(); |
| (...skipping 38 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 debug_rects[i], |
| 665 1.0 / contents_scale_y()); | 720 stroke_color, |
| 666 SkRect sk_rect = RectFToSkRect(debug_layer_rect); | 721 fill_color, |
| 667 paint.setColor(fill_color); | 722 stroke_width, |
| 668 paint.setStyle(SkPaint::kFill_Style); | 723 label_text); |
| 669 canvas->drawRect(sk_rect, paint); | 724 } |
| 670 | 725 |
| 671 paint.setColor(stroke_color); | 726 if (new_paint_rects.size()) { |
| 672 paint.setStyle(SkPaint::kStroke_Style); | 727 fade_step_ = DebugColors::kFadeSteps; |
| 673 paint.setStrokeWidth(SkFloatToScalar(stroke_width)); | 728 paint_rects_.swap(new_paint_rects); |
| 674 canvas->drawRect(sk_rect, paint); | 729 } else if (fade_step_ > 0) { |
| 675 | 730 fade_step_--; |
| 676 if (label_text.length()) { | 731 for (size_t i = 0; i < paint_rects_.size(); ++i) { |
| 677 const int kFontHeight = 12; | 732 DrawDebugRect(canvas, |
| 678 const int kPadding = 3; | 733 paint_rects_[i], |
| 679 | 734 DebugColors::PaintRectBorderColor(fade_step_), |
| 680 canvas->save(); | 735 DebugColors::PaintRectFillColor(fade_step_), |
| 681 canvas->clipRect(sk_rect); | 736 DebugColors::PaintRectBorderWidth(), |
| 682 canvas->translate(sk_rect.x(), sk_rect.y()); | 737 ""); |
| 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 } | 738 } |
| 705 } | 739 } |
| 740 if (fade_step_ > 0) | |
| 741 layer_tree_impl()->SetNeedsRedraw(); | |
|
caseq
2014/03/07 19:36:12
So it's here :-)
danakj
2014/03/07 19:41:11
Ah okay, I see. We need to fix the HUD redrawing s
| |
| 706 } | 742 } |
| 707 | 743 |
| 708 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { | 744 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { |
| 709 return "cc::HeadsUpDisplayLayerImpl"; | 745 return "cc::HeadsUpDisplayLayerImpl"; |
| 710 } | 746 } |
| 711 | 747 |
| 712 void HeadsUpDisplayLayerImpl::AsValueInto(base::DictionaryValue* dict) const { | 748 void HeadsUpDisplayLayerImpl::AsValueInto(base::DictionaryValue* dict) const { |
| 713 LayerImpl::AsValueInto(dict); | 749 LayerImpl::AsValueInto(dict); |
| 714 dict->SetString("layer_name", "Heads Up Display Layer"); | 750 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 715 } | 751 } |
| 716 | 752 |
| 717 } // namespace cc | 753 } // namespace cc |
| OLD | NEW |