| 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 #ifndef UI_GFX_X_X11_ATOM_CACHE_H_ | 5 #ifndef UI_GFX_X_X11_ATOM_CACHE_H_ |
| 6 #define UI_GFX_X_X11_ATOM_CACHE_H_ | 6 #define UI_GFX_X_X11_ATOM_CACHE_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 9 #include "ui/gfx/gfx_export.h" | 12 #include "ui/gfx/gfx_export.h" |
| 10 | 13 |
| 11 #include <map> | 14 typedef unsigned long Atom; |
| 12 #include <string> | 15 typedef struct _XDisplay XDisplay; |
| 13 | |
| 14 #include <X11/Xlib.h> | |
| 15 | |
| 16 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | |
| 17 #undef RootWindow | |
| 18 | 16 |
| 19 namespace ui { | 17 namespace ui { |
| 20 | 18 |
| 21 // Pre-caches all Atoms on first use to minimize roundtrips to the X11 | 19 // Pre-caches all Atoms on first use to minimize roundtrips to the X11 |
| 22 // server. By default, GetAtom() will CHECK() that atoms accessed through | 20 // server. By default, GetAtom() will CHECK() that atoms accessed through |
| 23 // GetAtom() were passed to the constructor, but this behaviour can be changed | 21 // GetAtom() were passed to the constructor, but this behaviour can be changed |
| 24 // with allow_uncached_atoms(). | 22 // with allow_uncached_atoms(). |
| 25 class GFX_EXPORT X11AtomCache { | 23 class GFX_EXPORT X11AtomCache { |
| 26 public: | 24 public: |
| 27 // Preinterns the NULL terminated list of string |to_cache_ on |xdisplay|. | 25 // Preinterns the NULL terminated list of string |to_cache_ on |xdisplay|. |
| 28 X11AtomCache(Display* xdisplay, const char** to_cache); | 26 X11AtomCache(XDisplay* xdisplay, const char** to_cache); |
| 29 ~X11AtomCache(); | 27 ~X11AtomCache(); |
| 30 | 28 |
| 31 // Returns the pre-interned Atom without having to go to the x server. | 29 // Returns the pre-interned Atom without having to go to the x server. |
| 32 ::Atom GetAtom(const char*) const; | 30 Atom GetAtom(const char*) const; |
| 33 | 31 |
| 34 // When an Atom isn't in the list of items we've cached, we should look it | 32 // 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. | 33 // up, cache it locally, and then return the result. |
| 36 void allow_uncached_atoms() { uncached_atoms_allowed_ = true; } | 34 void allow_uncached_atoms() { uncached_atoms_allowed_ = true; } |
| 37 | 35 |
| 38 private: | 36 private: |
| 39 Display* xdisplay_; | 37 XDisplay* xdisplay_; |
| 40 | 38 |
| 41 bool uncached_atoms_allowed_; | 39 bool uncached_atoms_allowed_; |
| 42 | 40 |
| 43 mutable std::map<std::string, ::Atom> cached_atoms_; | 41 mutable std::map<std::string, Atom> cached_atoms_; |
| 44 | 42 |
| 45 DISALLOW_COPY_AND_ASSIGN(X11AtomCache); | 43 DISALLOW_COPY_AND_ASSIGN(X11AtomCache); |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 } // namespace ui | 46 } // namespace ui |
| 49 | 47 |
| 50 #endif // UI_GFX_X_X11_ATOM_CACHE_H_ | 48 #endif // UI_GFX_X_X11_ATOM_CACHE_H_ |
| OLD | NEW |