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