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); | |
113 | |
114 if (fell_back_to_1x) { | 112 if (fell_back_to_1x) { |
115 // GRIT fell back to the 100% image, so rescale it to the correct size. | 113 // GRIT fell back to the 100% image, so rescale it to the correct size. |
116 image = skia::ImageOperations::Resize( | 114 image = skia::ImageOperations::Resize( |
117 image, | 115 image, |
118 skia::ImageOperations::RESIZE_LANCZOS3, | 116 skia::ImageOperations::RESIZE_LANCZOS3, |
119 gfx::ToCeiledInt(image.width() * scale), | 117 gfx::ToCeiledInt(image.width() * scale), |
120 gfx::ToCeiledInt(image.height() * scale)); | 118 gfx::ToCeiledInt(image.height() * scale)); |
121 // If --highlight-missing-scaled-resources is specified, log the resource | 119 // If --highlight-missing-scaled-resources is specified, log the resource |
122 // id and blend the created resource with red. | 120 // id and blend the created resource with red. |
123 if (ShouldHighlightMissingScaledResources()) { | 121 if (ShouldHighlightMissingScaledResources()) { |
124 LOG(ERROR) << "Missing " << scale << "x scaled resource. id=" | 122 LOG(ERROR) << "Missing " << scale << "x scaled resource. id=" |
125 << resource_id_; | 123 << resource_id_; |
126 | 124 |
127 SkBitmap mask; | 125 SkBitmap mask; |
128 mask.setConfig(SkBitmap::kARGB_8888_Config, | 126 mask.setConfig(SkBitmap::kARGB_8888_Config, |
129 image.width(), image.height()); | 127 image.width(), image.height()); |
130 mask.allocPixels(); | 128 mask.allocPixels(); |
131 mask.eraseColor(SK_ColorRED); | 129 mask.eraseColor(SK_ColorRED); |
132 image = SkBitmapOperations::CreateBlendedBitmap(image, mask, 0.2); | 130 image = SkBitmapOperations::CreateBlendedBitmap(image, mask, 0.2); |
133 } | 131 } |
134 } else { | 132 } else { |
135 image = PlatformScaleImage(image, loaded_image_scale, scale); | 133 image = PlatformScaleImage(image, ui::g_kScaleFactorScales[scale_factor], |
| 134 scale); |
136 } | 135 } |
137 return gfx::ImageSkiaRep(image, scale); | 136 return gfx::ImageSkiaRep(image, scale); |
138 } | 137 } |
139 | 138 |
140 private: | 139 private: |
141 ResourceBundle* rb_; | 140 ResourceBundle* rb_; |
142 const int resource_id_; | 141 const int resource_id_; |
143 | 142 |
144 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource); | 143 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource); |
145 }; | 144 }; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 345 } |
347 | 346 |
348 gfx::Image image; | 347 gfx::Image image; |
349 if (delegate_) | 348 if (delegate_) |
350 image = delegate_->GetImageNamed(resource_id); | 349 image = delegate_->GetImageNamed(resource_id); |
351 | 350 |
352 if (image.IsEmpty()) { | 351 if (image.IsEmpty()) { |
353 DCHECK(!data_packs_.empty()) << | 352 DCHECK(!data_packs_.empty()) << |
354 "Missing call to SetResourcesDataDLL?"; | 353 "Missing call to SetResourcesDataDLL?"; |
355 | 354 |
356 float scale = PlatformGetImageScale(); | 355 #if defined(OS_CHROMEOS) || defined(OS_WIN) |
| 356 ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor(); |
| 357 #else |
| 358 ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P; |
| 359 #endif |
| 360 |
| 361 float scale = GetImageScale(scale_factor_to_load); |
357 | 362 |
358 // TODO(oshima): Consider reading the image size from png IHDR chunk and | 363 // TODO(oshima): Consider reading the image size from png IHDR chunk and |
359 // skip decoding here and remove #ifdef below. | 364 // skip decoding here and remove #ifdef below. |
360 // ResourceBundle::GetSharedInstance() is destroyed after the | 365 // ResourceBundle::GetSharedInstance() is destroyed after the |
361 // BrowserMainLoop has finished running. |image_skia| is guaranteed to be | 366 // BrowserMainLoop has finished running. |image_skia| is guaranteed to be |
362 // destroyed before the resource bundle is destroyed. | 367 // destroyed before the resource bundle is destroyed. |
363 gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id), | 368 gfx::ImageSkia image_skia(new ResourceBundleImageSource(this, resource_id), |
364 scale); | 369 scale); |
365 if (image_skia.isNull()) { | 370 if (image_skia.isNull()) { |
366 LOG(WARNING) << "Unable to load image with id " << resource_id; | 371 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); | 821 return gfx::PNGCodec::Decode(buf, size, bitmap); |
817 } | 822 } |
818 | 823 |
819 #if !defined(OS_WIN) | 824 #if !defined(OS_WIN) |
820 // static | 825 // static |
821 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, | 826 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, |
822 float loaded_image_scale, | 827 float loaded_image_scale, |
823 float desired_scale) { | 828 float desired_scale) { |
824 return image; | 829 return image; |
825 } | 830 } |
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 | 831 #endif |
836 | 832 |
837 } // namespace ui | 833 } // namespace ui |
OLD | NEW |