Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: chrome/browser/browser_theme_provider.cc

Issue 243076: Move the JPEG and PNG codecs from base/gfx to app/gfx/codec. Move the classes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browser_theme_provider.h" 5 #include "chrome/browser/browser_theme_provider.h"
6 6
7 #include "app/gfx/codec/png_codec.h"
7 #include "app/gfx/skbitmap_operations.h" 8 #include "app/gfx/skbitmap_operations.h"
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/gfx/png_decoder.h"
10 #include "base/gfx/png_encoder.h"
11 #include "base/string_util.h" 10 #include "base/string_util.h"
12 #include "base/thread.h" 11 #include "base/thread.h"
13 #include "base/values.h" 12 #include "base/values.h"
14 #include "chrome/browser/browser_list.h" 13 #include "chrome/browser/browser_list.h"
15 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/browser_window.h" 15 #include "chrome/browser/browser_window.h"
17 #include "chrome/browser/metrics/user_metrics.h" 16 #include "chrome/browser/metrics/user_metrics.h"
18 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
19 #include "chrome/browser/theme_resources_util.h" 18 #include "chrome/browser/theme_resources_util.h"
20 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 BrowserThemeProvider::ImagesDiskCache::const_iterator iter; 217 BrowserThemeProvider::ImagesDiskCache::const_iterator iter;
219 for (iter = images_disk_cache_.begin(); 218 for (iter = images_disk_cache_.begin();
220 iter != images_disk_cache_.end(); 219 iter != images_disk_cache_.end();
221 iter++) { 220 iter++) {
222 FilePath image_path = (*iter).first; 221 FilePath image_path = (*iter).first;
223 BrowserThemeProvider::ImageCache::const_iterator found = 222 BrowserThemeProvider::ImageCache::const_iterator found =
224 themed_image_cache_.find((*iter).second); 223 themed_image_cache_.find((*iter).second);
225 if (found != themed_image_cache_.end()) { 224 if (found != themed_image_cache_.end()) {
226 SkBitmap* bitmap = found->second; 225 SkBitmap* bitmap = found->second;
227 std::vector<unsigned char> image_data; 226 std::vector<unsigned char> image_data;
228 if (!PNGEncoder::EncodeBGRASkBitmap(*bitmap, false, &image_data)) { 227 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &image_data)) {
229 NOTREACHED() << "Image file could not be encoded."; 228 NOTREACHED() << "Image file could not be encoded.";
230 return; 229 return;
231 } 230 }
232 const char* image_data_ptr = 231 const char* image_data_ptr =
233 reinterpret_cast<const char*>(&image_data[0]); 232 reinterpret_cast<const char*>(&image_data[0]);
234 if (!file_util::WriteFile(image_path, 233 if (!file_util::WriteFile(image_path,
235 image_data_ptr, image_data.size())) { 234 image_data_ptr, image_data.size())) {
236 NOTREACHED() << "Image file could not be written to disk."; 235 NOTREACHED() << "Image file could not be written to disk.";
237 return; 236 return;
238 } 237 }
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 if (!themeable_images_[id]) 642 if (!themeable_images_[id])
644 return NULL; 643 return NULL;
645 644
646 // Attempt to find the image in our theme bundle. 645 // Attempt to find the image in our theme bundle.
647 std::vector<unsigned char> raw_data, png_data; 646 std::vector<unsigned char> raw_data, png_data;
648 if (ReadThemeFileData(id, &raw_data)) { 647 if (ReadThemeFileData(id, &raw_data)) {
649 // Decode the PNG. 648 // Decode the PNG.
650 int image_width = 0; 649 int image_width = 0;
651 int image_height = 0; 650 int image_height = 0;
652 651
653 if (!PNGDecoder::Decode(&raw_data.front(), raw_data.size(), 652 if (!gfx::PNGCodec::Decode(&raw_data.front(), raw_data.size(),
654 PNGDecoder::FORMAT_BGRA, &png_data, 653 gfx::PNGCodec::FORMAT_BGRA, &png_data,
655 &image_width, &image_height)) { 654 &image_width, &image_height)) {
656 NOTREACHED() << "Unable to decode theme image resource " << id; 655 NOTREACHED() << "Unable to decode theme image resource " << id;
657 return NULL; 656 return NULL;
658 } 657 }
659 658
660 return PNGDecoder::CreateSkBitmapFromBGRAFormat(png_data, 659 return gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(png_data,
661 image_width, 660 image_width,
662 image_height); 661 image_height);
663 } else { 662 } else {
664 // TODO(glen): File no-longer exists, we're out of date. We should 663 // TODO(glen): File no-longer exists, we're out of date. We should
665 // clear the theme (or maybe just the pref that points to this 664 // clear the theme (or maybe just the pref that points to this
666 // image). 665 // image).
667 return NULL; 666 return NULL;
668 } 667 }
669 } 668 }
670 669
671 void BrowserThemeProvider::SaveThemeBitmap( 670 void BrowserThemeProvider::SaveThemeBitmap(
672 std::string resource_name, int id) { 671 std::string resource_name, int id) {
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 } 1289 }
1291 image_cache_.clear(); 1290 image_cache_.clear();
1292 images_disk_cache_.clear(); 1291 images_disk_cache_.clear();
1293 } 1292 }
1294 1293
1295 #if defined(OS_WIN) 1294 #if defined(OS_WIN)
1296 void BrowserThemeProvider::FreePlatformCaches() { 1295 void BrowserThemeProvider::FreePlatformCaches() {
1297 // Views (Skia) has no platform image cache to clear. 1296 // Views (Skia) has no platform image cache to clear.
1298 } 1297 }
1299 #endif 1298 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698