Skip to content
Snippets Groups Projects
Commit f06ca34a authored by sky@chromium.org's avatar sky@chromium.org
Browse files

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
parent 739c7c01
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/shm.h> #include <sys/shm.h>
#include <list>
#include <set> #include <set>
#include "base/logging.h" #include "base/logging.h"
...@@ -24,6 +25,34 @@ ...@@ -24,6 +25,34 @@
namespace x11_util { 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() { bool XDisplayExists() {
return (gdk_display_get_default() != NULL); return (gdk_display_get_default() != NULL);
} }
...@@ -330,15 +359,30 @@ bool GetXWindowStack(std::vector<XID>* windows) { ...@@ -330,15 +359,30 @@ bool GetXWindowStack(std::vector<XID>* windows) {
} }
XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual) { XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual) {
static XRenderPictFormat* pictformat = NULL;
if (pictformat)
return pictformat;
DCHECK(QueryRenderSupport(dpy)); 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"; 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; return pictformat;
} }
......
...@@ -19,11 +19,14 @@ extern "C" { ...@@ -19,11 +19,14 @@ extern "C" {
} }
namespace x11_util { namespace x11_util {
// These functions cache their results and must be called from the UI thread. // NOTE: these function caches the results and must be called from the UI
// Currently they don't support multiple screens/displays. // thread.
// Get the XRENDER format id for ARGB32 (Skia's format). // Get the XRENDER format id for ARGB32 (Skia's format).
//
// NOTE:Currently this don't support multiple screens/displays.
XRenderPictFormat* GetRenderARGB32Format(Display* dpy); XRenderPictFormat* GetRenderARGB32Format(Display* dpy);
// Get the XRENDER format id for the default visual on the first screen. This // Get the XRENDER format id for the default visual on the first screen. This
// is the format which our GTK window will have. // is the format which our GTK window will have.
XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual); XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment