Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: chrome/common/resource_bundle_linux.cc

Issue 100046: More linux ifdef tweaks. This reverts my earlier change (13503).... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/resource_bundle.cc ('k') | chrome/views/widget/root_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
9 #endif
10 8
11 #include "base/base_paths.h" 9 #include "base/base_paths.h"
12 #include "base/data_pack.h" 10 #include "base/data_pack.h"
13 #include "base/file_path.h" 11 #include "base/file_path.h"
14 #include "base/file_util.h" 12 #include "base/file_util.h"
15 #include "base/gfx/gtk_util.h" 13 #include "base/gfx/gtk_util.h"
16 #include "base/logging.h" 14 #include "base/logging.h"
17 #include "base/path_service.h" 15 #include "base/path_service.h"
18 #include "base/string_piece.h" 16 #include "base/string_piece.h"
19 #include "base/string_util.h" 17 #include "base/string_util.h"
20 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/gfx/chrome_font.h" 19 #include "chrome/common/gfx/chrome_font.h"
22 #include "chrome/common/gtk_util.h" 20 #include "chrome/common/gtk_util.h"
23 #include "chrome/common/l10n_util.h" 21 #include "chrome/common/l10n_util.h"
24 #include "SkBitmap.h" 22 #include "SkBitmap.h"
25 23
26 namespace { 24 namespace {
27 25
28 #if defined(TOOLKIT_GTK)
29 // Convert the raw image data into a GdkPixbuf. The GdkPixbuf that is returned 26 // Convert the raw image data into a GdkPixbuf. The GdkPixbuf that is returned
30 // has a ref count of 1 so the caller must call g_object_unref to free the 27 // has a ref count of 1 so the caller must call g_object_unref to free the
31 // memory. 28 // memory.
32 GdkPixbuf* LoadPixbuf(std::vector<unsigned char>& data) { 29 GdkPixbuf* LoadPixbuf(std::vector<unsigned char>& data) {
33 ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); 30 ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new());
34 bool ok = gdk_pixbuf_loader_write(loader.get(), 31 bool ok = gdk_pixbuf_loader_write(loader.get(),
35 static_cast<guint8*>(data.data()), data.size(), NULL); 32 static_cast<guint8*>(data.data()), data.size(), NULL);
36 if (!ok) 33 if (!ok)
37 return NULL; 34 return NULL;
38 // Calling gdk_pixbuf_loader_close forces the data to be parsed by the 35 // Calling gdk_pixbuf_loader_close forces the data to be parsed by the
39 // loader. We must do this before calling gdk_pixbuf_loader_get_pixbuf. 36 // loader. We must do this before calling gdk_pixbuf_loader_get_pixbuf.
40 ok = gdk_pixbuf_loader_close(loader.get(), NULL); 37 ok = gdk_pixbuf_loader_close(loader.get(), NULL);
41 if (!ok) 38 if (!ok)
42 return NULL; 39 return NULL;
43 GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader.get()); 40 GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader.get());
44 if (!pixbuf) 41 if (!pixbuf)
45 return NULL; 42 return NULL;
46 43
47 // The pixbuf is owned by the loader, so add a ref so when we delete the 44 // The pixbuf is owned by the loader, so add a ref so when we delete the
48 // loader (when the ScopedGObject goes out of scope), the pixbuf still 45 // loader (when the ScopedGObject goes out of scope), the pixbuf still
49 // exists. 46 // exists.
50 g_object_ref(pixbuf); 47 g_object_ref(pixbuf);
51 48
52 return pixbuf; 49 return pixbuf;
53 } 50 }
54 #endif
55 51
56 } // namespace 52 } // namespace
57 53
58 ResourceBundle::~ResourceBundle() { 54 ResourceBundle::~ResourceBundle() {
59 FreeImages(); 55 FreeImages();
60 // Free GdkPixbufs. 56 // Free GdkPixbufs.
61 for (GdkPixbufMap::iterator i = gdk_pixbufs_.begin(); 57 for (GdkPixbufMap::iterator i = gdk_pixbufs_.begin();
62 i != gdk_pixbufs_.end(); i++) { 58 i != gdk_pixbufs_.end(); i++) {
63 g_object_unref(i->second); 59 g_object_unref(i->second);
64 } 60 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return string16(); 152 return string16();
157 } 153 }
158 } 154 }
159 155
160 // Data pack encodes strings as UTF16. 156 // Data pack encodes strings as UTF16.
161 string16 msg(reinterpret_cast<const char16*>(data.data()), 157 string16 msg(reinterpret_cast<const char16*>(data.data()),
162 data.length() / 2); 158 data.length() / 2);
163 return msg; 159 return msg;
164 } 160 }
165 161
166 #if defined(TOOLKIT_GTK)
167 GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) { 162 GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) {
168 // Check to see if we already have the pixbuf in the cache. 163 // Check to see if we already have the pixbuf in the cache.
169 { 164 {
170 AutoLock lock_scope(lock_); 165 AutoLock lock_scope(lock_);
171 GdkPixbufMap::const_iterator found = gdk_pixbufs_.find(resource_id); 166 GdkPixbufMap::const_iterator found = gdk_pixbufs_.find(resource_id);
172 if (found != gdk_pixbufs_.end()) 167 if (found != gdk_pixbufs_.end())
173 return found->second; 168 return found->second;
174 } 169 }
175 170
176 171
(...skipping 28 matching lines...) Expand all
205 // This bitmap will be leaked, but this code should never be hit. 200 // This bitmap will be leaked, but this code should never be hit.
206 scoped_ptr<SkBitmap> skia_bitmap(new SkBitmap()); 201 scoped_ptr<SkBitmap> skia_bitmap(new SkBitmap());
207 skia_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32); 202 skia_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 32, 32);
208 skia_bitmap->allocPixels(); 203 skia_bitmap->allocPixels();
209 skia_bitmap->eraseARGB(255, 255, 0, 0); 204 skia_bitmap->eraseARGB(255, 255, 0, 0);
210 empty_bitmap = gfx::GdkPixbufFromSkBitmap(skia_bitmap.get()); 205 empty_bitmap = gfx::GdkPixbufFromSkBitmap(skia_bitmap.get());
211 } 206 }
212 return empty_bitmap; 207 return empty_bitmap;
213 } 208 }
214 } 209 }
215 #endif
OLDNEW
« no previous file with comments | « chrome/common/resource_bundle.cc ('k') | chrome/views/widget/root_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698