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" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 290 } |
291 | 291 |
292 if (debug_state.show_fps_counter || debug_state.continuous_painting) { | 292 if (debug_state.show_fps_counter || debug_state.continuous_painting) { |
293 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(), | 293 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(), |
294 SkMaxScalar(area.width(), 150)); | 294 SkMaxScalar(area.width(), 150)); |
295 } | 295 } |
296 | 296 |
297 if (debug_state.ShowMemoryStats()) | 297 if (debug_state.ShowMemoryStats()) |
298 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); | 298 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); |
299 } | 299 } |
300 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, | |
301 const std::string& text, | |
302 int size) const { | |
303 const bool anti_alias = paint->isAntiAlias(); | |
304 paint->setAntiAlias(true); | |
305 paint->setTextSize(size); | |
306 paint->setTypeface(typeface_.get()); | |
307 SkScalar text_width = paint->measureText(text.c_str(), text.length()); | |
308 | 300 |
309 paint->setAntiAlias(anti_alias); | |
310 return SkScalarCeilToInt(text_width); | |
311 } | |
312 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, | 301 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, |
313 SkPaint* paint, | 302 SkPaint* paint, |
314 const std::string& text, | 303 const std::string& text, |
315 SkPaint::Align align, | 304 SkPaint::Align align, |
316 int size, | 305 int size, |
317 int x, | 306 int x, |
318 int y) const { | 307 int y) const { |
319 const bool anti_alias = paint->isAntiAlias(); | 308 const bool anti_alias = paint->isAntiAlias(); |
320 paint->setAntiAlias(true); | 309 paint->setAntiAlias(true); |
321 | 310 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 SkCanvas* canvas, | 605 SkCanvas* canvas, |
617 const PaintTimeCounter* paint_time_counter, | 606 const PaintTimeCounter* paint_time_counter, |
618 int right, | 607 int right, |
619 int top) const { | 608 int top) const { |
620 const int kPadding = 4; | 609 const int kPadding = 4; |
621 const int kFontHeight = 14; | 610 const int kFontHeight = 14; |
622 | 611 |
623 const int kGraphWidth = paint_time_counter->HistorySize(); | 612 const int kGraphWidth = paint_time_counter->HistorySize(); |
624 const int kGraphHeight = 40; | 613 const int kGraphHeight = 40; |
625 | 614 |
626 SkPaint paint = CreatePaint(); | 615 const int width = kGraphWidth + 2 * kPadding; |
627 | |
628 const std::string title = "Compositor frame time (ms)"; | |
629 int title_text_width = MeasureText(&paint, title, kFontHeight); | |
630 int contents_width = std::max(title_text_width, kGraphWidth); | |
631 | |
632 const int width = contents_width + 2 * kPadding; | |
633 const int height = | 616 const int height = |
634 kFontHeight + kGraphHeight + 4 * kPadding + 2 + kFontHeight + kPadding; | 617 kFontHeight + kGraphHeight + 4 * kPadding + 2 + kFontHeight + kPadding; |
635 const int left = bounds().width() - width - right; | 618 const int left = bounds().width() - width - right; |
636 | 619 |
637 const SkRect area = SkRect::MakeXYWH(left, top, width, height); | 620 const SkRect area = SkRect::MakeXYWH(left, top, width, height); |
638 | 621 |
| 622 SkPaint paint = CreatePaint(); |
639 DrawGraphBackground(canvas, &paint, area); | 623 DrawGraphBackground(canvas, &paint, area); |
640 | 624 |
641 SkRect text_bounds = SkRect::MakeXYWH(left + kPadding, top + kPadding, | 625 SkRect text_bounds = SkRect::MakeXYWH( |
642 contents_width, kFontHeight); | 626 left + kPadding, top + kPadding, kGraphWidth, kFontHeight); |
643 SkRect text_bounds2 = | 627 SkRect text_bounds2 = SkRect::MakeXYWH(left + kPadding, |
644 SkRect::MakeXYWH(left + kPadding, text_bounds.bottom() + kPadding, | 628 text_bounds.bottom() + kPadding, |
645 contents_width, kFontHeight); | 629 kGraphWidth, |
646 SkRect graph_bounds = SkRect::MakeXYWH(left + (width - kGraphWidth) / 2, | 630 kFontHeight); |
| 631 SkRect graph_bounds = SkRect::MakeXYWH(left + kPadding, |
647 text_bounds2.bottom() + 2 * kPadding, | 632 text_bounds2.bottom() + 2 * kPadding, |
648 kGraphWidth, kGraphHeight); | 633 kGraphWidth, |
| 634 kGraphHeight); |
649 | 635 |
650 const std::string value_text = | 636 const std::string value_text = |
651 base::StringPrintf("%.1f", paint_time_graph_.value); | 637 base::StringPrintf("%.1f", paint_time_graph_.value); |
652 const std::string min_max_text = base::StringPrintf( | 638 const std::string min_max_text = base::StringPrintf( |
653 "%.1f-%.1f", paint_time_graph_.min, paint_time_graph_.max); | 639 "%.1f-%.1f", paint_time_graph_.min, paint_time_graph_.max); |
654 | 640 |
655 paint.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor()); | 641 paint.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor()); |
656 DrawText(canvas, &paint, title, SkPaint::kLeft_Align, kFontHeight, | 642 DrawText(canvas, &paint, "Compositor frame time(ms)", SkPaint::kLeft_Align, |
657 text_bounds.left(), text_bounds.bottom()); | 643 kFontHeight, text_bounds.left(), text_bounds.bottom()); |
658 DrawText(canvas, | 644 DrawText(canvas, |
659 &paint, | 645 &paint, |
660 value_text, | 646 value_text, |
661 SkPaint::kLeft_Align, | 647 SkPaint::kLeft_Align, |
662 kFontHeight, | 648 kFontHeight, |
663 text_bounds2.left(), | 649 text_bounds2.left(), |
664 text_bounds2.bottom()); | 650 text_bounds2.bottom()); |
665 DrawText(canvas, | 651 DrawText(canvas, |
666 &paint, | 652 &paint, |
667 min_max_text, | 653 min_max_text, |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 return "cc::HeadsUpDisplayLayerImpl"; | 842 return "cc::HeadsUpDisplayLayerImpl"; |
857 } | 843 } |
858 | 844 |
859 void HeadsUpDisplayLayerImpl::AsValueInto( | 845 void HeadsUpDisplayLayerImpl::AsValueInto( |
860 base::trace_event::TracedValue* dict) const { | 846 base::trace_event::TracedValue* dict) const { |
861 LayerImpl::AsValueInto(dict); | 847 LayerImpl::AsValueInto(dict); |
862 dict->SetString("layer_name", "Heads Up Display Layer"); | 848 dict->SetString("layer_name", "Heads Up Display Layer"); |
863 } | 849 } |
864 | 850 |
865 } // namespace cc | 851 } // namespace cc |
OLD | NEW |