diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-19 00:05:49 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-19 00:05:49 +0000 |
commit | 0a7800ee17acd0f383fac1a99d664ee6a12a878f (patch) | |
tree | 2ce016f5fbe9475a4378693d219bdd5ced6c4c4a /chrome | |
parent | de94c5128ce39f96d2058c435935b4bd3e6330a8 (diff) | |
download | chromium_src-0a7800ee17acd0f383fac1a99d664ee6a12a878f.zip chromium_src-0a7800ee17acd0f383fac1a99d664ee6a12a878f.tar.gz chromium_src-0a7800ee17acd0f383fac1a99d664ee6a12a878f.tar.bz2 |
linux: Load icons with gdk instead of using PNGDecoder.
BUG=14487
Review URL: http://codereview.chromium.org/131058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.cc | 19 | ||||
-rw-r--r-- | chrome/browser/icon_loader_linux.cc | 41 |
2 files changed, 30 insertions, 30 deletions
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index 6ed474f..a98601e 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -603,24 +603,9 @@ gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, // TODO(estade): draw a default icon if |icon_| is null. if (download_item->icon_) { - int width = download_item->icon_->width(); - int height = download_item->icon_->height(); - // Sometimes we get back icons that are the wrong size. Draw the correct - // size. This code should hopefully be made obsolete after we support SVG - // icons (although it could still be hit if a theme doesn't provide SVG or - // 16x16). - const int sixteen = download_util::kSmallIconSize; const int offset = download_util::kSmallProgressIconOffset; - if (sixteen != width || sixteen != height) { - // Draw the bitmap at a reduced scale. - download_item->icon_->buildMipMap(false); - canvas.DrawBitmapInt(*download_item->icon_, 0, 0, width, height, - widget->allocation.x + offset, widget->allocation.y + offset, - sixteen, sixteen, true); - } else { - canvas.DrawBitmapInt(*download_item->icon_, - widget->allocation.x + offset, widget->allocation.y + offset); - } + canvas.DrawBitmapInt(*download_item->icon_, + widget->allocation.x + offset, widget->allocation.y + offset); } return TRUE; diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc index 26788d8..64e2c27 100644 --- a/chrome/browser/icon_loader_linux.cc +++ b/chrome/browser/icon_loader_linux.cc @@ -4,9 +4,12 @@ #include "chrome/browser/icon_loader.h" +#include <gtk/gtk.h> + #include "base/file_util.h" #include "base/gfx/png_decoder.h" #include "base/logging.h" +#include "base/linux_util.h" #include "base/message_loop.h" #include "base/mime_util.h" #include "base/thread.h" @@ -14,27 +17,39 @@ #include "third_party/skia/include/core/SkBitmap.h" void IconLoader::ReadIcon() { - size_t size = 48; + int size = 48; if (icon_size_ == NORMAL) size = 32; else if (icon_size_ == SMALL) size = 16; FilePath filename = mime_util::GetMimeIcon(group_, size); - if (LowerCaseEqualsASCII(mime_util::GetFileMimeType(filename), "image/png")) { - std::string file_contents; - file_util::ReadFileToString(filename, &file_contents); - - std::vector<unsigned char> pixels; - int width, height; - if (PNGDecoder::Decode( - reinterpret_cast<const unsigned char*>(file_contents.c_str()), - file_contents.length(), PNGDecoder::FORMAT_BGRA, - &pixels, &width, &height)) { - bitmap_ = PNGDecoder::CreateSkBitmapFromBGRAFormat(pixels, width, height); + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename.value().c_str(), + size, size, NULL); + if (pixbuf) { + guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); + int width = gdk_pixbuf_get_width(pixbuf); + int height = gdk_pixbuf_get_height(pixbuf); + DCHECK_EQ(width, size); + DCHECK_EQ(height, size); + int stride = gdk_pixbuf_get_rowstride(pixbuf); + + if (!gdk_pixbuf_get_has_alpha(pixbuf)) { + LOG(WARNING) << "Got an image with no alpha channel, aborting load."; + } else { + uint8_t* BGRA_pixels = base::BGRAToRGBA(pixels, width, height, stride); + std::vector<unsigned char> pixel_vector; + pixel_vector.resize(height * stride); + memcpy(const_cast<unsigned char*>(pixel_vector.data()), BGRA_pixels, + height * stride); + bitmap_ = PNGDecoder::CreateSkBitmapFromBGRAFormat(pixel_vector, + width, height); + free(BGRA_pixels); } + + g_object_unref(pixbuf); } else { - // TODO(estade): support other file types. + LOG(WARNING) << "Unsupported file type or load error: " << filename.value(); } target_message_loop_->PostTask(FROM_HERE, |