| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "app/resource_bundle.h" | 5 #include "app/resource_bundle.h" |
| 6 | 6 |
| 7 #include "app/gfx/codec/png_codec.h" | 7 #include "app/gfx/codec/png_codec.h" |
| 8 #include "app/gfx/font.h" | 8 #include "app/gfx/font.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 void ResourceBundle::FreeImages() { | 62 void ResourceBundle::FreeImages() { |
| 63 for (SkImageMap::iterator i = skia_images_.begin(); | 63 for (SkImageMap::iterator i = skia_images_.begin(); |
| 64 i != skia_images_.end(); i++) { | 64 i != skia_images_.end(); i++) { |
| 65 delete i->second; | 65 delete i->second; |
| 66 } | 66 } |
| 67 skia_images_.clear(); | 67 skia_images_.clear(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 /* static */ | 70 /* static */ |
| 71 SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { | 71 SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) { |
| 72 std::vector<unsigned char> raw_data, png_data; | 72 std::vector<unsigned char> png_data; |
| 73 bool success = false; | |
| 74 | 73 |
| 75 if (!success) | 74 scoped_refptr<RefCountedMemory> memory( |
| 76 success = LoadResourceBytes(data_handle, resource_id, &raw_data); | 75 LoadResourceBytes(data_handle, resource_id)); |
| 77 if (!success) | 76 if (!memory) |
| 78 return NULL; | 77 return NULL; |
| 79 | 78 |
| 80 // Decode the PNG. | 79 // Decode the PNG. |
| 81 int image_width; | 80 int image_width; |
| 82 int image_height; | 81 int image_height; |
| 83 if (!gfx::PNGCodec::Decode(&raw_data.front(), raw_data.size(), | 82 if (!gfx::PNGCodec::Decode( |
| 84 gfx::PNGCodec::FORMAT_BGRA, | 83 memory->front(), memory->size(), |
| 85 &png_data, &image_width, &image_height)) { | 84 gfx::PNGCodec::FORMAT_BGRA, |
| 85 &png_data, &image_width, &image_height)) { |
| 86 NOTREACHED() << "Unable to decode image resource " << resource_id; | 86 NOTREACHED() << "Unable to decode image resource " << resource_id; |
| 87 return NULL; | 87 return NULL; |
| 88 } | 88 } |
| 89 | 89 |
| 90 return gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(png_data, | 90 return gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(png_data, |
| 91 image_width, | 91 image_width, |
| 92 image_height); | 92 image_height); |
| 93 } | 93 } |
| 94 | 94 |
| 95 std::string ResourceBundle::GetDataResource(int resource_id) { | 95 std::string ResourceBundle::GetDataResource(int resource_id) { |
| 96 return GetRawDataResource(resource_id).as_string(); | 96 return GetRawDataResource(resource_id).as_string(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool ResourceBundle::LoadImageResourceBytes(int resource_id, | 99 RefCountedStaticMemory* ResourceBundle::LoadImageResourceBytes( |
| 100 std::vector<unsigned char>* bytes) { | 100 int resource_id) { |
| 101 return LoadResourceBytes(theme_data_, resource_id, bytes); | 101 return LoadResourceBytes(theme_data_, resource_id); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool ResourceBundle::LoadDataResourceBytes(int resource_id, | 104 RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( |
| 105 std::vector<unsigned char>* bytes) { | 105 int resource_id) { |
| 106 return LoadResourceBytes(resources_data_, resource_id, bytes); | 106 return LoadResourceBytes(resources_data_, resource_id); |
| 107 } | 107 } |
| 108 | 108 |
| 109 SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { | 109 SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { |
| 110 // Check to see if we already have the Skia image in the cache. | 110 // Check to see if we already have the Skia image in the cache. |
| 111 { | 111 { |
| 112 AutoLock lock_scope(lock_); | 112 AutoLock lock_scope(lock_); |
| 113 SkImageMap::const_iterator found = skia_images_.find(resource_id); | 113 SkImageMap::const_iterator found = skia_images_.find(resource_id); |
| 114 if (found != skia_images_.end()) | 114 if (found != skia_images_.end()) |
| 115 return found->second; | 115 return found->second; |
| 116 } | 116 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 case MediumFont: | 193 case MediumFont: |
| 194 return *medium_font_; | 194 return *medium_font_; |
| 195 case MediumBoldFont: | 195 case MediumBoldFont: |
| 196 return *medium_bold_font_; | 196 return *medium_bold_font_; |
| 197 case LargeFont: | 197 case LargeFont: |
| 198 return *large_font_; | 198 return *large_font_; |
| 199 default: | 199 default: |
| 200 return *base_font_; | 200 return *base_font_; |
| 201 } | 201 } |
| 202 } | 202 } |
| OLD | NEW |