Performance histograms for extension content verification
[chromium-blink-merge.git] / ui / app_list / views / cached_label.cc
blobea289f3008120b40426615095428c5c1c995fc4b
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/strings/utf_string_conversions.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h"
11 namespace app_list {
13 CachedLabel::CachedLabel()
14 : needs_repaint_(true) {
17 void CachedLabel::PaintToBackingImage() {
18 if (image_.size() == size() && !needs_repaint_)
19 return;
21 bool is_opaque = SkColorGetA(background_color()) == 0xFF;
22 gfx::Canvas canvas(size(), 1.0f, is_opaque);
23 // If a background is provided, it will initialize the canvas in
24 // View::OnPaintBackground(). Otherwise, the background must be set here.
25 if (!background()) {
26 canvas.FillRect(
27 GetLocalBounds(), background_color(), SkXfermode::kSrc_Mode);
29 Label::OnPaint(&canvas);
30 image_ = gfx::ImageSkia(canvas.ExtractImageRep());
31 needs_repaint_ = false;
34 #if defined(OS_WIN)
35 void CachedLabel::OnPaint(gfx::Canvas* canvas) {
36 PaintToBackingImage();
37 canvas->DrawImageInt(image_, 0, 0);
39 #endif
41 } // namespace app_list