summaryrefslogtreecommitdiffstats
path: root/chrome/browser/themes
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-29 03:46:27 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-29 03:46:27 +0000
commit2b8ac34229b953d763712d038eb52bb989e52568 (patch)
treec3d2b10983efee188778bb43a3d7f2d7f284c31b /chrome/browser/themes
parentd5f6d64a34f875835b5750a54524df9502fb6f68 (diff)
downloadchromium_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/browser/themes')
-rw-r--r--chrome/browser/themes/browser_theme_pack.cc49
-rw-r--r--chrome/browser/themes/browser_theme_pack.h4
2 files changed, 8 insertions, 45 deletions
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,