Chromium Code Reviews| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 SkBitmap image; | 103 SkBitmap image; |
| 104 bool fell_back_to_1x = false; | 104 bool fell_back_to_1x = false; |
| 105 ScaleFactor scale_factor = GetSupportedScaleFactor(scale); | 105 ScaleFactor scale_factor = GetSupportedScaleFactor(scale); |
| 106 bool found = rb_->LoadBitmap(resource_id_, &scale_factor, | 106 bool found = rb_->LoadBitmap(resource_id_, &scale_factor, |
| 107 &image, &fell_back_to_1x); | 107 &image, &fell_back_to_1x); |
| 108 // If the resource is in the package with SCALE_FACTOR_NONE, it | 108 // If the resource is in the package with SCALE_FACTOR_NONE, it |
| 109 // can be used in any scale factor. The image is maked as "unscaled" | 109 // can be used in any scale factor. The image is maked as "unscaled" |
| 110 // so that the ImageSkia do not automatically scale. | 110 // so that the ImageSkia do not automatically scale. |
| 111 bool unscaled = scale_factor == ui::SCALE_FACTOR_NONE; | 111 bool unscaled = scale_factor == ui::SCALE_FACTOR_NONE; |
| 112 if (unscaled) | 112 if (unscaled) |
| 113 scale_factor = ui::SCALE_FACTOR_100P; | 113 scale_factor = ui::SCALE_FACTOR_100P; |
|
oshima
2014/05/15 23:55:06
would you mind changing this to
if (scale_factor
ananta
2014/05/16 00:13:50
Done.
| |
| 114 | 114 |
| 115 if (!found) | 115 if (!found) |
| 116 return gfx::ImageSkiaRep(); | 116 return gfx::ImageSkiaRep(); |
| 117 | 117 |
| 118 if (fell_back_to_1x) { | 118 if (fell_back_to_1x) { |
| 119 // GRIT fell back to the 100% image, so rescale it to the correct size. | 119 // GRIT fell back to the 100% image, so rescale it to the correct size. |
| 120 image = skia::ImageOperations::Resize( | 120 image = skia::ImageOperations::Resize( |
| 121 image, | 121 image, |
| 122 skia::ImageOperations::RESIZE_LANCZOS3, | 122 skia::ImageOperations::RESIZE_LANCZOS3, |
| 123 gfx::ToCeiledInt(image.width() * scale), | 123 gfx::ToCeiledInt(image.width() * scale), |
| 124 gfx::ToCeiledInt(image.height() * scale)); | 124 gfx::ToCeiledInt(image.height() * scale)); |
| 125 } else if (!unscaled) { | |
| 126 SkBitmap scaled_image = | |
| 127 PlatformScaleImage(image, | |
| 128 ui::GetScaleForScaleFactor(scale_factor), | |
| 129 scale); | |
| 130 if (scaled_image.isNull()) | |
| 131 scale = GetScaleForScaleFactor(scale_factor); | |
| 132 else | |
| 133 image = scaled_image; | |
| 134 } else { | 125 } else { |
| 135 scale = GetScaleForScaleFactor(scale_factor); | 126 scale = GetScaleForScaleFactor(scale_factor); |
| 136 } | 127 } |
| 137 return gfx::ImageSkiaRep(image, unscaled ? 0.0f : scale); | 128 return gfx::ImageSkiaRep(image, unscaled ? 0.0f : scale); |
| 138 } | 129 } |
| 139 | 130 |
| 140 private: | 131 private: |
| 141 ResourceBundle* rb_; | 132 ResourceBundle* rb_; |
| 142 const int resource_id_; | 133 const int resource_id_; |
| 143 | 134 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 if (image.IsEmpty()) { | 343 if (image.IsEmpty()) { |
| 353 DCHECK(!data_packs_.empty()) << | 344 DCHECK(!data_packs_.empty()) << |
| 354 "Missing call to SetResourcesDataDLL?"; | 345 "Missing call to SetResourcesDataDLL?"; |
| 355 | 346 |
| 356 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 347 #if defined(OS_CHROMEOS) || defined(OS_WIN) |
| 357 ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor(); | 348 ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor(); |
| 358 #else | 349 #else |
| 359 ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P; | 350 ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P; |
| 360 #endif | 351 #endif |
| 361 | 352 |
| 362 float scale = GetImageScale(scale_factor_to_load); | |
| 363 | |
| 364 // TODO(oshima): Consider reading the image size from png IHDR chunk and | 353 // TODO(oshima): Consider reading the image size from png IHDR chunk and |
| 365 // skip decoding here and remove #ifdef below. | 354 // skip decoding here and remove #ifdef below. |
| 366 // ResourceBundle::GetSharedInstance() is destroyed after the | 355 // ResourceBundle::GetSharedInstance() is destroyed after the |
| 367 // BrowserMainLoop has finished running. |image_skia| is guaranteed to be | 356 // BrowserMainLoop has finished running. |image_skia| is guaranteed to be |
| 368 // destroyed before the resource bundle is destroyed. | 357 // destroyed before the resource bundle is destroyed. |
| 369 gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id), | 358 gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id), |
| 370 scale); | 359 GetScaleForScaleFactor(scale_factor_to_load)); |
| 371 if (image_skia.isNull()) { | 360 if (image_skia.isNull()) { |
| 372 LOG(WARNING) << "Unable to load image with id " << resource_id; | 361 LOG(WARNING) << "Unable to load image with id " << resource_id; |
| 373 NOTREACHED(); // Want to assert in debug mode. | 362 NOTREACHED(); // Want to assert in debug mode. |
| 374 // The load failed to retrieve the image; show a debugging red square. | 363 // The load failed to retrieve the image; show a debugging red square. |
| 375 return GetEmptyImage(); | 364 return GetEmptyImage(); |
| 376 } | 365 } |
| 377 image_skia.SetReadOnly(); | 366 image_skia.SetReadOnly(); |
| 378 image = gfx::Image(image_skia); | 367 image = gfx::Image(image_skia); |
| 379 } | 368 } |
| 380 | 369 |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 | 795 |
| 807 // static | 796 // static |
| 808 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 797 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 809 size_t size, | 798 size_t size, |
| 810 SkBitmap* bitmap, | 799 SkBitmap* bitmap, |
| 811 bool* fell_back_to_1x) { | 800 bool* fell_back_to_1x) { |
| 812 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 801 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 813 return gfx::PNGCodec::Decode(buf, size, bitmap); | 802 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 814 } | 803 } |
| 815 | 804 |
| 816 #if !defined(OS_WIN) | |
| 817 // static | |
| 818 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, | |
| 819 float loaded_image_scale, | |
| 820 float desired_scale) { | |
| 821 return SkBitmap(); | |
| 822 } | |
| 823 #endif | |
| 824 | |
| 825 } // namespace ui | 805 } // namespace ui |
| OLD | NEW |