| 1 |
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- |
| 2 |
// PixmapCache.hh for Blackbox - an X11 Window manager |
| 3 |
// Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <[email protected]> |
| 4 |
// Copyright (c) 1997 - 2000, 2002 - 2005 |
| 5 |
// Bradley T Hughes <bhughes at trolltech.com> |
| 6 |
// |
| 7 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
// copy of this software and associated documentation files (the "Software"), |
| 9 |
// to deal in the Software without restriction, including without limitation |
| 10 |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
// and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
// Software is furnished to do so, subject to the following conditions: |
| 13 |
// |
| 14 |
// The above copyright notice and this permission notice shall be included in |
| 15 |
// all copies or substantial portions of the Software. |
| 16 |
// |
| 17 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 |
// DEALINGS IN THE SOFTWARE. |
| 24 |
|
| 25 |
#ifndef __PixmapCache_hh |
| 26 |
#define __PixmapCache_hh |
| 27 |
|
| 28 |
#include "Util.hh" |
| 29 |
|
| 30 |
namespace bt { |
| 31 |
|
| 32 |
// forward declarations |
| 33 |
class Texture; |
| 34 |
|
| 35 |
class PixmapCache : public NoCopy { |
| 36 |
public: |
| 37 |
/* |
| 38 |
Returns the cache limit in kilobytes. The default is one |
| 39 |
megabyte (1024 kilobytes). |
| 40 |
|
| 41 |
When this limit is reached, the cache will automatically free |
| 42 |
unused pixmaps to reduce the amount of server side memory used. |
| 43 |
|
| 44 |
NOTE: This limit is not a hard limit. The cache will never free |
| 45 |
a pixmap that is in use. This means it is possible that the |
| 46 |
PixmapCache memory usage can exceed this limit. |
| 47 |
*/ |
| 48 |
static unsigned long cacheLimit(void); |
| 49 |
|
| 50 |
/* |
| 51 |
Set the cache limit to the specified value (in kilobytes). |
| 52 |
*/ |
| 53 |
static void setCacheLimit(unsigned long limit); |
| 54 |
|
| 55 |
/* |
| 56 |
Returns the current amount of memory in kilobytes used by the X |
| 57 |
server for the pixmaps in the cache. |
| 58 |
*/ |
| 59 |
static unsigned long memoryUsage(void); |
| 60 |
|
| 61 |
/* |
| 62 |
Returns a pixmap matching the specified texture and size on the |
| 63 |
specified screen. The pixmap will be rendered if necessary. |
| 64 |
|
| 65 |
If old_pixmap is non-zero, PixmapCache::release(old_pixmap) will |
| 66 |
be called immediately after finding the requested pixmap. |
| 67 |
*/ |
| 68 |
static Pixmap find(unsigned int screen, |
| 69 |
const Texture &texture, |
| 70 |
unsigned int width, unsigned int height, |
| 71 |
Pixmap old_pixmap = 0ul); |
| 72 |
|
| 73 |
/* |
| 74 |
Indicates that the specified pixmap is no longer needed. |
| 75 |
Pixmaps contained in the cache are reference counted, so you |
| 76 |
should call this function once for each time you call |
| 77 |
PixmapCache::find(). |
| 78 |
*/ |
| 79 |
static void release(Pixmap pixmap); |
| 80 |
|
| 81 |
/* |
| 82 |
Free all unused pixmaps in the cache. |
| 83 |
*/ |
| 84 |
static void clearCache(void); |
| 85 |
|
| 86 |
private: |
| 87 |
// static only interface |
| 88 |
PixmapCache(); |
| 89 |
}; |
| 90 |
|
| 91 |
} // namespace bt |
| 92 |
|
| 93 |
#endif // __PixmapCache_hh |