diff options
author | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 21:30:12 +0000 |
---|---|---|
committer | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 21:30:12 +0000 |
commit | 35d53343ae436c2190670b0686fdbbba240d7155 (patch) | |
tree | 7dc826260d6a6ab4080042575c4ba473a4307085 /chrome/browser | |
parent | 3d841611c4344e1026491602d21d024957cda690 (diff) | |
download | chromium_src-35d53343ae436c2190670b0686fdbbba240d7155.zip chromium_src-35d53343ae436c2190670b0686fdbbba240d7155.tar.gz chromium_src-35d53343ae436c2190670b0686fdbbba240d7155.tar.bz2 |
This patch makes ImageSkia more like SkBitmap. The goal is to make swapping from SkBitmap to ImageSkia easier.
Notable changes:
- ImageSkia can be cheaply copied
- Added extractSubset, will remove after SkBitmaps have been converted to ImageSkia
- Modified API to look more like SkBitmap
Review URL: https://chromiumcodereview.appspot.com/10245003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 32 insertions, 30 deletions
diff --git a/chrome/browser/extensions/image_loading_tracker.cc b/chrome/browser/extensions/image_loading_tracker.cc index 3bbf4334e..ab43b06 100644 --- a/chrome/browser/extensions/image_loading_tracker.cc +++ b/chrome/browser/extensions/image_loading_tracker.cc @@ -18,6 +18,7 @@ #include "skia/ext/image_operations.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/image/image.h" +#include "ui/gfx/image/image_skia.h" #include "webkit/glue/image_decoder.h" using content::BrowserThread; @@ -303,13 +304,13 @@ void ImageLoadingTracker::OnImageLoaded( std::string extension_id = info->extension_id; if (info->bitmaps.size() > 0) { - std::vector<const SkBitmap*> bitmaps; + gfx::ImageSkia image_skia; for (std::vector<SkBitmap>::const_iterator it = info->bitmaps.begin(); it != info->bitmaps.end(); ++it) { - // gfx::Image takes ownership of this bitmap. - bitmaps.push_back(new SkBitmap(*it)); + // TODO(pkotwicz): Do something better but ONLY when ENABLE_DIP. + image_skia.AddBitmapForScale(*it, 1.0f); } - image = gfx::Image(bitmaps); + image = gfx::Image(image_skia); } load_map_.erase(load_map_it); diff --git a/chrome/browser/extensions/image_loading_tracker_unittest.cc b/chrome/browser/extensions/image_loading_tracker_unittest.cc index 4306936..edbbcee 100644 --- a/chrome/browser/extensions/image_loading_tracker_unittest.cc +++ b/chrome/browser/extensions/image_loading_tracker_unittest.cc @@ -218,11 +218,10 @@ TEST_F(ImageLoadingTrackerTest, MultipleImages) { EXPECT_EQ(1, image_loaded_count()); // Check that all images were loaded. - const std::vector<const SkBitmap*>& bitmaps = - image_.ToImageSkia()->bitmaps(); + const std::vector<SkBitmap> bitmaps = image_.ToImageSkia()->bitmaps(); ASSERT_EQ(2u, bitmaps.size()); - const SkBitmap* bmp1 = bitmaps[0]; - const SkBitmap* bmp2 = bitmaps[1]; + const SkBitmap* bmp1 = &bitmaps[0]; + const SkBitmap* bmp2 = &bitmaps[1]; if (bmp1->width() > bmp2->width()) { std::swap(bmp1, bmp2); } diff --git a/chrome/browser/themes/browser_theme_pack.cc b/chrome/browser/themes/browser_theme_pack.cc index 0ae0895..b5f17eb 100644 --- a/chrome/browser/themes/browser_theme_pack.cc +++ b/chrome/browser/themes/browser_theme_pack.cc @@ -311,15 +311,18 @@ base::RefCountedMemory* ReadFileData(const FilePath& path) { // the returned image. gfx::Image* CreateHSLShiftedImage(const gfx::Image& image, const color_utils::HSL& hsl_shift) { - const std::vector<const SkBitmap*>& src_bitmaps = - image.ToImageSkia()->bitmaps(); - std::vector<const SkBitmap*> dst_bitmaps; + const gfx::ImageSkia* src_image = image.ToImageSkia(); + const std::vector<SkBitmap> src_bitmaps = src_image->bitmaps(); + gfx::ImageSkia dst_image; for (size_t i = 0; i < src_bitmaps.size(); ++i) { - const SkBitmap* bitmap = src_bitmaps[i]; - dst_bitmaps.push_back(new SkBitmap( - SkBitmapOperations::CreateHSLShiftedBitmap(*bitmap, hsl_shift))); + const SkBitmap& bitmap = src_bitmaps[i]; + float scale_factor = + static_cast<float>(bitmap.width()) / src_image->width(); + dst_image.AddBitmapForScale( + SkBitmapOperations::CreateHSLShiftedBitmap(bitmap, hsl_shift), + scale_factor); } - return new gfx::Image(dst_bitmaps); + return new gfx::Image(dst_image); } } // namespace @@ -992,32 +995,32 @@ void BrowserThemePack::GenerateTabBackgroundImages(ImageCache* bitmaps) const { // with a PRS_THEME_FRAME. ImageCache::const_iterator it = bitmaps->find(prs_base_id); if (it != bitmaps->end()) { - const gfx::Image& image_to_tint = *(it->second); - const std::vector<const SkBitmap*>& bitmaps_to_tint = - image_to_tint.ToImageSkia()->bitmaps(); - std::vector<const SkBitmap*> tinted_bitmaps; + const gfx::ImageSkia* image_to_tint = (it->second)->ToImageSkia(); + const std::vector<SkBitmap> bitmaps_to_tint = image_to_tint->bitmaps(); + gfx::ImageSkia tinted_image; for (size_t j = 0; j < bitmaps_to_tint.size(); ++j) { SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( - *bitmaps_to_tint[j], GetTintInternal( + bitmaps_to_tint[j], GetTintInternal( ThemeService::TINT_BACKGROUND_TAB)); int vertical_offset = bitmaps->count(prs_id) ? kRestoredTabVerticalOffset : 0; - SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap( - bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height())); + SkBitmap bg_tab = SkBitmapOperations::CreateTiledBitmap( + bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height()); // If they've provided a custom image, overlay it. ImageCache::const_iterator overlay_it = bitmaps->find(prs_id); if (overlay_it != bitmaps->end()) { const SkBitmap* overlay = overlay_it->second->ToSkBitmap(); - SkCanvas canvas(*bg_tab); - for (int x = 0; x < bg_tab->width(); x += overlay->width()) + SkCanvas canvas(bg_tab); + for (int x = 0; x < bg_tab.width(); x += overlay->width()) canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); } - tinted_bitmaps.push_back(bg_tab); + float scale_factor = + static_cast<float>(bg_tab.width()) / image_to_tint->width(); + tinted_image.AddBitmapForScale(bg_tab, scale_factor); } - gfx::Image* tinted_image = new gfx::Image(tinted_bitmaps); - temp_output[prs_id] = tinted_image; + temp_output[prs_id] = new gfx::Image(tinted_image); } } diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm index bcc7991..46ce5f5 100644 --- a/chrome/browser/web_applications/web_app_mac.mm +++ b/chrome/browser/web_applications/web_app_mac.mm @@ -198,10 +198,9 @@ bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); bool image_added = false; - const std::vector<const SkBitmap*>& bitmaps = - info_.favicon.ToImageSkia()->bitmaps(); + const std::vector<SkBitmap> bitmaps = info_.favicon.ToImageSkia()->bitmaps(); for (size_t i = 0; i < bitmaps.size(); ++i) { - NSBitmapImageRep* image_rep = SkBitmapToImageRep(*bitmaps[i]); + NSBitmapImageRep* image_rep = SkBitmapToImageRep(bitmaps[i]); if (!image_rep) continue; |