Chromium Code Reviews| Index: cc/layers/heads_up_display_layer_impl.cc |
| diff --git a/cc/layers/heads_up_display_layer_impl.cc b/cc/layers/heads_up_display_layer_impl.cc |
| index be5af99c71edea84b8c11f2c2d4f5cddf675d94d..fe41492aef55f86807fce39ca6f7296d4743b6b4 100644 |
| --- a/cc/layers/heads_up_display_layer_impl.cc |
| +++ b/cc/layers/heads_up_display_layer_impl.cc |
| @@ -9,7 +9,6 @@ |
| #include "base/strings/stringprintf.h" |
| #include "cc/debug/debug_colors.h" |
| -#include "cc/debug/debug_rect_history.h" |
| #include "cc/debug/frame_rate_counter.h" |
| #include "cc/debug/paint_time_counter.h" |
| #include "cc/debug/traced_value.h" |
| @@ -71,7 +70,8 @@ HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, |
| typeface_(skia::AdoptRef( |
| SkTypeface::CreateFromName("monospace", SkTypeface::kBold))), |
| fps_graph_(60.0, 80.0), |
| - paint_time_graph_(16.0, 48.0) {} |
| + paint_time_graph_(16.0, 48.0), |
| + needs_update_(false) {} |
| HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} |
| @@ -225,7 +225,7 @@ void HeadsUpDisplayLayerImpl::UpdateHudContents() { |
| paint_time_graph_.UpdateUpperBound(); |
| } |
| -void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) const { |
| +void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) { |
| const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); |
| if (debug_state.ShowHudRects()) |
| @@ -586,11 +586,69 @@ SkRect HeadsUpDisplayLayerImpl::DrawPaintTimeDisplay( |
| return area; |
| } |
| +void HeadsUpDisplayLayerImpl::DrawDebugRect( |
| + SkCanvas* canvas, |
| + const DebugRect& rect, |
| + const SkColor stroke_color, |
| + const SkColor fill_color, |
| + const float stroke_width, |
| + const std::string label_text) const { |
| + SkPaint paint = CreatePaint(); |
| + |
| + gfx::RectF debug_layer_rect = gfx::ScaleRect( |
| + rect.rect, 1.0 / contents_scale_x(), 1.0 / contents_scale_y()); |
| + SkRect sk_rect = RectFToSkRect(debug_layer_rect); |
| + paint.setColor(fill_color); |
| + paint.setStyle(SkPaint::kFill_Style); |
| + canvas->drawRect(sk_rect, paint); |
| + |
| + paint.setColor(stroke_color); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + paint.setStrokeWidth(SkFloatToScalar(stroke_width)); |
| + canvas->drawRect(sk_rect, paint); |
| + |
| + if (label_text.length()) { |
| + const int kFontHeight = 12; |
| + const int kPadding = 3; |
| + |
| + canvas->save(); |
| + canvas->clipRect(sk_rect); |
| + canvas->translate(sk_rect.x(), sk_rect.y()); |
| + |
| + SkPaint label_paint = CreatePaint(); |
| + label_paint.setTextSize(kFontHeight); |
| + label_paint.setTypeface(typeface_.get()); |
| + label_paint.setColor(stroke_color); |
| + |
| + const SkScalar label_text_width = |
| + label_paint.measureText(label_text.c_str(), label_text.length()); |
| + canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, |
| + kFontHeight + 2 * kPadding), |
| + label_paint); |
| + |
| + label_paint.setAntiAlias(true); |
| + label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); |
| + canvas->drawText(label_text.c_str(), |
| + label_text.length(), |
| + kPadding, |
| + kFontHeight * 0.8f + kPadding, |
| + label_paint); |
| + |
| + canvas->restore(); |
| + } |
| +} |
| + |
| +int fade_step = 0; |
| +std::vector<DebugRect> paint_rects; |
|
caseq
2014/03/05 13:20:59
WAT?
malch
2014/03/05 14:43:26
Done.
|
| + |
| void HeadsUpDisplayLayerImpl::DrawDebugRects( |
| SkCanvas* canvas, |
| - DebugRectHistory* debug_rect_history) const { |
| + DebugRectHistory* debug_rect_history) { |
| const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects(); |
| - SkPaint paint = CreatePaint(); |
| + |
| + 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.
|
| + 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.
|
| + std::vector<DebugRect> new_paint_rects; |
| for (size_t i = 0; i < debug_rects.size(); ++i) { |
| SkColor stroke_color = 0; |
| @@ -600,8 +658,10 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects( |
| switch (debug_rects[i].type) { |
| case PAINT_RECT_TYPE: |
| - stroke_color = DebugColors::PaintRectBorderColor(); |
| - fill_color = DebugColors::PaintRectFillColor(); |
| + has_new_paint_rects = true; |
| + new_paint_rects.push_back(debug_rects[i]); |
| + stroke_color = DebugColors::PaintRectBorderColor(0); |
| + fill_color = DebugColors::PaintRectFillColor(0); |
| stroke_width = DebugColors::PaintRectBorderWidth(); |
| break; |
| case PROPERTY_CHANGED_RECT_TYPE: |
| @@ -660,47 +720,29 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects( |
| break; |
| } |
| - gfx::RectF debug_layer_rect = gfx::ScaleRect(debug_rects[i].rect, |
| - 1.0 / contents_scale_x(), |
| - 1.0 / contents_scale_y()); |
| - SkRect sk_rect = RectFToSkRect(debug_layer_rect); |
| - paint.setColor(fill_color); |
| - paint.setStyle(SkPaint::kFill_Style); |
| - canvas->drawRect(sk_rect, paint); |
| - |
| - paint.setColor(stroke_color); |
| - paint.setStyle(SkPaint::kStroke_Style); |
| - paint.setStrokeWidth(SkFloatToScalar(stroke_width)); |
| - canvas->drawRect(sk_rect, paint); |
| - |
| - if (label_text.length()) { |
| - const int kFontHeight = 12; |
| - const int kPadding = 3; |
| - |
| - canvas->save(); |
| - canvas->clipRect(sk_rect); |
| - canvas->translate(sk_rect.x(), sk_rect.y()); |
| - |
| - SkPaint label_paint = CreatePaint(); |
| - label_paint.setTextSize(kFontHeight); |
| - label_paint.setTypeface(typeface_.get()); |
| - label_paint.setColor(stroke_color); |
| - |
| - const SkScalar label_text_width = |
| - label_paint.measureText(label_text.c_str(), label_text.length()); |
| - canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, |
| - kFontHeight + 2 * kPadding), |
| - label_paint); |
| - |
| - label_paint.setAntiAlias(true); |
| - label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); |
| - canvas->drawText(label_text.c_str(), |
| - label_text.length(), |
| - kPadding, |
| - kFontHeight * 0.8f + kPadding, |
| - label_paint); |
| - |
| - canvas->restore(); |
| + DrawDebugRect(canvas, |
| + debug_rects[i], |
| + stroke_color, |
| + fill_color, |
| + stroke_width, |
| + label_text); |
| + } |
| + |
| + if (has_new_paint_rects) { |
| + fade_step = 0; |
| + paint_rects = new_paint_rects; |
| + needs_update_ = true; |
| + } else if (needs_update_) { |
| + fade_step++; |
| + if (fade_step >= DebugColors::kFadeSteps) |
| + needs_update_ = false; |
| + for (size_t i = 0; i < paint_rects.size(); ++i) { |
| + DrawDebugRect(canvas, |
| + paint_rects[i], |
| + DebugColors::PaintRectBorderColor(fade_step), |
| + DebugColors::PaintRectFillColor(fade_step), |
| + DebugColors::PaintRectBorderWidth(), |
| + ""); |
| } |
| } |
| } |