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
3 // found in the LICENSE file.
5 #include "ui/gfx/x/x11_atom_cache.h"
10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
15 X11AtomCache::X11AtomCache(XDisplay
* xdisplay
, const char** to_cache
)
16 : xdisplay_(xdisplay
),
17 uncached_atoms_allowed_(false) {
19 for (const char** i
= to_cache
; *i
!= NULL
; i
++)
22 scoped_ptr
<XAtom
[]> cached_atoms(new XAtom
[cache_count
]);
24 // Grab all the atoms we need now to minimize roundtrips to the X11 server.
25 XInternAtoms(xdisplay_
,
26 const_cast<char**>(to_cache
), cache_count
, False
,
29 for (int i
= 0; i
< cache_count
; ++i
)
30 cached_atoms_
.insert(std::make_pair(to_cache
[i
], cached_atoms
[i
]));
33 X11AtomCache::~X11AtomCache() {}
35 XAtom
X11AtomCache::GetAtom(const char* name
) const {
36 std::map
<std::string
, Atom
>::const_iterator it
= cached_atoms_
.find(name
);
38 if (uncached_atoms_allowed_
&& it
== cached_atoms_
.end()) {
39 XAtom atom
= XInternAtom(xdisplay_
, name
, false);
40 cached_atoms_
.insert(std::make_pair(name
, atom
));
44 CHECK(it
!= cached_atoms_
.end()) << " Atom " << name
<< " not found";