| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Check to see if the image is already in the cache. | 112 // Check to see if the image is already in the cache. |
| 113 { | 113 { |
| 114 base::AutoLock lock_scope(*lock_); | 114 base::AutoLock lock_scope(*lock_); |
| 115 ImageMap::const_iterator found = images_.find(resource_id); | 115 ImageMap::const_iterator found = images_.find(resource_id); |
| 116 if (found != images_.end()) | 116 if (found != images_.end()) |
| 117 return *found->second; | 117 return *found->second; |
| 118 } | 118 } |
| 119 | 119 |
| 120 scoped_ptr<SkBitmap> bitmap(LoadBitmap(resources_data_, resource_id)); | 120 scoped_ptr<SkBitmap> bitmap(LoadBitmap(resources_data_, resource_id)); |
| 121 if (bitmap.get()) { | 121 if (bitmap.get()) { |
| 122 // Check if there's a large version of the image as well. |
| 123 scoped_ptr<SkBitmap> large_bitmap; |
| 124 if (large_icon_resources_data_) |
| 125 large_bitmap.reset(LoadBitmap(large_icon_resources_data_, resource_id)); |
| 126 |
| 122 // The load was successful, so cache the image. | 127 // The load was successful, so cache the image. |
| 123 base::AutoLock lock_scope(*lock_); | 128 base::AutoLock lock_scope(*lock_); |
| 124 | 129 |
| 125 // Another thread raced the load and has already cached the image. | 130 // Another thread raced the load and has already cached the image. |
| 126 if (images_.count(resource_id)) | 131 if (images_.count(resource_id)) |
| 127 return *images_[resource_id]; | 132 return *images_[resource_id]; |
| 128 | 133 |
| 129 gfx::Image* image = new gfx::Image(bitmap.release()); | 134 std::vector<const SkBitmap*> bitmaps; |
| 135 bitmaps.push_back(bitmap.release()); |
| 136 if (large_bitmap.get()) |
| 137 bitmaps.push_back(large_bitmap.release()); |
| 138 gfx::Image* image = new gfx::Image(bitmaps); |
| 130 images_[resource_id] = image; | 139 images_[resource_id] = image; |
| 131 return *image; | 140 return *image; |
| 132 } | 141 } |
| 133 | 142 |
| 134 // The load failed to retrieve the image; show a debugging red square. | 143 // The load failed to retrieve the image; show a debugging red square. |
| 135 LOG(WARNING) << "Unable to load image with id " << resource_id; | 144 LOG(WARNING) << "Unable to load image with id " << resource_id; |
| 136 NOTREACHED(); // Want to assert in debug mode. | 145 NOTREACHED(); // Want to assert in debug mode. |
| 137 return *GetEmptyImage(); | 146 return *GetEmptyImage(); |
| 138 } | 147 } |
| 139 | 148 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 192 |
| 184 void ResourceBundle::ReloadFonts() { | 193 void ResourceBundle::ReloadFonts() { |
| 185 base::AutoLock lock_scope(*lock_); | 194 base::AutoLock lock_scope(*lock_); |
| 186 base_font_.reset(); | 195 base_font_.reset(); |
| 187 LoadFontsIfNecessary(); | 196 LoadFontsIfNecessary(); |
| 188 } | 197 } |
| 189 | 198 |
| 190 ResourceBundle::ResourceBundle() | 199 ResourceBundle::ResourceBundle() |
| 191 : lock_(new base::Lock), | 200 : lock_(new base::Lock), |
| 192 resources_data_(NULL), | 201 resources_data_(NULL), |
| 202 large_icon_resources_data_(NULL), |
| 193 locale_resources_data_(NULL) { | 203 locale_resources_data_(NULL) { |
| 194 } | 204 } |
| 195 | 205 |
| 196 void ResourceBundle::FreeImages() { | 206 void ResourceBundle::FreeImages() { |
| 197 STLDeleteContainerPairSecondPointers(images_.begin(), | 207 STLDeleteContainerPairSecondPointers(images_.begin(), |
| 198 images_.end()); | 208 images_.end()); |
| 199 images_.clear(); | 209 images_.clear(); |
| 200 } | 210 } |
| 201 | 211 |
| 202 void ResourceBundle::LoadFontsIfNecessary() { | 212 void ResourceBundle::LoadFontsIfNecessary() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 int resource_id, base::StringPiece* data) const { | 290 int resource_id, base::StringPiece* data) const { |
| 281 return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data); | 291 return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data); |
| 282 } | 292 } |
| 283 | 293 |
| 284 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( | 294 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( |
| 285 int resource_id) const { | 295 int resource_id) const { |
| 286 return data_pack_->GetStaticMemory(resource_id); | 296 return data_pack_->GetStaticMemory(resource_id); |
| 287 } | 297 } |
| 288 | 298 |
| 289 } // namespace ui | 299 } // namespace ui |
| OLD | NEW |