]> Dogcows Code - chaz/openbox/blob - otk/gccache.hh
correct a comment
[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 GCCacheItem;
15
16 class GCCacheContext {
17 public:
18 void set(const Color &_color, const XFontStruct * const _font,
19 const int _function, const int _subwindow, const int _linewidth);
20 void set(const XFontStruct * const _font);
21
22 ~GCCacheContext(void);
23
24 private:
25 GCCacheContext()
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 GCCacheContext(const GCCacheContext &_nocopy);
39 GCCacheContext &operator=(const GCCacheContext &_nocopy);
40
41 friend class GCCache;
42 friend class GCCacheItem;
43 };
44
45 class GCCacheItem {
46 public:
47 inline const GC &gc(void) const { return ctx->gc; }
48
49 private:
50 GCCacheItem(void) : ctx(0), count(0), hits(0), fault(false) { }
51
52 GCCacheContext *ctx;
53 unsigned int count;
54 unsigned int hits;
55 bool fault;
56
57 GCCacheItem(const GCCacheItem &_nocopy);
58 GCCacheItem &operator=(const GCCacheItem &_nocopy);
59
60 friend class GCCache;
61 };
62
63 class GCCache {
64 public:
65 GCCache(unsigned int screen_count);
66 ~GCCache(void);
67
68 // cleans up the cache
69 void purge(void);
70
71 GCCacheItem *find(const Color &_color, const XFontStruct * const _font = 0,
72 int _function = GXcopy, int _subwindow = ClipByChildren,
73 int _linewidth = 0);
74 void release(GCCacheItem *_item);
75
76 private:
77 GCCacheContext *nextContext(unsigned int _screen);
78 void release(GCCacheContext *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 GCCacheContext **contexts;
87 GCCacheItem **cache;
88 };
89
90 class Pen {
91 public:
92 inline Pen(const Color &_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(display->gcCache()), item(0) { }
97
98 inline ~Pen(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 Color &color;
108 const XFontStruct *font;
109 int linewidth;
110 int function;
111 int subwindow;
112
113 mutable GCCache *cache;
114 mutable GCCacheItem *item;
115 };
116
117 }
118
119 #endif // __gccache_hh
This page took 0.036819 seconds and 4 git commands to generate.