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/x/x11_atom_cache.h" | 5 #include "ui/aura/x11_atom_cache.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 | 8 |
9 #include "base/message_pump_x.h" | 9 #include "base/message_pump_x.h" |
10 | 10 |
11 namespace ui { | 11 namespace aura { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // A list of atoms that we'll intern on host creation to save roundtrips to the | 15 // A list of atoms that we'll intern on host creation to save roundtrips to the |
16 // X11 server. Must be kept in sync with AtomCache::AtomName | 16 // X11 server. Must be kept in sync with AtomCache::AtomName |
17 struct AtomInfo { | 17 struct AtomInfo { |
18 ui::AtomName id; | 18 AtomName id; |
19 const char* name; | 19 const char* name; |
20 } const kAtomList[] = { | 20 } const kAtomList[] = { |
21 { ATOM_WM_DELETE_WINDOW, "WM_DELETE_WINDOW" }, | 21 { ATOM_WM_DELETE_WINDOW, "WM_DELETE_WINDOW" }, |
22 { ATOM__NET_WM_MOVERESIZE, "_NET_WM_MOVERESIZE" }, | 22 { ATOM__NET_WM_MOVERESIZE, "_NET_WM_MOVERESIZE" }, |
23 { ATOM__NET_WM_PING, "_NET_WM_PING" }, | 23 { ATOM__NET_WM_PING, "_NET_WM_PING" }, |
24 { ATOM__NET_WM_PID, "_NET_WM_PID" }, | 24 { ATOM__NET_WM_PID, "_NET_WM_PID" }, |
25 { ATOM_WM_S0, "WM_S0" }, | 25 { ATOM_WM_S0, "WM_S0" }, |
26 { ATOM__MOTIF_WM_HINTS, "_MOTIF_WM_HINTS" } | 26 { ATOM__MOTIF_WM_HINTS, "_MOTIF_WM_HINTS" } |
27 }; | 27 }; |
28 | 28 |
29 // Our lists need to stay in sync here. | 29 // Our lists need to stay in sync here. |
30 COMPILE_ASSERT(arraysize(kAtomList) == ui::ATOM_COUNT, | 30 COMPILE_ASSERT(arraysize(kAtomList) == ATOM_COUNT, atom_lists_are_same_size); |
31 atom_lists_are_same_size); | |
32 | 31 |
33 } // namespace | 32 } // namespace |
34 | 33 |
35 X11AtomCache* X11AtomCache::GetInstance() { | |
36 return Singleton<X11AtomCache>::get(); | |
37 } | |
38 | |
39 ::Atom X11AtomCache::GetAtom(AtomName name) const { | 34 ::Atom X11AtomCache::GetAtom(AtomName name) const { |
40 std::map<AtomName, ::Atom>::const_iterator it = cached_atoms_.find(name); | 35 std::map<AtomName, ::Atom>::const_iterator it = cached_atoms_.find(name); |
41 DCHECK(it != cached_atoms_.end()); | 36 DCHECK(it != cached_atoms_.end()); |
42 return it->second; | 37 return it->second; |
43 } | 38 } |
44 | 39 |
45 X11AtomCache::X11AtomCache() { | 40 X11AtomCache::X11AtomCache() { |
46 const char* all_names[ATOM_COUNT]; | 41 const char* all_names[ATOM_COUNT]; |
47 ::Atom cached_atoms[ATOM_COUNT]; | 42 ::Atom cached_atoms[ATOM_COUNT]; |
48 | 43 |
49 for (int i = 0; i < ATOM_COUNT; ++i) | 44 for (int i = 0; i < ATOM_COUNT; ++i) |
50 all_names[i] = kAtomList[i].name; | 45 all_names[i] = kAtomList[i].name; |
51 | 46 |
52 // Grab all the atoms we need now to minimize roundtrips to the X11 server. | 47 // Grab all the atoms we need now to minimize roundtrips to the X11 server. |
53 XInternAtoms(base::MessagePumpX::GetDefaultXDisplay(), | 48 XInternAtoms(base::MessagePumpX::GetDefaultXDisplay(), |
54 const_cast<char**>(all_names), ATOM_COUNT, False, | 49 const_cast<char**>(all_names), ATOM_COUNT, False, |
55 cached_atoms); | 50 cached_atoms); |
56 | 51 |
57 for (int i = 0; i < ATOM_COUNT; ++i) | 52 for (int i = 0; i < ATOM_COUNT; ++i) |
58 cached_atoms_.insert(std::make_pair(kAtomList[i].id, cached_atoms[i])); | 53 cached_atoms_.insert(std::make_pair(kAtomList[i].id, cached_atoms[i])); |
59 } | 54 } |
60 | 55 |
61 X11AtomCache::~X11AtomCache() {} | 56 X11AtomCache::~X11AtomCache() {} |
62 | 57 |
63 } // namespace ui | 58 } // namespace aura |
64 | |
65 | |
OLD | NEW |