| 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/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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 363 } |
| 363 | 364 |
| 364 /* static */ | 365 /* static */ |
| 365 SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { | 366 SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { |
| 366 scoped_refptr<RefCountedMemory> memory( | 367 scoped_refptr<RefCountedMemory> memory( |
| 367 LoadResourceBytes(data_handle, resource_id)); | 368 LoadResourceBytes(data_handle, resource_id)); |
| 368 if (!memory) | 369 if (!memory) |
| 369 return NULL; | 370 return NULL; |
| 370 | 371 |
| 371 SkBitmap bitmap; | 372 SkBitmap bitmap; |
| 372 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) { | 373 if (gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) |
| 373 NOTREACHED() << "Unable to decode theme image resource " << resource_id; | 374 return new SkBitmap(bitmap); |
| 374 return NULL; | |
| 375 } | |
| 376 | 375 |
| 377 return new SkBitmap(bitmap); | 376 // 99% of our assets are PNGs, however fallback to JPEG. |
| 377 SkBitmap* allocated_bitmap = |
| 378 gfx::JPEGCodec::Decode(memory->front(), memory->size()); |
| 379 if (allocated_bitmap) |
| 380 return allocated_bitmap; |
| 381 |
| 382 NOTREACHED() << "Unable to decode theme image resource " << resource_id; |
| 383 return NULL; |
| 378 } | 384 } |
| 379 | 385 |
| 380 gfx::Image* ResourceBundle::GetEmptyImage() { | 386 gfx::Image* ResourceBundle::GetEmptyImage() { |
| 381 base::AutoLock lock(*lock_); | 387 base::AutoLock lock(*lock_); |
| 382 | 388 |
| 383 static gfx::Image* empty_image = NULL; | 389 static gfx::Image* empty_image = NULL; |
| 384 if (!empty_image) { | 390 if (!empty_image) { |
| 385 // The placeholder bitmap is bright red so people notice the problem. | 391 // The placeholder bitmap is bright red so people notice the problem. |
| 386 // This bitmap will be leaked, but this code should never be hit. | 392 // This bitmap will be leaked, but this code should never be hit. |
| 387 SkBitmap* bitmap = new SkBitmap(); | 393 SkBitmap* bitmap = new SkBitmap(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 } | 428 } |
| 423 | 429 |
| 424 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( | 430 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory( |
| 425 int resource_id) const { | 431 int resource_id) const { |
| 426 if (!data_pack_.get()) | 432 if (!data_pack_.get()) |
| 427 return NULL; | 433 return NULL; |
| 428 return data_pack_->GetStaticMemory(resource_id); | 434 return data_pack_->GetStaticMemory(resource_id); |
| 429 } | 435 } |
| 430 | 436 |
| 431 } // namespace ui | 437 } // namespace ui |
| OLD | NEW |