Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: cc/layers/heads_up_display_layer_impl.cc

Issue 1296673004: Devtools/CC: Remove continuous repainting feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/heads_up_display_layer_impl.h ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "base/trace_event/trace_event_argument.h" 13 #include "base/trace_event/trace_event_argument.h"
14 #include "cc/debug/debug_colors.h" 14 #include "cc/debug/debug_colors.h"
15 #include "cc/debug/frame_rate_counter.h" 15 #include "cc/debug/frame_rate_counter.h"
16 #include "cc/debug/paint_time_counter.h"
17 #include "cc/output/begin_frame_args.h" 16 #include "cc/output/begin_frame_args.h"
18 #include "cc/output/renderer.h" 17 #include "cc/output/renderer.h"
19 #include "cc/quads/texture_draw_quad.h" 18 #include "cc/quads/texture_draw_quad.h"
20 #include "cc/resources/memory_history.h" 19 #include "cc/resources/memory_history.h"
21 #include "cc/trees/layer_tree_host_impl.h" 20 #include "cc/trees/layer_tree_host_impl.h"
22 #include "cc/trees/layer_tree_impl.h" 21 #include "cc/trees/layer_tree_impl.h"
23 #include "skia/ext/platform_canvas.h" 22 #include "skia/ext/platform_canvas.h"
24 #include "third_party/skia/include/core/SkPaint.h" 23 #include "third_party/skia/include/core/SkPaint.h"
25 #include "third_party/skia/include/core/SkPath.h" 24 #include "third_party/skia/include/core/SkPath.h"
26 #include "third_party/skia/include/core/SkTypeface.h" 25 #include "third_party/skia/include/core/SkTypeface.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 base::TimeTicks now = layer_tree_impl()->CurrentBeginFrameArgs().frame_time; 237 base::TimeTicks now = layer_tree_impl()->CurrentBeginFrameArgs().frame_time;
239 if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) { 238 if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) {
240 time_of_last_graph_update_ = now; 239 time_of_last_graph_update_ = now;
241 240
242 if (debug_state.show_fps_counter) { 241 if (debug_state.show_fps_counter) {
243 FrameRateCounter* fps_counter = layer_tree_impl()->frame_rate_counter(); 242 FrameRateCounter* fps_counter = layer_tree_impl()->frame_rate_counter();
244 fps_graph_.value = fps_counter->GetAverageFPS(); 243 fps_graph_.value = fps_counter->GetAverageFPS();
245 fps_counter->GetMinAndMaxFPS(&fps_graph_.min, &fps_graph_.max); 244 fps_counter->GetMinAndMaxFPS(&fps_graph_.min, &fps_graph_.max);
246 } 245 }
247 246
248 if (debug_state.continuous_painting) {
249 PaintTimeCounter* paint_time_counter =
250 layer_tree_impl()->paint_time_counter();
251 base::TimeDelta latest, min, max;
252
253 if (paint_time_counter->End())
254 latest = **paint_time_counter->End();
255 paint_time_counter->GetMinAndMaxPaintTime(&min, &max);
256
257 paint_time_graph_.value = latest.InMillisecondsF();
258 paint_time_graph_.min = min.InMillisecondsF();
259 paint_time_graph_.max = max.InMillisecondsF();
260 }
261
262 if (debug_state.ShowMemoryStats()) { 247 if (debug_state.ShowMemoryStats()) {
263 MemoryHistory* memory_history = layer_tree_impl()->memory_history(); 248 MemoryHistory* memory_history = layer_tree_impl()->memory_history();
264 if (memory_history->End()) 249 if (memory_history->End())
265 memory_entry_ = **memory_history->End(); 250 memory_entry_ = **memory_history->End();
266 else 251 else
267 memory_entry_ = MemoryHistory::Entry(); 252 memory_entry_ = MemoryHistory::Entry();
268 } 253 }
269 } 254 }
270 255
271 fps_graph_.UpdateUpperBound(); 256 fps_graph_.UpdateUpperBound();
272 paint_time_graph_.UpdateUpperBound(); 257 paint_time_graph_.UpdateUpperBound();
273 } 258 }
274 259
275 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) { 260 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) {
276 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); 261 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state();
277 262
278 if (debug_state.ShowHudRects()) { 263 if (debug_state.ShowHudRects()) {
279 DrawDebugRects(canvas, layer_tree_impl()->debug_rect_history()); 264 DrawDebugRects(canvas, layer_tree_impl()->debug_rect_history());
280 if (IsAnimatingHUDContents()) { 265 if (IsAnimatingHUDContents()) {
281 layer_tree_impl()->SetNeedsRedraw(); 266 layer_tree_impl()->SetNeedsRedraw();
282 } 267 }
283 } 268 }
284 269
285 SkRect area = SkRect::MakeEmpty(); 270 if (!debug_state.show_fps_counter)
286 if (debug_state.continuous_painting) { 271 return;
287 area = DrawPaintTimeDisplay(
288 canvas, layer_tree_impl()->paint_time_counter(), 0, 0);
289 } else if (debug_state.show_fps_counter) {
290 // Don't show the FPS display when continuous painting is enabled, because
291 // it would show misleading numbers.
292 area =
293 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0);
294 }
295 272
296 if (debug_state.show_fps_counter || debug_state.continuous_painting) { 273 SkRect area =
297 area = DrawGpuRasterizationStatus(canvas, 0, area.bottom(), 274 DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0);
298 SkMaxScalar(area.width(), 150)); 275 DrawGpuRasterizationStatus(canvas, 0, area.bottom(),
299 } 276 SkMaxScalar(area.width(), 150));
300 277
301 if (debug_state.ShowMemoryStats()) 278 if (debug_state.ShowMemoryStats())
302 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); 279 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150));
303 } 280 }
304 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, 281 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint,
305 const std::string& text, 282 const std::string& text,
306 int size) const { 283 int size) const {
307 const bool anti_alias = paint->isAntiAlias(); 284 const bool anti_alias = paint->isAntiAlias();
308 paint->setAntiAlias(true); 285 paint->setAntiAlias(true);
309 paint->setTextSize(size); 286 paint->setTextSize(size);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 591
615 paint.setColor(color); 592 paint.setColor(color);
616 DrawText(canvas, &paint, "GPU raster: ", SkPaint::kLeft_Align, kFontHeight, 593 DrawText(canvas, &paint, "GPU raster: ", SkPaint::kLeft_Align, kFontHeight,
617 left + kPadding, top + kFontHeight + kPadding); 594 left + kPadding, top + kFontHeight + kPadding);
618 DrawText(canvas, &paint, status, SkPaint::kRight_Align, kFontHeight, 595 DrawText(canvas, &paint, status, SkPaint::kRight_Align, kFontHeight,
619 gpu_status_pos); 596 gpu_status_pos);
620 597
621 return area; 598 return area;
622 } 599 }
623 600
624 SkRect HeadsUpDisplayLayerImpl::DrawPaintTimeDisplay(
625 SkCanvas* canvas,
626 const PaintTimeCounter* paint_time_counter,
627 int right,
628 int top) const {
629 const int kPadding = 4;
630 const int kFontHeight = 14;
631
632 const int kGraphWidth =
633 base::saturated_cast<int>(paint_time_counter->HistorySize());
634 const int kGraphHeight = 40;
635
636 SkPaint paint = CreatePaint();
637
638 const std::string title = "Compositor frame time (ms)";
639 int title_text_width = MeasureText(&paint, title, kFontHeight);
640 int contents_width = std::max(title_text_width, kGraphWidth);
641
642 const int width = contents_width + 2 * kPadding;
643 const int height =
644 kFontHeight + kGraphHeight + 4 * kPadding + 2 + kFontHeight + kPadding;
645 const int left = bounds().width() - width - right;
646
647 const SkRect area = SkRect::MakeXYWH(left, top, width, height);
648
649 DrawGraphBackground(canvas, &paint, area);
650
651 SkRect text_bounds = SkRect::MakeXYWH(left + kPadding, top + kPadding,
652 contents_width, kFontHeight);
653 SkRect text_bounds2 =
654 SkRect::MakeXYWH(left + kPadding, text_bounds.bottom() + kPadding,
655 contents_width, kFontHeight);
656 SkRect graph_bounds = SkRect::MakeXYWH(left + (width - kGraphWidth) / 2,
657 text_bounds2.bottom() + 2 * kPadding,
658 kGraphWidth, kGraphHeight);
659
660 const std::string value_text =
661 base::StringPrintf("%.1f", paint_time_graph_.value);
662 const std::string min_max_text = base::StringPrintf(
663 "%.1f-%.1f", paint_time_graph_.min, paint_time_graph_.max);
664
665 paint.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
666 DrawText(canvas, &paint, title, SkPaint::kLeft_Align, kFontHeight,
667 text_bounds.left(), text_bounds.bottom());
668 DrawText(canvas,
669 &paint,
670 value_text,
671 SkPaint::kLeft_Align,
672 kFontHeight,
673 text_bounds2.left(),
674 text_bounds2.bottom());
675 DrawText(canvas,
676 &paint,
677 min_max_text,
678 SkPaint::kRight_Align,
679 kFontHeight,
680 text_bounds2.right(),
681 text_bounds2.bottom());
682
683 paint.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
684 for (PaintTimeCounter::RingBufferType::Iterator it =
685 paint_time_counter->End();
686 it;
687 --it) {
688 double pt = it->InMillisecondsF();
689
690 if (pt == 0.0)
691 continue;
692
693 double p = pt / paint_time_graph_.current_upper_bound;
694 if (p > 1.0)
695 p = 1.0;
696
697 canvas->drawRect(
698 SkRect::MakeXYWH(graph_bounds.left() + it.index(),
699 graph_bounds.bottom() - p * graph_bounds.height(),
700 1,
701 p * graph_bounds.height()),
702 paint);
703 }
704
705 DrawGraphLines(canvas, &paint, graph_bounds, paint_time_graph_);
706
707 return area;
708 }
709
710 void HeadsUpDisplayLayerImpl::DrawDebugRect( 601 void HeadsUpDisplayLayerImpl::DrawDebugRect(
711 SkCanvas* canvas, 602 SkCanvas* canvas,
712 SkPaint* paint, 603 SkPaint* paint,
713 const DebugRect& rect, 604 const DebugRect& rect,
714 SkColor stroke_color, 605 SkColor stroke_color,
715 SkColor fill_color, 606 SkColor fill_color,
716 float stroke_width, 607 float stroke_width,
717 const std::string& label_text) const { 608 const std::string& label_text) const {
718 gfx::Rect debug_layer_rect = 609 gfx::Rect debug_layer_rect =
719 gfx::ScaleToEnclosingRect(rect.rect, 1.0 / internal_contents_scale_, 610 gfx::ScaleToEnclosingRect(rect.rect, 1.0 / internal_contents_scale_,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 return "cc::HeadsUpDisplayLayerImpl"; 757 return "cc::HeadsUpDisplayLayerImpl";
867 } 758 }
868 759
869 void HeadsUpDisplayLayerImpl::AsValueInto( 760 void HeadsUpDisplayLayerImpl::AsValueInto(
870 base::trace_event::TracedValue* dict) const { 761 base::trace_event::TracedValue* dict) const {
871 LayerImpl::AsValueInto(dict); 762 LayerImpl::AsValueInto(dict);
872 dict->SetString("layer_name", "Heads Up Display Layer"); 763 dict->SetString("layer_name", "Heads Up Display Layer");
873 } 764 }
874 765
875 } // namespace cc 766 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/heads_up_display_layer_impl.h ('k') | cc/scheduler/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698