diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 17:36:17 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 17:36:17 +0000 |
commit | 52d70a7c296f2eeef7343ed94375a7abad4a65dc (patch) | |
tree | 83f282358ee747ae897c440d781ade9d6a0730bc /chrome | |
parent | 52bf465e9d660330d267d5b29c36fe3e9ce1d905 (diff) | |
download | chromium_src-52d70a7c296f2eeef7343ed94375a7abad4a65dc.zip chromium_src-52d70a7c296f2eeef7343ed94375a7abad4a65dc.tar.gz chromium_src-52d70a7c296f2eeef7343ed94375a7abad4a65dc.tar.bz2 |
Make PNGCodec::Decode(...) not make an intermediary copy of the decoded data;
instead have it write directly to the returned SkBitmap.
BUG=http://crbug.com/24493
TEST=Perf should get better. On the perf trybot, tab_complex_theme_cold got an average of ~40ms better.
Review URL: http://codereview.chromium.org/305001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29780 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.cc | 2 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 13 | ||||
-rw-r--r-- | chrome/browser/fav_icon_helper.cc | 9 | ||||
-rw-r--r-- | chrome/browser/gtk/list_store_favicon_loader.cc | 12 | ||||
-rw-r--r-- | chrome/browser/jumplist.cc | 8 | ||||
-rw-r--r-- | chrome/browser/possible_url_model.cc | 3 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_table_model.cc | 4 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.cc | 7 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database_unittest.cc | 2 |
9 files changed, 25 insertions, 35 deletions
diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index a6cc083..60c1cd4 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -649,7 +649,7 @@ void BookmarkModel::OnFavIconDataAvailable( DCHECK(node); node->set_favicon_load_handle(0); if (know_favicon && data.get() && - gfx::PNGCodec::Decode(&data->data, &fav_icon)) { + gfx::PNGCodec::Decode(data->front(), data->size(), &fav_icon)) { node->set_favicon(fav_icon); FavIconLoaded(node); } diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index eb7aeb4..c127cab 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -840,22 +840,15 @@ SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) const { raw_data = ReadThemeFileData(id); if (raw_data) { - std::vector<unsigned char> png_data; - // Decode the PNG. - int image_width = 0; - int image_height = 0; - + SkBitmap bitmap; if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(), - gfx::PNGCodec::FORMAT_BGRA, &png_data, - &image_width, &image_height)) { + &bitmap)) { NOTREACHED() << "Unable to decode theme image resource " << id; return NULL; } - return gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(png_data, - image_width, - image_height); + return new SkBitmap(bitmap); } else { // TODO(glen): File no-longer exists, we're out of date. We should // clear the theme (or maybe just the pref that points to this diff --git a/chrome/browser/fav_icon_helper.cc b/chrome/browser/fav_icon_helper.cc index f0d7d64..3563406 100644 --- a/chrome/browser/fav_icon_helper.cc +++ b/chrome/browser/fav_icon_helper.cc @@ -87,7 +87,7 @@ void FavIconHelper::FavIconDownloadFailed(int download_id) { void FavIconHelper::UpdateFavIcon(NavigationEntry* entry, const std::vector<unsigned char>& data) { SkBitmap image; - gfx::PNGCodec::Decode(&data, &image); + gfx::PNGCodec::Decode(&data.front(), data.size(), &image); UpdateFavIcon(entry, image); } @@ -187,12 +187,13 @@ void FavIconHelper::OnFavIconDataForInitialURL( // favicon or its expired. Continue on to DownloadFavIconOrAskHistory to // either download or check history again. DownloadFavIconOrAskHistory(entry); - } // else we haven't got the icon url. When we get it we'll ask the - // renderer to download the icon. + } + // else we haven't got the icon url. When we get it we'll ask the + // renderer to download the icon. } void FavIconHelper::DownloadFavIconOrAskHistory(NavigationEntry* entry) { - DCHECK(entry); // We should only get here if entry is valid. + DCHECK(entry); // We should only get here if entry is valid. if (fav_icon_expired_) { // We have the mapping, but the favicon is out of date. Download it now. ScheduleDownload(entry); diff --git a/chrome/browser/gtk/list_store_favicon_loader.cc b/chrome/browser/gtk/list_store_favicon_loader.cc index f0a146b..a4995db 100644 --- a/chrome/browser/gtk/list_store_favicon_loader.cc +++ b/chrome/browser/gtk/list_store_favicon_loader.cc @@ -69,17 +69,9 @@ void ListStoreFavIconLoader::OnGotFavIcon( favicon_handle_col_, 0, -1); if (know_fav_icon && image_data.get() && !image_data->data.empty()) { - int width, height; - std::vector<unsigned char> decoded_data; + SkBitmap icon; if (gfx::PNGCodec::Decode(&image_data->data.front(), - image_data->data.size(), - gfx::PNGCodec::FORMAT_BGRA, &decoded_data, - &width, &height)) { - SkBitmap icon; - icon.setConfig(SkBitmap::kARGB_8888_Config, width, height); - icon.allocPixels(); - memcpy(icon.getPixels(), &decoded_data.front(), - width * height * 4); + image_data->data.size(), &icon)) { GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); gtk_list_store_set(list_store_, &iter, favicon_col_, pixbuf, diff --git a/chrome/browser/jumplist.cc b/chrome/browser/jumplist.cc index 3dd2c55..1af060b 100644 --- a/chrome/browser/jumplist.cc +++ b/chrome/browser/jumplist.cc @@ -497,7 +497,9 @@ void JumpListUpdateTask::Run() { item != most_visited_pages_.end(); ++item) { SkBitmap icon_bitmap; if ((*item)->data().get() && - gfx::PNGCodec::Decode(&(*item)->data()->data, &icon_bitmap)) { + gfx::PNGCodec::Decode((*item)->data()->front(), + (*item)->data()->size(), + &icon_bitmap)) { std::wstring icon_path; if (CreateIconFile(icon_bitmap, icon_dir_, &icon_path)) (*item)->SetIcon(icon_path, 0, true); @@ -510,7 +512,9 @@ void JumpListUpdateTask::Run() { item != recently_closed_pages_.end(); ++item) { SkBitmap icon_bitmap; if ((*item)->data().get() && - gfx::PNGCodec::Decode(&(*item)->data()->data, &icon_bitmap)) { + gfx::PNGCodec::Decode((*item)->data()->front(), + (*item)->data()->size(), + &icon_bitmap)) { std::wstring icon_path; if (CreateIconFile(icon_bitmap, icon_dir_, &icon_path)) (*item)->SetIcon(icon_path, 0, true); diff --git a/chrome/browser/possible_url_model.cc b/chrome/browser/possible_url_model.cc index 5960ada..2f73ed9 100644 --- a/chrome/browser/possible_url_model.cc +++ b/chrome/browser/possible_url_model.cc @@ -176,7 +176,8 @@ void PossibleURLModel::OnFavIconAvailable( size_t index = consumer_.GetClientData(favicon_service, h); if (fav_icon_available) { // The decoder will leave our bitmap empty on error. - gfx::PNGCodec::Decode(&data->data, &(fav_icon_map_[index])); + gfx::PNGCodec::Decode(data->front(), data->size(), + &(fav_icon_map_[index])); // Notify the observer. if (!fav_icon_map_[index].isNull() && observer_) diff --git a/chrome/browser/search_engines/template_url_table_model.cc b/chrome/browser/search_engines/template_url_table_model.cc index 3b1aaca..4b9663f 100644 --- a/chrome/browser/search_engines/template_url_table_model.cc +++ b/chrome/browser/search_engines/template_url_table_model.cc @@ -100,7 +100,7 @@ class ModelEntry { GURL icon_url) { load_state_ = LOADED; if (know_favicon && data.get() && - gfx::PNGCodec::Decode(&data->data, &fav_icon_)) { + gfx::PNGCodec::Decode(data->front(), data->size(), &fav_icon_)) { model_->FavIconAvailable(this); } } @@ -313,7 +313,7 @@ int TemplateURLTableModel::IndexOfTemplateURL( int TemplateURLTableModel::MoveToMainGroup(int index) { if (index < last_search_engine_index_) - return index; // Already in the main group. + return index; // Already in the main group. ModelEntry* current_entry = entries_[index]; entries_.erase(index + entries_.begin()); diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index f611a93..e163f56 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -211,12 +211,11 @@ bool WebDatabase::GetWebAppImages(const GURL& url, s.BindString(0, history::HistoryDatabase::GURLToDatabaseURL(url)); while (s.Step()) { SkBitmap image; - std::vector<unsigned char> image_data; int col_bytes = s.ColumnByteLength(0); if (col_bytes > 0) { - image_data.resize(col_bytes); - memcpy(&image_data[0], s.ColumnBlob(0), col_bytes); - if (gfx::PNGCodec::Decode(&image_data, &image)) { + if (gfx::PNGCodec::Decode( + reinterpret_cast<const unsigned char*>(s.ColumnBlob(0)), + col_bytes, &image)) { images->push_back(image); } else { // Should only have valid image data in the db. diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index 32001e5..f6ac53b 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -665,7 +665,7 @@ TEST_F(WebDatabaseTest, WebAppImages) { // Set some random pixels so that we can identify the image. We don't use // transparent images because of pre-multiplication rounding errors. SkColor test_pixel_1 = 0xffccbbaa; - SkColor test_pixel_2 = 0x00aabbaa; + SkColor test_pixel_2 = 0xffaabbaa; SkColor test_pixel_3 = 0xff339966; image.getAddr32(0, 1)[0] = test_pixel_1; image.getAddr32(0, 1)[1] = test_pixel_2; |