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/gfx/x/x11_atom_cache.h" | 5 #include "ui/gfx/x/x11_atom_cache.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
| 8 #include <X11/Xlib.h> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 | 12 |
12 namespace ui { | 13 namespace ui { |
13 | 14 |
14 X11AtomCache::X11AtomCache(Display* xdisplay, const char** to_cache) | 15 X11AtomCache::X11AtomCache(XDisplay* xdisplay, const char** to_cache) |
15 : xdisplay_(xdisplay), | 16 : xdisplay_(xdisplay), |
16 uncached_atoms_allowed_(false) { | 17 uncached_atoms_allowed_(false) { |
17 int cache_count = 0; | 18 int cache_count = 0; |
18 for (const char** i = to_cache; *i != NULL; i++) | 19 for (const char** i = to_cache; *i != NULL; i++) |
19 cache_count++; | 20 cache_count++; |
20 | 21 |
21 scoped_ptr< ::Atom[]> cached_atoms(new ::Atom[cache_count]); | 22 scoped_ptr< Atom[]> cached_atoms(new Atom[cache_count]); |
22 | 23 |
23 // Grab all the atoms we need now to minimize roundtrips to the X11 server. | 24 // Grab all the atoms we need now to minimize roundtrips to the X11 server. |
24 XInternAtoms(xdisplay_, | 25 XInternAtoms(xdisplay_, |
25 const_cast<char**>(to_cache), cache_count, False, | 26 const_cast<char**>(to_cache), cache_count, False, |
26 cached_atoms.get()); | 27 cached_atoms.get()); |
27 | 28 |
28 for (int i = 0; i < cache_count; ++i) | 29 for (int i = 0; i < cache_count; ++i) |
29 cached_atoms_.insert(std::make_pair(to_cache[i], cached_atoms[i])); | 30 cached_atoms_.insert(std::make_pair(to_cache[i], cached_atoms[i])); |
30 } | 31 } |
31 | 32 |
32 X11AtomCache::~X11AtomCache() {} | 33 X11AtomCache::~X11AtomCache() {} |
33 | 34 |
34 ::Atom X11AtomCache::GetAtom(const char* name) const { | 35 Atom X11AtomCache::GetAtom(const char* name) const { |
35 std::map<std::string, ::Atom>::const_iterator it = cached_atoms_.find(name); | 36 std::map<std::string, Atom>::const_iterator it = cached_atoms_.find(name); |
36 | 37 |
37 if (uncached_atoms_allowed_ && it == cached_atoms_.end()) { | 38 if (uncached_atoms_allowed_ && it == cached_atoms_.end()) { |
38 ::Atom atom = XInternAtom(xdisplay_, name, false); | 39 Atom atom = XInternAtom(xdisplay_, name, false); |
39 cached_atoms_.insert(std::make_pair(name, atom)); | 40 cached_atoms_.insert(std::make_pair(name, atom)); |
40 return atom; | 41 return atom; |
41 } | 42 } |
42 | 43 |
43 CHECK(it != cached_atoms_.end()) << " Atom " << name << " not found"; | 44 CHECK(it != cached_atoms_.end()) << " Atom " << name << " not found"; |
44 return it->second; | 45 return it->second; |
45 } | 46 } |
46 | 47 |
47 } // namespace ui | 48 } // namespace ui |
OLD | NEW |