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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "ui/base/resource/resource_handle.h" | |
12 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
14 #include "ui/base/gtk/scoped_gobject.h" | 13 #include "ui/base/gtk/scoped_gobject.h" |
| 14 #include "ui/base/layout.h" |
| 15 #include "ui/base/resource/resource_handle.h" |
15 #include "ui/base/ui_base_paths.h" | 16 #include "ui/base/ui_base_paths.h" |
16 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
17 | 18 |
18 #include <gtk/gtk.h> | 19 #include <gtk/gtk.h> |
19 | 20 |
20 namespace ui { | 21 namespace ui { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Convert the raw image data into a GdkPixbuf. The GdkPixbuf that is returned | 25 // Convert the raw image data into a GdkPixbuf. The GdkPixbuf that is returned |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 return path.AppendASCII(pak_name.c_str()); | 59 return path.AppendASCII(pak_name.c_str()); |
59 | 60 |
60 // Return just the name of the pack file. | 61 // Return just the name of the pack file. |
61 return FilePath(pak_name.c_str()); | 62 return FilePath(pak_name.c_str()); |
62 } | 63 } |
63 | 64 |
64 } // namespace | 65 } // namespace |
65 | 66 |
66 void ResourceBundle::LoadCommonResources() { | 67 void ResourceBundle::LoadCommonResources() { |
67 AddDataPack(GetResourcesPakFilePath("chrome.pak"), | 68 AddDataPack(GetResourcesPakFilePath("chrome.pak"), |
68 ResourceHandle::kScaleFactor100x); | 69 SCALE_FACTOR_100P); |
69 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), | 70 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), |
70 ResourceHandle::kScaleFactor100x); | 71 SCALE_FACTOR_100P); |
71 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), | 72 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), |
72 ResourceHandle::kScaleFactor100x); | 73 SCALE_FACTOR_100P); |
73 } | 74 } |
74 | 75 |
75 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { | 76 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
76 // Use the negative |resource_id| for the key for BIDI-aware images. | 77 // Use the negative |resource_id| for the key for BIDI-aware images. |
77 int key = rtl == RTL_ENABLED ? -resource_id : resource_id; | 78 int key = rtl == RTL_ENABLED ? -resource_id : resource_id; |
78 | 79 |
79 // Check to see if the image is already in the cache. | 80 // Check to see if the image is already in the cache. |
80 { | 81 { |
81 base::AutoLock lock_scope(*images_and_fonts_lock_); | 82 base::AutoLock lock_scope(*images_and_fonts_lock_); |
82 if (images_.count(key)) | 83 if (images_.count(key)) |
83 return images_[key]; | 84 return images_[key]; |
84 } | 85 } |
85 | 86 |
86 gfx::Image image; | 87 gfx::Image image; |
87 if (delegate_) | 88 if (delegate_) |
88 image = delegate_->GetNativeImageNamed(resource_id, rtl); | 89 image = delegate_->GetNativeImageNamed(resource_id, rtl); |
89 | 90 |
90 if (image.IsEmpty()) { | 91 if (image.IsEmpty()) { |
91 scoped_refptr<base::RefCountedStaticMemory> data( | 92 scoped_refptr<base::RefCountedStaticMemory> data( |
92 LoadDataResourceBytes(resource_id)); | 93 LoadDataResourceBytes(resource_id, SCALE_FACTOR_100P)); |
93 GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED); | 94 GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED); |
94 | 95 |
95 if (!pixbuf) { | 96 if (!pixbuf) { |
96 LOG(WARNING) << "Unable to load pixbuf with id " << resource_id; | 97 LOG(WARNING) << "Unable to load pixbuf with id " << resource_id; |
97 NOTREACHED(); // Want to assert in debug mode. | 98 NOTREACHED(); // Want to assert in debug mode. |
98 return GetEmptyImage(); | 99 return GetEmptyImage(); |
99 } | 100 } |
100 | 101 |
101 image = gfx::Image(pixbuf); // Takes ownership. | 102 image = gfx::Image(pixbuf); // Takes ownership. |
102 } | 103 } |
103 | 104 |
104 base::AutoLock lock_scope(*images_and_fonts_lock_); | 105 base::AutoLock lock_scope(*images_and_fonts_lock_); |
105 | 106 |
106 // Another thread raced the load and has already cached the image. | 107 // Another thread raced the load and has already cached the image. |
107 if (images_.count(key)) | 108 if (images_.count(key)) |
108 return images_[key]; | 109 return images_[key]; |
109 | 110 |
110 images_[key] = image; | 111 images_[key] = image; |
111 return images_[key]; | 112 return images_[key]; |
112 } | 113 } |
113 | 114 |
114 } // namespace ui | 115 } // namespace ui |
OLD | NEW |