OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 pack->BuildSourceImagesArray(file_paths); | 429 pack->BuildSourceImagesArray(file_paths); |
430 | 430 |
431 if (!pack->LoadRawBitmapsTo(file_paths, &pack->images_on_ui_thread_)) | 431 if (!pack->LoadRawBitmapsTo(file_paths, &pack->images_on_ui_thread_)) |
432 return NULL; | 432 return NULL; |
433 | 433 |
434 pack->CopyImagesTo(pack->images_on_ui_thread_, &pack->images_on_file_thread_); | 434 pack->CopyImagesTo(pack->images_on_ui_thread_, &pack->images_on_file_thread_); |
435 | 435 |
436 pack->CreateImages(&pack->images_on_ui_thread_); | 436 pack->CreateImages(&pack->images_on_ui_thread_); |
437 pack->CreateImages(&pack->images_on_file_thread_); | 437 pack->CreateImages(&pack->images_on_file_thread_); |
438 | 438 |
439 // Make sure the images_on_file_thread_ has bitmaps for supported | |
440 // scale factors before passing to FILE thread. | |
441 for (ImageCache::iterator it = pack->images_on_file_thread_.begin(); | |
442 it != pack->images_on_file_thread_.end(); ++it) { | |
443 gfx::ImageSkia* image_skia = | |
444 const_cast<gfx::ImageSkia*>(it->second->ToImageSkia()); | |
445 image_skia->EnsureRepsForSupportedScaleFactors(); | |
446 image_skia->DeleteSource(); | |
447 } | |
448 | |
439 // For M22, as it is not possible to easily determine which scale factors are | 449 // For M22, as it is not possible to easily determine which scale factors are |
440 // in use, assume that the 1x scale factor is in use. | 450 // in use, assume that the 1x scale factor is in use. |
441 std::vector<ui::ScaleFactor> scale_factors_in_use; | 451 std::vector<ui::ScaleFactor> scale_factors_in_use; |
442 scale_factors_in_use.push_back(ui::SCALE_FACTOR_100P); | 452 scale_factors_in_use.push_back(ui::SCALE_FACTOR_100P); |
443 pack->GenerateImageReps(scale_factors_in_use); | 453 pack->GenerateImageReps(scale_factors_in_use); |
444 | 454 |
445 // The BrowserThemePack is now in a consistent state. | 455 // The BrowserThemePack is now in a consistent state. |
446 return pack; | 456 return pack; |
447 } | 457 } |
448 | 458 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 source_count * sizeof(*source_images_)); | 547 source_count * sizeof(*source_images_)); |
538 | 548 |
539 // Store results of GetScaleFactorsAsString() in std::string as | 549 // Store results of GetScaleFactorsAsString() in std::string as |
540 // base::StringPiece does not copy data in constructor. | 550 // base::StringPiece does not copy data in constructor. |
541 std::string scale_factors_string = GetScaleFactorsAsString(scale_factors_); | 551 std::string scale_factors_string = GetScaleFactorsAsString(scale_factors_); |
542 resources[kScaleFactorsID] = scale_factors_string; | 552 resources[kScaleFactorsID] = scale_factors_string; |
543 | 553 |
544 AddRawImagesTo(image_memory_, &resources); | 554 AddRawImagesTo(image_memory_, &resources); |
545 | 555 |
546 RawImages reencoded_images; | 556 RawImages reencoded_images; |
547 RepackImages(images_on_file_thread_, &reencoded_images); | 557 RepackImages(images_on_file_thread_, &reencoded_images); |
oshima
2012/08/23 07:23:14
Peter, is it ok to delete images in image_on_file_
| |
548 AddRawImagesTo(reencoded_images, &resources); | 558 AddRawImagesTo(reencoded_images, &resources); |
549 | 559 |
550 return ui::DataPack::WritePack(path, resources, ui::DataPack::BINARY); | 560 return ui::DataPack::WritePack(path, resources, ui::DataPack::BINARY); |
551 } | 561 } |
552 | 562 |
553 bool BrowserThemePack::GetTint(int id, color_utils::HSL* hsl) const { | 563 bool BrowserThemePack::GetTint(int id, color_utils::HSL* hsl) const { |
554 if (tints_) { | 564 if (tints_) { |
555 for (int i = 0; i < kTintArraySize; ++i) { | 565 for (int i = 0; i < kTintArraySize; ++i) { |
556 if (tints_[i].id == id) { | 566 if (tints_[i].id == id) { |
557 hsl->h = tints_[i].h; | 567 hsl->h = tints_[i].h; |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1224 ui::ScaleFactor scale_factor) const { | 1234 ui::ScaleFactor scale_factor) const { |
1225 if (prs_id < 0) | 1235 if (prs_id < 0) |
1226 return -1; | 1236 return -1; |
1227 | 1237 |
1228 for (size_t i = 0; i < scale_factors_.size(); ++i) { | 1238 for (size_t i = 0; i < scale_factors_.size(); ++i) { |
1229 if (scale_factors_[i] == scale_factor) | 1239 if (scale_factors_[i] == scale_factor) |
1230 return static_cast<int>(kPersistingImagesLength * i) + prs_id; | 1240 return static_cast<int>(kPersistingImagesLength * i) + prs_id; |
1231 } | 1241 } |
1232 return -1; | 1242 return -1; |
1233 } | 1243 } |
OLD | NEW |