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 "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/big_endian.h" | 9 #include "base/big_endian.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 346 } |
347 | 347 |
348 gfx::Image image; | 348 gfx::Image image; |
349 if (delegate_) | 349 if (delegate_) |
350 image = delegate_->GetImageNamed(resource_id); | 350 image = delegate_->GetImageNamed(resource_id); |
351 | 351 |
352 if (image.IsEmpty()) { | 352 if (image.IsEmpty()) { |
353 DCHECK(!data_packs_.empty()) << | 353 DCHECK(!data_packs_.empty()) << |
354 "Missing call to SetResourcesDataDLL?"; | 354 "Missing call to SetResourcesDataDLL?"; |
355 | 355 |
356 float scale = PlatformGetImageScale(); | 356 #if defined(OS_CHROMEOS) |
| 357 ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor(); |
| 358 #else |
| 359 ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P; |
| 360 #endif |
| 361 |
| 362 float scale = PlatformGetImageScale(scale_factor_to_load); |
357 | 363 |
358 // TODO(oshima): Consider reading the image size from png IHDR chunk and | 364 // TODO(oshima): Consider reading the image size from png IHDR chunk and |
359 // skip decoding here and remove #ifdef below. | 365 // skip decoding here and remove #ifdef below. |
360 // ResourceBundle::GetSharedInstance() is destroyed after the | 366 // ResourceBundle::GetSharedInstance() is destroyed after the |
361 // BrowserMainLoop has finished running. |image_skia| is guaranteed to be | 367 // BrowserMainLoop has finished running. |image_skia| is guaranteed to be |
362 // destroyed before the resource bundle is destroyed. | 368 // destroyed before the resource bundle is destroyed. |
363 gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id), | 369 gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id), |
364 scale); | 370 scale); |
365 if (image_skia.isNull()) { | 371 if (image_skia.isNull()) { |
366 LOG(WARNING) << "Unable to load image with id " << resource_id; | 372 LOG(WARNING) << "Unable to load image with id " << resource_id; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 } | 526 } |
521 | 527 |
522 ScaleFactor ResourceBundle::GetMaxScaleFactor() const { | 528 ScaleFactor ResourceBundle::GetMaxScaleFactor() const { |
523 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 529 #if defined(OS_CHROMEOS) || defined(OS_WIN) |
524 return max_scale_factor_; | 530 return max_scale_factor_; |
525 #else | 531 #else |
526 return GetSupportedScaleFactors().back(); | 532 return GetSupportedScaleFactors().back(); |
527 #endif | 533 #endif |
528 } | 534 } |
529 | 535 |
| 536 #if !defined(OS_WIN) |
| 537 // static |
| 538 float ResourceBundle::PlatformGetImageScale( |
| 539 ui::ScaleFactor scale_factor) { |
| 540 return GetImageScale(scale_factor); |
| 541 } |
| 542 #endif |
| 543 |
530 ResourceBundle::ResourceBundle(Delegate* delegate) | 544 ResourceBundle::ResourceBundle(Delegate* delegate) |
531 : delegate_(delegate), | 545 : delegate_(delegate), |
532 images_and_fonts_lock_(new base::Lock), | 546 images_and_fonts_lock_(new base::Lock), |
533 locale_resources_data_lock_(new base::Lock), | 547 locale_resources_data_lock_(new base::Lock), |
534 max_scale_factor_(SCALE_FACTOR_100P) { | 548 max_scale_factor_(SCALE_FACTOR_100P) { |
535 } | 549 } |
536 | 550 |
537 ResourceBundle::~ResourceBundle() { | 551 ResourceBundle::~ResourceBundle() { |
538 FreeImages(); | 552 FreeImages(); |
539 UnloadLocaleResources(); | 553 UnloadLocaleResources(); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 return gfx::PNGCodec::Decode(buf, size, bitmap); | 830 return gfx::PNGCodec::Decode(buf, size, bitmap); |
817 } | 831 } |
818 | 832 |
819 #if !defined(OS_WIN) | 833 #if !defined(OS_WIN) |
820 // static | 834 // static |
821 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, | 835 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, |
822 float loaded_image_scale, | 836 float loaded_image_scale, |
823 float desired_scale) { | 837 float desired_scale) { |
824 return image; | 838 return image; |
825 } | 839 } |
826 | |
827 float ResourceBundle::PlatformGetImageScale() { | |
828 #if defined(OS_CHROMEOS) | |
829 ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor(); | |
830 #else | |
831 ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P; | |
832 #endif | |
833 return GetImageScale(scale_factor_to_load); | |
834 } | |
835 #endif | 840 #endif |
836 | 841 |
837 } // namespace ui | 842 } // namespace ui |
OLD | NEW |