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 "cc/debug/debug_colors.h"
12 #include "cc/debug/debug_rect_history.h"
13 #include "cc/debug/frame_rate_counter.h"
14 #include "cc/debug/paint_time_counter.h"
15 #include "cc/debug/traced_value.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/trees/layer_tree_impl.h"
21 #include "skia/ext/platform_canvas.h"
22 #include "third_party/khronos/GLES2/gl2.h"
23 #include "third_party/khronos/GLES2/gl2ext.h"
24 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "third_party/skia/include/core/SkPaint.h"
26 #include "third_party/skia/include/core/SkTypeface.h"
27 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
28 #include "ui/gfx/point.h"
29 #include "ui/gfx/size.h"
33 static inline SkPaint
CreatePaint() {
35 #if (SK_R32_SHIFT || SK_B32_SHIFT != 16)
36 // The SkCanvas is in RGBA but the shader is expecting BGRA, so we need to
37 // swizzle our colors when drawing to the SkCanvas.
38 SkColorMatrix swizzle_matrix
;
39 for (int i
= 0; i
< 20; ++i
)
40 swizzle_matrix
.fMat
[i
] = 0;
41 swizzle_matrix
.fMat
[0 + 5 * 2] = 1;
42 swizzle_matrix
.fMat
[1 + 5 * 1] = 1;
43 swizzle_matrix
.fMat
[2 + 5 * 0] = 1;
44 swizzle_matrix
.fMat
[3 + 5 * 3] = 1;
46 skia::RefPtr
<SkColorMatrixFilter
> filter
=
47 skia::AdoptRef(new SkColorMatrixFilter(swizzle_matrix
));
48 paint
.setColorFilter(filter
.get());
53 HeadsUpDisplayLayerImpl::Graph::Graph(double indicator_value
,
54 double start_upper_bound
)
58 current_upper_bound(start_upper_bound
),
59 default_upper_bound(start_upper_bound
),
60 indicator(indicator_value
) {}
62 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() {
63 double target_upper_bound
= std::max(max
, default_upper_bound
);
64 current_upper_bound
+= (target_upper_bound
- current_upper_bound
) * 0.5;
65 return current_upper_bound
;
68 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl
* tree_impl
,
70 : LayerImpl(tree_impl
, id
),
71 typeface_(skia::AdoptRef(
72 SkTypeface::CreateFromName("monospace", SkTypeface::kBold
))),
73 fps_graph_(60.0, 80.0),
74 paint_time_graph_(16.0, 48.0) {}
76 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {}
78 scoped_ptr
<LayerImpl
> HeadsUpDisplayLayerImpl::CreateLayerImpl(
79 LayerTreeImpl
* tree_impl
) {
80 return HeadsUpDisplayLayerImpl::Create(tree_impl
, id()).PassAs
<LayerImpl
>();
83 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode
,
84 ResourceProvider
* resource_provider
) {
85 if (draw_mode
== DRAW_MODE_RESOURCELESS_SOFTWARE
)
89 hud_resource_
= ScopedResource::create(resource_provider
);
91 // TODO(danakj): The HUD could swap between two textures instead of creating a
92 // texture every frame in ubercompositor.
93 if (hud_resource_
->size() != content_bounds() ||
94 (hud_resource_
->id() &&
95 resource_provider
->InUseByConsumer(hud_resource_
->id()))) {
96 hud_resource_
->Free();
99 if (!hud_resource_
->id()) {
100 hud_resource_
->Allocate(content_bounds(),
101 ResourceProvider::TextureUsageAny
,
105 return LayerImpl::WillDraw(draw_mode
, resource_provider
);
108 void HeadsUpDisplayLayerImpl::AppendQuads(QuadSink
* quad_sink
,
109 AppendQuadsData
* append_quads_data
) {
110 if (!hud_resource_
->id())
113 SharedQuadState
* shared_quad_state
=
114 quad_sink
->UseSharedQuadState(CreateSharedQuadState());
116 gfx::Rect
quad_rect(content_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
,
134 quad_sink
->Append(quad
.PassAs
<DrawQuad
>(), append_quads_data
);
137 void HeadsUpDisplayLayerImpl::UpdateHudTexture(
139 ResourceProvider
* resource_provider
) {
140 if (draw_mode
== DRAW_MODE_RESOURCELESS_SOFTWARE
|| !hud_resource_
->id())
145 canvas_size
= hud_canvas_
->getDeviceSize();
147 canvas_size
.set(0, 0);
149 if (canvas_size
.width() != content_bounds().width() ||
150 canvas_size
.width() != content_bounds().height() || !hud_canvas_
) {
151 TRACE_EVENT0("cc", "ResizeHudCanvas");
153 hud_canvas_
= make_scoped_ptr(skia::CreateBitmapCanvas(
154 content_bounds().width(), content_bounds().height(), opaque
));
160 TRACE_EVENT0("cc", "DrawHudContents");
161 hud_canvas_
->clear(SkColorSetARGB(0, 0, 0, 0));
163 hud_canvas_
->scale(contents_scale_x(), contents_scale_y());
165 DrawHudContents(hud_canvas_
.get());
167 hud_canvas_
->restore();
170 TRACE_EVENT0("cc", "UploadHudTexture");
171 const SkBitmap
* bitmap
= &hud_canvas_
->getDevice()->accessBitmap(false);
172 SkAutoLockPixels
locker(*bitmap
);
174 gfx::Rect
content_rect(content_bounds());
175 DCHECK(bitmap
->config() == SkBitmap::kARGB_8888_Config
);
176 resource_provider
->SetPixels(hud_resource_
->id(),
177 static_cast<const uint8_t*>(bitmap
->getPixels()),
183 void HeadsUpDisplayLayerImpl::DidLoseOutputSurface() { hud_resource_
.reset(); }
185 bool HeadsUpDisplayLayerImpl::LayerIsAlwaysDamaged() const { return true; }
187 void HeadsUpDisplayLayerImpl::UpdateHudContents() {
188 const LayerTreeDebugState
& debug_state
= layer_tree_impl()->debug_state();
190 // Don't update numbers every frame so text is readable.
191 base::TimeTicks now
= layer_tree_impl()->CurrentFrameTimeTicks();
192 if (base::TimeDelta(now
- time_of_last_graph_update_
).InSecondsF() > 0.25f
) {
193 time_of_last_graph_update_
= now
;
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
);
201 if (debug_state
.continuous_painting
) {
202 PaintTimeCounter
* paint_time_counter
=
203 layer_tree_impl()->paint_time_counter();
204 base::TimeDelta latest
, min
, max
;
206 if (paint_time_counter
->End())
207 latest
= **paint_time_counter
->End();
208 paint_time_counter
->GetMinAndMaxPaintTime(&min
, &max
);
210 paint_time_graph_
.value
= latest
.InMillisecondsF();
211 paint_time_graph_
.min
= min
.InMillisecondsF();
212 paint_time_graph_
.max
= max
.InMillisecondsF();
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();
220 memory_entry_
= MemoryHistory::Entry();
224 fps_graph_
.UpdateUpperBound();
225 paint_time_graph_
.UpdateUpperBound();
228 void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas
* canvas
) const {
229 const LayerTreeDebugState
& debug_state
= layer_tree_impl()->debug_state();
231 if (debug_state
.ShowHudRects())
232 DrawDebugRects(canvas
, layer_tree_impl()->debug_rect_history());
234 SkRect area
= SkRect::MakeEmpty();
235 if (debug_state
.continuous_painting
) {
236 area
= DrawPaintTimeDisplay(
237 canvas
, layer_tree_impl()->paint_time_counter(), 0, 0);
238 } else if (debug_state
.show_fps_counter
) {
239 // Don't show the FPS display when continuous painting is enabled, because
240 // it would show misleading numbers.
242 DrawFPSDisplay(canvas
, layer_tree_impl()->frame_rate_counter(), 0, 0);
245 if (debug_state
.ShowMemoryStats())
246 DrawMemoryDisplay(canvas
, 0, area
.bottom(), SkMaxScalar(area
.width(), 150));
249 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas
* canvas
,
251 const std::string
& text
,
252 SkPaint::Align align
,
256 const bool anti_alias
= paint
->isAntiAlias();
257 paint
->setAntiAlias(true);
259 paint
->setTextSize(size
);
260 paint
->setTextAlign(align
);
261 paint
->setTypeface(typeface_
.get());
262 canvas
->drawText(text
.c_str(), text
.length(), x
, y
, *paint
);
264 paint
->setAntiAlias(anti_alias
);
267 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas
* canvas
,
269 const std::string
& text
,
270 SkPaint::Align align
,
272 const SkPoint
& pos
) const {
273 DrawText(canvas
, paint
, text
, align
, size
, pos
.x(), pos
.y());
276 void HeadsUpDisplayLayerImpl::DrawGraphBackground(SkCanvas
* canvas
,
278 const SkRect
& bounds
) const {
279 paint
->setColor(DebugColors::HUDBackgroundColor());
280 canvas
->drawRect(bounds
, *paint
);
283 void HeadsUpDisplayLayerImpl::DrawGraphLines(SkCanvas
* canvas
,
285 const SkRect
& bounds
,
286 const Graph
& graph
) const {
287 // Draw top and bottom line.
288 paint
->setColor(DebugColors::HUDSeparatorLineColor());
289 canvas
->drawLine(bounds
.left(),
295 bounds
.left(), bounds
.bottom(), bounds
.right(), bounds
.bottom(), *paint
);
297 // Draw indicator line (additive blend mode to increase contrast when drawn on
299 paint
->setColor(DebugColors::HUDIndicatorLineColor());
300 paint
->setXfermodeMode(SkXfermode::kPlus_Mode
);
301 const double indicator_top
=
302 bounds
.height() * (1.0 - graph
.indicator
/ graph
.current_upper_bound
) -
304 canvas
->drawLine(bounds
.left(),
305 bounds
.top() + indicator_top
,
307 bounds
.top() + indicator_top
,
309 paint
->setXfermode(NULL
);
312 SkRect
HeadsUpDisplayLayerImpl::DrawFPSDisplay(
314 const FrameRateCounter
* fps_counter
,
317 const int kPadding
= 4;
320 const int kFontHeight
= 15;
322 const int kGraphWidth
= fps_counter
->time_stamp_history_size() - 2;
323 const int kGraphHeight
= 40;
325 const int kHistogramWidth
= 37;
327 int width
= kGraphWidth
+ kHistogramWidth
+ 4 * kPadding
;
328 int height
= kFontHeight
+ kGraphHeight
+ 4 * kPadding
+ 2;
329 int left
= bounds().width() - width
- right
;
330 SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
332 SkPaint paint
= CreatePaint();
333 DrawGraphBackground(canvas
, &paint
, area
);
336 SkRect::MakeXYWH(left
+ kPadding
,
338 kGraphWidth
+ kHistogramWidth
+ kGap
+ 2,
340 SkRect graph_bounds
= SkRect::MakeXYWH(left
+ kPadding
,
341 text_bounds
.bottom() + 2 * kPadding
,
344 SkRect histogram_bounds
= SkRect::MakeXYWH(graph_bounds
.right() + kGap
,
349 const std::string value_text
=
350 base::StringPrintf("FPS:%5.1f", fps_graph_
.value
);
351 const std::string min_max_text
=
352 base::StringPrintf("%.0f-%.0f", fps_graph_
.min
, fps_graph_
.max
);
354 paint
.setColor(DebugColors::FPSDisplayTextAndGraphColor());
358 SkPaint::kLeft_Align
,
361 text_bounds
.bottom());
365 SkPaint::kRight_Align
,
368 text_bounds
.bottom());
370 DrawGraphLines(canvas
, &paint
, graph_bounds
, fps_graph_
);
372 // Collect graph and histogram data.
375 const int kHistogramSize
= 20;
376 double histogram
[kHistogramSize
] = { 1.0 };
377 double max_bucket_value
= 1.0;
379 for (FrameRateCounter::RingBufferType::Iterator it
= --fps_counter
->end(); it
;
381 base::TimeDelta delta
= fps_counter
->RecentFrameInterval(it
.index() + 1);
383 // Skip this particular instantaneous frame rate if it is not likely to have
385 if (!fps_counter
->IsBadFrameInterval(delta
)) {
386 double fps
= 1.0 / delta
.InSecondsF();
388 // Clamp the FPS to the range we want to plot visually.
389 double p
= fps
/ fps_graph_
.current_upper_bound
;
393 // Plot this data point.
395 SkPoint::Make(graph_bounds
.left() + it
.index(),
396 graph_bounds
.bottom() - p
* graph_bounds
.height());
402 // Use the fps value to find the right bucket in the histogram.
403 int bucket_index
= floor(p
* (kHistogramSize
- 1));
405 // Add the delta time to take the time spent at that fps rate into
407 histogram
[bucket_index
] += delta
.InSecondsF();
408 max_bucket_value
= std::max(histogram
[bucket_index
], max_bucket_value
);
412 // Draw FPS histogram.
413 paint
.setColor(DebugColors::HUDSeparatorLineColor());
414 canvas
->drawLine(histogram_bounds
.left() - 1,
415 histogram_bounds
.top() - 1,
416 histogram_bounds
.left() - 1,
417 histogram_bounds
.bottom() + 1,
419 canvas
->drawLine(histogram_bounds
.right() + 1,
420 histogram_bounds
.top() - 1,
421 histogram_bounds
.right() + 1,
422 histogram_bounds
.bottom() + 1,
425 paint
.setColor(DebugColors::FPSDisplayTextAndGraphColor());
426 const double bar_height
= histogram_bounds
.height() / kHistogramSize
;
428 for (int i
= kHistogramSize
- 1; i
>= 0; --i
) {
429 if (histogram
[i
] > 0) {
431 histogram
[i
] / max_bucket_value
* histogram_bounds
.width();
433 SkRect::MakeXYWH(histogram_bounds
.left(),
434 histogram_bounds
.bottom() - (i
+ 1) * bar_height
,
442 paint
.setAntiAlias(true);
443 paint
.setStyle(SkPaint::kStroke_Style
);
444 paint
.setStrokeWidth(1);
445 canvas
->drawPath(path
, paint
);
450 SkRect
HeadsUpDisplayLayerImpl::DrawMemoryDisplay(SkCanvas
* canvas
,
454 if (!memory_entry_
.bytes_total())
455 return SkRect::MakeEmpty();
457 const int kPadding
= 4;
458 const int kFontHeight
= 13;
460 const int height
= 3 * kFontHeight
+ 4 * kPadding
;
461 const int left
= bounds().width() - width
- right
;
462 const SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
464 const double megabyte
= 1024.0 * 1024.0;
466 SkPaint paint
= CreatePaint();
467 DrawGraphBackground(canvas
, &paint
, area
);
469 SkPoint title_pos
= SkPoint::Make(left
+ kPadding
, top
+ kFontHeight
);
470 SkPoint stat1_pos
= SkPoint::Make(left
+ width
- kPadding
- 1,
471 top
+ kPadding
+ 2 * kFontHeight
);
472 SkPoint stat2_pos
= SkPoint::Make(left
+ width
- kPadding
- 1,
473 top
+ 2 * kPadding
+ 3 * kFontHeight
);
475 paint
.setColor(DebugColors::MemoryDisplayTextColor());
479 SkPaint::kLeft_Align
,
484 base::StringPrintf("%6.1f MB used",
485 (memory_entry_
.bytes_unreleasable
+
486 memory_entry_
.bytes_allocated
) / megabyte
);
487 DrawText(canvas
, &paint
, text
, SkPaint::kRight_Align
, kFontHeight
, stat1_pos
);
489 if (memory_entry_
.bytes_over
) {
490 paint
.setColor(SK_ColorRED
);
491 text
= base::StringPrintf("%6.1f MB over",
492 memory_entry_
.bytes_over
/ megabyte
);
494 text
= base::StringPrintf("%6.1f MB max ",
495 memory_entry_
.total_budget_in_bytes
/ megabyte
);
497 DrawText(canvas
, &paint
, text
, SkPaint::kRight_Align
, kFontHeight
, stat2_pos
);
502 SkRect
HeadsUpDisplayLayerImpl::DrawPaintTimeDisplay(
504 const PaintTimeCounter
* paint_time_counter
,
507 const int kPadding
= 4;
508 const int kFontHeight
= 15;
510 const int kGraphWidth
= paint_time_counter
->HistorySize();
511 const int kGraphHeight
= 40;
513 const int width
= kGraphWidth
+ 2 * kPadding
;
515 kFontHeight
+ kGraphHeight
+ 4 * kPadding
+ 2 + kFontHeight
+ kPadding
;
516 const int left
= bounds().width() - width
- right
;
518 const SkRect area
= SkRect::MakeXYWH(left
, top
, width
, height
);
520 SkPaint paint
= CreatePaint();
521 DrawGraphBackground(canvas
, &paint
, area
);
523 SkRect text_bounds
= SkRect::MakeXYWH(
524 left
+ kPadding
, top
+ kPadding
, kGraphWidth
, kFontHeight
);
525 SkRect text_bounds2
= SkRect::MakeXYWH(left
+ kPadding
,
526 text_bounds
.bottom() + kPadding
,
529 SkRect graph_bounds
= SkRect::MakeXYWH(left
+ kPadding
,
530 text_bounds2
.bottom() + 2 * kPadding
,
534 const std::string value_text
=
535 base::StringPrintf("%.1f", paint_time_graph_
.value
);
536 const std::string min_max_text
= base::StringPrintf(
537 "%.1f-%.1f", paint_time_graph_
.min
, paint_time_graph_
.max
);
539 paint
.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
542 "Page paint time (ms)",
543 SkPaint::kLeft_Align
,
546 text_bounds
.bottom());
550 SkPaint::kLeft_Align
,
553 text_bounds2
.bottom());
557 SkPaint::kRight_Align
,
559 text_bounds2
.right(),
560 text_bounds2
.bottom());
562 paint
.setColor(DebugColors::PaintTimeDisplayTextAndGraphColor());
563 for (PaintTimeCounter::RingBufferType::Iterator it
=
564 paint_time_counter
->End();
567 double pt
= it
->InMillisecondsF();
572 double p
= pt
/ paint_time_graph_
.current_upper_bound
;
577 SkRect::MakeXYWH(graph_bounds
.left() + it
.index(),
578 graph_bounds
.bottom() - p
* graph_bounds
.height(),
580 p
* graph_bounds
.height()),
584 DrawGraphLines(canvas
, &paint
, graph_bounds
, paint_time_graph_
);
589 void HeadsUpDisplayLayerImpl::DrawDebugRects(
591 DebugRectHistory
* debug_rect_history
) const {
592 const std::vector
<DebugRect
>& debug_rects
= debug_rect_history
->debug_rects();
593 SkPaint paint
= CreatePaint();
595 for (size_t i
= 0; i
< debug_rects
.size(); ++i
) {
596 SkColor stroke_color
= 0;
597 SkColor fill_color
= 0;
598 float stroke_width
= 0.f
;
599 std::string label_text
;
601 switch (debug_rects
[i
].type
) {
602 case PAINT_RECT_TYPE
:
603 stroke_color
= DebugColors::PaintRectBorderColor();
604 fill_color
= DebugColors::PaintRectFillColor();
605 stroke_width
= DebugColors::PaintRectBorderWidth();
607 case PROPERTY_CHANGED_RECT_TYPE
:
608 stroke_color
= DebugColors::PropertyChangedRectBorderColor();
609 fill_color
= DebugColors::PropertyChangedRectFillColor();
610 stroke_width
= DebugColors::PropertyChangedRectBorderWidth();
612 case SURFACE_DAMAGE_RECT_TYPE
:
613 stroke_color
= DebugColors::SurfaceDamageRectBorderColor();
614 fill_color
= DebugColors::SurfaceDamageRectFillColor();
615 stroke_width
= DebugColors::SurfaceDamageRectBorderWidth();
617 case REPLICA_SCREEN_SPACE_RECT_TYPE
:
618 stroke_color
= DebugColors::ScreenSpaceSurfaceReplicaRectBorderColor();
619 fill_color
= DebugColors::ScreenSpaceSurfaceReplicaRectFillColor();
620 stroke_width
= DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth();
622 case SCREEN_SPACE_RECT_TYPE
:
623 stroke_color
= DebugColors::ScreenSpaceLayerRectBorderColor();
624 fill_color
= DebugColors::ScreenSpaceLayerRectFillColor();
625 stroke_width
= DebugColors::ScreenSpaceLayerRectBorderWidth();
627 case OCCLUDING_RECT_TYPE
:
628 stroke_color
= DebugColors::OccludingRectBorderColor();
629 fill_color
= DebugColors::OccludingRectFillColor();
630 stroke_width
= DebugColors::OccludingRectBorderWidth();
632 case NONOCCLUDING_RECT_TYPE
:
633 stroke_color
= DebugColors::NonOccludingRectBorderColor();
634 fill_color
= DebugColors::NonOccludingRectFillColor();
635 stroke_width
= DebugColors::NonOccludingRectBorderWidth();
637 case TOUCH_EVENT_HANDLER_RECT_TYPE
:
638 stroke_color
= DebugColors::TouchEventHandlerRectBorderColor();
639 fill_color
= DebugColors::TouchEventHandlerRectFillColor();
640 stroke_width
= DebugColors::TouchEventHandlerRectBorderWidth();
641 label_text
= "touch event listener";
643 case WHEEL_EVENT_HANDLER_RECT_TYPE
:
644 stroke_color
= DebugColors::WheelEventHandlerRectBorderColor();
645 fill_color
= DebugColors::WheelEventHandlerRectFillColor();
646 stroke_width
= DebugColors::WheelEventHandlerRectBorderWidth();
647 label_text
= "mousewheel event listener";
649 case NON_FAST_SCROLLABLE_RECT_TYPE
:
650 stroke_color
= DebugColors::NonFastScrollableRectBorderColor();
651 fill_color
= DebugColors::NonFastScrollableRectFillColor();
652 stroke_width
= DebugColors::NonFastScrollableRectBorderWidth();
653 label_text
= "repaints on scroll";
657 gfx::RectF debug_layer_rect
= gfx::ScaleRect(debug_rects
[i
].rect
,
658 1.0 / contents_scale_x(),
659 1.0 / contents_scale_y());
660 SkRect sk_rect
= RectFToSkRect(debug_layer_rect
);
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;
675 canvas
->clipRect(sk_rect
);
676 canvas
->translate(sk_rect
.x(), sk_rect
.y());
678 SkPaint label_paint
= CreatePaint();
679 label_paint
.setTextSize(kFontHeight
);
680 label_paint
.setTypeface(typeface_
.get());
681 label_paint
.setColor(stroke_color
);
683 const SkScalar label_text_width
=
684 label_paint
.measureText(label_text
.c_str(), label_text
.length());
685 canvas
->drawRect(SkRect::MakeWH(label_text_width
+ 2 * kPadding
,
686 kFontHeight
+ 2 * kPadding
),
689 label_paint
.setAntiAlias(true);
690 label_paint
.setColor(SkColorSetARGB(255, 50, 50, 50));
691 canvas
->drawText(label_text
.c_str(),
694 kFontHeight
* 0.8f
+ kPadding
,
702 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {
703 return "cc::HeadsUpDisplayLayerImpl";