OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #include "chrome/common/extensions/icon_transform.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkDevice.h" |
| 11 #include "third_party/skia/include/core/SkPaint.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 IconTransform::IconTransform() : alpha_(0) { |
| 16 } |
| 17 |
| 18 IconTransform::~IconTransform() { |
| 19 } |
| 20 |
| 21 const SkBitmap& IconTransform::RenderIcon(const SkBitmap& icon) { |
| 22 DCHECK_GT(icon.width(), 0); |
| 23 DCHECK_GT(icon.height(), 0); |
| 24 |
| 25 if (!device_.get() || |
| 26 (device_->width() != icon.width()) || |
| 27 (device_->height() != icon.height())) { |
| 28 device_.reset(new SkDevice( |
| 29 SkBitmap::kARGB_8888_Config, icon.width(), icon.height(), true)); |
| 30 } |
| 31 |
| 32 SkCanvas canvas(device_.get()); |
| 33 canvas.clear(0); |
| 34 SkPaint paint; |
| 35 paint.setAlpha(alpha_); |
| 36 canvas.drawBitmap(icon, 0, 0, &paint); |
| 37 return device_->accessBitmap(false); |
| 38 } |
| 39 |
| 40 } // namespace extensions |
OLD | NEW |