1 // Copyright 2013 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 "ui/app_list/views/cached_label.h"
7 #include "base/profiler/scoped_tracker.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/base/layout.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/views/widget/widget.h"
15 CachedLabel::CachedLabel()
16 : needs_repaint_(true) {
19 void CachedLabel::PaintToBackingImage() {
20 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
21 tracked_objects::ScopedTracker
tracking_profile1(
22 FROM_HERE_WITH_EXPLICIT_FUNCTION(
23 "431326 CachedLabel::PaintToBackingImage1"));
25 if (image_
.size() == size() && !needs_repaint_
)
28 bool is_opaque
= SkColorGetA(background_color()) == 0xFF;
30 ui::GetScaleFactorForNativeView(GetWidget()->GetNativeView());
31 gfx::Canvas
canvas(size(), scale_factor
, is_opaque
);
32 // If a background is provided, it will initialize the canvas in
33 // View::OnPaintBackground(). Otherwise, the background must be set here.
35 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
36 tracked_objects::ScopedTracker
tracking_profile2(
37 FROM_HERE_WITH_EXPLICIT_FUNCTION(
38 "431326 CachedLabel::PaintToBackingImage2"));
41 GetLocalBounds(), background_color(), SkXfermode::kSrc_Mode
);
44 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
45 tracked_objects::ScopedTracker
tracking_profile3(
46 FROM_HERE_WITH_EXPLICIT_FUNCTION(
47 "431326 CachedLabel::PaintToBackingImage3"));
49 Label::OnPaint(&canvas
);
51 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
52 tracked_objects::ScopedTracker
tracking_profile4(
53 FROM_HERE_WITH_EXPLICIT_FUNCTION(
54 "431326 CachedLabel::PaintToBackingImage4"));
56 image_
= gfx::ImageSkia(canvas
.ExtractImageRep());
57 needs_repaint_
= false;
61 void CachedLabel::OnPaint(gfx::Canvas
* canvas
) {
62 PaintToBackingImage();
63 canvas
->DrawImageInt(image_
, 0, 0);
67 void CachedLabel::OnDeviceScaleFactorChanged(
68 float device_scale_factor
) {
70 View::OnDeviceScaleFactorChanged(device_scale_factor
);
73 } // namespace app_list