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.
5 #include "cc/layers/heads_up_display_layer_impl.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/trace_event/trace_event.h"
12 #include "base/trace_event/trace_event_argument.h"
13 #include "cc/debug/debug_colors.h"
14 #include "cc/debug/frame_rate_counter.h"
15 #include "cc/debug/paint_time_counter.h"
16 #include "cc/output/begin_frame_args.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/trees/layer_tree_host_impl.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/geometry/point.h"
30 #include "ui/gfx/geometry/size.h"
31 #include "ui/gfx/geometry/size_conversions.h"
32 #include "ui/gfx/hud_font.h"
36 static inline SkPaint
CreatePaint() {
38 #if (SK_R32_SHIFT || SK_B32_SHIFT != 16)
39 // The SkCanvas is in RGBA but the shader is expecting BGRA, so we need to
40 // swizzle our colors when drawing to the SkCanvas.
41 SkColorMatrix swizzle_matrix
;
42 for (int i
= 0; i
< 20; ++i
)
43 swizzle_matrix
.fMat
[i
] = 0;
44 swizzle_matrix
.fMat
[0 + 5 * 2] = 1;
45 swizzle_matrix
.fMat
[1 + 5 * 1] = 1;
46 swizzle_matrix
.fMat
[2 + 5 * 0] = 1;
47 swizzle_matrix
.fMat
[3 + 5 * 3] = 1;
49 skia::RefPtr
<SkColorMatrixFilter
> filter
=
50 skia::AdoptRef(SkColorMatrixFilter::Create(swizzle_matrix
));
51 paint
.setColorFilter(filter
.get());
56 HeadsUpDisplayLayerImpl::Graph::Graph(double indicator_value
,
57 double start_upper_bound
)
61 current_upper_bound(start_upper_bound
),
62 default_upper_bound(start_upper_bound
),
63 indicator(indicator_value
) {}
65 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() {
66 double target_upper_bound
= std::max(max
, default_upper_bound
);
67 current_upper_bound
+= (target_upper_bound
- current_upper_bound
) * 0.5;
68 return current_upper_bound
;
71 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl
* tree_impl
,
73 : LayerImpl(tree_impl
, id
),
74 typeface_(gfx::GetHudTypeface()),
75 internal_contents_scale_(1.f
),
76 fps_graph_(60.0, 80.0),
77 paint_time_graph_(16.0, 48.0),
80 typeface_
= skia::AdoptRef(
81 SkTypeface::CreateFromName("monospace", SkTypeface::kBold
));
85 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {}
87 scoped_ptr
<LayerImpl
> HeadsUpDisplayLayerImpl::CreateLayerImpl(
88 LayerTreeImpl
* tree_impl
) {
89 return HeadsUpDisplayLayerImpl::Create(tree_impl
, id());
92 void HeadsUpDisplayLayerImpl::AcquireResource(
93 ResourceProvider
* resource_provider
) {
94 for (ScopedPtrVector
<ScopedResource
>::iterator it
= resources_
.begin();
95 it
!= resources_
.end();
97 if (!resource_provider
->InUseByConsumer((*it
)->id())) {
98 resources_
.swap(it
, resources_
.end() - 1);
103 scoped_ptr
<ScopedResource
> resource
=
104 ScopedResource::Create(resource_provider
);
105 resource
->Allocate(internal_content_bounds_
,
106 ResourceProvider::TEXTURE_HINT_IMMUTABLE
, RGBA_8888
);
107 resources_
.push_back(resource
.Pass());
110 class ResourceSizeIsEqualTo
{
112 explicit ResourceSizeIsEqualTo(const gfx::Size
& size_
)
113 : compare_size_(size_
) {}
115 bool operator()(const ScopedResource
* resource
) {
116 return resource
->size() == compare_size_
;
120 const gfx::Size compare_size_
;
123 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources(
124 ResourceProvider
* resource_provider
) {
125 ScopedPtrVector
<ScopedResource
>::iterator it_erase
=
126 resources_
.partition(ResourceSizeIsEqualTo(internal_content_bounds_
));
127 resources_
.erase(it_erase
, resources_
.end());
130 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode
,
131 ResourceProvider
* resource_provider
) {
132 if (draw_mode
== DRAW_MODE_RESOURCELESS_SOFTWARE
)
135 internal_contents_scale_
= draw_properties().ideal_contents_scale
;
136 internal_content_bounds_
=
137 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), internal_contents_scale_
));
139 ReleaseUnmatchedSizeResources(resource_provider
);
140 AcquireResource(resource_provider
);
141 return LayerImpl::WillDraw(draw_mode
, resource_provider
);
144 void HeadsUpDisplayLayerImpl::AppendQuads(
145 RenderPass
* render_pass
,
146 AppendQuadsData
* append_quads_data
) {
147 if (!resources_
.back()->id())
150 SharedQuadState
* shared_quad_state
=
151 render_pass
->CreateAndAppendSharedQuadState();
152 PopulateScaledSharedQuadState(shared_quad_state
, internal_contents_scale_
);
154 gfx::Rect
quad_rect(internal_content_bounds_
);
155 gfx::Rect
opaque_rect(contents_opaque() ? quad_rect
: gfx::Rect());
156 gfx::Rect
visible_quad_rect(quad_rect
);
157 bool premultiplied_alpha
= true;
158 gfx::PointF
uv_top_left(0.f
, 0.f
);
159 gfx::PointF
uv_bottom_right(1.f
, 1.f
);
160 const float vertex_opacity
[] = { 1.f
, 1.f
, 1.f
, 1.f
};
161 bool flipped
= false;
162 bool nearest_neighbor
= false;
163 TextureDrawQuad
* quad
=
164 render_pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
165 quad
->SetNew(shared_quad_state
,
169 resources_
.back()->id(),
179 void HeadsUpDisplayLayerImpl::UpdateHudTexture(
181 ResourceProvider
* resource_provider
) {
182 if (draw_mode
== DRAW_MODE_RESOURCELESS_SOFTWARE
|| !resources_
.back()->id())
187 canvas_size
= hud_surface_
->getCanvas()->getDeviceSize();
189 canvas_size
.set(0, 0);
191 if (canvas_size
.width() != internal_content_bounds_
.width() ||
192 canvas_size
.height() != internal_content_bounds_
.height() ||
194 TRACE_EVENT0("cc", "ResizeHudCanvas");
196 hud_surface_
= skia::AdoptRef(SkSurface::NewRasterN32Premul(
197 internal_content_bounds_
.width(), internal_content_bounds_
.height()));
203 TRACE_EVENT0("cc", "DrawHudContents");
204 hud_surface_
->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0));
205 hud_surface_
->getCanvas()->save();
206 hud_surface_
->getCanvas()->scale(internal_contents_scale_
,
207 internal_contents_scale_
);
209 DrawHudContents(hud_surface_
->getCanvas());
211 hud_surface_
->getCanvas()->restore();
214 TRACE_EVENT0("cc", "UploadHudTexture");
216 size_t row_bytes
= 0;
217 const void* pixels
= hud_surface_
->getCanvas()->peekPixels(&info
, &row_bytes
);
219 DCHECK(info
.colorType() == kN32_SkColorType
);
220 resource_provider
->CopyToResource(resources_
.back()->id(),
221 static_cast<const uint8_t*>(pixels
),
222 internal_content_bounds_
);
225 void HeadsUpDisplayLayerImpl::ReleaseResources() {
229 void HeadsUpDisplayLayerImpl::UpdateHudContents() {
230 const LayerTreeDebugState
& debug_state
= layer_tree_impl()->debug_state();
232 // Don't update numbers every frame so text is readable.
233 base::TimeTicks now
= layer_tree_impl()->CurrentBeginFrameArgs().frame_time
;
234 if (base::TimeDelta(now
- time_of_last_graph_update_
).InSecondsF() > 0.25f
) {
235 time_of_last_graph_update_
= now
;
237 if (debug_state
.show_fps_counter
) {
238 FrameRateCounter
* fps_counter
= layer_tree_impl()->frame_rate_counter();
239 fps_graph_
.value
= fps_counter
->GetAverageFPS();
240 fps_counter
->GetMinAndMaxFPS(&fps_graph_
.min
, &fps_graph_
.max
);
243 if (debug_state
.continuous_painting
) {
244 PaintTimeCounter
* paint_time_counter
=
245 layer_tree_impl()->paint_time_counter();
246 base::TimeDelta latest
, min
, max
;
248 if (paint_time_counter
->End())
249 latest
= **paint_time_counter
->End();
250 paint_time_counter
->GetMinAndMaxPaintTime(&min
, &max
);
252 paint_time_graph_
.value
= latest
.InMillisecondsF();
253 paint_time_graph_
.min
= min
.InMillisecondsF();
254 paint_time_graph_
.max
= max
.InMillisecondsF();
257 if (debug_state
.ShowMemoryStats()) {
258 MemoryHistory
* memory_history
= layer_tree_impl()->memory_history();
259 if (memory_history
->End())
260 memory_entry_
= **memory_history
->End();
262 memory_entry_
= MemoryHistory::Entry();
266 fps_graph_
.UpdateUpperBound();
267 paint_time_graph_
.UpdateUpperBound();
270 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas
* canvas
) {
271 const LayerTreeDebugState
& debug_state
= layer_tree_impl()->debug_state();
273 if (debug_state
.ShowHudRects()) {
274 DrawDebugRects(canvas
, layer_tree_impl()->debug_rect_history());
275 if (IsAnimatingHUDContents()) {
276 layer_tree_impl()->SetNeedsRedraw();
280 SkRect area
= SkRect::MakeEmpty();
281 if (debug_state
.continuous_painting
) {
282 area
= DrawPaintTimeDisplay(
283 canvas
, layer_tree_impl()->paint_time_counter(), 0, 0);
284 } else if (debug_state
.show_fps_counter
) {
285 // Don't show the FPS display when continuous painting is enabled, because
286 // it would show misleading numbers.
288 DrawFPSDisplay(canvas
, layer_tree_impl()->frame_rate_counter(), 0, 0);
291 if (debug_state
.show_fps_counter
|| debug_state
.continuous_painting
) {
292 area
= DrawGpuRasterizationStatus(canvas
, 0, area
.bottom(),
293 SkMaxScalar(area
.width(), 150));
296 if (debug_state
.ShowMemoryStats())
297 DrawMemoryDisplay(canvas
, 0, area
.bottom(), SkMaxScalar(area
.width(), 150));
300 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas
* canvas
,
302 const std::string
& text
,
303 SkPaint::Align align
,
307 const bool anti_alias
= paint
->isAntiAlias();
308 paint
->setAntiAlias(true);
310 paint
->setTextSize(size
);
311 paint
->setTextAlign(align
);
312 paint
->setTypeface(typeface_
.get());
313 canvas
->drawText(text
.c_str(), text
.length(), x
, y
, *paint
);
315 paint
->setAntiAlias(anti_alias
);
318 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas
* canvas
,
320 const std::string
& text
,
321 SkPaint::Align align
,
323 const SkPoint
& pos
) const {
324 DrawText(canvas
, paint
, text
, align
, size
, pos
.x(), pos
.y());
327 void HeadsUpDisplayLayerImpl::DrawGraphBackground(SkCanvas
* canvas
,
329 const SkRect
& bounds
) const {
330 paint
->setColor(DebugColors::HUDBackgroundColor());
331 canvas
->drawRect(bounds
, *paint
);
334 void HeadsUpDisplayLayerImpl::DrawGraphLines(SkCanvas
* canvas
,
336 const SkRect
& bounds
,
337 const Graph
& graph
) const {
338 // Draw top and bottom line.
339 paint
->setColor(DebugColors::HUDSeparatorLineColor());
340 canvas
->drawLine(bounds
.left(),
346 bounds
.left(), bounds
.bottom(), bounds
.right(), bounds
.bottom(), *paint
);
348 // Draw indicator line (additive blend mode to increase contrast when drawn on
350 paint
->setColor(DebugColors::HUDIndicatorLineColor());
351 paint
->setXfermodeMode(SkXfermode::kPlus_Mode
);
352 const double indicator_top
=
353 bounds
.height() * (1.0 - graph
.indicator
/ graph
.current_upper_bound
) -
355 canvas
->drawLine(bounds
.left(),
356 bounds
.top() + indicator_top
,
358 bounds
.top() + indicator_top
,
360 paint
->setXfermode(nullptr);
363 SkRect
HeadsUpDisplayLayerImpl::DrawFPSDisplay(
365 const FrameRateCounter
* fps_counter
,
368 const int kPadding
= 4;
371 const int kFontHeight
= 15;
373 const int kGraphWidth
= fps_counter
->time_stamp_history_size() - 2;
374 const int kGraphHeight
= 40;
376 const int kHistogramWidth
= 37;
378 int width
= kGraphWidth
+ kHistogramWidth
+ 4 * kPadding
;
379 int height
= kFontHeight
+ kGraphHeight
+ 4 * kPadding
+ 2;
380 int left
= bounds().width() - width
- right
;
381 SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
383 SkPaint paint
= CreatePaint();
384 DrawGraphBackground(canvas
, &paint
, area
);
387 SkRect::MakeXYWH(left
+ kPadding
,
389 kGraphWidth
+ kHistogramWidth
+ kGap
+ 2,
391 SkRect graph_bounds
= SkRect::MakeXYWH(left
+ kPadding
,
392 text_bounds
.bottom() + 2 * kPadding
,
395 SkRect histogram_bounds
= SkRect::MakeXYWH(graph_bounds
.right() + kGap
,
400 const std::string value_text
=
401 base::StringPrintf("FPS:%5.1f", fps_graph_
.value
);
402 const std::string min_max_text
=
403 base::StringPrintf("%.0f-%.0f", fps_graph_
.min
, fps_graph_
.max
);
405 VLOG(1) << value_text
;
407 paint
.setColor(DebugColors::FPSDisplayTextAndGraphColor());
411 SkPaint::kLeft_Align
,
414 text_bounds
.bottom());
418 SkPaint::kRight_Align
,
421 text_bounds
.bottom());
423 DrawGraphLines(canvas
, &paint
, graph_bounds
, fps_graph_
);
425 // Collect graph and histogram data.
428 const int kHistogramSize
= 20;
429 double histogram
[kHistogramSize
] = { 1.0 };
430 double max_bucket_value
= 1.0;
432 for (FrameRateCounter::RingBufferType::Iterator it
= --fps_counter
->end(); it
;
434 base::TimeDelta delta
= fps_counter
->RecentFrameInterval(it
.index() + 1);
436 // Skip this particular instantaneous frame rate if it is not likely to have
438 if (!fps_counter
->IsBadFrameInterval(delta
)) {
439 double fps
= 1.0 / delta
.InSecondsF();
441 // Clamp the FPS to the range we want to plot visually.
442 double p
= fps
/ fps_graph_
.current_upper_bound
;
446 // Plot this data point.
448 SkPoint::Make(graph_bounds
.left() + it
.index(),
449 graph_bounds
.bottom() - p
* graph_bounds
.height());
455 // Use the fps value to find the right bucket in the histogram.
456 int bucket_index
= floor(p
* (kHistogramSize
- 1));
458 // Add the delta time to take the time spent at that fps rate into
460 histogram
[bucket_index
] += delta
.InSecondsF();
461 max_bucket_value
= std::max(histogram
[bucket_index
], max_bucket_value
);
465 // Draw FPS histogram.
466 paint
.setColor(DebugColors::HUDSeparatorLineColor());
467 canvas
->drawLine(histogram_bounds
.left() - 1,
468 histogram_bounds
.top() - 1,
469 histogram_bounds
.left() - 1,
470 histogram_bounds
.bottom() + 1,
472 canvas
->drawLine(histogram_bounds
.right() + 1,
473 histogram_bounds
.top() - 1,
474 histogram_bounds
.right() + 1,
475 histogram_bounds
.bottom() + 1,
478 paint
.setColor(DebugColors::FPSDisplayTextAndGraphColor());
479 const double bar_height
= histogram_bounds
.height() / kHistogramSize
;
481 for (int i
= kHistogramSize
- 1; i
>= 0; --i
) {
482 if (histogram
[i
] > 0) {
484 histogram
[i
] / max_bucket_value
* histogram_bounds
.width();
486 SkRect::MakeXYWH(histogram_bounds
.left(),
487 histogram_bounds
.bottom() - (i
+ 1) * bar_height
,
495 paint
.setAntiAlias(true);
496 paint
.setStyle(SkPaint::kStroke_Style
);
497 paint
.setStrokeWidth(1);
498 canvas
->drawPath(path
, paint
);
503 SkRect
HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas
* canvas
,
507 if (!memory_entry_
.total_bytes_used
)
508 return SkRect::MakeEmpty();
510 const int kPadding
= 4;
511 const int kFontHeight
= 13;
513 const int height
= 3 * kFontHeight
+ 4 * kPadding
;
514 const int left
= bounds().width() - width
- right
;
515 const SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
517 const double kMegabyte
= 1024.0 * 1024.0;
519 SkPaint paint
= CreatePaint();
520 DrawGraphBackground(canvas
, &paint
, area
);
522 SkPoint title_pos
= SkPoint::Make(left
+ kPadding
, top
+ kFontHeight
);
523 SkPoint stat1_pos
= SkPoint::Make(left
+ width
- kPadding
- 1,
524 top
+ kPadding
+ 2 * kFontHeight
);
525 SkPoint stat2_pos
= SkPoint::Make(left
+ width
- kPadding
- 1,
526 top
+ 2 * kPadding
+ 3 * kFontHeight
);
528 paint
.setColor(DebugColors::MemoryDisplayTextColor());
532 SkPaint::kLeft_Align
,
536 std::string text
= base::StringPrintf(
537 "%6.1f MB used", memory_entry_
.total_bytes_used
/ kMegabyte
);
538 DrawText(canvas
, &paint
, text
, SkPaint::kRight_Align
, kFontHeight
, stat1_pos
);
540 if (!memory_entry_
.had_enough_memory
)
541 paint
.setColor(SK_ColorRED
);
542 text
= base::StringPrintf("%6.1f MB max ",
543 memory_entry_
.total_budget_in_bytes
/ kMegabyte
);
544 DrawText(canvas
, &paint
, text
, SkPaint::kRight_Align
, kFontHeight
, stat2_pos
);
549 SkRect
HeadsUpDisplayLayerImpl::DrawGpuRasterizationStatus(SkCanvas
* canvas
,
554 SkColor color
= SK_ColorRED
;
555 switch (layer_tree_impl()->GetGpuRasterizationStatus()) {
556 case GpuRasterizationStatus::ON
:
557 status
= "GPU raster: on";
558 color
= SK_ColorGREEN
;
560 case GpuRasterizationStatus::ON_FORCED
:
561 status
= "GPU raster: on (forced)";
562 color
= SK_ColorGREEN
;
564 case GpuRasterizationStatus::OFF_DEVICE
:
565 status
= "GPU raster: off (device)";
568 case GpuRasterizationStatus::OFF_VIEWPORT
:
569 status
= "GPU raster: off (viewport)";
570 color
= SK_ColorYELLOW
;
572 case GpuRasterizationStatus::OFF_CONTENT
:
573 status
= "GPU raster: off (content)";
574 color
= SK_ColorYELLOW
;
579 return SkRect::MakeEmpty();
581 const int kPadding
= 4;
582 const int kFontHeight
= 13;
584 const int height
= kFontHeight
+ 2 * kPadding
;
585 const int left
= bounds().width() - width
- right
;
586 const SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
588 SkPaint paint
= CreatePaint();
589 DrawGraphBackground(canvas
, &paint
, area
);
591 SkPoint gpu_status_pos
= SkPoint::Make(left
+ kPadding
, top
+ kFontHeight
);
593 paint
.setColor(color
);
594 DrawText(canvas
, &paint
, status
, SkPaint::kLeft_Align
, kFontHeight
,
600 SkRect
HeadsUpDisplayLayerImpl::DrawPaintTimeDisplay(
602 const PaintTimeCounter
* paint_time_counter
,
605 const int kPadding
= 4;
606 const int kFontHeight
= 15;
608 const int kGraphWidth
= paint_time_counter
->HistorySize();
609 const int kGraphHeight
= 40;
611 const int width
= kGraphWidth
+ 2 * kPadding
;
613 kFontHeight
+ kGraphHeight
+ 4 * kPadding
+ 2 + kFontHeight
+ kPadding
;
614 const int left
= bounds().width() - width
- right
;
616 const SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
618 SkPaint paint
= CreatePaint();
619 DrawGraphBackground(canvas
, &paint
, area
);
621 SkRect text_bounds
= SkRect::MakeXYWH(
622 left
+ kPadding
, top
+ kPadding
, kGraphWidth
, kFontHeight
);
623 SkRect text_bounds2
= SkRect::MakeXYWH(left
+ kPadding
,
624 text_bounds
.bottom() + kPadding
,
627 SkRect graph_bounds
= SkRect::MakeXYWH(left
+ kPadding
,
628 text_bounds2
.bottom() + 2 * kPadding
,
632 const std::string value_text
=
633 base::StringPrintf("%.1f", paint_time_graph_
.value
);
634 const std::string min_max_text
= base::StringPrintf(
635 "%.1f-%.1f", paint_time_graph_
.min
, paint_time_graph_
.max
);
637 paint
.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
638 DrawText(canvas
, &paint
, "Compositor frame time (ms)", SkPaint::kLeft_Align
,
639 kFontHeight
, text_bounds
.left(), text_bounds
.bottom());
643 SkPaint::kLeft_Align
,
646 text_bounds2
.bottom());
650 SkPaint::kRight_Align
,
652 text_bounds2
.right(),
653 text_bounds2
.bottom());
655 paint
.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
656 for (PaintTimeCounter::RingBufferType::Iterator it
=
657 paint_time_counter
->End();
660 double pt
= it
->InMillisecondsF();
665 double p
= pt
/ paint_time_graph_
.current_upper_bound
;
670 SkRect::MakeXYWH(graph_bounds
.left() + it
.index(),
671 graph_bounds
.bottom() - p
* graph_bounds
.height(),
673 p
* graph_bounds
.height()),
677 DrawGraphLines(canvas
, &paint
, graph_bounds
, paint_time_graph_
);
682 void HeadsUpDisplayLayerImpl::DrawDebugRect(
685 const DebugRect
& rect
,
686 SkColor stroke_color
,
689 const std::string
& label_text
) const {
690 gfx::Rect debug_layer_rect
=
691 gfx::ScaleToEnclosingRect(rect
.rect
, 1.0 / internal_contents_scale_
,
692 1.0 / internal_contents_scale_
);
693 SkIRect sk_rect
= RectToSkIRect(debug_layer_rect
);
694 paint
->setColor(fill_color
);
695 paint
->setStyle(SkPaint::kFill_Style
);
696 canvas
->drawIRect(sk_rect
, *paint
);
698 paint
->setColor(stroke_color
);
699 paint
->setStyle(SkPaint::kStroke_Style
);
700 paint
->setStrokeWidth(SkFloatToScalar(stroke_width
));
701 canvas
->drawIRect(sk_rect
, *paint
);
703 if (label_text
.length()) {
704 const int kFontHeight
= 12;
705 const int kPadding
= 3;
707 // The debug_layer_rect may be huge, and converting to a floating point may
708 // be lossy, so intersect with the HUD layer bounds first to prevent that.
709 gfx::Rect clip_rect
= debug_layer_rect
;
710 clip_rect
.Intersect(gfx::Rect(internal_content_bounds_
));
711 SkRect sk_clip_rect
= RectToSkRect(clip_rect
);
714 canvas
->clipRect(sk_clip_rect
);
715 canvas
->translate(sk_clip_rect
.x(), sk_clip_rect
.y());
717 SkPaint label_paint
= CreatePaint();
718 label_paint
.setTextSize(kFontHeight
);
719 label_paint
.setTypeface(typeface_
.get());
720 label_paint
.setColor(stroke_color
);
722 const SkScalar label_text_width
=
723 label_paint
.measureText(label_text
.c_str(), label_text
.length());
724 canvas
->drawRect(SkRect::MakeWH(label_text_width
+ 2 * kPadding
,
725 kFontHeight
+ 2 * kPadding
),
728 label_paint
.setAntiAlias(true);
729 label_paint
.setColor(SkColorSetARGB(255, 50, 50, 50));
730 canvas
->drawText(label_text
.c_str(),
733 kFontHeight
* 0.8f
+ kPadding
,
740 void HeadsUpDisplayLayerImpl::DrawDebugRects(
742 DebugRectHistory
* debug_rect_history
) {
743 SkPaint paint
= CreatePaint();
745 const std::vector
<DebugRect
>& debug_rects
= debug_rect_history
->debug_rects();
746 std::vector
<DebugRect
> new_paint_rects
;
748 for (size_t i
= 0; i
< debug_rects
.size(); ++i
) {
749 SkColor stroke_color
= 0;
750 SkColor fill_color
= 0;
751 float stroke_width
= 0.f
;
752 std::string label_text
;
754 switch (debug_rects
[i
].type
) {
755 case PAINT_RECT_TYPE
:
756 new_paint_rects
.push_back(debug_rects
[i
]);
758 case PROPERTY_CHANGED_RECT_TYPE
:
759 stroke_color
= DebugColors::PropertyChangedRectBorderColor();
760 fill_color
= DebugColors::PropertyChangedRectFillColor();
761 stroke_width
= DebugColors::PropertyChangedRectBorderWidth();
763 case SURFACE_DAMAGE_RECT_TYPE
:
764 stroke_color
= DebugColors::SurfaceDamageRectBorderColor();
765 fill_color
= DebugColors::SurfaceDamageRectFillColor();
766 stroke_width
= DebugColors::SurfaceDamageRectBorderWidth();
768 case REPLICA_SCREEN_SPACE_RECT_TYPE
:
769 stroke_color
= DebugColors::ScreenSpaceSurfaceReplicaRectBorderColor();
770 fill_color
= DebugColors::ScreenSpaceSurfaceReplicaRectFillColor();
771 stroke_width
= DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth();
773 case SCREEN_SPACE_RECT_TYPE
:
774 stroke_color
= DebugColors::ScreenSpaceLayerRectBorderColor();
775 fill_color
= DebugColors::ScreenSpaceLayerRectFillColor();
776 stroke_width
= DebugColors::ScreenSpaceLayerRectBorderWidth();
778 case TOUCH_EVENT_HANDLER_RECT_TYPE
:
779 stroke_color
= DebugColors::TouchEventHandlerRectBorderColor();
780 fill_color
= DebugColors::TouchEventHandlerRectFillColor();
781 stroke_width
= DebugColors::TouchEventHandlerRectBorderWidth();
782 label_text
= "touch event listener";
784 case WHEEL_EVENT_HANDLER_RECT_TYPE
:
785 stroke_color
= DebugColors::WheelEventHandlerRectBorderColor();
786 fill_color
= DebugColors::WheelEventHandlerRectFillColor();
787 stroke_width
= DebugColors::WheelEventHandlerRectBorderWidth();
788 label_text
= "mousewheel event listener";
790 case SCROLL_EVENT_HANDLER_RECT_TYPE
:
791 stroke_color
= DebugColors::ScrollEventHandlerRectBorderColor();
792 fill_color
= DebugColors::ScrollEventHandlerRectFillColor();
793 stroke_width
= DebugColors::ScrollEventHandlerRectBorderWidth();
794 label_text
= "scroll event listener";
796 case NON_FAST_SCROLLABLE_RECT_TYPE
:
797 stroke_color
= DebugColors::NonFastScrollableRectBorderColor();
798 fill_color
= DebugColors::NonFastScrollableRectFillColor();
799 stroke_width
= DebugColors::NonFastScrollableRectBorderWidth();
800 label_text
= "repaints on scroll";
802 case ANIMATION_BOUNDS_RECT_TYPE
:
803 stroke_color
= DebugColors::LayerAnimationBoundsBorderColor();
804 fill_color
= DebugColors::LayerAnimationBoundsFillColor();
805 stroke_width
= DebugColors::LayerAnimationBoundsBorderWidth();
806 label_text
= "animation bounds";
810 DrawDebugRect(canvas
,
819 if (new_paint_rects
.size()) {
820 paint_rects_
.swap(new_paint_rects
);
821 fade_step_
= DebugColors::kFadeSteps
;
823 if (fade_step_
> 0) {
825 for (size_t i
= 0; i
< paint_rects_
.size(); ++i
) {
826 DrawDebugRect(canvas
,
829 DebugColors::PaintRectBorderColor(fade_step_
),
830 DebugColors::PaintRectFillColor(fade_step_
),
831 DebugColors::PaintRectBorderWidth(),
837 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {
838 return "cc::HeadsUpDisplayLayerImpl";
841 void HeadsUpDisplayLayerImpl::AsValueInto(
842 base::trace_event::TracedValue
* dict
) const {
843 LayerImpl::AsValueInto(dict
);
844 dict
->SetString("layer_name", "Heads Up Display Layer");