Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: ui/base/resource/resource_bundle.cc

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as requested Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 #if defined(ENABLE_DIP)
252 image_skia.AddBitmapForScale(*bitmap, data_packs_[i]->GetScaleFactor());
253 #else
254 image_skia.AddBitmapForScale(*bitmap, 1.0f);
255 #endif
256 }
249 } 257 }
250 258
251 if (bitmaps.empty()) { 259 if (image_skia.empty()) {
252 LOG(WARNING) << "Unable to load image with id " << resource_id; 260 LOG(WARNING) << "Unable to load image with id " << resource_id;
253 NOTREACHED(); // Want to assert in debug mode. 261 NOTREACHED(); // Want to assert in debug mode.
254 // The load failed to retrieve the image; show a debugging red square. 262 // The load failed to retrieve the image; show a debugging red square.
255 return *GetEmptyImage(); 263 return *GetEmptyImage();
256 } 264 }
257 265
258 // The load was successful, so cache the image. 266 // The load was successful, so cache the image.
259 base::AutoLock lock_scope(*images_and_fonts_lock_); 267 base::AutoLock lock_scope(*images_and_fonts_lock_);
260 268
261 // Another thread raced the load and has already cached the image. 269 // Another thread raced the load and has already cached the image.
262 if (images_.count(resource_id)) 270 if (images_.count(resource_id))
263 return *images_[resource_id]; 271 return *images_[resource_id];
264 272
265 std::vector<const SkBitmap*> tmp_bitmaps; 273 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; 274 images_[resource_id] = image;
270 return *image; 275 return *image;
271 } 276 }
272 277
273 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { 278 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
274 return GetNativeImageNamed(resource_id, RTL_DISABLED); 279 return GetNativeImageNamed(resource_id, RTL_DISABLED);
275 } 280 }
276 281
277 base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( 282 base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes(
278 int resource_id) const { 283 int resource_id) const {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 SkBitmap* bitmap = new SkBitmap(); 411 SkBitmap* bitmap = new SkBitmap();
407 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); 412 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32);
408 bitmap->allocPixels(); 413 bitmap->allocPixels();
409 bitmap->eraseARGB(255, 255, 0, 0); 414 bitmap->eraseARGB(255, 255, 0, 0);
410 empty_image = new gfx::Image(bitmap); 415 empty_image = new gfx::Image(bitmap);
411 } 416 }
412 return empty_image; 417 return empty_image;
413 } 418 }
414 419
415 } // namespace ui 420 } // namespace ui
OLDNEW
« no previous file with comments | « skia/ext/skia_utils_mac_unittest.mm ('k') | ui/gfx/canvas.h » ('j') | ui/gfx/image/image.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698