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 #ifndef UI_GFX_X_X11_ATOM_CACHE_H_
6 #define UI_GFX_X_X11_ATOM_CACHE_H_
8 #include "base/basictypes.h"
9 #include "ui/gfx/gfx_export.h"
16 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
21 // Pre-caches all Atoms on first use to minimize roundtrips to the X11
22 // server. By default, GetAtom() will CHECK() that atoms accessed through
23 // GetAtom() were passed to the constructor, but this behaviour can be changed
24 // with allow_uncached_atoms().
25 class GFX_EXPORT X11AtomCache
{
27 // Preinterns the NULL terminated list of string |to_cache_ on |xdisplay|.
28 X11AtomCache(Display
* xdisplay
, const char** to_cache
);
31 // Returns the pre-interned Atom without having to go to the x server.
32 ::Atom
GetAtom(const char*) const;
34 // When an Atom isn't in the list of items we've cached, we should look it
35 // up, cache it locally, and then return the result.
36 void allow_uncached_atoms() { uncached_atoms_allowed_
= true; }
41 bool uncached_atoms_allowed_
;
43 mutable std::map
<std::string
, ::Atom
> cached_atoms_
;
45 DISALLOW_COPY_AND_ASSIGN(X11AtomCache
);
50 #endif // UI_GFX_X_X11_ATOM_CACHE_H_