summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-05 23:40:01 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-05 23:40:01 +0000
commita1e222426604f014562f34131f544e2e6cf4ddb3 (patch)
treeefa4fcd9bb0bf18033a9a8015b3252f9727eb409 /chrome
parent5dc49e45a85067fa5410cee7ffcadf5eeacd97db (diff)
downloadchromium_src-a1e222426604f014562f34131f544e2e6cf4ddb3.zip
chromium_src-a1e222426604f014562f34131f544e2e6cf4ddb3.tar.gz
chromium_src-a1e222426604f014562f34131f544e2e6cf4ddb3.tar.bz2
GTK: Refactor some things so GTK doesn't touch the on disk image cache.
Hopefully will solve crash. BUG=23588 Review URL: http://codereview.chromium.org/258020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28066 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_theme_provider.cc72
-rw-r--r--chrome/browser/browser_theme_provider.h5
-rw-r--r--chrome/browser/gtk/gtk_theme_provider.cc28
3 files changed, 64 insertions, 41 deletions
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc
index 4be04498..6ba4c5a 100644
--- a/chrome/browser/browser_theme_provider.cc
+++ b/chrome/browser/browser_theme_provider.cc
@@ -331,11 +331,6 @@ SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) {
// Try to load the image from the extension.
result.reset(LoadThemeBitmap(id));
- // If the extension doesn't provide the requested image, but has provided
- // a custom frame, then we may be able to generate the image required.
- if (!result.get())
- result.reset(GenerateTabBackgroundBitmap(id));
-
// If we still don't have an image, load it from resourcebundle.
if (!result.get())
result.reset(new SkBitmap(*rb_.GetBitmapNamed(id)));
@@ -1071,31 +1066,14 @@ SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) {
if (frame.get())
themed_image_cache_[id] = new SkBitmap(*frame.get());
} else {
- int base_id;
- std::string resource_name;
- if (id == IDR_THEME_TAB_BACKGROUND) {
- base_id = IDR_THEME_FRAME;
- resource_name = "theme_tab_background";
- } else {
- base_id = IDR_THEME_FRAME_INCOGNITO;
- resource_name = "theme_tab_background_incognito";
- }
- std::map<int, SkBitmap*>::iterator it = themed_image_cache_.find(base_id);
- if (it != themed_image_cache_.end()) {
- SkBitmap bg_tint = TintBitmap(*(it->second), TINT_BACKGROUND_TAB);
- int vertical_offset = HasCustomImage(id) ?
- kRestoredTabVerticalOffset : 0;
- SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap(
- bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height()));
-
- // If they've provided a custom image, overlay it.
- if (HasCustomImage(id)) {
- SkBitmap* overlay = LoadThemeBitmap(id);
- if (overlay) {
- SkCanvas canvas(*bg_tab);
- for (int x = 0; x < bg_tab->width(); x += overlay->width())
- canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL);
- }
+ SkBitmap* bg_tab = GenerateTabBackgroundBitmapImpl(id);
+
+ if (bg_tab) {
+ std::string resource_name;
+ if (id == IDR_THEME_TAB_BACKGROUND) {
+ resource_name = "theme_tab_background";
+ } else {
+ resource_name = "theme_tab_background_incognito";
}
themed_image_cache_[id] = bg_tab;
@@ -1107,6 +1085,40 @@ SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) {
return NULL;
}
+SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmapImpl(int id) {
+ int base_id;
+ if (id == IDR_THEME_TAB_BACKGROUND) {
+ base_id = IDR_THEME_FRAME;
+ } else {
+ base_id = IDR_THEME_FRAME_INCOGNITO;
+ }
+ // According to Miranda, it is safe to read from the themed-image_cache_ here
+ // because we only lock to write on the UI thread, and we only lock to read
+ // on the cache writing thread.
+ std::map<int, SkBitmap*>::iterator it = themed_image_cache_.find(base_id);
+ if (it != themed_image_cache_.end()) {
+ SkBitmap bg_tint = TintBitmap(*(it->second), TINT_BACKGROUND_TAB);
+ int vertical_offset = HasCustomImage(id) ?
+ kRestoredTabVerticalOffset : 0;
+ SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap(
+ bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height()));
+
+ // If they've provided a custom image, overlay it.
+ if (HasCustomImage(id)) {
+ SkBitmap* overlay = LoadThemeBitmap(id);
+ if (overlay) {
+ SkCanvas canvas(*bg_tab);
+ for (int x = 0; x < bg_tab->width(); x += overlay->width())
+ canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL);
+ }
+ }
+
+ return bg_tab;
+ }
+
+ return NULL;
+}
+
void BrowserThemeProvider::SaveCachedImageData() {
DictionaryValue* pref_images =
profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages);
diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h
index d6c20b6..0d3524b 100644
--- a/chrome/browser/browser_theme_provider.h
+++ b/chrome/browser/browser_theme_provider.h
@@ -261,6 +261,11 @@ class BrowserThemeProvider : public NonThreadSafe,
// from ClearCaches().
virtual void FreePlatformCaches();
+ // The implementation of GenerateTabBackgroundBitmap(). That function also
+ // must be locked and touches caches; this function only deals with image
+ // generation.
+ SkBitmap* GenerateTabBackgroundBitmapImpl(int id);
+
Profile* profile() { return profile_; }
// Subclasses may need us to not use the on-disk image cache. The GTK
diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc
index bc47e8f..296b72c 100644
--- a/chrome/browser/gtk/gtk_theme_provider.cc
+++ b/chrome/browser/gtk/gtk_theme_provider.cc
@@ -258,18 +258,23 @@ void GtkThemeProvider::NotifyThemeChanged() {
}
SkBitmap* GtkThemeProvider::LoadThemeBitmap(int id) {
- if (id == IDR_THEME_TOOLBAR && use_gtk_) {
- GtkStyle* style = gtk_rc_get_style(fake_window_);
- GdkColor* color = &style->bg[GTK_STATE_NORMAL];
- SkBitmap* bitmap = new SkBitmap;
- bitmap->setConfig(SkBitmap::kARGB_8888_Config,
- kToolbarImageWidth, kToolbarImageHeight);
- bitmap->allocPixels();
- bitmap->eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8);
- return bitmap;
- } else {
- return BrowserThemeProvider::LoadThemeBitmap(id);
+ if (use_gtk_) {
+ if (id == IDR_THEME_TOOLBAR) {
+ GtkStyle* style = gtk_rc_get_style(fake_window_);
+ GdkColor* color = &style->bg[GTK_STATE_NORMAL];
+ SkBitmap* bitmap = new SkBitmap;
+ bitmap->setConfig(SkBitmap::kARGB_8888_Config,
+ kToolbarImageWidth, kToolbarImageHeight);
+ bitmap->allocPixels();
+ bitmap->eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8);
+ return bitmap;
+ } else if ((id == IDR_THEME_TAB_BACKGROUND ||
+ id == IDR_THEME_TAB_BACKGROUND_INCOGNITO)) {
+ return GenerateTabBackgroundBitmapImpl(id);
+ }
}
+
+ return BrowserThemeProvider::LoadThemeBitmap(id);
}
void GtkThemeProvider::SaveThemeBitmap(const std::string resource_name,
@@ -434,6 +439,7 @@ void GtkThemeProvider::LoadGtkValues() {
force_process_images();
GenerateFrameColors();
+ AutoLock lock(themed_image_cache_lock_);
GenerateFrameImages();
}