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/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"
34 static inline SkPaint
CreatePaint() {
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;
47 skia::RefPtr
<SkColorMatrixFilter
> filter
=
48 skia::AdoptRef(new SkColorMatrixFilter(swizzle_matrix
));
49 paint
.setColorFilter(filter
.get());
54 HeadsUpDisplayLayerImpl::Graph::Graph(double indicator_value
,
55 double start_upper_bound
)
59 current_upper_bound(start_upper_bound
),
60 default_upper_bound(start_upper_bound
),
61 indicator(indicator_value
) {}
63 double 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
;
69 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl
* tree_impl
,
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) {}
77 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {}
79 scoped_ptr
<LayerImpl
> HeadsUpDisplayLayerImpl::CreateLayerImpl(
80 LayerTreeImpl
* tree_impl
) {
81 return HeadsUpDisplayLayerImpl::Create(tree_impl
, id()).PassAs
<LayerImpl
>();
84 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode
,
85 ResourceProvider
* resource_provider
) {
86 if (draw_mode
== DRAW_MODE_RESOURCELESS_SOFTWARE
)
90 hud_resource_
= ScopedResource::create(resource_provider
);
92 // TODO(danakj): Scale the HUD by device scale to make it more friendly under
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();
101 if (!hud_resource_
->id()) {
102 hud_resource_
->Allocate(
103 bounds(), GL_RGBA
, ResourceProvider::TextureUsageAny
);
106 return LayerImpl::WillDraw(draw_mode
, resource_provider
);
109 void HeadsUpDisplayLayerImpl::AppendQuads(QuadSink
* quad_sink
,
110 AppendQuadsData
* append_quads_data
) {
111 if (!hud_resource_
->id())
114 SharedQuadState
* shared_quad_state
=
115 quad_sink
->UseSharedQuadState(CreateSharedQuadState());
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
,
134 quad_sink
->Append(quad
.PassAs
<DrawQuad
>(), append_quads_data
);
137 void HeadsUpDisplayLayerImpl::UpdateHudTexture(
138 ResourceProvider
* resource_provider
) {
139 if (!hud_resource_
->id())
144 canvas_size
= hud_canvas_
->getDeviceSize();
146 canvas_size
.set(0, 0);
148 if (canvas_size
.fWidth
!= bounds().width() ||
149 canvas_size
.fHeight
!= bounds().height() || !hud_canvas_
) {
151 hud_canvas_
= make_scoped_ptr(
152 skia::CreateBitmapCanvas(bounds().width(), bounds().height(), opaque
));
157 hud_canvas_
->clear(SkColorSetARGB(0, 0, 0, 0));
158 DrawHudContents(hud_canvas_
.get());
160 const SkBitmap
* bitmap
= &hud_canvas_
->getDevice()->accessBitmap(false);
161 SkAutoLockPixels
locker(*bitmap
);
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()),
172 void HeadsUpDisplayLayerImpl::DidLoseOutputSurface() { hud_resource_
.reset(); }
174 bool HeadsUpDisplayLayerImpl::LayerIsAlwaysDamaged() const { return true; }
176 void HeadsUpDisplayLayerImpl::UpdateHudContents() {
177 const LayerTreeDebugState
& debug_state
= layer_tree_impl()->debug_state();
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
;
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
);
190 if (debug_state
.continuous_painting
) {
191 PaintTimeCounter
* paint_time_counter
=
192 layer_tree_impl()->paint_time_counter();
193 base::TimeDelta latest
, min
, max
;
195 if (paint_time_counter
->End())
196 latest
= **paint_time_counter
->End();
197 paint_time_counter
->GetMinAndMaxPaintTime(&min
, &max
);
199 paint_time_graph_
.value
= latest
.InMillisecondsF();
200 paint_time_graph_
.min
= min
.InMillisecondsF();
201 paint_time_graph_
.max
= max
.InMillisecondsF();
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();
209 memory_entry_
= MemoryHistory::Entry();
213 fps_graph_
.UpdateUpperBound();
214 paint_time_graph_
.UpdateUpperBound();
217 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas
* canvas
) const {
218 const LayerTreeDebugState
& debug_state
= layer_tree_impl()->debug_state();
220 if (debug_state
.ShowHudRects())
221 DrawDebugRects(canvas
, layer_tree_impl()->debug_rect_history());
223 SkRect area
= SkRect::MakeEmpty();
224 if (debug_state
.continuous_painting
) {
225 // Don't show the FPS display when continuous painting is enabled, because
226 // it would show misleading numbers.
227 area
= DrawPaintTimeDisplay(
228 canvas
, layer_tree_impl()->paint_time_counter(), 0, 0);
229 } else if (debug_state
.show_fps_counter
) {
231 DrawFPSDisplay(canvas
, layer_tree_impl()->frame_rate_counter(), 0, 0);
234 if (debug_state
.ShowMemoryStats())
235 DrawMemoryDisplay(canvas
, 0, area
.bottom(), SkMaxScalar(area
.width(), 150));
238 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas
* canvas
,
240 const std::string
& text
,
241 SkPaint::Align align
,
245 const bool anti_alias
= paint
->isAntiAlias();
246 paint
->setAntiAlias(true);
248 paint
->setTextSize(size
);
249 paint
->setTextAlign(align
);
250 paint
->setTypeface(typeface_
.get());
251 canvas
->drawText(text
.c_str(), text
.length(), x
, y
, *paint
);
253 paint
->setAntiAlias(anti_alias
);
256 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas
* canvas
,
258 const std::string
& text
,
259 SkPaint::Align align
,
261 const SkPoint
& pos
) const {
262 DrawText(canvas
, paint
, text
, align
, size
, pos
.x(), pos
.y());
265 void HeadsUpDisplayLayerImpl::DrawGraphBackground(SkCanvas
* canvas
,
267 const SkRect
& bounds
) const {
268 paint
->setColor(DebugColors::HUDBackgroundColor());
269 canvas
->drawRect(bounds
, *paint
);
272 void HeadsUpDisplayLayerImpl::DrawGraphLines(SkCanvas
* canvas
,
274 const SkRect
& bounds
,
275 const Graph
& graph
) const {
276 // Draw top and bottom line.
277 paint
->setColor(DebugColors::HUDSeparatorLineColor());
278 canvas
->drawLine(bounds
.left(),
284 bounds
.left(), bounds
.bottom(), bounds
.right(), bounds
.bottom(), *paint
);
286 // Draw indicator line (additive blend mode to increase contrast when drawn on
288 paint
->setColor(DebugColors::HUDIndicatorLineColor());
289 paint
->setXfermodeMode(SkXfermode::kPlus_Mode
);
290 const double indicator_top
=
291 bounds
.height() * (1.0 - graph
.indicator
/ graph
.current_upper_bound
) -
293 canvas
->drawLine(bounds
.left(),
294 bounds
.top() + indicator_top
,
296 bounds
.top() + indicator_top
,
298 paint
->setXfermode(NULL
);
301 SkRect
HeadsUpDisplayLayerImpl::DrawFPSDisplay(
303 const FrameRateCounter
* fps_counter
,
306 const int kPadding
= 4;
309 const int kFontHeight
= 15;
311 const int kGraphWidth
= fps_counter
->time_stamp_history_size() - 2;
312 const int kGraphHeight
= 40;
314 const int kHistogramWidth
= 37;
316 int width
= kGraphWidth
+ kHistogramWidth
+ 4 * kPadding
;
317 int height
= kFontHeight
+ kGraphHeight
+ 4 * kPadding
+ 2;
318 int left
= bounds().width() - width
- right
;
319 SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
321 SkPaint paint
= CreatePaint();
322 DrawGraphBackground(canvas
, &paint
, area
);
325 SkRect::MakeXYWH(left
+ kPadding
,
327 kGraphWidth
+ kHistogramWidth
+ kGap
+ 2,
329 SkRect graph_bounds
= SkRect::MakeXYWH(left
+ kPadding
,
330 text_bounds
.bottom() + 2 * kPadding
,
333 SkRect histogram_bounds
= SkRect::MakeXYWH(graph_bounds
.right() + kGap
,
338 const std::string value_text
=
339 base::StringPrintf("FPS:%5.1f", fps_graph_
.value
);
340 const std::string min_max_text
=
341 base::StringPrintf("%.0f-%.0f", fps_graph_
.min
, fps_graph_
.max
);
343 paint
.setColor(DebugColors::FPSDisplayTextAndGraphColor());
347 SkPaint::kLeft_Align
,
350 text_bounds
.bottom());
354 SkPaint::kRight_Align
,
357 text_bounds
.bottom());
359 DrawGraphLines(canvas
, &paint
, graph_bounds
, fps_graph_
);
361 // Collect graph and histogram data.
364 const int kHistogramSize
= 20;
365 double histogram
[kHistogramSize
] = { 1.0 };
366 double max_bucket_value
= 1.0;
368 for (FrameRateCounter::RingBufferType::Iterator it
= --fps_counter
->end(); it
;
370 base::TimeDelta delta
= fps_counter
->RecentFrameInterval(it
.index() + 1);
372 // Skip this particular instantaneous frame rate if it is not likely to have
374 if (!fps_counter
->IsBadFrameInterval(delta
)) {
375 double fps
= 1.0 / delta
.InSecondsF();
377 // Clamp the FPS to the range we want to plot visually.
378 double p
= fps
/ fps_graph_
.current_upper_bound
;
382 // Plot this data point.
384 SkPoint::Make(graph_bounds
.left() + it
.index(),
385 graph_bounds
.bottom() - p
* graph_bounds
.height());
391 // Use the fps value to find the right bucket in the histogram.
392 int bucket_index
= floor(p
* (kHistogramSize
- 1));
394 // Add the delta time to take the time spent at that fps rate into
396 histogram
[bucket_index
] += delta
.InSecondsF();
397 max_bucket_value
= std::max(histogram
[bucket_index
], max_bucket_value
);
401 // Draw FPS histogram.
402 paint
.setColor(DebugColors::HUDSeparatorLineColor());
403 canvas
->drawLine(histogram_bounds
.left() - 1,
404 histogram_bounds
.top() - 1,
405 histogram_bounds
.left() - 1,
406 histogram_bounds
.bottom() + 1,
408 canvas
->drawLine(histogram_bounds
.right() + 1,
409 histogram_bounds
.top() - 1,
410 histogram_bounds
.right() + 1,
411 histogram_bounds
.bottom() + 1,
414 paint
.setColor(DebugColors::FPSDisplayTextAndGraphColor());
415 const double bar_height
= histogram_bounds
.height() / kHistogramSize
;
417 for (int i
= kHistogramSize
- 1; i
>= 0; --i
) {
418 if (histogram
[i
] > 0) {
420 histogram
[i
] / max_bucket_value
* histogram_bounds
.width();
422 SkRect::MakeXYWH(histogram_bounds
.left(),
423 histogram_bounds
.bottom() - (i
+ 1) * bar_height
,
431 paint
.setAntiAlias(true);
432 paint
.setStyle(SkPaint::kStroke_Style
);
433 paint
.setStrokeWidth(1);
434 canvas
->drawPath(path
, paint
);
439 SkRect
HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas
* canvas
,
443 if (!memory_entry_
.bytes_total())
444 return SkRect::MakeEmpty();
446 const int kPadding
= 4;
447 const int kFontHeight
= 13;
449 const int height
= 3 * kFontHeight
+ 4 * kPadding
;
450 const int left
= bounds().width() - width
- right
;
451 const SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
453 const double megabyte
= 1024.0 * 1024.0;
455 SkPaint paint
= CreatePaint();
456 DrawGraphBackground(canvas
, &paint
, area
);
458 SkPoint title_pos
= SkPoint::Make(left
+ kPadding
, top
+ kFontHeight
);
459 SkPoint stat1_pos
= SkPoint::Make(left
+ width
- kPadding
- 1,
460 top
+ kPadding
+ 2 * kFontHeight
);
461 SkPoint stat2_pos
= SkPoint::Make(left
+ width
- kPadding
- 1,
462 top
+ 2 * kPadding
+ 3 * kFontHeight
);
464 paint
.setColor(DebugColors::MemoryDisplayTextColor());
468 SkPaint::kLeft_Align
,
473 base::StringPrintf("%6.1f MB used",
474 (memory_entry_
.bytes_unreleasable
+
475 memory_entry_
.bytes_allocated
) / megabyte
);
476 DrawText(canvas
, &paint
, text
, SkPaint::kRight_Align
, kFontHeight
, stat1_pos
);
478 if (memory_entry_
.bytes_over
) {
479 paint
.setColor(SK_ColorRED
);
480 text
= base::StringPrintf("%6.1f MB over",
481 memory_entry_
.bytes_over
/ megabyte
);
483 text
= base::StringPrintf("%6.1f MB max ",
484 memory_entry_
.total_budget_in_bytes
/ megabyte
);
486 DrawText(canvas
, &paint
, text
, SkPaint::kRight_Align
, kFontHeight
, stat2_pos
);
491 SkRect
HeadsUpDisplayLayerImpl::DrawPaintTimeDisplay(
493 const PaintTimeCounter
* paint_time_counter
,
496 const int kPadding
= 4;
497 const int kFontHeight
= 15;
499 const int kGraphWidth
= paint_time_counter
->HistorySize();
500 const int kGraphHeight
= 40;
502 const int width
= kGraphWidth
+ 2 * kPadding
;
504 kFontHeight
+ kGraphHeight
+ 4 * kPadding
+ 2 + kFontHeight
+ kPadding
;
505 const int left
= bounds().width() - width
- right
;
507 const SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
509 SkPaint paint
= CreatePaint();
510 DrawGraphBackground(canvas
, &paint
, area
);
512 SkRect text_bounds
= SkRect::MakeXYWH(
513 left
+ kPadding
, top
+ kPadding
, kGraphWidth
, kFontHeight
);
514 SkRect text_bounds2
= SkRect::MakeXYWH(left
+ kPadding
,
515 text_bounds
.bottom() + kPadding
,
518 SkRect graph_bounds
= SkRect::MakeXYWH(left
+ kPadding
,
519 text_bounds2
.bottom() + 2 * kPadding
,
523 const std::string value_text
=
524 base::StringPrintf("%.1f", paint_time_graph_
.value
);
525 const std::string min_max_text
= base::StringPrintf(
526 "%.1f-%.1f", paint_time_graph_
.min
, paint_time_graph_
.max
);
528 paint
.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
531 "Page paint time (ms)",
532 SkPaint::kLeft_Align
,
535 text_bounds
.bottom());
539 SkPaint::kLeft_Align
,
542 text_bounds2
.bottom());
546 SkPaint::kRight_Align
,
548 text_bounds2
.right(),
549 text_bounds2
.bottom());
551 paint
.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
552 for (PaintTimeCounter::RingBufferType::Iterator it
=
553 paint_time_counter
->End();
556 double pt
= it
->InMillisecondsF();
561 double p
= pt
/ paint_time_graph_
.current_upper_bound
;
566 SkRect::MakeXYWH(graph_bounds
.left() + it
.index(),
567 graph_bounds
.bottom() - p
* graph_bounds
.height(),
569 p
* graph_bounds
.height()),
573 DrawGraphLines(canvas
, &paint
, graph_bounds
, paint_time_graph_
);
578 void HeadsUpDisplayLayerImpl::DrawDebugRects(
580 DebugRectHistory
* debug_rect_history
) const {
581 const std::vector
<DebugRect
>& debug_rects
= debug_rect_history
->debug_rects();
582 float rect_scale
= 1.f
/ layer_tree_impl()->device_scale_factor();
583 SkPaint paint
= CreatePaint();
586 canvas
->scale(rect_scale
, rect_scale
);
588 for (size_t i
= 0; i
< debug_rects
.size(); ++i
) {
589 SkColor stroke_color
= 0;
590 SkColor fill_color
= 0;
591 float stroke_width
= 0.f
;
592 std::string label_text
;
594 switch (debug_rects
[i
].type
) {
595 case PAINT_RECT_TYPE
:
596 stroke_color
= DebugColors::PaintRectBorderColor();
597 fill_color
= DebugColors::PaintRectFillColor();
598 stroke_width
= DebugColors::PaintRectBorderWidth(layer_tree_impl());
600 case PROPERTY_CHANGED_RECT_TYPE
:
601 stroke_color
= DebugColors::PropertyChangedRectBorderColor();
602 fill_color
= DebugColors::PropertyChangedRectFillColor();
604 DebugColors::PropertyChangedRectBorderWidth(layer_tree_impl());
606 case SURFACE_DAMAGE_RECT_TYPE
:
607 stroke_color
= DebugColors::SurfaceDamageRectBorderColor();
608 fill_color
= DebugColors::SurfaceDamageRectFillColor();
610 DebugColors::SurfaceDamageRectBorderWidth(layer_tree_impl());
612 case REPLICA_SCREEN_SPACE_RECT_TYPE
:
613 stroke_color
= DebugColors::ScreenSpaceSurfaceReplicaRectBorderColor();
614 fill_color
= DebugColors::ScreenSpaceSurfaceReplicaRectFillColor();
615 stroke_width
= DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth(
618 case SCREEN_SPACE_RECT_TYPE
:
619 stroke_color
= DebugColors::ScreenSpaceLayerRectBorderColor();
620 fill_color
= DebugColors::ScreenSpaceLayerRectFillColor();
622 DebugColors::ScreenSpaceLayerRectBorderWidth(layer_tree_impl());
624 case OCCLUDING_RECT_TYPE
:
625 stroke_color
= DebugColors::OccludingRectBorderColor();
626 fill_color
= DebugColors::OccludingRectFillColor();
627 stroke_width
= DebugColors::OccludingRectBorderWidth(layer_tree_impl());
629 case NONOCCLUDING_RECT_TYPE
:
630 stroke_color
= DebugColors::NonOccludingRectBorderColor();
631 fill_color
= DebugColors::NonOccludingRectFillColor();
633 DebugColors::NonOccludingRectBorderWidth(layer_tree_impl());
635 case TOUCH_EVENT_HANDLER_RECT_TYPE
:
636 stroke_color
= DebugColors::TouchEventHandlerRectBorderColor();
637 fill_color
= DebugColors::TouchEventHandlerRectFillColor();
639 DebugColors::TouchEventHandlerRectBorderWidth(layer_tree_impl());
640 label_text
= "touch event listener";
642 case WHEEL_EVENT_HANDLER_RECT_TYPE
:
643 stroke_color
= DebugColors::WheelEventHandlerRectBorderColor();
644 fill_color
= DebugColors::WheelEventHandlerRectFillColor();
646 DebugColors::WheelEventHandlerRectBorderWidth(layer_tree_impl());
647 label_text
= "mousewheel event listener";
649 case NON_FAST_SCROLLABLE_RECT_TYPE
:
650 stroke_color
= DebugColors::NonFastScrollableRectBorderColor();
651 fill_color
= DebugColors::NonFastScrollableRectFillColor();
653 DebugColors::NonFastScrollableRectBorderWidth(layer_tree_impl());
654 label_text
= "repaints on scroll";
658 const gfx::RectF
& rect
= debug_rects
[i
].rect
;
660 SkRect::MakeXYWH(rect
.x(), rect
.y(), rect
.width(), rect
.height());
661 paint
.setColor(fill_color
);
662 paint
.setStyle(SkPaint::kFill_Style
);
663 canvas
->drawRect(sk_rect
, paint
);
665 paint
.setColor(stroke_color
);
666 paint
.setStyle(SkPaint::kStroke_Style
);
667 paint
.setStrokeWidth(SkFloatToScalar(stroke_width
));
668 canvas
->drawRect(sk_rect
, paint
);
670 if (label_text
.length()) {
671 const int kFontHeight
= 12;
672 const int kPadding
= 3;
673 const float device_scale_factor
=
674 layer_tree_impl()->device_scale_factor();
677 canvas
->clipRect(sk_rect
);
678 canvas
->translate(sk_rect
.x(), sk_rect
.y());
679 canvas
->scale(device_scale_factor
, device_scale_factor
);
681 SkPaint label_paint
= CreatePaint();
682 label_paint
.setTextSize(kFontHeight
);
683 label_paint
.setTypeface(typeface_
.get());
684 label_paint
.setColor(stroke_color
);
686 const SkScalar label_text_width
=
687 label_paint
.measureText(label_text
.c_str(), label_text
.length());
688 canvas
->drawRect(SkRect::MakeWH(label_text_width
+ 2 * kPadding
,
689 kFontHeight
+ 2 * kPadding
),
692 label_paint
.setAntiAlias(true);
693 label_paint
.setColor(SkColorSetARGB(255, 50, 50, 50));
694 canvas
->drawText(label_text
.c_str(),
697 kFontHeight
* 0.8f
+ kPadding
,
707 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {
708 return "cc::HeadsUpDisplayLayerImpl";