diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 20:21:13 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 20:21:13 +0000 |
commit | 8fcc39da6cd2a6ea148886e2d8333fc02bd62a21 (patch) | |
tree | 09dbcbaa42b748b54c923461a951d10df79327b6 /chrome/browser/browser_theme_provider_gtk.cc | |
parent | 9f50a2f07eb717f613b7cada7e25bfa6e3c79de2 (diff) | |
download | chromium_src-8fcc39da6cd2a6ea148886e2d8333fc02bd62a21.zip chromium_src-8fcc39da6cd2a6ea148886e2d8333fc02bd62a21.tar.gz chromium_src-8fcc39da6cd2a6ea148886e2d8333fc02bd62a21.tar.bz2 |
Add GetPixbufNamed to ThemeProvider. GetPixbufNamed converts a loaded theme bitmap to a GdkPixbuf and caches the image so ThemeProvider users don't need to release them ala ResourceBundle::GetPixbufNamed.
Review URL: http://codereview.chromium.org/113626
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_theme_provider_gtk.cc')
-rw-r--r-- | chrome/browser/browser_theme_provider_gtk.cc | 42 |
1 files changed, 42 insertions, 0 deletions
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; +} |