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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 /* static */ | 49 /* static */ |
50 ResourceBundle& ResourceBundle::GetSharedInstance() { | 50 ResourceBundle& ResourceBundle::GetSharedInstance() { |
51 // Must call InitSharedInstance before this function. | 51 // Must call InitSharedInstance before this function. |
52 CHECK(g_shared_instance_ != NULL); | 52 CHECK(g_shared_instance_ != NULL); |
53 return *g_shared_instance_; | 53 return *g_shared_instance_; |
54 } | 54 } |
55 | 55 |
56 ResourceBundle::ResourceBundle() | 56 ResourceBundle::ResourceBundle() |
57 : resources_data_(NULL), | 57 : resources_data_(NULL), |
58 locale_resources_data_(NULL), | 58 locale_resources_data_(NULL) { |
59 theme_data_(NULL) { | |
60 } | 59 } |
61 | 60 |
62 void ResourceBundle::FreeImages() { | 61 void ResourceBundle::FreeImages() { |
63 for (SkImageMap::iterator i = skia_images_.begin(); | 62 for (SkImageMap::iterator i = skia_images_.begin(); |
64 i != skia_images_.end(); i++) { | 63 i != skia_images_.end(); i++) { |
65 delete i->second; | 64 delete i->second; |
66 } | 65 } |
67 skia_images_.clear(); | 66 skia_images_.clear(); |
68 } | 67 } |
69 | 68 |
(...skipping 12 matching lines...) Expand all Loading... |
82 | 81 |
83 return new SkBitmap(bitmap); | 82 return new SkBitmap(bitmap); |
84 } | 83 } |
85 | 84 |
86 std::string ResourceBundle::GetDataResource(int resource_id) { | 85 std::string ResourceBundle::GetDataResource(int resource_id) { |
87 return GetRawDataResource(resource_id).as_string(); | 86 return GetRawDataResource(resource_id).as_string(); |
88 } | 87 } |
89 | 88 |
90 RefCountedStaticMemory* ResourceBundle::LoadImageResourceBytes( | 89 RefCountedStaticMemory* ResourceBundle::LoadImageResourceBytes( |
91 int resource_id) { | 90 int resource_id) { |
92 return LoadResourceBytes(theme_data_, resource_id); | 91 return LoadResourceBytes(resources_data_, resource_id); |
93 } | 92 } |
94 | 93 |
95 RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( | 94 RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( |
96 int resource_id) { | 95 int resource_id) { |
97 return LoadResourceBytes(resources_data_, resource_id); | 96 return LoadResourceBytes(resources_data_, resource_id); |
98 } | 97 } |
99 | 98 |
100 SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { | 99 SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { |
101 // Check to see if we already have the Skia image in the cache. | 100 // Check to see if we already have the Skia image in the cache. |
102 { | 101 { |
103 AutoLock lock_scope(lock_); | 102 AutoLock lock_scope(lock_); |
104 SkImageMap::const_iterator found = skia_images_.find(resource_id); | 103 SkImageMap::const_iterator found = skia_images_.find(resource_id); |
105 if (found != skia_images_.end()) | 104 if (found != skia_images_.end()) |
106 return found->second; | 105 return found->second; |
107 } | 106 } |
108 | 107 |
109 scoped_ptr<SkBitmap> bitmap; | 108 scoped_ptr<SkBitmap> bitmap; |
110 | 109 |
111 if (theme_data_) | 110 bitmap.reset(LoadBitmap(resources_data_, resource_id)); |
112 bitmap.reset(LoadBitmap(theme_data_, resource_id)); | |
113 | 111 |
114 // If we did not find the bitmap in the theme DLL, try the current one. | |
115 if (!bitmap.get()) | |
116 bitmap.reset(LoadBitmap(resources_data_, resource_id)); | |
117 | |
118 // We loaded successfully. Cache the Skia version of the bitmap. | |
119 if (bitmap.get()) { | 112 if (bitmap.get()) { |
| 113 // We loaded successfully. Cache the Skia version of the bitmap. |
120 AutoLock lock_scope(lock_); | 114 AutoLock lock_scope(lock_); |
121 | 115 |
122 // Another thread raced us, and has already cached the skia image. | 116 // Another thread raced us, and has already cached the skia image. |
123 if (skia_images_.count(resource_id)) | 117 if (skia_images_.count(resource_id)) |
124 return skia_images_[resource_id]; | 118 return skia_images_[resource_id]; |
125 | 119 |
126 skia_images_[resource_id] = bitmap.get(); | 120 skia_images_[resource_id] = bitmap.get(); |
127 return bitmap.release(); | 121 return bitmap.release(); |
128 } | 122 } |
129 | 123 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 case MediumFont: | 178 case MediumFont: |
185 return *medium_font_; | 179 return *medium_font_; |
186 case MediumBoldFont: | 180 case MediumBoldFont: |
187 return *medium_bold_font_; | 181 return *medium_bold_font_; |
188 case LargeFont: | 182 case LargeFont: |
189 return *large_font_; | 183 return *large_font_; |
190 default: | 184 default: |
191 return *base_font_; | 185 return *base_font_; |
192 } | 186 } |
193 } | 187 } |
OLD | NEW |