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

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

Issue 10494013: Add flag which shows missing 2x resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | « no previous file | ui/base/ui_base_switches.h » ('j') | ui/base/ui_base_switches.h » ('J')
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 "skia/ext/image_operations.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/layout.h" 23 #include "ui/base/layout.h"
23 #include "ui/base/resource/data_pack.h" 24 #include "ui/base/resource/data_pack.h"
24 #include "ui/base/ui_base_paths.h" 25 #include "ui/base/ui_base_paths.h"
25 #include "ui/base/ui_base_switches.h" 26 #include "ui/base/ui_base_switches.h"
26 #include "ui/gfx/codec/jpeg_codec.h" 27 #include "ui/gfx/codec/jpeg_codec.h"
27 #include "ui/gfx/codec/png_codec.h" 28 #include "ui/gfx/codec/png_codec.h"
28 #include "ui/gfx/image/image_skia.h" 29 #include "ui/gfx/image/image_skia.h"
29 #include "ui/gfx/screen.h" 30 #include "ui/gfx/screen.h"
31 #include "ui/gfx/skbitmap_operations.h"
30 32
31 namespace ui { 33 namespace ui {
32 34
33 namespace { 35 namespace {
34 36
35 // Font sizes relative to base font. 37 // Font sizes relative to base font.
36 #if defined(OS_CHROMEOS) && defined(CROS_FONTS_USING_BCI) 38 #if defined(OS_CHROMEOS) && defined(CROS_FONTS_USING_BCI)
37 const int kSmallFontSizeDelta = -3; 39 const int kSmallFontSizeDelta = -3;
38 const int kMediumFontSizeDelta = 2; 40 const int kMediumFontSizeDelta = 2;
39 const int kLargeFontSizeDelta = 7; 41 const int kLargeFontSizeDelta = 7;
40 #else 42 #else
41 const int kSmallFontSizeDelta = -2; 43 const int kSmallFontSizeDelta = -2;
42 const int kMediumFontSizeDelta = 3; 44 const int kMediumFontSizeDelta = 3;
43 const int kLargeFontSizeDelta = 8; 45 const int kLargeFontSizeDelta = 8;
44 #endif 46 #endif
45 47
48 // Creates a 2x resource if the 2x resource is missing from |image| or is the
49 // incorrect size. Blends the created resource with red to make it
50 // distinguishable from bitmaps in the resource pak.
51 void Create2xResourceIfMissing(gfx::ImageSkia image) {
52 CommandLine* command_line = CommandLine::ForCurrentProcess();
53 if (command_line->HasSwitch(
54 switches::kHighlightMissing2xResources) &&
55 command_line->HasSwitch(switches::kLoad2xResources) &&
56 !image.HasBitmapForScale(2.0f)) {
57 float bitmap_scale;
sky 2012/06/08 03:01:21 Why don't you also log.
58 SkBitmap bitmap = image.GetBitmapForScale(2.0f, &bitmap_scale);
59 SkBitmap bitmap2x = skia::ImageOperations::Resize(bitmap,
60 skia::ImageOperations::RESIZE_LANCZOS3,
61 image.width() * 2, image.height() * 2);
62
63 SkBitmap mask;
64 mask.setConfig(SkBitmap::kARGB_8888_Config,
65 bitmap2x.width(),
66 bitmap2x.height());
67 mask.allocPixels();
68 mask.eraseColor(SK_ColorRED);
69 SkBitmap result = SkBitmapOperations::CreateBlendedBitmap(bitmap2x, mask,
70 0.2);
71 image.AddBitmapForScale(result, 2.0f);
72 }
73 }
74
46 } // namespace 75 } // namespace
47 76
48 ResourceBundle* ResourceBundle::g_shared_instance_ = NULL; 77 ResourceBundle* ResourceBundle::g_shared_instance_ = NULL;
49 78
50 // static 79 // static
51 std::string ResourceBundle::InitSharedInstanceWithLocale( 80 std::string ResourceBundle::InitSharedInstanceWithLocale(
52 const std::string& pref_locale, Delegate* delegate) { 81 const std::string& pref_locale, Delegate* delegate) {
53 DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice"; 82 DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice";
54 g_shared_instance_ = new ResourceBundle(delegate); 83 g_shared_instance_ = new ResourceBundle(delegate);
55 84
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 281 }
253 } 282 }
254 283
255 if (image_skia.empty()) { 284 if (image_skia.empty()) {
256 LOG(WARNING) << "Unable to load image with id " << resource_id; 285 LOG(WARNING) << "Unable to load image with id " << resource_id;
257 NOTREACHED(); // Want to assert in debug mode. 286 NOTREACHED(); // Want to assert in debug mode.
258 // The load failed to retrieve the image; show a debugging red square. 287 // The load failed to retrieve the image; show a debugging red square.
259 return GetEmptyImage(); 288 return GetEmptyImage();
260 } 289 }
261 290
291 Create2xResourceIfMissing(image_skia);
292
262 image = gfx::Image(image_skia); 293 image = gfx::Image(image_skia);
263 } 294 }
264 295
265 // The load was successful, so cache the image. 296 // The load was successful, so cache the image.
266 base::AutoLock lock_scope(*images_and_fonts_lock_); 297 base::AutoLock lock_scope(*images_and_fonts_lock_);
267 298
268 // Another thread raced the load and has already cached the image. 299 // Another thread raced the load and has already cached the image.
269 if (images_.count(resource_id)) 300 if (images_.count(resource_id))
270 return images_[resource_id]; 301 return images_[resource_id];
271 302
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 SkBitmap bitmap; 524 SkBitmap bitmap;
494 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32); 525 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32);
495 bitmap.allocPixels(); 526 bitmap.allocPixels();
496 bitmap.eraseARGB(255, 255, 0, 0); 527 bitmap.eraseARGB(255, 255, 0, 0);
497 empty_image_ = gfx::Image(bitmap); 528 empty_image_ = gfx::Image(bitmap);
498 } 529 }
499 return empty_image_; 530 return empty_image_;
500 } 531 }
501 532
502 } // namespace ui 533 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/base/ui_base_switches.h » ('j') | ui/base/ui_base_switches.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698