Index: chrome/common/extensions/icon_transform.cc |
diff --git a/chrome/common/extensions/icon_transform.cc b/chrome/common/extensions/icon_transform.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7c45136e181c9c9f9d65fc1f55a08a9a6c91139a |
--- /dev/null |
+++ b/chrome/common/extensions/icon_transform.cc |
@@ -0,0 +1,40 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/common/extensions/icon_transform.h" |
+ |
+#include "base/logging.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "third_party/skia/include/core/SkCanvas.h" |
+#include "third_party/skia/include/core/SkDevice.h" |
+#include "third_party/skia/include/core/SkPaint.h" |
+ |
+namespace extensions { |
+ |
+IconTransform::IconTransform() : alpha_(0) { |
+} |
+ |
+IconTransform::~IconTransform() { |
+} |
+ |
+const SkBitmap& IconTransform::RenderIcon(const SkBitmap& icon) { |
+ DCHECK_GT(icon.width(), 0); |
+ DCHECK_GT(icon.height(), 0); |
+ |
+ if (!device_.get() || |
+ (device_->width() != icon.width()) || |
+ (device_->height() != icon.height())) { |
+ device_.reset(new SkDevice( |
+ SkBitmap::kARGB_8888_Config, icon.width(), icon.height(), true)); |
+ } |
+ |
+ SkCanvas canvas(device_.get()); |
+ canvas.clear(0); |
+ SkPaint paint; |
+ paint.setAlpha(alpha_); |
+ canvas.drawBitmap(icon, 0, 0, &paint); |
+ return device_->accessBitmap(false); |
+} |
+ |
+} // namespace extensions |