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

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: Updated comment 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
« no previous file with comments | « skia/ext/skia_utils_mac_unittest.mm ('k') | ui/gfx/canvas.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/image/image_skia.h"
27 28
28 namespace ui { 29 namespace ui {
29 30
30 namespace { 31 namespace {
31 32
32 // Font sizes relative to base font. 33 // Font sizes relative to base font.
33 #if defined(OS_CHROMEOS) && defined(CROS_FONTS_USING_BCI) 34 #if defined(OS_CHROMEOS) && defined(CROS_FONTS_USING_BCI)
34 const int kSmallFontSizeDelta = -3; 35 const int kSmallFontSizeDelta = -3;
35 const int kMediumFontSizeDelta = 2; 36 const int kMediumFontSizeDelta = 2;
36 const int kLargeFontSizeDelta = 7; 37 const int kLargeFontSizeDelta = 7;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return images_[resource_id]; 225 return images_[resource_id];
225 } 226 }
226 227
227 gfx::Image image; 228 gfx::Image image;
228 if (delegate_) 229 if (delegate_)
229 image = delegate_->GetImageNamed(resource_id); 230 image = delegate_->GetImageNamed(resource_id);
230 231
231 if (image.IsEmpty()) { 232 if (image.IsEmpty()) {
232 DCHECK(!delegate_ && !data_packs_.empty()) << 233 DCHECK(!delegate_ && !data_packs_.empty()) <<
233 "Missing call to SetResourcesDataDLL?"; 234 "Missing call to SetResourcesDataDLL?";
234 ScopedVector<const SkBitmap> bitmaps; 235 gfx::ImageSkia image_skia;
235 for (size_t i = 0; i < data_packs_.size(); ++i) { 236 for (size_t i = 0; i < data_packs_.size(); ++i) {
236 SkBitmap* bitmap = LoadBitmap(*data_packs_[i], resource_id); 237 scoped_ptr<SkBitmap> bitmap(LoadBitmap(*data_packs_[i], resource_id));
237 if (bitmap) 238 if (bitmap.get()) {
238 bitmaps.push_back(bitmap); 239 #if defined(ENABLE_DIP)
240 image_skia.AddBitmapForScale(*bitmap, data_packs_[i]->GetScaleFactor());
241 #else
242 image_skia.AddBitmapForScale(*bitmap, 1.0f);
243 #endif
244 }
239 } 245 }
240 246
241 if (bitmaps.empty()) { 247 if (image_skia.empty()) {
242 LOG(WARNING) << "Unable to load image with id " << resource_id; 248 LOG(WARNING) << "Unable to load image with id " << resource_id;
243 NOTREACHED(); // Want to assert in debug mode. 249 NOTREACHED(); // Want to assert in debug mode.
244 // The load failed to retrieve the image; show a debugging red square. 250 // The load failed to retrieve the image; show a debugging red square.
245 return GetEmptyImage(); 251 return GetEmptyImage();
246 } 252 }
247 253
248 std::vector<const SkBitmap*> tmp_bitmaps; 254 image = gfx::Image(image_skia);
249 bitmaps.release(&tmp_bitmaps);
250
251 // Takes ownership of bitmaps.
252 image = gfx::Image(tmp_bitmaps);
253 } 255 }
254 256
255 // The load was successful, so cache the image. 257 // The load was successful, so cache the image.
256 base::AutoLock lock_scope(*images_and_fonts_lock_); 258 base::AutoLock lock_scope(*images_and_fonts_lock_);
257 259
258 // Another thread raced the load and has already cached the image. 260 // Another thread raced the load and has already cached the image.
259 if (images_.count(resource_id)) 261 if (images_.count(resource_id))
260 return images_[resource_id]; 262 return images_[resource_id];
261 263
262 images_[resource_id] = image; 264 images_[resource_id] = image;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 SkBitmap bitmap; 470 SkBitmap bitmap;
469 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32); 471 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32);
470 bitmap.allocPixels(); 472 bitmap.allocPixels();
471 bitmap.eraseARGB(255, 255, 0, 0); 473 bitmap.eraseARGB(255, 255, 0, 0);
472 empty_image_ = gfx::Image(bitmap); 474 empty_image_ = gfx::Image(bitmap);
473 } 475 }
474 return empty_image_; 476 return empty_image_;
475 } 477 }
476 478
477 } // namespace ui 479 } // namespace ui
OLDNEW
« no previous file with comments | « skia/ext/skia_utils_mac_unittest.mm ('k') | ui/gfx/canvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698