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

Unified Diff: cc/layers/heads_up_display_layer_impl.cc

Issue 187343007: Adding fading effect for paint rectangles in HUD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed int to unsigned. Removed const where it's needless. Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
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..4df34ba0132ac7b05b7ef862ffade2205ef336ef 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),
+ fade_step_(0) {}
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,64 @@ SkRect HeadsUpDisplayLayerImpl::DrawPaintTimeDisplay(
return area;
}
+void HeadsUpDisplayLayerImpl::DrawDebugRect(
+ SkCanvas* canvas,
+ const DebugRect& rect,
+ SkColor stroke_color,
+ SkColor fill_color,
+ 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();
+ }
+}
+
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();
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.
+
+ std::vector<DebugRect> new_paint_rects;
for (size_t i = 0; i < debug_rects.size(); ++i) {
SkColor stroke_color = 0;
@@ -600,8 +653,10 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects(
switch (debug_rects[i].type) {
case PAINT_RECT_TYPE:
- stroke_color = DebugColors::PaintRectBorderColor();
- fill_color = DebugColors::PaintRectFillColor();
+ 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.
+ stroke_color =
+ DebugColors::PaintRectBorderColor(DebugColors::kFadeSteps);
+ fill_color = DebugColors::PaintRectFillColor(DebugColors::kFadeSteps);
stroke_width = DebugColors::PaintRectBorderWidth();
break;
case PROPERTY_CHANGED_RECT_TYPE:
@@ -660,49 +715,30 @@ 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 (new_paint_rects.size()) {
+ fade_step_ = DebugColors::kFadeSteps;
+ paint_rects_.swap(new_paint_rects);
+ } else if (fade_step_ > 0) {
+ fade_step_--;
+ 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(),
+ "");
}
}
+ if (fade_step_ > 0)
+ 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
}
const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {

Powered by Google App Engine
This is Rietveld 408576698