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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace ui { | 21 namespace ui { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // 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 |
26 // has a ref count of 1 so the caller must call g_object_unref to free the | 26 // has a ref count of 1 so the caller must call g_object_unref to free the |
27 // memory. | 27 // memory. |
28 GdkPixbuf* LoadPixbuf(base::RefCountedStaticMemory* data, bool rtl_enabled) { | 28 GdkPixbuf* LoadPixbuf(base::RefCountedStaticMemory* data, bool rtl_enabled) { |
29 ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); | 29 ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); |
30 bool ok = data && gdk_pixbuf_loader_write(loader.get(), | 30 bool ok = data && gdk_pixbuf_loader_write(loader.get(), |
31 reinterpret_cast<const guint8*>(data->front()), data->size(), NULL); | 31 data->front_as<guint8>(), data->size(), NULL); |
32 if (!ok) | 32 if (!ok) |
33 return NULL; | 33 return NULL; |
34 // Calling gdk_pixbuf_loader_close forces the data to be parsed by the | 34 // Calling gdk_pixbuf_loader_close forces the data to be parsed by the |
35 // loader. We must do this before calling gdk_pixbuf_loader_get_pixbuf. | 35 // loader. We must do this before calling gdk_pixbuf_loader_get_pixbuf. |
36 ok = gdk_pixbuf_loader_close(loader.get(), NULL); | 36 ok = gdk_pixbuf_loader_close(loader.get(), NULL); |
37 if (!ok) | 37 if (!ok) |
38 return NULL; | 38 return NULL; |
39 GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader.get()); | 39 GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader.get()); |
40 if (!pixbuf) | 40 if (!pixbuf) |
41 return NULL; | 41 return NULL; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 // Another thread raced the load and has already cached the image. | 104 // Another thread raced the load and has already cached the image. |
105 if (images_.count(key)) | 105 if (images_.count(key)) |
106 return images_[key]; | 106 return images_[key]; |
107 | 107 |
108 images_[key] = image; | 108 images_[key] = image; |
109 return images_[key]; | 109 return images_[key]; |
110 } | 110 } |
111 | 111 |
112 } // namespace ui | 112 } // namespace ui |
OLD | NEW |