]>
Dogcows Code - chaz/openbox/blob - GCCache.hh
614eac1df4a658a69c592ec11c6331f99fb4d79d
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // GCCache.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh at debian.org>
4 // Copyright (c) 1997 - 2000, 2002 Bradley T Hughes <bhughes at trolltech.com>
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
31 #include "BaseDisplay.hh"
36 class BGCCacheContext
{
38 void set(const BColor
&_color
, const XFontStruct
* const _font
,
39 const int _function
, const int _subwindow
, const int _linewidth
);
40 void set(const XFontStruct
* const _font
);
42 ~BGCCacheContext(void);
45 BGCCacheContext(const BaseDisplay
* const _display
)
46 : display(_display
), gc(0), pixel(0ul), fontid(0ul),
47 function(0), subwindow(0), used(false), screen(~(0u)), linewidth(0) {}
49 const BaseDisplay
*display
;
59 BGCCacheContext(const BGCCacheContext
&_nocopy
);
60 BGCCacheContext
&operator=(const BGCCacheContext
&_nocopy
);
62 friend class BGCCache
;
63 friend class BGCCacheItem
;
68 inline const GC
&gc(void) const { return ctx
->gc
; }
71 BGCCacheItem(void) : ctx(0), count(0), hits(0), fault(false) { }
78 BGCCacheItem(const BGCCacheItem
&_nocopy
);
79 BGCCacheItem
&operator=(const BGCCacheItem
&_nocopy
);
81 friend class BGCCache
;
86 BGCCache(const BaseDisplay
* const _display
, unsigned int screen_count
);
89 // cleans up the cache
92 BGCCacheItem
*find(const BColor
&_color
, const XFontStruct
* const _font
= 0,
93 int _function
= GXcopy
, int _subwindow
= ClipByChildren
,
95 void release(BGCCacheItem
*_item
);
98 BGCCacheContext
*nextContext(unsigned int _screen
);
99 void release(BGCCacheContext
*ctx
);
101 // this is closely modelled after the Qt GC cache, but with some of the
102 // complexity stripped out
103 const BaseDisplay
*display
;
105 const unsigned int context_count
;
106 const unsigned int cache_size
;
107 const unsigned int cache_buckets
;
108 const unsigned int cache_total_size
;
109 BGCCacheContext
**contexts
;
110 BGCCacheItem
**cache
;
115 inline BPen(const BColor
&_color
, const XFontStruct
* const _font
= 0,
116 int _linewidth
= 0, int _function
= GXcopy
,
117 int _subwindow
= ClipByChildren
)
118 : color(_color
), font(_font
), linewidth(_linewidth
), function(_function
),
119 subwindow(_subwindow
), cache(_color
.display()->gcCache()), item(0) { }
121 inline ~BPen(void) { if (item
) cache
->release(item
); }
123 inline const GC
&gc(void) const {
124 if (! item
) item
= cache
->find(color
, font
, function
, subwindow
,
131 const XFontStruct
*font
;
136 mutable BGCCache
*cache
;
137 mutable BGCCacheItem
*item
;
This page took 0.038845 seconds and 3 git commands to generate.