| OLD | NEW | 
|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/resource_bundle.h" | 5 #include "chrome/common/resource_bundle.h" | 
| 6 | 6 | 
| 7 #include "base/gfx/png_decoder.h" | 7 #include "base/gfx/png_decoder.h" | 
| 8 #include "base/logging.h" | 8 #include "base/logging.h" | 
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" | 
| 10 #include "chrome/common/gfx/chrome_font.h" | 10 #include "chrome/common/gfx/chrome_font.h" | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 78                                             std::vector<unsigned char>* bytes) { | 78                                             std::vector<unsigned char>* bytes) { | 
| 79   return LoadResourceBytes(theme_data_, resource_id, bytes); | 79   return LoadResourceBytes(theme_data_, resource_id, bytes); | 
| 80 } | 80 } | 
| 81 | 81 | 
| 82 bool ResourceBundle::LoadDataResourceBytes(int resource_id, | 82 bool ResourceBundle::LoadDataResourceBytes(int resource_id, | 
| 83                                            std::vector<unsigned char>* bytes) { | 83                                            std::vector<unsigned char>* bytes) { | 
| 84   return LoadResourceBytes(resources_data_, resource_id, bytes); | 84   return LoadResourceBytes(resources_data_, resource_id, bytes); | 
| 85 } | 85 } | 
| 86 | 86 | 
| 87 SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { | 87 SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { | 
|  | 88 #if defined(OS_WIN) | 
| 88   // Check to see if we already have the Skia image in the cache. | 89   // Check to see if we already have the Skia image in the cache. | 
| 89   { | 90   { | 
| 90     AutoLock lock_scope(lock_); | 91     AutoLock lock_scope(lock_); | 
| 91     SkImageMap::const_iterator found = skia_images_.find(resource_id); | 92     SkImageMap::const_iterator found = skia_images_.find(resource_id); | 
| 92     if (found != skia_images_.end()) | 93     if (found != skia_images_.end()) | 
| 93       return found->second; | 94       return found->second; | 
| 94   } | 95   } | 
| 95 | 96 | 
| 96   scoped_ptr<SkBitmap> bitmap; | 97   scoped_ptr<SkBitmap> bitmap; | 
| 97 | 98 | 
| 98   if (theme_data_) | 99   if (theme_data_) | 
| 99     bitmap.reset(LoadBitmap(theme_data_, resource_id)); | 100     bitmap.reset(LoadBitmap(theme_data_, resource_id)); | 
| 100 | 101 | 
| 101   // If we did not find the bitmap in the theme DLL, try the current one. | 102   // If we did not find the bitmap in the theme DLL, try the current one. | 
| 102   if (!bitmap.get()) | 103   if (!bitmap.get()) | 
| 103     bitmap.reset(LoadBitmap(resources_data_, resource_id)); | 104     bitmap.reset(LoadBitmap(resources_data_, resource_id)); | 
| 104 | 105 | 
| 105   // We loaded successfully.  Cache the Skia version of the bitmap. | 106   // We loaded successfully.  Cache the Skia version of the bitmap. | 
| 106   if (bitmap.get()) { | 107   if (bitmap.get()) { | 
| 107     AutoLock lock_scope(lock_); | 108     AutoLock lock_scope(lock_); | 
| 108 | 109 | 
| 109     // Another thread raced us, and has already cached the skia image. | 110     // Another thread raced us, and has already cached the skia image. | 
| 110     if (skia_images_.count(resource_id)) | 111     if (skia_images_.count(resource_id)) | 
| 111       return skia_images_[resource_id]; | 112       return skia_images_[resource_id]; | 
| 112 | 113 | 
| 113     skia_images_[resource_id] = bitmap.get(); | 114     skia_images_[resource_id] = bitmap.get(); | 
| 114     return bitmap.release(); | 115     return bitmap.release(); | 
| 115   } | 116   } | 
| 116 | 117 | 
|  | 118 #else | 
|  | 119   NOTIMPLEMENTED() << "image resource loading disabled; need data files"; | 
|  | 120 #endif | 
| 117   // We failed to retrieve the bitmap, show a debugging red square. | 121   // We failed to retrieve the bitmap, show a debugging red square. | 
| 118   { | 122   { | 
| 119     LOG(WARNING) << "Unable to load bitmap with id " << resource_id; | 123     LOG(WARNING) << "Unable to load bitmap with id " << resource_id; | 
|  | 124 #if defined(OS_WIN) | 
| 120     NOTREACHED();  // Want to assert in debug mode. | 125     NOTREACHED();  // Want to assert in debug mode. | 
|  | 126 #else | 
|  | 127     // TODO(port): remove this exception | 
|  | 128 #endif | 
| 121 | 129 | 
| 122     AutoLock lock_scope(lock_);  // Guard empty_bitmap initialization. | 130     AutoLock lock_scope(lock_);  // Guard empty_bitmap initialization. | 
| 123 | 131 | 
| 124     static SkBitmap* empty_bitmap = NULL; | 132     static SkBitmap* empty_bitmap = NULL; | 
| 125     if (!empty_bitmap) { | 133     if (!empty_bitmap) { | 
| 126       // The placeholder bitmap is bright red so people notice the problem. | 134       // The placeholder bitmap is bright red so people notice the problem. | 
| 127       // This bitmap will be leaked, but this code should never be hit. | 135       // This bitmap will be leaked, but this code should never be hit. | 
| 128       empty_bitmap = new SkBitmap(); | 136       empty_bitmap = new SkBitmap(); | 
| 129       empty_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); | 137       empty_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); | 
| 130       empty_bitmap->allocPixels(); | 138       empty_bitmap->allocPixels(); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 168     case MediumBoldFont: | 176     case MediumBoldFont: | 
| 169       return *medium_bold_font_; | 177       return *medium_bold_font_; | 
| 170     case LargeFont: | 178     case LargeFont: | 
| 171       return *large_font_; | 179       return *large_font_; | 
| 172     case WebFont: | 180     case WebFont: | 
| 173       return *web_font_; | 181       return *web_font_; | 
| 174     default: | 182     default: | 
| 175       return *base_font_; | 183       return *base_font_; | 
| 176   } | 184   } | 
| 177 } | 185 } | 
| OLD | NEW | 
|---|