]> Dogcows Code - chaz/openbox/blob - otk/gccache.hh
make shape work with the titlebar and handle
[chaz/openbox] / otk / gccache.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef GCCACHE_HH
3 #define GCCACHE_HH
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 }
8
9 #include "display.hh"
10 #include "color.hh"
11
12 namespace otk {
13
14 class BGCCacheItem;
15
16 class BGCCacheContext {
17 public:
18 void set(const BColor &_color, const XFontStruct * const _font,
19 const int _function, const int _subwindow, const int _linewidth);
20 void set(const XFontStruct * const _font);
21
22 ~BGCCacheContext(void);
23
24 private:
25 BGCCacheContext()
26 : gc(0), pixel(0ul), fontid(0ul),
27 function(0), subwindow(0), used(false), screen(~(0u)), linewidth(0) {}
28
29 GC gc;
30 unsigned long pixel;
31 unsigned long fontid;
32 int function;
33 int subwindow;
34 bool used;
35 unsigned int screen;
36 int linewidth;
37
38 BGCCacheContext(const BGCCacheContext &_nocopy);
39 BGCCacheContext &operator=(const BGCCacheContext &_nocopy);
40
41 friend class BGCCache;
42 friend class BGCCacheItem;
43 };
44
45 class BGCCacheItem {
46 public:
47 inline const GC &gc(void) const { return ctx->gc; }
48
49 private:
50 BGCCacheItem(void) : ctx(0), count(0), hits(0), fault(false) { }
51
52 BGCCacheContext *ctx;
53 unsigned int count;
54 unsigned int hits;
55 bool fault;
56
57 BGCCacheItem(const BGCCacheItem &_nocopy);
58 BGCCacheItem &operator=(const BGCCacheItem &_nocopy);
59
60 friend class BGCCache;
61 };
62
63 class BGCCache {
64 public:
65 BGCCache(unsigned int screen_count);
66 ~BGCCache(void);
67
68 // cleans up the cache
69 void purge(void);
70
71 BGCCacheItem *find(const BColor &_color, const XFontStruct * const _font = 0,
72 int _function = GXcopy, int _subwindow = ClipByChildren,
73 int _linewidth = 0);
74 void release(BGCCacheItem *_item);
75
76 private:
77 BGCCacheContext *nextContext(unsigned int _screen);
78 void release(BGCCacheContext *ctx);
79
80 // this is closely modelled after the Qt GC cache, but with some of the
81 // complexity stripped out
82 const unsigned int context_count;
83 const unsigned int cache_size;
84 const unsigned int cache_buckets;
85 const unsigned int cache_total_size;
86 BGCCacheContext **contexts;
87 BGCCacheItem **cache;
88 };
89
90 class BPen {
91 public:
92 inline BPen(const BColor &_color, const XFontStruct * const _font = 0,
93 int _linewidth = 0, int _function = GXcopy,
94 int _subwindow = ClipByChildren)
95 : color(_color), font(_font), linewidth(_linewidth), function(_function),
96 subwindow(_subwindow), cache(OBDisplay::gcCache()), item(0) { }
97
98 inline ~BPen(void) { if (item) cache->release(item); }
99
100 inline const GC &gc(void) const {
101 if (! item) item = cache->find(color, font, function, subwindow,
102 linewidth);
103 return item->gc();
104 }
105
106 private:
107 const BColor &color;
108 const XFontStruct *font;
109 int linewidth;
110 int function;
111 int subwindow;
112
113 mutable BGCCache *cache;
114 mutable BGCCacheItem *item;
115 };
116
117 }
118
119 #endif // GCCACHE_HH
This page took 0.043274 seconds and 4 git commands to generate.