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