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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/data_pack.h" | 19 #include "ui/base/resource/data_pack.h" |
20 #include "ui/base/ui_base_paths.h" | 20 #include "ui/base/ui_base_paths.h" |
21 #include "ui/base/ui_base_switches.h" | 21 #include "ui/base/ui_base_switches.h" |
| 22 #include "ui/gfx/codec/jpeg_codec.h" |
22 #include "ui/gfx/codec/png_codec.h" | 23 #include "ui/gfx/codec/png_codec.h" |
23 #include "ui/gfx/font.h" | 24 #include "ui/gfx/font.h" |
24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
25 | 26 |
26 namespace ui { | 27 namespace ui { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Font sizes relative to base font. | 31 // Font sizes relative to base font. |
31 #if defined(OS_CHROMEOS) && defined(CROS_FONTS_USING_BCI) | 32 #if defined(OS_CHROMEOS) && defined(CROS_FONTS_USING_BCI) |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } | 343 } |
343 | 344 |
344 // static | 345 // static |
345 SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { | 346 SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { |
346 scoped_refptr<RefCountedMemory> memory( | 347 scoped_refptr<RefCountedMemory> memory( |
347 LoadResourceBytes(data_handle, resource_id)); | 348 LoadResourceBytes(data_handle, resource_id)); |
348 if (!memory) | 349 if (!memory) |
349 return NULL; | 350 return NULL; |
350 | 351 |
351 SkBitmap bitmap; | 352 SkBitmap bitmap; |
352 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) { | 353 if (gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) |
353 NOTREACHED() << "Unable to decode theme image resource " << resource_id; | 354 return new SkBitmap(bitmap); |
354 return NULL; | |
355 } | |
356 | 355 |
357 return new SkBitmap(bitmap); | 356 // 99% of our assets are PNGs, however fallback to JPEG. |
| 357 SkBitmap* allocated_bitmap = |
| 358 gfx::JPEGCodec::Decode(memory->front(), memory->size()); |
| 359 if (allocated_bitmap) |
| 360 return allocated_bitmap; |
| 361 |
| 362 NOTREACHED() << "Unable to decode theme image resource " << resource_id; |
| 363 return NULL; |
358 } | 364 } |
359 | 365 |
360 gfx::Image* ResourceBundle::GetEmptyImage() { | 366 gfx::Image* ResourceBundle::GetEmptyImage() { |
361 base::AutoLock lock(*images_and_fonts_lock_); | 367 base::AutoLock lock(*images_and_fonts_lock_); |
362 | 368 |
363 static gfx::Image* empty_image = NULL; | 369 static gfx::Image* empty_image = NULL; |
364 if (!empty_image) { | 370 if (!empty_image) { |
365 // The placeholder bitmap is bright red so people notice the problem. | 371 // The placeholder bitmap is bright red so people notice the problem. |
366 // This bitmap will be leaked, but this code should never be hit. | 372 // This bitmap will be leaked, but this code should never be hit. |
367 SkBitmap* bitmap = new SkBitmap(); | 373 SkBitmap* bitmap = new SkBitmap(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 408 } |
403 | 409 |
404 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( | 410 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( |
405 int resource_id) const { | 411 int resource_id) const { |
406 if (!data_pack_.get()) | 412 if (!data_pack_.get()) |
407 return NULL; | 413 return NULL; |
408 return data_pack_->GetStaticMemory(resource_id); | 414 return data_pack_->GetStaticMemory(resource_id); |
409 } | 415 } |
410 | 416 |
411 } // namespace ui | 417 } // namespace ui |
OLD | NEW |