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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // gfx::ImageSkiaSource overrides: | 102 // gfx::ImageSkiaSource overrides: |
103 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 103 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
104 SkBitmap image; | 104 SkBitmap image; |
105 bool fell_back_to_1x = false; | 105 bool fell_back_to_1x = false; |
106 ScaleFactor scale_factor = GetSupportedScaleFactor(scale); | 106 ScaleFactor scale_factor = GetSupportedScaleFactor(scale); |
107 bool found = rb_->LoadBitmap(resource_id_, &scale_factor, | 107 bool found = rb_->LoadBitmap(resource_id_, &scale_factor, |
108 &image, &fell_back_to_1x); | 108 &image, &fell_back_to_1x); |
109 if (!found) | 109 if (!found) |
110 return gfx::ImageSkiaRep(); | 110 return gfx::ImageSkiaRep(); |
111 | 111 |
112 float loaded_image_scale = ui::GetImageScale(scale_factor); | 112 float loaded_image_scale = ui::GetImageScaleForScaleFactor(scale_factor); |
113 | 113 |
114 if (fell_back_to_1x) { | 114 if (fell_back_to_1x) { |
115 // GRIT fell back to the 100% image, so rescale it to the correct size. | 115 // GRIT fell back to the 100% image, so rescale it to the correct size. |
116 image = skia::ImageOperations::Resize( | 116 image = skia::ImageOperations::Resize( |
117 image, | 117 image, |
118 skia::ImageOperations::RESIZE_LANCZOS3, | 118 skia::ImageOperations::RESIZE_LANCZOS3, |
119 gfx::ToCeiledInt(image.width() * scale), | 119 gfx::ToCeiledInt(image.width() * scale), |
120 gfx::ToCeiledInt(image.height() * scale)); | 120 gfx::ToCeiledInt(image.height() * scale)); |
121 // If --highlight-missing-scaled-resources is specified, log the resource | 121 // If --highlight-missing-scaled-resources is specified, log the resource |
122 // id and blend the created resource with red. | 122 // id and blend the created resource with red. |
(...skipping 223 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) || defined(OS_WIN) |
| 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 = GetImageScale(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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 return gfx::PNGCodec::Decode(buf, size, bitmap); | 822 return gfx::PNGCodec::Decode(buf, size, bitmap); |
817 } | 823 } |
818 | 824 |
819 #if !defined(OS_WIN) | 825 #if !defined(OS_WIN) |
820 // static | 826 // static |
821 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, | 827 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, |
822 float loaded_image_scale, | 828 float loaded_image_scale, |
823 float desired_scale) { | 829 float desired_scale) { |
824 return image; | 830 return image; |
825 } | 831 } |
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 | 832 #endif |
836 | 833 |
837 } // namespace ui | 834 } // namespace ui |
OLD | NEW |