heads_up_display_layer_impl.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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
3// found in the LICENSE file.
4
5#include "cc/layers/heads_up_display_layer_impl.h"
6
7#include <algorithm>
8#include <vector>
9
10#include "base/strings/string_split.h"
11#include "base/strings/stringprintf.h"
12#include "cc/debug/debug_colors.h"
13#include "cc/debug/debug_rect_history.h"
14#include "cc/debug/frame_rate_counter.h"
15#include "cc/debug/paint_time_counter.h"
16#include "cc/layers/quad_sink.h"
17#include "cc/output/renderer.h"
18#include "cc/quads/texture_draw_quad.h"
19#include "cc/resources/memory_history.h"
20#include "cc/resources/tile_manager.h"
21#include "cc/trees/layer_tree_impl.h"
22#include "skia/ext/platform_canvas.h"
23#include "third_party/khronos/GLES2/gl2.h"
24#include "third_party/khronos/GLES2/gl2ext.h"
25#include "third_party/skia/include/core/SkBitmap.h"
26#include "third_party/skia/include/core/SkPaint.h"
27#include "third_party/skia/include/core/SkTypeface.h"
28#include "third_party/skia/include/effects/SkColorMatrixFilter.h"
29#include "ui/gfx/point.h"
30#include "ui/gfx/size.h"
31
32namespace cc {
33
34static inline SkPaint CreatePaint() {
35  SkPaint paint;
36#if (SK_R32_SHIFT || SK_B32_SHIFT != 16)
37  // The SkCanvas is in RGBA but the shader is expecting BGRA, so we need to
38  // swizzle our colors when drawing to the SkCanvas.
39  SkColorMatrix swizzle_matrix;
40  for (int i = 0; i < 20; ++i)
41    swizzle_matrix.fMat[i] = 0;
42  swizzle_matrix.fMat[0 + 5 * 2] = 1;
43  swizzle_matrix.fMat[1 + 5 * 1] = 1;
44  swizzle_matrix.fMat[2 + 5 * 0] = 1;
45  swizzle_matrix.fMat[3 + 5 * 3] = 1;
46
47  skia::RefPtr<SkColorMatrixFilter> filter =
48      skia::AdoptRef(new SkColorMatrixFilter(swizzle_matrix));
49  paint.setColorFilter(filter.get());
50#endif
51  return paint;
52}
53
54HeadsUpDisplayLayerImpl::Graph::Graph(double indicator_value,
55                                      double start_upper_bound)
56    : value(0.0),
57      min(0.0),
58      max(0.0),
59      current_upper_bound(start_upper_bound),
60      default_upper_bound(start_upper_bound),
61      indicator(indicator_value) {}
62
63double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() {
64  double target_upper_bound = std::max(max, default_upper_bound);
65  current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5;
66  return current_upper_bound;
67}
68
69HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl,
70                                                 int id)
71    : LayerImpl(tree_impl, id),
72      typeface_(skia::AdoptRef(
73          SkTypeface::CreateFromName("monospace", SkTypeface::kBold))),
74      fps_graph_(60.0, 80.0),
75      paint_time_graph_(16.0, 48.0) {}
76
77HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {}
78
79scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl(
80    LayerTreeImpl* tree_impl) {
81  return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
82}
83
84bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode,
85                                       ResourceProvider* resource_provider) {
86  if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
87    return false;
88
89  if (!hud_resource_)
90    hud_resource_ = ScopedResource::create(resource_provider);
91
92  // TODO(danakj): Scale the HUD by device scale to make it more friendly under
93  // high DPI.
94
95  // TODO(danakj): The HUD could swap between two textures instead of creating a
96  // texture every frame in ubercompositor.
97  if (hud_resource_->size() != bounds() ||
98      resource_provider->InUseByConsumer(hud_resource_->id()))
99    hud_resource_->Free();
100
101  if (!hud_resource_->id()) {
102    hud_resource_->Allocate(
103        bounds(), GL_RGBA, ResourceProvider::TextureUsageAny);
104  }
105
106  return LayerImpl::WillDraw(draw_mode, resource_provider);
107}
108
109void HeadsUpDisplayLayerImpl::AppendQuads(QuadSink* quad_sink,
110                                          AppendQuadsData* append_quads_data) {
111  if (!hud_resource_->id())
112    return;
113
114  SharedQuadState* shared_quad_state =
115      quad_sink->UseSharedQuadState(CreateSharedQuadState());
116
117  gfx::Rect quad_rect(bounds());
118  gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect());
119  bool premultiplied_alpha = true;
120  gfx::PointF uv_top_left(0.f, 0.f);
121  gfx::PointF uv_bottom_right(1.f, 1.f);
122  const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f };
123  bool flipped = false;
124  scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
125  quad->SetNew(shared_quad_state,
126               quad_rect,
127               opaque_rect,
128               hud_resource_->id(),
129               premultiplied_alpha,
130               uv_top_left,
131               uv_bottom_right,
132               vertex_opacity,
133               flipped);
134  quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
135}
136
137void HeadsUpDisplayLayerImpl::UpdateHudTexture(
138    ResourceProvider* resource_provider) {
139  if (!hud_resource_->id())
140    return;
141
142  SkISize canvas_size;
143  if (hud_canvas_)
144    canvas_size = hud_canvas_->getDeviceSize();
145  else
146    canvas_size.set(0, 0);
147
148  if (canvas_size.fWidth != bounds().width() ||
149      canvas_size.fHeight != bounds().height() || !hud_canvas_) {
150    bool opaque = false;
151    hud_canvas_ = make_scoped_ptr(
152        skia::CreateBitmapCanvas(bounds().width(), bounds().height(), opaque));
153  }
154
155  UpdateHudContents();
156
157  hud_canvas_->clear(SkColorSetARGB(0, 0, 0, 0));
158  DrawHudContents(hud_canvas_.get());
159
160  const SkBitmap* bitmap = &hud_canvas_->getDevice()->accessBitmap(false);
161  SkAutoLockPixels locker(*bitmap);
162
163  gfx::Rect layer_rect(bounds());
164  DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config);
165  resource_provider->SetPixels(hud_resource_->id(),
166                               static_cast<const uint8_t*>(bitmap->getPixels()),
167                               layer_rect,
168                               layer_rect,
169                               gfx::Vector2d());
170}
171
172void HeadsUpDisplayLayerImpl::DidLoseOutputSurface() { hud_resource_.reset(); }
173
174bool HeadsUpDisplayLayerImpl::LayerIsAlwaysDamaged() const { return true; }
175
176void HeadsUpDisplayLayerImpl::UpdateHudContents() {
177  const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state();
178
179  // Don't update numbers every frame so text is readable.
180  base::TimeTicks now = layer_tree_impl()->CurrentFrameTimeTicks();
181  if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) {
182    time_of_last_graph_update_ = now;
183
184    if (debug_state.show_fps_counter) {
185      FrameRateCounter* fps_counter = layer_tree_impl()->frame_rate_counter();
186      fps_graph_.value = fps_counter->GetAverageFPS();
187      fps_counter->GetMinAndMaxFPS(&fps_graph_.min, &fps_graph_.max);
188    }
189
190    if (debug_state.continuous_painting) {
191      PaintTimeCounter* paint_time_counter =
192          layer_tree_impl()->paint_time_counter();
193      base::TimeDelta latest, min, max;
194
195      if (paint_time_counter->End())
196        latest = **paint_time_counter->End();
197      paint_time_counter->GetMinAndMaxPaintTime(&min, &max);
198
199      paint_time_graph_.value = latest.InMillisecondsF();
200      paint_time_graph_.min = min.InMillisecondsF();
201      paint_time_graph_.max = max.InMillisecondsF();
202    }
203
204    if (debug_state.ShowMemoryStats()) {
205      MemoryHistory* memory_history = layer_tree_impl()->memory_history();
206      if (memory_history->End())
207        memory_entry_ = **memory_history->End();
208      else
209        memory_entry_ = MemoryHistory::Entry();
210    }
211  }
212
213  fps_graph_.UpdateUpperBound();
214  paint_time_graph_.UpdateUpperBound();
215}
216
217void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) const {
218  const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state();
219
220  if (debug_state.ShowHudRects())
221    DrawDebugRects(canvas, layer_tree_impl()->debug_rect_history());
222
223  if (debug_state.show_platform_layer_tree)
224    DrawPlatformLayerTree(canvas);
225
226  SkRect area = SkRect::MakeEmpty();
227  if (debug_state.continuous_painting) {
228    // Don't show the FPS display when continuous painting is enabled, because
229    // it would show misleading numbers.
230    area = DrawPaintTimeDisplay(
231        canvas, layer_tree_impl()->paint_time_counter(), 0, 0);
232  } else if (debug_state.show_fps_counter) {
233    area =
234        DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0);
235  }
236
237  if (debug_state.ShowMemoryStats())
238    DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150));
239}
240
241void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas,
242                                       SkPaint* paint,
243                                       const std::string& text,
244                                       SkPaint::Align align,
245                                       int size,
246                                       int x,
247                                       int y) const {
248  const bool anti_alias = paint->isAntiAlias();
249  paint->setAntiAlias(true);
250
251  paint->setTextSize(size);
252  paint->setTextAlign(align);
253  paint->setTypeface(typeface_.get());
254  canvas->drawText(text.c_str(), text.length(), x, y, *paint);
255
256  paint->setAntiAlias(anti_alias);
257}
258
259void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas,
260                                       SkPaint* paint,
261                                       const std::string& text,
262                                       SkPaint::Align align,
263                                       int size,
264                                       const SkPoint& pos) const {
265  DrawText(canvas, paint, text, align, size, pos.x(), pos.y());
266}
267
268void HeadsUpDisplayLayerImpl::DrawGraphBackground(SkCanvas* canvas,
269                                                  SkPaint* paint,
270                                                  const SkRect& bounds) const {
271  paint->setColor(DebugColors::HUDBackgroundColor());
272  canvas->drawRect(bounds, *paint);
273}
274
275void HeadsUpDisplayLayerImpl::DrawGraphLines(SkCanvas* canvas,
276                                             SkPaint* paint,
277                                             const SkRect& bounds,
278                                             const Graph& graph) const {
279  // Draw top and bottom line.
280  paint->setColor(DebugColors::HUDSeparatorLineColor());
281  canvas->drawLine(bounds.left(),
282                   bounds.top() - 1,
283                   bounds.right(),
284                   bounds.top() - 1,
285                   *paint);
286  canvas->drawLine(
287      bounds.left(), bounds.bottom(), bounds.right(), bounds.bottom(), *paint);
288
289  // Draw indicator line (additive blend mode to increase contrast when drawn on
290  // top of graph).
291  paint->setColor(DebugColors::HUDIndicatorLineColor());
292  paint->setXfermodeMode(SkXfermode::kPlus_Mode);
293  const double indicator_top =
294      bounds.height() * (1.0 - graph.indicator / graph.current_upper_bound) -
295      1.0;
296  canvas->drawLine(bounds.left(),
297                   bounds.top() + indicator_top,
298                   bounds.right(),
299                   bounds.top() + indicator_top,
300                   *paint);
301  paint->setXfermode(NULL);
302}
303
304void HeadsUpDisplayLayerImpl::DrawPlatformLayerTree(SkCanvas* canvas) const {
305  const int kFontHeight = 14;
306  SkPaint paint = CreatePaint();
307  DrawGraphBackground(
308      canvas,
309      &paint,
310      SkRect::MakeXYWH(0, 0, bounds().width(), bounds().height()));
311
312  std::string layer_tree = layer_tree_impl()->layer_tree_as_text();
313  std::vector<std::string> lines;
314  base::SplitString(layer_tree, '\n', &lines);
315
316  paint.setColor(DebugColors::PlatformLayerTreeTextColor());
317  for (size_t i = 0;
318       i < lines.size() &&
319           static_cast<int>(2 + i * kFontHeight) < bounds().height();
320       ++i) {
321    DrawText(canvas,
322             &paint,
323             lines[i],
324             SkPaint::kLeft_Align,
325             kFontHeight,
326             2,
327             2 + (i + 1) * kFontHeight);
328  }
329}
330
331SkRect HeadsUpDisplayLayerImpl::DrawFPSDisplay(
332    SkCanvas* canvas,
333    const FrameRateCounter* fps_counter,
334    int right,
335    int top) const {
336  const int kPadding = 4;
337  const int kGap = 6;
338
339  const int kFontHeight = 15;
340
341  const int kGraphWidth = fps_counter->time_stamp_history_size() - 2;
342  const int kGraphHeight = 40;
343
344  const int kHistogramWidth = 37;
345
346  int width = kGraphWidth + kHistogramWidth + 4 * kPadding;
347  int height = kFontHeight + kGraphHeight + 4 * kPadding + 2;
348  int left = bounds().width() - width - right;
349  SkRect area = SkRect::MakeXYWH(left, top, width, height);
350
351  SkPaint paint = CreatePaint();
352  DrawGraphBackground(canvas, &paint, area);
353
354  SkRect text_bounds =
355      SkRect::MakeXYWH(left + kPadding,
356                       top + kPadding,
357                       kGraphWidth + kHistogramWidth + kGap + 2,
358                       kFontHeight);
359  SkRect graph_bounds = SkRect::MakeXYWH(left + kPadding,
360                                         text_bounds.bottom() + 2 * kPadding,
361                                         kGraphWidth,
362                                         kGraphHeight);
363  SkRect histogram_bounds = SkRect::MakeXYWH(graph_bounds.right() + kGap,
364                                             graph_bounds.top(),
365                                             kHistogramWidth,
366                                             kGraphHeight);
367
368  const std::string value_text =
369      base::StringPrintf("FPS:%5.1f", fps_graph_.value);
370  const std::string min_max_text =
371      base::StringPrintf("%.0f-%.0f", fps_graph_.min, fps_graph_.max);
372
373  paint.setColor(DebugColors::FPSDisplayTextAndGraphColor());
374  DrawText(canvas,
375           &paint,
376           value_text,
377           SkPaint::kLeft_Align,
378           kFontHeight,
379           text_bounds.left(),
380           text_bounds.bottom());
381  DrawText(canvas,
382           &paint,
383           min_max_text,
384           SkPaint::kRight_Align,
385           kFontHeight,
386           text_bounds.right(),
387           text_bounds.bottom());
388
389  DrawGraphLines(canvas, &paint, graph_bounds, fps_graph_);
390
391  // Collect graph and histogram data.
392  SkPath path;
393
394  const int kHistogramSize = 20;
395  double histogram[kHistogramSize] = { 1.0 };
396  double max_bucket_value = 1.0;
397
398  for (FrameRateCounter::RingBufferType::Iterator it = --fps_counter->end(); it;
399       --it) {
400    base::TimeDelta delta = fps_counter->RecentFrameInterval(it.index() + 1);
401
402    // Skip this particular instantaneous frame rate if it is not likely to have
403    // been valid.
404    if (!fps_counter->IsBadFrameInterval(delta)) {
405      double fps = 1.0 / delta.InSecondsF();
406
407      // Clamp the FPS to the range we want to plot visually.
408      double p = fps / fps_graph_.current_upper_bound;
409      if (p > 1.0)
410        p = 1.0;
411
412      // Plot this data point.
413      SkPoint cur =
414          SkPoint::Make(graph_bounds.left() + it.index(),
415                        graph_bounds.bottom() - p * graph_bounds.height());
416      if (path.isEmpty())
417        path.moveTo(cur);
418      else
419        path.lineTo(cur);
420
421      // Use the fps value to find the right bucket in the histogram.
422      int bucket_index = floor(p * (kHistogramSize - 1));
423
424      // Add the delta time to take the time spent at that fps rate into
425      // account.
426      histogram[bucket_index] += delta.InSecondsF();
427      max_bucket_value = std::max(histogram[bucket_index], max_bucket_value);
428    }
429  }
430
431  // Draw FPS histogram.
432  paint.setColor(DebugColors::HUDSeparatorLineColor());
433  canvas->drawLine(histogram_bounds.left() - 1,
434                   histogram_bounds.top() - 1,
435                   histogram_bounds.left() - 1,
436                   histogram_bounds.bottom() + 1,
437                   paint);
438  canvas->drawLine(histogram_bounds.right() + 1,
439                   histogram_bounds.top() - 1,
440                   histogram_bounds.right() + 1,
441                   histogram_bounds.bottom() + 1,
442                   paint);
443
444  paint.setColor(DebugColors::FPSDisplayTextAndGraphColor());
445  const double bar_height = histogram_bounds.height() / kHistogramSize;
446
447  for (int i = kHistogramSize - 1; i >= 0; --i) {
448    if (histogram[i] > 0) {
449      double bar_width =
450          histogram[i] / max_bucket_value * histogram_bounds.width();
451      canvas->drawRect(
452          SkRect::MakeXYWH(histogram_bounds.left(),
453                           histogram_bounds.bottom() - (i + 1) * bar_height,
454                           bar_width,
455                           1),
456          paint);
457    }
458  }
459
460  // Draw FPS graph.
461  paint.setAntiAlias(true);
462  paint.setStyle(SkPaint::kStroke_Style);
463  paint.setStrokeWidth(1);
464  canvas->drawPath(path, paint);
465
466  return area;
467}
468
469SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas* canvas,
470                                                  int right,
471                                                  int top,
472                                                  int width) const {
473  if (!memory_entry_.bytes_total())
474    return SkRect::MakeEmpty();
475
476  const int kPadding = 4;
477  const int kFontHeight = 13;
478
479  const int height = 3 * kFontHeight + 4 * kPadding;
480  const int left = bounds().width() - width - right;
481  const SkRect area = SkRect::MakeXYWH(left, top, width, height);
482
483  const double megabyte = 1024.0 * 1024.0;
484
485  SkPaint paint = CreatePaint();
486  DrawGraphBackground(canvas, &paint, area);
487
488  SkPoint title_pos = SkPoint::Make(left + kPadding, top + kFontHeight);
489  SkPoint stat1_pos = SkPoint::Make(left + width - kPadding - 1,
490                                    top + kPadding + 2 * kFontHeight);
491  SkPoint stat2_pos = SkPoint::Make(left + width - kPadding - 1,
492                                    top + 2 * kPadding + 3 * kFontHeight);
493
494  paint.setColor(DebugColors::MemoryDisplayTextColor());
495  DrawText(canvas,
496           &paint,
497           "GPU memory",
498           SkPaint::kLeft_Align,
499           kFontHeight,
500           title_pos);
501
502  std::string text =
503      base::StringPrintf("%6.1f MB used",
504                         (memory_entry_.bytes_unreleasable +
505                          memory_entry_.bytes_allocated) / megabyte);
506  DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat1_pos);
507
508  if (memory_entry_.bytes_over) {
509    paint.setColor(SK_ColorRED);
510    text = base::StringPrintf("%6.1f MB over",
511                              memory_entry_.bytes_over / megabyte);
512  } else {
513    text = base::StringPrintf("%6.1f MB max ",
514                              memory_entry_.total_budget_in_bytes / megabyte);
515  }
516  DrawText(canvas, &paint, text, SkPaint::kRight_Align, kFontHeight, stat2_pos);
517
518  return area;
519}
520
521SkRect HeadsUpDisplayLayerImpl::DrawPaintTimeDisplay(
522    SkCanvas* canvas,
523    const PaintTimeCounter* paint_time_counter,
524    int right,
525    int top) const {
526  const int kPadding = 4;
527  const int kFontHeight = 15;
528
529  const int kGraphWidth = paint_time_counter->HistorySize();
530  const int kGraphHeight = 40;
531
532  const int width = kGraphWidth + 2 * kPadding;
533  const int height =
534      kFontHeight + kGraphHeight + 4 * kPadding + 2 + kFontHeight + kPadding;
535  const int left = bounds().width() - width - right;
536
537  const SkRect area = SkRect::MakeXYWH(left, top, width, height);
538
539  SkPaint paint = CreatePaint();
540  DrawGraphBackground(canvas, &paint, area);
541
542  SkRect text_bounds = SkRect::MakeXYWH(
543      left + kPadding, top + kPadding, kGraphWidth, kFontHeight);
544  SkRect text_bounds2 = SkRect::MakeXYWH(left + kPadding,
545                                         text_bounds.bottom() + kPadding,
546                                         kGraphWidth,
547                                         kFontHeight);
548  SkRect graph_bounds = SkRect::MakeXYWH(left + kPadding,
549                                         text_bounds2.bottom() + 2 * kPadding,
550                                         kGraphWidth,
551                                         kGraphHeight);
552
553  const std::string value_text =
554      base::StringPrintf("%.1f", paint_time_graph_.value);
555  const std::string min_max_text = base::StringPrintf(
556      "%.1f-%.1f", paint_time_graph_.min, paint_time_graph_.max);
557
558  paint.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
559  DrawText(canvas,
560           &paint,
561           "Page paint time (ms)",
562           SkPaint::kLeft_Align,
563           kFontHeight,
564           text_bounds.left(),
565           text_bounds.bottom());
566  DrawText(canvas,
567           &paint,
568           value_text,
569           SkPaint::kLeft_Align,
570           kFontHeight,
571           text_bounds2.left(),
572           text_bounds2.bottom());
573  DrawText(canvas,
574           &paint,
575           min_max_text,
576           SkPaint::kRight_Align,
577           kFontHeight,
578           text_bounds2.right(),
579           text_bounds2.bottom());
580
581  paint.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
582  for (PaintTimeCounter::RingBufferType::Iterator it =
583           paint_time_counter->End();
584       it;
585       --it) {
586    double pt = it->InMillisecondsF();
587
588    if (pt == 0.0)
589      continue;
590
591    double p = pt / paint_time_graph_.current_upper_bound;
592    if (p > 1.0)
593      p = 1.0;
594
595    canvas->drawRect(
596        SkRect::MakeXYWH(graph_bounds.left() + it.index(),
597                         graph_bounds.bottom() - p * graph_bounds.height(),
598                         1,
599                         p * graph_bounds.height()),
600        paint);
601  }
602
603  DrawGraphLines(canvas, &paint, graph_bounds, paint_time_graph_);
604
605  return area;
606}
607
608void HeadsUpDisplayLayerImpl::DrawDebugRects(
609    SkCanvas* canvas,
610    DebugRectHistory* debug_rect_history) const {
611  const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects();
612  float rect_scale = 1.f / layer_tree_impl()->device_scale_factor();
613  SkPaint paint = CreatePaint();
614
615  canvas->save();
616  canvas->scale(rect_scale, rect_scale);
617
618  for (size_t i = 0; i < debug_rects.size(); ++i) {
619    SkColor stroke_color = 0;
620    SkColor fill_color = 0;
621    float stroke_width = 0.f;
622
623    switch (debug_rects[i].type) {
624      case PAINT_RECT_TYPE:
625        stroke_color = DebugColors::PaintRectBorderColor();
626        fill_color = DebugColors::PaintRectFillColor();
627        stroke_width = DebugColors::PaintRectBorderWidth(layer_tree_impl());
628        break;
629      case PROPERTY_CHANGED_RECT_TYPE:
630        stroke_color = DebugColors::PropertyChangedRectBorderColor();
631        fill_color = DebugColors::PropertyChangedRectFillColor();
632        stroke_width =
633            DebugColors::PropertyChangedRectBorderWidth(layer_tree_impl());
634        break;
635      case SURFACE_DAMAGE_RECT_TYPE:
636        stroke_color = DebugColors::SurfaceDamageRectBorderColor();
637        fill_color = DebugColors::SurfaceDamageRectFillColor();
638        stroke_width =
639            DebugColors::SurfaceDamageRectBorderWidth(layer_tree_impl());
640        break;
641      case REPLICA_SCREEN_SPACE_RECT_TYPE:
642        stroke_color = DebugColors::ScreenSpaceSurfaceReplicaRectBorderColor();
643        fill_color = DebugColors::ScreenSpaceSurfaceReplicaRectFillColor();
644        stroke_width = DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth(
645            layer_tree_impl());
646        break;
647      case SCREEN_SPACE_RECT_TYPE:
648        stroke_color = DebugColors::ScreenSpaceLayerRectBorderColor();
649        fill_color = DebugColors::ScreenSpaceLayerRectFillColor();
650        stroke_width =
651            DebugColors::ScreenSpaceLayerRectBorderWidth(layer_tree_impl());
652        break;
653      case OCCLUDING_RECT_TYPE:
654        stroke_color = DebugColors::OccludingRectBorderColor();
655        fill_color = DebugColors::OccludingRectFillColor();
656        stroke_width = DebugColors::OccludingRectBorderWidth(layer_tree_impl());
657        break;
658      case NONOCCLUDING_RECT_TYPE:
659        stroke_color = DebugColors::NonOccludingRectBorderColor();
660        fill_color = DebugColors::NonOccludingRectFillColor();
661        stroke_width =
662            DebugColors::NonOccludingRectBorderWidth(layer_tree_impl());
663        break;
664    }
665
666    const gfx::RectF& rect = debug_rects[i].rect;
667    SkRect sk_rect =
668        SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height());
669    paint.setColor(fill_color);
670    paint.setStyle(SkPaint::kFill_Style);
671    canvas->drawRect(sk_rect, paint);
672
673    paint.setColor(stroke_color);
674    paint.setStyle(SkPaint::kStroke_Style);
675    paint.setStrokeWidth(SkFloatToScalar(stroke_width));
676    canvas->drawRect(sk_rect, paint);
677  }
678
679  canvas->restore();
680}
681
682const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {
683  return "cc::HeadsUpDisplayLayerImpl";
684}
685
686}  // namespace cc
687