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 aura::AtomName id; |
Daniel Erat
2012/05/21 22:49:43
nit: shouldn't need the aura:: qualifier here
| |
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) == aura::ATOM_COUNT, |
Daniel Erat
2012/05/21 22:49:43
or here
| |
31 atom_lists_are_same_size); | 31 atom_lists_are_same_size); |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 X11AtomCache* X11AtomCache::GetInstance() { | |
36 return Singleton<X11AtomCache>::get(); | |
37 } | |
38 | |
39 ::Atom X11AtomCache::GetAtom(AtomName name) const { | 35 ::Atom X11AtomCache::GetAtom(AtomName name) const { |
40 std::map<AtomName, ::Atom>::const_iterator it = cached_atoms_.find(name); | 36 std::map<AtomName, ::Atom>::const_iterator it = cached_atoms_.find(name); |
41 DCHECK(it != cached_atoms_.end()); | 37 DCHECK(it != cached_atoms_.end()); |
42 return it->second; | 38 return it->second; |
43 } | 39 } |
44 | 40 |
45 X11AtomCache::X11AtomCache() { | 41 X11AtomCache::X11AtomCache() { |
46 const char* all_names[ATOM_COUNT]; | 42 const char* all_names[ATOM_COUNT]; |
47 ::Atom cached_atoms[ATOM_COUNT]; | 43 ::Atom cached_atoms[ATOM_COUNT]; |
48 | 44 |
49 for (int i = 0; i < ATOM_COUNT; ++i) | 45 for (int i = 0; i < ATOM_COUNT; ++i) |
50 all_names[i] = kAtomList[i].name; | 46 all_names[i] = kAtomList[i].name; |
51 | 47 |
52 // Grab all the atoms we need now to minimize roundtrips to the X11 server. | 48 // Grab all the atoms we need now to minimize roundtrips to the X11 server. |
53 XInternAtoms(base::MessagePumpX::GetDefaultXDisplay(), | 49 XInternAtoms(base::MessagePumpX::GetDefaultXDisplay(), |
54 const_cast<char**>(all_names), ATOM_COUNT, False, | 50 const_cast<char**>(all_names), ATOM_COUNT, False, |
55 cached_atoms); | 51 cached_atoms); |
56 | 52 |
57 for (int i = 0; i < ATOM_COUNT; ++i) | 53 for (int i = 0; i < ATOM_COUNT; ++i) |
58 cached_atoms_.insert(std::make_pair(kAtomList[i].id, cached_atoms[i])); | 54 cached_atoms_.insert(std::make_pair(kAtomList[i].id, cached_atoms[i])); |
59 } | 55 } |
60 | 56 |
61 X11AtomCache::~X11AtomCache() {} | 57 X11AtomCache::~X11AtomCache() {} |
62 | 58 |
63 } // namespace ui | 59 } // namespace aura |
64 | |
65 | |
OLD | NEW |