]> Dogcows Code - chaz/openbox/blobdiff - src/GCCache.cc
sync with the 2.0 branch
[chaz/openbox] / src / GCCache.cc
index 941d67ef0d0c80bd07005206b59000b904649d5c..829d130fbc6b76f9ee622e4abfb1fef8a8365251 100644 (file)
@@ -35,14 +35,25 @@ extern "C" {
 #include "Util.hh"
 
 
+BGCCacheContext::~BGCCacheContext(void) {
+  if (gc)
+    XFreeGC(display->getXDisplay(), gc);
+}
+
+
 void BGCCacheContext::set(const BColor &_color,
                           const XFontStruct * const _font,
-                          const int _function, const int _subwindow) {
+                          const int _function, const int _subwindow,
+                          int _linewidth) {
   XGCValues gcv;
   pixel = gcv.foreground = _color.pixel();
   function = gcv.function = _function;
   subwindow = gcv.subwindow_mode = _subwindow;
-  unsigned long mask = GCForeground | GCFunction | GCSubwindowMode;
+  linewidth = gcv.line_width = _linewidth;
+  gcv.cap_style = CapProjecting;
+
+  unsigned long mask = GCForeground | GCFunction | GCSubwindowMode |
+    GCLineWidth | GCCapStyle;
 
   if (_font) {
     fontid = gcv.font = _font->fid;
@@ -67,9 +78,10 @@ void BGCCacheContext::set(const XFontStruct * const _font) {
 }
 
 
-BGCCache::BGCCache(const BaseDisplay * const _display)
+BGCCache::BGCCache(const BaseDisplay * const _display,
+                   unsigned int screen_count)
   : display(_display),  context_count(128u),
-    cache_size(16u), cache_buckets(8u),
+    cache_size(16u), cache_buckets(8u * screen_count),
     cache_total_size(cache_size * cache_buckets) {
 
   contexts = new BGCCacheContext*[context_count];
@@ -90,8 +102,6 @@ BGCCache::~BGCCache(void) {
   std::for_each(cache, cache + cache_total_size, PointerAssassin());
   delete [] cache;
   delete [] contexts;
-  cache = 0;
-  contexts = 0;
 }
 
 
@@ -108,14 +118,13 @@ BGCCacheContext *BGCCache::nextContext(unsigned int scr) {
       c->used = false;
       c->screen = scr;
     }
-    if (! c->used && c->screen == scr) {
-      c->used = true;
+    if (! c->used && c->screen == scr)
       return c;
-    }
   }
 
   fprintf(stderr, "BGCCache: context fault!\n");
   abort();
+  return (BGCCacheContext*) 0; // not reached
 }
 
 
@@ -126,19 +135,23 @@ void BGCCache::release(BGCCacheContext *ctx) {
 
 BGCCacheItem *BGCCache::find(const BColor &_color,
                              const XFontStruct * const _font,
-                             int _function, int _subwindow) {
+                             int _function, int _subwindow, int _linewidth) {
   const unsigned long pixel = _color.pixel();
   const unsigned int screen = _color.screen();
   const int key = _color.red() ^ _color.green() ^ _color.blue();
   int k = (key % cache_size) * cache_buckets;
-  int i = 0; // loop variable
+  unsigned int i = 0; // loop variable
   BGCCacheItem *c = cache[ k ], *prev = 0;
 
-  // this will either loop 8 times then return/abort or it will stop matching
+  /*
+    this will either loop cache_buckets times then return/abort or
+    it will stop matching
+  */
   while (c->ctx &&
          (c->ctx->pixel != pixel || c->ctx->function != _function ||
-          c->ctx->subwindow != _subwindow || c->ctx->screen != screen)) {
-    if (i < 7) {
+          c->ctx->subwindow != _subwindow || c->ctx->screen != screen ||
+          c->ctx->linewidth != _linewidth)) {
+    if (i < (cache_buckets - 1)) {
       prev = c;
       c = cache[ ++k ];
       ++i;
@@ -146,21 +159,20 @@ BGCCacheItem *BGCCache::find(const BColor &_color,
     }
     if (c->count == 0 && c->ctx->screen == screen) {
       // use this cache item
-      c->ctx->set(_color, _font, _function, _subwindow);
+      c->ctx->set(_color, _font, _function, _subwindow, _linewidth);
       c->ctx->used = true;
       c->count = 1;
       c->hits = 1;
       return c;
     }
     // cache fault!
-    fprintf(stderr, "BGCCache: cache fault\n");
+    fprintf(stderr, "BGCCache: cache fault, count: %d, screen: %d, item screen: %d\n", c->count, screen, c->ctx->screen);
     abort();
   }
 
-  const unsigned long fontid = _font ? _font->fid : 0;
   if (c->ctx) {
     // reuse existing context
-    if (fontid && fontid != c->ctx->fontid)
+    if (_font && _font->fid && _font->fid != c->ctx->fontid)
       c->ctx->set(_font);
     c->count++;
     c->hits++;
@@ -170,7 +182,7 @@ BGCCacheItem *BGCCache::find(const BColor &_color,
     }
   } else {
     c->ctx = nextContext(screen);
-    c->ctx->set(_color, _font, _function, _subwindow);
+    c->ctx->set(_color, _font, _function, _subwindow, _linewidth);
     c->ctx->used = true;
     c->count = 1;
     c->hits = 1;
This page took 0.023288 seconds and 4 git commands to generate.