Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: chrome/browser/chromeos/status/network_menu_icon.cc

Issue 10704199: Implement remaining SkBitmapOperations as ImageSkiaOperations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/status/network_menu_icon.cc
diff --git a/chrome/browser/chromeos/status/network_menu_icon.cc b/chrome/browser/chromeos/status/network_menu_icon.cc
index fb2b819bff97b2632573ce122a75696d97c6f89f..0efa3e41bff0bf158fb57acd0f52609c2fcd31df 100644
--- a/chrome/browser/chromeos/status/network_menu_icon.cc
+++ b/chrome/browser/chromeos/status/network_menu_icon.cc
@@ -17,8 +17,8 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/image/image_skia_source.h"
-#include "ui/gfx/skbitmap_operations.h"
using std::max;
using std::min;
@@ -158,12 +158,12 @@ const gfx::ImageSkia* BadgeForNetworkTechnology(
return ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id);
}
-const SkBitmap GetEmptyBitmapOfSameSize(const gfx::ImageSkiaRep& reference) {
+const SkBitmap GetEmptyBitmap(const gfx::Size pixel_size) {
typedef std::pair<int, int> SizeKey;
typedef std::map<SizeKey, SkBitmap> SizeBitmapMap;
static SizeBitmapMap* empty_bitmaps_ = new SizeBitmapMap;
- SizeKey key(reference.pixel_width(), reference.pixel_height());
+ SizeKey key(pixel_size.width(), pixel_size.height());
SizeBitmapMap::iterator iter = empty_bitmaps_->find(key);
if (iter != empty_bitmaps_->end())
@@ -177,28 +177,22 @@ const SkBitmap GetEmptyBitmapOfSameSize(const gfx::ImageSkiaRep& reference) {
return empty;
}
-class FadedImageSource : public gfx::ImageSkiaSource {
+class EmptyImageSource: public gfx::ImageSkiaSource {
public:
- FadedImageSource(const gfx::ImageSkia& source, double alpha)
- : source_(source),
- alpha_(alpha) {
+ EmptyImageSource(const gfx::Size& size)
+ : size_(size) {
}
- virtual ~FadedImageSource() {}
virtual gfx::ImageSkiaRep GetImageForScale(
ui::ScaleFactor scale_factor) OVERRIDE {
- gfx::ImageSkiaRep image_rep = source_.GetRepresentation(scale_factor);
- const SkBitmap empty_bitmap = GetEmptyBitmapOfSameSize(image_rep);
- SkBitmap faded_bitmap = SkBitmapOperations::CreateBlendedBitmap(
- empty_bitmap, image_rep.sk_bitmap(), alpha_);
- return gfx::ImageSkiaRep(faded_bitmap, image_rep.scale_factor());
+ gfx::Size pixel_size = size_.Scale(ui::GetScaleFactorScale(scale_factor));
+ SkBitmap empty_bitmap = GetEmptyBitmap(pixel_size);
+ return gfx::ImageSkiaRep(empty_bitmap, scale_factor);
}
-
private:
- const gfx::ImageSkia source_;
- const float alpha_;
+ const gfx::Size size_;
- DISALLOW_COPY_AND_ASSIGN(FadedImageSource);
+ DISALLOW_COPY_AND_ASSIGN(EmptyImageSource);
};
// This defines how we assemble a network icon.
@@ -252,74 +246,6 @@ class NetworkIconImageSource : public gfx::ImageSkiaSource {
DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource);
};
-// This defines how we assemble a network menu icon.
-class NetworkMenuIconSource : public gfx::ImageSkiaSource {
- public:
- NetworkMenuIconSource(NetworkMenuIcon::ImageType type,
- int index,
- NetworkMenuIcon::ResourceColorTheme color)
- : type_(type),
- index_(index),
- color_(color) {
- }
- virtual ~NetworkMenuIconSource() {}
-
- virtual gfx::ImageSkiaRep GetImageForScale(
- ui::ScaleFactor scale_factor) OVERRIDE {
- int width, height;
- gfx::ImageSkia* images;
- if (type_ == NetworkMenuIcon::ARCS) {
- if (index_ >= kNumArcsImages)
- return gfx::ImageSkiaRep();
- images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- color_ == NetworkMenuIcon::COLOR_DARK ?
- IDR_STATUSBAR_NETWORK_ARCS_DARK : IDR_STATUSBAR_NETWORK_ARCS_LIGHT);
- width = images->width();
- height = images->height() / kNumArcsImages;
- } else {
- if (index_ >= kNumBarsImages)
- return gfx::ImageSkiaRep();
-
- images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- color_ == NetworkMenuIcon::COLOR_DARK ?
- IDR_STATUSBAR_NETWORK_BARS_DARK : IDR_STATUSBAR_NETWORK_BARS_LIGHT);
- width = images->width();
- height = images->height() / kNumBarsImages;
- }
- gfx::ImageSkiaRep image_rep = images->GetRepresentation(scale_factor);
-
- float scale = ui::GetScaleFactorScale(image_rep.scale_factor());
- height *= scale;
- width *= scale;
-
- SkIRect subset = SkIRect::MakeXYWH(0, index_ * height, width, height);
-
- SkBitmap dst_bitmap;
- image_rep.sk_bitmap().extractSubset(&dst_bitmap, subset);
- return gfx::ImageSkiaRep(dst_bitmap, image_rep.scale_factor());
- }
-
- gfx::Size size() const {
- // NeworkMenuIcons all have the same size in DIP for arc/bars.
- if (type_ == NetworkMenuIcon::ARCS) {
- gfx::Size size = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_STATUSBAR_NETWORK_ARCS_DARK)->size();
- return gfx::Size(size.width(), size.height() / kNumArcsImages);
- } else {
- gfx::Size size = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_STATUSBAR_NETWORK_BARS_DARK)->size();
- return gfx::Size(size.width(), size.height() / kNumBarsImages);
- }
- }
-
- private:
- const NetworkMenuIcon::ImageType type_;
- const int index_;
- const NetworkMenuIcon::ResourceColorTheme color_;
-
- DISALLOW_COPY_AND_ASSIGN(NetworkMenuIconSource);
-};
-
gfx::ImageSkia CreateVpnImage() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const gfx::ImageSkia* ethernet_icon = rb.GetImageSkiaNamed(IDR_STATUSBAR_VPN);
@@ -328,6 +254,10 @@ gfx::ImageSkia CreateVpnImage() {
*ethernet_icon, NULL, NULL, vpn_badge, NULL);
}
+gfx::ImageSkia GetEmptyImage(const gfx::Size& size) {
+ return gfx::ImageSkia(new EmptyImageSource(size), size);
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -833,8 +763,8 @@ void NetworkMenuIcon::SetActiveNetworkIconAndText(const Network* network) {
// Even though this is the only place we use vpn_connecting_badge_,
// it is important that this is a member variable since we set a
// pointer to it and access that pointer in icon_->GenerateImage().
- vpn_connecting_badge_ = gfx::ImageSkia(
- new FadedImageSource(*vpn_badge, animation), vpn_badge->size());
+ vpn_connecting_badge_ = gfx::ImageSkiaOperations::CreateBlendedImage(
+ GetEmptyImage(vpn_badge->size()), *vpn_badge, animation);
icon_->set_bottom_left_badge(&vpn_connecting_badge_);
}
}
@@ -910,8 +840,8 @@ const gfx::ImageSkia NetworkMenuIcon::GenerateImageFromComponents(
// We blend connecting icons with a black image to generate a faded icon.
const gfx::ImageSkia NetworkMenuIcon::GenerateConnectingImage(
const gfx::ImageSkia& source) {
- return gfx::ImageSkia(new FadedImageSource(source, kConnectingImageAlpha),
- source.size());
+ return gfx::ImageSkiaOperations::CreateBlendedImage(
+ GetEmptyImage(source.size()), source, kConnectingImageAlpha);
}
// Generates and caches an icon image for a network's current state.
@@ -955,8 +885,28 @@ const gfx::ImageSkia NetworkMenuIcon::GetVpnImage() {
const gfx::ImageSkia NetworkMenuIcon::GetImage(ImageType type,
int index,
ResourceColorTheme color) {
- NetworkMenuIconSource* source = new NetworkMenuIconSource(type, index, color);
- return gfx::ImageSkia(source, source->size());
+ int width, height;
sky 2012/07/20 23:21:25 nit: initialize these (and images) just in case.
+ gfx::ImageSkia* images;
+ if (type == NetworkMenuIcon::ARCS) {
+ if (index >= kNumArcsImages)
+ return gfx::ImageSkia();
+ images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ color == NetworkMenuIcon::COLOR_DARK ?
+ IDR_STATUSBAR_NETWORK_ARCS_DARK : IDR_STATUSBAR_NETWORK_ARCS_LIGHT);
+ width = images->width();
+ height = images->height() / kNumArcsImages;
+ } else {
+ if (index >= kNumBarsImages)
+ return gfx::ImageSkia();
+
+ images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ color == NetworkMenuIcon::COLOR_DARK ?
+ IDR_STATUSBAR_NETWORK_BARS_DARK : IDR_STATUSBAR_NETWORK_BARS_LIGHT);
+ width = images->width();
+ height = images->height() / kNumBarsImages;
+ }
+ return gfx::ImageSkiaOperations::ExtractSubset(*images,
+ gfx::Rect(0, index * height, width, height));
}
const gfx::ImageSkia NetworkMenuIcon::GetDisconnectedImage(

Powered by Google App Engine
This is Rietveld 408576698