diff options
-rw-r--r-- | app/theme_provider.h | 17 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 8 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 12 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider_gtk.cc | 42 | ||||
-rw-r--r-- | chrome/browser/gtk/nine_box.cc | 34 | ||||
-rw-r--r-- | chrome/browser/gtk/nine_box.h | 2 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 |
7 files changed, 91 insertions, 25 deletions
diff --git a/app/theme_provider.h b/app/theme_provider.h index 7257886..29ce2ce 100644 --- a/app/theme_provider.h +++ b/app/theme_provider.h @@ -5,8 +5,13 @@ #ifndef APP_THEME_PROVIDER_H_ #define APP_THEME_PROVIDER_H_ +#include "base/basictypes.h" #include "third_party/skia/include/core/SkColor.h" +#if defined(OS_LINUX) +#include <gdk/gdk.h> +#endif + class SkBitmap; //////////////////////////////////////////////////////////////////////////////// @@ -28,6 +33,18 @@ class ThemeProvider { // Get the color specified by |id|. virtual SkColor GetColor(int id) = 0; + +#if defined(OS_LINUX) + // Gets the GdkPixbuf with the specified |id|. Returns a pointer to a shared + // instance of the GdkPixbuf. This shared GdkPixbuf is owned by the theme + // provider and should not be freed. + // + // The bitmap is assumed to exist. This function will log in release, and + // assert in debug mode if it does not. On failure, this will return a + // pointer to a shared empty placeholder bitmap so it will be visible what + // is missing. + virtual GdkPixbuf* GetPixbufNamed(int id) = 0; +#endif }; #endif // APP_THEME_PROVIDER_H_ diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index a169005..eaf6040 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -107,6 +107,14 @@ BrowserThemeProvider::BrowserThemeProvider() BrowserThemeProvider::~BrowserThemeProvider() { FreeImages(); +#if defined(OS_LINUX) + // Free GdkPixbufs. + for (GdkPixbufMap::iterator i = gdk_pixbufs_.begin(); + i != gdk_pixbufs_.end(); i++) { + g_object_unref(i->second); + } + gdk_pixbufs_.clear(); +#endif } void BrowserThemeProvider::Init(Profile* profile) { diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index b6a2e84..c4138db 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -11,10 +11,15 @@ #include "app/resource_bundle.h" #include "app/theme_provider.h" +#include "base/basictypes.h" #include "base/non_thread_safe.h" #include "base/ref_counted.h" #include "skia/ext/skia_utils.h" +#if defined(OS_LINUX) +#include <gdk/gdk.h> +#endif + class Extension; class Profile; class DictionaryValue; @@ -51,6 +56,9 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // ThemeProvider implementation. virtual SkBitmap* GetBitmapNamed(int id); virtual SkColor GetColor(int id); +#if defined(OS_LINUX) + virtual GdkPixbuf* GetPixbufNamed(int id); +#endif // Set the current theme to the theme defined in |extension|. void SetTheme(Extension* extension); @@ -119,6 +127,10 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // track of the pointers. typedef std::map<int, SkBitmap*> ImageCache; ImageCache image_cache_; +#if defined(OS_LINUX) + typedef std::map<int, GdkPixbuf*> GdkPixbufMap; + GdkPixbufMap gdk_pixbufs_; +#endif // List of generate images that aren't stored in ResourceBundles image cache // and need to be freed. diff --git a/chrome/browser/browser_theme_provider_gtk.cc b/chrome/browser/browser_theme_provider_gtk.cc new file mode 100644 index 0000000..0908d78 --- /dev/null +++ b/chrome/browser/browser_theme_provider_gtk.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/browser_theme_provider.h" + +#include "app/gfx/gtk_util.h" +#include "base/logging.h" + +GdkPixbuf* BrowserThemeProvider::GetPixbufNamed(int id) { + DCHECK(CalledOnValidThread()); + + // Check to see if we already have the pixbuf in the cache. + GdkPixbufMap::const_iterator found = gdk_pixbufs_.find(id); + if (found != gdk_pixbufs_.end()) + return found->second; + + SkBitmap* bitmap = GetBitmapNamed(id); + GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap); + + // We loaded successfully. Cache the pixbuf. + if (pixbuf) { + gdk_pixbufs_[id] = pixbuf; + return pixbuf; + } + + // We failed to retrieve the bitmap, show a debugging red square. + LOG(WARNING) << "Unable to load GdkPixbuf with id " << id; + NOTREACHED(); // Want to assert in debug mode. + + static GdkPixbuf* empty_bitmap = NULL; + if (!empty_bitmap) { + // The placeholder bitmap is bright red so people notice the problem. + // This bitmap will be leaked, but this code should never be hit. + scoped_ptr<SkBitmap> skia_bitmap(new SkBitmap()); + skia_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); + skia_bitmap->allocPixels(); + skia_bitmap->eraseARGB(255, 255, 0, 0); + empty_bitmap = gfx::GdkPixbufFromSkBitmap(skia_bitmap.get()); + } + return empty_bitmap; +} diff --git a/chrome/browser/gtk/nine_box.cc b/chrome/browser/gtk/nine_box.cc index 9fb6a52..e1f3aa6 100644 --- a/chrome/browser/gtk/nine_box.cc +++ b/chrome/browser/gtk/nine_box.cc @@ -28,15 +28,10 @@ void TileImage(cairo_t* cr, GdkPixbuf* src, cairo_fill(cr); } -GdkPixbuf* GetPixbufNamed(ThemeProvider* theme_provider, int name) { - return gfx::GdkPixbufFromSkBitmap(theme_provider->GetBitmapNamed(name)); -} - } // namespace NineBox::NineBox(int top_left, int top, int top_right, int left, int center, - int right, int bottom_left, int bottom, int bottom_right) - : ninebox_owns_images_(false) { + int right, int bottom_left, int bottom, int bottom_right) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); images_[0] = top_left ? rb.GetPixbufNamed(top_left) : NULL; images_[1] = top ? rb.GetPixbufNamed(top) : NULL; @@ -51,35 +46,28 @@ NineBox::NineBox(int top_left, int top, int top_right, int left, int center, NineBox::NineBox(ThemeProvider* theme_provider, int top_left, int top, int top_right, int left, int center, - int right, int bottom_left, int bottom, int bottom_right) - : ninebox_owns_images_(true) { + int right, int bottom_left, int bottom, int bottom_right) { images_[0] = top_left ? - GetPixbufNamed(theme_provider, top_left) : NULL; + theme_provider->GetPixbufNamed(top_left) : NULL; images_[1] = top ? - GetPixbufNamed(theme_provider, top) : NULL; + theme_provider->GetPixbufNamed(top) : NULL; images_[2] = top_right ? - GetPixbufNamed(theme_provider, top_right) : NULL; + theme_provider->GetPixbufNamed(top_right) : NULL; images_[3] = left ? - GetPixbufNamed(theme_provider, left) : NULL; + theme_provider->GetPixbufNamed(left) : NULL; images_[4] = center ? - GetPixbufNamed(theme_provider, center) : NULL; + theme_provider->GetPixbufNamed(center) : NULL; images_[5] = right ? - GetPixbufNamed(theme_provider, right) : NULL; + theme_provider->GetPixbufNamed(right) : NULL; images_[6] = bottom_left ? - GetPixbufNamed(theme_provider, bottom_left) : NULL; + theme_provider->GetPixbufNamed(bottom_left) : NULL; images_[7] = bottom ? - GetPixbufNamed(theme_provider, bottom) : NULL; + theme_provider->GetPixbufNamed(bottom) : NULL; images_[8] = bottom_right ? - GetPixbufNamed(theme_provider, bottom_right) : NULL; + theme_provider->GetPixbufNamed(bottom_right) : NULL; } NineBox::~NineBox() { - if (ninebox_owns_images_) { - for (size_t i = 0; i < 9; i++) { - if (images_[i]) - g_object_unref(images_[i]); - } - } } void NineBox::RenderToWidget(GtkWidget* dst) const { diff --git a/chrome/browser/gtk/nine_box.h b/chrome/browser/gtk/nine_box.h index c59e322..dfdfafb 100644 --- a/chrome/browser/gtk/nine_box.h +++ b/chrome/browser/gtk/nine_box.h @@ -54,8 +54,6 @@ class NineBox { private: GdkPixbuf* images_[9]; - // Determine if we own and need to free images_. - bool ninebox_owns_images_; }; #endif // CHROME_BROWSER_GTK_NINE_BOX_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index ef6a616..f60d671 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -592,6 +592,7 @@ 'browser/browser_process_impl.h', 'browser/browser_shutdown.cc', 'browser/browser_shutdown.h', + 'browser/browser_theme_provider_gtk.cc', 'browser/browser_theme_provider.cc', 'browser/browser_theme_provider.h', 'browser/browser_trial.cc', |