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

Side by Side Diff: ui/gfx/x/x11_atom_cache.cc

Issue 2914103002: Remove usages of XInternAtom (Closed)
Patch Set: Address sadrul and sergeyu comments Created 3 years, 6 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
« no previous file with comments | « ui/gfx/x/x11_atom_cache.h ('k') | ui/platform_window/x11/x11_window_base.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) 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 #include <X11/Xlib.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/singleton.h"
14
15 namespace {
16
17 const char* kAtomsToCache[] = {"Abs Dbl End Timestamp",
18 "Abs Dbl Fling X Velocity",
19 "Abs Dbl Fling Y Velocity",
20 "Abs Dbl Metrics Data 1",
21 "Abs Dbl Metrics Data 2",
22 "Abs Dbl Ordinal X",
23 "Abs Dbl Ordinal Y",
24 "Abs Dbl Start Timestamp",
25 "Abs Finger Count",
26 "Abs Fling State",
27 "Abs Metrics Type",
28 "Abs MT Orientation",
29 "Abs MT Position X",
30 "Abs MT Position Y",
31 "Abs MT Pressure",
32 "Abs MT Touch Major",
33 "Abs MT Touch Minor",
34 "Abs MT Tracking ID",
35 "application/octet-stream",
36 "application/vnd.chromium.test",
37 "ATOM",
38 "ATOM_PAIR",
39 "CARDINAL",
40 "CHECK",
41 "_CHROME_DISPLAY_INTERNAL",
42 "_CHROME_DISPLAY_ROTATION",
43 "_CHROME_DISPLAY_SCALE_FACTOR",
44 "CHOME_SELECTION",
45 "CHROME_SELECTION",
46 "_CHROMIUM_DRAG_RECEIVER",
47 "chromium/filename",
48 "CHROMIUM_TIMESTAMP",
49 "chromium/x-bookmark-entries",
50 "chromium/x-browser-actions",
51 "chromium/x-file-system-files",
52 "chromium/x-pepper-custom-data",
53 "chromium/x-renderer-taint",
54 "chromium/x-web-custom-data",
55 "chromium/x-webkit-paste",
56 "CLIPBOARD",
57 "CLIPBOARD_MANAGER",
58 "Content Protection",
59 "Desired",
60 "Device Node",
61 "Device Product ID",
62 "EDID",
63 "Enabled",
64 "FAKE_SELECTION",
65 "Full aspect",
66 "_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED",
67 "_ICC_PROFILE",
68 "image/png",
69 "INCR",
70 "KEYBOARD",
71 "LOCK",
72 "marker_event",
73 "_MOTIF_WM_HINTS",
74 "MOUSE",
75 "MULTIPLE",
76 "_NET_ACTIVE_WINDOW",
77 "_NET_CLIENT_LIST_STACKING",
78 "_NET_CURRENT_DESKTOP",
79 "_NET_FRAME_EXTENTS",
80 "_NETSCAPE_URL",
81 "_NET_SUPPORTED",
82 "_NET_SUPPORTING_WM_CHECK",
83 "_NET_WM_CM_S0",
84 "_NET_WM_DESKTOP",
85 "_NET_WM_ICON",
86 "_NET_WM_MOVERESIZE",
87 "_NET_WM_NAME",
88 "_NET_WM_PID",
89 "_NET_WM_PING",
90 "_NET_WM_STATE",
91 "_NET_WM_STATE_ABOVE",
92 "_NET_WM_STATE_FOCUSED",
93 "_NET_WM_STATE_FULLSCREEN",
94 "_NET_WM_STATE_HIDDEN",
95 "_NET_WM_STATE_MAXIMIZED_HORZ",
96 "_NET_WM_STATE_MAXIMIZED_VERT",
97 "_NET_WM_STATE_SKIP_TASKBAR",
98 "_NET_WM_STATE_STICKY",
99 "_NET_WM_USER_TIME",
100 "_NET_WM_WINDOW_OPACITY",
101 "_NET_WM_WINDOW_TYPE",
102 "_NET_WM_WINDOW_TYPE_DND",
103 "_NET_WM_WINDOW_TYPE_MENU",
104 "_NET_WM_WINDOW_TYPE_NORMAL",
105 "_NET_WM_WINDOW_TYPE_NOTIFICATION",
106 "_NET_WM_WINDOW_TYPE_TOOLTIP",
107 "_NET_WORKAREA",
108 "Rel Horiz Wheel",
109 "Rel Vert Wheel",
110 "SAVE_TARGETS",
111 "_SCREENSAVER_STATUS",
112 "_SCREENSAVER_VERSION",
113 "scaling mode",
114 "SELECTION_STRING",
115 "STRING",
116 "Tap Paused",
117 "TARGETS",
118 "TARGET1",
119 "TARGET2",
120 "TEXT",
121 "text/html",
122 "text/plain",
123 "text/plain;charset=utf-8",
124 "text/uri-list",
125 "text/rtf",
126 "text/x-moz-url",
127 "TIMESTAMP",
128 "TOUCHPAD",
129 "TOUCHSCREEN",
130 "Touch Timestamp",
131 "Undesired",
132 "UTF8_STRING",
133 "WM_CLASS",
134 "WM_DELETE_WINDOW",
135 "WM_PROTOCOLS",
136 "WM_WINDOW_ROLE",
137 "XdndActionAsk",
138 "XdndActionCopy",
139 "XdndActionDirectSave",
140 "XdndActionLink",
141 "XdndActionList",
142 "XdndActionMove",
143 "XdndActionPrivate",
144 "XdndAware",
145 "XdndDirectSave0",
146 "XdndDrop",
147 "XdndEnter",
148 "XdndFinished",
149 "XdndLeave",
150 "XdndPosition",
151 "XdndProxy",
152 "XdndSelection",
153 "XdndStatus",
154 "XdndTypeList",
155 nullptr};
156
157 } // namespace
13 158
14 namespace ui { 159 namespace ui {
15 160
16 X11AtomCache::X11AtomCache(XDisplay* xdisplay, const char* const* to_cache) 161 X11AtomCache* X11AtomCache::GetInstance() {
17 : xdisplay_(xdisplay), 162 return base::Singleton<X11AtomCache>::get();
18 uncached_atoms_allowed_(false) { 163 }
164
165 X11AtomCache::X11AtomCache() : xdisplay_(gfx::GetXDisplay()) {
19 int cache_count = 0; 166 int cache_count = 0;
20 for (const char* const* i = to_cache; *i; ++i) 167 for (const char* const* i = kAtomsToCache; *i; ++i)
21 ++cache_count; 168 ++cache_count;
22 169
23 std::unique_ptr<XAtom[]> cached_atoms(new XAtom[cache_count]); 170 std::unique_ptr<XAtom[]> cached_atoms(new XAtom[cache_count]);
24 171
25 // Grab all the atoms we need now to minimize roundtrips to the X11 server. 172 // Grab all the atoms we need now to minimize roundtrips to the X11 server.
26 XInternAtoms(xdisplay_, 173 XInternAtoms(xdisplay_, const_cast<char**>(kAtomsToCache), cache_count, False,
27 const_cast<char**>(to_cache), cache_count, False,
28 cached_atoms.get()); 174 cached_atoms.get());
29 175
30 for (int i = 0; i < cache_count; ++i) 176 for (int i = 0; i < cache_count; ++i)
31 cached_atoms_.insert(std::make_pair(to_cache[i], cached_atoms[i])); 177 cached_atoms_.insert(std::make_pair(kAtomsToCache[i], cached_atoms[i]));
32 } 178 }
33 179
34 X11AtomCache::~X11AtomCache() {} 180 X11AtomCache::~X11AtomCache() {}
35 181
36 XAtom X11AtomCache::GetAtom(const char* name) const { 182 XAtom X11AtomCache::GetAtom(const char* name) const {
37 std::map<std::string, Atom>::const_iterator it = cached_atoms_.find(name); 183 std::map<std::string, Atom>::const_iterator it = cached_atoms_.find(name);
38 184
39 if (uncached_atoms_allowed_ && it == cached_atoms_.end()) { 185 if (it == cached_atoms_.end()) {
40 XAtom atom = XInternAtom(xdisplay_, name, false); 186 XAtom atom = XInternAtom(xdisplay_, name, false);
41 cached_atoms_.insert(std::make_pair(name, atom)); 187 cached_atoms_.insert(std::make_pair(name, atom));
42 return atom; 188 return atom;
43 } 189 }
44 190
45 CHECK(it != cached_atoms_.end()) << " Atom " << name << " not found";
46 return it->second; 191 return it->second;
47 } 192 }
48 193
49 } // namespace ui 194 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/x/x11_atom_cache.h ('k') | ui/platform_window/x11/x11_window_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698