diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-29 03:46:27 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-29 03:46:27 +0000 |
commit | 2b8ac34229b953d763712d038eb52bb989e52568 (patch) | |
tree | c3d2b10983efee188778bb43a3d7f2d7f284c31b /chrome | |
parent | d5f6d64a34f875835b5750a54524df9502fb6f68 (diff) | |
download | chromium_src-2b8ac34229b953d763712d038eb52bb989e52568.zip chromium_src-2b8ac34229b953d763712d038eb52bb989e52568.tar.gz chromium_src-2b8ac34229b953d763712d038eb52bb989e52568.tar.bz2 |
Load 2x resources on demand
Currently, this always load 1x. This will be fixed in follow up CL to use currently used scale factor.
* Added thread check to ImageSkiaStorage using NonThreadSafe.
This is important as GetRepresentation may change the stage
now even for the Image obtained from ResourceBundle.
* Added SetReadOnly to protect read only resources (ones in ResourceBundle) from being modified by accident.
* Addded MakeThreadSafe to guarantee that it can be safely accessed from multiple threads.
BUG=141351,144367
TEST=covered by tests. Also run with --force-device-scale-factor=2 and --load-2x-resources and make sure chrome still uses 2x resources where available.
Review URL: https://chromiumcodereview.appspot.com/10820049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153846 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/login/user_image_loader.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wallpaper_manager.cc | 26 | ||||
-rw-r--r-- | chrome/browser/extensions/image_loading_tracker.cc | 4 | ||||
-rw-r--r-- | chrome/browser/icon_loader_chromeos.cc | 8 | ||||
-rw-r--r-- | chrome/browser/icon_loader_linux.cc | 5 | ||||
-rw-r--r-- | chrome/browser/icon_loader_mac.mm | 4 | ||||
-rw-r--r-- | chrome/browser/icon_loader_win.cc | 5 | ||||
-rw-r--r-- | chrome/browser/themes/browser_theme_pack.cc | 49 | ||||
-rw-r--r-- | chrome/browser/themes/browser_theme_pack.h | 4 | ||||
-rw-r--r-- | chrome/browser/ui/app_list/extension_app_item.cc | 13 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac.mm | 3 |
11 files changed, 45 insertions, 81 deletions
diff --git a/chrome/browser/chromeos/login/user_image_loader.cc b/chrome/browser/chromeos/login/user_image_loader.cc index 45f8228..da34f7d 100644 --- a/chrome/browser/chromeos/login/user_image_loader.cc +++ b/chrome/browser/chromeos/login/user_image_loader.cc @@ -92,11 +92,12 @@ void UserImageLoader::OnImageDecoded(const ImageDecoder* decoder, final_image = cropped_image; } } - + gfx::ImageSkia final_image_skia(final_image); + final_image_skia.MakeThreadSafe(); target_message_loop_->PostTask( FROM_HERE, base::Bind(image_info.loaded_cb, - UserImage(final_image, decoder->get_image_data()))); + UserImage(final_image_skia, decoder->get_image_data()))); image_info_map_.erase(info_it); } diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc index 4f9351f..dafb1b0 100644 --- a/chrome/browser/chromeos/login/wallpaper_manager.cc +++ b/chrome/browser/chromeos/login/wallpaper_manager.cc @@ -76,27 +76,10 @@ gfx::ImageSkia GetWallpaperThumbnail(const gfx::ImageSkia& wallpaper) { skia::ImageOperations::RESIZE_LANCZOS3, gfx::Size(kThumbnailWidth, kThumbnailHeight)); - // Ideally, this would call thumbnail.GetRepresentations(). But since that - // isn't exposed on non-mac yet, we have to do this here. - std::vector<ui::ScaleFactor> scales = ui::GetSupportedScaleFactors(); - for (size_t i = 0; i < scales.size(); ++i) { - if (wallpaper.HasRepresentation(scales[i])) - thumbnail.GetRepresentation(scales[i]); - } - + thumbnail.MakeThreadSafe(); return thumbnail; } -gfx::ImageSkia ImageSkiaDeepCopy(const gfx::ImageSkia& image) { - gfx::ImageSkia copy; - std::vector<gfx::ImageSkiaRep> reps = image.image_reps(); - for (std::vector<gfx::ImageSkiaRep>::iterator iter = reps.begin(); - iter != reps.end(); ++iter) { - copy.AddRepresentation(*iter); - } - return copy; -} - } // namespace namespace chromeos { @@ -205,7 +188,7 @@ gfx::ImageSkia WallpaperManager::GetCustomWallpaperThumbnail( const std::string& email) { CustomWallpaperMap::const_iterator it = custom_wallpaper_thumbnail_cache_.find(email); - if (it != wallpaper_cache_.end()) + if (it != custom_wallpaper_thumbnail_cache_.end()) return (*it).second; else return gfx::ImageSkia(); @@ -626,7 +609,7 @@ void WallpaperManager::CacheWallpaper(const std::string& email, FROM_HERE, base::Bind(&WallpaperManager::CacheThumbnail, base::Unretained(this), email, - ImageSkiaDeepCopy(wallpaper.image()))); + wallpaper.image().DeepCopy())); wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); } @@ -668,8 +651,7 @@ void WallpaperManager::FetchWallpaper(const std::string& email, FROM_HERE, base::Bind(&WallpaperManager::CacheThumbnail, base::Unretained(this), email, - ImageSkiaDeepCopy(wallpaper.image()))); - + wallpaper.image().DeepCopy())); wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); ash::Shell::GetInstance()->desktop_background_controller()-> SetCustomWallpaper(wallpaper.image(), layout); diff --git a/chrome/browser/extensions/image_loading_tracker.cc b/chrome/browser/extensions/image_loading_tracker.cc index 7e620e6..e6c8891 100644 --- a/chrome/browser/extensions/image_loading_tracker.cc +++ b/chrome/browser/extensions/image_loading_tracker.cc @@ -372,8 +372,10 @@ void ImageLoadingTracker::OnBitmapLoaded( gfx::Image image; std::string extension_id = info->extension_id; - if (!info->image_skia.isNull()) + if (!info->image_skia.isNull()) { + info->image_skia.MakeThreadSafe(); image = gfx::Image(info->image_skia); + } load_map_.erase(load_map_it); diff --git a/chrome/browser/icon_loader_chromeos.cc b/chrome/browser/icon_loader_chromeos.cc index e967e4e5..b8680be 100644 --- a/chrome/browser/icon_loader_chromeos.cc +++ b/chrome/browser/icon_loader_chromeos.cc @@ -20,6 +20,7 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/image/image.h" +#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia_operations.h" #include "webkit/glue/image_decoder.h" @@ -181,9 +182,10 @@ void IconLoader::ReadIcon() { LAZY_INSTANCE_INITIALIZER; int idr = icon_mapper.Get().Lookup(group_, icon_size_); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - const gfx::ImageSkia* image_skia = rb.GetImageNamed(idr).ToImageSkia(); - image_.reset(new gfx::Image( - ResizeImage(*image_skia, IconSizeToDIPSize(icon_size_)))); + gfx::ImageSkia image_skia(ResizeImage(*(rb.GetImageNamed(idr)).ToImageSkia(), + IconSizeToDIPSize(icon_size_))); + image_skia.MakeThreadSafe(); + image_.reset(new gfx::Image(image_skia)); target_message_loop_->PostTask( FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); } diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc index f0bb1e6..f5e9c22 100644 --- a/chrome/browser/icon_loader_linux.cc +++ b/chrome/browser/icon_loader_linux.cc @@ -12,6 +12,7 @@ #include "base/message_loop.h" #include "base/nix/mime_util_xdg.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/image/image_skia.h" #include "webkit/glue/image_decoder.h" using std::string; @@ -47,7 +48,9 @@ void IconLoader::ReadIcon() { if (!bitmap.empty()) { DCHECK_EQ(size_pixels, bitmap.width()); DCHECK_EQ(size_pixels, bitmap.height()); - image_.reset(new gfx::Image(bitmap)); + gfx::ImageSkia image_skia(bitmap); + image_skia.MakeThreadSafe(); + image_.reset(new gfx::Image(image_skia)); } else { LOG(WARNING) << "Unsupported file type or load error: " << filename.value(); diff --git a/chrome/browser/icon_loader_mac.mm b/chrome/browser/icon_loader_mac.mm index 7ec09ac..7313a69 100644 --- a/chrome/browser/icon_loader_mac.mm +++ b/chrome/browser/icon_loader_mac.mm @@ -33,7 +33,9 @@ void IconLoader::ReadIcon() { default: NOTREACHED(); } - image_.reset(new gfx::Image(gfx::ImageSkiaFromResizedNSImage(icon, size))); + gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size)); + image_skia.MakeThreadSafe(); + image_.reset(new gfx::Image(image_skia)); } target_message_loop_->PostTask(FROM_HERE, diff --git a/chrome/browser/icon_loader_win.cc b/chrome/browser/icon_loader_win.cc index 26c39fa..48e565f 100644 --- a/chrome/browser/icon_loader_win.cc +++ b/chrome/browser/icon_loader_win.cc @@ -12,6 +12,7 @@ #include "base/threading/thread.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/icon_util.h" +#include "ui/gfx/image/image_skia.h" #include "ui/gfx/size.h" void IconLoader::ReadIcon() { @@ -37,7 +38,9 @@ void IconLoader::ReadIcon() { scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON( file_info.hIcon)); - image_.reset(new gfx::Image(*bitmap)); + gfx::ImageSkia image_skia(*bitmap); + image_skia.MakeThreadSafe(); + image_.reset(new gfx::Image(image_skia)); DestroyIcon(file_info.hIcon); target_message_loop_->PostTask(FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); diff --git a/chrome/browser/themes/browser_theme_pack.cc b/chrome/browser/themes/browser_theme_pack.cc index a2672f7..c470ebd 100644 --- a/chrome/browser/themes/browser_theme_pack.cc +++ b/chrome/browser/themes/browser_theme_pack.cc @@ -436,11 +436,14 @@ scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromExtension( pack->CreateImages(&pack->images_on_ui_thread_); pack->CreateImages(&pack->images_on_file_thread_); - // For M22, as it is not possible to easily determine which scale factors are - // in use, assume that the 1x scale factor is in use. - std::vector<ui::ScaleFactor> scale_factors_in_use; - scale_factors_in_use.push_back(ui::SCALE_FACTOR_100P); - pack->GenerateImageReps(scale_factors_in_use); + // Make sure the |images_on_file_thread_| has bitmaps for supported + // scale factors before passing to FILE thread. + for (ImageCache::iterator it = pack->images_on_file_thread_.begin(); + it != pack->images_on_file_thread_.end(); ++it) { + gfx::ImageSkia* image_skia = + const_cast<gfx::ImageSkia*>(it->second->ToImageSkia()); + image_skia->MakeThreadSafe(); + } // The BrowserThemePack is now in a consistent state. return pack; @@ -1117,14 +1120,6 @@ void BrowserThemePack::RepackImages(const ImageCache& images, it != images.end(); ++it) { gfx::ImageSkia image_skia = *it->second->ToImageSkia(); - // Attempt to generate image reps for all supported scale factors. - for (ScaleFactors::const_iterator factor_it = scale_factors_.begin(); - factor_it != scale_factors_.end(); ++factor_it) { - // Ask for representation to force the representation to be generated - // if it wasn't already. - image_skia.GetRepresentation(*factor_it); - } - typedef std::vector<gfx::ImageSkiaRep> ImageSkiaReps; ImageSkiaReps image_reps = image_skia.image_reps(); if (image_reps.empty()) { @@ -1145,34 +1140,6 @@ void BrowserThemePack::RepackImages(const ImageCache& images, } } -void BrowserThemePack::GenerateImageReps( - const std::vector<ui::ScaleFactor>& scale_factors) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - for (ImageCache::const_iterator it = images_on_ui_thread_.begin(); - it != images_on_ui_thread_.end(); - ++it) { - const gfx::ImageSkia* image1 = it->second->ToImageSkia(); - const gfx::ImageSkia* image2 = - images_on_file_thread_[it->first]->ToImageSkia(); - - // Ensure that image reps are generated and cached in |image1| by - // calling GetRepresentation(). - for (size_t i = 0; i < scale_factors.size(); ++i) - image1->GetRepresentation(scale_factors[i]); - - // |image1| and |image2| have ImageSkiaSources which produce pixel - // equivalent output. Instead of regenerating again, copy the image reps - // which were generated for |image1| into |image2|. - // Don't do a deep copy of the SkBitmaps as SkBitmap is thread safe. - std::vector<gfx::ImageSkiaRep> image1_reps = image1->image_reps(); - for (size_t i = 0; i < image1_reps.size(); ++i) { - gfx::ImageSkiaRep image1_rep = image1_reps[i]; - const_cast<gfx::ImageSkia*>(image2)->AddRepresentation(gfx::ImageSkiaRep( - image1_rep.sk_bitmap(), image1_rep.scale_factor())); - } - } -} - void BrowserThemePack::MergeImageCaches( const ImageCache& source, ImageCache* destination) const { for (ImageCache::const_iterator it = source.begin(); it != source.end(); diff --git a/chrome/browser/themes/browser_theme_pack.h b/chrome/browser/themes/browser_theme_pack.h index d82d44d..ea9ccc6 100644 --- a/chrome/browser/themes/browser_theme_pack.h +++ b/chrome/browser/themes/browser_theme_pack.h @@ -181,10 +181,6 @@ class BrowserThemePack : public base::RefCountedThreadSafe< void RepackImages(const ImageCache& images, RawImages* reencoded_images) const; - // Generates image reps for |scale_factors| for - // |prepared_images_on_ui_thread_| and |prepared_images_on_file_thread_|. - void GenerateImageReps(const std::vector<ui::ScaleFactor>& scale_factors); - // Takes all images in |source| and puts them in |destination|, freeing any // image already in |destination| that |source| would overwrite. void MergeImageCaches(const ImageCache& source, diff --git a/chrome/browser/ui/app_list/extension_app_item.cc b/chrome/browser/ui/app_list/extension_app_item.cc index 1dedf03..079973f 100644 --- a/chrome/browser/ui/app_list/extension_app_item.cc +++ b/chrome/browser/ui/app_list/extension_app_item.cc @@ -181,10 +181,15 @@ void ExtensionAppItem::StartExtensionUninstall() { void ExtensionAppItem::OnImageLoaded(const gfx::Image& image, const std::string& extension_id, int tracker_index) { - if (!image.IsEmpty()) - SetIcon(*image.ToImageSkia()); - else - SetIcon(Extension::GetDefaultIcon(true /* is_app */)); + if (!image.IsEmpty()) { + gfx::ImageSkia image_skia = *image.ToImageSkia(); + image_skia.MakeThreadSafe(); + SetIcon(image_skia); + } else { + gfx::ImageSkia image_skia(Extension::GetDefaultIcon(true /* is_app */)); + image_skia.MakeThreadSafe(); + SetIcon(image_skia); + } } bool ExtensionAppItem::IsItemForCommandIdDynamic(int command_id) const { diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm index 2246926..f373076 100644 --- a/chrome/browser/web_applications/web_app_mac.mm +++ b/chrome/browser/web_applications/web_app_mac.mm @@ -198,8 +198,9 @@ bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); bool image_added = false; + info_.favicon.ToImageSkia()->EnsureRepsForSupportedScaleFactors(); std::vector<gfx::ImageSkiaRep> image_reps = - info_.favicon.ToImageSkia()->GetRepresentations(); + info_.favicon.ToImageSkia()->image_reps(); for (size_t i = 0; i < image_reps.size(); ++i) { NSBitmapImageRep* image_rep = SkBitmapToImageRep( image_reps[i].sk_bitmap()); |