| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/data_pack.h" | 22 #include "ui/base/resource/data_pack.h" |
| 23 #include "ui/base/ui_base_paths.h" | 23 #include "ui/base/ui_base_paths.h" |
| 24 #include "ui/base/ui_base_switches.h" | 24 #include "ui/base/ui_base_switches.h" |
| 25 #include "ui/gfx/codec/jpeg_codec.h" | 25 #include "ui/gfx/codec/jpeg_codec.h" |
| 26 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
| 27 #include "ui/gfx/font.h" | 27 #include "ui/gfx/font.h" |
| 28 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 29 #include "ui/gfx/image/image_skia.h" |
| 29 | 30 |
| 30 namespace ui { | 31 namespace ui { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 // Font sizes relative to base font. | 35 // Font sizes relative to base font. |
| 35 #if defined(OS_CHROMEOS) && defined(CROS_FONTS_USING_BCI) | 36 #if defined(OS_CHROMEOS) && defined(CROS_FONTS_USING_BCI) |
| 36 const int kSmallFontSizeDelta = -3; | 37 const int kSmallFontSizeDelta = -3; |
| 37 const int kMediumFontSizeDelta = 2; | 38 const int kMediumFontSizeDelta = 2; |
| 38 const int kLargeFontSizeDelta = 7; | 39 const int kLargeFontSizeDelta = 7; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { | 235 gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { |
| 235 // Check to see if the image is already in the cache. | 236 // Check to see if the image is already in the cache. |
| 236 { | 237 { |
| 237 base::AutoLock lock_scope(*images_and_fonts_lock_); | 238 base::AutoLock lock_scope(*images_and_fonts_lock_); |
| 238 ImageMap::const_iterator found = images_.find(resource_id); | 239 ImageMap::const_iterator found = images_.find(resource_id); |
| 239 if (found != images_.end()) | 240 if (found != images_.end()) |
| 240 return *found->second; | 241 return *found->second; |
| 241 } | 242 } |
| 242 | 243 |
| 243 DCHECK(!data_packs_.empty()) << "Missing call to SetResourcesDataDLL?"; | 244 DCHECK(!data_packs_.empty()) << "Missing call to SetResourcesDataDLL?"; |
| 244 ScopedVector<const SkBitmap> bitmaps; | 245 gfx::ImageSkia image_skia; |
| 245 for (size_t i = 0; i < data_packs_.size(); ++i) { | 246 for (size_t i = 0; i < data_packs_.size(); ++i) { |
| 246 SkBitmap* bitmap = LoadBitmap(*data_packs_[i], resource_id); | 247 // TODO(pkotwicz): Convert LoadBitmap to return reference instead of |
| 247 if (bitmap) | 248 // pointer. |
| 248 bitmaps.push_back(bitmap); | 249 scoped_ptr<SkBitmap> bitmap(LoadBitmap(*data_packs_[i], resource_id)); |
| 250 if (bitmap.get()) { |
| 251 // ImageSkia adds a reference to bitmap. |
| 252 #if defined(ENABLE_DIP) |
| 253 image_skia.AddBitmapForScale(*bitmap, data_packs_[i]->GetScaleFactor()); |
| 254 #else |
| 255 image_skia.AddBitmapForScale(*bitmap, 1.0f); |
| 256 #endif |
| 257 } |
| 249 } | 258 } |
| 250 | 259 |
| 251 if (bitmaps.empty()) { | 260 if (image_skia.empty()) { |
| 252 LOG(WARNING) << "Unable to load image with id " << resource_id; | 261 LOG(WARNING) << "Unable to load image with id " << resource_id; |
| 253 NOTREACHED(); // Want to assert in debug mode. | 262 NOTREACHED(); // Want to assert in debug mode. |
| 254 // The load failed to retrieve the image; show a debugging red square. | 263 // The load failed to retrieve the image; show a debugging red square. |
| 255 return *GetEmptyImage(); | 264 return *GetEmptyImage(); |
| 256 } | 265 } |
| 257 | 266 |
| 258 // The load was successful, so cache the image. | 267 // The load was successful, so cache the image. |
| 259 base::AutoLock lock_scope(*images_and_fonts_lock_); | 268 base::AutoLock lock_scope(*images_and_fonts_lock_); |
| 260 | 269 |
| 261 // Another thread raced the load and has already cached the image. | 270 // Another thread raced the load and has already cached the image. |
| 262 if (images_.count(resource_id)) | 271 if (images_.count(resource_id)) |
| 263 return *images_[resource_id]; | 272 return *images_[resource_id]; |
| 264 | 273 |
| 265 std::vector<const SkBitmap*> tmp_bitmaps; | 274 gfx::Image* image = new gfx::Image(image_skia); |
| 266 bitmaps.release(&tmp_bitmaps); | |
| 267 // Takes ownership of bitmaps. | |
| 268 gfx::Image* image = new gfx::Image(tmp_bitmaps); | |
| 269 images_[resource_id] = image; | 275 images_[resource_id] = image; |
| 270 return *image; | 276 return *image; |
| 271 } | 277 } |
| 272 | 278 |
| 273 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { | 279 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { |
| 274 return GetNativeImageNamed(resource_id, RTL_DISABLED); | 280 return GetNativeImageNamed(resource_id, RTL_DISABLED); |
| 275 } | 281 } |
| 276 | 282 |
| 277 base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( | 283 base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( |
| 278 int resource_id) const { | 284 int resource_id) const { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 SkBitmap* bitmap = new SkBitmap(); | 412 SkBitmap* bitmap = new SkBitmap(); |
| 407 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); | 413 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); |
| 408 bitmap->allocPixels(); | 414 bitmap->allocPixels(); |
| 409 bitmap->eraseARGB(255, 255, 0, 0); | 415 bitmap->eraseARGB(255, 255, 0, 0); |
| 410 empty_image = new gfx::Image(bitmap); | 416 empty_image = new gfx::Image(bitmap); |
| 411 } | 417 } |
| 412 return empty_image; | 418 return empty_image; |
| 413 } | 419 } |
| 414 | 420 |
| 415 } // namespace ui | 421 } // namespace ui |
| OLD | NEW |