summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 21:12:37 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 21:12:37 +0000
commitf06ca34a7f9942f3e7c8e7016238107e37e9e3ec (patch)
tree4799d03a488a195ed5bbc7effb15ff7616b7647a
parent739c7c016b1b70484aa996ffcbd84ef134cb5573 (diff)
downloadchromium_src-f06ca34a7f9942f3e7c8e7016238107e37e9e3ec.zip
chromium_src-f06ca34a7f9942f3e7c8e7016238107e37e9e3ec.tar.gz
chromium_src-f06ca34a7f9942f3e7c8e7016238107e37e9e3ec.tar.bz2
Changes x11_util::GetRenderVisualFormat to keep a cache of render
picts. This way we can support different visuals while still caching the value. BUG=none TEST=none Review URL: http://codereview.chromium.org/210021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26615 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/x11_util.cc54
-rw-r--r--chrome/common/x11_util_internal.h7
2 files changed, 54 insertions, 7 deletions
diff --git a/chrome/common/x11_util.cc b/chrome/common/x11_util.cc
index 0921c6e..14f85d9 100644
--- a/chrome/common/x11_util.cc
+++ b/chrome/common/x11_util.cc
@@ -15,6 +15,7 @@
#include <sys/ipc.h>
#include <sys/shm.h>
+#include <list>
#include <set>
#include "base/logging.h"
@@ -24,6 +25,34 @@
namespace x11_util {
+namespace {
+
+// Used to cache the XRenderPictFormat for a visual/display pair.
+struct CachedPictFormat {
+ bool equals(Display* display, Visual* visual) const {
+ return display == this->display && visual == this->visual;
+ }
+
+ Display* display;
+ Visual* visual;
+ XRenderPictFormat* format;
+};
+
+typedef std::list<CachedPictFormat> CachedPictFormats;
+
+// Returns the cache of pict formats.
+CachedPictFormats* get_cached_pict_formats() {
+ static CachedPictFormats* formats = NULL;
+ if (!formats)
+ formats = new CachedPictFormats();
+ return formats;
+}
+
+// Maximum number of CachedPictFormats we keep around.
+const size_t kMaxCacheSize = 5;
+
+} // namespace
+
bool XDisplayExists() {
return (gdk_display_get_default() != NULL);
}
@@ -330,15 +359,30 @@ bool GetXWindowStack(std::vector<XID>* windows) {
}
XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual) {
- static XRenderPictFormat* pictformat = NULL;
- if (pictformat)
- return pictformat;
-
DCHECK(QueryRenderSupport(dpy));
- pictformat = XRenderFindVisualFormat(dpy, visual);
+ CachedPictFormats* formats = get_cached_pict_formats();
+
+ for (CachedPictFormats::const_iterator i = formats->begin();
+ i != formats->end(); ++i) {
+ if (i->equals(dpy, visual))
+ return i->format;
+ }
+
+ // Not cached, look up the value.
+ XRenderPictFormat* pictformat = XRenderFindVisualFormat(dpy, visual);
CHECK(pictformat) << "XRENDER does not support default visual";
+ // And store it in the cache.
+ CachedPictFormat cached_value;
+ cached_value.visual = visual;
+ cached_value.display = dpy;
+ cached_value.format = pictformat;
+ formats->push_front(cached_value);
+
+ if (formats->size() == kMaxCacheSize)
+ formats->pop_back();
+
return pictformat;
}
diff --git a/chrome/common/x11_util_internal.h b/chrome/common/x11_util_internal.h
index 52a8a8c..8042530 100644
--- a/chrome/common/x11_util_internal.h
+++ b/chrome/common/x11_util_internal.h
@@ -19,11 +19,14 @@ extern "C" {
}
namespace x11_util {
- // These functions cache their results and must be called from the UI thread.
- // Currently they don't support multiple screens/displays.
+ // NOTE: these function caches the results and must be called from the UI
+ // thread.
// Get the XRENDER format id for ARGB32 (Skia's format).
+ //
+ // NOTE:Currently this don't support multiple screens/displays.
XRenderPictFormat* GetRenderARGB32Format(Display* dpy);
+
// Get the XRENDER format id for the default visual on the first screen. This
// is the format which our GTK window will have.
XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual);