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

Side by Side Diff: chrome/browser/themes/browser_theme_pack.cc

Issue 6849030: Add support for multi resolution icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/themes/browser_theme_pack.h" 5 #include "chrome/browser/themes/browser_theme_pack.h"
6 6
7 #include "base/stl_util-inl.h" 7 #include "base/stl_util-inl.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/themes/theme_service.h" 12 #include "chrome/browser/themes/theme_service.h"
13 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
14 #include "grit/app_resources.h" 14 #include "grit/app_resources.h"
15 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
16 #include "net/base/file_stream.h" 16 #include "net/base/file_stream.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "third_party/skia/include/core/SkCanvas.h" 18 #include "third_party/skia/include/core/SkCanvas.h"
19 #include "ui/base/resource/data_pack.h" 19 #include "ui/base/resource/data_pack.h"
20 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/codec/png_codec.h" 21 #include "ui/gfx/codec/png_codec.h"
22 #include "ui/gfx/codec/tiff_codec.h"
22 #include "ui/gfx/skbitmap_operations.h" 23 #include "ui/gfx/skbitmap_operations.h"
23 24
24 namespace { 25 namespace {
25 26
26 // Version number of the current theme pack. We just throw out and rebuild 27 // Version number of the current theme pack. We just throw out and rebuild
27 // theme packs that aren't int-equal to this. 28 // theme packs that aren't int-equal to this.
28 const int kThemePackVersion = 15; 29 const int kThemePackVersion = 15;
Elliot Glaysher 2011/04/14 18:33:41 Are old theme packs binary compatible with this ne
29 30
30 // IDs that are in the DataPack won't clash with the positive integer 31 // IDs that are in the DataPack won't clash with the positive integer
31 // int32_t. kHeaderID should always have the maximum value because we want the 32 // int32_t. kHeaderID should always have the maximum value because we want the
32 // "header" to be written last. That way we can detect whether the pack was 33 // "header" to be written last. That way we can detect whether the pack was
33 // successfully written and ignore and regenerate if it was only partially 34 // successfully written and ignore and regenerate if it was only partially
34 // written (i.e. chrome crashed on a different thread while writing the pack). 35 // written (i.e. chrome crashed on a different thread while writing the pack).
35 const int kHeaderID = UINT_MAX - 1; 36 const int kHeaderID = UINT_MAX - 1;
36 const int kTintsID = UINT_MAX - 2; 37 const int kTintsID = UINT_MAX - 2;
37 const int kColorsID = UINT_MAX - 3; 38 const int kColorsID = UINT_MAX - 3;
38 const int kDisplayPropertiesID = UINT_MAX - 4; 39 const int kDisplayPropertiesID = UINT_MAX - 4;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 BrowserThemePack::~BrowserThemePack() { 317 BrowserThemePack::~BrowserThemePack() {
317 if (!data_pack_.get()) { 318 if (!data_pack_.get()) {
318 delete header_; 319 delete header_;
319 delete [] tints_; 320 delete [] tints_;
320 delete [] colors_; 321 delete [] colors_;
321 delete [] display_properties_; 322 delete [] display_properties_;
322 delete [] source_images_; 323 delete [] source_images_;
323 } 324 }
324 325
325 STLDeleteValues(&prepared_images_); 326 STLDeleteValues(&prepared_images_);
327 for (MultiResImageCache::iterator i = loaded_images_.begin();
328 i != loaded_images_.end(); ++i) {
329 STLDeleteContainerPointers(i->second->begin(), i->second->end());
330 }
326 STLDeleteValues(&loaded_images_); 331 STLDeleteValues(&loaded_images_);
327 } 332 }
328 333
329 // static 334 // static
330 BrowserThemePack* BrowserThemePack::BuildFromExtension( 335 BrowserThemePack* BrowserThemePack::BuildFromExtension(
331 const Extension* extension) { 336 const Extension* extension) {
332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
333 DCHECK(extension); 338 DCHECK(extension);
334 DCHECK(extension->is_theme()); 339 DCHECK(extension->is_theme());
335 340
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 *result = display_properties_[i].property; 491 *result = display_properties_[i].property;
487 return true; 492 return true;
488 } 493 }
489 } 494 }
490 } 495 }
491 496
492 return false; 497 return false;
493 } 498 }
494 499
495 SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const { 500 SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const {
501 std::vector<SkBitmap*> bitmaps;
502 if (!GetBitmapsNamed(idr_id, bitmaps))
503 return NULL;
504 if (bitmaps.empty())
505 return NULL;
506 return *bitmaps.begin();
507 }
508
509 bool BrowserThemePack::GetBitmapsNamed(
510 int idr_id, std::vector<SkBitmap*>& bitmaps) const {
496 int prs_id = GetPersistentIDByIDR(idr_id); 511 int prs_id = GetPersistentIDByIDR(idr_id);
497 if (prs_id == -1) 512 if (prs_id == -1)
498 return NULL; 513 return false;
499 514
500 // Check our cache of prepared images, first. 515 // Check our cache of prepared images, first.
501 ImageCache::const_iterator image_iter = prepared_images_.find(prs_id); 516 ImageCache::const_iterator image_iter = prepared_images_.find(prs_id);
502 if (image_iter != prepared_images_.end()) 517 if (image_iter != prepared_images_.end()) {
503 return image_iter->second; 518 bitmaps.push_back(image_iter->second);
519 return true;
520 }
504 521
505 // Check if we've already loaded this image. 522 // Check if we've already loaded this image.
506 image_iter = loaded_images_.find(prs_id); 523 MultiResImageCache::const_iterator multi_image_iter =
507 if (image_iter != loaded_images_.end()) 524 loaded_images_.find(prs_id);
508 return image_iter->second; 525 if (multi_image_iter != loaded_images_.end()) {
526 bitmaps = *(multi_image_iter->second);
527 return true;
528 }
509 529
510 scoped_refptr<RefCountedMemory> memory; 530 scoped_refptr<RefCountedMemory> memory;
511 if (data_pack_.get()) { 531 if (data_pack_.get()) {
512 memory = data_pack_->GetStaticMemory(prs_id); 532 memory = data_pack_->GetStaticMemory(prs_id);
513 } else { 533 } else {
514 RawImages::const_iterator it = image_memory_.find(prs_id); 534 RawImages::const_iterator it = image_memory_.find(prs_id);
515 if (it != image_memory_.end()) { 535 if (it != image_memory_.end()) {
516 memory = it->second; 536 memory = it->second;
517 } 537 }
518 } 538 }
519 539
520 if (memory.get()) { 540 if (memory.get()) {
521 // Decode the PNG. 541 // Try to decode it as a PNG.
522 SkBitmap bitmap; 542 SkBitmap bitmap;
523 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), 543 if (gfx::PNGCodec::Decode(memory->front(), memory->size(),&bitmap)) {
524 &bitmap)) { 544 std::vector<SkBitmap*>* bitmaps_ptr = new std::vector<SkBitmap*>;
525 NOTREACHED() << "Unable to decode theme image resource " << idr_id 545 bitmaps_ptr->push_back(new SkBitmap(bitmap));
526 << " from saved DataPack."; 546 loaded_images_[prs_id] = bitmaps_ptr;
527 return NULL; 547 return true;
528 } 548 }
529 549
530 SkBitmap* ret = new SkBitmap(bitmap); 550 // Try to decode it as a TIFF.
531 loaded_images_[prs_id] = ret; 551 std::vector<SkBitmap> bitmaps;
552 if (gfx::TIFFCodec::Decode(memory->front(), memory->size(), bitmaps)) {
553 std::vector<SkBitmap*>* bitmaps_ptr = new std::vector<SkBitmap*>;
554 for (std::vector<SkBitmap>::iterator it = bitmaps.begin();
555 it != bitmaps.end(); ++it) {
556 bitmaps_ptr->push_back(new SkBitmap(*it));
557 }
558 loaded_images_[prs_id] = bitmaps_ptr;
559 return true;
560 }
532 561
533 return ret; 562 NOTREACHED() << "Unable to decode theme image resource " << idr_id
563 << " from saved DataPack.";
534 } 564 }
535 565
536 return NULL; 566 return false;
537 } 567 }
538 568
539 RefCountedMemory* BrowserThemePack::GetRawData(int idr_id) const { 569 RefCountedMemory* BrowserThemePack::GetRawData(int idr_id) const {
540 RefCountedMemory* memory = NULL; 570 RefCountedMemory* memory = NULL;
541 int prs_id = GetPersistentIDByIDR(idr_id); 571 int prs_id = GetPersistentIDByIDR(idr_id);
542 572
543 if (prs_id != -1) { 573 if (prs_id != -1) {
544 if (data_pack_.get()) { 574 if (data_pack_.get()) {
545 memory = data_pack_->GetStaticMemory(prs_id); 575 memory = data_pack_->GetStaticMemory(prs_id);
546 } else { 576 } else {
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 hsl.h = tints_[i].h; 1071 hsl.h = tints_[i].h;
1042 hsl.s = tints_[i].s; 1072 hsl.s = tints_[i].s;
1043 hsl.l = tints_[i].l; 1073 hsl.l = tints_[i].l;
1044 return hsl; 1074 return hsl;
1045 } 1075 }
1046 } 1076 }
1047 } 1077 }
1048 1078
1049 return ThemeService::GetDefaultTint(id); 1079 return ThemeService::GetDefaultTint(id);
1050 } 1080 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698